aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/filesystem/mount_table.cpp
diff options
context:
space:
mode:
authorMarcel Braun <marcel.braun@ost.ch>2026-03-28 19:16:27 +0100
committerMarcel Braun <marcel.braun@ost.ch>2026-03-28 19:16:27 +0100
commit2864e0b061f923a3c73c608b9c27ca4a7116e27c (patch)
tree7175be5fcaa789e0bfd6d0aeb4e7f6ac756cabf6 /kernel/src/filesystem/mount_table.cpp
parent05269b10e50a80f557c2be475904ff15dc1bbec4 (diff)
parent8a9bf5a90b7f46d5c615b55a3fc418b419db4926 (diff)
downloadteachos-2864e0b061f923a3c73c608b9c27ca4a7116e27c.tar.xz
teachos-2864e0b061f923a3c73c608b9c27ca4a7116e27c.zip
Merge branch 'vfs' into 'develop-BA-FS26'
implement basic vfs See merge request teachos/kernel!16
Diffstat (limited to 'kernel/src/filesystem/mount_table.cpp')
-rw-r--r--kernel/src/filesystem/mount_table.cpp38
1 files changed, 38 insertions, 0 deletions
diff --git a/kernel/src/filesystem/mount_table.cpp b/kernel/src/filesystem/mount_table.cpp
new file mode 100644
index 0000000..b9e57d4
--- /dev/null
+++ b/kernel/src/filesystem/mount_table.cpp
@@ -0,0 +1,38 @@
+#include "kernel/filesystem/mount_table.hpp"
+
+#include "kernel/filesystem/mount.hpp"
+
+#include <kstd/memory>
+
+#include <cstddef>
+#include <string_view>
+
+namespace filesystem
+{
+ void mount_table::add_mount(kstd::shared_ptr<mount> mount)
+ {
+ m_mounts.push_back(mount);
+ }
+
+ auto mount_table::find_longest_prefix_mount(std::string_view path) const -> kstd::shared_ptr<mount>
+ {
+ kstd::shared_ptr<mount> mount_with_longest_prefix = nullptr;
+ std::size_t best_len = 0;
+
+ 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 mount_with_longest_prefix;
+ }
+} // namespace filesystem \ No newline at end of file