aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/filesystem/mount_table.cpp
diff options
context:
space:
mode:
authorLukas Oesch <lukasoesch20@gmail.com>2026-03-28 17:28:32 +0100
committerLukas Oesch <lukasoesch20@gmail.com>2026-03-28 17:28:32 +0100
commita6f93bf8df0dbfa7d19aa1168bfc8b052e41c42f (patch)
treeb07657406fd2ce67e69819326b0c76e9409ef77c /kernel/src/filesystem/mount_table.cpp
parent4f7ae11655807acf68f49637cc9dd01a03af36d5 (diff)
downloadteachos-a6f93bf8df0dbfa7d19aa1168bfc8b052e41c42f.tar.xz
teachos-a6f93bf8df0dbfa7d19aa1168bfc8b052e41c42f.zip
fix vfs mount with /dev & /a and rootfs & devfs
Diffstat (limited to 'kernel/src/filesystem/mount_table.cpp')
-rw-r--r--kernel/src/filesystem/mount_table.cpp29
1 files changed, 19 insertions, 10 deletions
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 <kstd/memory>
-#include <algorithm>
+#include <cstddef>
+#include <string_view>
namespace filesystem
{
@@ -14,16 +14,25 @@ namespace filesystem
m_mounts.push_back(mount);
}
- auto mount_table::get_root_mount() const -> kstd::shared_ptr<mount>
+ auto mount_table::find_longest_prefix_mount(std::string_view path) const -> kstd::shared_ptr<mount>
{
- 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> mount_with_longest_prefix = nullptr;
+ std::size_t best_len = 0;
- auto mount_table::find_mount_by_dentry(kstd::shared_ptr<dentry> const & dentry) -> kstd::shared_ptr<mount>
- {
- 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