diff options
| author | Marcel Braun <marcel.braun@ost.ch> | 2026-05-25 14:13:11 +0200 |
|---|---|---|
| committer | Marcel Braun <marcel.braun@ost.ch> | 2026-05-25 14:13:11 +0200 |
| commit | 0ab7525951b0116241f393090987bedc07a18c33 (patch) | |
| tree | fdd1d16c7de4f35dfc6d527cb9caa554e0db2c0c /kernel/include | |
| parent | 093074d5209f2d0062be79059f5881ee051c07d0 (diff) | |
| parent | adb1b5f2d6858097227fa610e86d1152b79d0bfa (diff) | |
| download | kernel-0ab7525951b0116241f393090987bedc07a18c33.tar.xz kernel-0ab7525951b0116241f393090987bedc07a18c33.zip | |
Merge branch 'improve-mount-reference-count' into 'develop-BA-FS26'
Increase reference count of source_mount when one of its files is mounted somewhere
See merge request teachos/kernel!42
Diffstat (limited to 'kernel/include')
| -rw-r--r-- | kernel/include/kernel/filesystem/mount.hpp | 17 | ||||
| -rw-r--r-- | kernel/include/kernel/filesystem/vfs.hpp | 7 |
2 files changed, 15 insertions, 9 deletions
diff --git a/kernel/include/kernel/filesystem/mount.hpp b/kernel/include/kernel/filesystem/mount.hpp index 4ce374f..53d7f6d 100644 --- a/kernel/include/kernel/filesystem/mount.hpp +++ b/kernel/include/kernel/filesystem/mount.hpp @@ -24,11 +24,12 @@ namespace kernel::filesystem @param mount_dentry The dentry where the filesystem is mounted. @param root_dentry The root dentry of the mounted filesystem. @param fs The filesystem instance being mounted. - @param mount_path The path at which the filesystem is mounted. - @param parent_mount The parent mount that this mount is attached beneath. + @param parent_mount The mount that contains the mount_dentry. + @param source_mount The mount that the filesystem originates from. */ 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<filesystem> const & fs, kstd::shared_ptr<mount> const & parent_mount, + kstd::shared_ptr<mount> const & source_mount); /** @brief Get the dentry where the filesystem is mounted. @@ -56,15 +57,20 @@ namespace kernel::filesystem [[nodiscard]] auto parent_mount() const -> kstd::shared_ptr<mount> const &; /** + @brief Get the source mount where this mount originates from. + */ + [[nodiscard]] auto source_mount() const -> kstd::shared_ptr<mount>; + + /** @brief Increment the reference count for this mount. */ auto increment_ref_count() -> void; /** @brief Decrement the reference count for this mount. - @return True if the reference count reached zero, false otherwise. + @warning Throws if ref_count is zero. */ - [[nodiscard]] auto decrement_ref_count() -> bool; + auto decrement_ref_count() -> void; /** @brief Check if the mount is ready to be unmounted. @@ -83,6 +89,7 @@ namespace kernel::filesystem kstd::shared_ptr<dentry> m_root_dentry; kstd::shared_ptr<filesystem> m_filesystem{}; kstd::shared_ptr<mount> m_parent_mount{}; + kstd::weak_ptr<mount> m_source_mount{}; std::atomic_size_t m_ref_count; }; } // namespace kernel::filesystem diff --git a/kernel/include/kernel/filesystem/vfs.hpp b/kernel/include/kernel/filesystem/vfs.hpp index aec8bfe..e6f2327 100644 --- a/kernel/include/kernel/filesystem/vfs.hpp +++ b/kernel/include/kernel/filesystem/vfs.hpp @@ -32,8 +32,7 @@ namespace kernel::filesystem non_existent_path = -2, mount_point_not_found = -3, unmount_failed = -4, - invalid_filesystem = -5, - close_failed = -6 + invalid_filesystem = -5 }; /** @@ -103,8 +102,8 @@ namespace kernel::filesystem [[nodiscard]] auto find_mount(std::string_view path) const -> kstd::shared_ptr<mount>; auto do_mount_internal(kstd::shared_ptr<dentry> const & mount_point_dentry, - kstd::shared_ptr<mount> const & parent_mount, kstd::shared_ptr<filesystem> const & fs) - -> void; + kstd::shared_ptr<mount> const & parent_mount, kstd::shared_ptr<filesystem> const & fs, + kstd::shared_ptr<mount> const & source_mount = nullptr) -> void; auto graft_persistent_device_fs(kstd::shared_ptr<devfs::filesystem> const & device_fs) -> void; |
