From 78478a651d63ca8cb45d1735144d9a4427c03fc7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Lam?= Date: Sat, 3 Mar 2018 19:35:46 +0100 Subject: [PATCH] Boot: Move CreateVirtualFATFilesystem to Boot_WiiWAD It has nothing to do in the filesystem code. (It also smells like a workaround for some kind of timing issue.) --- Source/Core/Core/Boot/Boot_WiiWAD.cpp | 45 ++++++++++++++++++++++----- Source/Core/Core/IOS/FS/FileIO.cpp | 36 --------------------- Source/Core/Core/IOS/FS/FileIO.h | 1 - 3 files changed, 38 insertions(+), 44 deletions(-) diff --git a/Source/Core/Core/Boot/Boot_WiiWAD.cpp b/Source/Core/Core/Boot/Boot_WiiWAD.cpp index 156c2698a8..5ecfd48471 100644 --- a/Source/Core/Core/Boot/Boot_WiiWAD.cpp +++ b/Source/Core/Core/Boot/Boot_WiiWAD.cpp @@ -2,37 +2,68 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. -#include +#include #include #include -#include "Common/CommonPaths.h" #include "Common/CommonTypes.h" -#include "Common/FileUtil.h" #include "Common/MsgHandler.h" -#include "Common/NandPaths.h" #include "Core/Boot/Boot.h" #include "Core/CommonTitles.h" #include "Core/IOS/ES/ES.h" #include "Core/IOS/ES/Formats.h" -#include "Core/IOS/FS/FileIO.h" +#include "Core/IOS/FS/FileSystem.h" #include "Core/IOS/IOS.h" #include "Core/WiiUtils.h" #include "DiscIO/WiiWad.h" +// cdb.vff is a virtual Fat filesystem created on first launch of sysmenu +// we create it here as it is faster ~3 minutes for me when sysmenu does it +// ~1 second created here +static void CreateVirtualFATFilesystem(std::shared_ptr fs) +{ + constexpr u32 SYSMENU_UID = 0x1000; + constexpr u16 SYSMENU_GID = 0x1; + + const std::string cdb_path = "/title/00000001/00000002/data/cdb.vff"; + fs->CreateFile(SYSMENU_UID, SYSMENU_GID, cdb_path, 0, IOS::HLE::FS::Mode::ReadWrite, + IOS::HLE::FS::Mode::ReadWrite, IOS::HLE::FS::Mode::ReadWrite); + + constexpr size_t CDB_SIZE = 0x01400000; + const auto metadata = fs->GetMetadata(SYSMENU_UID, SYSMENU_GID, cdb_path); + if (!metadata || metadata->size >= CDB_SIZE) + return; + + const auto fd = fs->OpenFile(SYSMENU_UID, SYSMENU_GID, cdb_path, IOS::HLE::FS::Mode::Write); + if (!fd) + return; + + constexpr u8 CDB_HEADER[0x20] = {'V', 'F', 'F', 0x20, 0xfe, 0xff, 1, 0, 1, 0x40, 0, 0, 0, 0x20}; + constexpr u8 CDB_FAT[4] = {0xf0, 0xff, 0xff, 0xff}; + std::vector data(CDB_SIZE); + std::copy_n(CDB_HEADER, sizeof(CDB_HEADER), data.begin()); + std::copy_n(CDB_FAT, sizeof(CDB_FAT), data.begin() + sizeof(CDB_HEADER)); + std::copy_n(CDB_FAT, sizeof(CDB_FAT), data.begin() + 0x14020); + // write the final 0 to 0 file from the second FAT to 20 MiB + data[CDB_SIZE - 1] = 0; + fs->WriteFile(*fd, data.data(), static_cast(data.size())); + fs->Close(*fd); +} + bool CBoot::BootNANDTitle(const u64 title_id) { UpdateStateFlags([](StateFlags* state) { state->type = 0x04; // TYPE_NANDBOOT }); + auto* ios = IOS::HLE::GetIOS(); + if (title_id == Titles::SYSTEM_MENU) - IOS::HLE::CreateVirtualFATFilesystem(); + CreateVirtualFATFilesystem(ios->GetFS()); SetupWiiMemory(); - auto* ios = IOS::HLE::GetIOS(); return ios->GetES()->LaunchTitle(title_id); } diff --git a/Source/Core/Core/IOS/FS/FileIO.cpp b/Source/Core/Core/IOS/FS/FileIO.cpp index d7e3cb3f44..1c35ff6615 100644 --- a/Source/Core/Core/IOS/FS/FileIO.cpp +++ b/Source/Core/Core/IOS/FS/FileIO.cpp @@ -16,7 +16,6 @@ #include "Common/File.h" #include "Common/FileUtil.h" #include "Common/NandPaths.h" -#include "Core/CommonTitles.h" #include "Core/HW/Memmap.h" #include "Core/IOS/IOS.h" @@ -37,41 +36,6 @@ std::string BuildFilename(const std::string& wii_path) return nand_path; } -void CreateVirtualFATFilesystem() -{ - const int cdbSize = 0x01400000; - const std::string cdbPath = - Common::GetTitleDataPath(Titles::SYSTEM_MENU, Common::FROM_SESSION_ROOT) + "cdb.vff"; - if ((int)File::GetSize(cdbPath) < cdbSize) - { - // cdb.vff is a virtual Fat filesystem created on first launch of sysmenu - // we create it here as it is faster ~3 minutes for me when sysmenu does it ~1 second created - // here - const u8 cdbHDR[0x20] = {'V', 'F', 'F', 0x20, 0xfe, 0xff, 1, 0, 1, 0x40, 0, 0, 0, 0x20}; - const u8 cdbFAT[4] = {0xf0, 0xff, 0xff, 0xff}; - - File::IOFile cdbFile(cdbPath, "wb"); - if (cdbFile) - { - cdbFile.WriteBytes(cdbHDR, 0x20); - cdbFile.WriteBytes(cdbFAT, 0x4); - cdbFile.Seek(0x14020, SEEK_SET); - cdbFile.WriteBytes(cdbFAT, 0x4); - // 20 MiB file - cdbFile.Seek(cdbSize - 1, SEEK_SET); - // write the final 0 to 0 file from the second FAT to 20 MiB - cdbFile.WriteBytes(cdbHDR + 14, 1); - if (!cdbFile.IsGood()) - { - cdbFile.Close(); - File::Delete(cdbPath); - } - cdbFile.Flush(); - cdbFile.Close(); - } - } -} - namespace Device { FileIO::FileIO(Kernel& ios, const std::string& device_name) diff --git a/Source/Core/Core/IOS/FS/FileIO.h b/Source/Core/Core/IOS/FS/FileIO.h index df98921f32..f44b76f344 100644 --- a/Source/Core/Core/IOS/FS/FileIO.h +++ b/Source/Core/Core/IOS/FS/FileIO.h @@ -23,7 +23,6 @@ namespace IOS namespace HLE { std::string BuildFilename(const std::string& wii_path); -void CreateVirtualFATFilesystem(); namespace Device {