kernel/VFS: Add a way to unmount file systems
This commit is contained in:
parent
e7d482e78a
commit
29174ca228
@ -150,7 +150,7 @@ namespace VFS
|
||||
auto parent_path = TRY(parser.dirname());
|
||||
auto child = TRY(parser.basename());
|
||||
|
||||
kdbgln("vfs: mounting filesystem on target %s, parent dir %s", child.chars(), parent_path.chars());
|
||||
kdbgln("vfs: Mounting filesystem on target %s", path);
|
||||
|
||||
auto parent_inode = TRY(resolve_path(parent_path.chars(), auth, working_directory));
|
||||
|
||||
@ -164,4 +164,26 @@ namespace VFS
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> umount(const char* path, Credentials auth, SharedPtr<VFS::Inode> working_directory)
|
||||
{
|
||||
auto parser = TRY(PathParser::create(path));
|
||||
auto parent_path = TRY(parser.dirname());
|
||||
auto child = TRY(parser.basename());
|
||||
|
||||
kdbgln("vfs: Unmounting filesystem on target %s", path);
|
||||
|
||||
auto parent_inode = TRY(resolve_path(parent_path.chars(), auth, working_directory));
|
||||
|
||||
auto inode = TRY(parent_inode->find(child.chars()));
|
||||
if (!inode->is_mountpoint()) return err(EINVAL);
|
||||
|
||||
// There are still open file descriptors referencing files within this file system.
|
||||
if (inode->fs()->handles() != 0) return err(EBUSY);
|
||||
|
||||
auto mount = (MountInode*)inode.ptr();
|
||||
TRY(parent_inode->replace_entry(mount->source(), child.chars()));
|
||||
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
@ -260,4 +260,6 @@ namespace VFS
|
||||
Result<void> mount_root(SharedPtr<VFS::FileSystem> fs);
|
||||
Result<void> mount(const char* path, SharedPtr<VFS::FileSystem> fs, Credentials auth,
|
||||
SharedPtr<Inode> working_directory = {});
|
||||
|
||||
Result<void> umount(const char* path, Credentials auth, SharedPtr<Inode> working_directory = {});
|
||||
}
|
||||
|
@ -34,6 +34,15 @@ namespace DeviceRegistry
|
||||
return err(ENODEV);
|
||||
}
|
||||
|
||||
Result<void> create_special_device_inode(DeviceDescriptor& descriptor)
|
||||
{
|
||||
auto inode = TRY(g_device_fs->create_device_inode(descriptor.major, descriptor.minor));
|
||||
inode->chmod(descriptor.mode);
|
||||
TRY(g_device_fs->root_inode()->add_entry(inode, descriptor.name));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> register_special_device(u32 major, u32 minor, SharedPtr<Device> device, const char* name, mode_t mode)
|
||||
{
|
||||
for (const auto& descriptor : g_available_devices)
|
||||
@ -52,15 +61,6 @@ namespace DeviceRegistry
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> create_special_device_inode(DeviceDescriptor& descriptor)
|
||||
{
|
||||
auto inode = TRY(g_device_fs->create_device_inode(descriptor.major, descriptor.minor));
|
||||
inode->chmod(descriptor.mode);
|
||||
TRY(g_device_fs->root_inode()->add_entry(inode, descriptor.name));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> init()
|
||||
{
|
||||
auto device_fs = TRY(TmpFS::FileSystem::create());
|
||||
|
@ -66,6 +66,22 @@ Result<SharedPtr<VFS::Inode>> Thread::resolve_atfile(int dirfd, const String& pa
|
||||
return VFS::resolve_path(path.chars(), this->auth, descriptor->inode);
|
||||
}
|
||||
|
||||
FileDescriptor::FileDescriptor(SharedPtr<VFS::Inode> _inode, usize _offset, int _flags)
|
||||
: inode(_inode), offset(_offset), flags(_flags)
|
||||
{
|
||||
inode->fs()->add_handle();
|
||||
}
|
||||
|
||||
FileDescriptor::FileDescriptor(const FileDescriptor& f) : inode(f.inode), offset(f.offset), flags(f.flags)
|
||||
{
|
||||
inode->fs()->add_handle();
|
||||
}
|
||||
|
||||
FileDescriptor::~FileDescriptor()
|
||||
{
|
||||
inode->fs()->remove_handle();
|
||||
}
|
||||
|
||||
bool FileDescriptor::should_append()
|
||||
{
|
||||
return flags & O_APPEND;
|
||||
|
@ -33,6 +33,10 @@ struct FileDescriptor
|
||||
usize offset { 0 };
|
||||
int flags { 0 };
|
||||
|
||||
FileDescriptor(SharedPtr<VFS::Inode> inode, usize offset, int flags);
|
||||
FileDescriptor(const FileDescriptor& f);
|
||||
~FileDescriptor();
|
||||
|
||||
bool should_append();
|
||||
bool should_block();
|
||||
bool is_writable();
|
||||
|
Loading…
Reference in New Issue
Block a user