diff --git a/tasks/fs0/src/memfs/vnode.c b/tasks/fs0/src/memfs/vnode.c index df548ec..26ec12d 100644 --- a/tasks/fs0/src/memfs/vnode.c +++ b/tasks/fs0/src/memfs/vnode.c @@ -254,6 +254,10 @@ int memfs_vnode_mknod(struct vnode *v, char *dirname, unsigned int mode) strncpy((char *)memfsd->name, dirname, MEMFS_DNAME_MAX); memfsd->name[MEMFS_DNAME_MAX - 1] = '\0'; + BUG(); /* FIXME: Fix this issue. */ + /* Write the updated directory buffer back to disk */ + v->fops.write(v, 0, 1, v->dirbuf.buffer); + /* Update parent vnode */ v->size += sizeof(*memfsd); diff --git a/tasks/fs0/src/syscalls.c b/tasks/fs0/src/syscalls.c index 581475d..5829958 100644 --- a/tasks/fs0/src/syscalls.c +++ b/tasks/fs0/src/syscalls.c @@ -111,6 +111,19 @@ int sys_open(l4id_t sender, const char *pathname, int flags, unsigned int mode) return 0; } +int sys_close(l4id_t sender, int fd) +{ + struct vnode *v; + + /* Get the task */ + BUG_ON(!(task = find_task(sender))); + + /* Lookup vnode */ + if (!(v = vfs_lookup_byvnum(vfs_root.pivot->sb, vnum))) + return -EINVAL; /* No such vnode */ + +} + int sys_mkdir(l4id_t sender, const char *pathname, unsigned int mode) { struct tcb *task; diff --git a/tasks/fs0/src/vfs.c b/tasks/fs0/src/vfs.c index bac17c1..cc23597 100644 --- a/tasks/fs0/src/vfs.c +++ b/tasks/fs0/src/vfs.c @@ -59,16 +59,24 @@ struct vnode *vfs_lookup_byvnum(struct superblock *sb, unsigned long vnum) */ struct vnode *vfs_lookup_bypath(struct tcb *task, char *path) { - /* If it's the root or current dir, we already got it. */ + struct vnode *vnstart; + + /* Is it the root or current directory? If so, we already got it. */ if (!strcmp(path, "/")) return task->rootdir; if (!strcmp(path, ".")) return task->curdir; + /* Do we start from root or curdir? */ + if (path[0] == '/') + vnstart = task->rootdir; + else + vnstart = task->curdir; + /* * This does vfs cache + fs lookup. */ - return generic_vnode_lookup(task->rootdir, path); + return generic_vnode_lookup(vnstart, path); } int vfs_mount_root(struct superblock *sb) diff --git a/tasks/mm0/src/file.c b/tasks/mm0/src/file.c index 0940ccc..d820b2e 100644 --- a/tasks/mm0/src/file.c +++ b/tasks/mm0/src/file.c @@ -145,8 +145,8 @@ struct page *find_page(struct vm_file *f, unsigned long pfn) } /* - * This reads-in a range of pages from a file just like a page fault, - * but its not in the page fault path. + * This reads-in a range of pages from a file and populates the page cache + * just like a page fault, but its not in the page fault path. */ int read_file_pages(struct vm_file *vmfile, unsigned long pfn_start, unsigned long pfn_end) @@ -192,8 +192,8 @@ int sys_read(l4id_t sender, int fd, void *buf, int count) { unsigned long foff_pfn_start, foff_pfn_end; struct vm_file *vmfile; - struct tcb *t; unsigned long cursor; + struct tcb *t; int err; BUG_ON(!(t = find_task(sender))); @@ -215,9 +215,8 @@ int sys_read(l4id_t sender, int fd, void *buf, int count) * FIXME: If vmfiles are mapped contiguously on mm0, then these reads * can be implemented as a straightforward copy as below. * - * The problem is that in-memrory file pages are usually non-contiguous. + * The problem is that in-memory file pages are usually non-contiguous. * memcpy(buf, (void *)(vmfile->base + cursor), count); - * */ return 0; @@ -225,6 +224,26 @@ int sys_read(l4id_t sender, int fd, void *buf, int count) int sys_write(l4id_t sender, int fd, void *buf, int count) { + unsigned long foff_pfn_start, foff_pfn_end; + struct vm_file *vmfile; + unsigned long cursor; + struct tcb *t; + int err; + + BUG_ON(!(t = find_task(sender))); + + /* TODO: Check user buffer and count validity */ + if (fd < 0 || fd > TASK_OFILES_MAX) + return -EINVAL; + + vmfile = t->fd[fd].vmfile; + cursor = t->fd[fd].cursor; + + foff_pfn_start = __pfn(cursor); + foff_pfn_end = __pfn(page_align_up(cursor + count)); + + if ((err = write_file_pages(vmfile, foff_pfn_start, foff_pfn_end) < 0)) + return err; return 0; }