From 5f6b6c16659a25a8379751692c2ffb6c333bd760 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 17 Aug 2019 14:24:50 +0200 Subject: [PATCH] Kernel: Do the umount() by the guest's root inode identifier It was previously possible to unmount a filesystem mounted on /mnt by doing e.g "umount /mnt/some/path". --- Kernel/FileSystem/VirtualFileSystem.cpp | 21 +++++++++++---------- Kernel/FileSystem/VirtualFileSystem.h | 2 +- Kernel/Process.cpp | 7 ++----- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 4053b68c18..3b2b9c5274 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -58,25 +58,26 @@ KResult VFS::mount(NonnullRefPtr&& file_system, StringView path) return mount(move(file_system), result.value()); } -KResult VFS::unmount(NonnullRefPtr&& file_system) +KResult VFS::unmount(InodeIdentifier guest_inode_id) { LOCKER(m_lock); - dbg() << "VFS: unmount called with fsid " << file_system.ptr()->fsid(); + dbg() << "VFS: unmount called with inode " << guest_inode_id; - for (auto i = 0; i < m_mounts.size(); i++) { - auto mount = m_mounts.at(i); - if (mount.guest_fs().fsid() == file_system.ptr()->fsid()) { - if (mount.guest_fs().prepare_to_unmount() != KSuccess) { - dbg() << "VFS: Failed to unmount! Device busy"; - return KResult(-EBUSY); + for (int i = 0; i < m_mounts.size(); ++i) { + auto& mount = m_mounts.at(i); + if (mount.guest() == guest_inode_id) { + auto result = mount.guest_fs().prepare_to_unmount(); + if (result.is_error()) { + dbg() << "VFS: Failed to unmount!"; + return result; } - dbg() << "VFS: found fs " << file_system.ptr()->fsid() << " at mount " << i << "! Unmounting..."; + dbg() << "VFS: found fs " << mount.guest_fs().fsid() << " at mount index " << i << "! Unmounting..."; m_mounts.remove(i); return KSuccess; } } - dbg() << "VFS: unmount unable to find fsid in m_mounts!"; + dbg() << "VFS: Nothing mounted on inode " << guest_inode_id; return KResult(-ENODEV); } diff --git a/Kernel/FileSystem/VirtualFileSystem.h b/Kernel/FileSystem/VirtualFileSystem.h index 8887fba92c..dcce762312 100644 --- a/Kernel/FileSystem/VirtualFileSystem.h +++ b/Kernel/FileSystem/VirtualFileSystem.h @@ -59,7 +59,7 @@ public: bool mount_root(NonnullRefPtr&&); KResult mount(NonnullRefPtr&&, StringView path); KResult mount(NonnullRefPtr&&, Custody& mount_point); - KResult unmount(NonnullRefPtr&&); + KResult unmount(InodeIdentifier guest_inode_id); KResultOr> open(StringView path, int options, mode_t mode, Custody& base); KResultOr> create(StringView path, int options, mode_t mode, Custody& parent_custody); diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 84a169a1c9..bf5c4b0670 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -2811,11 +2811,8 @@ int Process::sys$umount(const char* mountpoint) if (metadata_or_error.is_error()) return metadata_or_error.error(); - auto fsid = metadata_or_error.value().inode.fsid(); - auto fs = Ext2FS::from_fsid(fsid); - auto ret = VFS::the().unmount(*fs); - - return ret; + auto guest_inode_id = metadata_or_error.value().inode; + return VFS::the().unmount(guest_inode_id); } ProcessTracer& Process::ensure_tracer()