diff options
| author | 2014-06-27 16:18:56 -0400 | |
|---|---|---|
| committer | 2014-07-04 20:37:45 -0400 | |
| commit | 17a6148f9df406a6ca4bdca98777e0aaf21f582a (patch) | |
| tree | 3763cf9417649428c81c7e9e0cb6abac251faa49 /src/core/hle/kernel/archive.cpp | |
| parent | APT: Added stubbed ReceiveParameter and various cleanups. (diff) | |
| download | yuzu-17a6148f9df406a6ca4bdca98777e0aaf21f582a.tar.gz yuzu-17a6148f9df406a6ca4bdca98777e0aaf21f582a.tar.xz yuzu-17a6148f9df406a6ca4bdca98777e0aaf21f582a.zip | |
FileSys: Added preliminary support for applications reading the RomFS archive.
Archive: Fixed brace ugliness for neobrain :)
FS: Commented out unused local variables to prevent warnings.
...But keeping them here for future use.
archive_romfs: Removed unused #include.
Diffstat (limited to 'src/core/hle/kernel/archive.cpp')
| -rw-r--r-- | src/core/hle/kernel/archive.cpp | 98 |
1 files changed, 92 insertions, 6 deletions
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp index d7351e702..f31c02ea9 100644 --- a/src/core/hle/kernel/archive.cpp +++ b/src/core/hle/kernel/archive.cpp | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #include "common/common_types.h" | 5 | #include "common/common_types.h" |
| 6 | 6 | ||
| 7 | #include "core/file_sys/archive.h" | ||
| 8 | #include "core/hle/service/service.h" | ||
| 7 | #include "core/hle/kernel/kernel.h" | 9 | #include "core/hle/kernel/kernel.h" |
| 8 | #include "core/hle/kernel/archive.h" | 10 | #include "core/hle/kernel/archive.h" |
| 9 | 11 | ||
| @@ -12,6 +14,21 @@ | |||
| 12 | 14 | ||
| 13 | namespace Kernel { | 15 | namespace Kernel { |
| 14 | 16 | ||
| 17 | // Command to access archive file | ||
| 18 | enum class FileCommand : u32 { | ||
| 19 | Dummy1 = 0x000100C6, | ||
| 20 | Control = 0x040100C4, | ||
| 21 | OpenSubFile = 0x08010100, | ||
| 22 | Read = 0x080200C2, | ||
| 23 | Write = 0x08030102, | ||
| 24 | GetSize = 0x08040000, | ||
| 25 | SetSize = 0x08050080, | ||
| 26 | GetAttributes = 0x08060000, | ||
| 27 | SetAttributes = 0x08070040, | ||
| 28 | Close = 0x08080000, | ||
| 29 | Flush = 0x08090000, | ||
| 30 | }; | ||
| 31 | |||
| 15 | class Archive : public Object { | 32 | class Archive : public Object { |
| 16 | public: | 33 | public: |
| 17 | const char* GetTypeName() const { return "Archive"; } | 34 | const char* GetTypeName() const { return "Archive"; } |
| @@ -20,7 +37,37 @@ public: | |||
| 20 | static Kernel::HandleType GetStaticHandleType() { return HandleType::Archive; } | 37 | static Kernel::HandleType GetStaticHandleType() { return HandleType::Archive; } |
| 21 | Kernel::HandleType GetHandleType() const { return HandleType::Archive; } | 38 | Kernel::HandleType GetHandleType() const { return HandleType::Archive; } |
| 22 | 39 | ||
| 23 | std::string name; ///< Name of archive (optional) | 40 | std::string name; ///< Name of archive (optional) |
| 41 | FileSys::Archive* backend; ///< Archive backend interface | ||
| 42 | |||
| 43 | /** | ||
| 44 | * Synchronize kernel object | ||
| 45 | * @param wait Boolean wait set if current thread should wait as a result of sync operation | ||
| 46 | * @return Result of operation, 0 on success, otherwise error code | ||
| 47 | */ | ||
| 48 | Result SyncRequest(bool* wait) { | ||
| 49 | u32* cmd_buff = Service::GetCommandBuffer(); | ||
| 50 | FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]); | ||
| 51 | switch (cmd) { | ||
| 52 | |||
| 53 | // Read from archive... | ||
| 54 | case FileCommand::Read: | ||
| 55 | { | ||
| 56 | u64 offset = cmd_buff[1] | ((u64) cmd_buff[2]) << 32; | ||
| 57 | u32 length = cmd_buff[3]; | ||
| 58 | u32 address = cmd_buff[5]; | ||
| 59 | cmd_buff[2] = backend->Read(offset, length, Memory::GetPointer(address)); | ||
| 60 | break; | ||
| 61 | } | ||
| 62 | |||
| 63 | // Unknown command... | ||
| 64 | default: | ||
| 65 | ERROR_LOG(KERNEL, "Unknown command=0x%08X!", cmd); | ||
| 66 | return -1; | ||
| 67 | } | ||
| 68 | cmd_buff[1] = 0; // No error | ||
| 69 | return 0; | ||
| 70 | } | ||
| 24 | 71 | ||
| 25 | /** | 72 | /** |
| 26 | * Wait for kernel object to synchronize | 73 | * Wait for kernel object to synchronize |
| @@ -29,32 +76,71 @@ public: | |||
| 29 | */ | 76 | */ |
| 30 | Result WaitSynchronization(bool* wait) { | 77 | Result WaitSynchronization(bool* wait) { |
| 31 | // TODO(bunnei): ImplementMe | 78 | // TODO(bunnei): ImplementMe |
| 32 | ERROR_LOG(OSHLE, "unimplemented function"); | 79 | ERROR_LOG(OSHLE, "(UNIMPLEMENTED)"); |
| 33 | return 0; | 80 | return 0; |
| 34 | } | 81 | } |
| 35 | }; | 82 | }; |
| 36 | 83 | ||
| 84 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 85 | |||
| 86 | std::map<FileSys::Archive::IdCode, Handle> g_archive_map; ///< Map of file archives by IdCode | ||
| 87 | |||
| 88 | /** | ||
| 89 | * Opens an archive | ||
| 90 | * @param id_code IdCode of the archive to open | ||
| 91 | * @return Handle to archive if it exists, otherwise a null handle (0) | ||
| 92 | */ | ||
| 93 | Handle OpenArchive(FileSys::Archive::IdCode id_code) { | ||
| 94 | auto itr = g_archive_map.find(id_code); | ||
| 95 | if (itr == g_archive_map.end()) { | ||
| 96 | return 0; | ||
| 97 | } | ||
| 98 | return itr->second; | ||
| 99 | } | ||
| 100 | |||
| 101 | /** | ||
| 102 | * Mounts an archive | ||
| 103 | * @param archive Pointer to the archive to mount | ||
| 104 | * @return Result of operation, 0 on success, otherwise error code | ||
| 105 | */ | ||
| 106 | Result MountArchive(Archive* archive) { | ||
| 107 | FileSys::Archive::IdCode id_code = archive->backend->GetIdCode(); | ||
| 108 | if (0 != OpenArchive(id_code)) { | ||
| 109 | ERROR_LOG(KERNEL, "Cannot mount two archives with the same ID code! (%d)", (int) id_code); | ||
| 110 | return -1; | ||
| 111 | } | ||
| 112 | g_archive_map[id_code] = archive->GetHandle(); | ||
| 113 | INFO_LOG(KERNEL, "Mounted archive %s", archive->GetName()); | ||
| 114 | return 0; | ||
| 115 | } | ||
| 116 | |||
| 37 | /** | 117 | /** |
| 38 | * Creates an Archive | 118 | * Creates an Archive |
| 39 | * @param name Optional name of Archive | ||
| 40 | * @param handle Handle to newly created archive object | 119 | * @param handle Handle to newly created archive object |
| 120 | * @param backend File system backend interface to the archive | ||
| 121 | * @param name Optional name of Archive | ||
| 41 | * @return Newly created Archive object | 122 | * @return Newly created Archive object |
| 42 | */ | 123 | */ |
| 43 | Archive* CreateArchive(Handle& handle, const std::string& name) { | 124 | Archive* CreateArchive(Handle& handle, FileSys::Archive* backend, const std::string& name) { |
| 44 | Archive* archive = new Archive; | 125 | Archive* archive = new Archive; |
| 45 | handle = Kernel::g_object_pool.Create(archive); | 126 | handle = Kernel::g_object_pool.Create(archive); |
| 46 | archive->name = name; | 127 | archive->name = name; |
| 128 | archive->backend = backend; | ||
| 129 | |||
| 130 | MountArchive(archive); | ||
| 131 | |||
| 47 | return archive; | 132 | return archive; |
| 48 | } | 133 | } |
| 49 | 134 | ||
| 50 | /** | 135 | /** |
| 51 | * Creates an Archive | 136 | * Creates an Archive |
| 137 | * @param backend File system backend interface to the archive | ||
| 52 | * @param name Optional name of Archive | 138 | * @param name Optional name of Archive |
| 53 | * @return Handle to newly created Archive object | 139 | * @return Handle to newly created Archive object |
| 54 | */ | 140 | */ |
| 55 | Handle CreateArchive(const std::string& name) { | 141 | Handle CreateArchive(FileSys::Archive* backend, const std::string& name) { |
| 56 | Handle handle; | 142 | Handle handle; |
| 57 | Archive* archive = CreateArchive(handle, name); | 143 | Archive* archive = CreateArchive(handle, backend, name); |
| 58 | return handle; | 144 | return handle; |
| 59 | } | 145 | } |
| 60 | 146 | ||