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 /src/kernel/user | |
parent | 0c710141bbb9bd62617d981a3dbaed1b8775fded (diff) | |
download | kogata-1b9ea946b8ec8c71a2bad9a7b2ce253145dcd97c.tar.gz kogata-1b9ea946b8ec8c71a2bad9a7b2ce253145dcd97c.zip |
Pass more information to FS driver on some ops (TODO bugcheck).
Diffstat (limited to 'src/kernel/user')
-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 |
3 files changed, 60 insertions, 54 deletions
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) { |