mirror of
https://github.com/drasko/codezero.git
synced 2026-01-12 02:43:15 +01:00
FS0 compiles with the changes, also caught an unparanthesised double-statement
if clause in lookup.c
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -5,15 +5,8 @@
|
||||
#include <lib/malloc.h>
|
||||
#include <l4/lib/list.h>
|
||||
#include <memfs/memfs.h>
|
||||
|
||||
/* 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 <l4/macros.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern struct list_head vnode_cache;
|
||||
extern struct list_head dentry_cache;
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user