#include "filesystem/vfs.hpp" #include "kapi/system.hpp" #include "devices/storage/storage_management.hpp" #include "filesystem/ext2/ext2_filesystem.hpp" #include "filesystem/mount.hpp" #include namespace filesystem { namespace { constinit auto static active_vfs = std::optional{}; // 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{}; } // namespace auto vfs::init() -> void { if (active_vfs) { kapi::system::panic("[FILESYSTEM] vfs has already been initialized."); } active_vfs.emplace(vfs{}); 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) { kapi::system::panic("[FILESYSTEM] Failed to mount root filesystem."); } active_vfs->m_root_mount = mount{"/", &*root_fs}; // TODO BA-FS26 mount all the other devices to "/dev/ramxy" } else { // TODO BA-FS26 ?? what when no boot_device == no modules loaded?? } } auto vfs::get() -> vfs & { if (!active_vfs) { kapi::system::panic("[FILESYSTEM] vfs has not been initialized."); } return *active_vfs; } } // namespace filesystem