mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 12:25:06 +00:00
Kernel: Added unmount ability to VFS
It is now possible to unmount file systems from the VFS via `umount`. It works via looking up the `fsid` of the filesystem from the `Inode`'s metatdata so I'm not sure how fragile it is. It seems to work for now though as something to get us going.
This commit is contained in:
parent
f7251c74a9
commit
bc22456f89
13 changed files with 98 additions and 3 deletions
|
@ -49,6 +49,7 @@ KResult VFS::mount(NonnullRefPtr<FS>&& file_system, Custody& mount_point)
|
|||
|
||||
KResult VFS::mount(NonnullRefPtr<FS>&& file_system, StringView path)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
auto result = resolve_path(path, root_custody());
|
||||
if (result.is_error()) {
|
||||
dbg() << "VFS: mount can't resolve mount point '" << path << "'";
|
||||
|
@ -57,6 +58,28 @@ KResult VFS::mount(NonnullRefPtr<FS>&& file_system, StringView path)
|
|||
return mount(move(file_system), result.value());
|
||||
}
|
||||
|
||||
KResult VFS::unmount(NonnullRefPtr<FS>&& file_system)
|
||||
{
|
||||
LOCKER(m_lock);
|
||||
dbg() << "VFS: unmount called with fsid " << file_system.ptr()->fsid();
|
||||
|
||||
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);
|
||||
}
|
||||
dbg() << "VFS: found fs " << file_system.ptr()->fsid() << " at mount " << i << "! Unmounting...";
|
||||
m_mounts.remove(i);
|
||||
return KSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
dbg() << "VFS: unmount unable to find fsid in m_mounts!";
|
||||
return KResult(-ENODEV);
|
||||
}
|
||||
|
||||
bool VFS::mount_root(NonnullRefPtr<FS>&& file_system)
|
||||
{
|
||||
if (m_root_inode) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue