diff --git a/tasks/fs0/src/memfs/vnode.c b/tasks/fs0/src/memfs/vnode.c index 6532af4..f3d75d2 100644 --- a/tasks/fs0/src/memfs/vnode.c +++ b/tasks/fs0/src/memfs/vnode.c @@ -203,9 +203,13 @@ int memfs_write_vnode(struct superblock *sb, struct vnode *v) /* + * Given a non-zero dirbuf, uses it, otherwise it allocates one on its own. + * * 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. + * + * TODO: Returns the list of posix-compliant dirent records in the buffer. */ void *memfs_vnode_readdir(struct vnode *v, void *dirbuf) { diff --git a/tasks/fs0/src/syscalls.c b/tasks/fs0/src/syscalls.c index eaeae41..4039de7 100644 --- a/tasks/fs0/src/syscalls.c +++ b/tasks/fs0/src/syscalls.c @@ -83,6 +83,31 @@ int sys_read(l4id_t sender, int fd, void *buf, int count) 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. + */ +int sys_readdir(l4id_t sender, int fd, void *buf, int count) +{ + struct vnode *v; + + /* Get the task */ + BUG_ON(!(t = find_task(sender))); + + /* Convert fd to vnode. */ + BUG_ON(!(v = t->fd[fd])); + + /* Ensure vnode is a directory */ + if (!vfs_isdir(v)) + return -ENOTDIR; + + /* Simply read its contents */ + v->ops.readdir(v, buf, count); +` + return 0; +} + int sys_write(l4id_t sender, int fd, const void *buf, int count) { return 0;