From 6a555af1f19d2e7a8a76963056ddba6a0cbb253e Mon Sep 17 00:00:00 2001 From: Liav A Date: Sun, 4 Dec 2022 10:27:19 +0200 Subject: [PATCH] Kernel: Add callback on ".." directory entry for a TmpFS root directory --- Kernel/FileSystem/TmpFS/FileSystem.h | 4 +++- Kernel/FileSystem/TmpFS/Inode.cpp | 25 +++++++++++++++++-------- Kernel/FileSystem/TmpFS/Inode.h | 3 +++ 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Kernel/FileSystem/TmpFS/FileSystem.h b/Kernel/FileSystem/TmpFS/FileSystem.h index 13c0fbbb759..29901480952 100644 --- a/Kernel/FileSystem/TmpFS/FileSystem.h +++ b/Kernel/FileSystem/TmpFS/FileSystem.h @@ -32,7 +32,9 @@ private: LockRefPtr m_root_inode; - unsigned m_next_inode_index { 1 }; + // NOTE: We start by assigning InodeIndex of 2, because 0 is invalid and 1 + // is reserved for the root directory inode. + unsigned m_next_inode_index { 2 }; unsigned next_inode_index(); }; diff --git a/Kernel/FileSystem/TmpFS/Inode.cpp b/Kernel/FileSystem/TmpFS/Inode.cpp index da51cf8b715..60c07e8bac2 100644 --- a/Kernel/FileSystem/TmpFS/Inode.cpp +++ b/Kernel/FileSystem/TmpFS/Inode.cpp @@ -18,6 +18,18 @@ TmpFSInode::TmpFSInode(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr> TmpFSInode::try_create(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr parent) @@ -27,13 +39,7 @@ ErrorOr> TmpFSInode::try_create(TmpFS& fs, InodeMe ErrorOr> TmpFSInode::try_create_root(TmpFS& fs) { - InodeMetadata metadata; - auto now = kgettimeofday(); - metadata.atime = now; - metadata.ctime = now; - metadata.mtime = now; - metadata.mode = S_IFDIR | S_ISVTX | 0777; - return try_create(fs, metadata, {}); + return adopt_nonnull_lock_ref_or_enomem(new (nothrow) TmpFSInode(fs)); } InodeMetadata TmpFSInode::metadata() const @@ -51,8 +57,11 @@ ErrorOr TmpFSInode::traverse_as_directory(Function(FileSyste return ENOTDIR; TRY(callback({ "."sv, identifier(), 0 })); - if (auto parent = m_parent.strong_ref()) + if (m_root_directory_inode) { + TRY(callback({ ".."sv, identifier(), 0 })); + } else if (auto parent = m_parent.strong_ref()) { TRY(callback({ ".."sv, parent->identifier(), 0 })); + } for (auto& child : m_children) { TRY(callback({ child.name->view(), child.inode->identifier(), 0 })); diff --git a/Kernel/FileSystem/TmpFS/Inode.h b/Kernel/FileSystem/TmpFS/Inode.h index 5f9c472833f..84af878f773 100644 --- a/Kernel/FileSystem/TmpFS/Inode.h +++ b/Kernel/FileSystem/TmpFS/Inode.h @@ -38,6 +38,7 @@ public: private: TmpFSInode(TmpFS& fs, InodeMetadata const& metadata, LockWeakPtr parent); + explicit TmpFSInode(TmpFS& fs); static ErrorOr> try_create(TmpFS&, InodeMetadata const& metadata, LockWeakPtr parent); static ErrorOr> try_create_root(TmpFS&); @@ -84,6 +85,8 @@ private: NonnullLockRefPtr m_content_buffer_vmobject; }; + bool const m_root_directory_inode { false }; + DataBlock::List m_blocks; Child::List m_children; };