#include #include #include #include #include #include #include #include namespace kernel::filesystem { auto mount_table::has_child_mounts(kstd::shared_ptr const & parent_mount) const -> bool { return std::ranges::any_of( m_mounts, [&parent_mount](auto const & mount) { return mount->get_parent_mount() == parent_mount; }); } 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); } if (auto root_dentry = mount->get_root_dentry()) { root_dentry->set_flag(dentry::dentry_flags::is_mount_root); } } auto mount_table::remove_mount(std::string_view path) -> operation_result { // TODO BA-FS26 check wheter something is open in this mount 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 == m_mounts.end()) { return operation_result::mount_not_found; } auto const & mount = *mount_it; if (has_child_mounts(mount)) { return operation_result::has_child_mounts; } mount->get_mount_dentry()->unset_flag(dentry::dentry_flags::is_mount_point); m_mounts.erase(mount_it); return operation_result::removed; } auto mount_table::find_exact_mount(std::string_view path) const -> kstd::shared_ptr { 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