forked from suyu/suyu
fs: Rename SaveDataDescriptor to SaveDataAttribute
This commit is contained in:
parent
0c262f8ac2
commit
45fd67c109
5 changed files with 63 additions and 41 deletions
|
@ -17,23 +17,23 @@ constexpr char SAVE_DATA_SIZE_FILENAME[] = ".yuzu_save_size";
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
void PrintSaveDataDescriptorWarnings(SaveDataDescriptor meta) {
|
void PrintSaveDataAttributeWarnings(SaveDataAttribute meta) {
|
||||||
if (meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData) {
|
if (meta.type == SaveDataType::SystemSaveData || meta.type == SaveDataType::SaveData) {
|
||||||
if (meta.zero_1 != 0) {
|
if (meta.zero_1 != 0) {
|
||||||
LOG_WARNING(Service_FS,
|
LOG_WARNING(Service_FS,
|
||||||
"Possibly incorrect SaveDataDescriptor, type is "
|
"Possibly incorrect SaveDataAttribute, type is "
|
||||||
"SystemSaveData||SaveData but offset 0x28 is non-zero ({:016X}).",
|
"SystemSaveData||SaveData but offset 0x28 is non-zero ({:016X}).",
|
||||||
meta.zero_1);
|
meta.zero_1);
|
||||||
}
|
}
|
||||||
if (meta.zero_2 != 0) {
|
if (meta.zero_2 != 0) {
|
||||||
LOG_WARNING(Service_FS,
|
LOG_WARNING(Service_FS,
|
||||||
"Possibly incorrect SaveDataDescriptor, type is "
|
"Possibly incorrect SaveDataAttribute, type is "
|
||||||
"SystemSaveData||SaveData but offset 0x30 is non-zero ({:016X}).",
|
"SystemSaveData||SaveData but offset 0x30 is non-zero ({:016X}).",
|
||||||
meta.zero_2);
|
meta.zero_2);
|
||||||
}
|
}
|
||||||
if (meta.zero_3 != 0) {
|
if (meta.zero_3 != 0) {
|
||||||
LOG_WARNING(Service_FS,
|
LOG_WARNING(Service_FS,
|
||||||
"Possibly incorrect SaveDataDescriptor, type is "
|
"Possibly incorrect SaveDataAttribute, type is "
|
||||||
"SystemSaveData||SaveData but offset 0x38 is non-zero ({:016X}).",
|
"SystemSaveData||SaveData but offset 0x38 is non-zero ({:016X}).",
|
||||||
meta.zero_3);
|
meta.zero_3);
|
||||||
}
|
}
|
||||||
|
@ -41,33 +41,32 @@ void PrintSaveDataDescriptorWarnings(SaveDataDescriptor meta) {
|
||||||
|
|
||||||
if (meta.type == SaveDataType::SystemSaveData && meta.title_id != 0) {
|
if (meta.type == SaveDataType::SystemSaveData && meta.title_id != 0) {
|
||||||
LOG_WARNING(Service_FS,
|
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}).",
|
"non-zero ({:016X}).",
|
||||||
meta.title_id);
|
meta.title_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (meta.type == SaveDataType::DeviceSaveData && meta.user_id != u128{0, 0}) {
|
if (meta.type == SaveDataType::DeviceSaveData && meta.user_id != u128{0, 0}) {
|
||||||
LOG_WARNING(Service_FS,
|
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})",
|
"non-zero ({:016X}{:016X})",
|
||||||
meta.user_id[1], meta.user_id[0]);
|
meta.user_id[1], meta.user_id[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ShouldSaveDataBeAutomaticallyCreated(SaveDataSpaceId space, const SaveDataDescriptor& desc) {
|
bool ShouldSaveDataBeAutomaticallyCreated(SaveDataSpaceId space, const SaveDataAttribute& attr) {
|
||||||
return desc.type == SaveDataType::CacheStorage || desc.type == SaveDataType::TemporaryStorage ||
|
return attr.type == SaveDataType::CacheStorage || attr.type == SaveDataType::TemporaryStorage ||
|
||||||
(space == SaveDataSpaceId::NandUser && ///< Normal Save Data -- Current Title & User
|
(space == SaveDataSpaceId::NandUser && ///< Normal Save Data -- Current Title & User
|
||||||
(desc.type == SaveDataType::SaveData || desc.type == SaveDataType::DeviceSaveData) &&
|
(attr.type == SaveDataType::SaveData || attr.type == SaveDataType::DeviceSaveData) &&
|
||||||
desc.title_id == 0 && desc.save_id == 0);
|
attr.title_id == 0 && attr.save_id == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
std::string SaveDataDescriptor::DebugInfo() const {
|
std::string SaveDataAttribute::DebugInfo() const {
|
||||||
return fmt::format("[type={:02X}, title_id={:016X}, user_id={:016X}{:016X}, "
|
return fmt::format("[title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}, type={:02X}, "
|
||||||
"save_id={:016X}, "
|
|
||||||
"rank={}, index={}]",
|
"rank={}, index={}]",
|
||||||
static_cast<u8>(type), title_id, user_id[1], user_id[0], save_id,
|
title_id, user_id[1], user_id[0], save_id, static_cast<u8>(type),
|
||||||
static_cast<u8>(rank), index);
|
static_cast<u8>(rank), index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,8 +79,8 @@ SaveDataFactory::SaveDataFactory(VirtualDir save_directory) : dir(std::move(save
|
||||||
SaveDataFactory::~SaveDataFactory() = default;
|
SaveDataFactory::~SaveDataFactory() = default;
|
||||||
|
|
||||||
ResultVal<VirtualDir> SaveDataFactory::Create(SaveDataSpaceId space,
|
ResultVal<VirtualDir> SaveDataFactory::Create(SaveDataSpaceId space,
|
||||||
const SaveDataDescriptor& meta) const {
|
const SaveDataAttribute& meta) const {
|
||||||
PrintSaveDataDescriptorWarnings(meta);
|
PrintSaveDataAttributeWarnings(meta);
|
||||||
|
|
||||||
const auto save_directory =
|
const auto save_directory =
|
||||||
GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
||||||
|
@ -98,7 +97,7 @@ ResultVal<VirtualDir> SaveDataFactory::Create(SaveDataSpaceId space,
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space,
|
ResultVal<VirtualDir> SaveDataFactory::Open(SaveDataSpaceId space,
|
||||||
const SaveDataDescriptor& meta) const {
|
const SaveDataAttribute& meta) const {
|
||||||
|
|
||||||
const auto save_directory =
|
const auto save_directory =
|
||||||
GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
GetFullPath(space, meta.type, meta.title_id, meta.user_id, meta.save_id);
|
||||||
|
|
|
@ -21,6 +21,7 @@ enum class SaveDataSpaceId : u8 {
|
||||||
TemporaryStorage = 3,
|
TemporaryStorage = 3,
|
||||||
SdCardUser = 4,
|
SdCardUser = 4,
|
||||||
ProperSystem = 100,
|
ProperSystem = 100,
|
||||||
|
SafeMode = 101,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SaveDataType : u8 {
|
enum class SaveDataType : u8 {
|
||||||
|
@ -30,28 +31,50 @@ enum class SaveDataType : u8 {
|
||||||
DeviceSaveData = 3,
|
DeviceSaveData = 3,
|
||||||
TemporaryStorage = 4,
|
TemporaryStorage = 4,
|
||||||
CacheStorage = 5,
|
CacheStorage = 5,
|
||||||
|
SystemBcat = 6,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class SaveDataRank : u8 {
|
enum class SaveDataRank : u8 {
|
||||||
Primary,
|
Primary = 0,
|
||||||
Secondary,
|
Secondary = 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SaveDataDescriptor {
|
enum class SaveDataFlags : u32 {
|
||||||
u64_le title_id;
|
None = (0 << 0),
|
||||||
|
KeepAfterResettingSystemSaveData = (1 << 0),
|
||||||
|
KeepAfterRefurbishment = (1 << 1),
|
||||||
|
KeepAfterResettingSystemSaveDataWithoutUserSaveData = (1 << 2),
|
||||||
|
NeedsSecureDelete = (1 << 3),
|
||||||
|
};
|
||||||
|
|
||||||
|
struct SaveDataAttribute {
|
||||||
|
u64 title_id;
|
||||||
u128 user_id;
|
u128 user_id;
|
||||||
u64_le save_id;
|
u64 save_id;
|
||||||
SaveDataType type;
|
SaveDataType type;
|
||||||
SaveDataRank rank;
|
SaveDataRank rank;
|
||||||
u16_le index;
|
u16 index;
|
||||||
INSERT_PADDING_BYTES(4);
|
INSERT_PADDING_BYTES(4);
|
||||||
u64_le zero_1;
|
u64 zero_1;
|
||||||
u64_le zero_2;
|
u64 zero_2;
|
||||||
u64_le zero_3;
|
u64 zero_3;
|
||||||
|
|
||||||
std::string DebugInfo() const;
|
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<u8, 0x190> unused;
|
||||||
|
};
|
||||||
|
static_assert(sizeof(SaveDataExtraData) == 0x200, "SaveDataExtraData has incorrect size.");
|
||||||
|
|
||||||
struct SaveDataSize {
|
struct SaveDataSize {
|
||||||
u64 normal;
|
u64 normal;
|
||||||
|
@ -64,8 +87,8 @@ public:
|
||||||
explicit SaveDataFactory(VirtualDir dir);
|
explicit SaveDataFactory(VirtualDir dir);
|
||||||
~SaveDataFactory();
|
~SaveDataFactory();
|
||||||
|
|
||||||
ResultVal<VirtualDir> Create(SaveDataSpaceId space, const SaveDataDescriptor& meta) const;
|
ResultVal<VirtualDir> Create(SaveDataSpaceId space, const SaveDataAttribute& meta) const;
|
||||||
ResultVal<VirtualDir> Open(SaveDataSpaceId space, const SaveDataDescriptor& meta) const;
|
ResultVal<VirtualDir> Open(SaveDataSpaceId space, const SaveDataAttribute& meta) const;
|
||||||
|
|
||||||
VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const;
|
VirtualDir GetSaveDataSpaceDirectory(SaveDataSpaceId space) const;
|
||||||
|
|
||||||
|
|
|
@ -1342,12 +1342,12 @@ void IApplicationFunctions::EnsureSaveData(Kernel::HLERequestContext& ctx) {
|
||||||
|
|
||||||
LOG_DEBUG(Service_AM, "called, uid={:016X}{:016X}", user_id[1], user_id[0]);
|
LOG_DEBUG(Service_AM, "called, uid={:016X}{:016X}", user_id[1], user_id[0]);
|
||||||
|
|
||||||
FileSys::SaveDataDescriptor descriptor{};
|
FileSys::SaveDataAttribute attribute{};
|
||||||
descriptor.title_id = system.CurrentProcess()->GetTitleID();
|
attribute.title_id = system.CurrentProcess()->GetTitleID();
|
||||||
descriptor.user_id = user_id;
|
attribute.user_id = user_id;
|
||||||
descriptor.type = FileSys::SaveDataType::SaveData;
|
attribute.type = FileSys::SaveDataType::SaveData;
|
||||||
const auto res = system.GetFileSystemController().CreateSaveData(
|
const auto res = system.GetFileSystemController().CreateSaveData(
|
||||||
FileSys::SaveDataSpaceId::NandUser, descriptor);
|
FileSys::SaveDataSpaceId::NandUser, attribute);
|
||||||
|
|
||||||
IPC::ResponseBuilder rb{ctx, 4};
|
IPC::ResponseBuilder rb{ctx, 4};
|
||||||
rb.Push(res.Code());
|
rb.Push(res.Code());
|
||||||
|
|
|
@ -311,7 +311,7 @@ ResultVal<FileSys::VirtualFile> FileSystemController::OpenRomFS(
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<FileSys::VirtualDir> FileSystemController::CreateSaveData(
|
ResultVal<FileSys::VirtualDir> 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={}",
|
LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}",
|
||||||
static_cast<u8>(space), save_struct.DebugInfo());
|
static_cast<u8>(space), save_struct.DebugInfo());
|
||||||
|
|
||||||
|
@ -323,15 +323,15 @@ ResultVal<FileSys::VirtualDir> FileSystemController::CreateSaveData(
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveData(
|
ResultVal<FileSys::VirtualDir> 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={}",
|
LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}",
|
||||||
static_cast<u8>(space), descriptor.DebugInfo());
|
static_cast<u8>(space), attribute.DebugInfo());
|
||||||
|
|
||||||
if (save_data_factory == nullptr) {
|
if (save_data_factory == nullptr) {
|
||||||
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
return FileSys::ERROR_ENTITY_NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
return save_data_factory->Open(space, descriptor);
|
return save_data_factory->Open(space, attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveDataSpace(
|
ResultVal<FileSys::VirtualDir> FileSystemController::OpenSaveDataSpace(
|
||||||
|
|
|
@ -31,7 +31,7 @@ enum class SaveDataSpaceId : u8;
|
||||||
enum class SaveDataType : u8;
|
enum class SaveDataType : u8;
|
||||||
enum class StorageId : u8;
|
enum class StorageId : u8;
|
||||||
|
|
||||||
struct SaveDataDescriptor;
|
struct SaveDataAttribute;
|
||||||
struct SaveDataSize;
|
struct SaveDataSize;
|
||||||
} // namespace FileSys
|
} // namespace FileSys
|
||||||
|
|
||||||
|
@ -69,9 +69,9 @@ public:
|
||||||
ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id,
|
||||||
FileSys::ContentRecordType type) const;
|
FileSys::ContentRecordType type) const;
|
||||||
ResultVal<FileSys::VirtualDir> CreateSaveData(
|
ResultVal<FileSys::VirtualDir> CreateSaveData(
|
||||||
FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& save_struct) const;
|
FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const;
|
||||||
ResultVal<FileSys::VirtualDir> OpenSaveData(
|
ResultVal<FileSys::VirtualDir> OpenSaveData(
|
||||||
FileSys::SaveDataSpaceId space, const FileSys::SaveDataDescriptor& save_struct) const;
|
FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const;
|
||||||
ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space) const;
|
ResultVal<FileSys::VirtualDir> OpenSaveDataSpace(FileSys::SaveDataSpaceId space) const;
|
||||||
ResultVal<FileSys::VirtualDir> OpenSDMC() const;
|
ResultVal<FileSys::VirtualDir> OpenSDMC() const;
|
||||||
ResultVal<FileSys::VirtualDir> OpenBISPartition(FileSys::BisPartitionId id) const;
|
ResultVal<FileSys::VirtualDir> OpenBISPartition(FileSys::BisPartitionId id) const;
|
||||||
|
|
Loading…
Reference in a new issue