From e356371f09df87ebab2d7e3d816de1147768dfa9 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Mon, 2 Mar 2015 23:02:59 +0100 Subject: Change VFS interface : handles no longer visible to underlying FS. --- src/kernel/user/vfs.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) (limited to 'src/kernel/user/vfs.c') diff --git a/src/kernel/user/vfs.c b/src/kernel/user/vfs.c index 710326a..a02dc9b 100644 --- a/src/kernel/user/vfs.c +++ b/src/kernel/user/vfs.c @@ -420,12 +420,13 @@ 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); + if (!open_ok) goto error; + h->refs = 1; h->fs = fs; h->node = n; - - bool open_ok = n->ops->open(n->data, mode, h); - if (!open_ok) goto error; + h->mode = mode; // our reference to node n is transferred to the file handle mutex_unlock(&n->lock); @@ -446,7 +447,7 @@ void ref_file(fs_handle_t *file) { void unref_file(fs_handle_t *file) { file->refs--; if (file->refs == 0) { - file->ops->close(file->data); + file->node->ops->close(file->node->data); unref_fs_node(file->node); unref_fs(file->fs); free(file); @@ -460,17 +461,17 @@ int file_get_mode(fs_handle_t *f) { size_t file_read(fs_handle_t *f, size_t offset, size_t len, char* buf) { if (!(f->mode & FM_READ)) return 0; - if (f->ops->read == 0) return 0; + if (f->node->ops->read == 0) return 0; - return f->ops->read(f->data, offset, len, buf); + return f->node->ops->read(f->node->data, offset, len, buf); } size_t file_write(fs_handle_t *f, size_t offset, size_t len, const char* buf) { if (!(f->mode & FM_WRITE)) return 0; - if (f->ops->write == 0) return 0; + if (f->node->ops->write == 0) return 0; - return f->ops->write(f->data, offset, len, buf); + return f->node->ops->write(f->node->data, offset, len, buf); } bool file_stat(fs_handle_t *f, stat_t *st) { @@ -480,27 +481,15 @@ 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; - if (f->ops->ioctl == 0) return -1; + if (f->node->ops->ioctl == 0) return -1; - return f->ops->ioctl(f->data, command, data); + return f->node->ops->ioctl(f->node->data, command, data); } -bool file_readdir(fs_handle_t *f, dirent_t *d) { +bool file_readdir(fs_handle_t *f, size_t ent_no, dirent_t *d) { if (!(f->mode & FM_READDIR)) return 0; - return f->ops->readdir && f->ops->readdir(f->data, d); -} - -uint32_t file_get_page(fs_handle_t *f, size_t offset) { - if (!(f->mode & FM_MMAP)) return 0; - ASSERT(f->ops->get_page != 0); - return f->ops->get_page(f->data, offset); -} - -void file_commit_page(fs_handle_t *f, size_t offset, uint64_t time) { - if (!(f->mode & FM_MMAP)) return; - ASSERT(f->ops->commit_page != 0); - f->ops->commit_page(f->data, offset, time); + return f->node->ops->readdir && f->node->ops->readdir(f->node->data, ent_no, d); } /* vim: set ts=4 sw=4 tw=0 noet :*/ -- cgit v1.2.3