From a6f93bf8df0dbfa7d19aa1168bfc8b052e41c42f Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Sat, 28 Mar 2026 17:28:32 +0100 Subject: fix vfs mount with /dev & /a and rootfs & devfs --- kernel/src/filesystem/mount_table.cpp | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'kernel/src/filesystem/mount_table.cpp') diff --git a/kernel/src/filesystem/mount_table.cpp b/kernel/src/filesystem/mount_table.cpp index 681c2b9..b9e57d4 100644 --- a/kernel/src/filesystem/mount_table.cpp +++ b/kernel/src/filesystem/mount_table.cpp @@ -1,11 +1,11 @@ #include "kernel/filesystem/mount_table.hpp" -#include "kernel/filesystem/dentry.hpp" #include "kernel/filesystem/mount.hpp" #include -#include +#include +#include namespace filesystem { @@ -14,16 +14,25 @@ namespace filesystem m_mounts.push_back(mount); } - auto mount_table::get_root_mount() const -> kstd::shared_ptr + auto mount_table::find_longest_prefix_mount(std::string_view path) const -> kstd::shared_ptr { - auto it = std::ranges::find_if(m_mounts, [](auto const & mount) { return mount->get_mount_dentry() == nullptr; }); - return it != m_mounts.end() ? *it : nullptr; - } + kstd::shared_ptr mount_with_longest_prefix = nullptr; + std::size_t best_len = 0; - auto mount_table::find_mount_by_dentry(kstd::shared_ptr const & dentry) -> kstd::shared_ptr - { - auto it = std::ranges::find_if(m_mounts, [&](auto const & mnt) { return mnt->get_mount_dentry() == dentry; }); + for (auto const & mount : m_mounts) + { + auto mp = mount->get_mount_path(); + + // /a/b/c should match /a/b but not /a/bb or /a/b/c/d, / should match everything + bool is_prefix = path.starts_with(mp) && (mp == "/" || path.size() == mp.size() || path[mp.size()] == '/'); + + if (is_prefix && mp.size() >= best_len) + { + mount_with_longest_prefix = mount; + best_len = mp.size(); + } + } - return it != m_mounts.end() ? *it : nullptr; + return mount_with_longest_prefix; } } // namespace filesystem \ No newline at end of file -- cgit v1.2.3