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 +++++----------------- 1 file changed, 12 insertions(+), 46 deletions(-) (limited to 'src/core/hle/service/filesystem/fsp/fs_i_directory.cpp') 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 -- cgit v1.2.3