diff options
| author | Marcel Braun <marcel.braun@ost.ch> | 2026-05-14 18:03:44 +0200 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-05-16 11:56:07 +0200 |
| commit | 4cc120e7dba5c858a3a0f68b63e91e8d7b831701 (patch) | |
| tree | 40b868ed3ecb539c4dab7c5109f86a934b4cd510 | |
| parent | 146c40b22b834e4bf8d5e1d7256d3071f11d4bf9 (diff) | |
| download | kernel-4cc120e7dba5c858a3a0f68b63e91e8d7b831701.tar.xz kernel-4cc120e7dba5c858a3a0f68b63e91e8d7b831701.zip | |
Refactor do_mount_internal to use target_mount as parameter
| -rw-r--r-- | kernel/include/kernel/filesystem/vfs.hpp | 4 | ||||
| -rw-r--r-- | kernel/src/filesystem/vfs.cpp | 30 |
2 files changed, 16 insertions, 18 deletions
diff --git a/kernel/include/kernel/filesystem/vfs.hpp b/kernel/include/kernel/filesystem/vfs.hpp index dfb8f0e..8515af0 100644 --- a/kernel/include/kernel/filesystem/vfs.hpp +++ b/kernel/include/kernel/filesystem/vfs.hpp @@ -94,8 +94,8 @@ namespace kernel::filesystem [[nodiscard]] auto resolve_path(std::string_view path) -> kstd::shared_ptr<dentry>; [[nodiscard]] auto find_mount(std::string_view path) -> kstd::shared_ptr<mount>; - auto do_mount_internal(kstd::shared_ptr<dentry> const & target_dentry, kstd::shared_ptr<filesystem> const & fs) - -> void; + auto do_mount_internal(kstd::shared_ptr<dentry> const & target_dentry, kstd::shared_ptr<mount> const & target_mount, + kstd::shared_ptr<filesystem> const & fs) -> void; auto graft_persistent_device_fs(kstd::shared_ptr<devfs::filesystem> const & device_fs) -> void; diff --git a/kernel/src/filesystem/vfs.cpp b/kernel/src/filesystem/vfs.cpp index 31ffa42..c395e74 100644 --- a/kernel/src/filesystem/vfs.cpp +++ b/kernel/src/filesystem/vfs.cpp @@ -47,7 +47,8 @@ namespace kernel::filesystem root_fs->mount(nullptr); auto root_fs_root_dentry = kstd::make_shared<dentry>(nullptr, root_fs->root_inode(), "/"); - m_mount_table.add_mount(kstd::make_shared<mount>(nullptr, root_fs_root_dentry, root_fs, nullptr)); + auto root_mount = kstd::make_shared<mount>(nullptr, root_fs_root_dentry, root_fs, nullptr); + m_mount_table.add_mount(root_mount); // mount devfs at /dev (inside rootfs, temporary, will be shadowed) auto device_fs = kstd::make_shared<devfs::filesystem>(); @@ -55,7 +56,7 @@ namespace kernel::filesystem if (auto dev_target_dentry = resolve_path("/dev")) { - do_mount_internal(dev_target_dentry, device_fs); + do_mount_internal(dev_target_dentry, root_mount, device_fs); } else { @@ -69,7 +70,7 @@ namespace kernel::filesystem { if (auto root_dentry = resolve_path("/")) { - do_mount_internal(root_dentry, boot_root_fs); + do_mount_internal(root_dentry, root_mount, boot_root_fs); graft_persistent_device_fs(device_fs); } } @@ -98,13 +99,15 @@ namespace kernel::filesystem return operation_result::invalid_path; } - if (auto target_dentry = resolve_path(target)) + auto [target_dentry, target_mount] = resolve_path_internal(target); + + if (target_dentry && target_mount) { if (auto source_dentry = resolve_path(source)) { if (auto fs = kernel::filesystem::filesystem::probe_and_mount(source_dentry->get_inode())) { - do_mount_internal(target_dentry, fs); + do_mount_internal(target_dentry, target_mount, fs); return operation_result::success; } return operation_result::invalid_filesystem; @@ -135,25 +138,20 @@ namespace kernel::filesystem return operation_result::mount_point_not_found; } - auto vfs::do_mount_internal(kstd::shared_ptr<dentry> const & target_dentry, kstd::shared_ptr<filesystem> const & fs) + auto vfs::do_mount_internal(kstd::shared_ptr<dentry> const & target_dentry, + kstd::shared_ptr<mount> const & target_mount, kstd::shared_ptr<filesystem> const & fs) -> void { - auto parent_mount_dentry = target_dentry->find_mount_root_dentry(); - kstd::shared_ptr<mount> parent_mount = nullptr; - if (parent_mount_dentry) - { - parent_mount = m_mount_table.find_exact_mount(parent_mount_dentry->get_absolute_path().view()); - } - auto new_fs_root = kstd::make_shared<dentry>(target_dentry->get_parent(), fs->root_inode(), target_dentry->get_name()); - auto new_mount = kstd::make_shared<mount>(target_dentry, new_fs_root, fs, parent_mount); + auto new_mount = kstd::make_shared<mount>(target_dentry, new_fs_root, fs, target_mount); m_mount_table.add_mount(new_mount); } auto vfs::graft_persistent_device_fs(kstd::shared_ptr<devfs::filesystem> const & device_fs) -> void { - if (auto new_root_dentry = resolve_path("/")) + auto [new_root_dentry, root_mount] = resolve_path_internal("/"); + if (new_root_dentry && root_mount) { auto dev_dentry = new_root_dentry->find_child("dev"); if (!dev_dentry) @@ -162,7 +160,7 @@ namespace kernel::filesystem new_root_dentry->add_child(dev_dentry); } - do_mount_internal(dev_dentry, device_fs); + do_mount_internal(dev_dentry, root_mount, device_fs); } } |
