diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-09-22 20:46:58 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-10-24 15:57:18 +0200 |
commit | 0e7b2348ea8fbfd9cb9fb532d552e27a9636010a (patch) | |
tree | 6a1352d49e1598e55ade71f922c92cb2a77ba78c /extras | |
parent | 7f89eb3cfff465cf32d03a2ae6919252eae67e9b (diff) |
libsqfs: Add the path lookup function back to the dir reader
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'extras')
-rw-r--r-- | extras/browse.c | 47 |
1 files changed, 7 insertions, 40 deletions
diff --git a/extras/browse.c b/extras/browse.c index 00e5dbe..70537f2 100644 --- a/extras/browse.c +++ b/extras/browse.c @@ -34,55 +34,22 @@ static char *prompt; static int resolve_ref(const char *path, sqfs_u64 *out) { - sqfs_dir_reader_state_t state; sqfs_inode_generic_t *inode; - sqfs_dir_node_t *ent; - const char *end; sqfs_u64 ref; - size_t len; int ret; - ref = *path == '/' ? super.root_inode_ref : working_dir; - - while (path != NULL && *path != '\0') { - if (*path == '/') { - while (*path == '/') - ++path; - continue; - } - - end = strchr(path, '/'); - len = (end == NULL) ? strlen(path) : (size_t)(end - path); - - ret = sqfs_dir_reader_get_inode(dr, ref, &inode); - if (ret != 0) - return ret; + ref = (*path == '/') ? super.root_inode_ref : working_dir; - ret = sqfs_dir_reader_open_dir(dr, inode, &state, 0); + ret = sqfs_dir_reader_get_inode(dr, ref, &inode); + if (ret == 0) { + ret = sqfs_dir_reader_resolve_path(dr, path, inode, &ref); sqfs_free(inode); - if (ret != 0) - return ret; - - do { - ret = sqfs_dir_reader_read(dr, &state, &ent); - if (ret < 0) - return ret; - if (ret > 0) - return 1; - - ret = strncmp((const char *)ent->name, path, len); - free(ent); - if (ret == 0 && ent->name[len] != '\0') - return 1; - } while (ret != 0); - - ref = state.ent_ref; - path = end; + if (ret == 0) + *out = ref; } - *out = ref; - return 0; + return ret; } static char *add_prefix(const char *pfx, size_t pfxlen, char *path) |