mount: simplify mount_traverse
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
a5c57b7893
commit
27c3ffa8b1
3 changed files with 26 additions and 112 deletions
24
fs/vfs/vfs.c
24
fs/vfs/vfs.c
|
|
@ -84,7 +84,7 @@ static int next_level(const char *path, dirent_t *dent, dirent_t **out_dirent)
|
|||
return -ENOENT;
|
||||
}
|
||||
|
||||
int vfs_openat(struct mount *mnt, dirent_t *in, const char *name, dirent_t **out)
|
||||
int vfs_openat(struct mount *mnt, dirent_t *in, const char *name, dirent_t **out, struct mount **out_mnt, bool follow)
|
||||
{
|
||||
if (!in || !name || !out)
|
||||
return -EINVAL;
|
||||
|
|
@ -99,6 +99,8 @@ int vfs_openat(struct mount *mnt, dirent_t *in, const char *name, dirent_t **out
|
|||
|
||||
if (*path_optr == '\0') {
|
||||
*out = current_dir;
|
||||
if (out_mnt)
|
||||
*out_mnt = mnt;
|
||||
kfree(path_optr);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -119,8 +121,15 @@ int vfs_openat(struct mount *mnt, dirent_t *in, const char *name, dirent_t **out
|
|||
dirent_dec_ref(current_dir);
|
||||
current_dir = next_dir;
|
||||
|
||||
cur_path += res;
|
||||
|
||||
while (*cur_path == '/')
|
||||
cur_path++;
|
||||
|
||||
bool at_end = (*cur_path == '\0');
|
||||
|
||||
struct mount *child = mount_find_child(cur_mount, current_dir);
|
||||
if (child) {
|
||||
if (child && (!at_end || follow)) {
|
||||
dirent_dec_ref(current_dir);
|
||||
cur_mount = child;
|
||||
current_dir = child->fs->root_dirent;
|
||||
|
|
@ -131,13 +140,10 @@ int vfs_openat(struct mount *mnt, dirent_t *in, const char *name, dirent_t **out
|
|||
dirent_inc_ref(current_dir);
|
||||
}
|
||||
|
||||
cur_path += res;
|
||||
|
||||
while (*cur_path == '/')
|
||||
cur_path++;
|
||||
|
||||
if (*cur_path == '\0') {
|
||||
if (at_end) {
|
||||
*out = current_dir;
|
||||
if (out_mnt)
|
||||
*out_mnt = cur_mount;
|
||||
ret = 0;
|
||||
goto out;
|
||||
}
|
||||
|
|
@ -157,7 +163,7 @@ int vfs_open(const char *abs_path, dirent_t **out)
|
|||
if (!root || !root->fs || !root->fs->root_dirent)
|
||||
return -ENOENT;
|
||||
|
||||
return vfs_openat(root, root->fs->root_dirent, abs_path, out);
|
||||
return vfs_openat(root, root->fs->root_dirent, abs_path, out, NULL, true);
|
||||
}
|
||||
|
||||
void vfs_close(dirent_t *dent)
|
||||
|
|
|
|||
Loading…
Reference in a new issue