|
|
@ -11,6 +11,7 @@ |
|
|
|
|
|
|
|
|
#include "common/assert.h"
|
|
|
#include "common/assert.h"
|
|
|
#include "common/common_types.h"
|
|
|
#include "common/common_types.h"
|
|
|
|
|
|
#include "common/hex_util.h"
|
|
|
#include "common/logging/log.h"
|
|
|
#include "common/logging/log.h"
|
|
|
#include "common/string_util.h"
|
|
|
#include "common/string_util.h"
|
|
|
#include "core/file_sys/directory.h"
|
|
|
#include "core/file_sys/directory.h"
|
|
|
@ -451,7 +452,147 @@ private: |
|
|
VfsDirectoryServiceWrapper backend; |
|
|
VfsDirectoryServiceWrapper backend; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
class ISaveDataInfoReader final : public ServiceFramework<ISaveDataInfoReader> { |
|
|
|
|
|
public: |
|
|
|
|
|
explicit ISaveDataInfoReader(FileSys::SaveDataSpaceId space) |
|
|
|
|
|
: ServiceFramework("ISaveDataInfoReader") { |
|
|
|
|
|
static const FunctionInfo functions[] = { |
|
|
|
|
|
{0, &ISaveDataInfoReader::ReadSaveDataInfo, "ReadSaveDataInfo"}, |
|
|
|
|
|
}; |
|
|
|
|
|
RegisterHandlers(functions); |
|
|
|
|
|
|
|
|
|
|
|
FindAllSaves(space); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ReadSaveDataInfo(Kernel::HLERequestContext& ctx) { |
|
|
|
|
|
// Calculate how many entries we can fit in the output buffer
|
|
|
|
|
|
const u64 count_entries = ctx.GetWriteBufferSize() / sizeof(SaveDataInfo); |
|
|
|
|
|
|
|
|
|
|
|
// Cap at total number of entries.
|
|
|
|
|
|
const u64 actual_entries = std::min(count_entries, info.size() - next_entry_index); |
|
|
|
|
|
|
|
|
|
|
|
// Determine data start and end
|
|
|
|
|
|
const auto* begin = reinterpret_cast<u8*>(info.data() + next_entry_index); |
|
|
|
|
|
const auto* end = reinterpret_cast<u8*>(info.data() + next_entry_index + actual_entries); |
|
|
|
|
|
const auto range_size = static_cast<std::size_t>(std::distance(begin, end)); |
|
|
|
|
|
|
|
|
|
|
|
next_entry_index += actual_entries; |
|
|
|
|
|
|
|
|
|
|
|
// Write the data to memory
|
|
|
|
|
|
ctx.WriteBuffer(begin, range_size); |
|
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 3}; |
|
|
|
|
|
rb.Push(RESULT_SUCCESS); |
|
|
|
|
|
rb.Push<u32>(static_cast<u32>(actual_entries)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private: |
|
|
|
|
|
static u64 stoull_be(std::string_view str) { |
|
|
|
|
|
if (str.size() != 16) |
|
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
|
|
const auto bytes = Common::HexStringToArray<0x8>(str); |
|
|
|
|
|
u64 out{}; |
|
|
|
|
|
std::memcpy(&out, bytes.data(), sizeof(u64)); |
|
|
|
|
|
|
|
|
|
|
|
return Common::swap64(out); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FindAllSaves(FileSys::SaveDataSpaceId space) { |
|
|
|
|
|
const auto save_root = OpenSaveDataSpace(space); |
|
|
|
|
|
ASSERT(save_root.Succeeded()); |
|
|
|
|
|
|
|
|
|
|
|
for (const auto& type : (*save_root)->GetSubdirectories()) { |
|
|
|
|
|
if (type->GetName() == "save") { |
|
|
|
|
|
for (const auto& save_id : type->GetSubdirectories()) { |
|
|
|
|
|
for (const auto& user_id : save_id->GetSubdirectories()) { |
|
|
|
|
|
const auto save_id_numeric = stoull_be(save_id->GetName()); |
|
|
|
|
|
auto user_id_numeric = Common::HexStringToArray<0x10>(user_id->GetName()); |
|
|
|
|
|
std::reverse(user_id_numeric.begin(), user_id_numeric.end()); |
|
|
|
|
|
|
|
|
|
|
|
if (save_id_numeric != 0) { |
|
|
|
|
|
// System Save Data
|
|
|
|
|
|
info.emplace_back(SaveDataInfo{ |
|
|
|
|
|
0, |
|
|
|
|
|
space, |
|
|
|
|
|
FileSys::SaveDataType::SystemSaveData, |
|
|
|
|
|
{}, |
|
|
|
|
|
user_id_numeric, |
|
|
|
|
|
save_id_numeric, |
|
|
|
|
|
0, |
|
|
|
|
|
user_id->GetSize(), |
|
|
|
|
|
{}, |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (const auto& title_id : user_id->GetSubdirectories()) { |
|
|
|
|
|
const auto device = |
|
|
|
|
|
std::all_of(user_id_numeric.begin(), user_id_numeric.end(), |
|
|
|
|
|
[](u8 val) { return val == 0; }); |
|
|
|
|
|
info.emplace_back(SaveDataInfo{ |
|
|
|
|
|
0, |
|
|
|
|
|
space, |
|
|
|
|
|
device ? FileSys::SaveDataType::DeviceSaveData |
|
|
|
|
|
: FileSys::SaveDataType::SaveData, |
|
|
|
|
|
{}, |
|
|
|
|
|
user_id_numeric, |
|
|
|
|
|
save_id_numeric, |
|
|
|
|
|
stoull_be(title_id->GetName()), |
|
|
|
|
|
title_id->GetSize(), |
|
|
|
|
|
{}, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} else if (space == FileSys::SaveDataSpaceId::TemporaryStorage) { |
|
|
|
|
|
// Temporary Storage
|
|
|
|
|
|
for (const auto& user_id : type->GetSubdirectories()) { |
|
|
|
|
|
for (const auto& title_id : user_id->GetSubdirectories()) { |
|
|
|
|
|
if (!title_id->GetFiles().empty() || |
|
|
|
|
|
!title_id->GetSubdirectories().empty()) { |
|
|
|
|
|
auto user_id_numeric = |
|
|
|
|
|
Common::HexStringToArray<0x10>(user_id->GetName()); |
|
|
|
|
|
std::reverse(user_id_numeric.begin(), user_id_numeric.end()); |
|
|
|
|
|
|
|
|
|
|
|
info.emplace_back(SaveDataInfo{ |
|
|
|
|
|
0, |
|
|
|
|
|
space, |
|
|
|
|
|
FileSys::SaveDataType::TemporaryStorage, |
|
|
|
|
|
{}, |
|
|
|
|
|
user_id_numeric, |
|
|
|
|
|
stoull_be(type->GetName()), |
|
|
|
|
|
stoull_be(title_id->GetName()), |
|
|
|
|
|
title_id->GetSize(), |
|
|
|
|
|
{}, |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
struct SaveDataInfo { |
|
|
|
|
|
u64_le save_id_unknown; |
|
|
|
|
|
FileSys::SaveDataSpaceId space; |
|
|
|
|
|
FileSys::SaveDataType type; |
|
|
|
|
|
INSERT_PADDING_BYTES(0x6); |
|
|
|
|
|
std::array<u8, 0x10> user_id; |
|
|
|
|
|
u64_le save_id; |
|
|
|
|
|
u64_le title_id; |
|
|
|
|
|
u64_le save_image_size; |
|
|
|
|
|
INSERT_PADDING_BYTES(0x28); |
|
|
|
|
|
}; |
|
|
|
|
|
static_assert(sizeof(SaveDataInfo) == 0x60, "SaveDataInfo has incorrect size."); |
|
|
|
|
|
|
|
|
|
|
|
std::vector<SaveDataInfo> info; |
|
|
|
|
|
u64 next_entry_index = 0; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { |
|
|
FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { |
|
|
|
|
|
// clang-format off
|
|
|
static const FunctionInfo functions[] = { |
|
|
static const FunctionInfo functions[] = { |
|
|
{0, nullptr, "MountContent"}, |
|
|
{0, nullptr, "MountContent"}, |
|
|
{1, &FSP_SRV::Initialize, "Initialize"}, |
|
|
{1, &FSP_SRV::Initialize, "Initialize"}, |
|
|
@ -485,7 +626,7 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { |
|
|
{58, nullptr, "ReadSaveDataFileSystemExtraData"}, |
|
|
{58, nullptr, "ReadSaveDataFileSystemExtraData"}, |
|
|
{59, nullptr, "WriteSaveDataFileSystemExtraData"}, |
|
|
{59, nullptr, "WriteSaveDataFileSystemExtraData"}, |
|
|
{60, nullptr, "OpenSaveDataInfoReader"}, |
|
|
{60, nullptr, "OpenSaveDataInfoReader"}, |
|
|
{61, nullptr, "OpenSaveDataInfoReaderBySaveDataSpaceId"}, |
|
|
|
|
|
|
|
|
{61, &FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId, "OpenSaveDataInfoReaderBySaveDataSpaceId"}, |
|
|
{62, nullptr, "OpenCacheStorageList"}, |
|
|
{62, nullptr, "OpenCacheStorageList"}, |
|
|
{64, nullptr, "OpenSaveDataInternalStorageFileSystem"}, |
|
|
{64, nullptr, "OpenSaveDataInternalStorageFileSystem"}, |
|
|
{65, nullptr, "UpdateSaveDataMacForDebug"}, |
|
|
{65, nullptr, "UpdateSaveDataMacForDebug"}, |
|
|
@ -544,6 +685,7 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { |
|
|
{1009, nullptr, "GetAndClearMemoryReportInfo"}, |
|
|
{1009, nullptr, "GetAndClearMemoryReportInfo"}, |
|
|
{1100, nullptr, "OverrideSaveDataTransferTokenSignVerificationKey"}, |
|
|
{1100, nullptr, "OverrideSaveDataTransferTokenSignVerificationKey"}, |
|
|
}; |
|
|
}; |
|
|
|
|
|
// clang-format on
|
|
|
RegisterHandlers(functions); |
|
|
RegisterHandlers(functions); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -618,6 +760,15 @@ void FSP_SRV::OpenReadOnlySaveDataFileSystem(Kernel::HLERequestContext& ctx) { |
|
|
MountSaveData(ctx); |
|
|
MountSaveData(ctx); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId(Kernel::HLERequestContext& ctx) { |
|
|
|
|
|
IPC::RequestParser rp{ctx}; |
|
|
|
|
|
const auto space = rp.PopRaw<FileSys::SaveDataSpaceId>(); |
|
|
|
|
|
|
|
|
|
|
|
IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
|
|
|
|
|
rb.Push(RESULT_SUCCESS); |
|
|
|
|
|
rb.PushIpcInterface<ISaveDataInfoReader>(std::make_shared<ISaveDataInfoReader>(space)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { |
|
|
void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { |
|
|
LOG_WARNING(Service_FS, "(STUBBED) called"); |
|
|
LOG_WARNING(Service_FS, "(STUBBED) called"); |
|
|
|
|
|
|
|
|
|