From 19d7324075336093fd3477ec692787a95cda8e90 Mon Sep 17 00:00:00 2001 From: wwylele Date: Wed, 14 Feb 2018 21:29:56 +0200 Subject: [PATCH] fs/archive: convert Directory to ServiceFramework --- src/core/hle/service/fs/archive.cpp | 59 ++++++++++++++--------------- src/core/hle/service/fs/archive.h | 9 ++--- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 3e5a667ed..bb892aef5 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp @@ -303,42 +303,41 @@ Kernel::SharedPtr File::Connect() { Directory::Directory(std::unique_ptr&& backend, const FileSys::Path& path) - : path(path), backend(std::move(backend)) {} + : ServiceFramework("", 1), path(path), backend(std::move(backend)) { + static const FunctionInfo functions[] = { + // clang-format off + {0x08010042, &Directory::Read, "Read"}, + {0x08020000, &Directory::Close, "Close"}, + // clang-format on + }; + RegisterHandlers(functions); +} Directory::~Directory() {} -void Directory::HandleSyncRequest(Kernel::SharedPtr server_session) { - u32* cmd_buff = Kernel::GetCommandBuffer(); - DirectoryCommand cmd = static_cast(cmd_buff[0]); - switch (cmd) { - // Read from directory... - case DirectoryCommand::Read: { - u32 count = cmd_buff[1]; - u32 address = cmd_buff[3]; - std::vector entries(count); - LOG_TRACE(Service_FS, "Read %s: count=%d", GetName().c_str(), count); +void Directory::Read(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx, 0x0801, 1, 2); + u32 count = rp.Pop(); + auto& buffer = rp.PopMappedBuffer(); + std::vector entries(count); + LOG_TRACE(Service_FS, "Read %s: count=%u", GetName().c_str(), count); + // Number of entries actually read + u32 read = backend->Read(static_cast(entries.size()), entries.data()); + buffer.Write(entries.data(), 0, read * sizeof(FileSys::Entry)); - // Number of entries actually read - u32 read = backend->Read(static_cast(entries.size()), entries.data()); - cmd_buff[2] = read; - Memory::WriteBlock(address, entries.data(), read * sizeof(FileSys::Entry)); - break; - } + IPC::RequestBuilder rb = rp.MakeBuilder(2, 2); + rb.Push(RESULT_SUCCESS); + rb.Push(read); + rb.PushMappedBuffer(buffer); +} - case DirectoryCommand::Close: { - LOG_TRACE(Service_FS, "Close %s", GetName().c_str()); - backend->Close(); - break; - } +void Directory::Close(Kernel::HLERequestContext& ctx) { + IPC::RequestParser rp(ctx, 0x0802, 0, 0); + LOG_TRACE(Service_FS, "Close %s", GetName().c_str()); + backend->Close(); - // Unknown command... - default: - LOG_ERROR(Service_FS, "Unknown command=0x%08X!", static_cast(cmd)); - ResultCode error = UnimplementedFunction(ErrorModule::FS); - cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. - return; - } - cmd_buff[1] = RESULT_SUCCESS.raw; // No error + IPC::RequestBuilder rb = rp.MakeBuilder(1, 0); + rb.Push(RESULT_SUCCESS); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h index df4c902d0..91beb5d93 100644 --- a/src/core/hle/service/fs/archive.h +++ b/src/core/hle/service/fs/archive.h @@ -87,7 +87,7 @@ private: void OpenSubFile(Kernel::HLERequestContext& ctx); }; -class Directory final : public Kernel::SessionRequestHandler { +class Directory final : public ServiceFramework { public: Directory(std::unique_ptr&& backend, const FileSys::Path& path); ~Directory(); @@ -100,11 +100,8 @@ public: std::unique_ptr backend; ///< File backend interface protected: - void HandleSyncRequest(Kernel::SharedPtr server_session) override; - - std::unique_ptr MakeSessionData() const override { - return nullptr; - } + void Read(Kernel::HLERequestContext& ctx); + void Close(Kernel::HLERequestContext& ctx); }; /**