diff options
Diffstat (limited to 'src/core/hle')
33 files changed, 1062 insertions, 939 deletions
diff --git a/src/core/hle/service/am/service/application_functions.cpp b/src/core/hle/service/am/service/application_functions.cpp index cb53b07e0..bfccb6b09 100644 --- a/src/core/hle/service/am/service/application_functions.cpp +++ b/src/core/hle/service/am/service/application_functions.cpp @@ -123,13 +123,13 @@ Result IApplicationFunctions::EnsureSaveData(Out<u64> out_size, Common::UUID use LOG_INFO(Service_AM, "called, uid={}", user_id.FormattedString()); FileSys::SaveDataAttribute attribute{}; - attribute.title_id = m_applet->program_id; + attribute.program_id = m_applet->program_id; attribute.user_id = user_id.AsU128(); - attribute.type = FileSys::SaveDataType::SaveData; + attribute.type = FileSys::SaveDataType::Account; FileSys::VirtualDir save_data{}; R_TRY(system.GetFileSystemController().OpenSaveDataController()->CreateSaveData( - &save_data, FileSys::SaveDataSpaceId::NandUser, attribute)); + &save_data, FileSys::SaveDataSpaceId::User, attribute)); *out_size = 0; R_SUCCEED(); diff --git a/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp b/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp index 39690018b..8483394d0 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp @@ -3,82 +3,34 @@ #include "core/file_sys/fs_filesystem.h" #include "core/file_sys/savedata_factory.h" +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/filesystem/fsp/fs_i_directory.h" -#include "core/hle/service/ipc_helpers.h" namespace Service::FileSystem { -template <typename T> -static void BuildEntryIndex(std::vector<FileSys::DirectoryEntry>& entries, - const std::vector<T>& new_data, FileSys::DirectoryEntryType type) { - entries.reserve(entries.size() + new_data.size()); - - for (const auto& new_entry : new_data) { - auto name = new_entry->GetName(); - - if (type == FileSys::DirectoryEntryType::File && - name == FileSys::GetSaveDataSizeFileName()) { - continue; - } - - entries.emplace_back(name, static_cast<s8>(type), - type == FileSys::DirectoryEntryType::Directory ? 0 - : new_entry->GetSize()); - } -} - -IDirectory::IDirectory(Core::System& system_, FileSys::VirtualDir backend_, +IDirectory::IDirectory(Core::System& system_, FileSys::VirtualDir directory_, FileSys::OpenDirectoryMode mode) - : ServiceFramework{system_, "IDirectory"}, backend(std::move(backend_)) { + : ServiceFramework{system_, "IDirectory"}, + backend(std::make_unique<FileSys::Fsa::IDirectory>(directory_, mode)) { static const FunctionInfo functions[] = { - {0, &IDirectory::Read, "Read"}, - {1, &IDirectory::GetEntryCount, "GetEntryCount"}, + {0, D<&IDirectory::Read>, "Read"}, + {1, D<&IDirectory::GetEntryCount>, "GetEntryCount"}, }; RegisterHandlers(functions); - - // TODO(DarkLordZach): Verify that this is the correct behavior. - // Build entry index now to save time later. - if (True(mode & FileSys::OpenDirectoryMode::Directory)) { - BuildEntryIndex(entries, backend->GetSubdirectories(), - FileSys::DirectoryEntryType::Directory); - } - if (True(mode & FileSys::OpenDirectoryMode::File)) { - BuildEntryIndex(entries, backend->GetFiles(), FileSys::DirectoryEntryType::File); - } } -void IDirectory::Read(HLERequestContext& ctx) { +Result IDirectory::Read( + Out<s64> out_count, + const OutArray<FileSys::DirectoryEntry, 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<FileSys::DirectoryEntry>(); - - // Cap at total number of entries. - const u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index); - - // Determine data start and end - const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index); - const auto* end = reinterpret_cast<u8*>(entries.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, 4}; - rb.Push(ResultSuccess); - rb.Push(actual_entries); + R_RETURN(backend->Read(out_count, out_entries.data(), out_entries.size())); } -void IDirectory::GetEntryCount(HLERequestContext& ctx) { +Result IDirectory::GetEntryCount(Out<s64> out_count) { LOG_DEBUG(Service_FS, "called"); - u64 count = entries.size() - next_entry_index; - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(count); + R_RETURN(backend->GetEntryCount(out_count)); } } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/fsp/fs_i_directory.h b/src/core/hle/service/filesystem/fsp/fs_i_directory.h index 793ecfcd7..b6251f7fd 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_directory.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_directory.h @@ -3,7 +3,9 @@ #pragma once +#include "core/file_sys/fsa/fs_i_directory.h" #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" @@ -15,16 +17,15 @@ namespace Service::FileSystem { class IDirectory final : public ServiceFramework<IDirectory> { public: - explicit IDirectory(Core::System& system_, FileSys::VirtualDir backend_, + explicit IDirectory(Core::System& system_, FileSys::VirtualDir directory_, FileSys::OpenDirectoryMode mode); private: - FileSys::VirtualDir backend; - std::vector<FileSys::DirectoryEntry> entries; - u64 next_entry_index = 0; + std::unique_ptr<FileSys::Fsa::IDirectory> backend; - void Read(HLERequestContext& ctx); - void GetEntryCount(HLERequestContext& ctx); + Result Read(Out<s64> out_count, + const OutArray<FileSys::DirectoryEntry, BufferAttr_HipcMapAlias> out_entries); + Result GetEntryCount(Out<s64> out_count); }; } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/fsp/fs_i_file.cpp b/src/core/hle/service/filesystem/fsp/fs_i_file.cpp index 9a18f6ec5..a355d46ae 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_file.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_file.cpp @@ -2,126 +2,64 @@ // 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_file.h" -#include "core/hle/service/ipc_helpers.h" namespace Service::FileSystem { -IFile::IFile(Core::System& system_, FileSys::VirtualFile backend_) - : ServiceFramework{system_, "IFile"}, backend(std::move(backend_)) { +IFile::IFile(Core::System& system_, FileSys::VirtualFile file_) + : ServiceFramework{system_, "IFile"}, backend{std::make_unique<FileSys::Fsa::IFile>(file_)} { + // clang-format off static const FunctionInfo functions[] = { - {0, &IFile::Read, "Read"}, - {1, &IFile::Write, "Write"}, - {2, &IFile::Flush, "Flush"}, - {3, &IFile::SetSize, "SetSize"}, - {4, &IFile::GetSize, "GetSize"}, + {0, D<&IFile::Read>, "Read"}, + {1, D<&IFile::Write>, "Write"}, + {2, D<&IFile::Flush>, "Flush"}, + {3, D<&IFile::SetSize>, "SetSize"}, + {4, D<&IFile::GetSize>, "GetSize"}, {5, nullptr, "OperateRange"}, {6, nullptr, "OperateRangeWithBuffer"}, }; + // clang-format on RegisterHandlers(functions); } -void IFile::Read(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const u64 option = rp.Pop<u64>(); - const s64 offset = rp.Pop<s64>(); - const s64 length = rp.Pop<s64>(); - - LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option, 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; - } +Result IFile::Read( + FileSys::ReadOption option, Out<s64> out_size, s64 offset, + const OutBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> out_buffer, + s64 size) { + LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset, + size); // Read the data from the Storage backend - std::vector<u8> output = backend->ReadBytes(length, offset); - - // Write the data to memory - ctx.WriteBuffer(output); - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(static_cast<u64>(output.size())); + R_RETURN( + backend->Read(reinterpret_cast<size_t*>(out_size.Get()), offset, out_buffer.data(), size)); } -void IFile::Write(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const u64 option = rp.Pop<u64>(); - const s64 offset = rp.Pop<s64>(); - const s64 length = rp.Pop<s64>(); - - LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option, 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; - } - - const auto data = ctx.ReadBuffer(); +Result IFile::Write( + const InBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> buffer, + FileSys::WriteOption option, s64 offset, s64 size) { + LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset, + size); - ASSERT_MSG(static_cast<s64>(data.size()) <= length, - "Attempting to write more data than requested (requested={:016X}, actual={:016X}).", - length, data.size()); - - // Write the data to the Storage backend - const auto write_size = - static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length)); - const std::size_t written = backend->Write(data.data(), write_size, offset); - - ASSERT_MSG(static_cast<s64>(written) == length, - "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length, - written); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_RETURN(backend->Write(offset, buffer.data(), size, option)); } -void IFile::Flush(HLERequestContext& ctx) { +Result IFile::Flush() { LOG_DEBUG(Service_FS, "called"); - // Exists for SDK compatibiltity -- No need to flush file. - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_RETURN(backend->Flush()); } -void IFile::SetSize(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const u64 size = rp.Pop<u64>(); +Result IFile::SetSize(s64 size) { LOG_DEBUG(Service_FS, "called, size={}", size); - backend->Resize(size); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_RETURN(backend->SetSize(size)); } -void IFile::GetSize(HLERequestContext& ctx) { - const u64 size = backend->GetSize(); - LOG_DEBUG(Service_FS, "called, size={}", size); +Result IFile::GetSize(Out<s64> out_size) { + LOG_DEBUG(Service_FS, "called"); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push<u64>(size); + R_RETURN(backend->GetSize(out_size)); } } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/fsp/fs_i_file.h b/src/core/hle/service/filesystem/fsp/fs_i_file.h index 5e5430c67..e8599ee2f 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_file.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_file.h @@ -3,6 +3,8 @@ #pragma once +#include "core/file_sys/fsa/fs_i_file.h" +#include "core/hle/service/cmif_types.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/service.h" @@ -10,16 +12,21 @@ namespace Service::FileSystem { class IFile final : public ServiceFramework<IFile> { public: - explicit IFile(Core::System& system_, FileSys::VirtualFile backend_); + explicit IFile(Core::System& system_, FileSys::VirtualFile file_); private: - FileSys::VirtualFile backend; + std::unique_ptr<FileSys::Fsa::IFile> backend; - void Read(HLERequestContext& ctx); - void Write(HLERequestContext& ctx); - void Flush(HLERequestContext& ctx); - void SetSize(HLERequestContext& ctx); - void GetSize(HLERequestContext& ctx); + Result Read(FileSys::ReadOption option, Out<s64> out_size, s64 offset, + const OutBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> + out_buffer, + s64 size); + Result Write( + const InBuffer<BufferAttr_HipcMapAlias | BufferAttr_HipcMapTransferAllowsNonSecure> buffer, + FileSys::WriteOption option, s64 offset, s64 size); + Result Flush(); + Result SetSize(s64 size); + Result GetSize(Out<s64> out_size); }; } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp index efa394dd1..d881e144d 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp @@ -2,261 +2,172 @@ // SPDX-License-Identifier: GPL-2.0-or-later #include "common/string_util.h" +#include "core/file_sys/fssrv/fssrv_sf_path.h" +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/filesystem/fsp/fs_i_directory.h" #include "core/hle/service/filesystem/fsp/fs_i_file.h" #include "core/hle/service/filesystem/fsp/fs_i_filesystem.h" -#include "core/hle/service/ipc_helpers.h" namespace Service::FileSystem { -IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir backend_, SizeGetter size_) - : ServiceFramework{system_, "IFileSystem"}, backend{std::move(backend_)}, size{std::move( - size_)} { +IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_getter_) + : ServiceFramework{system_, "IFileSystem"}, backend{std::make_unique<FileSys::Fsa::IFileSystem>( + dir_)}, + size_getter{std::move(size_getter_)} { static const FunctionInfo functions[] = { - {0, &IFileSystem::CreateFile, "CreateFile"}, - {1, &IFileSystem::DeleteFile, "DeleteFile"}, - {2, &IFileSystem::CreateDirectory, "CreateDirectory"}, - {3, &IFileSystem::DeleteDirectory, "DeleteDirectory"}, - {4, &IFileSystem::DeleteDirectoryRecursively, "DeleteDirectoryRecursively"}, - {5, &IFileSystem::RenameFile, "RenameFile"}, + {0, D<&IFileSystem::CreateFile>, "CreateFile"}, + {1, D<&IFileSystem::DeleteFile>, "DeleteFile"}, + {2, D<&IFileSystem::CreateDirectory>, "CreateDirectory"}, + {3, D<&IFileSystem::DeleteDirectory>, "DeleteDirectory"}, + {4, D<&IFileSystem::DeleteDirectoryRecursively>, "DeleteDirectoryRecursively"}, + {5, D<&IFileSystem::RenameFile>, "RenameFile"}, {6, nullptr, "RenameDirectory"}, - {7, &IFileSystem::GetEntryType, "GetEntryType"}, - {8, &IFileSystem::OpenFile, "OpenFile"}, - {9, &IFileSystem::OpenDirectory, "OpenDirectory"}, - {10, &IFileSystem::Commit, "Commit"}, - {11, &IFileSystem::GetFreeSpaceSize, "GetFreeSpaceSize"}, - {12, &IFileSystem::GetTotalSpaceSize, "GetTotalSpaceSize"}, - {13, &IFileSystem::CleanDirectoryRecursively, "CleanDirectoryRecursively"}, - {14, &IFileSystem::GetFileTimeStampRaw, "GetFileTimeStampRaw"}, + {7, D<&IFileSystem::GetEntryType>, "GetEntryType"}, + {8, D<&IFileSystem::OpenFile>, "OpenFile"}, + {9, D<&IFileSystem::OpenDirectory>, "OpenDirectory"}, + {10, D<&IFileSystem::Commit>, "Commit"}, + {11, D<&IFileSystem::GetFreeSpaceSize>, "GetFreeSpaceSize"}, + {12, D<&IFileSystem::GetTotalSpaceSize>, "GetTotalSpaceSize"}, + {13, D<&IFileSystem::CleanDirectoryRecursively>, "CleanDirectoryRecursively"}, + {14, D<&IFileSystem::GetFileTimeStampRaw>, "GetFileTimeStampRaw"}, {15, nullptr, "QueryEntry"}, - {16, &IFileSystem::GetFileSystemAttribute, "GetFileSystemAttribute"}, + {16, D<&IFileSystem::GetFileSystemAttribute>, "GetFileSystemAttribute"}, }; RegisterHandlers(functions); } -void IFileSystem::CreateFile(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; +Result IFileSystem::CreateFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path, + s32 option, s64 size) { + LOG_DEBUG(Service_FS, "called. file={}, option=0x{:X}, size=0x{:08X}", path->str, option, size); - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); - - const u64 file_mode = rp.Pop<u64>(); - const u32 file_size = rp.Pop<u32>(); - - LOG_DEBUG(Service_FS, "called. file={}, mode=0x{:X}, size=0x{:08X}", name, file_mode, - file_size); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.CreateFile(name, file_size)); + R_RETURN(backend->CreateFile(FileSys::Path(path->str), size)); } -void IFileSystem::DeleteFile(HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); +Result IFileSystem::DeleteFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) { + LOG_DEBUG(Service_FS, "called. file={}", path->str); - LOG_DEBUG(Service_FS, "called. file={}", name); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.DeleteFile(name)); + R_RETURN(backend->DeleteFile(FileSys::Path(path->str))); } -void IFileSystem::CreateDirectory(HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); - - LOG_DEBUG(Service_FS, "called. directory={}", name); +Result IFileSystem::CreateDirectory( + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) { + LOG_DEBUG(Service_FS, "called. directory={}", path->str); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.CreateDirectory(name)); + R_RETURN(backend->CreateDirectory(FileSys::Path(path->str))); } -void IFileSystem::DeleteDirectory(HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); - - LOG_DEBUG(Service_FS, "called. directory={}", name); +Result IFileSystem::DeleteDirectory( + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) { + LOG_DEBUG(Service_FS, "called. directory={}", path->str); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.DeleteDirectory(name)); + R_RETURN(backend->DeleteDirectory(FileSys::Path(path->str))); } -void IFileSystem::DeleteDirectoryRecursively(HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); +Result IFileSystem::DeleteDirectoryRecursively( + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) { + LOG_DEBUG(Service_FS, "called. directory={}", path->str); - LOG_DEBUG(Service_FS, "called. directory={}", name); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.DeleteDirectoryRecursively(name)); + R_RETURN(backend->DeleteDirectoryRecursively(FileSys::Path(path->str))); } -void IFileSystem::CleanDirectoryRecursively(HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); - - LOG_DEBUG(Service_FS, "called. Directory: {}", name); +Result IFileSystem::CleanDirectoryRecursively( + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) { + LOG_DEBUG(Service_FS, "called. Directory: {}", path->str); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.CleanDirectoryRecursively(name)); + R_RETURN(backend->CleanDirectoryRecursively(FileSys::Path(path->str))); } -void IFileSystem::RenameFile(HLERequestContext& ctx) { - const std::string src_name = Common::StringFromBuffer(ctx.ReadBuffer(0)); - const std::string dst_name = Common::StringFromBuffer(ctx.ReadBuffer(1)); - - LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); +Result IFileSystem::RenameFile( + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> old_path, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> new_path) { + LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", old_path->str, new_path->str); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.RenameFile(src_name, dst_name)); + R_RETURN(backend->RenameFile(FileSys::Path(old_path->str), FileSys::Path(new_path->str))); } -void IFileSystem::OpenFile(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); - - const auto mode = static_cast<FileSys::OpenMode>(rp.Pop<u32>()); - - LOG_DEBUG(Service_FS, "called. file={}, mode={}", name, mode); +Result IFileSystem::OpenFile(OutInterface<IFile> out_interface, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path, + u32 mode) { + LOG_DEBUG(Service_FS, "called. file={}, mode={}", path->str, mode); FileSys::VirtualFile vfs_file{}; - auto result = backend.OpenFile(&vfs_file, name, mode); - if (result != ResultSuccess) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - return; - } - - auto file = std::make_shared<IFile>(system, vfs_file); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IFile>(std::move(file)); -} - -void IFileSystem::OpenDirectory(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; + R_TRY(backend->OpenFile(&vfs_file, FileSys::Path(path->str), + static_cast<FileSys::OpenMode>(mode))); - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); - const auto mode = rp.PopRaw<FileSys::OpenDirectoryMode>(); + *out_interface = std::make_shared<IFile>(system, vfs_file); + R_SUCCEED(); +} - LOG_DEBUG(Service_FS, "called. directory={}, mode={}", name, mode); +Result IFileSystem::OpenDirectory(OutInterface<IDirectory> out_interface, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path, + u32 mode) { + LOG_DEBUG(Service_FS, "called. directory={}, mode={}", path->str, mode); FileSys::VirtualDir vfs_dir{}; - auto result = backend.OpenDirectory(&vfs_dir, name); - if (result != ResultSuccess) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - return; - } - - auto directory = std::make_shared<IDirectory>(system, vfs_dir, mode); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IDirectory>(std::move(directory)); -} + R_TRY(backend->OpenDirectory(&vfs_dir, FileSys::Path(path->str), + static_cast<FileSys::OpenDirectoryMode>(mode))); -void IFileSystem::GetEntryType(HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); + *out_interface = std::make_shared<IDirectory>(system, vfs_dir, + static_cast<FileSys::OpenDirectoryMode>(mode)); + R_SUCCEED(); +} - LOG_DEBUG(Service_FS, "called. file={}", name); +Result IFileSystem::GetEntryType( + Out<u32> out_type, const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) { + LOG_DEBUG(Service_FS, "called. file={}", path->str); FileSys::DirectoryEntryType vfs_entry_type{}; - auto result = backend.GetEntryType(&vfs_entry_type, name); - if (result != ResultSuccess) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - return; - } - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push<u32>(static_cast<u32>(vfs_entry_type)); + R_TRY(backend->GetEntryType(&vfs_entry_type, FileSys::Path(path->str))); + + *out_type = static_cast<u32>(vfs_entry_type); + R_SUCCEED(); } -void IFileSystem::Commit(HLERequestContext& ctx) { +Result IFileSystem::Commit() { LOG_WARNING(Service_FS, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void IFileSystem::GetFreeSpaceSize(HLERequestContext& ctx) { +Result IFileSystem::GetFreeSpaceSize( + Out<s64> out_size, const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) { LOG_DEBUG(Service_FS, "called"); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(size.get_free_size()); + *out_size = size_getter.get_free_size(); + R_SUCCEED(); } -void IFileSystem::GetTotalSpaceSize(HLERequestContext& ctx) { +Result IFileSystem::GetTotalSpaceSize( + Out<s64> out_size, const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) { LOG_DEBUG(Service_FS, "called"); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(size.get_total_size()); + *out_size = size_getter.get_total_size(); + R_SUCCEED(); } -void IFileSystem::GetFileTimeStampRaw(HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); - - LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); +Result IFileSystem::GetFileTimeStampRaw( + Out<FileSys::FileTimeStampRaw> out_timestamp, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path) { + LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", path->str); FileSys::FileTimeStampRaw vfs_timestamp{}; - auto result = backend.GetFileTimeStampRaw(&vfs_timestamp, name); - if (result != ResultSuccess) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - return; - } - - IPC::ResponseBuilder rb{ctx, 10}; - rb.Push(ResultSuccess); - rb.PushRaw(vfs_timestamp); + R_TRY(backend->GetFileTimeStampRaw(&vfs_timestamp, FileSys::Path(path->str))); + + *out_timestamp = vfs_timestamp; + R_SUCCEED(); } -void IFileSystem::GetFileSystemAttribute(HLERequestContext& ctx) { +Result IFileSystem::GetFileSystemAttribute(Out<FileSys::FileSystemAttribute> out_attribute) { LOG_WARNING(Service_FS, "(STUBBED) called"); - struct FileSystemAttribute { - u8 dir_entry_name_length_max_defined; - u8 file_entry_name_length_max_defined; - u8 dir_path_name_length_max_defined; - u8 file_path_name_length_max_defined; - INSERT_PADDING_BYTES_NOINIT(0x5); - u8 utf16_dir_entry_name_length_max_defined; - u8 utf16_file_entry_name_length_max_defined; - u8 utf16_dir_path_name_length_max_defined; - u8 utf16_file_path_name_length_max_defined; - INSERT_PADDING_BYTES_NOINIT(0x18); - s32 dir_entry_name_length_max; - s32 file_entry_name_length_max; - s32 dir_path_name_length_max; - s32 file_path_name_length_max; - INSERT_PADDING_WORDS_NOINIT(0x5); - s32 utf16_dir_entry_name_length_max; - s32 utf16_file_entry_name_length_max; - s32 utf16_dir_path_name_length_max; - s32 utf16_file_path_name_length_max; - INSERT_PADDING_WORDS_NOINIT(0x18); - INSERT_PADDING_WORDS_NOINIT(0x1); - }; - static_assert(sizeof(FileSystemAttribute) == 0xc0, "FileSystemAttribute has incorrect size"); - - FileSystemAttribute savedata_attribute{}; + FileSys::FileSystemAttribute savedata_attribute{}; savedata_attribute.dir_entry_name_length_max_defined = true; savedata_attribute.file_entry_name_length_max_defined = true; savedata_attribute.dir_entry_name_length_max = 0x40; savedata_attribute.file_entry_name_length_max = 0x40; - IPC::ResponseBuilder rb{ctx, 50}; - rb.Push(ResultSuccess); - rb.PushRaw(savedata_attribute); + *out_attribute = savedata_attribute; + R_SUCCEED(); } } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h index b06b3ef0e..dd069f36f 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h @@ -3,36 +3,58 @@ #pragma once +#include "common/common_funcs.h" +#include "core/file_sys/fs_filesystem.h" +#include "core/file_sys/fsa/fs_i_filesystem.h" #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/filesystem/fsp/fsp_util.h" +#include "core/hle/service/filesystem/fsp/fsp_types.h" #include "core/hle/service/service.h" +namespace FileSys::Sf { +struct Path; +} + namespace Service::FileSystem { +class IFile; +class IDirectory; + class IFileSystem final : public ServiceFramework<IFileSystem> { public: - explicit IFileSystem(Core::System& system_, FileSys::VirtualDir backend_, SizeGetter size_); - - void CreateFile(HLERequestContext& ctx); - void DeleteFile(HLERequestContext& ctx); - void CreateDirectory(HLERequestContext& ctx); - void DeleteDirectory(HLERequestContext& ctx); - void DeleteDirectoryRecursively(HLERequestContext& ctx); - void CleanDirectoryRecursively(HLERequestContext& ctx); - void RenameFile(HLERequestContext& ctx); - void OpenFile(HLERequestContext& ctx); - void OpenDirectory(HLERequestContext& ctx); - void GetEntryType(HLERequestContext& ctx); - void Commit(HLERequestContext& ctx); - void GetFreeSpaceSize(HLERequestContext& ctx); - void GetTotalSpaceSize(HLERequestContext& ctx); - void GetFileTimeStampRaw(HLERequestContext& ctx); - void GetFileSystemAttribute(HLERequestContext& ctx); + explicit IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_getter_); + + Result CreateFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path, s32 option, + s64 size); + Result DeleteFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); + Result CreateDirectory(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); + Result DeleteDirectory(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); + Result DeleteDirectoryRecursively( + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); + Result CleanDirectoryRecursively( + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); + Result RenameFile(const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> old_path, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> new_path); + Result OpenFile(OutInterface<IFile> out_interface, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path, u32 mode); + Result OpenDirectory(OutInterface<IDirectory> out_interface, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path, + u32 mode); + Result GetEntryType(Out<u32> out_type, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); + Result Commit(); + Result GetFreeSpaceSize(Out<s64> out_size, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); + Result GetTotalSpaceSize(Out<s64> out_size, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); + Result GetFileTimeStampRaw(Out<FileSys::FileTimeStampRaw> out_timestamp, + const InLargeData<FileSys::Sf::Path, BufferAttr_HipcPointer> path); + Result GetFileSystemAttribute(Out<FileSys::FileSystemAttribute> out_attribute); private: - VfsDirectoryServiceWrapper backend; - SizeGetter size; + std::unique_ptr<FileSys::Fsa::IFileSystem> backend; + SizeGetter size_getter; }; } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.cpp b/src/core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.cpp new file mode 100644 index 000000000..626328234 --- /dev/null +++ b/src/core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.cpp @@ -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 diff --git a/src/core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.h b/src/core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.h new file mode 100644 index 000000000..8ebf7c7d9 --- /dev/null +++ b/src/core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.h @@ -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 diff --git a/src/core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.cpp b/src/core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.cpp new file mode 100644 index 000000000..ff823586b --- /dev/null +++ b/src/core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.cpp @@ -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 diff --git a/src/core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.h b/src/core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.h new file mode 100644 index 000000000..e45ad852b --- /dev/null +++ b/src/core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.h @@ -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 diff --git a/src/core/hle/service/filesystem/fsp/fs_i_storage.cpp b/src/core/hle/service/filesystem/fsp/fs_i_storage.cpp index 98223c1f9..213f19808 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_storage.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_storage.cpp @@ -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(); + + LOG_DEBUG(Service_FS, "called, size={}", *out_size); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push<u64>(size); + R_SUCCEED(); } } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/fsp/fs_i_storage.h b/src/core/hle/service/filesystem/fsp/fs_i_storage.h index cb5bebcc9..74d879386 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_storage.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_storage.h @@ -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 diff --git a/src/core/hle/service/filesystem/fsp/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp/fsp_srv.cpp index 2d49f30c8..fc67a4713 100644 --- a/src/core/hle/service/filesystem/fsp/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp/fsp_srv.cpp @@ -27,8 +27,11 @@ #include "core/file_sys/system_archive/system_archive.h" #include "core/file_sys/vfs/vfs.h" #include "core/hle/result.h" +#include "core/hle/service/cmif_serialization.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/filesystem/fsp/fs_i_filesystem.h" +#include "core/hle/service/filesystem/fsp/fs_i_multi_commit_manager.h" +#include "core/hle/service/filesystem/fsp/fs_i_save_data_info_reader.h" #include "core/hle/service/filesystem/fsp/fs_i_storage.h" #include "core/hle/service/filesystem/fsp/fsp_srv.h" #include "core/hle/service/filesystem/romfs_controller.h" @@ -39,182 +42,6 @@ #include "core/reporter.h" namespace Service::FileSystem { -enum class FileSystemProxyType : u8 { - Code = 0, - Rom = 1, - Logo = 2, - Control = 3, - Manual = 4, - Meta = 5, - Data = 6, - Package = 7, - RegisteredUpdate = 8, -}; - -class ISaveDataInfoReader final : public ServiceFramework<ISaveDataInfoReader> { -public: - explicit 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, &ISaveDataInfoReader::ReadSaveDataInfo, "ReadSaveDataInfo"}, - }; - RegisterHandlers(functions); - - FindAllSaves(space); - } - - void ReadSaveDataInfo(HLERequestContext& ctx) { - LOG_DEBUG(Service_FS, "called"); - - // Calculate how many entries we can fit in the output buffer - const u64 count_entries = ctx.GetWriteBufferNumElements<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, 4}; - rb.Push(ResultSuccess); - rb.Push<u64>(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) { - 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") { - 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::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()) { - // 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::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; - u16_le index; - FileSys::SaveDataRank rank; - INSERT_PADDING_BYTES(0x25); - }; - static_assert(sizeof(SaveDataInfo) == 0x60, "SaveDataInfo has incorrect size."); - - ProcessId process_id = 0; - std::shared_ptr<SaveDataController> save_data_controller; - std::vector<SaveDataInfo> info; - u64 next_entry_index = 0; -}; FSP_SRV::FSP_SRV(Core::System& system_) : ServiceFramework{system_, "fsp-srv"}, fsc{system.GetFileSystemController()}, @@ -222,20 +49,20 @@ FSP_SRV::FSP_SRV(Core::System& system_) // clang-format off static const FunctionInfo functions[] = { {0, nullptr, "OpenFileSystem"}, - {1, &FSP_SRV::SetCurrentProcess, "SetCurrentProcess"}, + {1, D<&FSP_SRV::SetCurrentProcess>, "SetCurrentProcess"}, {2, nullptr, "OpenDataFileSystemByCurrentProcess"}, - {7, &FSP_SRV::OpenFileSystemWithPatch, "OpenFileSystemWithPatch"}, + {7, D<&FSP_SRV::OpenFileSystemWithPatch>, "OpenFileSystemWithPatch"}, {8, nullptr, "OpenFileSystemWithId"}, {9, nullptr, "OpenDataFileSystemByApplicationId"}, {11, nullptr, "OpenBisFileSystem"}, {12, nullptr, "OpenBisStorage"}, {13, nullptr, "InvalidateBisCache"}, {17, nullptr, "OpenHostFileSystem"}, - {18, &FSP_SRV::OpenSdCardFileSystem, "OpenSdCardFileSystem"}, + {18, D<&FSP_SRV::OpenSdCardFileSystem>, "OpenSdCardFileSystem"}, {19, nullptr, "FormatSdCardFileSystem"}, {21, nullptr, "DeleteSaveDataFileSystem"}, - {22, &FSP_SRV::CreateSaveDataFileSystem, "CreateSaveDataFileSystem"}, - {23, &FSP_SRV::CreateSaveDataFileSystemBySystemSaveDataId, "CreateSaveDataFileSystemBySystemSaveDataId"}, + {22, D<&FSP_SRV::CreateSaveDataFileSystem>, "CreateSaveDataFileSystem"}, + {23, D<&FSP_SRV::CreateSaveDataFileSystemBySystemSaveDataId>, "CreateSaveDataFileSystemBySystemSaveDataId"}, {24, nullptr, "RegisterSaveDataFileSystemAtomicDeletion"}, {25, nullptr, "DeleteSaveDataFileSystemBySaveDataSpaceId"}, {26, nullptr, "FormatSdCardDryRun"}, @@ -245,26 +72,26 @@ FSP_SRV::FSP_SRV(Core::System& system_) {31, nullptr, "OpenGameCardFileSystem"}, {32, nullptr, "ExtendSaveDataFileSystem"}, {33, nullptr, "DeleteCacheStorage"}, - {34, &FSP_SRV::GetCacheStorageSize, "GetCacheStorageSize"}, + {34, D<&FSP_SRV::GetCacheStorageSize>, "GetCacheStorageSize"}, {35, nullptr, "CreateSaveDataFileSystemByHashSalt"}, {36, nullptr, "OpenHostFileSystemWithOption"}, - {51, &FSP_SRV::OpenSaveDataFileSystem, "OpenSaveDataFileSystem"}, - {52, &FSP_SRV::OpenSaveDataFileSystemBySystemSaveDataId, "OpenSaveDataFileSystemBySystemSaveDataId"}, - {53, &FSP_SRV::OpenReadOnlySaveDataFileSystem, "OpenReadOnlySaveDataFileSystem"}, + {51, D<&FSP_SRV::OpenSaveDataFileSystem>, "OpenSaveDataFileSystem"}, + {52, D<&FSP_SRV::OpenSaveDataFileSystemBySystemSaveDataId>, "OpenSaveDataFileSystemBySystemSaveDataId"}, + {53, D<&FSP_SRV::OpenReadOnlySaveDataFileSystem>, "OpenReadOnlySaveDataFileSystem"}, {57, nullptr, "ReadSaveDataFileSystemExtraDataBySaveDataSpaceId"}, {58, nullptr, "ReadSaveDataFileSystemExtraData"}, {59, nullptr, "WriteSaveDataFileSystemExtraData"}, {60, nullptr, "OpenSaveDataInfoReader"}, - {61, &FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId, "OpenSaveDataInfoReaderBySaveDataSpaceId"}, - {62, &FSP_SRV::OpenSaveDataInfoReaderOnlyCacheStorage, "OpenSaveDataInfoReaderOnlyCacheStorage"}, + {61, D<&FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId>, "OpenSaveDataInfoReaderBySaveDataSpaceId"}, + {62, D<&FSP_SRV::OpenSaveDataInfoReaderOnlyCacheStorage>, "OpenSaveDataInfoReaderOnlyCacheStorage"}, {64, nullptr, "OpenSaveDataInternalStorageFileSystem"}, {65, nullptr, "UpdateSaveDataMacForDebug"}, {66, nullptr, "WriteSaveDataFileSystemExtraData2"}, {67, nullptr, "FindSaveDataWithFilter"}, {68, nullptr, "OpenSaveDataInfoReaderBySaveDataFilter"}, {69, nullptr, "ReadSaveDataFileSystemExtraDataBySaveDataAttribute"}, - {70, &FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute, "WriteSaveDataFileSystemExtraDataBySaveDataAttribute"}, - {71, &FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute, "ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute"}, + {70, D<&FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute>, "WriteSaveDataFileSystemExtraDataBySaveDataAttribute"}, + {71, D<&FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute>, "ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute"}, {80, nullptr, "OpenSaveDataMetaFile"}, {81, nullptr, "OpenSaveDataTransferManager"}, {82, nullptr, "OpenSaveDataTransferManagerVersion2"}, @@ -279,12 +106,12 @@ FSP_SRV::FSP_SRV(Core::System& system_) {110, nullptr, "OpenContentStorageFileSystem"}, {120, nullptr, "OpenCloudBackupWorkStorageFileSystem"}, {130, nullptr, "OpenCustomStorageFileSystem"}, - {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"}, + {200, D<&FSP_SRV::OpenDataStorageByCurrentProcess>, "OpenDataStorageByCurrentProcess"}, {201, nullptr, "OpenDataStorageByProgramId"}, - {202, &FSP_SRV::OpenDataStorageByDataId, "OpenDataStorageByDataId"}, - {203, &FSP_SRV::OpenPatchDataStorageByCurrentProcess, "OpenPatchDataStorageByCurrentProcess"}, + {202, D<&FSP_SRV::OpenDataStorageByDataId>, "OpenDataStorageByDataId"}, + {203, D<&FSP_SRV::OpenPatchDataStorageByCurrentProcess>, "OpenPatchDataStorageByCurrentProcess"}, {204, nullptr, "OpenDataFileSystemByProgramIndex"}, - {205, &FSP_SRV::OpenDataStorageWithProgramIndex, "OpenDataStorageWithProgramIndex"}, + {205, D<&FSP_SRV::OpenDataStorageWithProgramIndex>, "OpenDataStorageWithProgramIndex"}, {206, nullptr, "OpenDataStorageByPath"}, {400, nullptr, "OpenDeviceOperator"}, {500, nullptr, "OpenSdCardDetectionEventNotifier"}, @@ -324,25 +151,25 @@ FSP_SRV::FSP_SRV(Core::System& system_) {1000, nullptr, "SetBisRootForHost"}, {1001, nullptr, "SetSaveDataSize"}, {1002, nullptr, "SetSaveDataRootPath"}, - {1003, &FSP_SRV::DisableAutoSaveDataCreation, "DisableAutoSaveDataCreation"}, - {1004, &FSP_SRV::SetGlobalAccessLogMode, "SetGlobalAccessLogMode"}, - {1005, &FSP_SRV::GetGlobalAccessLogMode, "GetGlobalAccessLogMode"}, - {1006, &FSP_SRV::OutputAccessLogToSdCard, "OutputAccessLogToSdCard"}, + {1003, D<&FSP_SRV::DisableAutoSaveDataCreation>, "DisableAutoSaveDataCreation"}, + {1004, D<&FSP_SRV::SetGlobalAccessLogMode>, "SetGlobalAccessLogMode"}, + {1005, D<&FSP_SRV::GetGlobalAccessLogMode>, "GetGlobalAccessLogMode"}, + {1006, D<&FSP_SRV::OutputAccessLogToSdCard>, "OutputAccessLogToSdCard"}, {1007, nullptr, "RegisterUpdatePartition"}, {1008, nullptr, "OpenRegisteredUpdatePartition"}, {1009, nullptr, "GetAndClearMemoryReportInfo"}, {1010, nullptr, "SetDataStorageRedirectTarget"}, - {1011, &FSP_SRV::GetProgramIndexForAccessLog, "GetProgramIndexForAccessLog"}, + {1011, D<&FSP_SRV::GetProgramIndexForAccessLog>, "GetProgramIndexForAccessLog"}, {1012, nullptr, "GetFsStackUsage"}, {1013, nullptr, "UnsetSaveDataRootPath"}, {1014, nullptr, "OutputMultiProgramTagAccessLog"}, - {1016, &FSP_SRV::FlushAccessLogOnSdCard, "FlushAccessLogOnSdCard"}, + {1016, D<&FSP_SRV::FlushAccessLogOnSdCard>, "FlushAccessLogOnSdCard"}, {1017, nullptr, "OutputApplicationInfoAccessLog"}, {1018, nullptr, "SetDebugOption"}, {1019, nullptr, "UnsetDebugOption"}, {1100, nullptr, "OverrideSaveDataTransferTokenSignVerificationKey"}, {1110, nullptr, "CorruptSaveDataFileSystemBySaveDataSpaceId2"}, - {1200, &FSP_SRV::OpenMultiCommitManager, "OpenMultiCommitManager"}, + {1200, D<&FSP_SRV::OpenMultiCommitManager>, "OpenMultiCommitManager"}, {1300, nullptr, "OpenBisWiper"}, }; // clang-format on @@ -355,234 +182,177 @@ FSP_SRV::FSP_SRV(Core::System& system_) FSP_SRV::~FSP_SRV() = default; -void FSP_SRV::SetCurrentProcess(HLERequestContext& ctx) { - current_process_id = ctx.GetPID(); +Result FSP_SRV::SetCurrentProcess(ClientProcessId pid) { + current_process_id = *pid; LOG_DEBUG(Service_FS, "called. current_process_id=0x{:016X}", current_process_id); - const auto res = - fsc.OpenProcess(&program_id, &save_data_controller, &romfs_controller, current_process_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(res); + R_RETURN( + fsc.OpenProcess(&program_id, &save_data_controller, &romfs_controller, current_process_id)); } -void FSP_SRV::OpenFileSystemWithPatch(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - struct InputParameters { - FileSystemProxyType type; - u64 program_id; - }; - static_assert(sizeof(InputParameters) == 0x10, "InputParameters has wrong size"); - - const auto params = rp.PopRaw<InputParameters>(); - LOG_ERROR(Service_FS, "(STUBBED) called with type={}, program_id={:016X}", params.type, - params.program_id); +Result FSP_SRV::OpenFileSystemWithPatch(OutInterface<IFileSystem> out_interface, + FileSystemProxyType type, u64 open_program_id) { + LOG_ERROR(Service_FS, "(STUBBED) called with type={}, program_id={:016X}", type, + open_program_id); // FIXME: many issues with this - ASSERT(params.type == FileSystemProxyType::Manual); + ASSERT(type == FileSystemProxyType::Manual); const auto manual_romfs = romfs_controller->OpenPatchedRomFS( - params.program_id, FileSys::ContentRecordType::HtmlDocument); + open_program_id, FileSys::ContentRecordType::HtmlDocument); ASSERT(manual_romfs != nullptr); const auto extracted_romfs = FileSys::ExtractRomFS(manual_romfs); ASSERT(extracted_romfs != nullptr); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IFileSystem>(system, extracted_romfs, - SizeGetter::FromStorageId(fsc, FileSys::StorageId::NandUser)); + *out_interface = std::make_shared<IFileSystem>( + system, extracted_romfs, SizeGetter::FromStorageId(fsc, FileSys::StorageId::NandUser)); + + R_SUCCEED(); } -void FSP_SRV::OpenSdCardFileSystem(HLERequestContext& ctx) { +Result FSP_SRV::OpenSdCardFileSystem(OutInterface<IFileSystem> out_interface) { LOG_DEBUG(Service_FS, "called"); FileSys::VirtualDir sdmc_dir{}; fsc.OpenSDMC(&sdmc_dir); - auto filesystem = std::make_shared<IFileSystem>( + *out_interface = std::make_shared<IFileSystem>( system, sdmc_dir, SizeGetter::FromStorageId(fsc, FileSys::StorageId::SdCard)); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IFileSystem>(std::move(filesystem)); + R_SUCCEED(); } -void FSP_SRV::CreateSaveDataFileSystem(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - auto save_struct = rp.PopRaw<FileSys::SaveDataAttribute>(); - [[maybe_unused]] auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>(); - u128 uid = rp.PopRaw<u128>(); - +Result FSP_SRV::CreateSaveDataFileSystem(FileSys::SaveDataCreationInfo save_create_struct, + FileSys::SaveDataAttribute save_struct, u128 uid) { LOG_DEBUG(Service_FS, "called save_struct = {}, uid = {:016X}{:016X}", save_struct.DebugInfo(), uid[1], uid[0]); FileSys::VirtualDir save_data_dir{}; - save_data_controller->CreateSaveData(&save_data_dir, FileSys::SaveDataSpaceId::NandUser, - save_struct); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_RETURN(save_data_controller->CreateSaveData(&save_data_dir, FileSys::SaveDataSpaceId::User, + save_struct)); } -void FSP_SRV::CreateSaveDataFileSystemBySystemSaveDataId(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - auto save_struct = rp.PopRaw<FileSys::SaveDataAttribute>(); - [[maybe_unused]] auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>(); - +Result FSP_SRV::CreateSaveDataFileSystemBySystemSaveDataId( + FileSys::SaveDataCreationInfo save_create_struct, FileSys::SaveDataAttribute save_struct) { LOG_DEBUG(Service_FS, "called save_struct = {}", save_struct.DebugInfo()); FileSys::VirtualDir save_data_dir{}; - save_data_controller->CreateSaveData(&save_data_dir, FileSys::SaveDataSpaceId::NandSystem, - save_struct); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_RETURN(save_data_controller->CreateSaveData(&save_data_dir, FileSys::SaveDataSpaceId::System, + save_struct)); } -void FSP_SRV::OpenSaveDataFileSystem(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - struct Parameters { - FileSys::SaveDataSpaceId space_id; - FileSys::SaveDataAttribute attribute; - }; - - const auto parameters = rp.PopRaw<Parameters>(); - +Result FSP_SRV::OpenSaveDataFileSystem(OutInterface<IFileSystem> out_interface, + FileSys::SaveDataSpaceId space_id, + FileSys::SaveDataAttribute attribute) { LOG_INFO(Service_FS, "called."); FileSys::VirtualDir dir{}; - auto result = - save_data_controller->OpenSaveData(&dir, parameters.space_id, parameters.attribute); - if (result != ResultSuccess) { - IPC::ResponseBuilder rb{ctx, 2, 0, 0}; - rb.Push(FileSys::ResultTargetNotFound); - return; - } + R_TRY(save_data_controller->OpenSaveData(&dir, space_id, attribute)); FileSys::StorageId id{}; - switch (parameters.space_id) { - case FileSys::SaveDataSpaceId::NandUser: + switch (space_id) { + case FileSys::SaveDataSpaceId::User: id = FileSys::StorageId::NandUser; break; - case FileSys::SaveDataSpaceId::SdCardSystem: - case FileSys::SaveDataSpaceId::SdCardUser: + case FileSys::SaveDataSpaceId::SdSystem: + case FileSys::SaveDataSpaceId::SdUser: id = FileSys::StorageId::SdCard; break; - case FileSys::SaveDataSpaceId::NandSystem: + case FileSys::SaveDataSpaceId::System: id = FileSys::StorageId::NandSystem; break; - case FileSys::SaveDataSpaceId::TemporaryStorage: + case FileSys::SaveDataSpaceId::Temporary: case FileSys::SaveDataSpaceId::ProperSystem: case FileSys::SaveDataSpaceId::SafeMode: ASSERT(false); } - auto filesystem = + *out_interface = std::make_shared<IFileSystem>(system, std::move(dir), SizeGetter::FromStorageId(fsc, id)); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IFileSystem>(std::move(filesystem)); + R_SUCCEED(); } -void FSP_SRV::OpenSaveDataFileSystemBySystemSaveDataId(HLERequestContext& ctx) { +Result FSP_SRV::OpenSaveDataFileSystemBySystemSaveDataId(OutInterface<IFileSystem> out_interface, + FileSys::SaveDataSpaceId space_id, + FileSys::SaveDataAttribute attribute) { LOG_WARNING(Service_FS, "(STUBBED) called, delegating to 51 OpenSaveDataFilesystem"); - OpenSaveDataFileSystem(ctx); + R_RETURN(OpenSaveDataFileSystem(out_interface, space_id, attribute)); } -void FSP_SRV::OpenReadOnlySaveDataFileSystem(HLERequestContext& ctx) { +Result FSP_SRV::OpenReadOnlySaveDataFileSystem(OutInterface<IFileSystem> out_interface, + FileSys::SaveDataSpaceId space_id, + FileSys::SaveDataAttribute attribute) { LOG_WARNING(Service_FS, "(STUBBED) called, delegating to 51 OpenSaveDataFilesystem"); - OpenSaveDataFileSystem(ctx); + R_RETURN(OpenSaveDataFileSystem(out_interface, space_id, attribute)); } -void FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto space = rp.PopRaw<FileSys::SaveDataSpaceId>(); +Result FSP_SRV::OpenSaveDataInfoReaderBySaveDataSpaceId( + OutInterface<ISaveDataInfoReader> out_interface, FileSys::SaveDataSpaceId space) { LOG_INFO(Service_FS, "called, space={}", space); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<ISaveDataInfoReader>( - std::make_shared<ISaveDataInfoReader>(system, save_data_controller, space)); + *out_interface = std::make_shared<ISaveDataInfoReader>(system, save_data_controller, space); + + R_SUCCEED(); } -void FSP_SRV::OpenSaveDataInfoReaderOnlyCacheStorage(HLERequestContext& ctx) { +Result FSP_SRV::OpenSaveDataInfoReaderOnlyCacheStorage( + OutInterface<ISaveDataInfoReader> out_interface) { LOG_WARNING(Service_FS, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<ISaveDataInfoReader>(system, save_data_controller, - FileSys::SaveDataSpaceId::TemporaryStorage); + *out_interface = std::make_shared<ISaveDataInfoReader>(system, save_data_controller, + FileSys::SaveDataSpaceId::Temporary); + + R_SUCCEED(); } -void FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute(HLERequestContext& ctx) { +Result FSP_SRV::WriteSaveDataFileSystemExtraDataBySaveDataAttribute() { LOG_WARNING(Service_FS, "(STUBBED) called."); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - struct Parameters { - FileSys::SaveDataSpaceId space_id; - FileSys::SaveDataAttribute attribute; - }; - - const auto parameters = rp.PopRaw<Parameters>(); +Result FSP_SRV::ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute( + FileSys::SaveDataSpaceId space_id, FileSys::SaveDataAttribute attribute, + InBuffer<BufferAttr_HipcMapAlias> mask_buffer, OutBuffer<BufferAttr_HipcMapAlias> out_buffer) { // Stub this to None for now, backend needs an impl to read/write the SaveDataExtraData - constexpr auto flags = static_cast<u32>(FileSys::SaveDataFlags::None); + // In an earlier version of the code, this was returned as an out argument, but this is not + // correct + [[maybe_unused]] constexpr auto flags = static_cast<u32>(FileSys::SaveDataFlags::None); LOG_WARNING(Service_FS, - "(STUBBED) called, flags={}, space_id={}, attribute.title_id={:016X}\n" + "(STUBBED) called, flags={}, space_id={}, attribute.program_id={:016X}\n" "attribute.user_id={:016X}{:016X}, attribute.save_id={:016X}\n" "attribute.type={}, attribute.rank={}, attribute.index={}", - flags, parameters.space_id, parameters.attribute.title_id, - parameters.attribute.user_id[1], parameters.attribute.user_id[0], - parameters.attribute.save_id, parameters.attribute.type, parameters.attribute.rank, - parameters.attribute.index); - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(flags); + flags, space_id, attribute.program_id, attribute.user_id[1], attribute.user_id[0], + attribute.system_save_data_id, attribute.type, attribute.rank, attribute.index); + + R_SUCCEED(); } -void FSP_SRV::OpenDataStorageByCurrentProcess(HLERequestContext& ctx) { +Result FSP_SRV::OpenDataStorageByCurrentProcess(OutInterface<IStorage> out_interface) { LOG_DEBUG(Service_FS, "called"); if (!romfs) { auto current_romfs = romfs_controller->OpenRomFSCurrentProcess(); if (!current_romfs) { // TODO (bunnei): Find the right error code to use here - LOG_CRITICAL(Service_FS, "no file system interface available!"); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultUnknown); - return; + LOG_CRITICAL(Service_FS, "No file system interface available!"); + R_RETURN(ResultUnknown); } romfs = current_romfs; } - auto storage = std::make_shared<IStorage>(system, romfs); + *out_interface = std::make_shared<IStorage>(system, romfs); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IStorage>(std::move(storage)); + R_SUCCEED(); } -void FSP_SRV::OpenDataStorageByDataId(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto storage_id = rp.PopRaw<FileSys::StorageId>(); - const auto unknown = rp.PopRaw<u32>(); - const auto title_id = rp.PopRaw<u64>(); - +Result FSP_SRV::OpenDataStorageByDataId(OutInterface<IStorage> out_interface, + FileSys::StorageId storage_id, u32 unknown, u64 title_id) { LOG_DEBUG(Service_FS, "called with storage_id={:02X}, unknown={:08X}, title_id={:016X}", storage_id, unknown, title_id); @@ -592,19 +362,15 @@ void FSP_SRV::OpenDataStorageByDataId(HLERequestContext& ctx) { const auto archive = FileSys::SystemArchive::SynthesizeSystemArchive(title_id); if (archive != nullptr) { - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface(std::make_shared<IStorage>(system, archive)); - return; + *out_interface = std::make_shared<IStorage>(system, archive); + R_SUCCEED(); } // TODO(DarkLordZach): Find the right error code to use here LOG_ERROR(Service_FS, - "could not open data storage with title_id={:016X}, storage_id={:02X}", title_id, + "Could not open data storage with title_id={:016X}, storage_id={:02X}", title_id, storage_id); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultUnknown); - return; + R_RETURN(ResultUnknown); } const FileSys::PatchManager pm{title_id, fsc, content_provider}; @@ -614,28 +380,20 @@ void FSP_SRV::OpenDataStorageByDataId(HLERequestContext& ctx) { auto storage = std::make_shared<IStorage>( system, pm.PatchRomFS(base.get(), std::move(data), FileSys::ContentRecordType::Data)); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IStorage>(std::move(storage)); + *out_interface = std::move(storage); + R_SUCCEED(); } -void FSP_SRV::OpenPatchDataStorageByCurrentProcess(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - const auto storage_id = rp.PopRaw<FileSys::StorageId>(); - const auto title_id = rp.PopRaw<u64>(); +Result FSP_SRV::OpenPatchDataStorageByCurrentProcess(OutInterface<IStorage> out_interface, + FileSys::StorageId storage_id, u64 title_id) { + LOG_WARNING(Service_FS, "(STUBBED) called with storage_id={:02X}, title_id={:016X}", storage_id, + title_id); - LOG_DEBUG(Service_FS, "called with storage_id={:02X}, title_id={:016X}", storage_id, title_id); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(FileSys::ResultTargetNotFound); + R_RETURN(FileSys::ResultTargetNotFound); } -void FSP_SRV::OpenDataStorageWithProgramIndex(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - - const auto program_index = rp.PopRaw<u8>(); - +Result FSP_SRV::OpenDataStorageWithProgramIndex(OutInterface<IStorage> out_interface, + u8 program_index) { LOG_DEBUG(Service_FS, "called, program_index={}", program_index); auto patched_romfs = romfs_controller->OpenPatchedRomFSWithProgramIndex( @@ -643,123 +401,80 @@ void FSP_SRV::OpenDataStorageWithProgramIndex(HLERequestContext& ctx) { if (!patched_romfs) { // TODO: Find the right error code to use here - LOG_ERROR(Service_FS, "could not open storage with program_index={}", program_index); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultUnknown); - return; + LOG_ERROR(Service_FS, "Could not open storage with program_index={}", program_index); + R_RETURN(ResultUnknown); } - auto storage = std::make_shared<IStorage>(system, std::move(patched_romfs)); + *out_interface = std::make_shared<IStorage>(system, std::move(patched_romfs)); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IStorage>(std::move(storage)); + R_SUCCEED(); } -void FSP_SRV::DisableAutoSaveDataCreation(HLERequestContext& ctx) { +Result FSP_SRV::DisableAutoSaveDataCreation() { LOG_DEBUG(Service_FS, "called"); save_data_controller->SetAutoCreate(false); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void FSP_SRV::SetGlobalAccessLogMode(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - access_log_mode = rp.PopEnum<AccessLogMode>(); +Result FSP_SRV::SetGlobalAccessLogMode(AccessLogMode access_log_mode_) { + LOG_DEBUG(Service_FS, "called, access_log_mode={}", access_log_mode_); - LOG_DEBUG(Service_FS, "called, access_log_mode={}", access_log_mode); + access_log_mode = access_log_mode_; - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void FSP_SRV::GetGlobalAccessLogMode(HLERequestContext& ctx) { +Result FSP_SRV::GetGlobalAccessLogMode(Out<AccessLogMode> out_access_log_mode) { LOG_DEBUG(Service_FS, "called"); - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.PushEnum(access_log_mode); -} + *out_access_log_mode = access_log_mode; -void FSP_SRV::OutputAccessLogToSdCard(HLERequestContext& ctx) { - const auto raw = ctx.ReadBufferCopy(); - auto log = Common::StringFromFixedZeroTerminatedBuffer( - reinterpret_cast<const char*>(raw.data()), raw.size()); + R_SUCCEED(); +} +Result FSP_SRV::OutputAccessLogToSdCard(InBuffer<BufferAttr_HipcMapAlias> log_message_buffer) { LOG_DEBUG(Service_FS, "called"); + auto log = Common::StringFromFixedZeroTerminatedBuffer( + reinterpret_cast<const char*>(log_message_buffer.data()), log_message_buffer.size()); reporter.SaveFSAccessLog(log); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void FSP_SRV::GetProgramIndexForAccessLog(HLERequestContext& ctx) { - LOG_DEBUG(Service_FS, "called"); +Result FSP_SRV::GetProgramIndexForAccessLog(Out<AccessLogVersion> out_access_log_version, + Out<u32> out_access_log_program_index) { + LOG_DEBUG(Service_FS, "(STUBBED) called"); + + *out_access_log_version = AccessLogVersion::Latest; + *out_access_log_program_index = access_log_program_index; - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.PushEnum(AccessLogVersion::Latest); - rb.Push(access_log_program_index); + R_SUCCEED(); } -void FSP_SRV::FlushAccessLogOnSdCard(HLERequestContext& ctx) { +Result FSP_SRV::FlushAccessLogOnSdCard() { LOG_DEBUG(Service_FS, "(STUBBED) called"); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + R_SUCCEED(); } -void FSP_SRV::GetCacheStorageSize(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto index{rp.Pop<s32>()}; - +Result FSP_SRV::GetCacheStorageSize(s32 index, Out<s64> out_data_size, Out<s64> out_journal_size) { LOG_WARNING(Service_FS, "(STUBBED) called with index={}", index); - IPC::ResponseBuilder rb{ctx, 6}; - rb.Push(ResultSuccess); - rb.Push(s64{0}); - rb.Push(s64{0}); -} - -class IMultiCommitManager final : public ServiceFramework<IMultiCommitManager> { -public: - explicit IMultiCommitManager(Core::System& system_) - : ServiceFramework{system_, "IMultiCommitManager"} { - static const FunctionInfo functions[] = { - {1, &IMultiCommitManager::Add, "Add"}, - {2, &IMultiCommitManager::Commit, "Commit"}, - }; - RegisterHandlers(functions); - } + *out_data_size = 0; + *out_journal_size = 0; -private: - FileSys::VirtualFile backend; - - void Add(HLERequestContext& ctx) { - LOG_WARNING(Service_FS, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); - } - - void Commit(HLERequestContext& ctx) { - LOG_WARNING(Service_FS, "(STUBBED) called"); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); - } -}; + R_SUCCEED(); +} -void FSP_SRV::OpenMultiCommitManager(HLERequestContext& ctx) { +Result FSP_SRV::OpenMultiCommitManager(OutInterface<IMultiCommitManager> out_interface) { LOG_DEBUG(Service_FS, "called"); - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IMultiCommitManager>(std::make_shared<IMultiCommitManager>(system)); + *out_interface = std::make_shared<IMultiCommitManager>(system); + + R_SUCCEED(); } } // namespace Service::FileSystem diff --git a/src/core/hle/service/filesystem/fsp/fsp_srv.h b/src/core/hle/service/filesystem/fsp/fsp_srv.h index 59406e6f9..ee67f6bc1 100644 --- a/src/core/hle/service/filesystem/fsp/fsp_srv.h +++ b/src/core/hle/service/filesystem/fsp/fsp_srv.h @@ -4,6 +4,9 @@ #pragma once #include <memory> +#include "core/file_sys/fs_save_data_types.h" +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/filesystem/fsp/fsp_types.h" #include "core/hle/service/service.h" namespace Core { @@ -20,6 +23,11 @@ namespace Service::FileSystem { class RomFsController; class SaveDataController; +class IFileSystem; +class ISaveDataInfoReader; +class IStorage; +class IMultiCommitManager; + enum class AccessLogVersion : u32 { V7_0_0 = 2, @@ -38,30 +46,46 @@ public: ~FSP_SRV() override; private: - void SetCurrentProcess(HLERequestContext& ctx); - void OpenFileSystemWithPatch(HLERequestContext& ctx); - void OpenSdCardFileSystem(HLERequestContext& ctx); - void CreateSaveDataFileSystem(HLERequestContext& ctx); - void CreateSaveDataFileSystemBySystemSaveDataId(HLERequestContext& ctx); - void OpenSaveDataFileSystem(HLERequestContext& ctx); - void OpenSaveDataFileSystemBySystemSaveDataId(HLERequestContext& ctx); - void OpenReadOnlySaveDataFileSystem(HLERequestContext& ctx); - void OpenSaveDataInfoReaderBySaveDataSpaceId(HLERequestContext& ctx); - void OpenSaveDataInfoReaderOnlyCacheStorage(HLERequestContext& ctx); - void WriteSaveDataFileSystemExtraDataBySaveDataAttribute(HLERequestContext& ctx); - void ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute(HLERequestContext& ctx); - void OpenDataStorageByCurrentProcess(HLERequestContext& ctx); - void OpenDataStorageByDataId(HLERequestContext& ctx); - void OpenPatchDataStorageByCurrentProcess(HLERequestContext& ctx); - void OpenDataStorageWithProgramIndex(HLERequestContext& ctx); - void DisableAutoSaveDataCreation(HLERequestContext& ctx); - void SetGlobalAccessLogMode(HLERequestContext& ctx); - void GetGlobalAccessLogMode(HLERequestContext& ctx); - void OutputAccessLogToSdCard(HLERequestContext& ctx); - void FlushAccessLogOnSdCard(HLERequestContext& ctx); - void GetProgramIndexForAccessLog(HLERequestContext& ctx); - void OpenMultiCommitManager(HLERequestContext& ctx); - void GetCacheStorageSize(HLERequestContext& ctx); + Result SetCurrentProcess(ClientProcessId pid); + Result OpenFileSystemWithPatch(OutInterface<IFileSystem> out_interface, + FileSystemProxyType type, u64 open_program_id); + Result OpenSdCardFileSystem(OutInterface<IFileSystem> out_interface); + Result CreateSaveDataFileSystem(FileSys::SaveDataCreationInfo save_create_struct, + FileSys::SaveDataAttribute save_struct, u128 uid); + Result CreateSaveDataFileSystemBySystemSaveDataId( + FileSys::SaveDataCreationInfo save_create_struct, FileSys::SaveDataAttribute save_struct); + Result OpenSaveDataFileSystem(OutInterface<IFileSystem> out_interface, + FileSys::SaveDataSpaceId space_id, + FileSys::SaveDataAttribute attribute); + Result OpenSaveDataFileSystemBySystemSaveDataId(OutInterface<IFileSystem> out_interface, + FileSys::SaveDataSpaceId space_id, + FileSys::SaveDataAttribute attribute); + Result OpenReadOnlySaveDataFileSystem(OutInterface<IFileSystem> out_interface, + FileSys::SaveDataSpaceId space_id, + FileSys::SaveDataAttribute attribute); + Result OpenSaveDataInfoReaderBySaveDataSpaceId(OutInterface<ISaveDataInfoReader> out_interface, + FileSys::SaveDataSpaceId space); + Result OpenSaveDataInfoReaderOnlyCacheStorage(OutInterface<ISaveDataInfoReader> out_interface); + Result WriteSaveDataFileSystemExtraDataBySaveDataAttribute(); + Result ReadSaveDataFileSystemExtraDataWithMaskBySaveDataAttribute( + FileSys::SaveDataSpaceId space_id, FileSys::SaveDataAttribute attribute, + InBuffer<BufferAttr_HipcMapAlias> mask_buffer, + OutBuffer<BufferAttr_HipcMapAlias> out_buffer); + Result OpenDataStorageByCurrentProcess(OutInterface<IStorage> out_interface); + Result OpenDataStorageByDataId(OutInterface<IStorage> out_interface, + FileSys::StorageId storage_id, u32 unknown, u64 title_id); + Result OpenPatchDataStorageByCurrentProcess(OutInterface<IStorage> out_interface, + FileSys::StorageId storage_id, u64 title_id); + Result OpenDataStorageWithProgramIndex(OutInterface<IStorage> out_interface, u8 program_index); + Result DisableAutoSaveDataCreation(); + Result SetGlobalAccessLogMode(AccessLogMode access_log_mode_); + Result GetGlobalAccessLogMode(Out<AccessLogMode> out_access_log_mode); + Result OutputAccessLogToSdCard(InBuffer<BufferAttr_HipcMapAlias> log_message_buffer); + Result FlushAccessLogOnSdCard(); + Result GetProgramIndexForAccessLog(Out<AccessLogVersion> out_access_log_version, + Out<u32> out_access_log_program_index); + Result OpenMultiCommitManager(OutInterface<IMultiCommitManager> out_interface); + Result GetCacheStorageSize(s32 index, Out<s64> out_data_size, Out<s64> out_journal_size); FileSystemController& fsc; const FileSys::ContentProvider& content_provider; diff --git a/src/core/hle/service/filesystem/fsp/fsp_util.h b/src/core/hle/service/filesystem/fsp/fsp_types.h index 253f866db..294da6a2d 100644 --- a/src/core/hle/service/filesystem/fsp/fsp_util.h +++ b/src/core/hle/service/filesystem/fsp/fsp_types.h @@ -7,6 +7,18 @@ namespace Service::FileSystem { +enum class FileSystemProxyType : u8 { + Code = 0, + Rom = 1, + Logo = 2, + Control = 3, + Manual = 4, + Meta = 5, + Data = 6, + Package = 7, + RegisteredUpdate = 8, +}; + struct SizeGetter { std::function<u64()> get_free_size; std::function<u64()> get_total_size; diff --git a/src/core/hle/service/psc/ovln/ovln_types.h b/src/core/hle/service/psc/ovln/ovln_types.h new file mode 100644 index 000000000..343b05dcc --- /dev/null +++ b/src/core/hle/service/psc/ovln/ovln_types.h @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "common/bit_field.h" +#include "common/common_types.h" + +namespace Service::PSC { + +using OverlayNotification = std::array<u64, 0x10>; +static_assert(sizeof(OverlayNotification) == 0x80, "OverlayNotification has incorrect size"); + +union MessageFlags { + u64 raw; + BitField<0, 8, u64> message_type; + BitField<8, 8, u64> queue_type; +}; +static_assert(sizeof(MessageFlags) == 0x8, "MessageFlags has incorrect size"); + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/ovln/receiver.cpp b/src/core/hle/service/psc/ovln/receiver.cpp new file mode 100644 index 000000000..85f62816d --- /dev/null +++ b/src/core/hle/service/psc/ovln/receiver.cpp @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/psc/ovln/receiver.h" + +namespace Service::PSC { + +IReceiver::IReceiver(Core::System& system_) : ServiceFramework{system_, "IReceiver"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, nullptr, "AddSource"}, + {1, nullptr, "RemoveSource"}, + {2, nullptr, "GetReceiveEventHandle"}, + {3, nullptr, "Receive"}, + {4, nullptr, "ReceiveWithTick"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IReceiver::~IReceiver() = default; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/ovln/receiver.h b/src/core/hle/service/psc/ovln/receiver.h new file mode 100644 index 000000000..c47a4ff7e --- /dev/null +++ b/src/core/hle/service/psc/ovln/receiver.h @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/service.h" + +namespace Service::PSC { + +class IReceiver final : public ServiceFramework<IReceiver> { +public: + explicit IReceiver(Core::System& system_); + ~IReceiver() override; +}; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/ovln/receiver_service.cpp b/src/core/hle/service/psc/ovln/receiver_service.cpp new file mode 100644 index 000000000..bb988e905 --- /dev/null +++ b/src/core/hle/service/psc/ovln/receiver_service.cpp @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/psc/ovln/receiver.h" +#include "core/hle/service/psc/ovln/receiver_service.h" + +namespace Service::PSC { + +IReceiverService::IReceiverService(Core::System& system_) : ServiceFramework{system_, "ovln:rcv"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, D<&IReceiverService::OpenReceiver>, "OpenReceiver"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IReceiverService::~IReceiverService() = default; + +Result IReceiverService::OpenReceiver(Out<SharedPointer<IReceiver>> out_receiver) { + LOG_DEBUG(Service_PSC, "called"); + *out_receiver = std::make_shared<IReceiver>(system); + R_SUCCEED(); +} + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/ovln/receiver_service.h b/src/core/hle/service/psc/ovln/receiver_service.h new file mode 100644 index 000000000..b3b31ba4a --- /dev/null +++ b/src/core/hle/service/psc/ovln/receiver_service.h @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" + +namespace Service::PSC { + +class IReceiver; + +class IReceiverService final : public ServiceFramework<IReceiverService> { +public: + explicit IReceiverService(Core::System& system_); + ~IReceiverService() override; + +private: + Result OpenReceiver(Out<SharedPointer<IReceiver>> out_receiver); +}; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/ovln/sender.cpp b/src/core/hle/service/psc/ovln/sender.cpp new file mode 100644 index 000000000..3227a56f2 --- /dev/null +++ b/src/core/hle/service/psc/ovln/sender.cpp @@ -0,0 +1,32 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/psc/ovln/sender.h" + +namespace Service::PSC { + +ISender::ISender(Core::System& system_) : ServiceFramework{system_, "ISender"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, D<&ISender::Send>, "Send"}, + {1, nullptr, "GetUnreceivedMessageCount"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +ISender::~ISender() = default; + +Result ISender::Send(const OverlayNotification& notification, MessageFlags flags) { + std::string data; + for (const auto m : notification) { + data += fmt::format("{:016X} ", m); + } + + LOG_WARNING(Service_PSC, "(STUBBED) called, flags={} notification={}", flags.raw, data); + R_SUCCEED(); +} + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/ovln/sender.h b/src/core/hle/service/psc/ovln/sender.h new file mode 100644 index 000000000..c1575428e --- /dev/null +++ b/src/core/hle/service/psc/ovln/sender.h @@ -0,0 +1,21 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/psc/ovln/ovln_types.h" +#include "core/hle/service/service.h" + +namespace Service::PSC { + +class ISender final : public ServiceFramework<ISender> { +public: + explicit ISender(Core::System& system_); + ~ISender() override; + +private: + Result Send(const OverlayNotification& notification, MessageFlags flags); +}; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/ovln/sender_service.cpp b/src/core/hle/service/psc/ovln/sender_service.cpp new file mode 100644 index 000000000..18d2c83a3 --- /dev/null +++ b/src/core/hle/service/psc/ovln/sender_service.cpp @@ -0,0 +1,30 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/psc/ovln/sender.h" +#include "core/hle/service/psc/ovln/sender_service.h" + +namespace Service::PSC { + +ISenderService::ISenderService(Core::System& system_) : ServiceFramework{system_, "ovln:snd"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, D<&ISenderService::OpenSender>, "OpenSender"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +ISenderService::~ISenderService() = default; + +Result ISenderService::OpenSender(Out<SharedPointer<ISender>> out_sender, u32 sender_id, + std::array<u64, 2> data) { + LOG_WARNING(Service_PSC, "(STUBBED) called, sender_id={}, data={:016X} {:016X}", sender_id, + data[0], data[1]); + *out_sender = std::make_shared<ISender>(system); + R_SUCCEED(); +} + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/ovln/sender_service.h b/src/core/hle/service/psc/ovln/sender_service.h new file mode 100644 index 000000000..10027701f --- /dev/null +++ b/src/core/hle/service/psc/ovln/sender_service.h @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" + +namespace Service::PSC { + +class ISender; + +class ISenderService final : public ServiceFramework<ISenderService> { +public: + explicit ISenderService(Core::System& system_); + ~ISenderService() override; + +private: + Result OpenSender(Out<SharedPointer<ISender>> out_sender, u32 sender_id, + std::array<u64, 2> data); +}; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/pm_control.cpp b/src/core/hle/service/psc/pm_control.cpp new file mode 100644 index 000000000..7dedb7662 --- /dev/null +++ b/src/core/hle/service/psc/pm_control.cpp @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/psc/pm_control.h" + +namespace Service::PSC { + +IPmControl::IPmControl(Core::System& system_) : ServiceFramework{system_, "psc:c"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, nullptr, "Initialize"}, + {1, nullptr, "DispatchRequest"}, + {2, nullptr, "GetResult"}, + {3, nullptr, "GetState"}, + {4, nullptr, "Cancel"}, + {5, nullptr, "PrintModuleInformation"}, + {6, nullptr, "GetModuleInformation"}, + {10, nullptr, "AcquireStateLock"}, + {11, nullptr, "HasStateLock"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IPmControl::~IPmControl() = default; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/pm_control.h b/src/core/hle/service/psc/pm_control.h new file mode 100644 index 000000000..e0ae2f39c --- /dev/null +++ b/src/core/hle/service/psc/pm_control.h @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/service.h" + +namespace Service::PSC { + +class IPmControl final : public ServiceFramework<IPmControl> { +public: + explicit IPmControl(Core::System& system_); + ~IPmControl() override; +}; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/pm_module.cpp b/src/core/hle/service/psc/pm_module.cpp new file mode 100644 index 000000000..74dc7ed4e --- /dev/null +++ b/src/core/hle/service/psc/pm_module.cpp @@ -0,0 +1,24 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/psc/pm_module.h" + +namespace Service::PSC { + +IPmModule::IPmModule(Core::System& system_) : ServiceFramework{system_, "IPmModule"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, nullptr, "Initialize"}, + {1, nullptr, "GetRequest"}, + {2, nullptr, "Acknowledge"}, + {3, nullptr, "Finalize"}, + {4, nullptr, "AcknowledgeEx"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IPmModule::~IPmModule() = default; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/pm_module.h b/src/core/hle/service/psc/pm_module.h new file mode 100644 index 000000000..b3a2d2584 --- /dev/null +++ b/src/core/hle/service/psc/pm_module.h @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/service.h" + +namespace Service::PSC { + +class IPmModule final : public ServiceFramework<IPmModule> { +public: + explicit IPmModule(Core::System& system_); + ~IPmModule() override; +}; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/pm_service.cpp b/src/core/hle/service/psc/pm_service.cpp new file mode 100644 index 000000000..c4e0ad228 --- /dev/null +++ b/src/core/hle/service/psc/pm_service.cpp @@ -0,0 +1,28 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "core/hle/service/cmif_serialization.h" +#include "core/hle/service/psc/pm_module.h" +#include "core/hle/service/psc/pm_service.h" + +namespace Service::PSC { + +IPmService::IPmService(Core::System& system_) : ServiceFramework{system_, "psc:m"} { + // clang-format off + static const FunctionInfo functions[] = { + {0, D<&IPmService::GetPmModule>, "GetPmModule"}, + }; + // clang-format on + + RegisterHandlers(functions); +} + +IPmService::~IPmService() = default; + +Result IPmService::GetPmModule(Out<SharedPointer<IPmModule>> out_module) { + LOG_DEBUG(Service_PSC, "called"); + *out_module = std::make_shared<IPmModule>(system); + R_SUCCEED(); +} + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/pm_service.h b/src/core/hle/service/psc/pm_service.h new file mode 100644 index 000000000..08e14c6f8 --- /dev/null +++ b/src/core/hle/service/psc/pm_service.h @@ -0,0 +1,22 @@ +// SPDX-FileCopyrightText: Copyright 2024 yuzu Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "core/hle/service/cmif_types.h" +#include "core/hle/service/service.h" + +namespace Service::PSC { + +class IPmModule; + +class IPmService final : public ServiceFramework<IPmService> { +public: + explicit IPmService(Core::System& system_); + ~IPmService() override; + +private: + Result GetPmModule(Out<SharedPointer<IPmModule>> out_module); +}; + +} // namespace Service::PSC diff --git a/src/core/hle/service/psc/psc.cpp b/src/core/hle/service/psc/psc.cpp index 44310756b..e1762d694 100644 --- a/src/core/hle/service/psc/psc.cpp +++ b/src/core/hle/service/psc/psc.cpp @@ -1,11 +1,10 @@ // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project // SPDX-License-Identifier: GPL-2.0-or-later -#include <memory> - -#include "common/logging/log.h" -#include "core/core.h" -#include "core/hle/service/ipc_helpers.h" +#include "core/hle/service/psc/ovln/receiver_service.h" +#include "core/hle/service/psc/ovln/sender_service.h" +#include "core/hle/service/psc/pm_control.h" +#include "core/hle/service/psc/pm_service.h" #include "core/hle/service/psc/psc.h" #include "core/hle/service/psc/time/manager.h" #include "core/hle/service/psc/time/power_state_service.h" @@ -15,71 +14,13 @@ namespace Service::PSC { -class IPmControl final : public ServiceFramework<IPmControl> { -public: - explicit IPmControl(Core::System& system_) : ServiceFramework{system_, "psc:c"} { - // clang-format off - static const FunctionInfo functions[] = { - {0, nullptr, "Initialize"}, - {1, nullptr, "DispatchRequest"}, - {2, nullptr, "GetResult"}, - {3, nullptr, "GetState"}, - {4, nullptr, "Cancel"}, - {5, nullptr, "PrintModuleInformation"}, - {6, nullptr, "GetModuleInformation"}, - {10, nullptr, "AcquireStateLock"}, - {11, nullptr, "HasStateLock"}, - }; - // clang-format on - - RegisterHandlers(functions); - } -}; - -class IPmModule final : public ServiceFramework<IPmModule> { -public: - explicit IPmModule(Core::System& system_) : ServiceFramework{system_, "IPmModule"} { - // clang-format off - static const FunctionInfo functions[] = { - {0, nullptr, "Initialize"}, - {1, nullptr, "GetRequest"}, - {2, nullptr, "Acknowledge"}, - {3, nullptr, "Finalize"}, - {4, nullptr, "AcknowledgeEx"}, - }; - // clang-format on - - RegisterHandlers(functions); - } -}; - -class IPmService final : public ServiceFramework<IPmService> { -public: - explicit IPmService(Core::System& system_) : ServiceFramework{system_, "psc:m"} { - // clang-format off - static const FunctionInfo functions[] = { - {0, &IPmService::GetPmModule, "GetPmModule"}, - }; - // clang-format on - - RegisterHandlers(functions); - } - -private: - void GetPmModule(HLERequestContext& ctx) { - LOG_DEBUG(Service_PSC, "called"); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface<IPmModule>(system); - } -}; - void LoopProcess(Core::System& system) { auto server_manager = std::make_unique<ServerManager>(system); server_manager->RegisterNamedService("psc:c", std::make_shared<IPmControl>(system)); server_manager->RegisterNamedService("psc:m", std::make_shared<IPmService>(system)); + server_manager->RegisterNamedService("ovln:rcv", std::make_shared<IReceiverService>(system)); + server_manager->RegisterNamedService("ovln:snd", std::make_shared<ISenderService>(system)); auto time = std::make_shared<Time::TimeManager>(system); diff --git a/src/core/hle/service/psc/psc.h b/src/core/hle/service/psc/psc.h index 459137f42..c83d07ca8 100644 --- a/src/core/hle/service/psc/psc.h +++ b/src/core/hle/service/psc/psc.h @@ -7,10 +7,6 @@ namespace Core { class System; } -namespace Service::SM { -class ServiceManager; -} - namespace Service::PSC { void LoopProcess(Core::System& system); |