diff --git a/tasks/fs0/src/lookup.c b/tasks/fs0/src/lookup.c index b5b02d3..b23d384 100644 --- a/tasks/fs0/src/lookup.c +++ b/tasks/fs0/src/lookup.c @@ -22,11 +22,17 @@ struct vnode *lookup_dentry_children(struct dentry *parentdir, struct vnode *v; list_for_each_entry(childdir, &parentdir->children, child) - /* Non-zero result means either found it or error occured */ - if ((v = childdir->vnode->ops.lookup(childdir->vnode, pdata))) + if (IS_ERR(v = childdir->vnode->ops.lookup(childdir->vnode, + pdata))) + /* Means not found, continue search */ + if ((int)v == -ENOENT) + continue; + else /* A real error */ + return v; + else /* No error, so found it */ return v; - /* Out of all children dentries, neither was a match, so we return 0 */ + /* Out of all children dentries, neither was a match */ return PTR_ERR(-ENOENT); } @@ -40,13 +46,14 @@ struct vnode *generic_vnode_lookup(struct vnode *thisnode, int err; component = pathdata_next_component(pdata); - + printf("looking up: %s\n", component); /* Does this path component match with any of this vnode's dentries? */ list_for_each_entry(d, &thisnode->dentries, vref) { + printf("comparing dentry %s with %s\n", d->name, component); if (d->ops.compare(d, component)) { /* Is this a directory? */ if (vfs_isdir(thisnode)) { - /* Are there any more path components? */ + /* Are there more path components? */ if (!list_empty(&pdata->list)) { /* Read directory contents */ if ((err = d->vnode->ops.readdir(d->vnode)) < 0) diff --git a/tasks/fs0/src/syscalls.c b/tasks/fs0/src/syscalls.c index af397c9..52af532 100644 --- a/tasks/fs0/src/syscalls.c +++ b/tasks/fs0/src/syscalls.c @@ -43,6 +43,20 @@ int pager_sys_open(l4id_t sender, int fd, unsigned long vnum, unsigned long size return 0; } +/* Directories only for now */ +void print_vnode(struct vnode *v) +{ + struct dentry *d, *c; + + printf("Vnode name:\n"); + list_for_each_entry(d, &v->dentries, vref) { + printf("%s\n", d->name); + printf("Children dentries:\n"); + list_for_each_entry(c, &d->children, child) + printf("%s\n", c->name); + } +} + /* Creates a node under a directory, e.g. a file, directory. */ int vfs_create(struct tcb *task, struct pathdata *pdata, unsigned int mode) { @@ -65,6 +79,7 @@ int vfs_create(struct tcb *task, struct pathdata *pdata, unsigned int mode) if ((err = vparent->ops.mknod(vparent, nodename, mode)) < 0) return err; + // print_vnode(vparent); return 0; } diff --git a/tasks/test0/src/dirtest.c b/tasks/test0/src/dirtest.c index f7eea0c..0a21b27 100644 --- a/tasks/test0/src/dirtest.c +++ b/tasks/test0/src/dirtest.c @@ -151,6 +151,13 @@ int dirtest(void) if (mkdir("/dev", 0) < 0) perror("MKDIR"); + if (mkdir("/usr/bin", 0) < 0) + perror("MKDIR"); + if (mkdir("/home/", 0) < 0) + perror("MKDIR"); + if (mkdir("/home/bahadir", 0) < 0) + perror("MKDIR"); + printf("\nlsdir root directory:\n"); lsdir("/");