diff options
author | Alex Auvolat <alex@adnab.me> | 2015-03-10 17:07:08 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2015-03-10 17:07:08 +0100 |
commit | 1b9ea946b8ec8c71a2bad9a7b2ce253145dcd97c (patch) | |
tree | 6db9ebffcd557d2e06f90b004cd1c325acc7c7f2 | |
parent | 0c710141bbb9bd62617d981a3dbaed1b8775fded (diff) | |
download | kogata-1b9ea946b8ec8c71a2bad9a7b2ce253145dcd97c.tar.gz kogata-1b9ea946b8ec8c71a2bad9a7b2ce253145dcd97c.zip |
Pass more information to FS driver on some ops (TODO bugcheck).
-rw-r--r-- | src/kernel/core/sys.c | 1 | ||||
-rw-r--r-- | src/kernel/dev/pciide.c | 18 | ||||
-rw-r--r-- | src/kernel/dev/vesa.c | 14 | ||||
-rw-r--r-- | src/kernel/fs/iso9660.c | 14 | ||||
-rw-r--r-- | src/kernel/include/vfs.h | 12 | ||||
-rw-r--r-- | src/kernel/user/ipc.c | 25 | ||||
-rw-r--r-- | src/kernel/user/nullfs.c | 75 | ||||
-rw-r--r-- | src/kernel/user/vfs.c | 14 | ||||
-rwxr-xr-x | src/tests/utests/run_qemu_test.sh | 2 |
9 files changed, 91 insertions, 84 deletions
diff --git a/src/kernel/core/sys.c b/src/kernel/core/sys.c index fceada7..8be6c7f 100644 --- a/src/kernel/core/sys.c +++ b/src/kernel/core/sys.c @@ -1,5 +1,6 @@ #include <sys.h> #include <dbglog.h> +#include <thread.h> // Kernel panic and kernel assert failure diff --git a/src/kernel/dev/pciide.c b/src/kernel/dev/pciide.c index 5abc148..9a78315 100644 --- a/src/kernel/dev/pciide.c +++ b/src/kernel/dev/pciide.c @@ -656,12 +656,12 @@ typedef struct { uint8_t type; } ide_vfs_dev_t; -bool ide_vfs_open(fs_node_ptr n, int mode); -bool ide_vfs_stat(fs_node_ptr n, stat_t *st); +bool ide_vfs_open(fs_node_t *n, int mode); +bool ide_vfs_stat(fs_node_t *n, stat_t *st); size_t ide_vfs_read(fs_handle_t *f, size_t offset, size_t len, char* buf); size_t ide_vfs_write(fs_handle_t *f, size_t offset, size_t len, const char* buf); -int ide_vfs_ioctl(fs_node_ptr f, int command, void* data); +int ide_vfs_ioctl(fs_handle_t *f, int command, void* data); void ide_vfs_close(fs_handle_t *f); fs_node_ops_t ide_vfs_node_ops = { @@ -707,8 +707,8 @@ void ide_register_device(ide_controller_t *c, uint8_t device, fs_t *iofs) { } } -bool ide_vfs_open(fs_node_ptr n, int mode) { - ide_vfs_dev_t *d = (ide_vfs_dev_t*)n; +bool ide_vfs_open(fs_node_t *n, int mode) { + ide_vfs_dev_t *d = (ide_vfs_dev_t*)n->data; int ok_modes = (FM_READ | (d->type == IDE_ATA ? FM_WRITE : 0) @@ -718,8 +718,8 @@ bool ide_vfs_open(fs_node_ptr n, int mode) { return true; } -bool ide_vfs_stat(fs_node_ptr n, stat_t *st) { - ide_vfs_dev_t *d = (ide_vfs_dev_t*)n; +bool ide_vfs_stat(fs_node_t *n, stat_t *st) { + ide_vfs_dev_t *d = (ide_vfs_dev_t*)n->data; st->type = FT_BLOCKDEV | FT_DEV; st->access = (d->type == IDE_ATA ? FM_WRITE : 0) | FM_READ | FM_IOCTL; @@ -752,8 +752,8 @@ uint8_t err = ide_write_sectors(d->c, d->device, return len; } -int ide_vfs_ioctl(fs_node_ptr f, int command, void* data) { - ide_vfs_dev_t *d = (ide_vfs_dev_t*)f; +int ide_vfs_ioctl(fs_handle_t *h, int command, void* data) { + ide_vfs_dev_t *d = (ide_vfs_dev_t*)h->node->data; int ret = 0; diff --git a/src/kernel/dev/vesa.c b/src/kernel/dev/vesa.c index 645a649..f1a87d8 100644 --- a/src/kernel/dev/vesa.c +++ b/src/kernel/dev/vesa.c @@ -214,10 +214,10 @@ typedef struct { // ---- VESA code -bool vesa_open(fs_node_ptr n, int mode); +bool vesa_open(fs_node_t *n, int mode); void vesa_close(fs_handle_t *f); -int vesa_ioctl(fs_node_ptr n, int command, void* data); -bool vesa_stat(fs_node_ptr n, stat_t *st); +int vesa_ioctl(fs_handle_t *n, int command, void* data); +bool vesa_stat(fs_node_t *n, stat_t *st); void vesa_init_driver(fs_t *iofs, vesa_mode_t *mode_data, int nmodes); void vesa_clear(vesa_driver_t *d); @@ -354,7 +354,7 @@ fail_setup: if (mode_data) free(mode_data); } -bool vesa_open(fs_node_ptr n, int mode) { +bool vesa_open(fs_node_t *n, int mode) { int ok_modes = FM_READ | FM_WRITE | FM_MMAP; if (mode & ~ok_modes) return false; @@ -365,13 +365,13 @@ void vesa_close(fs_handle_t *f) { // nothing to do } -int vesa_ioctl(fs_node_ptr n, int command, void* data) { +int vesa_ioctl(fs_handle_t *h, int command, void* data) { // TODO return 0; } -bool vesa_stat(fs_node_ptr n, stat_t *st) { - vesa_driver_t *d = (vesa_driver_t*)d; +bool vesa_stat(fs_node_t *n, stat_t *st) { + vesa_driver_t *d = (vesa_driver_t*)n->data; framebuffer_info_t *i = (d->current_mode == -1 ? 0 : &d->modes[d->current_mode].info); diff --git a/src/kernel/fs/iso9660.c b/src/kernel/fs/iso9660.c index 9fd8d0b..4c1bdd2 100644 --- a/src/kernel/fs/iso9660.c +++ b/src/kernel/fs/iso9660.c @@ -6,15 +6,15 @@ bool iso9660_make(fs_handle_t *source, const char* opts, fs_t *t); void iso9660_fs_shutdown(fs_ptr f); -bool iso9660_node_stat(fs_node_ptr n, stat_t *st); +bool iso9660_node_stat(fs_node_t *n, stat_t *st); void iso9660_node_dispose(fs_node_t *n); void iso9660_node_close(fs_handle_t *h); -bool iso9660_dir_open(fs_node_ptr n, int mode); +bool iso9660_dir_open(fs_node_t *n, int mode); bool iso9660_dir_walk(fs_node_t* n, const char* file, struct fs_node *node_d); bool iso9660_dir_readdir(fs_handle_t *h, size_t ent_no, dirent_t *d); -bool iso9660_file_open(fs_node_ptr n, int mode); +bool iso9660_file_open(fs_node_t *n, int mode); size_t iso9660_node_read(fs_node_t *n, size_t offset, size_t len, char* buf); @@ -156,8 +156,8 @@ static void dr_stat(iso9660_dr_t *dr, stat_t *st) { // ---- The actual code -bool iso9660_node_stat(fs_node_ptr n, stat_t *st) { - iso9660_node_t *node = (iso9660_node_t*)n; +bool iso9660_node_stat(fs_node_t *n, stat_t *st) { + iso9660_node_t *node = (iso9660_node_t*)n->data; dr_stat(&node->dr, st); return true; @@ -175,7 +175,7 @@ void iso9660_node_close(fs_handle_t *h) { // nothing to do } -bool iso9660_dir_open(fs_node_ptr n, int mode) { +bool iso9660_dir_open(fs_node_t *n, int mode) { if (mode != FM_READDIR) return false; return true; @@ -238,7 +238,7 @@ bool iso9660_dir_walk(fs_node_t *n, const char* search_for, struct fs_node *node return false; // not found } -bool iso9660_file_open(fs_node_ptr n, int mode) { +bool iso9660_file_open(fs_node_t *n, int mode) { int ok_modes = FM_READ | FM_MMAP; if (mode & ~ok_modes) return false; diff --git a/src/kernel/include/vfs.h b/src/kernel/include/vfs.h index 888c0bc..be35726 100644 --- a/src/kernel/include/vfs.h +++ b/src/kernel/include/vfs.h @@ -80,20 +80,20 @@ typedef struct fs_handle { // - delete() is not expected to delete recursively : it should fail on a non-empty directory typedef struct fs_node_ops { - bool (*open)(fs_node_ptr n, int mode); + bool (*open)(fs_node_t *n, int mode); size_t (*read)(fs_handle_t *h, size_t offset, size_t len, char* buf); size_t (*write)(fs_handle_t *h, size_t offset, size_t len, const char* buf); bool (*readdir)(fs_handle_t *h, size_t ent_no, dirent_t *d); int (*poll)(fs_handle_t *h, void** out_wait_obj); void (*close)(fs_handle_t *h); - bool (*stat)(fs_node_ptr n, stat_t *st); - int (*ioctl)(fs_node_ptr n, int command, void* data); + bool (*stat)(fs_node_t *n, stat_t *st); + int (*ioctl)(fs_handle_t *h, int command, void* data); bool (*walk)(fs_node_t *n, const char* file, struct fs_node *node_d); - bool (*delete)(fs_node_ptr n, const char* file); - bool (*move)(fs_node_ptr n, 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 + bool (*delete)(fs_node_t *n, const char* file); + bool (*move)(fs_node_t *n, const char* old_name, struct fs_node *new_parent, const char *new_name); + bool (*create)(fs_node_t *n, const char* name, int type); // create sub-node in directory void (*dispose)(fs_node_t *n); } fs_node_ops_t; diff --git a/src/kernel/user/ipc.c b/src/kernel/user/ipc.c index e565082..9149663 100644 --- a/src/kernel/user/ipc.c +++ b/src/kernel/user/ipc.c @@ -12,8 +12,8 @@ static size_t channel_read(fs_handle_t *c, size_t offset, size_t len, char* buf); static size_t channel_write(fs_handle_t *c, size_t offset, size_t len, const char* buf); static int channel_poll(fs_handle_t *c, void** out_wait_obj); -static bool channel_open(fs_node_ptr c, int mode); -static bool channel_stat(fs_node_ptr c, stat_t *st); +static bool channel_open(fs_node_t *c, int mode); +static bool channel_stat(fs_node_t *c, stat_t *st); static void channel_close(fs_handle_t *c); static void channel_dispose(fs_node_t *c); @@ -189,15 +189,15 @@ int channel_poll(fs_handle_t *h, void** out_wait_obj) { return ret; } -bool channel_open(fs_node_ptr ch, int mode) { +bool channel_open(fs_node_t *ch, int mode) { int ok_modes = FM_READ | FM_WRITE | FM_BLOCKING; if (mode & ~ok_modes) return false; return true; } -bool channel_stat(fs_node_ptr ch, stat_t *st) { - channel_t *c = (channel_t*)ch; +bool channel_stat(fs_node_t *ch, stat_t *st) { + channel_t *c = (channel_t*)ch->data; mutex_lock(&c->lock); @@ -231,9 +231,9 @@ void channel_dispose(fs_node_t *n) { // ---- Shared memory // ---- ------ ------ -bool shm_open(fs_node_ptr n, int mode); +bool shm_open(fs_node_t *n, int mode); void shm_close(fs_handle_t *h); -bool shm_stat(fs_node_ptr n, stat_t *st); +bool shm_stat(fs_node_t *n, stat_t *st); void shm_dispose(fs_node_t *n); fs_node_ops_t shm_ops = { @@ -285,7 +285,7 @@ error: return 0; } -bool shm_open(fs_node_ptr n, int mode) { +bool shm_open(fs_node_t *n, int mode) { int ok_modes = FM_READ | FM_WRITE | FM_MMAP; if (mode & ~ok_modes) return false; @@ -296,9 +296,12 @@ void shm_close(fs_handle_t *h) { // nothing to do } -bool shm_stat(fs_node_ptr n, stat_t *st) { - // TODO - return false; +bool shm_stat(fs_node_t *n, stat_t *st) { + st->size = n->pager->size; + st->type = FT_REGULAR; + st->access = FM_READ | FM_WRITE | FM_MMAP; + + return true; } void shm_dispose(fs_node_t *n) { diff --git a/src/kernel/user/nullfs.c b/src/kernel/user/nullfs.c index 636d7fa..17a93d2 100644 --- a/src/kernel/user/nullfs.c +++ b/src/kernel/user/nullfs.c @@ -7,29 +7,29 @@ #include <pager.h> // nullfs driver -static bool nullfs_fs_make(fs_handle_t *source, const char* opts, fs_t *d); +bool nullfs_fs_make(fs_handle_t *source, const char* opts, fs_t *d); // nullfs fs_t -static void nullfs_fs_shutdown(fs_ptr fs); +void nullfs_fs_shutdown(fs_ptr fs); // nullfs directory node -static bool nullfs_d_open(fs_node_ptr n, int mode); -static bool nullfs_d_stat(fs_node_ptr n, stat_t *st); -static bool nullfs_d_walk(fs_node_t *n, const char* file, struct fs_node *node_d); -static bool nullfs_d_delete(fs_node_ptr n, const char* file); -static bool nullfs_d_move(fs_node_ptr n, const char* old_name, fs_node_t *new_parent, const char *new_name); -static bool nullfs_d_create(fs_node_ptr n, const char* file, int type); -static void nullfs_d_dispose(fs_node_t *n); -static bool nullfs_d_readdir(fs_handle_t *f, size_t ent_no, dirent_t *d); -static void nullfs_d_close(fs_handle_t *f); +bool nullfs_d_open(fs_node_t *n, int mode); +bool nullfs_d_stat(fs_node_t *n, stat_t *st); +bool nullfs_d_walk(fs_node_t *n, const char* file, struct fs_node *node_d); +bool nullfs_d_delete(fs_node_t *n, const char* file); +bool nullfs_d_move(fs_node_t *n, const char* old_name, fs_node_t *new_parent, const char *new_name); +bool nullfs_d_create(fs_node_t *n, const char* file, int type); +void nullfs_d_dispose(fs_node_t *n); +bool nullfs_d_readdir(fs_handle_t *f, size_t ent_no, dirent_t *d); +void nullfs_d_close(fs_handle_t *f); // nullfs ram file node -static bool nullfs_f_open(fs_node_ptr n, int mode); -static bool nullfs_f_stat(fs_node_ptr n, stat_t *st); -static void nullfs_f_dispose(fs_node_t *n); -static size_t nullfs_f_read(fs_handle_t *f, size_t offset, size_t len, char* buf); -static size_t nullfs_f_write(fs_handle_t *f, size_t offset, size_t len, const char* buf); -static void nullfs_f_close(fs_handle_t *f); +bool nullfs_f_open(fs_node_t *n, int mode); +bool nullfs_f_stat(fs_node_t *n, stat_t *st); +void nullfs_f_dispose(fs_node_t *n); +size_t nullfs_f_read(fs_handle_t *f, size_t offset, size_t len, char* buf); +size_t nullfs_f_write(fs_handle_t *f, size_t offset, size_t len, const char* buf); +void nullfs_f_close(fs_handle_t *f); // VTables that go with it static fs_driver_ops_t nullfs_driver_ops = { @@ -226,14 +226,14 @@ error: // -- Directory node -- -bool nullfs_d_open(fs_node_ptr n, int mode) { +bool nullfs_d_open(fs_node_t *n, int mode) { if (mode != FM_READDIR) return false; return true; } -bool nullfs_d_stat(fs_node_ptr n, stat_t *st) { - nullfs_dir_t* d = (nullfs_dir_t*)n; +bool nullfs_d_stat(fs_node_t *n, stat_t *st) { + nullfs_dir_t* d = (nullfs_dir_t*)n->data; mutex_lock(&d->lock); @@ -270,8 +270,8 @@ bool nullfs_d_walk(fs_node_t *n, const char* file, struct fs_node *node_d) { return true; } -bool nullfs_d_delete(fs_node_ptr n, const char* file) { - nullfs_dir_t* d = (nullfs_dir_t*)n; +bool nullfs_d_delete(fs_node_t *n, const char* file) { + nullfs_dir_t* d = (nullfs_dir_t*)n->data; mutex_lock(&d->lock); @@ -321,14 +321,14 @@ error: return false; } -bool nullfs_d_move(fs_node_ptr n, const char* old_name, fs_node_t *new_parent, const char *new_name) { +bool nullfs_d_move(fs_node_t *n, const char* old_name, fs_node_t *new_parent, const char *new_name) { dbg_printf("Not implemented: move in nullfs. Failing potentially valid move request.\n"); return false; //TODO } -bool nullfs_d_create(fs_node_ptr n, const char* file, int type) { - nullfs_dir_t *d = (nullfs_dir_t*)n; +bool nullfs_d_create(fs_node_t *n, const char* file, int type) { + nullfs_dir_t *d = (nullfs_dir_t*)n->data; nullfs_item_t *i = 0; if (type == FT_REGULAR) { @@ -434,12 +434,15 @@ bool nullfs_d_readdir(fs_handle_t *f, size_t ent_no, dirent_t *d) { strncpy(d->name, i->name, DIR_MAX); d->name[DIR_MAX-1] = 0; - if (i->ops->stat) { - i->ops->stat(i->data, &d->st); - } else { - // no stat operation : should we do something else ? - memset(&d->st, 0, sizeof(stat_t)); - } + + // dirty hack so that we can stat (TODO do this better) + fs_node_t n; + memset(&n, 0, sizeof(fs_node_t)); + n.fs = f->node->fs; + n.ops = i->ops; + n.data = i->data; + n.pager = i->pager; + n.ops->stat(&n, &d->st); break; } @@ -457,8 +460,8 @@ void nullfs_d_close(fs_handle_t *f) { // -- File node -- -bool nullfs_f_open(fs_node_ptr n, int mode) { - nullfs_file_t *f = (nullfs_file_t*)n; +bool nullfs_f_open(fs_node_t *n, int mode) { + nullfs_file_t *f = (nullfs_file_t*)n->data; if (mode & ~f->ok_modes) return false; @@ -474,8 +477,8 @@ bool nullfs_f_open(fs_node_ptr n, int mode) { return true; } -bool nullfs_f_stat(fs_node_ptr n, stat_t *st) { - nullfs_file_t *f = (nullfs_file_t*)n; +bool nullfs_f_stat(fs_node_t *n, stat_t *st) { + nullfs_file_t *f = (nullfs_file_t*)n->data; mutex_lock(&f->lock); st->type = FT_REGULAR; @@ -492,7 +495,7 @@ void nullfs_f_dispose(fs_node_t *n) { // -- File handle -- -static void nullfs_f_close(fs_handle_t *h) { +void nullfs_f_close(fs_handle_t *h) { // nothing to do } diff --git a/src/kernel/user/vfs.c b/src/kernel/user/vfs.c index 66ede94..6df0a25 100644 --- a/src/kernel/user/vfs.c +++ b/src/kernel/user/vfs.c @@ -303,7 +303,7 @@ bool fs_create(fs_t *fs, const char* file, int type) { if (n == 0) return false; mutex_lock(&n->lock); - bool ret = n->ops->create && n->ops->create(n->data, name, type); + bool ret = n->ops->create && n->ops->create(n, name, type); mutex_unlock(&n->lock); unref_fs_node(n); @@ -324,7 +324,7 @@ bool fs_delete(fs_t *fs, const char* file) { } mutex_lock(&n->lock); - bool ret = n->ops->delete && n->ops->delete(n->data, name); + bool ret = n->ops->delete && n->ops->delete(n, name); mutex_unlock(&n->lock); unref_fs_node(n); @@ -366,7 +366,7 @@ bool fs_move(fs_t *fs, const char* from, const char* to) { goto unlock_end; } - ret = old_parent->ops->move(old_parent->data, old_name, new_parent, new_name); + ret = old_parent->ops->move(old_parent, old_name, new_parent, new_name); if (ret) { // adjust node parameters @@ -399,7 +399,7 @@ bool fs_stat(fs_t *fs, const char* file, stat_t *st) { if (n == 0) return false; mutex_lock(&n->lock); - bool ret = n->ops->stat && n->ops->stat(n->data, st); + bool ret = n->ops->stat && n->ops->stat(n, st); mutex_unlock(&n->lock); unref_fs_node(n); @@ -428,7 +428,7 @@ fs_handle_t* fs_open(fs_t *fs, const char* file, int mode) { fs_handle_t *h = (fs_handle_t*)malloc(sizeof(fs_handle_t)); if (h == 0) goto error; - bool open_ok = n->ops->open(n->data, mode); + bool open_ok = n->ops->open(n, mode); if (!open_ok) goto error; h->refs = 1; @@ -483,7 +483,7 @@ size_t file_write(fs_handle_t *f, size_t offset, size_t len, const char* buf) { } bool file_stat(fs_handle_t *f, stat_t *st) { - return f->node->ops->stat && f->node->ops->stat(f->node->data, st); + return f->node->ops->stat && f->node->ops->stat(f->node, st); } int file_ioctl(fs_handle_t *f, int command, void* data) { @@ -491,7 +491,7 @@ int file_ioctl(fs_handle_t *f, int command, void* data) { if (f->node->ops->ioctl == 0) return -1; - return f->node->ops->ioctl(f->node->data, command, data); + return f->node->ops->ioctl(f, command, data); } bool file_readdir(fs_handle_t *f, size_t ent_no, dirent_t *d) { diff --git a/src/tests/utests/run_qemu_test.sh b/src/tests/utests/run_qemu_test.sh index 4d8bc6b..2de4bbb 100755 --- a/src/tests/utests/run_qemu_test.sh +++ b/src/tests/utests/run_qemu_test.sh @@ -1,6 +1,6 @@ #!/bin/bash -if [ $1 = 'watchdog' ]; then +if [ "$1" = "watchdog" ]; then sleep 3 & PID=$! echo $PID > pid2 |