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 /src/kernel | |
parent | 13db03fcc4a476c8881ccafe0852e72410c67b3a (diff) | |
download | kogata-2d4d64189501c253ed6a5b5ff5e27da1cb34407a.tar.gz kogata-2d4d64189501c253ed6a5b5ff5e27da1cb34407a.zip |
Think a bit ; ioctls only on open file descriptors.
Diffstat (limited to 'src/kernel')
-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 |
5 files changed, 9 insertions, 61 deletions
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) { |