vfs: add mount support
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
This commit is contained in:
parent
9bbe42b95a
commit
7c8b46eeda
3 changed files with 318 additions and 20 deletions
35
fs/vfs/vfs.c
35
fs/vfs/vfs.c
|
|
@ -6,7 +6,6 @@
|
|||
#include <lib/string.h>
|
||||
#include <lib/errno.h>
|
||||
|
||||
static fs_t *root_fs = NULL;
|
||||
static list_t fs_type_list = {0};
|
||||
|
||||
static char *path_trim(const char *name)
|
||||
|
|
@ -85,7 +84,7 @@ static int next_level(const char *path, dirent_t *dent, dirent_t **out_dirent)
|
|||
return -ENOENT;
|
||||
}
|
||||
|
||||
int vfs_openat(dirent_t *in, const char *name, dirent_t **out)
|
||||
int vfs_openat(struct mount *mnt, dirent_t *in, const char *name, dirent_t **out)
|
||||
{
|
||||
if (!in || !name || !out)
|
||||
return -EINVAL;
|
||||
|
|
@ -94,6 +93,7 @@ int vfs_openat(dirent_t *in, const char *name, dirent_t **out)
|
|||
if (!path_optr)
|
||||
return -ENOMEM;
|
||||
|
||||
struct mount *cur_mount = mnt;
|
||||
dirent_t *current_dir = in;
|
||||
dirent_inc_ref(current_dir);
|
||||
|
||||
|
|
@ -118,6 +118,19 @@ int vfs_openat(dirent_t *in, const char *name, dirent_t **out)
|
|||
|
||||
dirent_dec_ref(current_dir);
|
||||
current_dir = next_dir;
|
||||
|
||||
struct mount *child = mount_find_child(cur_mount, current_dir);
|
||||
if (child) {
|
||||
dirent_dec_ref(current_dir);
|
||||
cur_mount = child;
|
||||
current_dir = child->fs->root_dirent;
|
||||
if (!current_dir) {
|
||||
ret = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
dirent_inc_ref(current_dir);
|
||||
}
|
||||
|
||||
cur_path += res;
|
||||
|
||||
while (*cur_path == '/')
|
||||
|
|
@ -140,10 +153,11 @@ int vfs_open(const char *abs_path, dirent_t **out)
|
|||
if (!abs_path || !out)
|
||||
return -EINVAL;
|
||||
|
||||
if (!root_fs->root_dirent)
|
||||
struct mount *root = vfs_get_root_mount();
|
||||
if (!root || !root->fs || !root->fs->root_dirent)
|
||||
return -ENOENT;
|
||||
|
||||
return vfs_openat(root_fs->root_dirent, abs_path, out);
|
||||
return vfs_openat(root, root->fs->root_dirent, abs_path, out);
|
||||
}
|
||||
|
||||
void vfs_close(dirent_t *dent)
|
||||
|
|
@ -284,16 +298,6 @@ int vfs_unlink(dirent_t *parent, const char *name)
|
|||
return res;
|
||||
}
|
||||
|
||||
int vfs_mount(const char *mount_point, fs_t *fs_to_mount)
|
||||
{
|
||||
if (!mount_point || !strcmp(mount_point, "/")) {
|
||||
root_fs = fs_to_mount;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -ENOSYS;
|
||||
}
|
||||
|
||||
void vfs_register(struct fs_driver *fs)
|
||||
{
|
||||
struct fs_driver *ins = kalloc(sizeof(*fs), ALLOC_KERN);
|
||||
|
|
@ -308,8 +312,5 @@ void vfs_register(struct fs_driver *fs)
|
|||
void vfs_init(void)
|
||||
{
|
||||
inode_init();
|
||||
root_fs = kalloc(sizeof(fs_t), ALLOC_KERN);
|
||||
memset(root_fs, 0, sizeof(*root_fs));
|
||||
|
||||
list_create(&fs_type_list);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue