summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Subv2015-02-07 13:06:48 -0500
committerGravatar Yuri Kunde Schlesner2015-02-10 13:43:45 -0200
commit071663e07423cac6037c72153edafea1efe9da9f (patch)
treebe08a19970e7ea3ef1e8c48aaf927ff323a0abd1 /src/core
parentResultVal: Fixed compilation when reassigning a ResultVal. (diff)
downloadyuzu-071663e07423cac6037c72153edafea1efe9da9f.tar.gz
yuzu-071663e07423cac6037c72153edafea1efe9da9f.tar.xz
yuzu-071663e07423cac6037c72153edafea1efe9da9f.zip
Archives: Expose the File and Directory classes to HLE
Diffstat (limited to 'src/core')
-rw-r--r--src/core/hle/service/fs/archive.cpp80
-rw-r--r--src/core/hle/service/fs/archive.h34
-rw-r--r--src/core/hle/service/fs/fs_user.cpp6
3 files changed, 62 insertions, 58 deletions
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 6c6a59e47..481715f17 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -20,7 +20,6 @@
20#include "core/file_sys/archive_sdmc.h" 20#include "core/file_sys/archive_sdmc.h"
21#include "core/file_sys/directory_backend.h" 21#include "core/file_sys/directory_backend.h"
22#include "core/hle/service/fs/archive.h" 22#include "core/hle/service/fs/archive.h"
23#include "core/hle/kernel/session.h"
24#include "core/hle/result.h" 23#include "core/hle/result.h"
25 24
26// Specializes std::hash for ArchiveIdCode, so that we can use it in std::unordered_map. 25// Specializes std::hash for ArchiveIdCode, so that we can use it in std::unordered_map.
@@ -76,31 +75,19 @@ enum class DirectoryCommand : u32 {
76 Close = 0x08020000, 75 Close = 0x08020000,
77}; 76};
78 77
79class File : public Kernel::Session { 78ResultVal<bool> File::SyncRequest() {
80public: 79 u32* cmd_buff = Kernel::GetCommandBuffer();
81 File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path) 80 FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
82 : path(path), priority(0), backend(std::move(backend)) { 81 switch (cmd) {
83 }
84
85 std::string GetName() const override { return "Path: " + path.DebugStr(); }
86
87 FileSys::Path path; ///< Path of the file
88 u32 priority; ///< Priority of the file. TODO(Subv): Find out what this means
89 std::unique_ptr<FileSys::FileBackend> backend; ///< File backend interface
90
91 ResultVal<bool> SyncRequest() override {
92 u32* cmd_buff = Kernel::GetCommandBuffer();
93 FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
94 switch (cmd) {
95 82
96 // Read from file... 83 // Read from file...
97 case FileCommand::Read: 84 case FileCommand::Read:
98 { 85 {
99 u64 offset = cmd_buff[1] | ((u64) cmd_buff[2]) << 32; 86 u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32;
100 u32 length = cmd_buff[3]; 87 u32 length = cmd_buff[3];
101 u32 address = cmd_buff[5]; 88 u32 address = cmd_buff[5];
102 LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x", 89 LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x",
103 GetTypeName().c_str(), GetName().c_str(), offset, length, address); 90 GetTypeName().c_str(), GetName().c_str(), offset, length, address);
104 cmd_buff[2] = backend->Read(offset, length, Memory::GetPointer(address)); 91 cmd_buff[2] = backend->Read(offset, length, Memory::GetPointer(address));
105 break; 92 break;
106 } 93 }
@@ -108,12 +95,12 @@ public:
108 // Write to file... 95 // Write to file...
109 case FileCommand::Write: 96 case FileCommand::Write:
110 { 97 {
111 u64 offset = cmd_buff[1] | ((u64) cmd_buff[2]) << 32; 98 u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32;
112 u32 length = cmd_buff[3]; 99 u32 length = cmd_buff[3];
113 u32 flush = cmd_buff[4]; 100 u32 flush = cmd_buff[4];
114 u32 address = cmd_buff[6]; 101 u32 address = cmd_buff[6];
115 LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x", 102 LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x",
116 GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush); 103 GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush);
117 cmd_buff[2] = backend->Write(offset, length, flush, Memory::GetPointer(address)); 104 cmd_buff[2] = backend->Write(offset, length, flush, Memory::GetPointer(address));
118 break; 105 break;
119 } 106 }
@@ -131,7 +118,7 @@ public:
131 { 118 {
132 u64 size = cmd_buff[1] | ((u64)cmd_buff[2] << 32); 119 u64 size = cmd_buff[1] | ((u64)cmd_buff[2] << 32);
133 LOG_TRACE(Service_FS, "SetSize %s %s size=%llu", 120 LOG_TRACE(Service_FS, "SetSize %s %s size=%llu",
134 GetTypeName().c_str(), GetName().c_str(), size); 121 GetTypeName().c_str(), GetName().c_str(), size);
135 backend->SetSize(size); 122 backend->SetSize(size);
136 break; 123 break;
137 } 124 }
@@ -177,27 +164,15 @@ public:
177 ResultCode error = UnimplementedFunction(ErrorModule::FS); 164 ResultCode error = UnimplementedFunction(ErrorModule::FS);
178 cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. 165 cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
179 return error; 166 return error;
180 }
181 cmd_buff[1] = 0; // No error
182 return MakeResult<bool>(false);
183 }
184};
185
186class Directory : public Kernel::Session {
187public:
188 Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path)
189 : path(path), backend(std::move(backend)) {
190 } 167 }
168 cmd_buff[1] = RESULT_SUCCESS.raw; // No error
169 return MakeResult<bool>(false);
170}
191 171
192 std::string GetName() const override { return "Directory: " + path.DebugStr(); } 172ResultVal<bool> Directory::SyncRequest() {
193 173 u32* cmd_buff = Kernel::GetCommandBuffer();
194 FileSys::Path path; ///< Path of the directory 174 DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
195 std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface 175 switch (cmd) {
196
197 ResultVal<bool> SyncRequest() override {
198 u32* cmd_buff = Kernel::GetCommandBuffer();
199 DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
200 switch (cmd) {
201 176
202 // Read from directory... 177 // Read from directory...
203 case DirectoryCommand::Read: 178 case DirectoryCommand::Read:
@@ -206,7 +181,7 @@ public:
206 u32 address = cmd_buff[3]; 181 u32 address = cmd_buff[3];
207 auto entries = reinterpret_cast<FileSys::Entry*>(Memory::GetPointer(address)); 182 auto entries = reinterpret_cast<FileSys::Entry*>(Memory::GetPointer(address));
208 LOG_TRACE(Service_FS, "Read %s %s: count=%d", 183 LOG_TRACE(Service_FS, "Read %s %s: count=%d",
209 GetTypeName().c_str(), GetName().c_str(), count); 184 GetTypeName().c_str(), GetName().c_str(), count);
210 185
211 // Number of entries actually read 186 // Number of entries actually read
212 cmd_buff[2] = backend->Read(count, entries); 187 cmd_buff[2] = backend->Read(count, entries);
@@ -226,11 +201,10 @@ public:
226 ResultCode error = UnimplementedFunction(ErrorModule::FS); 201 ResultCode error = UnimplementedFunction(ErrorModule::FS);
227 cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that. 202 cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
228 return MakeResult<bool>(false); 203 return MakeResult<bool>(false);
229 }
230 cmd_buff[1] = 0; // No error
231 return MakeResult<bool>(false);
232 } 204 }
233}; 205 cmd_buff[1] = RESULT_SUCCESS.raw; // No error
206 return MakeResult<bool>(false);
207}
234 208
235//////////////////////////////////////////////////////////////////////////////////////////////////// 209////////////////////////////////////////////////////////////////////////////////////////////////////
236 210
@@ -294,7 +268,7 @@ ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factor
294 return RESULT_SUCCESS; 268 return RESULT_SUCCESS;
295} 269}
296 270
297ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle archive_handle, 271ResultVal<Kernel::SharedPtr<File>> OpenFileFromArchive(ArchiveHandle archive_handle,
298 const FileSys::Path& path, const FileSys::Mode mode) { 272 const FileSys::Path& path, const FileSys::Mode mode) {
299 ArchiveBackend* archive = GetArchive(archive_handle); 273 ArchiveBackend* archive = GetArchive(archive_handle);
300 if (archive == nullptr) 274 if (archive == nullptr)
@@ -307,7 +281,7 @@ ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle
307 } 281 }
308 282
309 auto file = Kernel::SharedPtr<File>(new File(std::move(backend), path)); 283 auto file = Kernel::SharedPtr<File>(new File(std::move(backend), path));
310 return MakeResult<Kernel::SharedPtr<Kernel::Session>>(std::move(file)); 284 return MakeResult<Kernel::SharedPtr<File>>(std::move(file));
311} 285}
312 286
313ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { 287ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
@@ -393,7 +367,7 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, cons
393 ErrorSummary::NothingHappened, ErrorLevel::Status); 367 ErrorSummary::NothingHappened, ErrorLevel::Status);
394} 368}
395 369
396ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHandle archive_handle, 370ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
397 const FileSys::Path& path) { 371 const FileSys::Path& path) {
398 ArchiveBackend* archive = GetArchive(archive_handle); 372 ArchiveBackend* archive = GetArchive(archive_handle);
399 if (archive == nullptr) 373 if (archive == nullptr)
@@ -406,7 +380,7 @@ ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHa
406 } 380 }
407 381
408 auto directory = Kernel::SharedPtr<Directory>(new Directory(std::move(backend), path)); 382 auto directory = Kernel::SharedPtr<Directory>(new Directory(std::move(backend), path));
409 return MakeResult<Kernel::SharedPtr<Kernel::Session>>(std::move(directory)); 383 return MakeResult<Kernel::SharedPtr<Directory>>(std::move(directory));
410} 384}
411 385
412ResultCode FormatSaveData() { 386ResultCode FormatSaveData() {
diff --git a/src/core/hle/service/fs/archive.h b/src/core/hle/service/fs/archive.h
index 3d9b8a761..e27ad7d60 100644
--- a/src/core/hle/service/fs/archive.h
+++ b/src/core/hle/service/fs/archive.h
@@ -8,6 +8,7 @@
8 8
9#include "core/file_sys/archive_backend.h" 9#include "core/file_sys/archive_backend.h"
10#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/kernel.h"
11#include "core/hle/kernel/session.h"
11#include "core/hle/result.h" 12#include "core/hle/result.h"
12 13
13/// The unique system identifier hash, also known as ID0 14/// The unique system identifier hash, also known as ID0
@@ -36,6 +37,35 @@ enum class ArchiveIdCode : u32 {
36 37
37typedef u64 ArchiveHandle; 38typedef u64 ArchiveHandle;
38 39
40class File : public Kernel::Session {
41public:
42 File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path& path)
43 : path(path), priority(0), backend(std::move(backend)) {
44 }
45
46 std::string GetName() const override { return "Path: " + path.DebugStr(); }
47
48 FileSys::Path path; ///< Path of the file
49 u32 priority; ///< Priority of the file. TODO(Subv): Find out what this means
50 std::unique_ptr<FileSys::FileBackend> backend; ///< File backend interface
51
52 ResultVal<bool> SyncRequest() override;
53};
54
55class Directory : public Kernel::Session {
56public:
57 Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path)
58 : path(path), backend(std::move(backend)) {
59 }
60
61 std::string GetName() const override { return "Directory: " + path.DebugStr(); }
62
63 FileSys::Path path; ///< Path of the directory
64 std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface
65
66 ResultVal<bool> SyncRequest() override;
67};
68
39/** 69/**
40 * Opens an archive 70 * Opens an archive
41 * @param id_code IdCode of the archive to open 71 * @param id_code IdCode of the archive to open
@@ -64,7 +94,7 @@ ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factor
64 * @param mode Mode under which to open the File 94 * @param mode Mode under which to open the File
65 * @return The opened File object as a Session 95 * @return The opened File object as a Session
66 */ 96 */
67ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenFileFromArchive(ArchiveHandle archive_handle, 97ResultVal<Kernel::SharedPtr<File>> OpenFileFromArchive(ArchiveHandle archive_handle,
68 const FileSys::Path& path, const FileSys::Mode mode); 98 const FileSys::Path& path, const FileSys::Mode mode);
69 99
70/** 100/**
@@ -128,7 +158,7 @@ ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, cons
128 * @param path Path to the Directory inside of the Archive 158 * @param path Path to the Directory inside of the Archive
129 * @return The opened Directory object as a Session 159 * @return The opened Directory object as a Session
130 */ 160 */
131ResultVal<Kernel::SharedPtr<Kernel::Session>> OpenDirectoryFromArchive(ArchiveHandle archive_handle, 161ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
132 const FileSys::Path& path); 162 const FileSys::Path& path);
133 163
134/** 164/**
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp
index 94a3a31c8..d57dd042b 100644
--- a/src/core/hle/service/fs/fs_user.cpp
+++ b/src/core/hle/service/fs/fs_user.cpp
@@ -61,7 +61,7 @@ static void OpenFile(Service::Interface* self) {
61 61
62 LOG_DEBUG(Service_FS, "path=%s, mode=%d attrs=%u", file_path.DebugStr().c_str(), mode.hex, attributes); 62 LOG_DEBUG(Service_FS, "path=%s, mode=%d attrs=%u", file_path.DebugStr().c_str(), mode.hex, attributes);
63 63
64 ResultVal<SharedPtr<Session>> file_res = OpenFileFromArchive(archive_handle, file_path, mode); 64 ResultVal<SharedPtr<File>> file_res = OpenFileFromArchive(archive_handle, file_path, mode);
65 cmd_buff[1] = file_res.Code().raw; 65 cmd_buff[1] = file_res.Code().raw;
66 if (file_res.Succeeded()) { 66 if (file_res.Succeeded()) {
67 cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom(); 67 cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
@@ -117,7 +117,7 @@ static void OpenFileDirectly(Service::Interface* self) {
117 } 117 }
118 SCOPE_EXIT({ CloseArchive(*archive_handle); }); 118 SCOPE_EXIT({ CloseArchive(*archive_handle); });
119 119
120 ResultVal<SharedPtr<Session>> file_res = OpenFileFromArchive(*archive_handle, file_path, mode); 120 ResultVal<SharedPtr<File>> file_res = OpenFileFromArchive(*archive_handle, file_path, mode);
121 cmd_buff[1] = file_res.Code().raw; 121 cmd_buff[1] = file_res.Code().raw;
122 if (file_res.Succeeded()) { 122 if (file_res.Succeeded()) {
123 cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom(); 123 cmd_buff[3] = Kernel::g_handle_table.Create(*file_res).MoveFrom();
@@ -337,7 +337,7 @@ static void OpenDirectory(Service::Interface* self) {
337 337
338 LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str()); 338 LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_path.DebugStr().c_str());
339 339
340 ResultVal<SharedPtr<Session>> dir_res = OpenDirectoryFromArchive(archive_handle, dir_path); 340 ResultVal<SharedPtr<Directory>> dir_res = OpenDirectoryFromArchive(archive_handle, dir_path);
341 cmd_buff[1] = dir_res.Code().raw; 341 cmd_buff[1] = dir_res.Code().raw;
342 if (dir_res.Succeeded()) { 342 if (dir_res.Succeeded()) {
343 cmd_buff[3] = Kernel::g_handle_table.Create(*dir_res).MoveFrom(); 343 cmd_buff[3] = Kernel::g_handle_table.Create(*dir_res).MoveFrom();