1
0
Fork 1
forked from suyu/suyu

fsp: Migrate remaining interfaces to cmif serialization

This commit is contained in:
FearlessTobi 2024-02-19 02:58:25 +01:00
parent fdf4a5bc90
commit 4c71bf3d90
6 changed files with 48 additions and 62 deletions

View file

@ -1,34 +1,32 @@
// 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_multi_commit_manager.h"
#include "core/hle/service/ipc_helpers.h"
namespace Service::FileSystem {
IMultiCommitManager::IMultiCommitManager(Core::System& system_)
: ServiceFramework{system_, "IMultiCommitManager"} {
static const FunctionInfo functions[] = {
{1, &IMultiCommitManager::Add, "Add"},
{2, &IMultiCommitManager::Commit, "Commit"},
{1, D<&IMultiCommitManager::Add>, "Add"},
{2, D<&IMultiCommitManager::Commit>, "Commit"},
};
RegisterHandlers(functions);
}
IMultiCommitManager::~IMultiCommitManager() = default;
void IMultiCommitManager::Add(HLERequestContext& ctx) {
Result IMultiCommitManager::Add() {
LOG_WARNING(Service_FS, "(STUBBED) called");
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
R_SUCCEED();
}
void IMultiCommitManager::Commit(HLERequestContext& ctx) {
Result IMultiCommitManager::Commit() {
LOG_WARNING(Service_FS, "(STUBBED) called");
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
R_SUCCEED();
}
} // namespace Service::FileSystem

View file

@ -14,8 +14,8 @@ public:
~IMultiCommitManager() override;
private:
void Add(HLERequestContext& ctx);
void Commit(HLERequestContext& ctx);
Result Add();
Result Commit();
FileSys::VirtualFile backend;
};

View file

@ -3,19 +3,19 @@
#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"
#include "core/hle/service/ipc_helpers.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_} {
: ServiceFramework{system_, "ISaveDataInfoReader"}, save_data_controller{
save_data_controller_} {
static const FunctionInfo functions[] = {
{0, &ISaveDataInfoReader::ReadSaveDataInfo, "ReadSaveDataInfo"},
{0, D<&ISaveDataInfoReader::ReadSaveDataInfo>, "ReadSaveDataInfo"},
};
RegisterHandlers(functions);
@ -36,11 +36,12 @@ static u64 stoull_be(std::string_view str) {
return Common::swap64(out);
}
void ISaveDataInfoReader::ReadSaveDataInfo(HLERequestContext& ctx) {
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 = ctx.GetWriteBufferNumElements<SaveDataInfo>();
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);
@ -53,11 +54,10 @@ void ISaveDataInfoReader::ReadSaveDataInfo(HLERequestContext& ctx) {
next_entry_index += actual_entries;
// Write the data to memory
ctx.WriteBuffer(begin, range_size);
std::memcpy(out_entries.data(), begin, range_size);
*out_count = actual_entries;
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(ResultSuccess);
rb.Push<u64>(actual_entries);
R_SUCCEED();
}
void ISaveDataInfoReader::FindAllSaves(FileSys::SaveDataSpaceId space) {

View file

@ -5,6 +5,7 @@
#include <vector>
#include "common/common_types.h"
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/service.h"
namespace Service::FileSystem {
@ -18,13 +19,6 @@ public:
FileSys::SaveDataSpaceId space);
~ISaveDataInfoReader() override;
void ReadSaveDataInfo(HLERequestContext& ctx);
private:
void FindAllSaves(FileSys::SaveDataSpaceId space);
void FindNormalSaves(FileSys::SaveDataSpaceId space, const FileSys::VirtualDir& type);
void FindTemporaryStorageSaves(FileSys::SaveDataSpaceId space, const FileSys::VirtualDir& type);
struct SaveDataInfo {
u64_le save_id_unknown;
FileSys::SaveDataSpaceId space;
@ -40,6 +34,14 @@ private:
};
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;

View file

@ -2,61 +2,44 @@
// SPDX-License-Identifier: GPL-2.0-or-later
#include "core/file_sys/errors.h"
#include "core/hle/service/cmif_serialization.h"
#include "core/hle/service/filesystem/fsp/fs_i_storage.h"
#include "core/hle/service/ipc_helpers.h"
namespace Service::FileSystem {
IStorage::IStorage(Core::System& system_, FileSys::VirtualFile backend_)
: ServiceFramework{system_, "IStorage"}, backend(std::move(backend_)) {
static const FunctionInfo functions[] = {
{0, &IStorage::Read, "Read"},
{0, D<&IStorage::Read>, "Read"},
{1, nullptr, "Write"},
{2, nullptr, "Flush"},
{3, nullptr, "SetSize"},
{4, &IStorage::GetSize, "GetSize"},
{4, D<&IStorage::GetSize>, "GetSize"},
{5, nullptr, "OperateRange"},
};
RegisterHandlers(functions);
}
void IStorage::Read(HLERequestContext& ctx) {
IPC::RequestParser rp{ctx};
const s64 offset = rp.Pop<s64>();
const s64 length = rp.Pop<s64>();
Result IStorage::Read(
OutBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> out_bytes,
s64 offset, s64 length) {
LOG_DEBUG(Service_FS, "called, offset=0x{:X}, length={}", offset, length);
// Error checking
if (length < 0) {
LOG_ERROR(Service_FS, "Length is less than 0, length={}", length);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(FileSys::ResultInvalidSize);
return;
}
if (offset < 0) {
LOG_ERROR(Service_FS, "Offset is less than 0, offset={}", offset);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(FileSys::ResultInvalidOffset);
return;
}
R_UNLESS(length >= 0, FileSys::ResultInvalidSize);
R_UNLESS(offset >= 0, FileSys::ResultInvalidOffset);
// Read the data from the Storage backend
std::vector<u8> output = backend->ReadBytes(length, offset);
// Write the data to memory
ctx.WriteBuffer(output);
backend->Read(out_bytes.data(), length, offset);
IPC::ResponseBuilder rb{ctx, 2};
rb.Push(ResultSuccess);
R_SUCCEED();
}
void IStorage::GetSize(HLERequestContext& ctx) {
const u64 size = backend->GetSize();
LOG_DEBUG(Service_FS, "called, size={}", size);
Result IStorage::GetSize(Out<u64> out_size) {
*out_size = backend->GetSize();
IPC::ResponseBuilder rb{ctx, 4};
rb.Push(ResultSuccess);
rb.Push<u64>(size);
LOG_DEBUG(Service_FS, "called, size={}", *out_size);
R_SUCCEED();
}
} // namespace Service::FileSystem

View file

@ -4,6 +4,7 @@
#pragma once
#include "core/file_sys/vfs/vfs.h"
#include "core/hle/service/cmif_types.h"
#include "core/hle/service/filesystem/filesystem.h"
#include "core/hle/service/service.h"
@ -16,8 +17,10 @@ public:
private:
FileSys::VirtualFile backend;
void Read(HLERequestContext& ctx);
void GetSize(HLERequestContext& ctx);
Result Read(
OutBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> out_bytes,
s64 offset, s64 length);
Result GetSize(Out<u64> out_size);
};
} // namespace Service::FileSystem