]> git.neil.brown.name Git - lafs-utils.git/commitdiff
Add 'remainder' arg to lafs_lookup_path
authorNeilBrown <neilb@suse.de>
Mon, 21 Mar 2011 06:39:29 +0000 (17:39 +1100)
committerNeilBrown <neilb@suse.de>
Mon, 21 Mar 2011 06:39:29 +0000 (17:39 +1100)
This allows us to find where to create something.

If 'remainder' is provided, the tail of the path that couldn't
be found is placed there, and the last directory that was found is
returned.

Signed-off-by: NeilBrown <neilb@suse.de>
include/lafs/lafs.h
lib/lafs_lookup_path.c
tools/lafs.c

index 926c13f6afb312ebe03e287acec650662ddc4e5a..7f60a38c7b9309609f71c261136c3c9abe0d5d41 100644 (file)
@@ -94,7 +94,7 @@ struct lafs_iblk *lafs_leaf_find(struct lafs_ino *inode,
                                 u32 addr, int adopt, u32 *next);
 u32 lafs_dir_lookup(struct lafs_ino *dir, char *name, int len);
 struct lafs_ino *lafs_lookup_path(struct lafs_ino *root, struct lafs_ino *cwd,
-                                 char *path);
+                                 char *path, char **remainder);
 
 
 
index cf29cb6f4d10b9f83c7c8e4a884a2306299854e4..439638fd1090fa07ea1904acfb3f9d376a371212 100644 (file)
@@ -1,7 +1,7 @@
 #include <lafs/lafs.h>
 
 struct lafs_ino *lafs_lookup_path(struct lafs_ino *root, struct lafs_ino *cwd,
-                                 char *path)
+                                 char *path, char **remainder)
 {
        if (!path)
                return cwd;
@@ -14,16 +14,21 @@ struct lafs_ino *lafs_lookup_path(struct lafs_ino *root, struct lafs_ino *cwd,
        while (cwd && *path) {
                char *p = path;
                int len;
-               u32 inum;
+               u32 inum = 0;
                while (*path && *path != '/')
                        path++;
                len = path - p;
                while (*path == '/')
                        path++;
 
-               inum = lafs_dir_lookup(cwd, p, len);
-               if (!inum)
-                       return NULL;
+               if (cwd->type == TypeDir)
+                       inum = lafs_dir_lookup(cwd, p, len);
+               if (!inum) {
+                       if (!remainder)
+                               return NULL;
+                       *remainder = p;
+                       return cwd;
+               }
                cwd = lafs_get_inode(cwd->filesys, inum);
        }
        return cwd;
index 18c29dbe907826265abde9c8c0e40b8ffe2c85c0..437b080f401b07d1ab2ea3ff1cae58547e8907e9 100644 (file)
@@ -580,7 +580,7 @@ static char *internal_gen(const char *prefix, int state)
                /*pre is the directory, prefix is the component prefix */
                inode = lafs_get_itable(gen_state->lafs);
                inode = lafs_get_inode(inode, 2);
-               inode = lafs_lookup_path(inode, inode, pre);
+               inode = lafs_lookup_path(inode, inode, pre, NULL);
                index = -1;
        } else {
                if (index + 1 == 0) {
@@ -1283,7 +1283,7 @@ static void c_show_inode(struct state *st, void **args)
        } else {
                char *path = args[2];
                inode = lafs_get_inode(inode, 2);
-               inode = lafs_lookup_path(inode, inode, path);
+               inode = lafs_lookup_path(inode, inode, path, NULL);
 
                if (!inode) {
                        printf("show inode: cannot find inode for %s\n", path);
@@ -1507,7 +1507,7 @@ static void c_ls(struct state *st, void **args)
        ino = lafs_get_itable(st->lafs);
        ino = lafs_get_inode(ino, 2);
        if (path)
-               ino = lafs_lookup_path(ino, ino, path);
+               ino = lafs_lookup_path(ino, ino, path, NULL);
 
        if (!ino) {
                printf("ls: cannot find inode for %s\n", path?:"/");