|
|
|
@ -95,22 +95,24 @@ err_free_dir: |
|
|
|
|
|
|
|
|
|
struct mufs_tree *resolve_path(struct mufs *fs, const char *path) |
|
|
|
|
{ |
|
|
|
|
struct mufs_dir *dir; |
|
|
|
|
struct mufs_dirent entry; |
|
|
|
|
struct mufs_tree *tree; |
|
|
|
|
struct mufs_dir *dir = NULL; |
|
|
|
|
struct mufs_dirent entry, *found = NULL; |
|
|
|
|
struct mufs_tree *tree = NULL; |
|
|
|
|
char *s, *p, *end; |
|
|
|
|
int ret; |
|
|
|
|
|
|
|
|
|
if (!(s = mufs_abspath(path))) |
|
|
|
|
return NULL; |
|
|
|
|
|
|
|
|
|
if (strcmp(s, "/") == 0) |
|
|
|
|
return &fs->root; |
|
|
|
|
|
|
|
|
|
if (!(dir = open_dirent(fs, NULL))) |
|
|
|
|
if (strcmp(s, "/") == 0) { |
|
|
|
|
tree = &fs->root; |
|
|
|
|
goto err_free_s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (p = s + 1; *p != '\0'; p = end) { |
|
|
|
|
if (!(dir = open_dirent(fs, found))) |
|
|
|
|
goto err_free_s; |
|
|
|
|
|
|
|
|
|
end = p + strcspn(p, "/"); |
|
|
|
|
|
|
|
|
|
if (*end == '/') |
|
|
|
@ -120,29 +122,22 @@ struct mufs_tree *resolve_path(struct mufs *fs, const char *path) |
|
|
|
|
if (strcmp(entry.path, p) != 0) |
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
mufs_closedir(dir); |
|
|
|
|
|
|
|
|
|
if (!(dir = open_dirent(fs, &entry))) |
|
|
|
|
goto err_free_s; |
|
|
|
|
|
|
|
|
|
found = &entry; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (ret < 0) |
|
|
|
|
goto err_close_dir; |
|
|
|
|
} |
|
|
|
|
goto err_closedir; |
|
|
|
|
|
|
|
|
|
tree = dir->tree; |
|
|
|
|
|
|
|
|
|
mufs_closedir(dir); |
|
|
|
|
|
|
|
|
|
return tree; |
|
|
|
|
tree = dir->tree; |
|
|
|
|
dir->tree = NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err_close_dir: |
|
|
|
|
err_closedir: |
|
|
|
|
mufs_closedir(dir); |
|
|
|
|
err_free_s: |
|
|
|
|
free(s); |
|
|
|
|
return NULL; |
|
|
|
|
return tree; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct mufs_dir *mufs_opendir(struct mufs *fs, const char *path) |
|
|
|
|