1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 17:38:12 +00:00

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".
This commit is contained in:
Andreas Kling 2019-08-17 14:24:50 +02:00
parent c029f39895
commit 5f6b6c1665
3 changed files with 14 additions and 16 deletions

View file

@ -58,25 +58,26 @@ KResult VFS::mount(NonnullRefPtr<FS>&& file_system, StringView path)
return mount(move(file_system), result.value());
}
KResult VFS::unmount(NonnullRefPtr<FS>&& 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);
}