Kernel: Tidy up VirtualFileSystem::mount_root() a little bit

- Return KResult instead of bool
- Use TRY()
This commit is contained in:
Andreas Kling 2021-09-05 14:46:44 +02:00
parent b0f2acbd91
commit 71187d865e
Notes: sideshowbarker 2024-07-18 04:43:10 +09:00
3 changed files with 7 additions and 10 deletions

View File

@ -111,11 +111,11 @@ KResult VirtualFileSystem::unmount(Inode& guest_inode)
});
}
bool VirtualFileSystem::mount_root(FileSystem& fs)
KResult VirtualFileSystem::mount_root(FileSystem& fs)
{
if (m_root_inode) {
dmesgln("VirtualFileSystem: mount_root can't mount another root");
return false;
return EEXIST;
}
Mount mount { fs, nullptr, root_mount_flags };
@ -123,7 +123,7 @@ bool VirtualFileSystem::mount_root(FileSystem& fs)
auto& root_inode = fs.root_inode();
if (!root_inode.is_directory()) {
dmesgln("VirtualFileSystem: root inode ({}) for / is not a directory :(", root_inode.identifier());
return false;
return ENOTDIR;
}
m_root_inode = root_inode;
@ -133,11 +133,8 @@ bool VirtualFileSystem::mount_root(FileSystem& fs)
mounts.append(move(mount));
});
auto custody_or_error = Custody::try_create(nullptr, "", *m_root_inode, root_mount_flags);
if (custody_or_error.is_error())
return false;
m_root_custody = custody_or_error.release_value();
return true;
m_root_custody = TRY(Custody::try_create(nullptr, "", *m_root_inode, root_mount_flags));
return KSuccess;
}
auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount*

View File

@ -42,7 +42,7 @@ public:
VirtualFileSystem();
~VirtualFileSystem();
bool mount_root(FileSystem&);
KResult mount_root(FileSystem&);
KResult mount(FileSystem&, Custody& mount_point, int flags);
KResult bind_mount(Custody& source, Custody& mount_point, int flags);
KResult remount(Custody& mount_point, int new_flags);

View File

@ -320,7 +320,7 @@ void init_stage2(void*)
SB16::detect();
StorageManagement::initialize(kernel_command_line().root_device(), kernel_command_line().is_force_pio());
if (!VirtualFileSystem::the().mount_root(StorageManagement::the().root_filesystem())) {
if (VirtualFileSystem::the().mount_root(StorageManagement::the().root_filesystem()).is_error()) {
PANIC("VirtualFileSystem::mount_root failed");
}