diff options
| author | marcel.braun <marcel.braun@ost.ch> | 2026-03-23 21:41:37 +0100 |
|---|---|---|
| committer | Lukas Oesch <lukasoesch20@gmail.com> | 2026-03-26 21:18:55 +0100 |
| commit | fbb4eefce7bf825b0406f6fa63de318153a3b95a (patch) | |
| tree | 6be6701f47ecfd1b63dde39f3f8da2b8d953d45e /kernel/src/filesystem/vfs.cpp | |
| parent | 336b25458b75e28c93c0bab23ccd359042f9df41 (diff) | |
| download | teachos-fbb4eefce7bf825b0406f6fa63de318153a3b95a.tar.xz teachos-fbb4eefce7bf825b0406f6fa63de318153a3b95a.zip | |
Implement resolve_path
Diffstat (limited to 'kernel/src/filesystem/vfs.cpp')
| -rw-r--r-- | kernel/src/filesystem/vfs.cpp | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/kernel/src/filesystem/vfs.cpp b/kernel/src/filesystem/vfs.cpp index ece3080..0e8a76d 100644 --- a/kernel/src/filesystem/vfs.cpp +++ b/kernel/src/filesystem/vfs.cpp @@ -15,6 +15,7 @@ #include <algorithm> #include <optional> +#include <ranges> #include <string_view> namespace filesystem @@ -42,7 +43,6 @@ namespace filesystem if (auto boot_device = storage_mgmt.determine_boot_device()) { m_root_fs = kstd::make_shared<ext2::ext2_filesystem>(); - m_root_fs->mount(boot_device); m_root_dentry = kstd::make_shared<dentry>(nullptr, m_root_fs->root_inode()); @@ -131,7 +131,7 @@ namespace filesystem m_device_nodes.push_back(device_node_entry{device->name().view(), kstd::make_shared<device_inode>(device)}); } - auto vfs::resolve_path(std::string_view path) -> std::optional<dentry> + auto vfs::resolve_path(std::string_view path) -> kstd::shared_ptr<dentry> { // TODO BA-FS26 implement real path resolution with mounts and directories etc. // For now, just support device nodes at /dev/<device_name>. @@ -148,13 +148,49 @@ namespace filesystem if (entry != m_device_nodes.end()) { - return dentry{nullptr, entry->value().node}; + return kstd::make_shared<dentry>(nullptr, entry->value().node); } - return std::nullopt; + return nullptr; } + else if (!path.empty() && path.front() == '/') + { + auto path_parts = + std::views::split(path, '/') | std::views::filter([](auto const & part) { return !part.empty(); }); + auto parent = m_root_dentry; - return std::nullopt; + for (auto const & part : path_parts) + { + if (auto child = parent->find_child(std::string_view{part})) + { + parent = child; + } + else if (auto found_inode = m_root_fs->lookup(parent->get_inode(), std::string_view{part})) + { + auto next_dentry = kstd::make_shared<dentry>(parent, found_inode, std::string_view{part}); + parent->add_child(next_dentry); + parent = next_dentry; + } + else + { + 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; } } // namespace filesystem
\ No newline at end of file |
