diff options
author | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-20 15:00:51 +0100 |
---|---|---|
committer | Alex Auvolat <alex.auvolat@ens.fr> | 2015-02-20 15:00:51 +0100 |
commit | 2d4d64189501c253ed6a5b5ff5e27da1cb34407a (patch) | |
tree | 488ed008de322f0ffbfd1efdaec2041811b41a1c | |
parent | 13db03fcc4a476c8881ccafe0852e72410c67b3a (diff) | |
download | kogata-2d4d64189501c253ed6a5b5ff5e27da1cb34407a.tar.gz kogata-2d4d64189501c253ed6a5b5ff5e27da1cb34407a.zip |
Think a bit ; ioctls only on open file descriptors.
-rw-r--r-- | README.md | 8 | ||||
-rw-r--r-- | src/common/include/mmap.h | 1 | ||||
-rw-r--r-- | src/common/include/syscallproto.h | 8 | ||||
-rw-r--r-- | src/kernel/core/kmain.c | 17 | ||||
-rw-r--r-- | src/kernel/include/vfs.h | 3 | ||||
-rw-r--r-- | src/kernel/user/nullfs.c | 4 | ||||
-rw-r--r-- | src/kernel/user/syscall.c | 29 | ||||
-rw-r--r-- | src/kernel/user/vfs.c | 17 | ||||
-rw-r--r-- | src/lib/include/syscall.h | 3 | ||||
-rw-r--r-- | src/lib/libkogata/syscall.c | 7 |
10 files changed, 22 insertions, 75 deletions
@@ -88,17 +88,19 @@ running the tests): ### Plans for soon -* Implement syscalls +* Implement missing syscalls * Write device drivers : VGA, keyboard, ATA, FAT, VESA ### Things to design +* Cache architecture +* IPC * How does a process exit, what does it do, how do processes synchronize ? -* Timers, workers, sleeping * Have several threads in a single process * Better handling of errors (rather than panicing) ; userspace apps should not have the possibility of crashing the system -* How does a process transmit information (such as environment or arguments) to its children ? +* How does a process transmit information (such as environment, arguments, file + descriptors) to its children ? ### Things not sure diff --git a/src/common/include/mmap.h b/src/common/include/mmap.h index 777950f..3134403 100644 --- a/src/common/include/mmap.h +++ b/src/common/include/mmap.h @@ -4,3 +4,4 @@ #define MM_WRITE (0x02) #define MM_EXEC (0x04) +/* vim: set ts=4 sw=4 tw=0 noet :*/ diff --git a/src/common/include/syscallproto.h b/src/common/include/syscallproto.h index fd56017..6f0418e 100644 --- a/src/common/include/syscallproto.h +++ b/src/common/include/syscallproto.h @@ -17,7 +17,6 @@ #define SC_DELETE 21 // args: file, file_strlen #define SC_MOVE 22 // args: old_file, old_file_strlen, new_file, new_file_strlen #define SC_STAT 23 // args: file, file_strlen, out stat_t* data -#define SC_IOCTL 24 // args: file, file_strlen, command, out void* data #define SC_OPEN 30 // args: file, file_strlen, mode #define SC_CLOSE 31 // args: fd @@ -25,7 +24,7 @@ #define SC_WRITE 33 // args: fd, offset, size, data #define SC_READDIR 34 // args: fd, out dirent_t *data #define SC_STAT_OPEN 35 // args: fd, out stat_t *data -- stat on open file handle -#define SC_IOCTL_OPEN 36 // args: fd, command, out void* data +#define SC_IOCTL 36 // args: fd, command, out void* data #define SC_GET_MODE 37 // args: fd -- get mode for open file handle #define SC_MAKE_FS 40 @@ -33,8 +32,9 @@ #define SC_RM_FS 42 #define SC_NEW_PROC 50 -#define SC_BIND_FS 51 // bind FS to children process -#define SC_PROC_EXEC 52 // execute binary in process +#define SC_BIND_FS 51 // bind FS to child process +#define SC_BIND_FD 52 // copy a file descriptor to child process +#define SC_PROC_EXEC 53 // execute binary in process // much more to do diff --git a/src/kernel/core/kmain.c b/src/kernel/core/kmain.c index 12c813e..219bab1 100644 --- a/src/kernel/core/kmain.c +++ b/src/kernel/core/kmain.c @@ -165,14 +165,6 @@ void kernel_init_stage2(void* data) { dbg_printf("Adding module to VFS: '%s' (size %d)\n", name, len); - /* - // This would be the "good" way of doing it : - fs_handle_t* mod_f = fs_open(devfs, name, FM_WRITE | FM_CREATE); - ASSERT(mod_f != 0); - ASSERT(file_write(mod_f, 0, len, (char*)mods[i].mod_start) == len); - unref_file(mod_f); - */ - // But since we have a nullfs, we can do it that way to prevent useless data copies : ASSERT(nullfs_add_ram_file(devfs, name, (char*)mods[i].mod_start, len, false, FM_READ | FM_MMAP)); @@ -180,6 +172,7 @@ void kernel_init_stage2(void* data) { TEST_PLACEHOLDER_AFTER_DEVFS; + // Launch INIT fs_handle_t *init_bin = fs_open(devfs, "/mod/init.bin", FM_READ | FM_MMAP); if (init_bin == 0) PANIC("No init.bin module provided!"); if (!is_elf(init_bin)) PANIC("init.bin is not valid ELF32 binary"); @@ -197,13 +190,7 @@ void kernel_init_stage2(void* data) { start_process(init_p, e); - //TODO : - // - (OK) populate devfs with information regarding kernel command line & modules - // - create user process with init module provided on command line - // - give it rights to devfs - // - launch it - // - just return, this thread is done - + // We are done here dbg_printf("Reached kmain end! I'll just stop here and do nothing.\n"); } diff --git a/src/kernel/include/vfs.h b/src/kernel/include/vfs.h index c5777a2..cca4952 100644 --- a/src/kernel/include/vfs.h +++ b/src/kernel/include/vfs.h @@ -48,6 +48,7 @@ typedef struct { size_t (*read)(fs_handle_ptr f, size_t offset, size_t len, char* buf); size_t (*write)(fs_handle_ptr f, size_t offset, size_t len, const char* buf); bool (*readdir)(fs_handle_ptr f, dirent_t *d); + int (*ioctl)(fs_handle_ptr f, int command, void* data); void (*close)(fs_handle_ptr f); } fs_handle_ops_t; @@ -88,7 +89,6 @@ typedef struct { bool (*delete)(fs_node_ptr n, const char* file); bool (*move)(fs_node_ptr dir, const char* old_name, struct fs_node *new_parent, const char *new_name); bool (*create)(fs_node_ptr n, const char* name, int type); // create sub-node in directory - int (*ioctl)(fs_node_ptr n, int command, void* data); void (*dispose)(fs_node_ptr n); } fs_node_ops_t; @@ -161,7 +161,6 @@ bool fs_create(fs_t *fs, const char* file, int type); bool fs_delete(fs_t *fs, const char* file); bool fs_move(fs_t *fs, const char* from, const char* to); bool fs_stat(fs_t *fs, const char* file, stat_t *st); -int fs_ioctl(fs_t *fs, const char* file, int command, void* data); fs_handle_t* fs_open(fs_t *fs, const char* file, int mode); void ref_file(fs_handle_t *file); diff --git a/src/kernel/user/nullfs.c b/src/kernel/user/nullfs.c index c3f83cf..0ca0073 100644 --- a/src/kernel/user/nullfs.c +++ b/src/kernel/user/nullfs.c @@ -53,7 +53,6 @@ static fs_node_ops_t nullfs_d_ops = { .move = nullfs_d_move, .create = nullfs_d_create, .dispose = nullfs_d_dispose, - .ioctl = 0, }; static fs_handle_ops_t nullfs_dh_ops = { @@ -61,6 +60,7 @@ static fs_handle_ops_t nullfs_dh_ops = { .close = nullfs_dh_close, .read = 0, .write = 0, + .ioctl = 0, }; static fs_node_ops_t nullfs_f_ops = { @@ -71,7 +71,6 @@ static fs_node_ops_t nullfs_f_ops = { .create = 0, .delete = 0, .move = 0, - .ioctl =0, }; static fs_handle_ops_t nullfs_fh_ops = { @@ -79,6 +78,7 @@ static fs_handle_ops_t nullfs_fh_ops = { .write = nullfs_fh_write, .close = nullfs_fh_close, .readdir = 0, + .ioctl =0, }; diff --git a/src/kernel/user/syscall.c b/src/kernel/user/syscall.c index f1f5f86..bcf6ef4 100644 --- a/src/kernel/user/syscall.c +++ b/src/kernel/user/syscall.c @@ -175,30 +175,6 @@ end_stat: return ret; } -static uint32_t ioctl_sc(sc_args_t args) { - int ret = -1; - - char* fn = sc_copy_string(args.a, args.b); - if (fn == 0) goto end_ioctl; - - char* sep = strchr(fn, ':'); - if (sep == 0) goto end_ioctl; - - *sep = 0; - char* file = sep + 1; - - fs_t *fs = proc_find_fs(current_process(), fn); - if (fs == 0) goto end_ioctl; - - void* data = (void*)args.d; - if (data >= (void*)K_HIGHHALF_ADDR) goto end_ioctl; - ret = fs_ioctl(fs, file, args.c, data); - -end_ioctl: - if (fn) free(fn); - return ret; -} - static uint32_t open_sc(sc_args_t args) { int ret = 0; @@ -268,7 +244,7 @@ static uint32_t stat_open_sc(sc_args_t args) { return file_stat(h, o); } -static uint32_t ioctl_open_sc(sc_args_t args) { +static uint32_t ioctl_sc(sc_args_t args) { fs_handle_t *h = proc_read_fd(current_process(), args.a); if (h == 0) return -1; @@ -303,7 +279,6 @@ void setup_syscall_table() { sc_handlers[SC_DELETE] = delete_sc; sc_handlers[SC_MOVE] = move_sc; sc_handlers[SC_STAT] = stat_sc; - sc_handlers[SC_IOCTL] = ioctl_sc; sc_handlers[SC_OPEN] = open_sc; sc_handlers[SC_CLOSE] = close_sc; @@ -311,7 +286,7 @@ void setup_syscall_table() { sc_handlers[SC_WRITE] = write_sc; sc_handlers[SC_READDIR] = readdir_sc; sc_handlers[SC_STAT_OPEN] = stat_open_sc; - sc_handlers[SC_IOCTL_OPEN] = ioctl_open_sc; + sc_handlers[SC_IOCTL] = ioctl_sc; sc_handlers[SC_GET_MODE] = get_mode_sc; } diff --git a/src/kernel/user/vfs.c b/src/kernel/user/vfs.c index 31f162a..a5f03ca 100644 --- a/src/kernel/user/vfs.c +++ b/src/kernel/user/vfs.c @@ -354,18 +354,6 @@ bool fs_stat(fs_t *fs, const char* file, stat_t *st) { return ret; } -int fs_ioctl(fs_t *fs, const char* file, int command, void* data) { - fs_node_t* n = fs_walk_path(&fs->root, file); - if (n == 0) return -1; - - mutex_lock(&n->lock); - int ret = (n->ops->ioctl ? n->ops->ioctl(n->data, command, data) : -1); - mutex_unlock(&n->lock); - - unref_fs_node(n); - return ret; -} - // =================== // // OPERATIONS ON FILES // // =================== // @@ -446,10 +434,9 @@ bool file_stat(fs_handle_t *f, stat_t *st) { int file_ioctl(fs_handle_t *f, int command, void* data) { if (!(f->mode & FM_IOCTL)) return -1; - int ret = -1; - if (f->node->ops->ioctl) ret = f->node->ops->ioctl(f->node->data, command, data); + if (f->ops->ioctl == 0) return -1; - return ret; + return f->ops->ioctl(f->data, command, data); } bool file_readdir(fs_handle_t *f, dirent_t *d) { diff --git a/src/lib/include/syscall.h b/src/lib/include/syscall.h index fb82c33..991b081 100644 --- a/src/lib/include/syscall.h +++ b/src/lib/include/syscall.h @@ -26,7 +26,6 @@ bool create(const char* name, int type); bool delete(const char* name); bool move(const char* oldname, const char* newname); bool stat(const char* name, stat_t *s); -int ioctl(const char* filename, int command, void* data); fd_t open(const char* name, int mode); void close(fd_t file); @@ -34,7 +33,7 @@ size_t read(fd_t file, size_t offset, size_t len, char *buf); size_t write(fd_t file, size_t offset, size_t len, const char* buf); bool readdir(fd_t file, dirent_t *d); bool stat_open(fd_t file, stat_t *s); -int ioctl_open(fd_t file, int command, void* data); +int ioctl(fd_t file, int command, void* data); int get_mode(fd_t file); // more todo diff --git a/src/lib/libkogata/syscall.c b/src/lib/libkogata/syscall.c index afda7c7..52e320c 100644 --- a/src/lib/libkogata/syscall.c +++ b/src/lib/libkogata/syscall.c @@ -64,9 +64,6 @@ bool move(const char* oldname, const char* newname) { bool stat(const char* name, stat_t *s) { return call(SC_STAT, (uint32_t)name, strlen(name), (uint32_t)s, 0, 0); } -int ioctl(const char* filename, int command, void* data) { - return call(SC_IOCTL, (uint32_t)filename, strlen(filename), command, (uint32_t)data, 0); -} fd_t open(const char* name, int mode) { return call(SC_OPEN, (uint32_t)name, strlen(name), mode, 0, 0); @@ -86,8 +83,8 @@ bool readdir(fd_t file, dirent_t *d) { bool stat_open(fd_t file, stat_t *s) { return call(SC_STAT_OPEN, file, (uint32_t)s, 0, 0, 0); } -int ioctl_open(fd_t file, int command, void* data) { - return call(SC_IOCTL_OPEN, file, command, (uint32_t)data, 0, 0); +int ioctl(fd_t file, int command, void* data) { + return call(SC_IOCTL, file, command, (uint32_t)data, 0, 0); } int get_mode(fd_t file) { return call(SC_GET_MODE, file, 0, 0, 0, 0); |