mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 17:45:09 +00:00
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:
parent
4d77cdf9a8
commit
1e6ab0ed22
2 changed files with 15 additions and 27 deletions
|
@ -38,28 +38,17 @@ InodeIdentifier VFS::root_inode_id() const
|
||||||
return m_root_inode->identifier();
|
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();
|
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
|
// 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));
|
m_mounts.append(move(mount));
|
||||||
mount_point.did_mount_on({});
|
mount_point.did_mount_on({});
|
||||||
return KSuccess;
|
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)
|
KResult VFS::unmount(InodeIdentifier guest_inode_id)
|
||||||
{
|
{
|
||||||
LOCKER(m_lock);
|
LOCKER(m_lock);
|
||||||
|
@ -83,17 +72,17 @@ KResult VFS::unmount(InodeIdentifier guest_inode_id)
|
||||||
return KResult(-ENODEV);
|
return KResult(-ENODEV);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VFS::mount_root(NonnullRefPtr<FS>&& file_system)
|
bool VFS::mount_root(FS& file_system)
|
||||||
{
|
{
|
||||||
if (m_root_inode) {
|
if (m_root_inode) {
|
||||||
kprintf("VFS: mount_root can't mount another root\n");
|
kprintf("VFS: mount_root can't mount another root\n");
|
||||||
return false;
|
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_id = mount.guest().fs()->root_inode();
|
||||||
auto root_inode = mount->guest().fs()->get_inode(root_inode_id);
|
auto root_inode = mount.guest().fs()->get_inode(root_inode_id);
|
||||||
if (!root_inode->is_directory()) {
|
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());
|
kprintf("VFS: root inode (%02u:%08u) for / is not a directory :(\n", root_inode_id.fsid(), root_inode_id.index());
|
||||||
return false;
|
return false;
|
||||||
|
@ -614,10 +603,10 @@ RefPtr<Inode> VFS::get_inode(InodeIdentifier inode_id)
|
||||||
return inode_id.fs()->get_inode(inode_id);
|
return inode_id.fs()->get_inode(inode_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
VFS::Mount::Mount(RefPtr<Custody>&& host_custody, NonnullRefPtr<FS>&& guest_fs)
|
VFS::Mount::Mount(FS& guest_fs, Custody* host_custody)
|
||||||
: m_guest(guest_fs->root_inode())
|
: m_guest(guest_fs.root_inode())
|
||||||
, m_guest_fs(move(guest_fs))
|
, m_guest_fs(guest_fs)
|
||||||
, m_host_custody(move(host_custody))
|
, m_host_custody(host_custody)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,7 +41,7 @@ class VFS {
|
||||||
public:
|
public:
|
||||||
class Mount {
|
class Mount {
|
||||||
public:
|
public:
|
||||||
Mount(RefPtr<Custody>&&, NonnullRefPtr<FS>&&);
|
Mount(FS&, Custody* host_custody);
|
||||||
|
|
||||||
InodeIdentifier host() const;
|
InodeIdentifier host() const;
|
||||||
InodeIdentifier guest() const { return m_guest; }
|
InodeIdentifier guest() const { return m_guest; }
|
||||||
|
@ -62,9 +62,8 @@ public:
|
||||||
VFS();
|
VFS();
|
||||||
~VFS();
|
~VFS();
|
||||||
|
|
||||||
bool mount_root(NonnullRefPtr<FS>&&);
|
bool mount_root(FS&);
|
||||||
KResult mount(NonnullRefPtr<FS>&&, StringView path);
|
KResult mount(FS&, Custody& mount_point);
|
||||||
KResult mount(NonnullRefPtr<FS>&&, Custody& mount_point);
|
|
||||||
KResult unmount(InodeIdentifier guest_inode_id);
|
KResult unmount(InodeIdentifier guest_inode_id);
|
||||||
|
|
||||||
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
|
KResultOr<NonnullRefPtr<FileDescription>> open(StringView path, int options, mode_t mode, Custody& base, Optional<UidAndGid> = {});
|
||||||
|
@ -110,7 +109,7 @@ private:
|
||||||
Lock m_lock { "VFSLock" };
|
Lock m_lock { "VFSLock" };
|
||||||
|
|
||||||
RefPtr<Inode> m_root_inode;
|
RefPtr<Inode> m_root_inode;
|
||||||
NonnullOwnPtrVector<Mount> m_mounts;
|
Vector<Mount> m_mounts;
|
||||||
|
|
||||||
RefPtr<Custody> m_root_custody;
|
RefPtr<Custody> m_root_custody;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue