|
|
|
@ -93,7 +93,8 @@ err_free_dir: |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
struct mufs_tree *resolve_path(struct mufs *fs, const char *path) |
|
|
|
|
struct mufs_tree *resolve_path(struct mufs *fs, const char *path, |
|
|
|
|
struct mufs_stat *stat) |
|
|
|
|
{ |
|
|
|
|
struct mufs_dir *dir = NULL; |
|
|
|
|
struct mufs_dirent entry, *found = NULL; |
|
|
|
@ -106,6 +107,12 @@ struct mufs_tree *resolve_path(struct mufs *fs, const char *path) |
|
|
|
|
|
|
|
|
|
if (strcmp(s, "/") == 0) { |
|
|
|
|
tree = &fs->root; |
|
|
|
|
|
|
|
|
|
if (stat) { |
|
|
|
|
stat->type = MUFS_DIR; |
|
|
|
|
stat->file_size = tree->file_size; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
goto err_free_s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -130,9 +137,15 @@ struct mufs_tree *resolve_path(struct mufs *fs, const char *path) |
|
|
|
|
goto err_closedir; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (dir) { |
|
|
|
|
tree = dir->tree; |
|
|
|
|
dir->tree = NULL; |
|
|
|
|
if (!dir) |
|
|
|
|
goto err_free_s; |
|
|
|
|
|
|
|
|
|
tree = dir->tree; |
|
|
|
|
dir->tree = NULL; |
|
|
|
|
|
|
|
|
|
if (stat) { |
|
|
|
|
stat->type = entry.type; |
|
|
|
|
stat->file_size = tree->file_size; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
err_closedir: |
|
|
|
@ -144,6 +157,7 @@ err_free_s: |
|
|
|
|
|
|
|
|
|
struct mufs_dir *mufs_opendir(struct mufs *fs, const char *path) |
|
|
|
|
{ |
|
|
|
|
struct mufs_stat stat; |
|
|
|
|
struct mufs_dir *dir; |
|
|
|
|
|
|
|
|
|
if (!(dir = malloc(sizeof(*dir)))) |
|
|
|
@ -151,7 +165,7 @@ struct mufs_dir *mufs_opendir(struct mufs *fs, const char *path) |
|
|
|
|
|
|
|
|
|
dir->fs = fs; |
|
|
|
|
|
|
|
|
|
if (!(dir->tree = resolve_path(fs, path))) |
|
|
|
|
if (!(dir->tree = resolve_path(fs, path, &stat)) || stat.type != MUFS_DIR) |
|
|
|
|
goto err_free_dir; |
|
|
|
|
|
|
|
|
|
dir->va = 0; |
|
|
|
|