From 329dc53982548d2d72f7367aa9aeeaff99e6bcb4 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Thu, 14 Feb 2008 21:23:49 +0000 Subject: [PATCH] FS0 compiles with the changes, also caught an unparanthesised double-statement if clause in lookup.c --- tasks/fs0/include/fs.h | 11 +++++++++++ tasks/fs0/include/vfs.h | 11 ++--------- tasks/fs0/src/lookup.c | 7 ++++--- tasks/fs0/src/memfs/vnode.c | 11 +++++------ tasks/fs0/src/syscalls.c | 8 ++++---- tasks/fs0/src/vfs.c | 28 +++++++++++++++------------- 6 files changed, 41 insertions(+), 35 deletions(-) diff --git a/tasks/fs0/include/fs.h b/tasks/fs0/include/fs.h index 42ccd96..8468ca1 100644 --- a/tasks/fs0/include/fs.h +++ b/tasks/fs0/include/fs.h @@ -84,10 +84,21 @@ struct dentry { struct list_head child; /* List of dentries with same parent */ struct list_head children; /* List of children dentries */ struct list_head vref; /* For vnode's dirent reference list */ + struct list_head cache_list; /* Dentry cache reference */ struct vnode *vnode; /* The vnode associated with dirent */ struct dentry_ops ops; }; +/* + * Buffer to keep directory content. This is the only vnode content + * that fs0 maintains. All other file data is in mm0 page cache. + */ +struct dirbuf { + unsigned long npages; + int dirty; + u8 *buffer; +}; + struct vnode { unsigned long vnum; /* Filesystem-wide unique vnode id */ int refcnt; /* Reference counter */ diff --git a/tasks/fs0/include/vfs.h b/tasks/fs0/include/vfs.h index 37efd5c..e15e352 100644 --- a/tasks/fs0/include/vfs.h +++ b/tasks/fs0/include/vfs.h @@ -5,15 +5,8 @@ #include #include #include - -/* Buffer to keep directory content. This is the only vnode content - * that fs0 maintains. All other file data is in mm0 page cache. - */ -struct dirbuf { - unsigned long npages; - int dirty; - u8 *buf; -}; +#include +#include extern struct list_head vnode_cache; extern struct list_head dentry_cache; diff --git a/tasks/fs0/src/lookup.c b/tasks/fs0/src/lookup.c index aafe402..382327b 100644 --- a/tasks/fs0/src/lookup.c +++ b/tasks/fs0/src/lookup.c @@ -74,15 +74,16 @@ struct vnode *generic_vnode_lookup(struct vnode *thisnode, char *path) /* Is this a directory? */ if (vfs_isdir(thisnode)) { /* Are there any more path components? */ - if (path) + if (path) { /* Read directory contents */ if ((err = (int)d->vnode->ops.readdir(d->vnode))) - return err; + return PTR_ERR(err); + /* Search all children one level below. */ if ((found = lookup_dentry_children(d, path))) /* Either found, or non-zero error */ return found; - else + } else return thisnode; } else { /* Its a file */ if (path) /* There's still path, but not directory */ diff --git a/tasks/fs0/src/memfs/vnode.c b/tasks/fs0/src/memfs/vnode.c index 334d489..466ab18 100644 --- a/tasks/fs0/src/memfs/vnode.c +++ b/tasks/fs0/src/memfs/vnode.c @@ -214,7 +214,6 @@ int memfs_write_vnode(struct superblock *sb, struct vnode *v) int memfs_vnode_readdir(struct vnode *v) { int err; - u8 *dirbuf; struct memfs_dentry *memfsd; struct dentry *parent = list_entry(v->dentries.next, struct dentry, vref); @@ -224,13 +223,13 @@ int memfs_vnode_readdir(struct vnode *v) return -ENOTDIR; /* If a buffer is there, it means the directory is already read */ - if (v->dirbuf->buffer) + if (v->dirbuf.buffer) return 0; /* This is as big as a page */ - v->dirbuf->buffer = vfs_alloc_dirbuf(); - v->dirbuf->npages = 1; - memfsd = dirbuf = v->dirbuf->buffer; + v->dirbuf.buffer = vfs_alloc_dirpage(); + v->dirbuf.npages = 1; + memfsd = (struct memfs_dentry *) v->dirbuf.buffer; /* * Fail if vnode size is bigger than a page. Since this allocation @@ -239,7 +238,7 @@ int memfs_vnode_readdir(struct vnode *v) BUG_ON(v->size > PAGE_SIZE); /* Read memfsd contents into the buffer */ - if ((err = v->fops.read(v, 0, 1, dirbuf))) + if ((err = v->fops.read(v, 0, 1, v->dirbuf.buffer))) return err; /* Read fs-specific directory entry into vnode and dentry caches. */ diff --git a/tasks/fs0/src/syscalls.c b/tasks/fs0/src/syscalls.c index e95001f..5f8af4b 100644 --- a/tasks/fs0/src/syscalls.c +++ b/tasks/fs0/src/syscalls.c @@ -50,7 +50,7 @@ int do_open(l4id_t sender, const char *pathname, int flags, unsigned int mode) memcpy(pathcopy, pathname, strlen(pathname)); /* Get the vnode */ - if (IS_ERR(v = vfs_lookup(vfs_root.pivot->sb, pathcopy))) + if (IS_ERR(v = vfs_lookup_bypath(vfs_root.pivot->sb, pathcopy))) return (int)v; /* Get the task */ @@ -103,7 +103,7 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count) BUG_ON(!(vnum = t->fd[fd])); /* Lookup vnode */ - if (!(v = vfs_lookup_byvnum(vnum))) + if (!(v = vfs_lookup_byvnum(vfs_root.pivot->sb, vnum))) return -EINVAL; /* No such vnode */ /* Ensure vnode is a directory */ @@ -118,8 +118,8 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count) nbytes = (v->size <= count) ? v->size : 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 */ + if (v->dirbuf.buffer && (v->dirbuf.npages * PAGE_SIZE) >= nbytes) { + memcpy(buf, v->dirbuf.buffer, nbytes); /* Finish the job */ return nbytes; } diff --git a/tasks/fs0/src/vfs.c b/tasks/fs0/src/vfs.c index 26a4c89..9788115 100644 --- a/tasks/fs0/src/vfs.c +++ b/tasks/fs0/src/vfs.c @@ -9,6 +9,16 @@ struct list_head vnode_cache; struct list_head dentry_cache; +/* + * / + * /boot + * /boot/images/mm0.axf + * /boot/images/fs0.axf + * /boot/images/test0.axf + * /file.txt + */ +struct vfs_mountpoint vfs_root; + /* * Vnodes in the vnode cache have 2 keys. One is their dentry names, the other * is their vnum. This one checks the vnode cache by the given vnum first. @@ -21,7 +31,7 @@ struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum) int err; /* Check the vnode cache by vnum */ - list_for_each_entry(v, vnode_cache, cache_list) + list_for_each_entry(v, &vnode_cache, cache_list) if (v->vnum == vnum) return v; @@ -36,9 +46,11 @@ struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum) /* Check the actual filesystem for the vnode */ v = vfs_alloc_vnode(); v->vnum = vnum; - if ((err = v->read_vnode(sb, v)) < 0) { + + /* Note this only checks given superblock */ + if ((err = sb->ops->read_vnode(sb, v)) < 0) { vfs_free_vnode(v); - return err; + return PTR_ERR(err); } /* Add the vnode back to vnode cache */ @@ -68,16 +80,6 @@ struct vnode *vfs_lookup_bypath(struct superblock *sb, char *path) return sb->root->ops.lookup(sb->root, path); } -/* - * / - * /boot - * /boot/images/mm0.axf - * /boot/images/fs0.axf - * /boot/images/test0.axf - * /file.txt - */ -struct vfs_mountpoint vfs_root; - int vfs_mount_root(struct superblock *sb) { /* Lookup the root vnode of this superblock */