fs.mitm: use new namespace types for saves

This commit is contained in:
Michael Scire 2020-03-24 17:50:36 -07:00
parent 9bb5af9823
commit 0af2758fde
4 changed files with 29 additions and 29 deletions

View file

@ -176,7 +176,7 @@ namespace ams::mitm::fs {
return ResultSuccess();
}
Result FsMitmService::OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 _space_id, const FsSaveDataAttribute &attribute) {
Result FsMitmService::OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> 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<FsSaveDataSpaceId>(_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<const FsSaveDataAttribute *>(&attribute))), sm::mitm::ResultShouldForwardToSession());
std::unique_ptr<fs::fsa::IFileSystem> save_ifs = std::make_unique<fs::RemoteFileSystem>(save_fs);
/* Mount the SD card using fs.mitm's session. */
@ -205,7 +206,7 @@ namespace ams::mitm::fs {
std::shared_ptr<fs::fsa::IFileSystem> sd_ifs = std::make_shared<fs::RemoteFileSystem>(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));

View file

@ -82,7 +82,7 @@ namespace ams::mitm::fs {
Result OpenFileSystemWithPatch(sf::Out<std::shared_ptr<IFileSystemInterface>> out, ncm::ProgramId program_id, u32 _filesystem_type);
Result OpenFileSystemWithId(sf::Out<std::shared_ptr<IFileSystemInterface>> out, const fssrv::sf::Path &path, ncm::ProgramId program_id, u32 _filesystem_type);
Result OpenSdCardFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out);
Result OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 space_id, const FsSaveDataAttribute &attribute);
Result OpenSaveDataFileSystem(sf::Out<std::shared_ptr<IFileSystemInterface>> out, u8 space_id, const ams::fs::SaveDataAttribute &attribute);
Result OpenBisStorage(sf::Out<std::shared_ptr<IStorageInterface>> out, u32 bis_partition_id);
Result OpenDataStorageByCurrentProcess(sf::Out<std::shared_ptr<IStorageInterface>> out);
Result OpenDataStorageByDataId(sf::Out<std::shared_ptr<IStorageInterface>> out, ncm::DataId data_id, u8 storage_id);

View file

@ -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<SaveDataSpaceId>(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<size_t>(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<size_t>(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast<u64>(program_id), attribute.uid.uid[1], attribute.uid.uid[0]));
out_path_len = static_cast<size_t>(std::snprintf(dst, dst_size, "/atmosphere/saves/%s/%s/%s/%016lx/%016lx%016lx", emummc_str, space_id_str, save_type_str, static_cast<u64>(program_id), attribute.user_id.data[1], attribute.user_id.data[0]));
}
R_UNLESS(out_path_len < dst_size, fs::ResultTooLongPath());

View file

@ -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);
};
}