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.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.cpp')
| -rw-r--r-- | kernel/src/filesystem/mount.cpp | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/kernel/src/filesystem/mount.cpp b/kernel/src/filesystem/mount.cpp new file mode 100644 index 0000000..ead7479 --- /dev/null +++ b/kernel/src/filesystem/mount.cpp @@ -0,0 +1,90 @@ +#include <kernel/filesystem/mount.hpp> + +#include <kernel/filesystem/dentry.hpp> +#include <kernel/filesystem/filesystem.hpp> + +#include <kapi/system.hpp> + +#include <kstd/memory> +#include <kstd/string> + +#include <cstddef> +#include <string_view> + +namespace kernel::filesystem +{ + mount::mount(kstd::shared_ptr<dentry> const & mount_dentry, kstd::shared_ptr<dentry> const & root_dentry, + kstd::shared_ptr<filesystem> const & fs, kstd::shared_ptr<mount> const & parent_mount, + kstd::shared_ptr<mount> const & source_mount) + : m_mount_dentry(mount_dentry) + , m_root_dentry(root_dentry) + , m_filesystem(fs) + , m_parent_mount(parent_mount) + , m_source_mount(source_mount) + , m_ref_count(0) + { + if (!m_filesystem) + { + kapi::system::panic("[FILESYSTEM] mount initialized with null filesystem."); + } + } + + auto mount::mount_dentry() const -> kstd::shared_ptr<dentry> const & + { + return m_mount_dentry; + } + + auto mount::get_filesystem() const -> kstd::shared_ptr<filesystem> const & + { + return m_filesystem; + } + + auto mount::root_dentry() const -> kstd::shared_ptr<dentry> const & + { + return m_root_dentry; + } + + auto mount::mount_path() const -> kstd::string + { + if (m_mount_dentry) + { + return m_mount_dentry->absolute_path(); + } + return "/"; + } + + auto mount::parent_mount() const -> kstd::shared_ptr<mount> const & + { + return m_parent_mount; + } + + auto mount::source_mount() const -> kstd::shared_ptr<mount> + { + return m_source_mount.lock(); + } + + auto mount::increment_ref_count() -> void + { + m_ref_count += 1; + } + + auto mount::decrement_ref_count() -> void + { + if (m_ref_count == 0) + { + kapi::system::panic("[FILESYSTEM] decrement_ref_count() was called but ref_count is 0"); + } + + m_ref_count -= 1; + } + + auto mount::is_ready_to_unmount() const -> bool + { + return m_ref_count == 0; + } + + auto mount::ref_count() const -> size_t + { + return m_ref_count; + } +} // namespace kernel::filesystem
\ No newline at end of file |
