mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 22:28:11 +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());
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
bool mount_root(NonnullRefPtr<FS>&&);
|
||||
KResult mount(NonnullRefPtr<FS>&&, StringView path);
|
||||
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>> 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())
|
||||
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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue