aboutsummaryrefslogtreecommitdiff
path: root/kernel/src/filesystem/mount_table.cpp
diff options
context:
space:
mode:
authorLukas Oesch <lukasoesch20@gmail.com>2026-05-12 08:51:49 +0200
committerLukas Oesch <lukasoesch20@gmail.com>2026-05-12 08:51:49 +0200
commitac5213633721fcf0e72da814d7ef70c51090c3f9 (patch)
tree4a88dfc1c2fbab3ce7d670e4289bdaa5df77352d /kernel/src/filesystem/mount_table.cpp
parentcb86b1fdb4656d37937a27343a4971ee5896bd3a (diff)
downloadkernel-ac5213633721fcf0e72da814d7ef70c51090c3f9.tar.xz
kernel-ac5213633721fcf0e72da814d7ef70c51090c3f9.zip
refactoring, simplify code
Diffstat (limited to 'kernel/src/filesystem/mount_table.cpp')
-rw-r--r--kernel/src/filesystem/mount_table.cpp51
1 files changed, 10 insertions, 41 deletions
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<mount> const & candidate, kstd::shared_ptr<mount> 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<mount> const & candidate,
- kstd::vector<kstd::shared_ptr<mount>> 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<mount> 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<mount> 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<mount>
{
- 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