diff options
| author | 2018-01-16 19:20:12 -0800 | |
|---|---|---|
| committer | 2018-01-21 15:39:28 -0500 | |
| commit | d64b7d7dfda8123cc8e0d6abaf358a4a08ba795c (patch) | |
| tree | 8131ceeb6ec598cf7cf83132a19cc6ab981a4ff0 /src | |
| parent | file_sys: Cleanup to better match Switch file system constructs. (diff) | |
| download | yuzu-d64b7d7dfda8123cc8e0d6abaf358a4a08ba795c.tar.gz yuzu-d64b7d7dfda8123cc8e0d6abaf358a4a08ba795c.tar.xz yuzu-d64b7d7dfda8123cc8e0d6abaf358a4a08ba795c.zip | |
filesystem: Implement basic IStorage functionality.
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/CMakeLists.txt | 4 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/filesystem.cpp | 54 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/filesystem.h | 41 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp_srv.cpp | 132 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp_srv.h | 25 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 2 |
6 files changed, 258 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 5ff1311a2..433e7e596 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -97,6 +97,10 @@ add_library(core STATIC | |||
| 97 | hle/service/audio/audio.h | 97 | hle/service/audio/audio.h |
| 98 | hle/service/audio/audout_u.cpp | 98 | hle/service/audio/audout_u.cpp |
| 99 | hle/service/audio/audout_u.h | 99 | hle/service/audio/audout_u.h |
| 100 | hle/service/filesystem/filesystem.cpp | ||
| 101 | hle/service/filesystem/filesystem.h | ||
| 102 | hle/service/filesystem/fsp_srv.cpp | ||
| 103 | hle/service/filesystem/fsp_srv.h | ||
| 100 | hle/service/hid/hid.cpp | 104 | hle/service/hid/hid.cpp |
| 101 | hle/service/hid/hid.h | 105 | hle/service/hid/hid.h |
| 102 | hle/service/lm/lm.cpp | 106 | hle/service/lm/lm.cpp |
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp new file mode 100644 index 000000000..4b47548fd --- /dev/null +++ b/src/core/hle/service/filesystem/filesystem.cpp | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <boost/container/flat_map.hpp> | ||
| 6 | #include "core/file_sys/filesystem.h" | ||
| 7 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 8 | #include "core/hle/service/filesystem/fsp_srv.h" | ||
| 9 | |||
| 10 | namespace Service { | ||
| 11 | namespace FileSystem { | ||
| 12 | |||
| 13 | /** | ||
| 14 | * Map of registered file systems, identified by type. Once an file system is registered here, it | ||
| 15 | * is never removed until UnregisterFileSystems is called. | ||
| 16 | */ | ||
| 17 | static boost::container::flat_map<Type, std::unique_ptr<FileSys::FileSystemFactory>> filesystem_map; | ||
| 18 | |||
| 19 | ResultCode RegisterFileSystem(std::unique_ptr<FileSys::FileSystemFactory>&& factory, Type type) { | ||
| 20 | auto result = filesystem_map.emplace(type, std::move(factory)); | ||
| 21 | |||
| 22 | bool inserted = result.second; | ||
| 23 | ASSERT_MSG(inserted, "Tried to register more than one system with same id code"); | ||
| 24 | |||
| 25 | auto& filesystem = result.first->second; | ||
| 26 | LOG_DEBUG(Service_FS, "Registered file system %s with id code 0x%08X", | ||
| 27 | filesystem->GetName().c_str(), static_cast<u32>(type)); | ||
| 28 | return RESULT_SUCCESS; | ||
| 29 | } | ||
| 30 | |||
| 31 | ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type, | ||
| 32 | FileSys::Path& path) { | ||
| 33 | LOG_TRACE(Service_FS, "Opening FileSystem with type=%d", type); | ||
| 34 | |||
| 35 | auto itr = filesystem_map.find(type); | ||
| 36 | if (itr == filesystem_map.end()) { | ||
| 37 | // TODO(bunnei): Find a better error code for this | ||
| 38 | return ResultCode(-1); | ||
| 39 | } | ||
| 40 | |||
| 41 | return itr->second->Open(path); | ||
| 42 | } | ||
| 43 | |||
| 44 | void UnregisterFileSystems() { | ||
| 45 | filesystem_map.clear(); | ||
| 46 | } | ||
| 47 | |||
| 48 | void InstallInterfaces(SM::ServiceManager& service_manager) { | ||
| 49 | UnregisterFileSystems(); | ||
| 50 | std::make_shared<FSP_SRV>()->InstallAsService(service_manager); | ||
| 51 | } | ||
| 52 | |||
| 53 | } // namespace FileSystem | ||
| 54 | } // namespace Service | ||
diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h new file mode 100644 index 000000000..52db83e62 --- /dev/null +++ b/src/core/hle/service/filesystem/filesystem.h | |||
| @@ -0,0 +1,41 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <memory> | ||
| 8 | #include "common/common_types.h" | ||
| 9 | #include "core/file_sys/filesystem.h" | ||
| 10 | #include "core/hle/result.h" | ||
| 11 | #include "core/hle/service/service.h" | ||
| 12 | |||
| 13 | namespace Service { | ||
| 14 | namespace FileSystem { | ||
| 15 | |||
| 16 | /// Supported FileSystem types | ||
| 17 | enum class Type { | ||
| 18 | RomFS = 1, | ||
| 19 | }; | ||
| 20 | |||
| 21 | /** | ||
| 22 | * Registers a FileSystem, instances of which can later be opened using its IdCode. | ||
| 23 | * @param factory FileSystem backend interface to use | ||
| 24 | * @param type Type used to access this type of FileSystem | ||
| 25 | */ | ||
| 26 | ResultCode RegisterFileSystem(std::unique_ptr<FileSys::FileSystemFactory>&& factory, Type type); | ||
| 27 | |||
| 28 | /** | ||
| 29 | * Opens a file system | ||
| 30 | * @param type Type of the file system to open | ||
| 31 | * @param path Path to the file system, used with Binary paths | ||
| 32 | * @return FileSys::FileSystemBackend interface to the file system | ||
| 33 | */ | ||
| 34 | ResultVal<std::unique_ptr<FileSys::FileSystemBackend>> OpenFileSystem(Type type, | ||
| 35 | FileSys::Path& path); | ||
| 36 | |||
| 37 | /// Registers all Filesystem services with the specified service manager. | ||
| 38 | void InstallInterfaces(SM::ServiceManager& service_manager); | ||
| 39 | |||
| 40 | } // namespace Filesystem | ||
| 41 | } // namespace Service | ||
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp new file mode 100644 index 000000000..47a97f0fd --- /dev/null +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -0,0 +1,132 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/logging/log.h" | ||
| 6 | #include "core/core.h" | ||
| 7 | #include "core/file_sys/filesystem.h" | ||
| 8 | #include "core/file_sys/storage.h" | ||
| 9 | #include "core/hle/ipc_helpers.h" | ||
| 10 | #include "core/hle/kernel/client_port.h" | ||
| 11 | #include "core/hle/kernel/client_session.h" | ||
| 12 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 13 | #include "core/hle/service/filesystem/fsp_srv.h" | ||
| 14 | |||
| 15 | namespace Service { | ||
| 16 | namespace FileSystem { | ||
| 17 | |||
| 18 | class IStorage final : public ServiceFramework<IStorage> { | ||
| 19 | public: | ||
| 20 | IStorage(std::unique_ptr<FileSys::StorageBackend>&& backend) | ||
| 21 | : ServiceFramework("IStorage"), backend(std::move(backend)) { | ||
| 22 | static const FunctionInfo functions[] = { | ||
| 23 | {0, &IStorage::Read, "Read"}, {1, &IStorage::Write, "Write"}, | ||
| 24 | {2, &IStorage::Flush, "Flush"}, {3, &IStorage::SetSize, "SetSize"}, | ||
| 25 | {4, &IStorage::GetSize, "GetSize"}, | ||
| 26 | }; | ||
| 27 | RegisterHandlers(functions); | ||
| 28 | } | ||
| 29 | |||
| 30 | private: | ||
| 31 | std::unique_ptr<FileSys::StorageBackend> backend; | ||
| 32 | |||
| 33 | void Read(Kernel::HLERequestContext& ctx) { | ||
| 34 | IPC::RequestParser rp{ctx}; | ||
| 35 | u64 offset = rp.Pop<u64>(); | ||
| 36 | u64 length = rp.Pop<u64>(); | ||
| 37 | |||
| 38 | LOG_DEBUG(Service, "called, offset=0x%llx, length=0x%llx", offset, length); | ||
| 39 | |||
| 40 | auto descriptor = ctx.BufferDescriptorB()[0]; | ||
| 41 | std::vector<u8> output(length); | ||
| 42 | |||
| 43 | ResultVal<size_t> res = backend->Read(offset, length, output.data()); | ||
| 44 | if (res.Failed()) { | ||
| 45 | IPC::RequestBuilder rb{ctx, 2}; | ||
| 46 | rb.Push(res.Code()); | ||
| 47 | } | ||
| 48 | |||
| 49 | Memory::WriteBlock(descriptor.Address(), output.data(), descriptor.Size()); | ||
| 50 | |||
| 51 | IPC::RequestBuilder rb{ctx, 2}; | ||
| 52 | rb.Push(RESULT_SUCCESS); | ||
| 53 | } | ||
| 54 | |||
| 55 | void Write(Kernel::HLERequestContext& ctx) { | ||
| 56 | IPC::RequestBuilder rb{ctx, 2}; | ||
| 57 | rb.Push(RESULT_SUCCESS); | ||
| 58 | LOG_WARNING(Service, "(STUBBED) called"); | ||
| 59 | } | ||
| 60 | |||
| 61 | void Flush(Kernel::HLERequestContext& ctx) { | ||
| 62 | IPC::RequestBuilder rb{ctx, 2}; | ||
| 63 | rb.Push(RESULT_SUCCESS); | ||
| 64 | LOG_WARNING(Service, "(STUBBED) called"); | ||
| 65 | } | ||
| 66 | |||
| 67 | void SetSize(Kernel::HLERequestContext& ctx) { | ||
| 68 | IPC::RequestBuilder rb{ctx, 2}; | ||
| 69 | rb.Push(RESULT_SUCCESS); | ||
| 70 | LOG_WARNING(Service, "(STUBBED) called"); | ||
| 71 | } | ||
| 72 | |||
| 73 | void GetSize(Kernel::HLERequestContext& ctx) { | ||
| 74 | IPC::RequestBuilder rb{ctx, 2}; | ||
| 75 | rb.Push(RESULT_SUCCESS); | ||
| 76 | LOG_WARNING(Service, "(STUBBED) called"); | ||
| 77 | } | ||
| 78 | }; | ||
| 79 | |||
| 80 | FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { | ||
| 81 | static const FunctionInfo functions[] = { | ||
| 82 | {1, &FSP_SRV::Initalize, "Initalize"}, | ||
| 83 | {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"}, | ||
| 84 | {203, &FSP_SRV::OpenRomStorage, "OpenRomStorage"}, | ||
| 85 | {1005, &FSP_SRV::GetGlobalAccessLogMode, "GetGlobalAccessLogMode"}, | ||
| 86 | }; | ||
| 87 | RegisterHandlers(functions); | ||
| 88 | } | ||
| 89 | |||
| 90 | void FSP_SRV::Initalize(Kernel::HLERequestContext& ctx) { | ||
| 91 | IPC::RequestBuilder rb{ctx, 2}; | ||
| 92 | rb.Push(RESULT_SUCCESS); | ||
| 93 | LOG_WARNING(Service, "(STUBBED) called"); | ||
| 94 | } | ||
| 95 | |||
| 96 | void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { | ||
| 97 | IPC::RequestBuilder rb{ctx, 4}; | ||
| 98 | rb.Push(RESULT_SUCCESS); | ||
| 99 | rb.Push<u32>(5); | ||
| 100 | LOG_WARNING(Service, "(STUBBED) called"); | ||
| 101 | } | ||
| 102 | |||
| 103 | void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { | ||
| 104 | FileSys::Path path; | ||
| 105 | auto filesystem = OpenFileSystem(Type::RomFS, path); | ||
| 106 | if (filesystem.Failed()) { | ||
| 107 | IPC::RequestBuilder rb{ctx, 2}; | ||
| 108 | rb.Push(filesystem.Code()); | ||
| 109 | return; | ||
| 110 | } | ||
| 111 | |||
| 112 | auto storage = filesystem.Unwrap()->OpenFile({}, {}); | ||
| 113 | if (storage.Failed()) { | ||
| 114 | IPC::RequestBuilder rb{ctx, 2}; | ||
| 115 | rb.Push(storage.Code()); | ||
| 116 | return; | ||
| 117 | } | ||
| 118 | |||
| 119 | // TODO: What if already opened? | ||
| 120 | |||
| 121 | IPC::RequestBuilder rb{ctx, 2, 0, 0, 1}; | ||
| 122 | rb.Push(RESULT_SUCCESS); | ||
| 123 | rb.PushIpcInterface<IStorage>(std::move(storage.Unwrap())); | ||
| 124 | LOG_WARNING(Service, "(STUBBED) called"); | ||
| 125 | } | ||
| 126 | |||
| 127 | void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) { | ||
| 128 | OpenDataStorageByCurrentProcess(ctx); | ||
| 129 | } | ||
| 130 | |||
| 131 | } // namespace Filesystem | ||
| 132 | } // namespace Service | ||
diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h new file mode 100644 index 000000000..b41ba6bd1 --- /dev/null +++ b/src/core/hle/service/filesystem/fsp_srv.h | |||
| @@ -0,0 +1,25 @@ | |||
| 1 | // Copyright 2018 yuzu emulator team | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/hle/service/service.h" | ||
| 8 | |||
| 9 | namespace Service { | ||
| 10 | namespace FileSystem { | ||
| 11 | |||
| 12 | class FSP_SRV final : public ServiceFramework<FSP_SRV> { | ||
| 13 | public: | ||
| 14 | FSP_SRV(); | ||
| 15 | ~FSP_SRV() = default; | ||
| 16 | |||
| 17 | private: | ||
| 18 | void Initalize(Kernel::HLERequestContext& ctx); | ||
| 19 | void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); | ||
| 20 | void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); | ||
| 21 | void OpenRomStorage(Kernel::HLERequestContext& ctx); | ||
| 22 | }; | ||
| 23 | |||
| 24 | } // namespace Filesystem | ||
| 25 | } // namespace Service | ||
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 19213a2f4..3f5ce56c6 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -19,6 +19,7 @@ | |||
| 19 | #include "core/hle/service/aoc/aoc_u.h" | 19 | #include "core/hle/service/aoc/aoc_u.h" |
| 20 | #include "core/hle/service/apm/apm.h" | 20 | #include "core/hle/service/apm/apm.h" |
| 21 | #include "core/hle/service/audio/audio.h" | 21 | #include "core/hle/service/audio/audio.h" |
| 22 | #include "core/hle/service/filesystem/filesystem.h" | ||
| 22 | #include "core/hle/service/hid/hid.h" | 23 | #include "core/hle/service/hid/hid.h" |
| 23 | #include "core/hle/service/lm/lm.h" | 24 | #include "core/hle/service/lm/lm.h" |
| 24 | #include "core/hle/service/nvdrv/nvdrv.h" | 25 | #include "core/hle/service/nvdrv/nvdrv.h" |
| @@ -172,6 +173,7 @@ void Init() { | |||
| 172 | AOC::InstallInterfaces(*SM::g_service_manager); | 173 | AOC::InstallInterfaces(*SM::g_service_manager); |
| 173 | APM::InstallInterfaces(*SM::g_service_manager); | 174 | APM::InstallInterfaces(*SM::g_service_manager); |
| 174 | Audio::InstallInterfaces(*SM::g_service_manager); | 175 | Audio::InstallInterfaces(*SM::g_service_manager); |
| 176 | FileSystem::InstallInterfaces(*SM::g_service_manager); | ||
| 175 | HID::InstallInterfaces(*SM::g_service_manager); | 177 | HID::InstallInterfaces(*SM::g_service_manager); |
| 176 | LM::InstallInterfaces(*SM::g_service_manager); | 178 | LM::InstallInterfaces(*SM::g_service_manager); |
| 177 | Nvidia::InstallInterfaces(*SM::g_service_manager); | 179 | Nvidia::InstallInterfaces(*SM::g_service_manager); |