diff --git a/externals/dynarmic b/externals/dynarmic index f7d11baa1c..990a569b7a 160000 --- a/externals/dynarmic +++ b/externals/dynarmic @@ -1 +1 @@ -Subproject commit f7d11baa1cba82f7926058bebdeb6b1c23cff8eb +Subproject commit 990a569b7a5f2518fe08682f5ebf8536e5388d66 diff --git a/src/common/common_paths.h b/src/common/common_paths.h index 9bf3efaf27..70f6d410a7 100644 --- a/src/common/common_paths.h +++ b/src/common/common_paths.h @@ -30,7 +30,7 @@ #define CONFIG_DIR "config" #define CACHE_DIR "cache" #define SDMC_DIR "sdmc" -#define NAND_DIR "nand" +#define SAVE_DIR "save" #define SYSDATA_DIR "sysdata" #define LOG_DIR "log" diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 7213abe18d..39f6d07009 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -711,7 +711,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new } #endif paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; - paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP; + paths[D_SAVE_IDX] = paths[D_USER_IDX] + SAVE_DIR DIR_SEP; paths[D_SYSDATA_IDX] = paths[D_USER_IDX] + SYSDATA_DIR DIR_SEP; // TODO: Put the logs in a better location for each OS paths[D_LOGS_IDX] = paths[D_USER_IDX] + LOG_DIR DIR_SEP; @@ -735,7 +735,7 @@ const std::string& GetUserPath(const unsigned int DirIDX, const std::string& new paths[D_CONFIG_IDX] = paths[D_USER_IDX] + CONFIG_DIR DIR_SEP; paths[D_CACHE_IDX] = paths[D_USER_IDX] + CACHE_DIR DIR_SEP; paths[D_SDMC_IDX] = paths[D_USER_IDX] + SDMC_DIR DIR_SEP; - paths[D_NAND_IDX] = paths[D_USER_IDX] + NAND_DIR DIR_SEP; + paths[D_SAVE_IDX] = paths[D_USER_IDX] + SAVE_DIR DIR_SEP; break; } } diff --git a/src/common/file_util.h b/src/common/file_util.h index 5bc7fbf7c5..73670d893e 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -23,7 +23,7 @@ enum { D_CONFIG_IDX, D_CACHE_IDX, D_SDMC_IDX, - D_NAND_IDX, + D_SAVE_IDX, D_SYSDATA_IDX, D_LOGS_IDX, NUM_PATH_INDICES diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h index 295a3133e7..1a32a373b5 100644 --- a/src/core/file_sys/filesystem.h +++ b/src/core/file_sys/filesystem.h @@ -167,35 +167,4 @@ public: virtual ResultVal GetEntryType(const std::string& path) const = 0; }; -class FileSystemFactory : NonCopyable { -public: - virtual ~FileSystemFactory() {} - - /** - * Get a descriptive name for the archive (e.g. "RomFS", "SaveData", etc.) - */ - virtual std::string GetName() const = 0; - - /** - * Tries to open the archive of this type with the specified path - * @param path Path to the archive - * @return An ArchiveBackend corresponding operating specified archive path. - */ - virtual ResultVal> Open(const Path& path) = 0; - - /** - * Deletes the archive contents and then re-creates the base folder - * @param path Path to the archive - * @return ResultCode of the operation, 0 on success - */ - virtual ResultCode Format(const Path& path) = 0; - - /** - * Retrieves the format info about the archive with the specified path - * @param path Path to the archive - * @return Format information about the archive or error code - */ - virtual ResultVal GetFormatInfo(const Path& path) const = 0; -}; - } // namespace FileSys diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp index 84ae0d99b3..946fc0452f 100644 --- a/src/core/file_sys/romfs_factory.cpp +++ b/src/core/file_sys/romfs_factory.cpp @@ -11,28 +11,17 @@ namespace FileSys { -RomFS_Factory::RomFS_Factory(Loader::AppLoader& app_loader) { +RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader) { // Load the RomFS from the app if (Loader::ResultStatus::Success != app_loader.ReadRomFS(romfs_file, data_offset, data_size)) { LOG_ERROR(Service_FS, "Unable to read RomFS!"); } } -ResultVal> RomFS_Factory::Open(const Path& path) { +ResultVal> RomFSFactory::Open(u64 title_id) { + // TODO(DarkLordZach): Use title id. auto archive = std::make_unique(romfs_file, data_offset, data_size); return MakeResult>(std::move(archive)); } -ResultCode RomFS_Factory::Format(const Path& path) { - LOG_ERROR(Service_FS, "Unimplemented Format archive {}", GetName()); - // TODO(bunnei): Find the right error code for this - return ResultCode(-1); -} - -ResultVal RomFS_Factory::GetFormatInfo(const Path& path) const { - LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName()); - // TODO(bunnei): Find the right error code for this - return ResultCode(-1); -} - } // namespace FileSys diff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.h index e0698e6429..c9e20c3ab1 100644 --- a/src/core/file_sys/romfs_factory.h +++ b/src/core/file_sys/romfs_factory.h @@ -15,16 +15,11 @@ namespace FileSys { /// File system interface to the RomFS archive -class RomFS_Factory final : public FileSystemFactory { +class RomFSFactory { public: - explicit RomFS_Factory(Loader::AppLoader& app_loader); + explicit RomFSFactory(Loader::AppLoader& app_loader); - std::string GetName() const override { - return "ArchiveFactory_RomFS"; - } - ResultVal> Open(const Path& path) override; - ResultCode Format(const Path& path) override; - ResultVal GetFormatInfo(const Path& path) const override; + ResultVal> Open(u64 title_id); private: std::shared_ptr romfs_file; diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index f3aa213af9..89a8aad211 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -12,11 +12,20 @@ namespace FileSys { -SaveData_Factory::SaveData_Factory(std::string nand_directory) - : nand_directory(std::move(nand_directory)) {} +std::string SaveStructDebugInfo(SaveStruct save_struct) { + return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}]", + static_cast(save_struct.type), save_struct.title_id, + save_struct.user_id[1], save_struct.user_id[0], save_struct.save_id); +} -ResultVal> SaveData_Factory::Open(const Path& path) { - std::string save_directory = GetFullPath(); +SaveDataFactory::SaveDataFactory(std::string save_directory) + : save_directory(std::move(save_directory)) {} + +ResultVal> SaveDataFactory::Open(SaveDataSpaceId space, + + SaveStruct meta) { + std::string save_directory = + GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); if (!FileUtil::Exists(save_directory)) { // TODO(bunnei): This is a work-around to always create a save data directory if it does not @@ -36,10 +45,12 @@ ResultVal> SaveData_Factory::Open(const Path& return MakeResult>(std::move(archive)); } -ResultCode SaveData_Factory::Format(const Path& path) { - LOG_WARNING(Service_FS, "Format archive {}", GetName()); +ResultCode SaveDataFactory::Format(SaveDataSpaceId space, SaveStruct meta) { + LOG_WARNING(Service_FS, "Formatting save data of space={:01X}, meta={}", static_cast(space), + SaveStructDebugInfo(meta)); // Create the save data directory. - if (!FileUtil::CreateFullPath(GetFullPath())) { + if (!FileUtil::CreateFullPath( + GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id))) { // TODO(Subv): Find the correct error code. return ResultCode(-1); } @@ -47,17 +58,18 @@ ResultCode SaveData_Factory::Format(const Path& path) { return RESULT_SUCCESS; } -ResultVal SaveData_Factory::GetFormatInfo(const Path& path) const { - LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName()); - // TODO(bunnei): Find the right error code for this - return ResultCode(-1); -} +std::string SaveDataFactory::GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, + u128 user_id, u64 save_id) const { + static std::vector space_names = {"sysnand", "usrnand", "sd", "temp"}; + static std::vector type_names = {"system", "user", "bcat", + "device", "temp", "cache"}; -std::string SaveData_Factory::GetFullPath() const { - u64 title_id = Core::CurrentProcess()->program_id; - // TODO(Subv): Somehow obtain this value. - u32 user = 0; - return fmt::format("{}save/{:016X}/{:08X}/", nand_directory, title_id, user); + if (type == SaveDataType::SaveData && title_id == 0) + title_id = Core::CurrentProcess()->program_id; + + return fmt::format("{}{}/{}/{:016X}/{:016X}{:016X}/{:016X}", save_directory, + space_names[static_cast(space)], type_names[static_cast(type)], + title_id, user_id[1], user_id[0], save_id); } } // namespace FileSys diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index 73a42aab6e..1850b4bdc3 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h @@ -12,22 +12,41 @@ namespace FileSys { -/// File system interface to the SaveData archive -class SaveData_Factory final : public FileSystemFactory { -public: - explicit SaveData_Factory(std::string nand_directory); +enum class SaveDataSpaceId : u8 { NandSystem = 0, NandUser = 1, SdCard = 2, TemporaryStorage = 3 }; - std::string GetName() const override { - return "SaveData_Factory"; - } - ResultVal> Open(const Path& path) override; - ResultCode Format(const Path& path) override; - ResultVal GetFormatInfo(const Path& path) const override; +enum class SaveDataType : u8 { + SystemSaveData = 0, + SaveData = 1, + BcatDeliveryCacheStorage = 2, + DeviceSaveData = 3, + TemporaryStorage = 4, + CacheStorage = 5 +}; + +struct SaveStruct { + u64 title_id; + u128 user_id; + u64 save_id; + SaveDataType type; + INSERT_PADDING_BYTES(31); +}; +static_assert(sizeof(SaveStruct) == 0x40, "SaveStruct has incorrect size."); + +std::string SaveStructDebugInfo(SaveStruct save_struct); + +/// File system interface to the SaveData archive +class SaveDataFactory { +public: + explicit SaveDataFactory(std::string save_directory); + + ResultVal> Open(SaveDataSpaceId space, SaveStruct meta); + ResultCode Format(SaveDataSpaceId space, SaveStruct meta); private: - std::string nand_directory; + std::string save_directory; - std::string GetFullPath() const; + std::string GetFullPath(SaveDataSpaceId space, SaveDataType type, u64 title_id, u128 user_id, + u64 save_id) const; }; } // namespace FileSys diff --git a/src/core/file_sys/sdmc_factory.cpp b/src/core/file_sys/sdmc_factory.cpp index 2e5ffb764e..ac6f2f9710 100644 --- a/src/core/file_sys/sdmc_factory.cpp +++ b/src/core/file_sys/sdmc_factory.cpp @@ -12,9 +12,9 @@ namespace FileSys { -SDMC_Factory::SDMC_Factory(std::string sd_directory) : sd_directory(std::move(sd_directory)) {} +SDMCFactory::SDMCFactory(std::string sd_directory) : sd_directory(std::move(sd_directory)) {} -ResultVal> SDMC_Factory::Open(const Path& path) { +ResultVal> SDMCFactory::Open() { // Create the SD Card directory if it doesn't already exist. if (!FileUtil::IsDirectory(sd_directory)) { FileUtil::CreateFullPath(sd_directory); @@ -24,16 +24,4 @@ ResultVal> SDMC_Factory::Open(const Path& pat return MakeResult>(std::move(archive)); } -ResultCode SDMC_Factory::Format(const Path& path) { - LOG_ERROR(Service_FS, "Unimplemented Format archive {}", GetName()); - // TODO(Subv): Find the right error code for this - return ResultCode(-1); -} - -ResultVal SDMC_Factory::GetFormatInfo(const Path& path) const { - LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName()); - // TODO(bunnei): Find the right error code for this - return ResultCode(-1); -} - } // namespace FileSys diff --git a/src/core/file_sys/sdmc_factory.h b/src/core/file_sys/sdmc_factory.h index 93becda255..09bec7fced 100644 --- a/src/core/file_sys/sdmc_factory.h +++ b/src/core/file_sys/sdmc_factory.h @@ -13,16 +13,11 @@ namespace FileSys { /// File system interface to the SDCard archive -class SDMC_Factory final : public FileSystemFactory { +class SDMCFactory { public: - explicit SDMC_Factory(std::string sd_directory); + explicit SDMCFactory(std::string sd_directory); - std::string GetName() const override { - return "SDMC_Factory"; - } - ResultVal> Open(const Path& path) override; - ResultCode Format(const Path& path) override; - ResultVal GetFormatInfo(const Path& path) const override; + ResultVal> Open(); private: std::string sd_directory; diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index a871b3eaa0..b201fcaad1 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -616,15 +616,18 @@ void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; u128 uid = rp.PopRaw(); + FileSys::SaveDataSpaceId space = FileSys::SaveDataSpaceId::NandUser; + FileSys::SaveStruct save_struct = {}; + LOG_WARNING(Service, "(STUBBED) called uid = {:016X}{:016X}", uid[1], uid[0]); IPC::ResponseBuilder rb{ctx, 4}; FileSys::Path unused; - auto savedata = FileSystem::OpenFileSystem(FileSystem::Type::SaveData, unused); + auto savedata = FileSystem::OpenSaveData(space, save_struct); if (savedata.Failed()) { // Create the save data and return an error indicating that the operation was performed. - FileSystem::FormatFileSystem(FileSystem::Type::SaveData); + FileSystem::FormatSaveData(space, save_struct); // TODO(Subv): Find out the correct error code for this. rb.Push(ResultCode(ErrorModule::FS, 40)); } else { diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index f58b518b62..4077e2399f 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -16,57 +16,91 @@ namespace Service::FileSystem { * Map of registered file systems, identified by type. Once an file system is registered here, it * is never removed until UnregisterFileSystems is called. */ -static boost::container::flat_map> filesystem_map; +static std::unique_ptr romfs; +static std::unique_ptr save_data; +static std::unique_ptr sdmc; -ResultCode RegisterFileSystem(std::unique_ptr&& factory, Type type) { - auto result = filesystem_map.emplace(type, std::move(factory)); - - bool inserted = result.second; - ASSERT_MSG(inserted, "Tried to register more than one system with same id code"); - - auto& filesystem = result.first->second; - LOG_DEBUG(Service_FS, "Registered file system {} with id code 0x{:08X}", filesystem->GetName(), - static_cast(type)); +ResultCode RegisterRomFS(std::unique_ptr&& factory) { + ASSERT_MSG(romfs == nullptr, "Tried to register a second RomFS"); + romfs = std::move(factory); + LOG_DEBUG(Service_FS, "Registered RomFS"); return RESULT_SUCCESS; } -ResultVal> OpenFileSystem(Type type, - FileSys::Path& path) { - LOG_TRACE(Service_FS, "Opening FileSystem with type={}", static_cast(type)); - - auto itr = filesystem_map.find(type); - if (itr == filesystem_map.end()) { - // TODO(bunnei): Find a better error code for this - return ResultCode(-1); - } - - return itr->second->Open(path); +ResultCode RegisterSaveData(std::unique_ptr&& factory) { + ASSERT_MSG(romfs == nullptr, "Tried to register a second save data"); + save_data = std::move(factory); + LOG_DEBUG(Service_FS, "Registered save data"); + return RESULT_SUCCESS; } -ResultCode FormatFileSystem(Type type) { - LOG_TRACE(Service_FS, "Formatting FileSystem with type={}", static_cast(type)); +ResultCode RegisterSDMC(std::unique_ptr&& factory) { + ASSERT_MSG(romfs == nullptr, "Tried to register a second SDMC"); + sdmc = std::move(factory); + LOG_DEBUG(Service_FS, "Registered SDMC"); + return RESULT_SUCCESS; +} - auto itr = filesystem_map.find(type); - if (itr == filesystem_map.end()) { +ResultVal> OpenRomFS(u64 title_id) { + LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}", title_id); + + if (romfs == nullptr) { // TODO(bunnei): Find a better error code for this return ResultCode(-1); } - FileSys::Path unused; - return itr->second->Format(unused); + return romfs->Open(title_id); +} + +ResultVal> OpenSaveData( + FileSys::SaveDataSpaceId space, FileSys::SaveStruct save_struct) { + LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}", + static_cast(space), SaveStructDebugInfo(save_struct)); + + if (save_data == nullptr) { + // TODO(bunnei): Find a better error code for this + return ResultCode(-1); + } + + return save_data->Open(space, save_struct); +} + +ResultVal> OpenSDMC() { + LOG_TRACE(Service_FS, "Opening SDMC"); + + if (romfs == nullptr) { + // TODO(bunnei): Find a better error code for this + return ResultCode(-1); + } + + return sdmc->Open(); +} + +ResultCode FormatSaveData(FileSys::SaveDataSpaceId space, FileSys::SaveStruct save_struct) { + LOG_TRACE(Service_FS, "Formatting Save Data for space_id={:01X}, save_struct={}", + static_cast(space), SaveStructDebugInfo(save_struct)); + + if (save_data == nullptr) { + // TODO(bunnei): Find a better error code for this + return ResultCode(-1); + } + + return save_data->Format(space, save_struct); } void RegisterFileSystems() { - filesystem_map.clear(); + romfs = nullptr; + save_data = nullptr; + sdmc = nullptr; - std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX); + std::string save_directory = FileUtil::GetUserPath(D_SAVE_IDX); std::string sd_directory = FileUtil::GetUserPath(D_SDMC_IDX); - auto savedata = std::make_unique(std::move(nand_directory)); - RegisterFileSystem(std::move(savedata), Type::SaveData); + auto savedata = std::make_unique(std::move(save_directory)); + RegisterSaveData(std::move(savedata)); - auto sdcard = std::make_unique(std::move(sd_directory)); - RegisterFileSystem(std::move(sdcard), Type::SDMC); + auto sdcard = std::make_unique(std::move(sd_directory)); + RegisterSDMC(std::move(sdcard)); } void InstallInterfaces(SM::ServiceManager& service_manager) { diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 56d26146e9..86a57f29d9 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -6,12 +6,13 @@ #include #include "common/common_types.h" +#include "core/file_sys/romfs_factory.h" +#include "core/file_sys/savedata_factory.h" +#include "core/file_sys/sdmc_factory.h" #include "core/hle/result.h" namespace FileSys { class FileSystemBackend; -class FileSystemFactory; -class Path; } // namespace FileSys namespace Service { @@ -22,35 +23,22 @@ class ServiceManager; namespace FileSystem { -/// Supported FileSystem types -enum class Type { - RomFS = 1, - SaveData = 2, - SDMC = 3, -}; +ResultCode RegisterRomFS(std::unique_ptr&& factory); +ResultCode RegisterSaveData(std::unique_ptr&& factory); +ResultCode RegisterSDMC(std::unique_ptr&& factory); -/** - * Registers a FileSystem, instances of which can later be opened using its IdCode. - * @param factory FileSystem backend interface to use - * @param type Type used to access this type of FileSystem - */ -ResultCode RegisterFileSystem(std::unique_ptr&& factory, Type type); +// TODO(DarkLordZach): BIS Filesystem +// ResultCode RegisterBIS(std::unique_ptr&& factory); -/** - * Opens a file system - * @param type Type of the file system to open - * @param path Path to the file system, used with Binary paths - * @return FileSys::FileSystemBackend interface to the file system - */ -ResultVal> OpenFileSystem(Type type, - FileSys::Path& path); +ResultVal> OpenRomFS(u64 title_id); +ResultVal> OpenSaveData( + FileSys::SaveDataSpaceId space, FileSys::SaveStruct save_struct); +ResultVal> OpenSDMC(); -/** - * Formats a file system - * @param type Type of the file system to format - * @return ResultCode of the operation - */ -ResultCode FormatFileSystem(Type type); +// TODO(DarkLordZach): BIS Filesystem +// ResultVal> OpenBIS(); + +ResultCode FormatSaveData(FileSys::SaveDataSpaceId space, FileSys::SaveStruct save_struct); /// Registers all Filesystem services with the specified service manager. void InstallInterfaces(SM::ServiceManager& service_manager); diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 82efe7f7db..555cc0e2f4 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -13,11 +13,21 @@ #include "core/hle/ipc_helpers.h" #include "core/hle/kernel/client_port.h" #include "core/hle/kernel/client_session.h" +#include "core/hle/kernel/process.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/filesystem/fsp_srv.h" namespace Service::FileSystem { +enum class StorageId : u8 { + None = 0, + Host = 1, + GameCard = 2, + NandSystem = 3, + NandUser = 4, + SdCard = 5 +}; + class IStorage final : public ServiceFramework { public: IStorage(std::unique_ptr&& backend) @@ -487,17 +497,6 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { RegisterHandlers(functions); } -void FSP_SRV::TryLoadRomFS() { - if (romfs) { - return; - } - FileSys::Path unused; - auto res = OpenFileSystem(Type::RomFS, unused); - if (res.Succeeded()) { - romfs = std::move(res.Unwrap()); - } -} - void FSP_SRV::Initialize(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_FS, "(STUBBED) called"); @@ -509,7 +508,7 @@ void FSP_SRV::MountSdCard(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); FileSys::Path unused; - auto filesystem = OpenFileSystem(Type::SDMC, unused).Unwrap(); + auto filesystem = OpenSDMC().Unwrap(); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(RESULT_SUCCESS); @@ -530,12 +529,12 @@ void FSP_SRV::CreateSaveData(Kernel::HLERequestContext& ctx) { } void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_FS, "(STUBBED) called"); + IPC::RequestParser rp{ctx}; - // TODO(Subv): Read the input parameters and mount the requested savedata instead of always - // mounting the current process' savedata. - FileSys::Path unused; - auto filesystem = OpenFileSystem(Type::SaveData, unused); + auto space_id = rp.PopRaw(); + auto save_struct = rp.PopRaw(); + + auto filesystem = OpenSaveData(space_id, save_struct); if (filesystem.Failed()) { IPC::ResponseBuilder rb{ctx, 2, 0, 0}; @@ -559,8 +558,8 @@ void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); - TryLoadRomFS(); - if (!romfs) { + auto romfs = OpenRomFS(Core::System::GetInstance().CurrentProcess()->program_id); + if (romfs.Failed()) { // TODO (bunnei): Find the right error code to use here LOG_CRITICAL(Service_FS, "no file system interface available!"); IPC::ResponseBuilder rb{ctx, 2}; @@ -568,8 +567,8 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { return; } - // Attempt to open a StorageBackend interface to the RomFS - auto storage = romfs->OpenFile({}, {}); + auto storage = romfs.Unwrap()->OpenFile({}, {}); + if (storage.Failed()) { LOG_CRITICAL(Service_FS, "no storage interface available!"); IPC::ResponseBuilder rb{ctx, 2}; @@ -583,8 +582,35 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { } void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) { - LOG_WARNING(Service_FS, "(STUBBED) called, using OpenDataStorageByCurrentProcess"); - OpenDataStorageByCurrentProcess(ctx); + IPC::RequestParser rp{ctx}; + + auto storage_id = rp.PopRaw(); + auto title_id = rp.PopRaw(); + + LOG_DEBUG(Service_FS, "called with storage_id={:02X}, title_id={:016X}", + static_cast(storage_id), title_id); + + auto romfs = OpenRomFS(title_id); + if (romfs.Failed()) { + // TODO (bunnei): Find the right error code to use here + LOG_CRITICAL(Service_FS, "no file system interface available!"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(ResultCode(-1)); + return; + } + + auto storage = romfs.Unwrap()->OpenFile({}, {}); + + if (storage.Failed()) { + LOG_CRITICAL(Service_FS, "no storage interface available!"); + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(storage.Code()); + return; + } + + IPC::ResponseBuilder rb{ctx, 2, 0, 1}; + rb.Push(RESULT_SUCCESS); + rb.PushIpcInterface(std::move(storage.Unwrap())); } } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h index acb78fac12..4653eee4e5 100644 --- a/src/core/hle/service/filesystem/fsp_srv.h +++ b/src/core/hle/service/filesystem/fsp_srv.h @@ -19,8 +19,6 @@ public: ~FSP_SRV() = default; private: - void TryLoadRomFS(); - void Initialize(Kernel::HLERequestContext& ctx); void MountSdCard(Kernel::HLERequestContext& ctx); void CreateSaveData(Kernel::HLERequestContext& ctx); diff --git a/src/core/loader/deconstructed_rom_directory.cpp b/src/core/loader/deconstructed_rom_directory.cpp index 5fdb1d2893..0b11bf4f3a 100644 --- a/src/core/loader/deconstructed_rom_directory.cpp +++ b/src/core/loader/deconstructed_rom_directory.cpp @@ -154,8 +154,7 @@ ResultStatus AppLoader_DeconstructedRomDirectory::Load( // Register the RomFS if a ".romfs" file was found if (!filepath_romfs.empty()) { - Service::FileSystem::RegisterFileSystem(std::make_unique(*this), - Service::FileSystem::Type::RomFS); + Service::FileSystem::RegisterRomFS(std::make_unique(*this)); } is_loaded = true; diff --git a/src/core/loader/nca.cpp b/src/core/loader/nca.cpp index 0fd930ae20..b463f369c4 100644 --- a/src/core/loader/nca.cpp +++ b/src/core/loader/nca.cpp @@ -277,8 +277,7 @@ ResultStatus AppLoader_NCA::Load(Kernel::SharedPtr& process) { metadata.GetMainThreadStackSize()); if (nca->GetRomFsSize() > 0) - Service::FileSystem::RegisterFileSystem(std::make_unique(*this), - Service::FileSystem::Type::RomFS); + Service::FileSystem::RegisterRomFS(std::make_unique(*this)); is_loaded = true; return ResultStatus::Success; diff --git a/src/core/loader/nso.cpp b/src/core/loader/nso.cpp index 1c629e21f3..7b3d6b8375 100644 --- a/src/core/loader/nso.cpp +++ b/src/core/loader/nso.cpp @@ -115,7 +115,7 @@ VAddr AppLoader_NSO::LoadModule(const std::string& name, const std::vector& std::vector program_image; for (int i = 0; i < nso_header.segments.size(); ++i) { std::vector compressed_data(nso_header.segments_compressed_size[i]); - for (int j = 0; j < nso_header.segments_compressed_size[i]; ++j) + for (auto j = 0; j < nso_header.segments_compressed_size[i]; ++j) compressed_data[j] = file_data[nso_header.segments[i].offset + j]; std::vector data = DecompressSegment(compressed_data, nso_header.segments[i]); program_image.resize(nso_header.segments[i].location);