@brief 文件系统子系统初始化入口
| 15 | |
| 16 | /// @brief 文件系统子系统初始化入口 |
| 17 | auto FileSystemInit() -> void { |
| 18 | // 初始化 VFS |
| 19 | auto init_result = vfs::Init(); |
| 20 | if (!init_result.has_value()) { |
| 21 | klog::Err("FileSystemInit: vfs::Init failed: {}", |
| 22 | init_result.error().message()); |
| 23 | return; |
| 24 | } |
| 25 | |
| 26 | // 创建 ramfs 根文件系统并挂载到 "/" |
| 27 | static ramfs::RamFs root_ramfs; |
| 28 | auto mount_result = vfs::GetMountTable().Mount("/", &root_ramfs, nullptr); |
| 29 | if (!mount_result.has_value()) { |
| 30 | klog::Err("FileSystemInit: failed to mount ramfs at /: {}", |
| 31 | mount_result.error().message()); |
| 32 | return; |
| 33 | } |
| 34 | |
| 35 | // Mount FatFS on the first available block device at /mnt/fat |
| 36 | DeviceNode* blk_nodes[4]{}; |
| 37 | const size_t blk_count = DeviceManagerSingleton::instance().FindDevicesByType( |
| 38 | DeviceType::kBlock, blk_nodes, 4); |
| 39 | |
| 40 | if (blk_count > 0 && blk_nodes[0]->block_device != nullptr) { |
| 41 | auto* blk = blk_nodes[0]->block_device; |
| 42 | static fatfs::FatFsFileSystem fat_fs(kRootFsDriveId); |
| 43 | auto fat_mount = fat_fs.Mount(blk); |
| 44 | if (!fat_mount.has_value()) { |
| 45 | klog::Err("FileSystemInit: FatFsFileSystem::Mount failed: {}", |
| 46 | fat_mount.error().message()); |
| 47 | } else { |
| 48 | auto vfs_mount = vfs::GetMountTable().Mount("/mnt/fat", &fat_fs, blk); |
| 49 | if (!vfs_mount.has_value()) { |
| 50 | klog::Err("FileSystemInit: vfs mount at /mnt/fat failed: {}", |
| 51 | vfs_mount.error().message()); |
| 52 | } else { |
| 53 | klog::Info("FileSystemInit: FatFS mounted at /mnt/fat (device: {})", |
| 54 | blk->GetName()); |
| 55 | } |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | klog::Info("FileSystemInit: complete"); |
| 60 | } |
no test coverage detected