From e355d5e6aa84b1ea4de70820159b5f1af13bc6f8 Mon Sep 17 00:00:00 2001 From: Lukas Oesch Date: Sun, 15 Mar 2026 18:32:16 +0100 Subject: implement first draft of make_device_node --- kernel/filesystem/src/vfs.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'kernel/filesystem/src/vfs.cpp') 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 + +#include +#include #include +#include 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{}; + // TODO BA-FS26 use kstd::vector when available + constinit auto static filesystems = std::array, 1>{}; + + // TODO BA-FS26 @Felix + // TODO BA-FS26 depends on the length of ram_disk_device name + constinit std::array 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 -- cgit v1.2.3