FS0 compiles with the changes, also caught an unparanthesised double-statement

if clause in lookup.c
This commit is contained in:
Bahadir Balban
2008-02-14 21:23:49 +00:00
parent b54a0f78e8
commit 329dc53982
6 changed files with 41 additions and 35 deletions

View File

@@ -84,10 +84,21 @@ struct dentry {
struct list_head child; /* List of dentries with same parent */ struct list_head child; /* List of dentries with same parent */
struct list_head children; /* List of children dentries */ struct list_head children; /* List of children dentries */
struct list_head vref; /* For vnode's dirent reference list */ 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 vnode *vnode; /* The vnode associated with dirent */
struct dentry_ops ops; 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 { struct vnode {
unsigned long vnum; /* Filesystem-wide unique vnode id */ unsigned long vnum; /* Filesystem-wide unique vnode id */
int refcnt; /* Reference counter */ int refcnt; /* Reference counter */

View File

@@ -5,15 +5,8 @@
#include <lib/malloc.h> #include <lib/malloc.h>
#include <l4/lib/list.h> #include <l4/lib/list.h>
#include <memfs/memfs.h> #include <memfs/memfs.h>
#include <l4/macros.h>
/* Buffer to keep directory content. This is the only vnode content #include <stdio.h>
* that fs0 maintains. All other file data is in mm0 page cache.
*/
struct dirbuf {
unsigned long npages;
int dirty;
u8 *buf;
};
extern struct list_head vnode_cache; extern struct list_head vnode_cache;
extern struct list_head dentry_cache; extern struct list_head dentry_cache;

View File

@@ -74,15 +74,16 @@ struct vnode *generic_vnode_lookup(struct vnode *thisnode, char *path)
/* Is this a directory? */ /* Is this a directory? */
if (vfs_isdir(thisnode)) { if (vfs_isdir(thisnode)) {
/* Are there any more path components? */ /* Are there any more path components? */
if (path) if (path) {
/* Read directory contents */ /* Read directory contents */
if ((err = (int)d->vnode->ops.readdir(d->vnode))) if ((err = (int)d->vnode->ops.readdir(d->vnode)))
return err; return PTR_ERR(err);
/* Search all children one level below. */ /* Search all children one level below. */
if ((found = lookup_dentry_children(d, path))) if ((found = lookup_dentry_children(d, path)))
/* Either found, or non-zero error */ /* Either found, or non-zero error */
return found; return found;
else } else
return thisnode; return thisnode;
} else { /* Its a file */ } else { /* Its a file */
if (path) /* There's still path, but not directory */ if (path) /* There's still path, but not directory */

View File

@@ -214,7 +214,6 @@ int memfs_write_vnode(struct superblock *sb, struct vnode *v)
int memfs_vnode_readdir(struct vnode *v) int memfs_vnode_readdir(struct vnode *v)
{ {
int err; int err;
u8 *dirbuf;
struct memfs_dentry *memfsd; struct memfs_dentry *memfsd;
struct dentry *parent = list_entry(v->dentries.next, struct dentry *parent = list_entry(v->dentries.next,
struct dentry, vref); struct dentry, vref);
@@ -224,13 +223,13 @@ int memfs_vnode_readdir(struct vnode *v)
return -ENOTDIR; return -ENOTDIR;
/* If a buffer is there, it means the directory is already read */ /* If a buffer is there, it means the directory is already read */
if (v->dirbuf->buffer) if (v->dirbuf.buffer)
return 0; return 0;
/* This is as big as a page */ /* This is as big as a page */
v->dirbuf->buffer = vfs_alloc_dirbuf(); v->dirbuf.buffer = vfs_alloc_dirpage();
v->dirbuf->npages = 1; v->dirbuf.npages = 1;
memfsd = dirbuf = v->dirbuf->buffer; memfsd = (struct memfs_dentry *) v->dirbuf.buffer;
/* /*
* Fail if vnode size is bigger than a page. Since this allocation * 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); BUG_ON(v->size > PAGE_SIZE);
/* Read memfsd contents into the buffer */ /* 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; return err;
/* Read fs-specific directory entry into vnode and dentry caches. */ /* Read fs-specific directory entry into vnode and dentry caches. */

View File

@@ -50,7 +50,7 @@ int do_open(l4id_t sender, const char *pathname, int flags, unsigned int mode)
memcpy(pathcopy, pathname, strlen(pathname)); memcpy(pathcopy, pathname, strlen(pathname));
/* Get the vnode */ /* 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; return (int)v;
/* Get the task */ /* 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])); BUG_ON(!(vnum = t->fd[fd]));
/* Lookup vnode */ /* Lookup vnode */
if (!(v = vfs_lookup_byvnum(vnum))) if (!(v = vfs_lookup_byvnum(vfs_root.pivot->sb, vnum)))
return -EINVAL; /* No such vnode */ return -EINVAL; /* No such vnode */
/* Ensure vnode is a directory */ /* 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; nbytes = (v->size <= count) ? v->size : count;
/* Do we have those bytes at hand? */ /* Do we have those bytes at hand? */
if (v->dirbuf->buffer && (v->dirbuf->npages * PAGE_SIZE) >= nbytes) { 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); /* Finish the job */
return nbytes; return nbytes;
} }

View File

@@ -9,6 +9,16 @@
struct list_head vnode_cache; struct list_head vnode_cache;
struct list_head dentry_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 * 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. * 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; int err;
/* Check the vnode cache by vnum */ /* 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) if (v->vnum == vnum)
return v; return v;
@@ -36,9 +46,11 @@ struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum)
/* Check the actual filesystem for the vnode */ /* Check the actual filesystem for the vnode */
v = vfs_alloc_vnode(); v = vfs_alloc_vnode();
v->vnum = vnum; 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); vfs_free_vnode(v);
return err; return PTR_ERR(err);
} }
/* Add the vnode back to vnode cache */ /* 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); 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) int vfs_mount_root(struct superblock *sb)
{ {
/* Lookup the root vnode of this superblock */ /* Lookup the root vnode of this superblock */