Kernel: Make FileSystem::root_inode() return a plain Inode&

All file system classes are expected to keep their root Inode object
in memory, so this function can safely return an Inode&.
This commit is contained in:
Andreas Kling 2021-07-18 01:50:47 +02:00
parent 58c6d30f6a
commit 1f18558ee2
Notes: sideshowbarker 2024-07-18 08:50:43 +09:00
16 changed files with 20 additions and 21 deletions

View file

@ -61,7 +61,7 @@ bool DevFS::initialize()
return true;
}
NonnullRefPtr<Inode> DevFS::root_inode() const
Inode& DevFS::root_inode()
{
return *m_root_inode;
}

View file

@ -28,7 +28,7 @@ public:
void notify_new_device(Device&);
void notify_device_removal(Device&);
virtual NonnullRefPtr<Inode> root_inode() const override;
virtual Inode& root_inode() override;
private:
DevFS();

View file

@ -51,7 +51,7 @@ static InodeIndex pty_index_to_inode_index(unsigned pty_index)
return pty_index + 2;
}
NonnullRefPtr<Inode> DevPtsFS::root_inode() const
Inode& DevPtsFS::root_inode()
{
return *m_root_inode;
}

View file

@ -25,7 +25,7 @@ public:
virtual bool initialize() override;
virtual StringView class_name() const override { return "DevPtsFS"sv; }
virtual NonnullRefPtr<Inode> root_inode() const override;
virtual Inode& root_inode() override;
static void register_slave_pty(SlavePTY&);
static void unregister_slave_pty(SlavePTY&);

View file

@ -154,7 +154,7 @@ bool Ext2FS::initialize()
return true;
}
NonnullRefPtr<Inode> Ext2FS::root_inode() const
Ext2FSInode& Ext2FS::root_inode()
{
return *m_root_inode;
}

View file

@ -128,7 +128,7 @@ private:
bool flush_super_block();
virtual StringView class_name() const override { return "Ext2FS"sv; }
virtual NonnullRefPtr<Inode> root_inode() const override;
virtual Ext2FSInode& root_inode() override;
RefPtr<Inode> get_inode(InodeIdentifier) const;
KResultOr<NonnullRefPtr<Inode>> create_inode(Ext2FSInode& parent_inode, const String& name, mode_t, dev_t, uid_t, gid_t);
KResult create_directory(Ext2FSInode& parent_inode, const String& name, mode_t, uid_t, gid_t);

View file

@ -33,7 +33,7 @@ public:
virtual bool initialize() = 0;
virtual StringView class_name() const = 0;
virtual NonnullRefPtr<Inode> root_inode() const = 0;
virtual Inode& root_inode() = 0;
virtual bool supports_watchers() const { return false; }
bool is_readonly() const { return m_readonly; }

View file

@ -243,7 +243,7 @@ Plan9FS::ProtocolVersion Plan9FS::parse_protocol_version(const StringView& s) co
return ProtocolVersion::v9P2000;
}
NonnullRefPtr<Inode> Plan9FS::root_inode() const
Inode& Plan9FS::root_inode()
{
return *m_root_inode;
}

View file

@ -26,7 +26,7 @@ public:
virtual bool supports_watchers() const override { return false; }
virtual NonnullRefPtr<Inode> root_inode() const override;
virtual Inode& root_inode() override;
u16 allocate_tag() { return m_next_tag++; }
u32 allocate_fid() { return m_next_fid++; }

View file

@ -64,7 +64,7 @@ bool ProcFS::initialize()
return true;
}
NonnullRefPtr<Inode> ProcFS::root_inode() const
Inode& ProcFS::root_inode()
{
return *m_root_inode;
}

View file

@ -28,7 +28,7 @@ public:
virtual bool initialize() override;
virtual StringView class_name() const override { return "ProcFS"sv; }
virtual NonnullRefPtr<Inode> root_inode() const override;
virtual Inode& root_inode() override;
private:
ProcFS();

View file

@ -80,7 +80,7 @@ bool SysFS::initialize()
return true;
}
NonnullRefPtr<Inode> SysFS::root_inode() const
Inode& SysFS::root_inode()
{
return *m_root_inode;
}

View file

@ -65,7 +65,7 @@ public:
virtual bool initialize() override;
virtual StringView class_name() const override { return "SysFS"sv; }
virtual NonnullRefPtr<Inode> root_inode() const override;
virtual Inode& root_inode() override;
private:
SysFS();

View file

@ -30,10 +30,9 @@ bool TmpFS::initialize()
return !m_root_inode.is_null();
}
NonnullRefPtr<Inode> TmpFS::root_inode() const
Inode& TmpFS::root_inode()
{
VERIFY(!m_root_inode.is_null());
return *m_root_inode;
}

View file

@ -28,7 +28,7 @@ public:
virtual bool supports_watchers() const override { return true; }
virtual NonnullRefPtr<Inode> root_inode() const override;
virtual Inode& root_inode() override;
private:
TmpFS();

View file

@ -121,13 +121,13 @@ bool VirtualFileSystem::mount_root(FileSystem& fs)
Mount mount { fs, nullptr, root_mount_flags };
auto root_inode = fs.root_inode();
if (!root_inode->is_directory()) {
dmesgln("VirtualFileSystem: root inode ({}) for / is not a directory :(", root_inode->identifier());
auto& root_inode = fs.root_inode();
if (!root_inode.is_directory()) {
dmesgln("VirtualFileSystem: root inode ({}) for / is not a directory :(", root_inode.identifier());
return false;
}
m_root_inode = move(root_inode);
m_root_inode = root_inode;
dmesgln("VirtualFileSystem: mounted root from {} ({})", fs.class_name(), static_cast<FileBackedFileSystem&>(fs).file_description().absolute_path());
m_mounts.append(move(mount));
@ -172,7 +172,7 @@ KResult VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function<b
resolved_inode = entry.inode;
// FIXME: This is now broken considering chroot and bind mounts.
bool is_root_inode = dir_inode.identifier() == dir_inode.fs().root_inode()->identifier();
bool is_root_inode = dir_inode.identifier() == dir_inode.fs().root_inode().identifier();
if (is_root_inode && !is_vfs_root(dir_inode.identifier()) && entry.name == "..") {
auto mount = find_mount_for_guest(dir_inode.identifier());
VERIFY(mount);