mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:07:35 +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:
parent
c029f39895
commit
5f6b6c1665
3 changed files with 14 additions and 16 deletions
|
@ -58,25 +58,26 @@ KResult VFS::mount(NonnullRefPtr<FS>&& file_system, StringView path)
|
||||||
return mount(move(file_system), result.value());
|
return mount(move(file_system), result.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
KResult VFS::unmount(NonnullRefPtr<FS>&& file_system)
|
KResult VFS::unmount(InodeIdentifier guest_inode_id)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
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++) {
|
for (int i = 0; i < m_mounts.size(); ++i) {
|
||||||
auto mount = m_mounts.at(i);
|
auto& mount = m_mounts.at(i);
|
||||||
if (mount.guest_fs().fsid() == file_system.ptr()->fsid()) {
|
if (mount.guest() == guest_inode_id) {
|
||||||
if (mount.guest_fs().prepare_to_unmount() != KSuccess) {
|
auto result = mount.guest_fs().prepare_to_unmount();
|
||||||
dbg() << "VFS: Failed to unmount! Device busy";
|
if (result.is_error()) {
|
||||||
return KResult(-EBUSY);
|
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);
|
m_mounts.remove(i);
|
||||||
return KSuccess;
|
return KSuccess;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dbg() << "VFS: unmount unable to find fsid in m_mounts!";
|
dbg() << "VFS: Nothing mounted on inode " << guest_inode_id;
|
||||||
return KResult(-ENODEV);
|
return KResult(-ENODEV);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
bool mount_root(NonnullRefPtr<FS>&&);
|
bool mount_root(NonnullRefPtr<FS>&&);
|
||||||
KResult mount(NonnullRefPtr<FS>&&, StringView path);
|
KResult mount(NonnullRefPtr<FS>&&, StringView path);
|
||||||
KResult mount(NonnullRefPtr<FS>&&, Custody& mount_point);
|
KResult mount(NonnullRefPtr<FS>&&, Custody& mount_point);
|
||||||
KResult unmount(NonnullRefPtr<FS>&&);
|
KResult unmount(InodeIdentifier guest_inode_id);
|
||||||
|
|
||||||
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base);
|
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base);
|
||||||
KResultOr<NonnullRefPtr<FileDescription>> create(StringView path, int options, mode_t mode, Custody& parent_custody);
|
KResultOr<NonnullRefPtr<FileDescription>> create(StringView path, int options, mode_t mode, Custody& parent_custody);
|
||||||
|
|
|
@ -2811,11 +2811,8 @@ int Process::sys$umount(const char* mountpoint)
|
||||||
if (metadata_or_error.is_error())
|
if (metadata_or_error.is_error())
|
||||||
return metadata_or_error.error();
|
return metadata_or_error.error();
|
||||||
|
|
||||||
auto fsid = metadata_or_error.value().inode.fsid();
|
auto guest_inode_id = metadata_or_error.value().inode;
|
||||||
auto fs = Ext2FS::from_fsid(fsid);
|
return VFS::the().unmount(guest_inode_id);
|
||||||
auto ret = VFS::the().unmount(*fs);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ProcessTracer& Process::ensure_tracer()
|
ProcessTracer& Process::ensure_tracer()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue