From 45fd67c1093e0aa252228e250a66488029396764 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 30 Jul 2020 15:29:39 -0400 Subject: [PATCH 1/3] fs: Rename SaveDataDescriptor to SaveDataAttribute --- src/core/file_sys/savedata_factory.cpp | 33 +++++++------ src/core/file_sys/savedata_factory.h | 47 ++++++++++++++----- src/core/hle/service/am/am.cpp | 10 ++-- .../hle/service/filesystem/filesystem.cpp | 8 ++-- src/core/hle/service/filesystem/filesystem.h | 6 +-- 5 files changed, 63 insertions(+), 41 deletions(-) diff --git a/src/core/file_sys/savedata_factory.cpp b/src/core/file_sys/savedata_factory.cpp index adfd2c1a4..ba4efee3a 100644 --- a/src/core/file_sys/savedata_factory.cpp +++ b/src/core/file_sys/savedata_factory.cpp @@ -17,23 +17,23 @@ constexpr char SAVE_DATA_SIZE_FILENAME[] = ".yuzu_save_size"; namespace { -void PrintSaveDataDescriptorWarnings(SaveDataDescriptor meta) { +void PrintSaveDataAttributeWarnings(SaveDataAttribute meta) { if (meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData) { if (meta.zero_1 != 0) { LOG_WARNING(Service_FS, - "Possibly incorrect SaveDataDescriptor, type is " + "Possibly incorrect SaveDataAttribute, type is " "SystemSaveData||SaveData but offset 0x28 is non-zero ({:016X}).", meta.zero_1); } if (meta.zero_2 != 0) { LOG_WARNING(Service_FS, - "Possibly incorrect SaveDataDescriptor, type is " + "Possibly incorrect SaveDataAttribute, type is " "SystemSaveData||SaveData but offset 0x30 is non-zero ({:016X}).", meta.zero_2); } if (meta.zero_3 != 0) { LOG_WARNING(Service_FS, - "Possibly incorrect SaveDataDescriptor, type is " + "Possibly incorrect SaveDataAttribute, type is " "SystemSaveData||SaveData but offset 0x38 is non-zero ({:016X}).", meta.zero_3); } @@ -41,33 +41,32 @@ void PrintSaveDataDescriptorWarnings(SaveDataDescriptor meta) { if (meta.type == SaveDataType::SystemSaveData && meta.title_id != 0) { LOG_WARNING(Service_FS, - "Possibly incorrect SaveDataDescriptor, type is SystemSaveData but title_id is " + "Possibly incorrect SaveDataAttribute, type is SystemSaveData but title_id is " "non-zero ({:016X}).", meta.title_id); } if (meta.type == SaveDataType::DeviceSaveData && meta.user_id != u128{0, 0}) { LOG_WARNING(Service_FS, - "Possibly incorrect SaveDataDescriptor, type is DeviceSaveData but user_id is " + "Possibly incorrect SaveDataAttribute, type is DeviceSaveData but user_id is " "non-zero ({:016X}{:016X})", meta.user_id[1], meta.user_id[0]); } } -bool ShouldSaveDataBeAutomaticallyCreated(SaveDataSpaceId space, const SaveDataDescriptor& desc) { - return desc.type == SaveDataType::CacheStorage || desc.type == SaveDataType::TemporaryStorage || +bool ShouldSaveDataBeAutomaticallyCreated(SaveDataSpaceId space, const SaveDataAttribute& attr) { + return attr.type == SaveDataType::CacheStorage || attr.type == SaveDataType::TemporaryStorage || (space == SaveDataSpaceId::NandUser && ///< Normal Save Data -- Current Title & User - (desc.type == SaveDataType::SaveData || desc.type == SaveDataType::DeviceSaveData) && - desc.title_id == 0 && desc.save_id == 0); + (attr.type == SaveDataType::SaveData || attr.type == SaveDataType::DeviceSaveData) && + attr.title_id == 0 && attr.save_id == 0); } } // Anonymous namespace -std::string SaveDataDescriptor::DebugInfo() const { - return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, " - "save_id={:016X}, " +std::string SaveDataAttribute::DebugInfo() const { + return fmt::format("[title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}, type={:02X}, " "rank={}, index={}]", - static_cast(type), title_id, user_id[1], user_id[0], save_id, + title_id, user_id[1], user_id[0], save_id, static_cast(type), static_cast(rank), index); } @@ -80,8 +79,8 @@ SaveDataFactory::SaveDataFactory(VirtualDir save_directory) : dir(std::move(save SaveDataFactory::~SaveDataFactory() = default; ResultVal SaveDataFactory::Create(SaveDataSpaceId space, - const SaveDataDescriptor& meta) const { - PrintSaveDataDescriptorWarnings(meta); + const SaveDataAttribute& meta) const { + PrintSaveDataAttributeWarnings(meta); const auto save_directory = GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); @@ -98,7 +97,7 @@ ResultVal SaveDataFactory::Create(SaveDataSpaceId space, } ResultVal SaveDataFactory::Open(SaveDataSpaceId space, - const SaveDataDescriptor& meta) const { + const SaveDataAttribute& meta) const { const auto save_directory = GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id); diff --git a/src/core/file_sys/savedata_factory.h b/src/core/file_sys/savedata_factory.h index 991e57aa1..6625bbbd8 100644 --- a/src/core/file_sys/savedata_factory.h +++ b/src/core/file_sys/savedata_factory.h @@ -21,6 +21,7 @@ enum class SaveDataSpaceId : u8 { TemporaryStorage = 3, SdCardUser = 4, ProperSystem = 100, + SafeMode = 101, }; enum class SaveDataType : u8 { @@ -30,28 +31,50 @@ enum class SaveDataType : u8 { DeviceSaveData = 3, TemporaryStorage = 4, CacheStorage = 5, + SystemBcat = 6, }; enum class SaveDataRank : u8 { - Primary, - Secondary, + Primary = 0, + Secondary = 1, }; -struct SaveDataDescriptor { - u64_le title_id; +enum class SaveDataFlags : u32 { + None = (0 << 0), + KeepAfterResettingSystemSaveData = (1 << 0), + KeepAfterRefurbishment = (1 << 1), + KeepAfterResettingSystemSaveDataWithoutUserSaveData = (1 << 2), + NeedsSecureDelete = (1 << 3), +}; + +struct SaveDataAttribute { + u64 title_id; u128 user_id; - u64_le save_id; + u64 save_id; SaveDataType type; SaveDataRank rank; - u16_le index; + u16 index; INSERT_PADDING_BYTES(4); - u64_le zero_1; - u64_le zero_2; - u64_le zero_3; + u64 zero_1; + u64 zero_2; + u64 zero_3; std::string DebugInfo() const; }; -static_assert(sizeof(SaveDataDescriptor) == 0x40, "SaveDataDescriptor has incorrect size."); +static_assert(sizeof(SaveDataAttribute) == 0x40, "SaveDataAttribute has incorrect size."); + +struct SaveDataExtraData { + SaveDataAttribute attr; + u64 owner_id; + s64 timestamp; + SaveDataFlags flags; + INSERT_PADDING_BYTES(4); + s64 available_size; + s64 journal_size; + s64 commit_id; + std::array unused; +}; +static_assert(sizeof(SaveDataExtraData) == 0x200, "SaveDataExtraData has incorrect size."); struct SaveDataSize { u64 normal; @@ -64,8 +87,8 @@ public: explicit SaveDataFactory(VirtualDir dir); ~SaveDataFactory(); - ResultVal Create(SaveDataSpaceId space, const SaveDataDescriptor& meta) const; - ResultVal Open(SaveDataSpaceId space, const SaveDataDescriptor& meta) const; + ResultVal Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const; + ResultVal Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const; VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const; diff --git a/src/core/hle/service/am/am.cpp b/src/core/hle/service/am/am.cpp index ceed20609..55a1edf1a 100644 --- a/src/core/hle/service/am/am.cpp +++ b/src/core/hle/service/am/am.cpp @@ -1342,12 +1342,12 @@ void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) { LOG_DEBUG(Service_AM, "called, uid={:016X}{:016X}", user_id[1], user_id[0]); - FileSys::SaveDataDescriptor descriptor{}; - descriptor.title_id = system.CurrentProcess()->GetTitleID(); - descriptor.user_id = user_id; - descriptor.type = FileSys::SaveDataType::SaveData; + FileSys::SaveDataAttribute attribute{}; + attribute.title_id = system.CurrentProcess()->GetTitleID(); + attribute.user_id = user_id; + attribute.type = FileSys::SaveDataType::SaveData; const auto res = system.GetFileSystemController().CreateSaveData( - FileSys::SaveDataSpaceId::NandUser, descriptor); + FileSys::SaveDataSpaceId::NandUser, attribute); IPC::ResponseBuilder rb{ctx, 4}; rb.Push(res.Code()); diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index c66124998..4490f8e4c 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -311,7 +311,7 @@ ResultVal FileSystemController::OpenRomFS( } ResultVal FileSystemController::CreateSaveData( - FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& save_struct) const { + FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const { LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}", static_cast(space), save_struct.DebugInfo()); @@ -323,15 +323,15 @@ ResultVal FileSystemController::CreateSaveData( } ResultVal FileSystemController::OpenSaveData( - FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& descriptor) const { + FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& attribute) const { LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}", - static_cast(space), descriptor.DebugInfo()); + static_cast(space), attribute.DebugInfo()); if (save_data_factory == nullptr) { return FileSys::ERROR_ENTITY_NOT_FOUND; } - return save_data_factory->Open(space, descriptor); + return save_data_factory->Open(space, attribute); } ResultVal FileSystemController::OpenSaveDataSpace( diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 1b0a6a949..6dbbf0b2b 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -31,7 +31,7 @@ enum class SaveDataSpaceId : u8; enum class SaveDataType : u8; enum class StorageId : u8; -struct SaveDataDescriptor; +struct SaveDataAttribute; struct SaveDataSize; } // namespace FileSys @@ -69,9 +69,9 @@ public: ResultVal OpenRomFS(u64 title_id, FileSys::StorageId storage_id, FileSys::ContentRecordType type) const; ResultVal CreateSaveData( - FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& save_struct) const; + FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const; ResultVal OpenSaveData( - FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& save_struct) const; + FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const; ResultVal OpenSaveDataSpace(FileSys::SaveDataSpaceId space) const; ResultVal OpenSDMC() const; ResultVal OpenBISPartition(FileSys::BisPartitionId id) const; From 124102009373927d89f717cf3382d611ad97b0ec Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Thu, 30 Jul 2020 15:39:44 -0400 Subject: [PATCH 2/3] fsp-srv: Stub Read/WriteSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute Stub these 2 service commands required for Animal Crossing: New Horizons Update 1.4.0 --- src/core/hle/service/filesystem/fsp_srv.cpp | 73 +++++++++++++++------ src/core/hle/service/filesystem/fsp_srv.h | 6 +- 2 files changed, 56 insertions(+), 23 deletions(-) diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 20c331b77..87b4bcb0a 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -696,8 +696,8 @@ FSP_SRV::FSP_SRV(FileSystemController& fsc, const Core::Reporter& reporter) {67, nullptr, "FindSaveDataWithFilter"}, {68, nullptr, "OpenSaveDataInfoReaderBySaveDataFilter"}, {69, nullptr, "ReadSaveDataFileSystemExtraDataBySaveDataAttribute"}, - {70, nullptr, "WriteSaveDataFileSystemExtraDataBySaveDataAttribute"}, - {71, nullptr, "ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute"}, + {70, &FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute, "WriteSaveDataFileSystemExtraDataBySaveDataAttribute"}, + {71, &FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute, "ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute"}, {80, nullptr, "OpenSaveDataMetaFile"}, {81, nullptr, "OpenSaveDataTransferManager"}, {82, nullptr, "OpenSaveDataTransferManagerVersion2"}, @@ -812,7 +812,7 @@ void FSP_SRV::OpenSdCardFileSystem(Kernel::HLERequestContext& ctx) { void FSP_SRV::CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - auto save_struct = rp.PopRaw(); + auto save_struct = rp.PopRaw(); [[maybe_unused]] auto save_create_struct = rp.PopRaw>(); u128 uid = rp.PopRaw(); @@ -826,17 +826,18 @@ void FSP_SRV::CreateSaveDataFileSystem(Kernel::HLERequestContext& ctx) { } void FSP_SRV::OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx) { - LOG_INFO(Service_FS, "called."); + IPC::RequestParser rp{ctx}; struct Parameters { - FileSys::SaveDataSpaceId save_data_space_id; - FileSys::SaveDataDescriptor descriptor; + FileSys::SaveDataSpaceId space_id; + FileSys::SaveDataAttribute attribute; }; - IPC::RequestParser rp{ctx}; const auto parameters = rp.PopRaw(); - auto dir = fsc.OpenSaveData(parameters.save_data_space_id, parameters.descriptor); + LOG_INFO(Service_FS, "called."); + + auto dir = fsc.OpenSaveData(parameters.space_id, parameters.attribute); if (dir.Failed()) { IPC::ResponseBuilder rb{ctx, 2, 0, 0}; rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); @@ -844,13 +845,18 @@ void FSP_SRV::OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx) { } FileSys::StorageId id; - if (parameters.save_data_space_id == FileSys::SaveDataSpaceId::NandUser) { + + switch (parameters.space_id) { + case FileSys::SaveDataSpaceId::NandUser: id = FileSys::StorageId::NandUser; - } else if (parameters.save_data_space_id == FileSys::SaveDataSpaceId::SdCardSystem || - parameters.save_data_space_id == FileSys::SaveDataSpaceId::SdCardUser) { + break; + case FileSys::SaveDataSpaceId::SdCardSystem: + case FileSys::SaveDataSpaceId::SdCardUser: id = FileSys::StorageId::SdCard; - } else { + break; + case FileSys::SaveDataSpaceId::NandSystem: id = FileSys::StorageId::NandSystem; + break; } auto filesystem = @@ -876,22 +882,29 @@ void FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& rb.PushIpcInterface(std::make_shared(space, fsc)); } -void FSP_SRV::SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - log_mode = rp.PopEnum(); - - LOG_DEBUG(Service_FS, "called, log_mode={:08X}", static_cast(log_mode)); - +void FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute(Kernel::HLERequestContext& ctx) { + LOG_WARNING(Service_FS, "(STUBBED) called."); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } -void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { - LOG_DEBUG(Service_FS, "called"); +void FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute( + Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + + struct Parameters { + FileSys::SaveDataSpaceId space_id; + FileSys::SaveDataAttribute attribute; + }; + + const auto parameters = rp.PopRaw(); + // Stub this to None for now, backend needs an impl to read/write the SaveDataExtraData + constexpr auto flags = static_cast(FileSys::SaveDataFlags::None); IPC::ResponseBuilder rb{ctx, 3}; + LOG_WARNING(Service_FS, "(STUBBED) called, flags={}", flags); rb.Push(RESULT_SUCCESS); - rb.PushEnum(log_mode); + rb.Push(flags); } void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { @@ -966,6 +979,24 @@ void FSP_SRV::OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ct rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); } +void FSP_SRV::SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp{ctx}; + log_mode = rp.PopEnum(); + + LOG_DEBUG(Service_FS, "called, log_mode={:08X}", static_cast(log_mode)); + + IPC::ResponseBuilder rb{ctx, 2}; + rb.Push(RESULT_SUCCESS); +} + +void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { + LOG_DEBUG(Service_FS, "called"); + + IPC::ResponseBuilder rb{ctx, 3}; + rb.Push(RESULT_SUCCESS); + rb.PushEnum(log_mode); +} + void FSP_SRV::OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx) { const auto raw = ctx.ReadBuffer(); auto log = Common::StringFromFixedZeroTerminatedBuffer( diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h index dfb3e395b..4964e874e 100644 --- a/src/core/hle/service/filesystem/fsp_srv.h +++ b/src/core/hle/service/filesystem/fsp_srv.h @@ -43,11 +43,13 @@ private: void OpenSaveDataFileSystem(Kernel::HLERequestContext& ctx); void OpenReadOnlySaveDataFileSystem(Kernel::HLERequestContext& ctx); void OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& ctx); - void SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); - void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); + void WriteSaveDataFileSystemExtraDataBySaveDataAttribute(Kernel::HLERequestContext& ctx); + void ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(Kernel::HLERequestContext& ctx); void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); void OpenDataStorageByDataId(Kernel::HLERequestContext& ctx); void OpenPatchDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); + void SetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); + void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); void OutputAccessLogToSdCard(Kernel::HLERequestContext& ctx); void GetAccessLogVersionInfo(Kernel::HLERequestContext& ctx); void OpenMultiCommitManager(Kernel::HLERequestContext& ctx); From fc86cb4ca27e38d4ffd02a13337100d987d25304 Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Fri, 31 Jul 2020 11:02:59 -0400 Subject: [PATCH 3/3] minor nits --- src/core/hle/service/filesystem/fsp_srv.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 87b4bcb0a..26fd87f58 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -884,6 +884,7 @@ void FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& void FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute(Kernel::HLERequestContext& ctx) { LOG_WARNING(Service_FS, "(STUBBED) called."); + IPC::ResponseBuilder rb{ctx, 2}; rb.Push(RESULT_SUCCESS); } @@ -901,8 +902,9 @@ void FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute( // Stub this to None for now, backend needs an impl to read/write the SaveDataExtraData constexpr auto flags = static_cast(FileSys::SaveDataFlags::None); - IPC::ResponseBuilder rb{ctx, 3}; LOG_WARNING(Service_FS, "(STUBBED) called, flags={}", flags); + + IPC::ResponseBuilder rb{ctx, 3}; rb.Push(RESULT_SUCCESS); rb.Push(flags); }