Kernel: Simplify VFS::Mount handling

No need to pass around RefPtr<>s and NonnullRefPtr<>s and no need to
heap-allocate them.

Also remove VFS::mount(NonnullRefPtr<FS>&&, StringView path) - it has been
unused for a long time.
This commit is contained in:
Sergey Bugaev 2020-01-11 18:05:24 +03:00 committed by Andreas Kling
parent 4d77cdf9a8
commit 1e6ab0ed22
Notes: sideshowbarker 2024-07-19 10:12:02 +09:00
2 changed files with 15 additions and 27 deletions

View File

@ -38,28 +38,17 @@ InodeIdentifier VFS::root_inode_id() const
return m_root_inode->identifier();
}
KResult VFS::mount(NonnullRefPtr<FS>&& file_system, Custody& mount_point)
KResult VFS::mount(FS& file_system, Custody& mount_point)
{
auto& inode = mount_point.inode();
dbg() << "VFS: Mounting " << file_system->class_name() << " at " << mount_point.absolute_path() << " (inode: " << inode.identifier() << ")";
dbg() << "VFS: Mounting " << file_system.class_name() << " at " << mount_point.absolute_path() << " (inode: " << inode.identifier() << ")";
// FIXME: check that this is not already a mount point
auto mount = make<Mount>(mount_point, move(file_system));
Mount mount { file_system, &mount_point };
m_mounts.append(move(mount));
mount_point.did_mount_on({});
return KSuccess;
}
KResult VFS::mount(NonnullRefPtr<FS>&& file_system, StringView path)
{
LOCKER(m_lock);
auto result = resolve_path(path, current->process().root_directory());
if (result.is_error()) {
dbg() << "VFS: mount can't resolve mount point '" << path << "'";
return result.error();
}
return mount(move(file_system), result.value());
}
KResult VFS::unmount(InodeIdentifier guest_inode_id)
{
LOCKER(m_lock);
@ -83,17 +72,17 @@ KResult VFS::unmount(InodeIdentifier guest_inode_id)
return KResult(-ENODEV);
}
bool VFS::mount_root(NonnullRefPtr<FS>&& file_system)
bool VFS::mount_root(FS& file_system)
{
if (m_root_inode) {
kprintf("VFS: mount_root can't mount another root\n");
return false;
}
auto mount = make<Mount>(nullptr, move(file_system));
Mount mount { file_system, nullptr };
auto root_inode_id = mount->guest().fs()->root_inode();
auto root_inode = mount->guest().fs()->get_inode(root_inode_id);
auto root_inode_id = mount.guest().fs()->root_inode();
auto root_inode = mount.guest().fs()->get_inode(root_inode_id);
if (!root_inode->is_directory()) {
kprintf("VFS: root inode (%02u:%08u) for / is not a directory :(\n", root_inode_id.fsid(), root_inode_id.index());
return false;
@ -614,10 +603,10 @@ RefPtr<Inode> VFS::get_inode(InodeIdentifier inode_id)
return inode_id.fs()->get_inode(inode_id);
}
VFS::Mount::Mount(RefPtr<Custody>&& host_custody, NonnullRefPtr<FS>&& guest_fs)
: m_guest(guest_fs->root_inode())
, m_guest_fs(move(guest_fs))
, m_host_custody(move(host_custody))
VFS::Mount::Mount(FS& guest_fs, Custody* host_custody)
: m_guest(guest_fs.root_inode())
, m_guest_fs(guest_fs)
, m_host_custody(host_custody)
{
}

View File

@ -41,7 +41,7 @@ class VFS {
public:
class Mount {
public:
Mount(RefPtr<Custody>&&, NonnullRefPtr<FS>&&);
Mount(FS&, Custody* host_custody);
InodeIdentifier host() const;
InodeIdentifier guest() const { return m_guest; }
@ -62,9 +62,8 @@ public:
VFS();
~VFS();
bool mount_root(NonnullRefPtr<FS>&&);
KResult mount(NonnullRefPtr<FS>&&, StringView path);
KResult mount(NonnullRefPtr<FS>&&, Custody& mount_point);
bool mount_root(FS&);
KResult mount(FS&, Custody& mount_point);
KResult unmount(InodeIdentifier guest_inode_id);
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
@ -110,7 +109,7 @@ private:
Lock m_lock { "VFSLock" };
RefPtr<Inode> m_root_inode;
NonnullOwnPtrVector<Mount> m_mounts;
Vector<Mount> m_mounts;
RefPtr<Custody> m_root_custody;
};