From ac5213633721fcf0e72da814d7ef70c51090c3f9 Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Tue, 12 May 2026 08:51:49 +0200 Subject: refactoring, simplify code --- kernel/src/filesystem/mount_table.cpp | 51 +++++++---------------------------- 1 file changed, 10 insertions(+), 41 deletions(-) (limited to 'kernel/src') diff --git a/kernel/src/filesystem/mount_table.cpp b/kernel/src/filesystem/mount_table.cpp index 74c18ca..daef93e 100644 --- a/kernel/src/filesystem/mount_table.cpp +++ b/kernel/src/filesystem/mount_table.cpp @@ -12,38 +12,6 @@ namespace kernel::filesystem { - namespace - { - auto is_descendant_of(kstd::shared_ptr const & candidate, kstd::shared_ptr const & ancestor) -> bool - { - for (auto current = candidate; current; current = current->get_parent_mount()) - { - if (current == ancestor) - { - return true; - } - } - - return false; - } - - auto is_strict_prefix(std::string_view prefix, std::string_view path) -> bool - { - return prefix != "/" && path.starts_with(prefix) && path.size() > prefix.size() && path[prefix.size()] == '/'; - } - - auto is_visible_mount(kstd::shared_ptr const & candidate, - kstd::vector> const & mounts) -> bool - { - return std::ranges::none_of(mounts, [&](auto const & other) { - // TODO BA-FS26 really correct? - return other != candidate && - is_strict_prefix(other->get_mount_path().view(), candidate->get_mount_path().view()) && - !is_descendant_of(candidate, other); - }); - } - } // namespace - auto mount_table::has_child_mounts(kstd::shared_ptr const & parent_mount) const -> bool { return std::ranges::any_of( @@ -53,6 +21,7 @@ namespace kernel::filesystem void mount_table::add_mount(kstd::shared_ptr const & mount) { m_mounts.push_back(mount); + if (auto mount_dentry = mount->get_mount_dentry()) { mount_dentry->set_flag(dentry::dentry_flags::is_mount_point); @@ -65,11 +34,11 @@ namespace kernel::filesystem auto mount_table::remove_mount(std::string_view path) -> operation_result { - auto mount_it = std::ranges::find_if(std::ranges::reverse_view(m_mounts), [&](auto const & mount) { - return mount->get_mount_path() == path && is_visible_mount(mount, m_mounts); - }); + auto mount_range = + std::ranges::find_last_if(m_mounts, [&](auto const & mount) { return mount->get_mount_path() == path; }); + auto mount_it = mount_range.begin(); - if (mount_it == std::ranges::reverse_view(m_mounts).end()) + if (mount_it == m_mounts.end()) { return operation_result::mount_not_found; } @@ -81,15 +50,15 @@ namespace kernel::filesystem } mount->get_mount_dentry()->unset_flag(dentry::dentry_flags::is_mount_point); - m_mounts.erase(std::ranges::find(m_mounts, mount)); + m_mounts.erase(mount_it); return operation_result::removed; } auto mount_table::find_exact_mount(std::string_view path) const -> kstd::shared_ptr { - 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; + auto mount_range = + std::ranges::find_last_if(m_mounts, [&](auto const & mount) { return mount->get_mount_path() == path; }); + auto mount_it = mount_range.begin(); + return (mount_it != m_mounts.end()) ? *mount_it : nullptr; } } // namespace kernel::filesystem \ No newline at end of file -- cgit v1.2.3