From d5e4617ab5c8b7e72e2155de886135766ce61c7a Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sat, 10 Feb 2024 18:15:58 +0100 Subject: fs: Add FileSystemAccessor classes --- .../hle/service/filesystem/fsp/fs_i_directory.cpp | 58 ++++------------- .../hle/service/filesystem/fsp/fs_i_directory.h | 7 +- src/core/hle/service/filesystem/fsp/fs_i_file.cpp | 74 +++++----------------- src/core/hle/service/filesystem/fsp/fs_i_file.h | 5 +- .../hle/service/filesystem/fsp/fs_i_filesystem.cpp | 41 ++++++++---- .../hle/service/filesystem/fsp/fs_i_filesystem.h | 5 +- 6 files changed, 65 insertions(+), 125 deletions(-) (limited to 'src/core/hle/service/filesystem') 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..661da5326 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_directory.cpp @@ -8,43 +8,15 @@ namespace Service::FileSystem { -template -static void BuildEntryIndex(std::vector& entries, - const std::vector& 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(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(directory_, mode)) { static const FunctionInfo functions[] = { {0, &IDirectory::Read, "Read"}, {1, &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) { @@ -53,32 +25,26 @@ void IDirectory::Read(HLERequestContext& ctx) { // Calculate how many entries we can fit in the output buffer const u64 count_entries = ctx.GetWriteBufferNumElements(); - // 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(entries.data() + next_entry_index); - const auto* end = reinterpret_cast(entries.data() + next_entry_index + actual_entries); - const auto range_size = static_cast(std::distance(begin, end)); - - next_entry_index += actual_entries; + s64 out_count{}; + FileSys::DirectoryEntry* out_entries = nullptr; + const auto result = backend->Read(&out_count, out_entries, count_entries); // Write the data to memory - ctx.WriteBuffer(begin, range_size); + ctx.WriteBuffer(out_entries, out_count); IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(actual_entries); + rb.Push(result); + rb.Push(out_count); } void IDirectory::GetEntryCount(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); - u64 count = entries.size() - next_entry_index; + s64 out_count{}; IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(count); + rb.Push(backend->GetEntryCount(&out_count)); + rb.Push(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..0dec4367b 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_directory.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_directory.h @@ -3,6 +3,7 @@ #pragma once +#include "core/file_sys/fsa/fs_i_directory.h" #include "core/file_sys/vfs/vfs.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/service.h" @@ -15,13 +16,11 @@ namespace Service::FileSystem { class IDirectory final : public ServiceFramework { 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 entries; - u64 next_entry_index = 0; + std::unique_ptr backend; void Read(HLERequestContext& ctx); void GetEntryCount(HLERequestContext& ctx); 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..8fb8620de 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_file.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_file.cpp @@ -7,8 +7,8 @@ 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(file_)} { static const FunctionInfo functions[] = { {0, &IFile::Read, "Read"}, {1, &IFile::Write, "Write"}, @@ -29,79 +29,40 @@ void IFile::Read(HLERequestContext& ctx) { 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; - } - // Read the data from the Storage backend - std::vector output = backend->ReadBytes(length, offset); + std::vector output(length); + std::size_t bytes_read; + const auto result = backend->Read(&bytes_read, offset, output.data(), length); // Write the data to memory ctx.WriteBuffer(output); IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); - rb.Push(static_cast(output.size())); + rb.Push(result); + rb.Push(static_cast(bytes_read)); } void IFile::Write(HLERequestContext& ctx) { IPC::RequestParser rp{ctx}; - const u64 option = rp.Pop(); + const auto option = rp.PopRaw(); + [[maybe_unused]] const u32 unused = rp.Pop(); const s64 offset = rp.Pop(); const s64 length = rp.Pop(); - 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; - } + LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset, + length); const auto data = ctx.ReadBuffer(); - ASSERT_MSG(static_cast(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::distance(data.begin(), data.begin() + length)); - const std::size_t written = backend->Write(data.data(), write_size, offset); - - ASSERT_MSG(static_cast(written) == length, - "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length, - written); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(backend->Write(offset, data.data(), length, option)); } void IFile::Flush(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); - // Exists for SDK compatibiltity -- No need to flush file. - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(backend->Flush()); } void IFile::SetSize(HLERequestContext& ctx) { @@ -109,18 +70,17 @@ void IFile::SetSize(HLERequestContext& ctx) { const u64 size = rp.Pop(); LOG_DEBUG(Service_FS, "called, size={}", size); - backend->Resize(size); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(ResultSuccess); + rb.Push(backend->SetSize(size)); } void IFile::GetSize(HLERequestContext& ctx) { - const u64 size = backend->GetSize(); + s64 size; + const auto result = backend->GetSize(&size); LOG_DEBUG(Service_FS, "called, size={}", size); IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(ResultSuccess); + rb.Push(result); rb.Push(size); } 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..887fd3ba2 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,7 @@ #pragma once +#include "core/file_sys/fsa/fs_i_file.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/service.h" @@ -10,10 +11,10 @@ namespace Service::FileSystem { class IFile final : public ServiceFramework { public: - explicit IFile(Core::System& system_, FileSys::VirtualFile backend_); + explicit IFile(Core::System& system_, FileSys::VirtualFile file_); private: - FileSys::VirtualFile backend; + std::unique_ptr backend; void Read(HLERequestContext& ctx); void Write(HLERequestContext& ctx); 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..1e69d22b8 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp @@ -9,9 +9,9 @@ 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_) + : ServiceFramework{system_, "IFileSystem"}, + backend{std::make_unique(dir_)}, size{std::move(size_)} { static const FunctionInfo functions[] = { {0, &IFileSystem::CreateFile, "CreateFile"}, {1, &IFileSystem::DeleteFile, "DeleteFile"}, @@ -39,6 +39,7 @@ void IFileSystem::CreateFile(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); const u64 file_mode = rp.Pop(); const u32 file_size = rp.Pop(); @@ -47,67 +48,75 @@ void IFileSystem::CreateFile(HLERequestContext& ctx) { file_size); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.CreateFile(name, file_size)); + rb.Push(backend->CreateFile(path, file_size)); } void IFileSystem::DeleteFile(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); LOG_DEBUG(Service_FS, "called. file={}", name); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.DeleteFile(name)); + rb.Push(backend->DeleteFile(path)); } void IFileSystem::CreateDirectory(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); LOG_DEBUG(Service_FS, "called. directory={}", name); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.CreateDirectory(name)); + rb.Push(backend->CreateDirectory(path)); } void IFileSystem::DeleteDirectory(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); LOG_DEBUG(Service_FS, "called. directory={}", name); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.DeleteDirectory(name)); + rb.Push(backend->DeleteDirectory(path)); } void IFileSystem::DeleteDirectoryRecursively(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); LOG_DEBUG(Service_FS, "called. directory={}", name); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.DeleteDirectoryRecursively(name)); + rb.Push(backend->DeleteDirectoryRecursively(path)); } void IFileSystem::CleanDirectoryRecursively(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); LOG_DEBUG(Service_FS, "called. Directory: {}", name); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.CleanDirectoryRecursively(name)); + rb.Push(backend->CleanDirectoryRecursively(path)); } 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)); + const auto src_path = FileSys::Path(src_name.c_str()); + const auto dst_path = FileSys::Path(dst_name.c_str()); + LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend.RenameFile(src_name, dst_name)); + rb.Push(backend->RenameFile(src_path, dst_path)); } void IFileSystem::OpenFile(HLERequestContext& ctx) { @@ -115,13 +124,14 @@ void IFileSystem::OpenFile(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); const auto mode = static_cast(rp.Pop()); LOG_DEBUG(Service_FS, "called. file={}, mode={}", name, mode); FileSys::VirtualFile vfs_file{}; - auto result = backend.OpenFile(&vfs_file, name, mode); + auto result = backend->OpenFile(&vfs_file, path, mode); if (result != ResultSuccess) { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -140,12 +150,13 @@ void IFileSystem::OpenDirectory(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); const auto mode = rp.PopRaw(); LOG_DEBUG(Service_FS, "called. directory={}, mode={}", name, mode); FileSys::VirtualDir vfs_dir{}; - auto result = backend.OpenDirectory(&vfs_dir, name); + auto result = backend->OpenDirectory(&vfs_dir, path, mode); if (result != ResultSuccess) { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -162,11 +173,12 @@ void IFileSystem::OpenDirectory(HLERequestContext& ctx) { void IFileSystem::GetEntryType(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); LOG_DEBUG(Service_FS, "called. file={}", name); FileSys::DirectoryEntryType vfs_entry_type{}; - auto result = backend.GetEntryType(&vfs_entry_type, name); + auto result = backend->GetEntryType(&vfs_entry_type, path); if (result != ResultSuccess) { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); @@ -204,11 +216,12 @@ void IFileSystem::GetTotalSpaceSize(HLERequestContext& ctx) { void IFileSystem::GetFileTimeStampRaw(HLERequestContext& ctx) { const auto file_buffer = ctx.ReadBuffer(); const std::string name = Common::StringFromBuffer(file_buffer); + const auto path = FileSys::Path(name.c_str()); LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); FileSys::FileTimeStampRaw vfs_timestamp{}; - auto result = backend.GetFileTimeStampRaw(&vfs_timestamp, name); + auto result = backend->GetFileTimeStampRaw(&vfs_timestamp, path); if (result != ResultSuccess) { IPC::ResponseBuilder rb{ctx, 2}; rb.Push(result); 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..d500be725 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h @@ -3,6 +3,7 @@ #pragma once +#include "core/file_sys/fsa/fs_i_filesystem.h" #include "core/file_sys/vfs/vfs.h" #include "core/hle/service/filesystem/filesystem.h" #include "core/hle/service/filesystem/fsp/fsp_util.h" @@ -12,7 +13,7 @@ namespace Service::FileSystem { class IFileSystem final : public ServiceFramework { public: - explicit IFileSystem(Core::System& system_, FileSys::VirtualDir backend_, SizeGetter size_); + explicit IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_); void CreateFile(HLERequestContext& ctx); void DeleteFile(HLERequestContext& ctx); @@ -31,7 +32,7 @@ public: void GetFileSystemAttribute(HLERequestContext& ctx); private: - VfsDirectoryServiceWrapper backend; + std::unique_ptr backend; SizeGetter size; }; -- cgit v1.2.3 From 934e420e36e817c673a839e2a417785906bfe91c Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sat, 10 Feb 2024 20:58:43 +0100 Subject: fs: Refactor to use cmif serialization --- .../hle/service/filesystem/fsp/fs_i_directory.cpp | 32 +-- .../hle/service/filesystem/fsp/fs_i_directory.h | 6 +- src/core/hle/service/filesystem/fsp/fs_i_file.cpp | 78 ++---- src/core/hle/service/filesystem/fsp/fs_i_file.h | 16 +- .../hle/service/filesystem/fsp/fs_i_filesystem.cpp | 292 +++++++-------------- .../hle/service/filesystem/fsp/fs_i_filesystem.h | 80 ++++-- 6 files changed, 209 insertions(+), 295 deletions(-) (limited to 'src/core/hle/service/filesystem') 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 661da5326..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,8 +3,8 @@ #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 { @@ -13,38 +13,24 @@ IDirectory::IDirectory(Core::System& system_, FileSys::VirtualDir directory_, : ServiceFramework{system_, "IDirectory"}, backend(std::make_unique(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); } -void IDirectory::Read(HLERequestContext& ctx) { +Result IDirectory::Read( + Out out_count, + const OutArray out_entries) { LOG_DEBUG(Service_FS, "called."); - // Calculate how many entries we can fit in the output buffer - const u64 count_entries = ctx.GetWriteBufferNumElements(); - - s64 out_count{}; - FileSys::DirectoryEntry* out_entries = nullptr; - const auto result = backend->Read(&out_count, out_entries, count_entries); - - // Write the data to memory - ctx.WriteBuffer(out_entries, out_count); - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.Push(out_count); + R_RETURN(backend->Read(out_count, out_entries.data(), out_entries.size())); } -void IDirectory::GetEntryCount(HLERequestContext& ctx) { +Result IDirectory::GetEntryCount(Out out_count) { LOG_DEBUG(Service_FS, "called"); - s64 out_count{}; - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(backend->GetEntryCount(&out_count)); - rb.Push(out_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 0dec4367b..b6251f7fd 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_directory.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_directory.h @@ -5,6 +5,7 @@ #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" @@ -22,8 +23,9 @@ public: private: std::unique_ptr backend; - void Read(HLERequestContext& ctx); - void GetEntryCount(HLERequestContext& ctx); + Result Read(Out out_count, + const OutArray out_entries); + Result GetEntryCount(Out 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 8fb8620de..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,86 +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 file_) : ServiceFramework{system_, "IFile"}, backend{std::make_unique(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(); - const s64 offset = rp.Pop(); - const s64 length = rp.Pop(); - - LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option, offset, length); +Result IFile::Read( + FileSys::ReadOption option, Out out_size, s64 offset, + const OutBuffer 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 output(length); - std::size_t bytes_read; - const auto result = backend->Read(&bytes_read, offset, output.data(), length); - - // Write the data to memory - ctx.WriteBuffer(output); - - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.Push(static_cast(bytes_read)); + R_RETURN( + backend->Read(reinterpret_cast(out_size.Get()), offset, out_buffer.data(), size)); } -void IFile::Write(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const auto option = rp.PopRaw(); - [[maybe_unused]] const u32 unused = rp.Pop(); - const s64 offset = rp.Pop(); - const s64 length = rp.Pop(); - +Result IFile::Write( + const InBuffer buffer, + FileSys::WriteOption option, s64 offset, s64 size) { LOG_DEBUG(Service_FS, "called, option={}, offset=0x{:X}, length={}", option.value, offset, - length); - - const auto data = ctx.ReadBuffer(); + size); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend->Write(offset, data.data(), length, option)); + R_RETURN(backend->Write(offset, buffer.data(), size, option)); } -void IFile::Flush(HLERequestContext& ctx) { +Result IFile::Flush() { LOG_DEBUG(Service_FS, "called"); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend->Flush()); + R_RETURN(backend->Flush()); } -void IFile::SetSize(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; - const u64 size = rp.Pop(); +Result IFile::SetSize(s64 size) { LOG_DEBUG(Service_FS, "called, size={}", size); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend->SetSize(size)); + R_RETURN(backend->SetSize(size)); } -void IFile::GetSize(HLERequestContext& ctx) { - s64 size; - const auto result = backend->GetSize(&size); - LOG_DEBUG(Service_FS, "called, size={}", size); +Result IFile::GetSize(Out out_size) { + LOG_DEBUG(Service_FS, "called"); - IPC::ResponseBuilder rb{ctx, 4}; - rb.Push(result); - rb.Push(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 887fd3ba2..e8599ee2f 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_file.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_file.h @@ -4,6 +4,7 @@ #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" @@ -16,11 +17,16 @@ public: private: std::unique_ptr 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 out_size, s64 offset, + const OutBuffer + out_buffer, + s64 size); + Result Write( + const InBuffer buffer, + FileSys::WriteOption option, s64 offset, s64 size); + Result Flush(); + Result SetSize(s64 size); + Result GetSize(Out 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 1e69d22b8..7fc62cb3e 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp @@ -2,274 +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 dir_, SizeGetter size_) +IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_getter_) : ServiceFramework{system_, "IFileSystem"}, - backend{std::make_unique(dir_)}, size{std::move(size_)} { + backend{std::make_unique(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 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 auto path = FileSys::Path(name.c_str()); - - const u64 file_mode = rp.Pop(); - const u32 file_size = rp.Pop(); - - 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(path, 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); - const auto path = FileSys::Path(name.c_str()); +Result IFileSystem::DeleteFile(const InLargeData 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(path)); + 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); - const auto path = FileSys::Path(name.c_str()); - - LOG_DEBUG(Service_FS, "called. directory={}", name); +Result IFileSystem::CreateDirectory( + const InLargeData path) { + LOG_DEBUG(Service_FS, "called. directory={}", path->str); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend->CreateDirectory(path)); + 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); - const auto path = FileSys::Path(name.c_str()); - - LOG_DEBUG(Service_FS, "called. directory={}", name); +Result IFileSystem::DeleteDirectory( + const InLargeData path) { + LOG_DEBUG(Service_FS, "called. directory={}", path->str); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend->DeleteDirectory(path)); + 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); - const auto path = FileSys::Path(name.c_str()); +Result IFileSystem::DeleteDirectoryRecursively( + const InLargeData 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(path)); + 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); - const auto path = FileSys::Path(name.c_str()); - - LOG_DEBUG(Service_FS, "called. Directory: {}", name); +Result IFileSystem::CleanDirectoryRecursively( + const InLargeData path) { + LOG_DEBUG(Service_FS, "called. Directory: {}", path->str); - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend->CleanDirectoryRecursively(path)); + 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)); - - const auto src_path = FileSys::Path(src_name.c_str()); - const auto dst_path = FileSys::Path(dst_name.c_str()); +Result IFileSystem::RenameFile( + const InLargeData old_path, + const InLargeData new_path) { + LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", old_path->str, new_path->str); - LOG_DEBUG(Service_FS, "called. file '{}' to file '{}'", src_name, dst_name); - - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(backend->RenameFile(src_path, dst_path)); + 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 path = FileSys::Path(name.c_str()); - - const auto mode = static_cast(rp.Pop()); - - LOG_DEBUG(Service_FS, "called. file={}, mode={}", name, mode); +Result IFileSystem::OpenFile(OutInterface out_interface, + const InLargeData path, + u32 mode) { + LOG_DEBUG(Service_FS, "called. file={}, mode={}", path->str, mode); FileSys::VirtualFile vfs_file{}; - auto result = backend->OpenFile(&vfs_file, path, mode); - if (result != ResultSuccess) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - return; - } - - auto file = std::make_shared(system, vfs_file); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface(std::move(file)); -} - -void IFileSystem::OpenDirectory(HLERequestContext& ctx) { - IPC::RequestParser rp{ctx}; + R_TRY(backend->OpenFile(&vfs_file, FileSys::Path(path->str), + static_cast(mode))); - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); - const auto path = FileSys::Path(name.c_str()); - const auto mode = rp.PopRaw(); + *out_interface = std::make_shared(system, vfs_file); + R_SUCCEED(); +} - LOG_DEBUG(Service_FS, "called. directory={}, mode={}", name, mode); +Result IFileSystem::OpenDirectory(OutInterface out_interface, + const InLargeData path, + u32 mode) { + LOG_DEBUG(Service_FS, "called. directory={}, mode={}", path->str, mode); FileSys::VirtualDir vfs_dir{}; - auto result = backend->OpenDirectory(&vfs_dir, path, mode); - if (result != ResultSuccess) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - return; - } - - auto directory = std::make_shared(system, vfs_dir, mode); - - IPC::ResponseBuilder rb{ctx, 2, 0, 1}; - rb.Push(ResultSuccess); - rb.PushIpcInterface(std::move(directory)); -} + R_TRY(backend->OpenDirectory(&vfs_dir, FileSys::Path(path->str), + static_cast(mode))); -void IFileSystem::GetEntryType(HLERequestContext& ctx) { - const auto file_buffer = ctx.ReadBuffer(); - const std::string name = Common::StringFromBuffer(file_buffer); - const auto path = FileSys::Path(name.c_str()); + *out_interface = std::make_shared(system, vfs_dir, + static_cast(mode)); + R_SUCCEED(); +} - LOG_DEBUG(Service_FS, "called. file={}", name); +Result IFileSystem::GetEntryType( + Out out_type, const InLargeData path) { + LOG_DEBUG(Service_FS, "called. file={}", path->str); FileSys::DirectoryEntryType vfs_entry_type{}; - auto result = backend->GetEntryType(&vfs_entry_type, path); - if (result != ResultSuccess) { - IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result); - return; - } - - IPC::ResponseBuilder rb{ctx, 3}; - rb.Push(ResultSuccess); - rb.Push(static_cast(vfs_entry_type)); + R_TRY(backend->GetEntryType(&vfs_entry_type, FileSys::Path(path->str))); + + *out_type = static_cast(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 out_size, const InLargeData 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 out_size, const InLargeData 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); - const auto path = FileSys::Path(name.c_str()); - - LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); +Result IFileSystem::GetFileTimeStampRaw( + Out out_timestamp, + const InLargeData path) { + LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", path->str); FileSys::FileTimeStampRaw vfs_timestamp{}; - auto result = backend->GetFileTimeStampRaw(&vfs_timestamp, path); - 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 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{}; 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 d500be725..d07b74938 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h @@ -5,35 +5,79 @@ #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/service.h" +namespace FileSys::Sf { +struct Path; +} + namespace Service::FileSystem { +class IFile; +class IDirectory; + class IFileSystem final : public ServiceFramework { public: - explicit IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, 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_); + + 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"); + + Result CreateFile(const InLargeData path, + s32 option, s64 size); + Result DeleteFile(const InLargeData path); + Result CreateDirectory(const InLargeData path); + Result DeleteDirectory(const InLargeData path); + Result DeleteDirectoryRecursively( + const InLargeData path); + Result CleanDirectoryRecursively( + const InLargeData path); + Result RenameFile(const InLargeData old_path, + const InLargeData new_path); + Result OpenFile(OutInterface out_interface, + const InLargeData path, u32 mode); + Result OpenDirectory(OutInterface out_interface, + const InLargeData path, + u32 mode); + Result GetEntryType(Out out_type, + const InLargeData path); + Result Commit(); + Result GetFreeSpaceSize(Out out_size, + const InLargeData path); + Result GetTotalSpaceSize(Out out_size, + const InLargeData path); + Result GetFileTimeStampRaw(Out out_timestamp, + const InLargeData path); + Result GetFileSystemAttribute(Out out_attribute); private: std::unique_ptr backend; - SizeGetter size; + SizeGetter size_getter; }; } // namespace Service::FileSystem -- cgit v1.2.3 From ba70dc4c13ff84b51d2937f5c8ba873b061cb4c1 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Sun, 11 Feb 2024 22:27:20 +0100 Subject: Address review comments --- src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp | 4 ++-- src/core/hle/service/filesystem/fsp/fs_i_filesystem.h | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/core/hle/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 7fc62cb3e..86dd5b7e9 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp @@ -11,8 +11,8 @@ namespace Service::FileSystem { IFileSystem::IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_getter_) - : ServiceFramework{system_, "IFileSystem"}, - backend{std::make_unique(dir_)}, + : ServiceFramework{system_, "IFileSystem"}, backend{std::make_unique( + dir_)}, size_getter{std::move(size_getter_)} { static const FunctionInfo functions[] = { {0, D<&IFileSystem::CreateFile>, "CreateFile"}, 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 d07b74938..230ab8d71 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h @@ -3,6 +3,7 @@ #pragma once +#include "common/common_funcs.h" #include "core/file_sys/fsa/fs_i_filesystem.h" #include "core/file_sys/vfs/vfs.h" #include "core/hle/service/cmif_types.h" @@ -48,8 +49,8 @@ public: }; static_assert(sizeof(FileSystemAttribute) == 0xC0, "FileSystemAttribute has incorrect size"); - Result CreateFile(const InLargeData path, - s32 option, s64 size); + Result CreateFile(const InLargeData path, s32 option, + s64 size); Result DeleteFile(const InLargeData path); Result CreateDirectory(const InLargeData path); Result DeleteDirectory(const InLargeData path); -- cgit v1.2.3 From ef5027712413705802d10c797b0f0b66375a9f58 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Mon, 19 Feb 2024 19:22:51 +0100 Subject: Address review comments pt. 2 --- .../hle/service/filesystem/fsp/fs_i_filesystem.cpp | 4 ++-- .../hle/service/filesystem/fsp/fs_i_filesystem.h | 28 ++-------------------- 2 files changed, 4 insertions(+), 28 deletions(-) (limited to 'src/core/hle/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 86dd5b7e9..d881e144d 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.cpp @@ -157,10 +157,10 @@ Result IFileSystem::GetFileTimeStampRaw( R_SUCCEED(); } -Result IFileSystem::GetFileSystemAttribute(Out out_attribute) { +Result IFileSystem::GetFileSystemAttribute(Out out_attribute) { LOG_WARNING(Service_FS, "(STUBBED) called"); - 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; 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 230ab8d71..113369203 100644 --- a/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h +++ b/src/core/hle/service/filesystem/fsp/fs_i_filesystem.h @@ -4,6 +4,7 @@ #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" @@ -24,31 +25,6 @@ class IFileSystem final : public ServiceFramework { public: explicit IFileSystem(Core::System& system_, FileSys::VirtualDir dir_, SizeGetter size_getter_); - 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"); - Result CreateFile(const InLargeData path, s32 option, s64 size); Result DeleteFile(const InLargeData path); @@ -74,7 +50,7 @@ public: const InLargeData path); Result GetFileTimeStampRaw(Out out_timestamp, const InLargeData path); - Result GetFileSystemAttribute(Out out_attribute); + Result GetFileSystemAttribute(Out out_attribute); private: std::unique_ptr backend; -- cgit v1.2.3