From 5de93f707c8ac8931b2e5668f4431f88d8443821 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Fri, 15 Feb 2008 12:22:07 +0000 Subject: [PATCH] Fixed lookup return value. Now using generic_lookup directy, i.e. not through a vnode, because it really isn't fs-specific. --- tasks/fs0/main.c | 6 ++++++ tasks/fs0/src/lookup.c | 4 ++-- tasks/fs0/src/memfs/vnode.c | 11 ++++++----- tasks/fs0/src/syscalls.c | 31 +++++++++++++++++-------------- tasks/fs0/src/vfs.c | 14 +++++--------- 5 files changed, 36 insertions(+), 30 deletions(-) diff --git a/tasks/fs0/main.c b/tasks/fs0/main.c index 1ed7a9a..5c65904 100644 --- a/tasks/fs0/main.c +++ b/tasks/fs0/main.c @@ -27,6 +27,12 @@ * either high-level vfs code, or the mm0 page cache. * - readdir provides a posix-compliant dirent structure list in dirbuf. * - memfs dentries should be identical to posix struct dirents. + * + * ALL DONE!!! But untested. + * + * - Add mkdir + * - Add create + * - Add read/write -> This will need page cache and mm0 involvement. */ /* TODO: diff --git a/tasks/fs0/src/lookup.c b/tasks/fs0/src/lookup.c index a5e1efb..1e3c1ac 100644 --- a/tasks/fs0/src/lookup.c +++ b/tasks/fs0/src/lookup.c @@ -57,7 +57,7 @@ struct vnode *lookup_dentry_children(struct dentry *parentdir, char *path) return v; /* Out of all children dentries, neither was a match, so we return 0 */ - return 0; + return PTR_ERR(-ENOENT); } /* Lookup, recursive, assuming single-mountpoint */ @@ -68,7 +68,7 @@ struct vnode *generic_vnode_lookup(struct vnode *thisnode, char *path) struct vnode *found; int err; - /* Does this path component match with any of parent vnode's names? */ + /* Does this path component match with any of this vnode's dentries? */ list_for_each_entry(d, &thisnode->dentries, vref) { if (d->ops.compare(d, component)) { /* Is this a directory? */ diff --git a/tasks/fs0/src/memfs/vnode.c b/tasks/fs0/src/memfs/vnode.c index cf89201..06ef9bb 100644 --- a/tasks/fs0/src/memfs/vnode.c +++ b/tasks/fs0/src/memfs/vnode.c @@ -205,11 +205,13 @@ int memfs_write_vnode(struct superblock *sb, struct vnode *v) } /* - * Allocates and populates all dentries and their corresponding vnodes that are - * the direct children of vnode v. This means that by each call to readdir, the vfs - * layer increases its cache of filesystem tree by one level beneath that directory. + * Reads the vnode directory contents into vnode's buffer in a posix-compliant + * struct dirent format. * - * TODO: Returns the list of posix-compliant dirent records in the buffer. + * Reading the buffer, allocates and populates all dentries and their + * corresponding vnodes that are the direct children of vnode v. This means + * that by each call to readdir, the vfs layer increases its cache of filesystem + * tree by one level beneath that directory. */ int memfs_vnode_readdir(struct vnode *v) { @@ -278,7 +280,6 @@ int memfs_vnode_readdir(struct vnode *v) } struct vnode_ops memfs_vnode_operations = { - .lookup = generic_vnode_lookup, .readdir = memfs_vnode_readdir, }; diff --git a/tasks/fs0/src/syscalls.c b/tasks/fs0/src/syscalls.c index 5f8af4b..a8cda8f 100644 --- a/tasks/fs0/src/syscalls.c +++ b/tasks/fs0/src/syscalls.c @@ -78,15 +78,28 @@ int sys_open(l4id_t sender, const char *pathname, int flags, unsigned int mode) return do_open(sender, pathname, flags, mode); } +int sys_mkdir(l4id_t sender, const char *pathname, unsigned int mode) +{ + return 0; +} + int sys_read(l4id_t sender, int fd, void *buf, int count) { return 0; } +int sys_write(l4id_t sender, int fd, const void *buf, int count) +{ + return 0; +} + +int sys_lseek(l4id_t sender, int fd, int offset, int whence) +{ + return 0; +} + /* - * FIXME: Read count is not considered yet. Take that into account. - * FIXME: Do we pass this buf back to mm0. Do we get it from mm0??? - * Fix generic_vnode_lookup as well. + * Reads @count bytes of posix struct dirents into @buf */ int sys_readdir(l4id_t sender, int fd, void *buf, int count) { @@ -119,20 +132,10 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count) /* Do we have those bytes at hand? */ if (v->dirbuf.buffer && (v->dirbuf.npages * PAGE_SIZE) >= nbytes) { - memcpy(buf, v->dirbuf.buffer, nbytes); /* Finish the job */ + memcpy(buf, v->dirbuf.buffer, nbytes); return nbytes; } return 0; } -int sys_write(l4id_t sender, int fd, const void *buf, int count) -{ - return 0; -} - -int sys_lseek(l4id_t sender, int fd, int offset, int whence) -{ - return 0; -} - diff --git a/tasks/fs0/src/vfs.c b/tasks/fs0/src/vfs.c index 9788115..4846255 100644 --- a/tasks/fs0/src/vfs.c +++ b/tasks/fs0/src/vfs.c @@ -30,7 +30,7 @@ struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum) struct vnode *v; int err; - /* Check the vnode cache by vnum */ + /* Check the vnode flat list by vnum */ list_for_each_entry(v, &vnode_cache, cache_list) if (v->vnum == vnum) return v; @@ -53,7 +53,7 @@ struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum) return PTR_ERR(err); } - /* Add the vnode back to vnode cache */ + /* Add the vnode back to vnode flat list */ list_add(&v->cache_list, &vnode_cache); return v; @@ -70,14 +70,10 @@ struct vnode *vfs_lookup_bypath(struct superblock *sb, char *path) if (!strcmp(path, "/")) return sb->root; - /* TODO: Check the vnode cache by path component - * - * This should split the path into components and compare - * each of them with each vnode's dentry list. + /* + * This does vfs cache + fs lookup. */ - - /* It's not in the cache, look it up from filesystem. */ - return sb->root->ops.lookup(sb->root, path); + return generic_vnode_lookup(sb->root, path); } int vfs_mount_root(struct superblock *sb)