From 4238e2e9be9c3e26c634c09db97d531401b6996b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 11 Jul 2021 00:50:08 +0200 Subject: [PATCH] Kernel: Only allow looking up Mounts by InodeIdentifier Let's simplify the interface by not allowing lookup by Inode&. --- Kernel/FileSystem/VirtualFileSystem.cpp | 24 +++--------------------- Kernel/FileSystem/VirtualFileSystem.h | 2 -- 2 files changed, 3 insertions(+), 23 deletions(-) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 1066de52e4..a82398090b 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -82,7 +82,7 @@ KResult VirtualFileSystem::remount(Custody& mount_point, int new_flags) dbgln("VirtualFileSystem: Remounting {}", mount_point.try_create_absolute_path()); - Mount* mount = find_mount_for_guest(mount_point.inode()); + Mount* mount = find_mount_for_guest(mount_point.inode().identifier()); if (!mount) return ENODEV; @@ -139,15 +139,6 @@ bool VirtualFileSystem::mount_root(FileSystem& fs) return true; } -auto VirtualFileSystem::find_mount_for_host(Inode& inode) -> Mount* -{ - for (auto& mount : m_mounts) { - if (mount.host() == &inode) - return &mount; - } - return nullptr; -} - auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount* { for (auto& mount : m_mounts) { @@ -157,15 +148,6 @@ auto VirtualFileSystem::find_mount_for_host(InodeIdentifier id) -> Mount* return nullptr; } -auto VirtualFileSystem::find_mount_for_guest(Inode& inode) -> Mount* -{ - for (auto& mount : m_mounts) { - if (&mount.guest() == &inode) - return &mount; - } - return nullptr; -} - auto VirtualFileSystem::find_mount_for_guest(InodeIdentifier id) -> Mount* { for (auto& mount : m_mounts) { @@ -192,7 +174,7 @@ KResult VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Functionidentifier(); if (is_root_inode && !is_vfs_root(dir_inode.identifier()) && entry.name == "..") { - auto mount = find_mount_for_guest(dir_inode); + auto mount = find_mount_for_guest(dir_inode.identifier()); VERIFY(mount); VERIFY(mount->host()); resolved_inode = mount->host()->identifier(); @@ -965,7 +947,7 @@ KResultOr> VirtualFileSystem::resolve_path_without_veil(S // See if there's something mounted on the child; in that case // we would need to return the guest inode, not the host inode. - if (auto mount = find_mount_for_host(*child_inode)) { + if (auto mount = find_mount_for_host(child_inode->identifier())) { child_inode = mount->guest(); mount_flags_for_child = mount->flags(); } diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h index 58241db6d2..c0820cc9ea 100644 --- a/Kernel/FileSystem/VirtualFileSystem.h +++ b/Kernel/FileSystem/VirtualFileSystem.h @@ -86,9 +86,7 @@ private: KResult traverse_directory_inode(Inode&, Function); - Mount* find_mount_for_host(Inode&); Mount* find_mount_for_host(InodeIdentifier); - Mount* find_mount_for_guest(Inode&); Mount* find_mount_for_guest(InodeIdentifier); Lock m_lock { "VFSLock" };