From 0af2758fde9631297578ade714a3c182fbb96a1d Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Tue, 24 Mar 2020 17:50:36 -0700 Subject: [PATCH] fs.mitm: use new namespace types for saves --- .../source/fs_mitm/fs_mitm_service.cpp | 9 ++-- .../source/fs_mitm/fs_mitm_service.hpp | 2 +- .../source/fs_mitm/fsmitm_save_utils.cpp | 45 +++++++++---------- .../source/fs_mitm/fsmitm_save_utils.hpp | 2 +- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp index 7ff723007..20ee2f2c7 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.cpp @@ -176,7 +176,7 @@ namespace ams::mitm::fs { return ResultSuccess(); } - Result FsMitmService::OpenSaveDataFileSystem(sf::Out> out, u8 _space_id, const FsSaveDataAttribute &attribute) { + Result FsMitmService::OpenSaveDataFileSystem(sf::Out> out, u8 _space_id, const fs::SaveDataAttribute &attribute) { /* We only want to intercept saves for games, right now. */ const bool is_game_or_hbl = this->client_info.override_status.IsHbl() || ncm::IsApplicationId(this->client_info.program_id); R_UNLESS(is_game_or_hbl, sm::mitm::ResultShouldForwardToSession()); @@ -188,14 +188,15 @@ namespace ams::mitm::fs { R_UNLESS(cfg::HasContentSpecificFlag(this->client_info.program_id, "redirect_save"), sm::mitm::ResultShouldForwardToSession()); /* Only redirect account savedata. */ - R_UNLESS(attribute.save_data_type == FsSaveDataType_Account, sm::mitm::ResultShouldForwardToSession()); + R_UNLESS(attribute.type == fs::SaveDataType::Account, sm::mitm::ResultShouldForwardToSession()); /* Get enum type for space id. */ auto space_id = static_cast(_space_id); /* Verify we can open the save. */ + static_assert(sizeof(fs::SaveDataAttribute) == sizeof(::FsSaveDataAttribute)); FsFileSystem save_fs; - R_UNLESS(R_SUCCEEDED(fsOpenSaveDataFileSystemFwd(this->forward_service.get(), &save_fs, space_id, &attribute)), sm::mitm::ResultShouldForwardToSession()); + R_UNLESS(R_SUCCEEDED(fsOpenSaveDataFileSystemFwd(this->forward_service.get(), &save_fs, space_id, reinterpret_cast(&attribute))), sm::mitm::ResultShouldForwardToSession()); std::unique_ptr save_ifs = std::make_unique(save_fs); /* Mount the SD card using fs.mitm's session. */ @@ -205,7 +206,7 @@ namespace ams::mitm::fs { std::shared_ptr sd_ifs = std::make_shared(sd_fs); /* Verify that we can open the save directory, and that it exists. */ - const ncm::ProgramId application_id = attribute.application_id == 0 ? this->client_info.program_id : ncm::ProgramId{attribute.application_id}; + const ncm::ProgramId application_id = attribute.program_id == ncm::InvalidProgramId ? this->client_info.program_id : attribute.program_id; char save_dir_path[fs::EntryNameLengthMax + 1]; R_TRY(mitm::fs::SaveUtil::GetDirectorySaveDataPath(save_dir_path, sizeof(save_dir_path), application_id, space_id, attribute)); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp index 63ff73700..c6ce4039f 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fs_mitm_service.hpp @@ -82,7 +82,7 @@ namespace ams::mitm::fs { Result OpenFileSystemWithPatch(sf::Out> out, ncm::ProgramId program_id, u32 _filesystem_type); Result OpenFileSystemWithId(sf::Out> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type); Result OpenSdCardFileSystem(sf::Out> out); - Result OpenSaveDataFileSystem(sf::Out> out, u8 space_id, const FsSaveDataAttribute &attribute); + Result OpenSaveDataFileSystem(sf::Out> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute); Result OpenBisStorage(sf::Out> out, u32 bis_partition_id); Result OpenDataStorageByCurrentProcess(sf::Out> out); Result OpenDataStorageByDataId(sf::Out> out, ncm::DataId data_id, u8 storage_id); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.cpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.cpp index 3881b56c1..65be46822 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.cpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.cpp @@ -22,24 +22,24 @@ namespace ams::mitm::fs { namespace { Result GetSaveDataSpaceIdString(const char **out_str, u8 space_id) { - switch (space_id) { - case FsSaveDataSpaceId_System: - case FsSaveDataSpaceId_ProperSystem: + switch (static_cast(space_id)) { + case SaveDataSpaceId::System: + case SaveDataSpaceId::ProperSystem: *out_str = "sys"; break; - case FsSaveDataSpaceId_User: + case SaveDataSpaceId::User: *out_str = "user"; break; - case FsSaveDataSpaceId_SdSystem: + case SaveDataSpaceId::SdSystem: *out_str = "sd_sys"; break; - case FsSaveDataSpaceId_Temporary: + case SaveDataSpaceId::Temporary: *out_str = "temp"; break; - case FsSaveDataSpaceId_SdUser: + case SaveDataSpaceId::SdUser: *out_str = "sd_user"; break; - case FsSaveDataSpaceId_SafeMode: + case SaveDataSpaceId::SafeMode: *out_str = "safe"; break; default: @@ -49,27 +49,27 @@ namespace ams::mitm::fs { return ResultSuccess(); } - Result GetSaveDataTypeString(const char **out_str, u8 save_data_type) { + Result GetSaveDataTypeString(const char **out_str, SaveDataType save_data_type) { switch (save_data_type) { - case FsSaveDataType_System: + case SaveDataType::System: *out_str = "system"; break; - case FsSaveDataType_Account: + case SaveDataType::Account: *out_str = "account"; break; - case FsSaveDataType_Bcat: + case SaveDataType::Bcat: *out_str = "bcat"; break; - case FsSaveDataType_Device: + case SaveDataType::Device: *out_str = "device"; break; - case FsSaveDataType_Temporary: + case SaveDataType::Temporary: *out_str = "temp"; break; - case FsSaveDataType_Cache: + case SaveDataType::Cache: *out_str = "cache"; break; - case FsSaveDataType_SystemBcat: + case SaveDataType::SystemBcat: *out_str = "system_bcat"; break; default: @@ -80,30 +80,29 @@ namespace ams::mitm::fs { return ResultSuccess(); } - constexpr inline bool IsEmptyAccountId(const AccountUid &uid) { - constexpr AccountUid empty_uid = {}; - return std::memcmp(&uid, &empty_uid, sizeof(uid)) == 0; + constexpr inline bool IsEmptyAccountId(const UserId &uid) { + return uid == InvalidUserId; } } - Result SaveUtil::GetDirectorySaveDataPath(char *dst, size_t dst_size, ncm::ProgramId program_id, u8 space_id, const FsSaveDataAttribute &attribute) { + Result SaveUtil::GetDirectorySaveDataPath(char *dst, size_t dst_size, ncm::ProgramId program_id, u8 space_id, const fs::SaveDataAttribute &attribute) { /* Saves should be separate for emunand vs sysnand. */ const char *emummc_str = emummc::IsActive() ? "emummc" : "sysmmc"; /* Get space_id, save_data_type strings. */ const char *space_id_str, *save_type_str; R_TRY(GetSaveDataSpaceIdString(&space_id_str, space_id)); - R_TRY(GetSaveDataTypeString(&save_type_str, attribute.save_data_type)); + R_TRY(GetSaveDataTypeString(&save_type_str, attribute.type)); /* Initialize the path. */ - const bool is_system = attribute.system_save_data_id != 0 && IsEmptyAccountId(attribute.uid); + const bool is_system = attribute.system_save_data_id != InvalidSystemSaveDataId && IsEmptyAccountId(attribute.user_id); size_t out_path_len; if (is_system) { out_path_len = static_cast(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx", emummc_str, space_id_str, save_type_str, attribute.system_save_data_id)); } else { - out_path_len = static_cast(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast(program_id), attribute.uid.uid[1], attribute.uid.uid[0])); + out_path_len = static_cast(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast(program_id), attribute.user_id.data[1], attribute.user_id.data[0])); } R_UNLESS(out_path_len < dst_size, fs::ResultTooLongPath()); diff --git a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.hpp b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.hpp index 3245f30b8..3fb8d2c64 100644 --- a/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.hpp +++ b/stratosphere/ams_mitm/source/fs_mitm/fsmitm_save_utils.hpp @@ -20,7 +20,7 @@ namespace ams::mitm::fs { class SaveUtil { public: - static Result GetDirectorySaveDataPath(char *dst, size_t dst_size, ncm::ProgramId program_id, u8 space_id, const FsSaveDataAttribute &attribute); + static Result GetDirectorySaveDataPath(char *dst, size_t dst_size, ncm::ProgramId program_id, u8 space_id, const ams::fs::SaveDataAttribute &attribute); }; }