From d1ddf314d65a230c3cc4ee10274f80a60804736e Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 22 Jun 2023 19:57:12 +0200 Subject: [PATCH] kernel: Make pivot_root() reset the parent entry of the new root directory Otherwise it would just be pointing to the old parent fs, and we don't want that. --- kernel/src/fs/VFS.cpp | 1 + kernel/src/fs/VFS.h | 2 ++ kernel/src/fs/ext2/FileSystem.cpp | 5 +++++ kernel/src/fs/ext2/FileSystem.h | 2 ++ kernel/src/fs/tmpfs/FileSystem.cpp | 5 +++++ kernel/src/fs/tmpfs/FileSystem.h | 2 ++ 6 files changed, 17 insertions(+) diff --git a/kernel/src/fs/VFS.cpp b/kernel/src/fs/VFS.cpp index 340eefdd..a4effaa4 100644 --- a/kernel/src/fs/VFS.cpp +++ b/kernel/src/fs/VFS.cpp @@ -217,6 +217,7 @@ namespace VFS g_root_inode = new_root_inode; TRY(new_root_parent_inode->replace_entry(((MountInode*)g_root_inode.ptr())->source(), new_root_path.chars())); ((MountInode*)g_root_inode.ptr())->set_source({}); + g_root_inode->fs()->reset_mount_dir(); return {}; } diff --git a/kernel/src/fs/VFS.h b/kernel/src/fs/VFS.h index cdb5b6ff..8abf7602 100644 --- a/kernel/src/fs/VFS.h +++ b/kernel/src/fs/VFS.h @@ -36,6 +36,8 @@ namespace VFS virtual Result set_mount_dir(SharedPtr parent) = 0; + virtual Result reset_mount_dir() = 0; + virtual bool is_readonly() const { return false; diff --git a/kernel/src/fs/ext2/FileSystem.cpp b/kernel/src/fs/ext2/FileSystem.cpp index 1be95315..31a80ec6 100644 --- a/kernel/src/fs/ext2/FileSystem.cpp +++ b/kernel/src/fs/ext2/FileSystem.cpp @@ -125,4 +125,9 @@ namespace Ext2 { return m_root_inode->replace_entry(inode, ".."); } + + Result FileSystem::reset_mount_dir() + { + return m_root_inode->replace_entry(m_root_inode, ".."); + } } diff --git a/kernel/src/fs/ext2/FileSystem.h b/kernel/src/fs/ext2/FileSystem.h index 812dd079..cd2945fd 100644 --- a/kernel/src/fs/ext2/FileSystem.h +++ b/kernel/src/fs/ext2/FileSystem.h @@ -149,6 +149,8 @@ namespace Ext2 Result set_mount_dir(SharedPtr) override; + Result reset_mount_dir() override; + bool is_readonly() const override { return true; diff --git a/kernel/src/fs/tmpfs/FileSystem.cpp b/kernel/src/fs/tmpfs/FileSystem.cpp index 465fb5f5..e871e2b5 100644 --- a/kernel/src/fs/tmpfs/FileSystem.cpp +++ b/kernel/src/fs/tmpfs/FileSystem.cpp @@ -72,6 +72,11 @@ namespace TmpFS return m_root_inode->replace_entry(parent, ".."); } + Result FileSystem::reset_mount_dir() + { + return m_root_inode->replace_entry(m_root_inode, ".."); + } + void FileSystem::set_root(SharedPtr root) { m_root_inode = root; diff --git a/kernel/src/fs/tmpfs/FileSystem.h b/kernel/src/fs/tmpfs/FileSystem.h index 374b6f44..2542c740 100644 --- a/kernel/src/fs/tmpfs/FileSystem.h +++ b/kernel/src/fs/tmpfs/FileSystem.h @@ -20,6 +20,8 @@ namespace TmpFS Result set_mount_dir(SharedPtr parent) override; + Result reset_mount_dir() override; + static Result> create(); dev_t host_device_id() const override