lookup return value was changed from -ENOENT to 0 when vnode not found,

Fixed a point in code that expected 0.

Next: lookups should not consume from path every time called but only
when moving to children to lookup.
This commit is contained in:
Bahadir Balban
2008-04-15 23:45:46 +01:00
parent 577a2bffe4
commit 9a66893288
3 changed files with 34 additions and 5 deletions

View File

@@ -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)

View File

@@ -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;
}

View File

@@ -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("/");