From d216f780a4b4bddc3d39772824a870080d81a875 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 4 Aug 2023 22:34:58 +0300 Subject: [PATCH] Kernel/VFS: Remove the find_mount_for_guest method We don't really need this method anymore, because we could just try to find the mount entry based on the given mount point host custody. This also allows us to remove the is_vfs_root and root_inode_id methods from the VirtualFileSystem class. --- Kernel/FileSystem/VirtualFileSystem.cpp | 24 +----------------------- Kernel/FileSystem/VirtualFileSystem.h | 7 +------ 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index c7ddb99d90..fb62e19dc1 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -94,12 +94,6 @@ UNMAP_AFTER_INIT VirtualFileSystem::VirtualFileSystem() UNMAP_AFTER_INIT VirtualFileSystem::~VirtualFileSystem() = default; -InodeIdentifier VirtualFileSystem::root_inode_id() const -{ - VERIFY(m_root_inode); - return m_root_inode->identifier(); -} - bool VirtualFileSystem::check_matching_absolute_path_hierarchy(Custody const& first_custody, Custody const& second_custody) { // Are both custodies the root mount? @@ -251,7 +245,7 @@ ErrorOr VirtualFileSystem::remount(Custody& mount_point, int new_flags) { dbgln("VirtualFileSystem: Remounting inode {}", mount_point.inode().identifier()); - auto* mount = find_mount_for_guest(mount_point.inode().identifier()); + auto* mount = find_mount_for_host_custody(mount_point); if (!mount) return ENODEV; @@ -400,22 +394,6 @@ auto VirtualFileSystem::find_mount_for_host_custody(Custody const& current_custo }); } -auto VirtualFileSystem::find_mount_for_guest(InodeIdentifier id) -> Mount* -{ - return m_mounts.with([&](auto& mounts) -> Mount* { - for (auto& mount : mounts) { - if (mount.guest().identifier() == id) - return &mount; - } - return nullptr; - }); -} - -bool VirtualFileSystem::is_vfs_root(InodeIdentifier inode) const -{ - return inode == root_inode_id(); -} - ErrorOr VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function(FileSystem::DirectoryEntryView const&)> callback) { return dir_inode.traverse_as_directory([&](auto& entry) -> ErrorOr { diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h index 103c346f7e..ad7c7afb3d 100644 --- a/Kernel/FileSystem/VirtualFileSystem.h +++ b/Kernel/FileSystem/VirtualFileSystem.h @@ -88,8 +88,6 @@ public: ErrorOr for_each_mount(Function(Mount const&)>) const; - InodeIdentifier root_inode_id() const; - void sync_filesystems(); void lock_all_filesystems(); @@ -111,16 +109,13 @@ private: ErrorOr add_file_system_to_mount_table(FileSystem& file_system, Custody& mount_point, int flags); - bool is_vfs_root(InodeIdentifier) const; - ErrorOr traverse_directory_inode(Inode&, Function(FileSystem::DirectoryEntryView const&)>); static bool check_matching_absolute_path_hierarchy(Custody const& first_custody, Custody const& second_custody); bool mount_point_exists_at_custody(Custody& mount_point); - // FIXME: These functions are totally unsafe as someone could unmount the returned Mount underneath us. + // FIXME: This function is totally unsafe as someone could unmount the returned Mount underneath us. Mount* find_mount_for_host_custody(Custody const& current_custody); - Mount* find_mount_for_guest(InodeIdentifier); RefPtr m_root_inode;