aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--kernel/include/kernel/filesystem/mount_table.hpp10
-rw-r--r--kernel/src/filesystem/mount_table.cpp8
-rw-r--r--kernel/src/filesystem/vfs.cpp10
3 files changed, 20 insertions, 8 deletions
diff --git a/kernel/include/kernel/filesystem/mount_table.hpp b/kernel/include/kernel/filesystem/mount_table.hpp
index 00277ea..8e57d9e 100644
--- a/kernel/include/kernel/filesystem/mount_table.hpp
+++ b/kernel/include/kernel/filesystem/mount_table.hpp
@@ -39,13 +39,19 @@ namespace kernel::filesystem
[[nodiscard]] auto remove_mount(std::string_view path) -> operation_result;
/**
- @brief Finds the mount with the longest prefix matching the given @p path. This method is used to determine which
- mounted filesystem should handle a given path lookup.
+ @brief Finds the mount with the longest prefix matching the given @p path.
@param path The path to match against the mount paths in the table.
@return A pointer to the mount with the longest matching prefix, or a null pointer if no mount matches the path.
*/
[[nodiscard]] auto find_longest_prefix_mount(std::string_view path) const -> kstd::shared_ptr<mount>;
+ /**
+ @brief Finds the mount with the exact mount path matching the given @p path.
+ @param path The path to match against the mount paths in the table.
+ @return A pointer to the mount with the exact matching path, or a null pointer if no mount matches the path.
+ */
+ [[nodiscard]] auto find_exact_mount(std::string_view path) const -> kstd::shared_ptr<mount>;
+
private:
[[nodiscard]] auto has_child_mounts(kstd::shared_ptr<mount> const & parent_mount) const -> bool;
diff --git a/kernel/src/filesystem/mount_table.cpp b/kernel/src/filesystem/mount_table.cpp
index e21e497..965e83b 100644
--- a/kernel/src/filesystem/mount_table.cpp
+++ b/kernel/src/filesystem/mount_table.cpp
@@ -102,4 +102,12 @@ namespace kernel::filesystem
return mount_with_longest_prefix;
}
+
+ auto mount_table::find_exact_mount(std::string_view path) const -> kstd::shared_ptr<mount>
+ {
+ auto reversed_mounts = std::ranges::reverse_view(m_mounts);
+ auto mount_it =
+ std::ranges::find_if(reversed_mounts, [&](auto const & mount) { return mount->get_mount_path() == path; });
+ return (mount_it != reversed_mounts.end()) ? *mount_it : nullptr;
+ }
} // namespace kernel::filesystem \ No newline at end of file
diff --git a/kernel/src/filesystem/vfs.cpp b/kernel/src/filesystem/vfs.cpp
index 7f21a5c..19f5f48 100644
--- a/kernel/src/filesystem/vfs.cpp
+++ b/kernel/src/filesystem/vfs.cpp
@@ -41,7 +41,6 @@ namespace kernel::filesystem
auto vfs::init_internal() -> void
{
- // Mount rootfs at / as the temporary base
auto root_fs = kstd::make_shared<rootfs::filesystem>();
root_fs->mount(nullptr);
@@ -140,8 +139,8 @@ namespace kernel::filesystem
kstd::shared_ptr<filesystem> const & fs) -> void
{
auto mount_path = mount_point_dentry->get_full_path();
-
auto parent_mount = m_mount_table.find_longest_prefix_mount(mount_path.view());
+
auto new_fs_root =
kstd::make_shared<dentry>(mount_point_dentry->get_parent(), fs->root_inode(), mount_point_dentry->get_name());
auto new_mount = kstd::make_shared<mount>(mount_point_dentry, new_fs_root, fs, mount_path.view(), parent_mount);
@@ -156,7 +155,7 @@ namespace kernel::filesystem
}
// TODO BA-FS26 refactor (get mount by path, no more prefix matching)
- auto current_mount = m_mount_table.find_longest_prefix_mount("/");
+ auto current_mount = m_mount_table.find_exact_mount("/");
if (!current_mount)
{
kapi::system::panic("[FILESYSTEM] no root mount found.");
@@ -217,8 +216,7 @@ namespace kernel::filesystem
}
else if (next_dentry->has_flag(dentry::dentry_flags::mounted))
{
- // TODO BA-FS26 really do it like this? or just call "get" without longes_prefix stuff
- current_mount = m_mount_table.find_longest_prefix_mount(next_dentry->get_full_path().view());
+ current_mount = m_mount_table.find_exact_mount(next_dentry->get_full_path().view());
if (!current_mount)
{
kapi::system::panic("[FILESYSTEM] mount for dentry with mounted flag not found.");
@@ -246,7 +244,7 @@ namespace kernel::filesystem
if (path::is_valid_absolute_path(symbolic_link_path))
{
- current_mount = m_mount_table.find_longest_prefix_mount("/");
+ current_mount = m_mount_table.find_exact_mount("/");
current_dentry = current_mount->root_dentry();
}
continue;