diff options
| author | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-24 18:52:41 +0100 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-26 21:19:03 +0100 |
| commit | 7351349f296f100f10db62b5a834a971fbe51473 (patch) | |
| tree | 297c9cd647c36fad6909ce71ce714a8d737498da /kernel | |
| parent | a2ac8770937a28d0d4c674e25c9b3c77802a5c9e (diff) | |
| download | teachos-7351349f296f100f10db62b5a834a971fbe51473.tar.xz teachos-7351349f296f100f10db62b5a834a971fbe51473.zip | |
small refactoring
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/src/filesystem/mount_table.cpp | 6 | ||||
| -rw-r--r-- | kernel/src/filesystem/vfs.cpp | 36 |
2 files changed, 13 insertions, 29 deletions
diff --git a/kernel/src/filesystem/mount_table.cpp b/kernel/src/filesystem/mount_table.cpp index 0e9a53d..b4a906b 100644 --- a/kernel/src/filesystem/mount_table.cpp +++ b/kernel/src/filesystem/mount_table.cpp @@ -18,11 +18,11 @@ namespace filesystem auto mount_table::find_mount_by_dentry(kstd::shared_ptr<dentry> const & dentry) -> kstd::shared_ptr<mount> { - auto found = + auto it = std::ranges::find_if(m_mounts, [&](auto const & mount) { return mount->get_dentry().get() == dentry.get(); }); - if (found != m_mounts.end()) + if (it != m_mounts.end()) { - return *found; + return *it; } kapi::system::panic("[FILESYSTEM] dentry has mount flag set but no corresponding mount found."); } diff --git a/kernel/src/filesystem/vfs.cpp b/kernel/src/filesystem/vfs.cpp index c77736a..78dec77 100644 --- a/kernel/src/filesystem/vfs.cpp +++ b/kernel/src/filesystem/vfs.cpp @@ -39,7 +39,6 @@ namespace filesystem auto vfs::init_internal() -> void { auto storage_mgmt = devices::storage::storage_management::get(); - // TODO BA-FS26 fix mounting boot_device if (auto boot_device = storage_mgmt.determine_boot_device()) { m_root_fs = kstd::make_shared<ext2::ext2_filesystem>(); @@ -82,9 +81,9 @@ namespace filesystem return nullptr; } - auto vfs::do_mount(std::string_view path, kstd::shared_ptr<filesystem> const & new_filesystem) -> int + auto vfs::do_mount(std::string_view path, kstd::shared_ptr<filesystem> const & filesystem) -> int { - if (!new_filesystem) + if (!filesystem) { return -1; // TODO BA-FS26 panic or errorcode? } @@ -100,22 +99,19 @@ namespace filesystem return -1; // TODO BA-FS26 panic or errorcode? } - auto mount_dentry = resolve_path(path); - - if (!mount_dentry) + if (auto mount_dentry = resolve_path(path)) { - return -1; // mount point path doesn't exist - } + // TODO BA-FS26 check if mount point is already mounted and handle it (unmount old fs, fail, etc.) - // TODO BA-FS26 check if mount point is already mounted and handle it (unmount old fs, fail, etc.) + mount_dentry->set_flag(dentry::dentry_flags::dcache_mounted); + m_mount_table.add_mount(kstd::make_shared<mount>(mount_dentry, filesystem)); - mount_dentry->set_flag(dentry::dentry_flags::dcache_mounted); - m_mount_table.add_mount(kstd::make_shared<mount>(mount_dentry, new_filesystem)); + filesystem->set_root_dentry(kstd::make_shared<dentry>(mount_dentry->get_parent(), filesystem->root_inode())); - new_filesystem->set_root_dentry( - kstd::make_shared<dentry>(mount_dentry->get_parent(), new_filesystem->root_inode())); + return 0; + } - return 0; + return -1; } auto vfs::make_device_node(kstd::shared_ptr<devices::device> const & device) -> void @@ -183,18 +179,6 @@ namespace filesystem return nullptr; } } - // | std::views::transform([this](auto const & part) { - // // TODO BA-FS26 implement real path resolution with mounts and directories etc. - // // For now, just return null for any non-device-node path. - // return std::optional<kstd::shared_ptr<dentry>>{}; - // }) - // | std::views::filter([](auto const & opt) { return opt.has_value(); }) - // | std::views::transform([](auto const & opt) { return opt.value(); }) - // | std::ranges::find_if(m_mount_table, [&](auto const & mount) { - // // TODO BA-FS26 implement real path resolution with mounts and directories etc. - // // For now, just check if the first path component matches a mount point. - // return part == mount.path(); - // }); } return nullptr; |
