mirror of
https://github.com/drasko/codezero.git
synced 2026-02-28 09:43:14 +01:00
Some efforts to adding better support for readdir
This commit is contained in:
@@ -75,6 +75,8 @@ int initialise(void)
|
||||
memfs_format_filesystem(rootdev_blocks);
|
||||
|
||||
INIT_LIST_HEAD(&vm_file_list);
|
||||
INIT_LIST_HEAD(&vnode_cache);
|
||||
INIT_LIST_HEAD(&dentry_cache);
|
||||
|
||||
/* Search for a filesystem on the root device */
|
||||
BUG_ON(IS_ERR(root_sb = vfs_probe_filesystems(rootdev_blocks)));
|
||||
|
||||
@@ -91,6 +91,7 @@ int sys_read(l4id_t sender, int fd, void *buf, int count)
|
||||
int sys_readdir(l4id_t sender, int fd, void *buf, int count)
|
||||
{
|
||||
struct vnode *v;
|
||||
struct tcb *t;
|
||||
|
||||
/* Get the task */
|
||||
BUG_ON(!(t = find_task(sender)));
|
||||
@@ -104,7 +105,7 @@ int sys_readdir(l4id_t sender, int fd, void *buf, int count)
|
||||
|
||||
/* Simply read its contents */
|
||||
v->ops.readdir(v, buf, count);
|
||||
`
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,12 +6,49 @@
|
||||
#include <fs.h>
|
||||
#include <vfs.h>
|
||||
|
||||
struct vnode *vfs_lookup(struct superblock *sb, char *path)
|
||||
struct list_head vnode_cache;
|
||||
struct list_head dentry_cache;
|
||||
|
||||
/*
|
||||
* 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.
|
||||
* If nothing is found, it reads the vnode from disk into cache.
|
||||
*/
|
||||
struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum)
|
||||
{
|
||||
struct vnode *v;
|
||||
|
||||
/* Check the vnode cache by vnum */
|
||||
list_for_each_entry(v, vnode_cache, cache_list)
|
||||
if (v->vnum == vnum)
|
||||
return v;
|
||||
|
||||
/* Otherwise ask the filesystem:
|
||||
* TODO:
|
||||
* vfs_alloc_vnode() -> This should also add the empty vnode to vnode cache.
|
||||
* read_vnode() -> read it from filesystem.
|
||||
* return what's read.
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
* Vnodes in the vnode cache have 2 keys. One is their dentry name, the
|
||||
* other is their vnum. This one checks the vnode cache by the path first.
|
||||
* If nothing is found, it reads the vnode from disk into the cache.
|
||||
*/
|
||||
struct vnode *vfs_lookup_bypath(struct superblock *sb, char *path)
|
||||
{
|
||||
/* If it's just / we already got it. */
|
||||
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.
|
||||
*/
|
||||
|
||||
/* It's not in the cache, look it up from filesystem. */
|
||||
return sb->root->ops.lookup(sb->root, path);
|
||||
}
|
||||
|
||||
@@ -28,7 +65,7 @@ struct vfs_mountpoint vfs_root;
|
||||
int vfs_mount_root(struct superblock *sb)
|
||||
{
|
||||
/* Lookup the root vnode of this superblock */
|
||||
vfs_root.pivot = vfs_lookup(sb, "/");
|
||||
vfs_root.pivot = vfs_lookup_bypath(sb, "/");
|
||||
vfs_root.sb = sb;
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user