From 80f400a150e1cdc900ac89b70f92349be4b34f33 Mon Sep 17 00:00:00 2001 From: Liav A Date: Fri, 4 Aug 2023 21:57:37 +0300 Subject: [PATCH] Kernel/VFS: Don't resolve root inode mounts when traversing a directory This is not useful, as we have literally zero knowledge about where this inode is actually located at with respect to the entire global path tree so we could easily encounter a case where we do the following: ``` mkdir -p /tmp2 mount /dev/hda /tmp2 ``` and when traversing the /tmp2 directory entries, we will see the root inode of /dev/hda on "/tmp2/tmp2", even if it was not mounted. Therefore, we should just plainly give the raw directory entries as they are written "on the disk". Anything else that needs to exactly know if there's an underlying mounted filesystem, can just use the stat syscall instead. --- Kernel/FileSystem/VirtualFileSystem.cpp | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/Kernel/FileSystem/VirtualFileSystem.cpp b/Kernel/FileSystem/VirtualFileSystem.cpp index b60eb6daea..eabb69b956 100644 --- a/Kernel/FileSystem/VirtualFileSystem.cpp +++ b/Kernel/FileSystem/VirtualFileSystem.cpp @@ -408,21 +408,7 @@ bool VirtualFileSystem::is_vfs_root(InodeIdentifier inode) const ErrorOr VirtualFileSystem::traverse_directory_inode(Inode& dir_inode, Function(FileSystem::DirectoryEntryView const&)> callback) { return dir_inode.traverse_as_directory([&](auto& entry) -> ErrorOr { - InodeIdentifier resolved_inode; - if (auto mount = find_mount_for_host(entry.inode)) - resolved_inode = mount->guest().identifier(); - else - resolved_inode = entry.inode; - - // FIXME: This is now broken considering chroot and bind mounts. - 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); - VERIFY(mount->host()); - resolved_inode = mount->host()->identifier(); - } - TRY(callback({ entry.name, resolved_inode, entry.file_type })); + TRY(callback({ entry.name, entry.inode, entry.file_type })); return {}; }); }