-int
-vfs_mount(const char* target, const char* fs_name, struct device* device)
-{
- int errno;
- struct v_dnode* mnt;
-
- if (!(errno = vfs_walk(__current->cwd, target, &mnt, NULL, 0))) {
- errno = vfs_mount_at(fs_name, device, mnt);
- }
-
- return errno;
-}
-
-int
-vfs_unmount(const char* target)
-{
- int errno;
- struct v_dnode* mnt;
-
- if (!(errno = vfs_walk(__current->cwd, target, &mnt, NULL, 0))) {
- errno = vfs_unmount_at(mnt);
- }
-
- return errno;
-}
-
-int
-vfs_mount_at(const char* fs_name,
- struct device* device,
- struct v_dnode* mnt_point)
-{
- if (!(mnt_point->inode->itype & VFS_IFDIR)) {
- return ENOTDIR;
- }
-
- struct filesystem* fs = fsm_get(fs_name);
- if (!fs) {
- return ENODEV;
- }
-
- struct v_superblock* sb = vfs_sb_alloc();
- sb->dev = device;
- sb->fs_id = fs->fs_id;
-
- int errno = 0;
- if (!(errno = fs->mount(sb, mnt_point))) {
- sb->fs = fs;
- sb->root = mnt_point;
- mnt_point->super_block = sb;
- llist_append(&root_sb->sb_list, &sb->sb_list);
- }
-
- return errno;
-}
-
-int
-vfs_unmount_at(struct v_dnode* mnt_point)
-{
- // FIXME deal with the detached dcache subtree
- int errno = 0;
- struct v_superblock* sb = mnt_point->super_block;
- if (!sb) {
- return EINVAL;
- }
-
- if (sb->root != mnt_point) {
- return EINVAL;
- }
-
- if (!(errno = sb->fs->unmount(sb))) {
- struct v_dnode* fs_root = sb->root;
- vfs_dcache_remove(fs_root);
-
- llist_delete(&sb->sb_list);
- vfs_sb_free(sb);
- vfs_d_free(fs_root);
- }
- return errno;
-}
-