summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2014-11-14 00:07:02 -0500
committerGravatar bunnei2014-11-17 22:18:58 -0500
commit3e09c07378a73b959c02830e1c0ffb584a60087c (patch)
tree936e6b2571702777c7d050bca3ad0fdf8a2a6536 /src
parentFileSys: Updated backend code to use FileSys::Path instead of string for paths. (diff)
downloadyuzu-3e09c07378a73b959c02830e1c0ffb584a60087c.tar.gz
yuzu-3e09c07378a73b959c02830e1c0ffb584a60087c.tar.xz
yuzu-3e09c07378a73b959c02830e1c0ffb584a60087c.zip
FS_User: Support FileSye::Path in a more generic way.
added a todo to kernel archive
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/kernel/archive.cpp11
-rw-r--r--src/core/hle/service/fs_user.cpp107
2 files changed, 76 insertions, 42 deletions
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index 5d734d042..e911f4dc9 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -367,6 +367,17 @@ Handle CreateArchive(FileSys::Archive* backend, const std::string& name) {
367 * @return Opened File object 367 * @return Opened File object
368 */ 368 */
369Handle OpenFileFromArchive(Handle archive_handle, const FileSys::Path& path, const FileSys::Mode mode) { 369Handle OpenFileFromArchive(Handle archive_handle, const FileSys::Path& path, const FileSys::Mode mode) {
370 // TODO(bunnei): Binary type files get a raw file pointer to the archive. Currently, we create
371 // the archive file handles at app loading, and then keep them persistent throughout execution.
372 // Archives file handles are just reused and not actually freed until emulation shut down.
373 // Verify if real hardware works this way, or if new handles are created each time
374 if (path.GetType() == FileSys::Binary)
375 // TODO(bunnei): FixMe - this is a hack to compensate for an incorrect FileSys backend
376 // design. While the functionally of this is OK, our implementation decision to separate
377 // normal files from archive file pointers is very likely wrong.
378 // See https://github.com/citra-emu/citra/issues/205
379 return archive_handle;
380
370 File* file = new File; 381 File* file = new File;
371 Handle handle = Kernel::g_object_pool.Create(file); 382 Handle handle = Kernel::g_object_pool.Create(file);
372 383
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index 1548b9ee5..8d8f0a201 100644
--- a/src/core/hle/service/fs_user.cpp
+++ b/src/core/hle/service/fs_user.cpp
@@ -28,6 +28,22 @@ void Initialize(Service::Interface* self) {
28 DEBUG_LOG(KERNEL, "called"); 28 DEBUG_LOG(KERNEL, "called");
29} 29}
30 30
31/**
32 * FS_User::OpenFile service function
33 * Inputs:
34 * 1 : Transaction
35 * 2 : Archive handle lower word
36 * 3 : Archive handle upper word
37 * 4 : Low path type
38 * 5 : Low path size
39 * 6 : Open flags
40 * 7 : Attributes
41 * 8 : (LowPathSize << 14) | 2
42 * 9 : Low path data pointer
43 * Outputs:
44 * 1 : Result of function, 0 on success, otherwise error code
45 * 3 : File handle
46 */
31void OpenFile(Service::Interface* self) { 47void OpenFile(Service::Interface* self) {
32 u32* cmd_buff = Service::GetCommandBuffer(); 48 u32* cmd_buff = Service::GetCommandBuffer();
33 49
@@ -39,28 +55,16 @@ void OpenFile(Service::Interface* self) {
39 FileSys::Mode mode; mode.hex = cmd_buff[6]; 55 FileSys::Mode mode; mode.hex = cmd_buff[6];
40 u32 attributes = cmd_buff[7]; // TODO(Link Mauve): do something with those attributes. 56 u32 attributes = cmd_buff[7]; // TODO(Link Mauve): do something with those attributes.
41 u32 filename_ptr = cmd_buff[9]; 57 u32 filename_ptr = cmd_buff[9];
42
43 FileSys::Path file_path(filename_type, filename_size, filename_ptr); 58 FileSys::Path file_path(filename_type, filename_size, filename_ptr);
44 std::string file_string;
45 switch (file_path.GetType()) {
46 case FileSys::Char:
47 case FileSys::Wchar:
48 file_string = file_path.AsString();
49 break;
50 default:
51 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead");
52 return;
53 }
54 59
55 DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s", 60 DEBUG_LOG(KERNEL, "path=%s, mode=%d attrs=%d", file_path.DebugStr().c_str(), mode, attributes);
56 filename_type, filename_size, mode, attributes, file_string.c_str());
57 61
58 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_path, mode); 62 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_path, mode);
59 if (handle) { 63 if (handle) {
60 cmd_buff[1] = 0; 64 cmd_buff[1] = 0;
61 cmd_buff[3] = handle; 65 cmd_buff[3] = handle;
62 } else { 66 } else {
63 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_string.c_str()); 67 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_path.DebugStr().c_str());
64 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. 68 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
65 cmd_buff[1] = -1; 69 cmd_buff[1] = -1;
66 } 70 }
@@ -68,6 +72,25 @@ void OpenFile(Service::Interface* self) {
68 DEBUG_LOG(KERNEL, "called"); 72 DEBUG_LOG(KERNEL, "called");
69} 73}
70 74
75/**
76 * FS_User::OpenFileDirectly service function
77 * Inputs:
78 * 1 : Transaction
79 * 2 : Archive ID
80 * 3 : Archive low path type
81 * 4 : Archive low path size
82 * 5 : File low path type
83 * 6 : File low path size
84 * 7 : Flags
85 * 8 : Attributes
86 * 9 : (ArchiveLowPathSize << 14) | 0x802
87 * 10 : Archive low path
88 * 11 : (FileLowPathSize << 14) | 2
89 * 12 : File low path
90 * Outputs:
91 * 1 : Result of function, 0 on success, otherwise error code
92 * 3 : File handle
93 */
71void OpenFileDirectly(Service::Interface* self) { 94void OpenFileDirectly(Service::Interface* self) {
72 u32* cmd_buff = Service::GetCommandBuffer(); 95 u32* cmd_buff = Service::GetCommandBuffer();
73 96
@@ -80,47 +103,33 @@ void OpenFileDirectly(Service::Interface* self) {
80 u32 attributes = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes. 103 u32 attributes = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes.
81 u32 archivename_ptr = cmd_buff[10]; 104 u32 archivename_ptr = cmd_buff[10];
82 u32 filename_ptr = cmd_buff[12]; 105 u32 filename_ptr = cmd_buff[12];
106 FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr);
107 FileSys::Path file_path(filename_type, filename_size, filename_ptr);
83 108
84 DEBUG_LOG(KERNEL, "archive_type=%d archive_size=%d file_type=%d file_size=%d file_mode=%d file_attrs=%d", 109 DEBUG_LOG(KERNEL, "archive_path=%s file_path=%s, mode=%d attributes=%d",
85 archivename_type, archivename_size, filename_type, filename_size, mode, attributes); 110 archive_path.DebugStr().c_str(), file_path.DebugStr().c_str(), mode, attributes);
86 111
87 if (archivename_type != FileSys::Empty) { 112 if (archive_path.GetType() != FileSys::Empty) {
88 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported"); 113 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
89 cmd_buff[1] = -1; 114 cmd_buff[1] = -1;
90 return; 115 return;
91 } 116 }
92 117
93 // TODO(Link Mauve): check if we should even get a handle for the archive, and don't leak it. 118 // TODO(Link Mauve): Check if we should even get a handle for the archive, and don't leak it
94 Handle archive_handle = Kernel::OpenArchive(archive_id); 119 Handle archive_handle = Kernel::OpenArchive(archive_id);
95 if (archive_handle) { 120 if (!archive_handle) {
96 cmd_buff[1] = 0;
97 // cmd_buff[2] isn't used according to 3dmoo's implementation.
98 cmd_buff[3] = archive_handle;
99 } else {
100 ERROR_LOG(KERNEL, "failed to get a handle for archive"); 121 ERROR_LOG(KERNEL, "failed to get a handle for archive");
101 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. 122 // TODO(Link Mauve): Check for the actual error values, this one was just chosen arbitrarily
102 cmd_buff[1] = -1; 123 cmd_buff[1] = -1;
103 return; 124 return;
104 } 125 }
105 126
106 FileSys::Path file_path(filename_type, filename_size, filename_ptr);
107 std::string file_string;
108 switch (file_path.GetType()) {
109 case FileSys::Char:
110 case FileSys::Wchar:
111 file_string = file_path.AsString();
112 break;
113 default:
114 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead");
115 return;
116 }
117
118 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_path, mode); 127 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_path, mode);
119 if (handle) { 128 if (handle) {
120 cmd_buff[1] = 0; 129 cmd_buff[1] = 0;
121 cmd_buff[3] = handle; 130 cmd_buff[3] = handle;
122 } else { 131 } else {
123 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_string.c_str()); 132 ERROR_LOG(KERNEL, "failed to get a handle for file %s", file_path.DebugStr().c_str());
124 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily. 133 // TODO(Link Mauve): check for the actual error values, this one was just chosen arbitrarily.
125 cmd_buff[1] = -1; 134 cmd_buff[1] = -1;
126 } 135 }
@@ -205,17 +214,31 @@ void OpenDirectory(Service::Interface* self) {
205 DEBUG_LOG(KERNEL, "called"); 214 DEBUG_LOG(KERNEL, "called");
206} 215}
207 216
217/**
218 * FS_User::OpenArchive service function
219 * Inputs:
220 * 1 : Archive ID
221 * 2 : Archive low path type
222 * 3 : Archive low path size
223 * 4 : (LowPathSize << 14) | 2
224 * 5 : Archive low path
225 * Outputs:
226 * 1 : Result of function, 0 on success, otherwise error code
227 * 2 : Archive handle lower word (unused)
228 * 3 : Archive handle upper word (same as file handle)
229 */
208void OpenArchive(Service::Interface* self) { 230void OpenArchive(Service::Interface* self) {
209 u32* cmd_buff = Service::GetCommandBuffer(); 231 u32* cmd_buff = Service::GetCommandBuffer();
210 232
211 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]); 233 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]);
212 auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]); 234 auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
213 u32 archivename_size = cmd_buff[3]; 235 u32 archivename_size = cmd_buff[3];
214 u32 archivename_ptr = cmd_buff[5]; 236 u32 archivename_ptr = cmd_buff[5];
237 FileSys::Path archive_path(archivename_type, archivename_size, archivename_ptr);
215 238
216 DEBUG_LOG(KERNEL, "type=%d size=%d", archivename_type, archivename_size); 239 DEBUG_LOG(KERNEL, "archive_path=%s", archive_path.DebugStr().c_str());
217 240
218 if (archivename_type != FileSys::Empty) { 241 if (archive_path.GetType() != FileSys::Empty) {
219 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported"); 242 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
220 cmd_buff[1] = -1; 243 cmd_buff[1] = -1;
221 return; 244 return;