Browse Source
Merge pull request #13073 from FearlessTobi/fsp-srv-ipc
Merge pull request #13073 from FearlessTobi/fsp-srv-ipc
fsp: Migrate remaining interfaces to cmif serializationpull/15/merge
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 715 additions and 643 deletions
-
6src/android/app/src/main/jni/native.cpp
-
7src/core/CMakeLists.txt
-
175src/core/file_sys/fs_save_data_types.h
-
90src/core/file_sys/savedata_factory.cpp
-
68src/core/file_sys/savedata_factory.h
-
6src/core/hle/service/am/service/application_functions.cpp
-
2src/core/hle/service/filesystem/fsp/fs_i_filesystem.h
-
33src/core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.cpp
-
23src/core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.h
-
161src/core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.cpp
-
50src/core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.h
-
47src/core/hle/service/filesystem/fsp/fs_i_storage.cpp
-
7src/core/hle/service/filesystem/fsp/fs_i_storage.h
-
589src/core/hle/service/filesystem/fsp/fsp_srv.cpp
-
72src/core/hle/service/filesystem/fsp/fsp_srv.h
-
12src/core/hle/service/filesystem/fsp/fsp_types.h
-
10src/yuzu/main.cpp
@ -0,0 +1,175 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project |
|||
// SPDX-License-Identifier: GPL-2.0-or-later |
|||
|
|||
#pragma once |
|||
|
|||
#include <array> |
|||
#include <fmt/format.h> |
|||
#include "common/common_funcs.h" |
|||
#include "common/common_types.h" |
|||
|
|||
namespace FileSys { |
|||
|
|||
using SaveDataId = u64; |
|||
using SystemSaveDataId = u64; |
|||
using SystemBcatSaveDataId = SystemSaveDataId; |
|||
using ProgramId = u64; |
|||
|
|||
enum class SaveDataSpaceId : u8 { |
|||
System = 0, |
|||
User = 1, |
|||
SdSystem = 2, |
|||
Temporary = 3, |
|||
SdUser = 4, |
|||
|
|||
ProperSystem = 100, |
|||
SafeMode = 101, |
|||
}; |
|||
|
|||
enum class SaveDataType : u8 { |
|||
System = 0, |
|||
Account = 1, |
|||
Bcat = 2, |
|||
Device = 3, |
|||
Temporary = 4, |
|||
Cache = 5, |
|||
SystemBcat = 6, |
|||
}; |
|||
|
|||
enum class SaveDataRank : u8 { |
|||
Primary = 0, |
|||
Secondary = 1, |
|||
}; |
|||
|
|||
struct SaveDataSize { |
|||
u64 normal; |
|||
u64 journal; |
|||
}; |
|||
static_assert(sizeof(SaveDataSize) == 0x10, "SaveDataSize has invalid size."); |
|||
|
|||
using UserId = u128; |
|||
static_assert(std::is_trivially_copyable_v<UserId>, "Data type must be trivially copyable."); |
|||
static_assert(sizeof(UserId) == 0x10, "UserId has invalid size."); |
|||
|
|||
constexpr inline SystemSaveDataId InvalidSystemSaveDataId = 0; |
|||
constexpr inline UserId InvalidUserId = {}; |
|||
|
|||
enum class SaveDataFlags : u32 { |
|||
None = (0 << 0), |
|||
KeepAfterResettingSystemSaveData = (1 << 0), |
|||
KeepAfterRefurbishment = (1 << 1), |
|||
KeepAfterResettingSystemSaveDataWithoutUserSaveData = (1 << 2), |
|||
NeedsSecureDelete = (1 << 3), |
|||
}; |
|||
|
|||
enum class SaveDataMetaType : u8 { |
|||
None = 0, |
|||
Thumbnail = 1, |
|||
ExtensionContext = 2, |
|||
}; |
|||
|
|||
struct SaveDataMetaInfo { |
|||
u32 size; |
|||
SaveDataMetaType type; |
|||
INSERT_PADDING_BYTES(0xB); |
|||
}; |
|||
static_assert(std::is_trivially_copyable_v<SaveDataMetaInfo>, |
|||
"Data type must be trivially copyable."); |
|||
static_assert(sizeof(SaveDataMetaInfo) == 0x10, "SaveDataMetaInfo has invalid size."); |
|||
|
|||
struct SaveDataCreationInfo { |
|||
s64 size; |
|||
s64 journal_size; |
|||
s64 block_size; |
|||
u64 owner_id; |
|||
u32 flags; |
|||
SaveDataSpaceId space_id; |
|||
bool pseudo; |
|||
INSERT_PADDING_BYTES(0x1A); |
|||
}; |
|||
static_assert(std::is_trivially_copyable_v<SaveDataCreationInfo>, |
|||
"Data type must be trivially copyable."); |
|||
static_assert(sizeof(SaveDataCreationInfo) == 0x40, "SaveDataCreationInfo has invalid size."); |
|||
|
|||
struct SaveDataAttribute { |
|||
ProgramId program_id; |
|||
UserId user_id; |
|||
SystemSaveDataId system_save_data_id; |
|||
SaveDataType type; |
|||
SaveDataRank rank; |
|||
u16 index; |
|||
INSERT_PADDING_BYTES(0x1C); |
|||
|
|||
static constexpr SaveDataAttribute Make(ProgramId program_id, SaveDataType type, UserId user_id, |
|||
SystemSaveDataId system_save_data_id, u16 index, |
|||
SaveDataRank rank) { |
|||
return { |
|||
.program_id = program_id, |
|||
.user_id = user_id, |
|||
.system_save_data_id = system_save_data_id, |
|||
.type = type, |
|||
.rank = rank, |
|||
.index = index, |
|||
}; |
|||
} |
|||
|
|||
static constexpr SaveDataAttribute Make(ProgramId program_id, SaveDataType type, UserId user_id, |
|||
SystemSaveDataId system_save_data_id, u16 index) { |
|||
return Make(program_id, type, user_id, system_save_data_id, index, SaveDataRank::Primary); |
|||
} |
|||
|
|||
static constexpr SaveDataAttribute Make(ProgramId program_id, SaveDataType type, UserId user_id, |
|||
SystemSaveDataId system_save_data_id) { |
|||
return Make(program_id, type, user_id, system_save_data_id, 0, SaveDataRank::Primary); |
|||
} |
|||
|
|||
std::string DebugInfo() const { |
|||
return fmt::format( |
|||
"[title_id={:016X}, user_id={:016X}{:016X}, save_id={:016X}, type={:02X}, " |
|||
"rank={}, index={}]", |
|||
program_id, user_id[1], user_id[0], system_save_data_id, static_cast<u8>(type), |
|||
static_cast<u8>(rank), index); |
|||
} |
|||
}; |
|||
static_assert(sizeof(SaveDataAttribute) == 0x40); |
|||
static_assert(std::is_trivially_destructible<SaveDataAttribute>::value); |
|||
|
|||
constexpr inline bool operator<(const SaveDataAttribute& lhs, const SaveDataAttribute& rhs) { |
|||
return std::tie(lhs.program_id, lhs.user_id, lhs.system_save_data_id, lhs.index, lhs.rank) < |
|||
std::tie(rhs.program_id, rhs.user_id, rhs.system_save_data_id, rhs.index, rhs.rank); |
|||
} |
|||
|
|||
constexpr inline bool operator==(const SaveDataAttribute& lhs, const SaveDataAttribute& rhs) { |
|||
return std::tie(lhs.program_id, lhs.user_id, lhs.system_save_data_id, lhs.type, lhs.rank, |
|||
lhs.index) == std::tie(rhs.program_id, rhs.user_id, rhs.system_save_data_id, |
|||
rhs.type, rhs.rank, rhs.index); |
|||
} |
|||
|
|||
constexpr inline bool operator!=(const SaveDataAttribute& lhs, const SaveDataAttribute& rhs) { |
|||
return !(lhs == rhs); |
|||
} |
|||
|
|||
struct SaveDataExtraData { |
|||
SaveDataAttribute attr; |
|||
u64 owner_id; |
|||
s64 timestamp; |
|||
u32 flags; |
|||
INSERT_PADDING_BYTES(4); |
|||
s64 available_size; |
|||
s64 journal_size; |
|||
s64 commit_id; |
|||
INSERT_PADDING_BYTES(0x190); |
|||
}; |
|||
static_assert(sizeof(SaveDataExtraData) == 0x200, "SaveDataExtraData has invalid size."); |
|||
static_assert(std::is_trivially_copyable_v<SaveDataExtraData>, |
|||
"Data type must be trivially copyable."); |
|||
|
|||
struct HashSalt { |
|||
static constexpr size_t Size = 32; |
|||
|
|||
std::array<u8, Size> value; |
|||
}; |
|||
static_assert(std::is_trivially_copyable_v<HashSalt>, "Data type must be trivially copyable."); |
|||
static_assert(sizeof(HashSalt) == HashSalt::Size); |
|||
|
|||
} // namespace FileSys |
|||
@ -0,0 +1,33 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|||
|
|||
#include "core/hle/service/cmif_serialization.h"
|
|||
#include "core/hle/service/filesystem/fsp/fs_i_filesystem.h"
|
|||
#include "core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.h"
|
|||
|
|||
namespace Service::FileSystem { |
|||
|
|||
IMultiCommitManager::IMultiCommitManager(Core::System& system_) |
|||
: ServiceFramework{system_, "IMultiCommitManager"} { |
|||
static const FunctionInfo functions[] = { |
|||
{1, D<&IMultiCommitManager::Add>, "Add"}, |
|||
{2, D<&IMultiCommitManager::Commit>, "Commit"}, |
|||
}; |
|||
RegisterHandlers(functions); |
|||
} |
|||
|
|||
IMultiCommitManager::~IMultiCommitManager() = default; |
|||
|
|||
Result IMultiCommitManager::Add(std::shared_ptr<IFileSystem> filesystem) { |
|||
LOG_WARNING(Service_FS, "(STUBBED) called"); |
|||
|
|||
R_SUCCEED(); |
|||
} |
|||
|
|||
Result IMultiCommitManager::Commit() { |
|||
LOG_WARNING(Service_FS, "(STUBBED) called"); |
|||
|
|||
R_SUCCEED(); |
|||
} |
|||
|
|||
} // namespace Service::FileSystem
|
|||
@ -0,0 +1,23 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project |
|||
// SPDX-License-Identifier: GPL-2.0-or-later |
|||
|
|||
#pragma once |
|||
|
|||
#include "core/file_sys/vfs/vfs.h" |
|||
#include "core/hle/service/service.h" |
|||
|
|||
namespace Service::FileSystem { |
|||
|
|||
class IMultiCommitManager final : public ServiceFramework<IMultiCommitManager> { |
|||
public: |
|||
explicit IMultiCommitManager(Core::System& system_); |
|||
~IMultiCommitManager() override; |
|||
|
|||
private: |
|||
Result Add(std::shared_ptr<IFileSystem> filesystem); |
|||
Result Commit(); |
|||
|
|||
FileSys::VirtualFile backend; |
|||
}; |
|||
|
|||
} // namespace Service::FileSystem |
|||
@ -0,0 +1,161 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|||
// SPDX-License-Identifier: GPL-2.0-or-later
|
|||
|
|||
#include "common/hex_util.h"
|
|||
#include "core/file_sys/savedata_factory.h"
|
|||
#include "core/hle/service/cmif_serialization.h"
|
|||
#include "core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.h"
|
|||
#include "core/hle/service/filesystem/save_data_controller.h"
|
|||
|
|||
namespace Service::FileSystem { |
|||
|
|||
ISaveDataInfoReader::ISaveDataInfoReader(Core::System& system_, |
|||
std::shared_ptr<SaveDataController> save_data_controller_, |
|||
FileSys::SaveDataSpaceId space) |
|||
: ServiceFramework{system_, "ISaveDataInfoReader"}, save_data_controller{ |
|||
save_data_controller_} { |
|||
static const FunctionInfo functions[] = { |
|||
{0, D<&ISaveDataInfoReader::ReadSaveDataInfo>, "ReadSaveDataInfo"}, |
|||
}; |
|||
RegisterHandlers(functions); |
|||
|
|||
FindAllSaves(space); |
|||
} |
|||
|
|||
ISaveDataInfoReader::~ISaveDataInfoReader() = default; |
|||
|
|||
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); |
|||
} |
|||
|
|||
Result ISaveDataInfoReader::ReadSaveDataInfo( |
|||
Out<u64> out_count, OutArray<SaveDataInfo, BufferAttr_HipcMapAlias> out_entries) { |
|||
LOG_DEBUG(Service_FS, "called"); |
|||
|
|||
// Calculate how many entries we can fit in the output buffer
|
|||
const u64 count_entries = out_entries.size(); |
|||
|
|||
// 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
|
|||
std::memcpy(out_entries.data(), begin, range_size); |
|||
*out_count = actual_entries; |
|||
|
|||
R_SUCCEED(); |
|||
} |
|||
|
|||
void ISaveDataInfoReader::FindAllSaves(FileSys::SaveDataSpaceId space) { |
|||
FileSys::VirtualDir save_root{}; |
|||
const auto result = save_data_controller->OpenSaveDataSpace(&save_root, space); |
|||
|
|||
if (result != ResultSuccess || save_root == nullptr) { |
|||
LOG_ERROR(Service_FS, "The save root for the space_id={:02X} was invalid!", space); |
|||
return; |
|||
} |
|||
|
|||
for (const auto& type : save_root->GetSubdirectories()) { |
|||
if (type->GetName() == "save") { |
|||
FindNormalSaves(space, type); |
|||
} else if (space == FileSys::SaveDataSpaceId::Temporary) { |
|||
FindTemporaryStorageSaves(space, type); |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ISaveDataInfoReader::FindNormalSaves(FileSys::SaveDataSpaceId space, |
|||
const FileSys::VirtualDir& type) { |
|||
for (const auto& save_id : type->GetSubdirectories()) { |
|||
for (const auto& user_id : save_id->GetSubdirectories()) { |
|||
// Skip non user id subdirectories
|
|||
if (user_id->GetName().size() != 0x20) { |
|||
continue; |
|||
} |
|||
|
|||
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::System, |
|||
{}, |
|||
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::Device : FileSys::SaveDataType::Account, |
|||
{}, |
|||
user_id_numeric, |
|||
save_id_numeric, |
|||
stoull_be(title_id->GetName()), |
|||
title_id->GetSize(), |
|||
{}, |
|||
{}, |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ISaveDataInfoReader::FindTemporaryStorageSaves(FileSys::SaveDataSpaceId space, |
|||
const FileSys::VirtualDir& type) { |
|||
for (const auto& user_id : type->GetSubdirectories()) { |
|||
// Skip non user id subdirectories
|
|||
if (user_id->GetName().size() != 0x20) { |
|||
continue; |
|||
} |
|||
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::Temporary, |
|||
{}, |
|||
user_id_numeric, |
|||
stoull_be(type->GetName()), |
|||
stoull_be(title_id->GetName()), |
|||
title_id->GetSize(), |
|||
{}, |
|||
{}, |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
} // namespace Service::FileSystem
|
|||
@ -0,0 +1,50 @@ |
|||
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project |
|||
// SPDX-License-Identifier: GPL-2.0-or-later |
|||
|
|||
#pragma once |
|||
|
|||
#include <vector> |
|||
#include "common/common_types.h" |
|||
#include "core/hle/service/cmif_types.h" |
|||
#include "core/hle/service/service.h" |
|||
|
|||
namespace Service::FileSystem { |
|||
|
|||
class SaveDataController; |
|||
|
|||
class ISaveDataInfoReader final : public ServiceFramework<ISaveDataInfoReader> { |
|||
public: |
|||
explicit ISaveDataInfoReader(Core::System& system_, |
|||
std::shared_ptr<SaveDataController> save_data_controller_, |
|||
FileSys::SaveDataSpaceId space); |
|||
~ISaveDataInfoReader() override; |
|||
|
|||
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; |
|||
u16_le index; |
|||
FileSys::SaveDataRank rank; |
|||
INSERT_PADDING_BYTES(0x25); |
|||
}; |
|||
static_assert(sizeof(SaveDataInfo) == 0x60, "SaveDataInfo has incorrect size."); |
|||
|
|||
Result ReadSaveDataInfo(Out<u64> out_count, |
|||
OutArray<SaveDataInfo, BufferAttr_HipcMapAlias> out_entries); |
|||
|
|||
private: |
|||
void FindAllSaves(FileSys::SaveDataSpaceId space); |
|||
void FindNormalSaves(FileSys::SaveDataSpaceId space, const FileSys::VirtualDir& type); |
|||
void FindTemporaryStorageSaves(FileSys::SaveDataSpaceId space, const FileSys::VirtualDir& type); |
|||
|
|||
std::shared_ptr<SaveDataController> save_data_controller; |
|||
std::vector<SaveDataInfo> info; |
|||
u64 next_entry_index = 0; |
|||
}; |
|||
|
|||
} // namespace Service::FileSystem |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue