diff options
Diffstat (limited to 'kernel/filesystem/src/vfs.cpp')
| -rw-r--r-- | kernel/filesystem/src/vfs.cpp | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/kernel/filesystem/src/vfs.cpp b/kernel/filesystem/src/vfs.cpp index 2ecf847..578fde4 100644 --- a/kernel/filesystem/src/vfs.cpp +++ b/kernel/filesystem/src/vfs.cpp @@ -13,6 +13,7 @@ #include "filesystem/open_file_description.hpp" #include <kstd/cstring> +#include <kstd/memory> #include <algorithm> #include <optional> @@ -23,15 +24,6 @@ namespace filesystem namespace { constinit auto static active_vfs = std::optional<vfs>{}; - - // TODO BA-FS26 @Felix better solution? while dynamic memory not available? - // TODO BA-FS26 remove when dynamic memory available; - constinit auto static root_fs = std::optional<ext2::ext2_filesystem>{}; - - // TODO BA-FS26 remove when dynamic memory available; - constinit auto static temp_device_file = std::optional<device_file>{}; - // TODO BA-FS26 remove when dynamic memory available; - constinit auto static temp_inode_file = std::optional<inode_file>{}; } // namespace auto vfs::init() -> void @@ -46,13 +38,13 @@ namespace filesystem auto storage_mgmt = devices::storage::storage_management::get(); if (auto boot_device = storage_mgmt.determine_boot_device()) { - root_fs.emplace(ext2::ext2_filesystem{}); - if (root_fs->mount(boot_device) != 0) + active_vfs->m_root_fs = kstd::make_shared<ext2::ext2_filesystem>(); + if (active_vfs->m_root_fs->mount(boot_device) != 0) { kapi::system::panic("[FILESYSTEM] Failed to mount root filesystem."); } - active_vfs->m_root_mount = mount{"/", &*root_fs}; + active_vfs->m_root_mount = mount{"/", active_vfs->m_root_fs}; std::ranges::for_each(storage_mgmt.all_controllers(), [&](auto controller) { std::ranges::for_each(controller->all_devices(), [&](auto device) { active_vfs->make_device_node(device); }); @@ -78,39 +70,30 @@ namespace filesystem { if (auto custody = resolve_path(path)) { - auto * node = custody->get_inode(); + auto node = custody->get_inode(); if (node->is_device()) { - temp_device_file.emplace(node->backing_device()); - temp_device_file->open(); - return open_file_description{&*temp_device_file}; + auto current_device_file = kstd::make_shared<device_file>(node->backing_device()); + current_device_file->open(); + return open_file_description{current_device_file}; } - temp_inode_file.emplace(node); - temp_inode_file->open(); - return open_file_description{&*temp_inode_file}; + auto current_inode_file = kstd::make_shared<inode_file>(node); + current_inode_file->open(); + return open_file_description{current_inode_file}; } return std::nullopt; } - auto vfs::make_device_node(devices::device * device) -> void + auto vfs::make_device_node(kstd::shared_ptr<devices::device> device) -> void { if (!device) { kapi::system::panic("[FILESYSTEM] make_device_node called with null device."); } - auto const device_name = device->name(); - - // TODO BA-FS26 this logic isn't needed anymore when kstd::vector available, just use push_back - auto const slot = std::ranges::find_if(m_device_nodes, [](auto const & entry) { return !entry.has_value(); }); - if (slot == m_device_nodes.end()) - { - kapi::system::panic("[FILESYSTEM] No free slot available for device nodes."); - } - - slot->emplace(device_node_entry{device_name, inode{device}}); + m_device_nodes.push_back(device_node_entry{device->name(), kstd::make_shared<inode>(device)}); } auto vfs::resolve_path(std::string_view path) -> std::optional<custody> @@ -128,7 +111,7 @@ namespace filesystem if (entry != m_device_nodes.end()) { - return custody{nullptr, &entry->value().node}; + return custody{static_cast<kstd::shared_ptr<custody>>(nullptr), entry->value().node}; } return std::nullopt; |
