[FS, USER] Debug filesystem, fs syscalls
This commit is contained in:
parent
2fe66e4f80
commit
fd782365b7
@ -7,6 +7,11 @@ int main(int argc, char **argv)
|
|||||||
(void) argc;
|
(void) argc;
|
||||||
(void) argv;
|
(void) argv;
|
||||||
|
|
||||||
|
|
||||||
|
FILE *fp = fopen("/dev/debug", "w");
|
||||||
|
fprintf(fp, "Hello, filesystem!\n");
|
||||||
|
|
||||||
|
|
||||||
for(;;);
|
for(;;);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -30,24 +30,19 @@ int kmain(uint64_t multiboot_magic, void *multiboot_data)
|
|||||||
|
|
||||||
debug_info("Syscall enabled:%d\n", CPUID_FEATURE_SYSCALL);
|
debug_info("Syscall enabled:%d\n", CPUID_FEATURE_SYSCALL);
|
||||||
|
|
||||||
|
|
||||||
|
fs_mount(0, "/");
|
||||||
|
fs_mount(&debug_file, "/dev/debug");
|
||||||
|
|
||||||
|
fs_write(&debug_file, "TESTING DEBUG FILE", 18, 0);
|
||||||
|
|
||||||
process_t *p1 = process_spawn(0);
|
process_t *p1 = process_spawn(0);
|
||||||
char *args[] = {"init", "Hello, arg", "5", 0};
|
char *args[] = {"init", "Hello, arg", "5", 0};
|
||||||
char *env[] = {"OS=mittos64", 0};
|
char *env[] = {"OS=mittos64", 0};
|
||||||
|
p1->fp[1].file = fs_namef("/dev/debug");
|
||||||
thread_t *th = exec_elf(p1, mboot_data.init, args, env);
|
thread_t *th = exec_elf(p1, mboot_data.init, args, env);
|
||||||
scheduler_insert(th);
|
scheduler_insert(th);
|
||||||
|
|
||||||
procmm_print_map(p1->mmap);
|
|
||||||
fs_mount(0, "/");
|
|
||||||
fs_mount(0, "/dev");
|
|
||||||
fs_mount(0, "/home/user/mnt/photos");
|
|
||||||
|
|
||||||
|
|
||||||
fs_namef("/");
|
|
||||||
fs_namef("/usr/local/bin/python");
|
|
||||||
fs_namef("/dev/tty0");
|
|
||||||
fs_namef("/home/thomas");
|
|
||||||
fs_namef("/home/user/mnt/photos/2016/june");
|
|
||||||
|
|
||||||
asm("sti");
|
asm("sti");
|
||||||
debug_info("BOOT COMPLETE\n");
|
debug_info("BOOT COMPLETE\n");
|
||||||
schedule();
|
schedule();
|
||||||
|
20
kernel/fs/debug_fs.c
Normal file
20
kernel/fs/debug_fs.c
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#include <vfs.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
size_t debug_write(file_t *file, void *buffer, size_t nbyte, size_t offset)
|
||||||
|
{
|
||||||
|
(void)file;
|
||||||
|
(void)offset;
|
||||||
|
debug_putsn(buffer, nbyte);
|
||||||
|
return nbyte;
|
||||||
|
}
|
||||||
|
|
||||||
|
fs_driver_t debug_fs = {
|
||||||
|
.write = debug_write,
|
||||||
|
};
|
||||||
|
|
||||||
|
file_t debug_file = {
|
||||||
|
.refs = 1,
|
||||||
|
.type = FS_TTY,
|
||||||
|
.driver = &debug_fs,
|
||||||
|
};
|
@ -7,6 +7,9 @@ typedef struct process_st process_t;
|
|||||||
#include <cpu.h>
|
#include <cpu.h>
|
||||||
#include <sync.h>
|
#include <sync.h>
|
||||||
#include <mem.h>
|
#include <mem.h>
|
||||||
|
#include <vfs.h>
|
||||||
|
|
||||||
|
#define PROC_NUMFP 20
|
||||||
|
|
||||||
struct procmm_mmap_st;
|
struct procmm_mmap_st;
|
||||||
typedef struct process_st
|
typedef struct process_st
|
||||||
@ -20,6 +23,11 @@ typedef struct process_st
|
|||||||
LIST(struct process_st, children);
|
LIST(struct process_st, children);
|
||||||
LIST(struct process_st, siblings);
|
LIST(struct process_st, siblings);
|
||||||
LIST(thread_t, threads);
|
LIST(thread_t, threads);
|
||||||
|
struct {
|
||||||
|
file_t *file;
|
||||||
|
uint64_t flags;
|
||||||
|
uint64_t pos;
|
||||||
|
} fp[PROC_NUMFP];
|
||||||
} process_t;
|
} process_t;
|
||||||
|
|
||||||
#define PROC_STATE_READY 1
|
#define PROC_STATE_READY 1
|
||||||
|
@ -40,8 +40,15 @@ typedef long (*syscall_handler_t)(long num, long, long, long, long, long, long);
|
|||||||
|
|
||||||
#define SYSCALL_REGISTER(name, num) syscall_handlers[num] = syscall_##name
|
#define SYSCALL_REGISTER(name, num) syscall_handlers[num] = syscall_##name
|
||||||
|
|
||||||
|
SYSCALL_DECL(open);
|
||||||
|
SYSCALL_DECL(close);
|
||||||
|
SYSCALL_DECL(read);
|
||||||
SYSCALL_DECL(write);
|
SYSCALL_DECL(write);
|
||||||
|
SYSCALL_DECL(isatty);
|
||||||
|
SYSCALL_DECL(seek);
|
||||||
|
|
||||||
SYSCALL_DECL(brk);
|
SYSCALL_DECL(brk);
|
||||||
|
|
||||||
SYSCALL_DECL(fork);
|
SYSCALL_DECL(fork);
|
||||||
SYSCALL_DECL(exit);
|
SYSCALL_DECL(exit);
|
||||||
SYSCALL_DECL(wait);
|
SYSCALL_DECL(wait);
|
||||||
|
@ -22,6 +22,7 @@ typedef struct dirent_st
|
|||||||
#define FS_FILE 0x1
|
#define FS_FILE 0x1
|
||||||
#define FS_DIR 0x2
|
#define FS_DIR 0x2
|
||||||
#define FS_PIPE 0x3
|
#define FS_PIPE 0x3
|
||||||
|
#define FS_TTY 0x4
|
||||||
|
|
||||||
typedef struct fs_driver_st
|
typedef struct fs_driver_st
|
||||||
{
|
{
|
||||||
@ -56,3 +57,5 @@ void fs_mount(file_t *root, const char *path);
|
|||||||
void fs_umount(const char *path);
|
void fs_umount(const char *path);
|
||||||
|
|
||||||
file_t *fs_namef(const char *path);
|
file_t *fs_namef(const char *path);
|
||||||
|
|
||||||
|
file_t debug_file;
|
||||||
|
@ -24,6 +24,16 @@ process_t *process_spawn(process_t *parent)
|
|||||||
LIST_APPEND(parent->children, proc, siblings);
|
LIST_APPEND(parent->children, proc, siblings);
|
||||||
proc->mmap = procmm_new_map(proc, parent->mmap);
|
proc->mmap = procmm_new_map(proc, parent->mmap);
|
||||||
spin_unlock(&parent->lock);
|
spin_unlock(&parent->lock);
|
||||||
|
for(int i = 0; i < PROC_NUMFP; i++)
|
||||||
|
{
|
||||||
|
if(parent->fp[i].file)
|
||||||
|
{
|
||||||
|
proc->fp[i].file = fs_get(parent->fp[i].file);
|
||||||
|
proc->fp[i].pos = parent->fp[i].pos;
|
||||||
|
proc->fp[i].flags = parent->fp[i].flags;
|
||||||
|
fs_open(proc->fp[i].file, proc->fp[i].flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
proc->mmap = procmm_new_map(proc, 0);
|
proc->mmap = procmm_new_map(proc, 0);
|
||||||
}
|
}
|
||||||
@ -76,6 +86,14 @@ void process_exit(process_t *proc, uint64_t status)
|
|||||||
c->parent = init_proc;
|
c->parent = init_proc;
|
||||||
LIST_APPEND(init_proc->children, c, siblings);
|
LIST_APPEND(init_proc->children, c, siblings);
|
||||||
}
|
}
|
||||||
|
for(int i = 0; i < PROC_NUMFP; i++)
|
||||||
|
{
|
||||||
|
if(proc->fp[i].file)
|
||||||
|
{
|
||||||
|
fs_close(proc->fp[i].file);
|
||||||
|
fs_put(proc->fp[i].file);
|
||||||
|
}
|
||||||
|
}
|
||||||
proc->state = PROC_STATE_ZOMBIE;
|
proc->state = PROC_STATE_ZOMBIE;
|
||||||
spin_unlock(&proc->lock);
|
spin_unlock(&proc->lock);
|
||||||
}
|
}
|
||||||
|
@ -4,17 +4,77 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <mem.h>
|
#include <mem.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <process.h>
|
||||||
|
#include <vfs.h>
|
||||||
|
|
||||||
|
SYSCALL_DEF(open)
|
||||||
|
{
|
||||||
|
SYSCALL_INIT(char *, path, int, flags, int, mode);
|
||||||
|
process_t *p = get_current_process();
|
||||||
|
for(int i = 0; i < PROC_NUMFP; i++)
|
||||||
|
{
|
||||||
|
if(!p->fp[i].file)
|
||||||
|
{
|
||||||
|
p->fp[i].file = fs_namef(path);
|
||||||
|
p->fp[i].flags = flags;
|
||||||
|
fs_open(p->fp[i].file, flags);
|
||||||
|
p->fp[i].pos = 0;
|
||||||
|
if(p->fp[i].file)
|
||||||
|
return i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSCALL_DEF(close)
|
||||||
|
{
|
||||||
|
SYSCALL_INIT(int, fd);
|
||||||
|
process_t *p = get_current_process();
|
||||||
|
int retval = fs_close(p->fp[fd].file);
|
||||||
|
fs_put(p->fp[fd].file);
|
||||||
|
p->fp[fd].file = 0;
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSCALL_DEF(isatty)
|
||||||
|
{
|
||||||
|
SYSCALL_INIT(int, fd);
|
||||||
|
process_t *p = get_current_process();
|
||||||
|
if(p->fp[fd].file && ((p->fp[fd].file->type & FS_TTY) == FS_TTY))
|
||||||
|
return 1;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
SYSCALL_DEF(read)
|
||||||
|
{
|
||||||
|
SYSCALL_INIT(int, fd, void *, buffer, size_t, nbyte);
|
||||||
|
process_t *p = get_current_process();
|
||||||
|
int64_t bytes = fs_read(p->fp[fd].file, buffer, nbyte, p->fp[fd].pos);
|
||||||
|
p->fp[fd].pos += bytes;
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
SYSCALL_DEF(write)
|
SYSCALL_DEF(write)
|
||||||
{
|
{
|
||||||
SYSCALL_INIT(int, fd, void *, buffer, size_t, nbyte);
|
SYSCALL_INIT(int, fd, void *, buffer, size_t, nbyte);
|
||||||
|
|
||||||
|
process_t *p = get_current_process();
|
||||||
if(fd == 1)
|
int64_t bytes = fs_write(p->fp[fd].file, buffer, nbyte, p->fp[fd].pos);
|
||||||
{
|
p->fp[fd].pos += bytes;
|
||||||
debugn(buffer, nbyte);
|
return bytes;
|
||||||
return nbyte;
|
}
|
||||||
}
|
|
||||||
|
SYSCALL_DEF(seek)
|
||||||
return 0;
|
{
|
||||||
|
SYSCALL_INIT(int, fd, long, offset, int, whence);
|
||||||
|
process_t *p = get_current_process();
|
||||||
|
if(!p->fp[fd].file)
|
||||||
|
return -1;
|
||||||
|
if(whence == 0)
|
||||||
|
p->fp[fd].pos = offset;
|
||||||
|
else if(whence == 1)
|
||||||
|
p->fp[fd].pos += offset;
|
||||||
|
|
||||||
|
return p->fp[fd].pos;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#include <mem.h>
|
#include <mem.h>
|
||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <list.h>
|
#include <list.h>
|
||||||
|
#include <vfs.h>
|
||||||
|
|
||||||
SYSCALL_DEF(fork)
|
SYSCALL_DEF(fork)
|
||||||
{
|
{
|
||||||
|
@ -56,8 +56,15 @@ void syscall_init()
|
|||||||
memset(syscall_handlers, 0, 1024*sizeof(syscall_handler_t));
|
memset(syscall_handlers, 0, 1024*sizeof(syscall_handler_t));
|
||||||
|
|
||||||
SYSCALL_REGISTER(debug, SYS_DEBUG);
|
SYSCALL_REGISTER(debug, SYS_DEBUG);
|
||||||
|
SYSCALL_REGISTER(open, SYS_OPEN);
|
||||||
|
SYSCALL_REGISTER(close, SYS_CLOSE);
|
||||||
|
SYSCALL_REGISTER(read, SYS_READ);
|
||||||
SYSCALL_REGISTER(write, SYS_WRITE);
|
SYSCALL_REGISTER(write, SYS_WRITE);
|
||||||
|
SYSCALL_REGISTER(isatty, SYS_ISATTY);
|
||||||
|
SYSCALL_REGISTER(seek, SYS_SEEK);
|
||||||
|
|
||||||
SYSCALL_REGISTER(brk, SYS_BRK);
|
SYSCALL_REGISTER(brk, SYS_BRK);
|
||||||
|
|
||||||
SYSCALL_REGISTER(fork, SYS_FORK);
|
SYSCALL_REGISTER(fork, SYS_FORK);
|
||||||
SYSCALL_REGISTER(exit, SYS_EXIT);
|
SYSCALL_REGISTER(exit, SYS_EXIT);
|
||||||
SYSCALL_REGISTER(wait, SYS_WAIT);
|
SYSCALL_REGISTER(wait, SYS_WAIT);
|
||||||
|
@ -4,18 +4,48 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/uio.h>
|
#include <sys/uio.h>
|
||||||
|
|
||||||
SYSCALL_DEF(ioctl)
|
|
||||||
{
|
|
||||||
SYSCALL_INIT(int, fd, unsigned long, request);
|
|
||||||
|
|
||||||
if(fd == 1 && request == TIOCGWINSZ)
|
SYSCALL_DEF(open)
|
||||||
{
|
{
|
||||||
return 0;
|
SYSCALL_INIT(char *, path, int, flags, int, mode);
|
||||||
}
|
return kernel_syscall(SYS_OPEN, path, flags, mode);
|
||||||
kernel_debug("==> IOCTL - unsupported request:%lx\n", request);
|
}
|
||||||
return -1;
|
SYSCALL_DEF(close)
|
||||||
|
{
|
||||||
|
SYSCALL_INIT(int, fd);
|
||||||
|
return kernel_syscall(SYS_CLOSE, fd);
|
||||||
|
}
|
||||||
|
SYSCALL_DEF(read)
|
||||||
|
{
|
||||||
|
SYSCALL_INIT(int, fd, void *, buffer, size_t, nbyte);
|
||||||
|
|
||||||
|
return kernel_syscall(SYS_READ, fd, buffer, nbyte);
|
||||||
|
}
|
||||||
|
SYSCALL_DEF(write)
|
||||||
|
{
|
||||||
|
SYSCALL_INIT(int, fd, void *, buffer, size_t, nbyte);
|
||||||
|
|
||||||
|
return kernel_syscall(SYS_WRITE, fd, buffer, nbyte);
|
||||||
|
}
|
||||||
|
SYSCALL_DEF(lseek)
|
||||||
|
{
|
||||||
|
SYSCALL_INIT(int, fd, long, offset, int, whence);
|
||||||
|
return kernel_syscall(SYS_SEEK, fd, offset, whence);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SYSCALL_DEF(readv)
|
||||||
|
{
|
||||||
|
SYSCALL_INIT(int, fd, const struct iovec *, iov, int, iovcnt);
|
||||||
|
|
||||||
|
size_t len = 0;
|
||||||
|
|
||||||
|
for(int i=0; i < iovcnt; i++)
|
||||||
|
{
|
||||||
|
len += read(fd, iov[i].iov_base, iov[i].iov_len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (long)len;
|
||||||
|
}
|
||||||
SYSCALL_DEF(writev)
|
SYSCALL_DEF(writev)
|
||||||
{
|
{
|
||||||
SYSCALL_INIT(int, fd, const struct iovec *, iov, int, iovcnt);
|
SYSCALL_INIT(int, fd, const struct iovec *, iov, int, iovcnt);
|
||||||
@ -29,10 +59,13 @@ SYSCALL_DEF(writev)
|
|||||||
|
|
||||||
return (long)len;
|
return (long)len;
|
||||||
}
|
}
|
||||||
|
SYSCALL_DEF(ioctl)
|
||||||
SYSCALL_DEF(write)
|
|
||||||
{
|
{
|
||||||
SYSCALL_INIT(int, fd, void *, buffer, size_t, nbyte);
|
SYSCALL_INIT(int, fd, unsigned long, request);
|
||||||
|
|
||||||
return kernel_syscall(SYS_WRITE, fd, buffer, nbyte);
|
if(request == TIOCGWINSZ)
|
||||||
|
return !kernel_syscall(SYS_ISATTY, fd);
|
||||||
|
|
||||||
|
kernel_debug("==> IOCTL - unsupported request:%lx\n", request);
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,16 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define SYS_WRITE 0x001
|
#define SYS_DEBUG 0x3FF
|
||||||
#define SYS_BRK 0x002
|
|
||||||
#define SYS_FORK 0x003
|
#define SYS_OPEN 0x001
|
||||||
#define SYS_EXIT 0x004
|
#define SYS_CLOSE 0x002
|
||||||
#define SYS_WAIT 0x005
|
#define SYS_READ 0x003
|
||||||
#define SYS_DEBUG 0x3FF
|
#define SYS_WRITE 0x004
|
||||||
|
#define SYS_ISATTY 0x005
|
||||||
|
#define SYS_SEEK 0x006
|
||||||
|
|
||||||
|
#define SYS_BRK 0x007
|
||||||
|
|
||||||
|
#define SYS_FORK 0x008
|
||||||
|
#define SYS_EXIT 0x009
|
||||||
|
#define SYS_WAIT 0x00A
|
||||||
|
Loading…
x
Reference in New Issue
Block a user