diff options
Diffstat (limited to 'kernel/filesystem/src/vfs.cpp')
| -rw-r--r-- | kernel/filesystem/src/vfs.cpp | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/kernel/filesystem/src/vfs.cpp b/kernel/filesystem/src/vfs.cpp index 3f2576f..573994a 100644 --- a/kernel/filesystem/src/vfs.cpp +++ b/kernel/filesystem/src/vfs.cpp @@ -2,11 +2,17 @@ #include "kapi/system.hpp" +#include "devices/device.hpp" #include "devices/storage/storage_management.hpp" #include "filesystem/ext2/ext2_filesystem.hpp" #include "filesystem/mount.hpp" +#include <kstd/cstring> + +#include <algorithm> +#include <array> #include <optional> +#include <string_view> namespace filesystem { @@ -17,6 +23,12 @@ namespace filesystem // 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 use kstd::vector when available + constinit auto static filesystems = std::array<std::optional<ext2::ext2_filesystem>, 1>{}; + + // TODO BA-FS26 @Felix + // TODO BA-FS26 depends on the length of ram_disk_device name + constinit std::array<char, 10> device_mount_path = {'/', 'd', 'e', 'v', '/', 'x', 'x', 'x', 'x', '\0'}; } // namespace auto vfs::init() -> void @@ -39,7 +51,9 @@ namespace filesystem active_vfs->m_root_mount = mount{"/", &*root_fs}; - // TODO BA-FS26 mount all the other devices to "/dev/ramxy" + 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); }); + }); } else { @@ -57,4 +71,19 @@ namespace filesystem return *active_vfs; } + auto vfs::make_device_node(devices::device * device) -> void + { + auto device_name = device->name(); + kstd::libc::memcpy(&device_mount_path[5], device_name.data(), device_name.size()); + + // TODO BA-FS26 use kstd::vector and push_back when available + filesystems[0].emplace(ext2::ext2_filesystem{}); + if (filesystems[0]->mount(device) != 0) + { + kapi::system::panic("[FILESYSTEM] Failed to mount device filesystem."); + } + + m_mounts[0] = mount{std::string_view{device_mount_path.data()}, &*filesystems[0]}; + } + } // namespace filesystem
\ No newline at end of file |
