diff options
author | Andreas Kling <awesomekling@gmail.com> | 2020-01-10 12:35:18 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2020-01-10 13:16:55 +0100 |
commit | 7380c8ec6e679280581beaf0d994297bb5a6a616 (patch) | |
tree | 83e41e01cd28583f94698171541ca092e4af2332 /Kernel/FileSystem | |
parent | 952bb95baa36d385fa26ea40777dbe2addb1db65 (diff) | |
download | serenity-7380c8ec6e679280581beaf0d994297bb5a6a616.zip |
TmpFS: Synthesize "." and ".." in traverse_as_directory()
As Sergey pointed out, it's silly to have proper entries for . and ..
in TmpFS when we can just synthesize them on the fly.
Note that we have to tolerate removal of . and .. via remove_child()
to keep VFS::rmdir() happy.
Diffstat (limited to 'Kernel/FileSystem')
-rw-r--r-- | Kernel/FileSystem/TmpFS.cpp | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/Kernel/FileSystem/TmpFS.cpp b/Kernel/FileSystem/TmpFS.cpp index e468db749c..ec16969d1e 100644 --- a/Kernel/FileSystem/TmpFS.cpp +++ b/Kernel/FileSystem/TmpFS.cpp @@ -96,10 +96,7 @@ RefPtr<Inode> TmpFS::create_directory(InodeIdentifier parent_id, const String& n // Ensure it's a directory. mode &= ~0170000; mode |= 0040000; - auto new_directory = create_inode(parent_id, name, mode, 0, 0, uid, gid, error); - new_directory->add_child(new_directory->identifier(), ".", 0); - new_directory->add_child(parent_id, "..", 0); - return new_directory; + return create_inode(parent_id, name, mode, 0, 0, uid, gid, error); } TmpFSInode::TmpFSInode(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent) @@ -125,10 +122,7 @@ NonnullRefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs) { InodeMetadata metadata; metadata.mode = 0041777; - auto root_inode = create(fs, metadata, { fs.fsid(), 1 }); - root_inode->add_child(root_inode->identifier(), ".", 0); - root_inode->add_child(root_inode->identifier(), "..", 0); - return root_inode; + return create(fs, metadata, { fs.fsid(), 1 }); } InodeMetadata TmpFSInode::metadata() const @@ -145,6 +139,9 @@ bool TmpFSInode::traverse_as_directory(Function<bool(const FS::DirectoryEntry&)> if (!is_directory()) return false; + callback({ ".", identifier(), 0 }); + callback({ "..", m_parent, 0 }); + for (auto& it : m_children) callback(it.value.entry); return true; @@ -222,7 +219,7 @@ size_t TmpFSInode::directory_entry_count() const { LOCKER(m_lock); ASSERT(is_directory()); - return m_children.size(); + return 2 + m_children.size(); } void TmpFSInode::flush_metadata() @@ -278,6 +275,9 @@ KResult TmpFSInode::remove_child(const StringView& name) LOCKER(m_lock); ASSERT(is_directory()); + if (name == "." || name == "..") + return KSuccess; + auto it = m_children.find(name); if (it == m_children.end()) return KResult(-ENOENT); |