diff options
| author | Lukas Oesch <lukas.oesch@ost.ch> | 2026-06-10 10:40:46 +0200 |
|---|---|---|
| committer | Lukas Oesch <lukas.oesch@ost.ch> | 2026-06-10 10:40:46 +0200 |
| commit | 33abd5cf264cb9e34121082105b0bc17b3cf7a36 (patch) | |
| tree | 36b15d53fea04f4f9d9af817100f7ad013bd9b5c /kernel/src/filesystem/mount_table.cpp | |
| parent | d01caf1c4aef3c89c68b9d1cc9fe56445f0860b5 (diff) | |
| parent | 7e27130c342b7299a1d2188a7192a7f17b5ac2ad (diff) | |
| download | kernel-33abd5cf264cb9e34121082105b0bc17b3cf7a36.tar.xz kernel-33abd5cf264cb9e34121082105b0bc17b3cf7a36.zip | |
Merge of BA-FS26 branch into develop
See merge request teachos/kernel!49
Diffstat (limited to 'kernel/src/filesystem/mount_table.cpp')
| -rw-r--r-- | kernel/src/filesystem/mount_table.cpp | 79 |
1 files changed, 79 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..e4baac7 --- /dev/null +++ b/kernel/src/filesystem/mount_table.cpp @@ -0,0 +1,79 @@ +#include <kernel/filesystem/mount_table.hpp> + +#include <kernel/filesystem/dentry.hpp> +#include <kernel/filesystem/mount.hpp> + +#include <kstd/memory> +#include <kstd/vector> + +#include <algorithm> +#include <ranges> +#include <string_view> + +namespace kernel::filesystem +{ + auto mount_table::has_child_mounts(kstd::shared_ptr<mount> const & parent_mount) const -> bool + { + return std::ranges::any_of(m_mounts, + [&parent_mount](auto const & mount) { return mount->parent_mount() == parent_mount; }); + } + + auto mount_table::add_mount(kstd::shared_ptr<mount> const & mount) -> void + { + m_mounts.push_back(mount); + + if (auto source_mount = mount->source_mount()) + { + source_mount->increment_ref_count(); + } + + if (auto mount_dentry = mount->mount_dentry()) + { + mount_dentry->set_flag(dentry::dentry_flags::is_mount_point); + } + } + + auto mount_table::remove_mount(std::string_view path) -> operation_result + { + auto mount_it = find_mount_iterator(path); + if (mount_it == m_mounts.end()) + { + return operation_result::mount_not_found; + } + + auto const & mount = *mount_it; + if (!mount->is_ready_to_unmount()) + { + return operation_result::cannot_be_unmounted; + } + if (has_child_mounts(mount)) + { + return operation_result::has_child_mounts; + } + + if (auto source_mount = mount->source_mount()) + { + source_mount->decrement_ref_count(); + } + + if (auto mount_dentry = mount->mount_dentry()) + { + mount_dentry->unset_flag(dentry::dentry_flags::is_mount_point); + } + + m_mounts.erase(mount_it); + return operation_result::removed; + } + + auto mount_table::find_mount(std::string_view path) const -> kstd::shared_ptr<mount> + { + auto mount_it = find_mount_iterator(path); + return (mount_it != m_mounts.end()) ? *mount_it : nullptr; + } + + auto mount_table::find_mount_iterator(std::string_view path) const + -> kstd::vector<kstd::shared_ptr<mount>>::const_iterator + { + return std::ranges::find_last_if(m_mounts, [&](auto const & mount) { return mount->mount_path() == path; }).begin(); + } +} // namespace kernel::filesystem
\ No newline at end of file |
