From 1f18558ee23bdfc8ab6d2978c50a8e9eab5c6646 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 18 Jul 2021 01:50:47 +0200 Subject: [PATCH] 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&. --- Kernel/FileSystem/DevFS.cpp | 2 +- Kernel/FileSystem/DevFS.h | 2 +- Kernel/FileSystem/DevPtsFS.cpp | 2 +- Kernel/FileSystem/DevPtsFS.h | 2 +- Kernel/FileSystem/Ext2FileSystem.cpp | 2 +- Kernel/FileSystem/Ext2FileSystem.h | 2 +- Kernel/FileSystem/FileSystem.h | 2 +- Kernel/FileSystem/Plan9FileSystem.cpp | 2 +- Kernel/FileSystem/Plan9FileSystem.h | 2 +- Kernel/FileSystem/ProcFS.cpp | 2 +- Kernel/FileSystem/ProcFS.h | 2 +- Kernel/FileSystem/SysFS.cpp | 2 +- Kernel/FileSystem/SysFS.h | 2 +- Kernel/FileSystem/TmpFS.cpp | 3 +-- Kernel/FileSystem/TmpFS.h | 2 +- Kernel/FileSystem/VirtualFileSystem.cpp | 10 +++++----- 16 files changed, 20 insertions(+), 21 deletions(-) diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp index 2f40a006de3..2cbd16b714d 100644 --- a/Kernel/FileSystem/DevFS.cpp +++ b/Kernel/FileSystem/DevFS.cpp @@ -61,7 +61,7 @@ bool DevFS::initialize() return true; } -NonnullRefPtr DevFS::root_inode() const +Inode& DevFS::root_inode() { return *m_root_inode; } diff --git a/Kernel/FileSystem/DevFS.h b/Kernel/FileSystem/DevFS.h index 5c53f19d665..1b3fc4d4b1b 100644 --- a/Kernel/FileSystem/DevFS.h +++ b/Kernel/FileSystem/DevFS.h @@ -28,7 +28,7 @@ public: void notify_new_device(Device&); void notify_device_removal(Device&); - virtual NonnullRefPtr root_inode() const override; + virtual Inode& root_inode() override; private: DevFS(); diff --git a/Kernel/FileSystem/DevPtsFS.cpp b/Kernel/FileSystem/DevPtsFS.cpp index 5b1ab50ec4c..45ae20fcb4a 100644 --- a/Kernel/FileSystem/DevPtsFS.cpp +++ b/Kernel/FileSystem/DevPtsFS.cpp @@ -51,7 +51,7 @@ static InodeIndex pty_index_to_inode_index(unsigned pty_index) return pty_index + 2; } -NonnullRefPtr DevPtsFS::root_inode() const +Inode& DevPtsFS::root_inode() { return *m_root_inode; } diff --git a/Kernel/FileSystem/DevPtsFS.h b/Kernel/FileSystem/DevPtsFS.h index 24a650ffeb3..1fe8bad9a7d 100644 --- a/Kernel/FileSystem/DevPtsFS.h +++ b/Kernel/FileSystem/DevPtsFS.h @@ -25,7 +25,7 @@ public: virtual bool initialize() override; virtual StringView class_name() const override { return "DevPtsFS"sv; } - virtual NonnullRefPtr root_inode() const override; + virtual Inode& root_inode() override; static void register_slave_pty(SlavePTY&); static void unregister_slave_pty(SlavePTY&); diff --git a/Kernel/FileSystem/Ext2FileSystem.cpp b/Kernel/FileSystem/Ext2FileSystem.cpp index b5e4d58813b..c2b493b2726 100644 --- a/Kernel/FileSystem/Ext2FileSystem.cpp +++ b/Kernel/FileSystem/Ext2FileSystem.cpp @@ -154,7 +154,7 @@ bool Ext2FS::initialize() return true; } -NonnullRefPtr Ext2FS::root_inode() const +Ext2FSInode& Ext2FS::root_inode() { return *m_root_inode; } diff --git a/Kernel/FileSystem/Ext2FileSystem.h b/Kernel/FileSystem/Ext2FileSystem.h index c71eefca761..d3318ab2e4f 100644 --- a/Kernel/FileSystem/Ext2FileSystem.h +++ b/Kernel/FileSystem/Ext2FileSystem.h @@ -128,7 +128,7 @@ private: bool flush_super_block(); virtual StringView class_name() const override { return "Ext2FS"sv; } - virtual NonnullRefPtr root_inode() const override; + virtual Ext2FSInode& root_inode() override; RefPtr get_inode(InodeIdentifier) const; KResultOr> 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); diff --git a/Kernel/FileSystem/FileSystem.h b/Kernel/FileSystem/FileSystem.h index 512a0c165f2..f71f96fdad1 100644 --- a/Kernel/FileSystem/FileSystem.h +++ b/Kernel/FileSystem/FileSystem.h @@ -33,7 +33,7 @@ public: virtual bool initialize() = 0; virtual StringView class_name() const = 0; - virtual NonnullRefPtr root_inode() const = 0; + virtual Inode& root_inode() = 0; virtual bool supports_watchers() const { return false; } bool is_readonly() const { return m_readonly; } diff --git a/Kernel/FileSystem/Plan9FileSystem.cpp b/Kernel/FileSystem/Plan9FileSystem.cpp index 2aef7819888..c8a015ded1b 100644 --- a/Kernel/FileSystem/Plan9FileSystem.cpp +++ b/Kernel/FileSystem/Plan9FileSystem.cpp @@ -243,7 +243,7 @@ Plan9FS::ProtocolVersion Plan9FS::parse_protocol_version(const StringView& s) co return ProtocolVersion::v9P2000; } -NonnullRefPtr Plan9FS::root_inode() const +Inode& Plan9FS::root_inode() { return *m_root_inode; } diff --git a/Kernel/FileSystem/Plan9FileSystem.h b/Kernel/FileSystem/Plan9FileSystem.h index ba26834c59c..aae3aa7447d 100644 --- a/Kernel/FileSystem/Plan9FileSystem.h +++ b/Kernel/FileSystem/Plan9FileSystem.h @@ -26,7 +26,7 @@ public: virtual bool supports_watchers() const override { return false; } - virtual NonnullRefPtr root_inode() const override; + virtual Inode& root_inode() override; u16 allocate_tag() { return m_next_tag++; } u32 allocate_fid() { return m_next_fid++; } diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index c134039e819..8aea1d979f7 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -64,7 +64,7 @@ bool ProcFS::initialize() return true; } -NonnullRefPtr ProcFS::root_inode() const +Inode& ProcFS::root_inode() { return *m_root_inode; } diff --git a/Kernel/FileSystem/ProcFS.h b/Kernel/FileSystem/ProcFS.h index a477ccd304a..51d08108e0d 100644 --- a/Kernel/FileSystem/ProcFS.h +++ b/Kernel/FileSystem/ProcFS.h @@ -28,7 +28,7 @@ public: virtual bool initialize() override; virtual StringView class_name() const override { return "ProcFS"sv; } - virtual NonnullRefPtr root_inode() const override; + virtual Inode& root_inode() override; private: ProcFS(); diff --git a/Kernel/FileSystem/SysFS.cpp b/Kernel/FileSystem/SysFS.cpp index 1dc08a135bf..40c33ff7d23 100644 --- a/Kernel/FileSystem/SysFS.cpp +++ b/Kernel/FileSystem/SysFS.cpp @@ -80,7 +80,7 @@ bool SysFS::initialize() return true; } -NonnullRefPtr SysFS::root_inode() const +Inode& SysFS::root_inode() { return *m_root_inode; } diff --git a/Kernel/FileSystem/SysFS.h b/Kernel/FileSystem/SysFS.h index b31d5cc749a..a02887ff4b6 100644 --- a/Kernel/FileSystem/SysFS.h +++ b/Kernel/FileSystem/SysFS.h @@ -65,7 +65,7 @@ public: virtual bool initialize() override; virtual StringView class_name() const override { return "SysFS"sv; } - virtual NonnullRefPtr root_inode() const override; + virtual Inode& root_inode() override; private: SysFS(); diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp index 979e9d4c6f7..8758601dd1a 100644 --- a/Kernel/FileSystem/TmpFS.cpp +++ b/Kernel/FileSystem/TmpFS.cpp @@ -30,10 +30,9 @@ bool TmpFS::initialize() return !m_root_inode.is_null(); } -NonnullRefPtr TmpFS::root_inode() const +Inode& TmpFS::root_inode() { VERIFY(!m_root_inode.is_null()); - return *m_root_inode; } diff --git a/Kernel/FileSystem/TmpFS.h b/Kernel/FileSystem/TmpFS.h index 4e30ec236fa..c57a5e23ecb 100644 --- a/Kernel/FileSystem/TmpFS.h +++ b/Kernel/FileSystem/TmpFS.h @@ -28,7 +28,7 @@ public: virtual bool supports_watchers() const override { return true; } - virtual NonnullRefPtr root_inode() const override; + virtual Inode& root_inode() override; private: TmpFS(); diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index 1e55006abf1..25e1c0b904c 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -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(fs).file_description().absolute_path()); m_mounts.append(move(mount)); @@ -172,7 +172,7 @@ KResult VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Functionidentifier(); + 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);