summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/file_sys/archive.h99
-rw-r--r--src/core/hle/service/fs_user.cpp149
-rw-r--r--src/core/hle/service/fs_user.h29
3 files changed, 139 insertions, 138 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
index aeabf09ac..38145eed8 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -7,11 +7,13 @@
7#include <memory> 7#include <memory>
8 8
9#include "common/common_types.h" 9#include "common/common_types.h"
10#include "common/string_util.h"
10#include "common/bit_field.h" 11#include "common/bit_field.h"
11 12
12#include "core/file_sys/file.h" 13#include "core/file_sys/file.h"
13#include "core/file_sys/directory.h" 14#include "core/file_sys/directory.h"
14 15
16#include "core/mem_map.h"
15#include "core/hle/kernel/kernel.h" 17#include "core/hle/kernel/kernel.h"
16 18
17//////////////////////////////////////////////////////////////////////////////////////////////////// 19////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -19,6 +21,15 @@
19 21
20namespace FileSys { 22namespace FileSys {
21 23
24// Path string type
25enum LowPathType : u32 {
26 Invalid = 0,
27 Empty = 1,
28 Binary = 2,
29 Char = 3,
30 Wchar = 4
31};
32
22union Mode { 33union Mode {
23 u32 hex; 34 u32 hex;
24 BitField<0, 1, u32> read_flag; 35 BitField<0, 1, u32> read_flag;
@@ -26,6 +37,94 @@ union Mode {
26 BitField<2, 1, u32> create_flag; 37 BitField<2, 1, u32> create_flag;
27}; 38};
28 39
40class Path {
41public:
42
43 Path():
44 type(Invalid)
45 {
46 }
47
48 Path(LowPathType type, u32 size, u32 pointer):
49 type(type)
50 {
51 switch (type) {
52 case Binary:
53 {
54 u8* data = Memory::GetPointer(pointer);
55 binary = std::vector<u8>(data, data + size);
56 break;
57 }
58 case Char:
59 {
60 const char* data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
61 string = std::string(data, size - 1); // Data is always null-terminated.
62 break;
63 }
64 case Wchar:
65 {
66 const char16_t* data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer));
67 u16str = std::u16string(data, size/2 - 1); // Data is always null-terminated.
68 break;
69 }
70 }
71 }
72
73 LowPathType GetType() const {
74 return type;
75 }
76
77 const std::string AsString() const {
78 switch (GetType()) {
79 case Char:
80 return string;
81 case Wchar:
82 return Common::UTF16ToUTF8(u16str);
83 case Empty:
84 return {};
85 default:
86 ERROR_LOG(KERNEL, "LowPathType cannot be converted to string!");
87 return {};
88 }
89 }
90
91 const std::u16string AsU16Str() const {
92 switch (GetType()) {
93 case Char:
94 return Common::UTF8ToUTF16(string);
95 case Wchar:
96 return u16str;
97 case Empty:
98 return {};
99 default:
100 ERROR_LOG(KERNEL, "LowPathType cannot be converted to u16string!");
101 return {};
102 }
103 }
104
105 const std::vector<u8> AsBinary() const {
106 switch (GetType()) {
107 case Binary:
108 return binary;
109 case Char:
110 return std::vector<u8>(string.begin(), string.end());
111 case Wchar:
112 return std::vector<u8>(u16str.begin(), u16str.end());
113 case Empty:
114 return {};
115 default:
116 ERROR_LOG(KERNEL, "LowPathType cannot be converted to binary!");
117 return {};
118 }
119 }
120
121private:
122 LowPathType type;
123 std::vector<u8> binary;
124 std::string string;
125 std::u16string u16str;
126};
127
29class Archive : NonCopyable { 128class Archive : NonCopyable {
30public: 129public:
31 /// Supported archive types 130 /// Supported archive types
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index 8093254ee..9dc83291d 100644
--- a/src/core/hle/service/fs_user.cpp
+++ b/src/core/hle/service/fs_user.cpp
@@ -14,75 +14,6 @@
14 14
15namespace FS_User { 15namespace FS_User {
16 16
17FS_Path::FS_Path(LowPathType type, u32 size, u32 pointer):
18 type(type)
19{
20 switch (type) {
21 case Binary:
22 {
23 auto data = Memory::GetPointer(pointer);
24 binary = std::vector<u8>(data, data + size);
25 break;
26 }
27 case Char:
28 {
29 auto data = reinterpret_cast<const char*>(Memory::GetPointer(pointer));
30 string = std::string(data, size - 1);
31 }
32 case Wchar:
33 {
34 auto data = reinterpret_cast<const char16_t*>(Memory::GetPointer(pointer));
35 u16str = std::u16string(data, size/2 - 1);
36 }
37 }
38}
39
40FS_Path::LowPathType FS_Path::GetType() const {
41 return type;
42}
43
44const std::vector<u8>& FS_Path::GetBinary() const {
45 return binary;
46}
47
48const std::string& FS_Path::GetString() const {
49 _dbg_assert_msg_(KERNEL, type == Char, "LowPathType is not Char!");
50 return string;
51}
52
53const std::u16string& FS_Path::GetU16Str() const {
54 _dbg_assert_msg_(KERNEL, type == Wchar, "LowPathType is not Wchar!");
55 return u16str;
56}
57
58std::string FS_Path::AsString() {
59 switch (GetType()) {
60 case FS_Path::Char:
61 return GetString();
62 case FS_Path::Empty:
63 return {};
64 case FS_Path::Wchar:
65 {
66 auto str16 = GetU16Str();
67 return Common::UTF16ToUTF8(std::wstring(str16.cbegin(), str16.cend()));
68 }
69 }
70}
71
72std::u16string FS_Path::AsU16Str() {
73 switch (GetType()) {
74 case FS_Path::Wchar:
75 return GetU16Str();
76 case FS_Path::Empty:
77 return {};
78 case FS_Path::Char:
79 {
80 auto str = GetString();
81 return std::u16string(str.cbegin(), str.cend());
82 }
83 }
84}
85
86// We currently return 0 for success and -1 for failure in cmd_buff[1]. -1 was chosen because it 17// We currently return 0 for success and -1 for failure in cmd_buff[1]. -1 was chosen because it
87// puts all the sections of the http://3dbrew.org/wiki/Error_codes to something non-zero, to make 18// puts all the sections of the http://3dbrew.org/wiki/Error_codes to something non-zero, to make
88// sure we don't mislead the application into thinking something worked. 19// sure we don't mislead the application into thinking something worked.
@@ -103,22 +34,22 @@ void OpenFile(Service::Interface* self) {
103 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to 34 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to
104 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case. 35 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
105 Handle archive_handle = static_cast<Handle>(cmd_buff[3]); 36 Handle archive_handle = static_cast<Handle>(cmd_buff[3]);
106 auto filename_type = static_cast<FS_Path::LowPathType>(cmd_buff[4]); 37 auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
107 u32 filename_size = cmd_buff[5]; 38 u32 filename_size = cmd_buff[5];
108 FileSys::Mode mode; mode.hex = cmd_buff[6]; 39 FileSys::Mode mode; mode.hex = cmd_buff[6];
109 u32 attributes = cmd_buff[7]; // TODO(Link Mauve): do something with those attributes. 40 u32 attributes = cmd_buff[7]; // TODO(Link Mauve): do something with those attributes.
110 u32 filename_ptr = cmd_buff[9]; 41 u32 filename_ptr = cmd_buff[9];
111 42
112 FS_Path file_path(filename_type, filename_size, filename_ptr); 43 FileSys::Path file_path(filename_type, filename_size, filename_ptr);
113 std::string file_string; 44 std::string file_string;
114 switch (file_path.GetType()) { 45 switch (file_path.GetType()) {
115 case FS_Path::Char: 46 case FileSys::Char:
116 case FS_Path::Wchar: 47 case FileSys::Wchar:
117 file_string = file_path.AsString(); 48 file_string = file_path.AsString();
118 break; 49 break;
119 default: 50 default:
120 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead"); 51 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead");
121 return; 52 return;
122 } 53 }
123 54
124 DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s", 55 DEBUG_LOG(KERNEL, "type=%d size=%d mode=%d attrs=%d data=%s",
@@ -141,9 +72,9 @@ void OpenFileDirectly(Service::Interface* self) {
141 u32* cmd_buff = Service::GetCommandBuffer(); 72 u32* cmd_buff = Service::GetCommandBuffer();
142 73
143 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]); 74 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[2]);
144 auto archivename_type = static_cast<FS_Path::LowPathType>(cmd_buff[3]); 75 auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
145 u32 archivename_size = cmd_buff[4]; 76 u32 archivename_size = cmd_buff[4];
146 auto filename_type = static_cast<FS_Path::LowPathType>(cmd_buff[5]); 77 auto filename_type = static_cast<FileSys::LowPathType>(cmd_buff[5]);
147 u32 filename_size = cmd_buff[6]; 78 u32 filename_size = cmd_buff[6];
148 FileSys::Mode mode; mode.hex = cmd_buff[7]; 79 FileSys::Mode mode; mode.hex = cmd_buff[7];
149 u32 attributes = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes. 80 u32 attributes = cmd_buff[8]; // TODO(Link Mauve): do something with those attributes.
@@ -153,7 +84,7 @@ void OpenFileDirectly(Service::Interface* self) {
153 DEBUG_LOG(KERNEL, "archive_type=%d archive_size=%d file_type=%d file_size=%d file_mode=%d file_attrs=%d", 84 DEBUG_LOG(KERNEL, "archive_type=%d archive_size=%d file_type=%d file_size=%d file_mode=%d file_attrs=%d",
154 archivename_type, archivename_size, filename_type, filename_size, mode, attributes); 85 archivename_type, archivename_size, filename_type, filename_size, mode, attributes);
155 86
156 if (archivename_type != FS_Path::Empty) { 87 if (archivename_type != FileSys::Empty) {
157 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported"); 88 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
158 cmd_buff[1] = -1; 89 cmd_buff[1] = -1;
159 return; 90 return;
@@ -172,16 +103,16 @@ void OpenFileDirectly(Service::Interface* self) {
172 return; 103 return;
173 } 104 }
174 105
175 FS_Path file_path(filename_type, filename_size, filename_ptr); 106 FileSys::Path file_path(filename_type, filename_size, filename_ptr);
176 std::string file_string; 107 std::string file_string;
177 switch (file_path.GetType()) { 108 switch (file_path.GetType()) {
178 case FS_Path::Char: 109 case FileSys::Char:
179 case FS_Path::Wchar: 110 case FileSys::Wchar:
180 file_string = file_path.AsString(); 111 file_string = file_path.AsString();
181 break; 112 break;
182 default: 113 default:
183 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead"); 114 WARN_LOG(KERNEL, "file LowPath type is currently unsupported; returning archive handle instead");
184 return; 115 return;
185 } 116 }
186 117
187 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode); 118 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_string, mode);
@@ -214,20 +145,20 @@ void CreateDirectory(Service::Interface* self) {
214 // TODO: cmd_buff[2], aka archive handle lower word, isn't used according to 145 // TODO: cmd_buff[2], aka archive handle lower word, isn't used according to
215 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case. 146 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
216 Handle archive_handle = static_cast<Handle>(cmd_buff[3]); 147 Handle archive_handle = static_cast<Handle>(cmd_buff[3]);
217 auto dirname_type = static_cast<FS_Path::LowPathType>(cmd_buff[4]); 148 auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[4]);
218 u32 dirname_size = cmd_buff[5]; 149 u32 dirname_size = cmd_buff[5];
219 u32 dirname_ptr = cmd_buff[8]; 150 u32 dirname_ptr = cmd_buff[8];
220 151
221 FS_Path dir_path(dirname_type, dirname_size, dirname_ptr); 152 FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
222 std::string dir_string; 153 std::string dir_string;
223 switch (dir_path.GetType()) { 154 switch (dir_path.GetType()) {
224 case FS_Path::Char: 155 case FileSys::Char:
225 case FS_Path::Wchar: 156 case FileSys::Wchar:
226 dir_string = dir_path.AsString(); 157 dir_string = dir_path.AsString();
227 break; 158 break;
228 default: 159 default:
229 cmd_buff[1] = -1; 160 cmd_buff[1] = -1;
230 return; 161 return;
231 } 162 }
232 163
233 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); 164 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
@@ -243,20 +174,20 @@ void OpenDirectory(Service::Interface* self) {
243 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to 174 // TODO(Link Mauve): cmd_buff[2], aka archive handle lower word, isn't used according to
244 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case. 175 // 3dmoo's or ctrulib's implementations. Triple check if it's really the case.
245 Handle archive_handle = static_cast<Handle>(cmd_buff[2]); 176 Handle archive_handle = static_cast<Handle>(cmd_buff[2]);
246 auto dirname_type = static_cast<FS_Path::LowPathType>(cmd_buff[3]); 177 auto dirname_type = static_cast<FileSys::LowPathType>(cmd_buff[3]);
247 u32 dirname_size = cmd_buff[4]; 178 u32 dirname_size = cmd_buff[4];
248 u32 dirname_ptr = cmd_buff[6]; 179 u32 dirname_ptr = cmd_buff[6];
249 180
250 FS_Path dir_path(dirname_type, dirname_size, dirname_ptr); 181 FileSys::Path dir_path(dirname_type, dirname_size, dirname_ptr);
251 std::string dir_string; 182 std::string dir_string;
252 switch (dir_path.GetType()) { 183 switch (dir_path.GetType()) {
253 case FS_Path::Char: 184 case FileSys::Char:
254 case FS_Path::Wchar: 185 case FileSys::Wchar:
255 dir_string = dir_path.AsString(); 186 dir_string = dir_path.AsString();
256 break; 187 break;
257 default: 188 default:
258 cmd_buff[1] = -1; 189 cmd_buff[1] = -1;
259 return; 190 return;
260 } 191 }
261 192
262 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); 193 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
@@ -278,13 +209,13 @@ void OpenArchive(Service::Interface* self) {
278 u32* cmd_buff = Service::GetCommandBuffer(); 209 u32* cmd_buff = Service::GetCommandBuffer();
279 210
280 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]); 211 auto archive_id = static_cast<FileSys::Archive::IdCode>(cmd_buff[1]);
281 auto archivename_type = static_cast<FS_Path::LowPathType>(cmd_buff[2]); 212 auto archivename_type = static_cast<FileSys::LowPathType>(cmd_buff[2]);
282 u32 archivename_size = cmd_buff[3]; 213 u32 archivename_size = cmd_buff[3];
283 u32 archivename_ptr = cmd_buff[5]; 214 u32 archivename_ptr = cmd_buff[5];
284 215
285 DEBUG_LOG(KERNEL, "type=%d size=%d", archivename_type, archivename_size); 216 DEBUG_LOG(KERNEL, "type=%d size=%d", archivename_type, archivename_size);
286 217
287 if (archivename_type != FS_Path::Empty) { 218 if (archivename_type != FileSys::Empty) {
288 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported"); 219 ERROR_LOG(KERNEL, "archive LowPath type other than empty is currently unsupported");
289 cmd_buff[1] = -1; 220 cmd_buff[1] = -1;
290 return; 221 return;
diff --git a/src/core/hle/service/fs_user.h b/src/core/hle/service/fs_user.h
index 44f89ef4a..005382540 100644
--- a/src/core/hle/service/fs_user.h
+++ b/src/core/hle/service/fs_user.h
@@ -11,35 +11,6 @@
11 11
12namespace FS_User { 12namespace FS_User {
13 13
14class FS_Path {
15public:
16 // Command to access archive file
17 enum LowPathType : u32 {
18 Invalid = 0,
19 Empty = 1,
20 Binary = 2,
21 Char = 3,
22 Wchar = 4
23 };
24
25 FS_Path(LowPathType type, u32 size, u32 pointer);
26
27 LowPathType GetType() const;
28
29 const std::vector<u8>& GetBinary() const;
30 const std::string& GetString() const;
31 const std::u16string& GetU16Str() const;
32
33 std::string AsString();
34 std::u16string AsU16Str();
35
36private:
37 LowPathType type;
38 std::vector<u8> binary;
39 std::string string;
40 std::u16string u16str;
41};
42
43/// Interface to "fs:USER" service 14/// Interface to "fs:USER" service
44class Interface : public Service::Interface { 15class Interface : public Service::Interface {
45public: 16public: