소스 검색

TmpFS: Add "." and ".." entries to all directories

It was so weird not seeing them in "ls -la" output :^)
Andreas Kling 5 년 전
부모
커밋
bb9db9d430
1개의 변경된 파일9개의 추가작업 그리고 4개의 파일을 삭제
  1. 9 4
      Kernel/FileSystem/TmpFS.cpp

+ 9 - 4
Kernel/FileSystem/TmpFS.cpp

@@ -96,7 +96,10 @@ RefPtr<Inode> TmpFS::create_directory(InodeIdentifier parent_id, const String& n
     // Ensure it's a directory.
     mode &= ~0170000;
     mode |= 0040000;
-    return create_inode(parent_id, name, mode, 0, 0, uid, gid, error);
+    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;
 }
 
 TmpFSInode::TmpFSInode(TmpFS& fs, InodeMetadata metadata, InodeIdentifier parent)
@@ -122,7 +125,10 @@ NonnullRefPtr<TmpFSInode> TmpFSInode::create_root(TmpFS& fs)
 {
     InodeMetadata metadata;
     metadata.mode = 0041777;
-    return create(fs, metadata, { fs.fsid(), 1 });
+    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;
 }
 
 InodeMetadata TmpFSInode::metadata() const
@@ -211,8 +217,7 @@ size_t TmpFSInode::directory_entry_count() const
 {
     LOCKER(m_lock);
     ASSERT(is_directory());
-
-    return 2 + m_children.size();
+    return m_children.size();
 }
 
 void TmpFSInode::flush_metadata()