diff options
author | Andreas Kling <kling@serenityos.org> | 2021-07-18 02:21:34 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-18 02:21:34 +0200 |
commit | d3cf4cd8f021393a8f95cea39c234013da758a2c (patch) | |
tree | 3636aedc09d026100240bb1da56d24ca18be333b | |
parent | bd37840cf5f9ae554f5edce4178809f2658710a3 (diff) | |
download | serenity-d3cf4cd8f021393a8f95cea39c234013da758a2c.zip |
Kernel/DevFS: Remove redundant DevFS& member from DevFSInode
All Inode subclasses can get to their FileSystem via Inode::fs().
-rw-r--r-- | Kernel/FileSystem/DevFS.cpp | 20 | ||||
-rw-r--r-- | Kernel/FileSystem/DevFS.h | 4 |
2 files changed, 13 insertions, 11 deletions
diff --git a/Kernel/FileSystem/DevFS.cpp b/Kernel/FileSystem/DevFS.cpp index 2cbd16b714..23332fa695 100644 --- a/Kernel/FileSystem/DevFS.cpp +++ b/Kernel/FileSystem/DevFS.cpp @@ -218,12 +218,12 @@ RefPtr<Inode> DevFSDirectoryInode::lookup(StringView) DevFSRootDirectoryInode::DevFSRootDirectoryInode(DevFS& fs) : DevFSDirectoryInode(fs) - , m_parent_fs(fs) { } + KResult DevFSRootDirectoryInode::traverse_as_directory(Function<bool(FileSystem::DirectoryEntryView const&)> callback) const { - MutexLocker locker(m_parent_fs.m_lock); + MutexLocker locker(fs().m_lock); callback({ ".", identifier(), 0 }); callback({ "..", identifier(), 0 }); @@ -244,7 +244,7 @@ KResult DevFSRootDirectoryInode::traverse_as_directory(Function<bool(FileSystem: } RefPtr<Inode> DevFSRootDirectoryInode::lookup(StringView name) { - MutexLocker locker(m_parent_fs.m_lock); + MutexLocker locker(fs().m_lock); for (auto& subdirectory : m_subdirectories) { if (subdirectory.name() == name) return subdirectory; @@ -263,7 +263,7 @@ RefPtr<Inode> DevFSRootDirectoryInode::lookup(StringView name) } KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(StringView name, mode_t mode, dev_t, uid_t, gid_t) { - MutexLocker locker(m_parent_fs.m_lock); + MutexLocker locker(fs().m_lock); InodeMetadata metadata; metadata.mode = mode; @@ -274,15 +274,15 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(StringView } if (name != "pts") return EROFS; - auto new_directory_inode = adopt_ref_if_nonnull(new (nothrow) DevFSPtsDirectoryInode(m_parent_fs)); + auto new_directory_inode = adopt_ref_if_nonnull(new (nothrow) DevFSPtsDirectoryInode(fs())); if (!new_directory_inode) return ENOMEM; if (!m_subdirectories.try_ensure_capacity(m_subdirectories.size() + 1)) return ENOMEM; - if (!m_parent_fs.m_nodes.try_ensure_capacity(m_parent_fs.m_nodes.size() + 1)) + if (!fs().m_nodes.try_ensure_capacity(fs().m_nodes.size() + 1)) return ENOMEM; m_subdirectories.append(*new_directory_inode); - m_parent_fs.m_nodes.append(*new_directory_inode); + fs().m_nodes.append(*new_directory_inode); return KResult(KSuccess); } if (metadata.is_symlink()) { @@ -293,15 +293,15 @@ KResultOr<NonnullRefPtr<Inode>> DevFSRootDirectoryInode::create_child(StringView auto name_kstring = KString::try_create(name); if (!name_kstring) return ENOMEM; - auto new_link_inode = adopt_ref_if_nonnull(new (nothrow) DevFSLinkInode(m_parent_fs, name_kstring.release_nonnull())); + auto new_link_inode = adopt_ref_if_nonnull(new (nothrow) DevFSLinkInode(fs(), name_kstring.release_nonnull())); if (!new_link_inode) return ENOMEM; if (!m_links.try_ensure_capacity(m_links.size() + 1)) return ENOMEM; - if (!m_parent_fs.m_nodes.try_ensure_capacity(m_parent_fs.m_nodes.size() + 1)) + if (!fs().m_nodes.try_ensure_capacity(fs().m_nodes.size() + 1)) return ENOMEM; m_links.append(*new_link_inode); - m_parent_fs.m_nodes.append(*new_link_inode); + fs().m_nodes.append(*new_link_inode); return new_link_inode.release_nonnull(); } return EROFS; diff --git a/Kernel/FileSystem/DevFS.h b/Kernel/FileSystem/DevFS.h index 1b3fc4d4b1..557804e671 100644 --- a/Kernel/FileSystem/DevFS.h +++ b/Kernel/FileSystem/DevFS.h @@ -48,6 +48,9 @@ class DevFSInode : public Inode { public: virtual StringView name() const = 0; + DevFS& fs() { return static_cast<DevFS&>(Inode::fs()); } + DevFS const& fs() const { return static_cast<DevFS const&>(Inode::fs()); } + protected: DevFSInode(DevFS&); virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer& buffer, FileDescription*) const override; @@ -153,7 +156,6 @@ private: NonnullRefPtrVector<DevFSDirectoryInode> m_subdirectories; NonnullRefPtrVector<DevFSLinkInode> m_links; - DevFS& m_parent_fs; }; } |