diff options
| -rw-r--r-- | kernel/include/kernel/filesystem/mount_table.hpp | 7 | ||||
| -rw-r--r-- | kernel/src/filesystem/mount_table.cpp | 24 | ||||
| -rw-r--r-- | kernel/src/filesystem/mount_table.tests.cpp | 37 |
3 files changed, 0 insertions, 68 deletions
diff --git a/kernel/include/kernel/filesystem/mount_table.hpp b/kernel/include/kernel/filesystem/mount_table.hpp index 8e57d9e..59b9503 100644 --- a/kernel/include/kernel/filesystem/mount_table.hpp +++ b/kernel/include/kernel/filesystem/mount_table.hpp @@ -39,13 +39,6 @@ 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. - @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. diff --git a/kernel/src/filesystem/mount_table.cpp b/kernel/src/filesystem/mount_table.cpp index b67e05c..30a94f4 100644 --- a/kernel/src/filesystem/mount_table.cpp +++ b/kernel/src/filesystem/mount_table.cpp @@ -82,30 +82,6 @@ namespace kernel::filesystem return operation_result::removed; } - // TODO BA-FS26 remove? - 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.view()) && (mp == "/" || path.size() == mp.size() || path[mp.size()] == '/'); - bool visible = is_visible_mount(mount, m_mounts); - - if (is_prefix && visible && mp.size() >= best_len) - { - mount_with_longest_prefix = mount; - best_len = mp.size(); - } - } - - 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); diff --git a/kernel/src/filesystem/mount_table.tests.cpp b/kernel/src/filesystem/mount_table.tests.cpp index 732d32f..80772ca 100644 --- a/kernel/src/filesystem/mount_table.tests.cpp +++ b/kernel/src/filesystem/mount_table.tests.cpp @@ -19,12 +19,6 @@ SCENARIO("Mount table construction", "[filesystem][mount_table]") { kernel::filesystem::mount_table table; - THEN("finding any mount returns null") - { - REQUIRE(table.find_longest_prefix_mount("/") == nullptr); - REQUIRE(table.find_longest_prefix_mount("/any/path") == nullptr); - } - THEN("removing any mount returns mount_not_found") { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::mount_not_found); @@ -62,15 +56,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] REQUIRE(mount_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); } - THEN("finding mounts by longest prefix returns the correct mount") - { - REQUIRE(table.find_longest_prefix_mount("/") == mount1); - REQUIRE(table.find_longest_prefix_mount("/file") == mount1); - REQUIRE(table.find_longest_prefix_mount("/mnt") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt/file") == mount2); - REQUIRE(table.find_longest_prefix_mount("/other") == mount1); - } - THEN("finding mounts by exact valid path returns the correct mount") { REQUIRE(table.find_exact_mount("/") == mount1); @@ -87,7 +72,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] { REQUIRE(table.remove_mount("/mnt") == kernel::filesystem::mount_table::operation_result::removed); REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); - REQUIRE(table.find_longest_prefix_mount("/mnt") == mount1); } THEN("removing a mount that does not exist returns mount_not_found") @@ -117,15 +101,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] table.add_mount(mount1); table.add_mount(mount2); - THEN("finding mounts by longest prefix returns the correct mount") - { - REQUIRE(table.find_longest_prefix_mount("/") == mount2); - REQUIRE(table.find_longest_prefix_mount("/file") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt/file") == mount2); - REQUIRE(table.find_longest_prefix_mount("/other") == mount2); - } - THEN("finding mounts by exact valid path returns the correct mount") { REQUIRE(table.find_exact_mount("/") == mount2); @@ -135,7 +110,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::removed); REQUIRE_FALSE(root_dentry2->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); - REQUIRE(table.find_longest_prefix_mount("/") == mount1); } } @@ -168,16 +142,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] table.add_mount(mount2); table.add_mount(mount3); - THEN("finding mounts by path returns the correct mount based on longest prefix") - { - REQUIRE(table.find_longest_prefix_mount("/") == mount1); - REQUIRE(table.find_longest_prefix_mount("/file") == mount1); - REQUIRE(table.find_longest_prefix_mount("/mnt") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt/file") == mount2); - REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == mount3); - REQUIRE(table.find_longest_prefix_mount("/other") == mount1); - } - THEN("removing a mount with child mounts returns has_child_mounts") { REQUIRE(table.remove_mount("/") == kernel::filesystem::mount_table::operation_result::has_child_mounts); @@ -188,7 +152,6 @@ SCENARIO("Adding, finding and removing mounts in the mount table", "[filesystem] { REQUIRE(table.remove_mount("/mnt/submnt") == kernel::filesystem::mount_table::operation_result::removed); REQUIRE_FALSE(root_dentry3->has_flag(kernel::filesystem::dentry::dentry_flags::mounted)); - REQUIRE(table.find_longest_prefix_mount("/mnt/submnt") == mount2); } } } |
