summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2014-11-17 22:26:54 -0500
committerGravatar bunnei2014-11-17 22:26:54 -0500
commitb66859714bda5968e36fed47a2ff8516bcfd2248 (patch)
treef1a933079afdfea73e76a187441733642489e2b0 /src
parentMerge pull request #201 from archshift/boss (diff)
parentArchive: Fixed to not destroy archive handle on close. (diff)
downloadyuzu-b66859714bda5968e36fed47a2ff8516bcfd2248.tar.gz
yuzu-b66859714bda5968e36fed47a2ff8516bcfd2248.tar.xz
yuzu-b66859714bda5968e36fed47a2ff8516bcfd2248.zip
Merge pull request #192 from bunnei/fs-fix-paths
FileSys: Updates backend code to use FileSys::Path and fixes binary path types.
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/archive.h35
-rw-r--r--src/core/file_sys/archive_romfs.cpp6
-rw-r--r--src/core/file_sys/archive_romfs.h6
-rw-r--r--src/core/file_sys/archive_sdmc.cpp12
-rw-r--r--src/core/file_sys/archive_sdmc.h6
-rw-r--r--src/core/file_sys/directory_sdmc.cpp4
-rw-r--r--src/core/file_sys/directory_sdmc.h2
-rw-r--r--src/core/file_sys/file_sdmc.cpp4
-rw-r--r--src/core/file_sys/file_sdmc.h2
-rw-r--r--src/core/hle/kernel/archive.cpp31
-rw-r--r--src/core/hle/kernel/archive.h6
-rw-r--r--src/core/hle/service/fs_user.cpp115
12 files changed, 146 insertions, 83 deletions
diff --git a/src/core/file_sys/archive.h b/src/core/file_sys/archive.h
index 38145eed8..dc2d2ced9 100644
--- a/src/core/file_sys/archive.h
+++ b/src/core/file_sys/archive.h
@@ -74,6 +74,35 @@ public:
74 return type; 74 return type;
75 } 75 }
76 76
77 /**
78 * Gets the string representation of the path for debugging
79 * @return String representation of the path for debugging
80 */
81 const std::string DebugStr() const {
82 switch (GetType()) {
83 case Invalid:
84 return "[Invalid]";
85 case Empty:
86 return "[Empty]";
87 case Binary:
88 {
89 std::stringstream res;
90 res << "[Binary: ";
91 for (unsigned byte : binary)
92 res << std::hex << std::setw(2) << std::setfill('0') << byte;
93 res << ']';
94 return res.str();
95 }
96 case Char:
97 return "[Char: " + AsString() + ']';
98 case Wchar:
99 return "[Wchar: " + AsString() + ']';
100 default:
101 ERROR_LOG(KERNEL, "LowPathType cannot be converted to string!");
102 return {};
103 }
104 }
105
77 const std::string AsString() const { 106 const std::string AsString() const {
78 switch (GetType()) { 107 switch (GetType()) {
79 case Char: 108 case Char:
@@ -153,21 +182,21 @@ public:
153 * @param mode Mode to open the file with 182 * @param mode Mode to open the file with
154 * @return Opened file, or nullptr 183 * @return Opened file, or nullptr
155 */ 184 */
156 virtual std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const = 0; 185 virtual std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const = 0;
157 186
158 /** 187 /**
159 * Create a directory specified by its path 188 * Create a directory specified by its path
160 * @param path Path relative to the archive 189 * @param path Path relative to the archive
161 * @return Whether the directory could be created 190 * @return Whether the directory could be created
162 */ 191 */
163 virtual bool CreateDirectory(const std::string& path) const = 0; 192 virtual bool CreateDirectory(const Path& path) const = 0;
164 193
165 /** 194 /**
166 * Open a directory specified by its path 195 * Open a directory specified by its path
167 * @param path Path relative to the archive 196 * @param path Path relative to the archive
168 * @return Opened directory, or nullptr 197 * @return Opened directory, or nullptr
169 */ 198 */
170 virtual std::unique_ptr<Directory> OpenDirectory(const std::string& path) const = 0; 199 virtual std::unique_ptr<Directory> OpenDirectory(const Path& path) const = 0;
171 200
172 /** 201 /**
173 * Read data from the archive 202 * Read data from the archive
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp
index cc759faa8..3ea60134f 100644
--- a/src/core/file_sys/archive_romfs.cpp
+++ b/src/core/file_sys/archive_romfs.cpp
@@ -29,7 +29,7 @@ Archive_RomFS::~Archive_RomFS() {
29 * @param mode Mode to open the file with 29 * @param mode Mode to open the file with
30 * @return Opened file, or nullptr 30 * @return Opened file, or nullptr
31 */ 31 */
32std::unique_ptr<File> Archive_RomFS::OpenFile(const std::string& path, const Mode mode) const { 32std::unique_ptr<File> Archive_RomFS::OpenFile(const Path& path, const Mode mode) const {
33 return std::unique_ptr<File>(new File_RomFS); 33 return std::unique_ptr<File>(new File_RomFS);
34} 34}
35 35
@@ -38,7 +38,7 @@ std::unique_ptr<File> Archive_RomFS::OpenFile(const std::string& path, const Mod
38 * @param path Path relative to the archive 38 * @param path Path relative to the archive
39 * @return Whether the directory could be created 39 * @return Whether the directory could be created
40 */ 40 */
41bool Archive_RomFS::CreateDirectory(const std::string& path) const { 41bool Archive_RomFS::CreateDirectory(const Path& path) const {
42 ERROR_LOG(FILESYS, "Attempted to create a directory in ROMFS."); 42 ERROR_LOG(FILESYS, "Attempted to create a directory in ROMFS.");
43 return false; 43 return false;
44}; 44};
@@ -48,7 +48,7 @@ bool Archive_RomFS::CreateDirectory(const std::string& path) const {
48 * @param path Path relative to the archive 48 * @param path Path relative to the archive
49 * @return Opened directory, or nullptr 49 * @return Opened directory, or nullptr
50 */ 50 */
51std::unique_ptr<Directory> Archive_RomFS::OpenDirectory(const std::string& path) const { 51std::unique_ptr<Directory> Archive_RomFS::OpenDirectory(const Path& path) const {
52 return std::unique_ptr<Directory>(new Directory_RomFS); 52 return std::unique_ptr<Directory>(new Directory_RomFS);
53} 53}
54 54
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h
index ae2344e82..8d5715734 100644
--- a/src/core/file_sys/archive_romfs.h
+++ b/src/core/file_sys/archive_romfs.h
@@ -34,21 +34,21 @@ public:
34 * @param mode Mode to open the file with 34 * @param mode Mode to open the file with
35 * @return Opened file, or nullptr 35 * @return Opened file, or nullptr
36 */ 36 */
37 std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const override; 37 std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override;
38 38
39 /** 39 /**
40 * Create a directory specified by its path 40 * Create a directory specified by its path
41 * @param path Path relative to the archive 41 * @param path Path relative to the archive
42 * @return Whether the directory could be created 42 * @return Whether the directory could be created
43 */ 43 */
44 bool CreateDirectory(const std::string& path) const override; 44 bool CreateDirectory(const Path& path) const override;
45 45
46 /** 46 /**
47 * Open a directory specified by its path 47 * Open a directory specified by its path
48 * @param path Path relative to the archive 48 * @param path Path relative to the archive
49 * @return Opened directory, or nullptr 49 * @return Opened directory, or nullptr
50 */ 50 */
51 std::unique_ptr<Directory> OpenDirectory(const std::string& path) const override; 51 std::unique_ptr<Directory> OpenDirectory(const Path& path) const override;
52 52
53 /** 53 /**
54 * Read data from the archive 54 * Read data from the archive
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp
index 66931e93e..ecdb7f211 100644
--- a/src/core/file_sys/archive_sdmc.cpp
+++ b/src/core/file_sys/archive_sdmc.cpp
@@ -49,8 +49,8 @@ bool Archive_SDMC::Initialize() {
49 * @param mode Mode to open the file with 49 * @param mode Mode to open the file with
50 * @return Opened file, or nullptr 50 * @return Opened file, or nullptr
51 */ 51 */
52std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode mode) const { 52std::unique_ptr<File> Archive_SDMC::OpenFile(const Path& path, const Mode mode) const {
53 DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.c_str(), mode); 53 DEBUG_LOG(FILESYS, "called path=%s mode=%d", path.DebugStr().c_str(), mode);
54 File_SDMC* file = new File_SDMC(this, path, mode); 54 File_SDMC* file = new File_SDMC(this, path, mode);
55 if (!file->Open()) 55 if (!file->Open())
56 return nullptr; 56 return nullptr;
@@ -62,8 +62,8 @@ std::unique_ptr<File> Archive_SDMC::OpenFile(const std::string& path, const Mode
62 * @param path Path relative to the archive 62 * @param path Path relative to the archive
63 * @return Whether the directory could be created 63 * @return Whether the directory could be created
64 */ 64 */
65bool Archive_SDMC::CreateDirectory(const std::string& path) const { 65bool Archive_SDMC::CreateDirectory(const Path& path) const {
66 return FileUtil::CreateDir(GetMountPoint() + path); 66 return FileUtil::CreateDir(GetMountPoint() + path.AsString());
67} 67}
68 68
69/** 69/**
@@ -71,8 +71,8 @@ bool Archive_SDMC::CreateDirectory(const std::string& path) const {
71 * @param path Path relative to the archive 71 * @param path Path relative to the archive
72 * @return Opened directory, or nullptr 72 * @return Opened directory, or nullptr
73 */ 73 */
74std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const std::string& path) const { 74std::unique_ptr<Directory> Archive_SDMC::OpenDirectory(const Path& path) const {
75 DEBUG_LOG(FILESYS, "called path=%s", path.c_str()); 75 DEBUG_LOG(FILESYS, "called path=%s", path.DebugStr().c_str());
76 Directory_SDMC* directory = new Directory_SDMC(this, path); 76 Directory_SDMC* directory = new Directory_SDMC(this, path);
77 return std::unique_ptr<Directory>(directory); 77 return std::unique_ptr<Directory>(directory);
78} 78}
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h
index 0e059b635..1f621b3f7 100644
--- a/src/core/file_sys/archive_sdmc.h
+++ b/src/core/file_sys/archive_sdmc.h
@@ -38,21 +38,21 @@ public:
38 * @param mode Mode to open the file with 38 * @param mode Mode to open the file with
39 * @return Opened file, or nullptr 39 * @return Opened file, or nullptr
40 */ 40 */
41 std::unique_ptr<File> OpenFile(const std::string& path, const Mode mode) const override; 41 std::unique_ptr<File> OpenFile(const Path& path, const Mode mode) const override;
42 42
43 /** 43 /**
44 * Create a directory specified by its path 44 * Create a directory specified by its path
45 * @param path Path relative to the archive 45 * @param path Path relative to the archive
46 * @return Whether the directory could be created 46 * @return Whether the directory could be created
47 */ 47 */
48 bool CreateDirectory(const std::string& path) const override; 48 bool CreateDirectory(const Path& path) const override;
49 49
50 /** 50 /**
51 * Open a directory specified by its path 51 * Open a directory specified by its path
52 * @param path Path relative to the archive 52 * @param path Path relative to the archive
53 * @return Opened directory, or nullptr 53 * @return Opened directory, or nullptr
54 */ 54 */
55 std::unique_ptr<Directory> OpenDirectory(const std::string& path) const override; 55 std::unique_ptr<Directory> OpenDirectory(const Path& path) const override;
56 56
57 /** 57 /**
58 * Read data from the archive 58 * Read data from the archive
diff --git a/src/core/file_sys/directory_sdmc.cpp b/src/core/file_sys/directory_sdmc.cpp
index fd558def9..923ca6862 100644
--- a/src/core/file_sys/directory_sdmc.cpp
+++ b/src/core/file_sys/directory_sdmc.cpp
@@ -15,11 +15,11 @@
15 15
16namespace FileSys { 16namespace FileSys {
17 17
18Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const std::string& path) { 18Directory_SDMC::Directory_SDMC(const Archive_SDMC* archive, const Path& path) {
19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass 19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
20 // the root directory we set while opening the archive. 20 // the root directory we set while opening the archive.
21 // For example, opening /../../usr/bin can give the emulated program your installed programs. 21 // For example, opening /../../usr/bin can give the emulated program your installed programs.
22 std::string absolute_path = archive->GetMountPoint() + path; 22 std::string absolute_path = archive->GetMountPoint() + path.AsString();
23 FileUtil::ScanDirectoryTree(absolute_path, directory); 23 FileUtil::ScanDirectoryTree(absolute_path, directory);
24 children_iterator = directory.children.begin(); 24 children_iterator = directory.children.begin();
25} 25}
diff --git a/src/core/file_sys/directory_sdmc.h b/src/core/file_sys/directory_sdmc.h
index cb8d32fda..4520d0401 100644
--- a/src/core/file_sys/directory_sdmc.h
+++ b/src/core/file_sys/directory_sdmc.h
@@ -19,7 +19,7 @@ namespace FileSys {
19class Directory_SDMC final : public Directory { 19class Directory_SDMC final : public Directory {
20public: 20public:
21 Directory_SDMC(); 21 Directory_SDMC();
22 Directory_SDMC(const Archive_SDMC* archive, const std::string& path); 22 Directory_SDMC(const Archive_SDMC* archive, const Path& path);
23 ~Directory_SDMC() override; 23 ~Directory_SDMC() override;
24 24
25 /** 25 /**
diff --git a/src/core/file_sys/file_sdmc.cpp b/src/core/file_sys/file_sdmc.cpp
index 26204392c..a4b90670a 100644
--- a/src/core/file_sys/file_sdmc.cpp
+++ b/src/core/file_sys/file_sdmc.cpp
@@ -15,11 +15,11 @@
15 15
16namespace FileSys { 16namespace FileSys {
17 17
18File_SDMC::File_SDMC(const Archive_SDMC* archive, const std::string& path, const Mode mode) { 18File_SDMC::File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode) {
19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass 19 // TODO(Link Mauve): normalize path into an absolute path without "..", it can currently bypass
20 // the root directory we set while opening the archive. 20 // the root directory we set while opening the archive.
21 // For example, opening /../../etc/passwd can give the emulated program your users list. 21 // For example, opening /../../etc/passwd can give the emulated program your users list.
22 this->path = archive->GetMountPoint() + path; 22 this->path = archive->GetMountPoint() + path.AsString();
23 this->mode.hex = mode.hex; 23 this->mode.hex = mode.hex;
24} 24}
25 25
diff --git a/src/core/file_sys/file_sdmc.h b/src/core/file_sys/file_sdmc.h
index df032f7c0..80b445968 100644
--- a/src/core/file_sys/file_sdmc.h
+++ b/src/core/file_sys/file_sdmc.h
@@ -19,7 +19,7 @@ namespace FileSys {
19class File_SDMC final : public File { 19class File_SDMC final : public File {
20public: 20public:
21 File_SDMC(); 21 File_SDMC();
22 File_SDMC(const Archive_SDMC* archive, const std::string& path, const Mode mode); 22 File_SDMC(const Archive_SDMC* archive, const Path& path, const Mode mode);
23 ~File_SDMC() override; 23 ~File_SDMC() override;
24 24
25 /** 25 /**
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
index 764082d71..8f1c95d0f 100644
--- a/src/core/hle/kernel/archive.cpp
+++ b/src/core/hle/kernel/archive.cpp
@@ -99,7 +99,6 @@ public:
99 case FileCommand::Close: 99 case FileCommand::Close:
100 { 100 {
101 DEBUG_LOG(KERNEL, "Close %s %s", GetTypeName().c_str(), GetName().c_str()); 101 DEBUG_LOG(KERNEL, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
102 Kernel::g_object_pool.Destroy<Archive>(GetHandle());
103 CloseArchive(backend->GetIdCode()); 102 CloseArchive(backend->GetIdCode());
104 break; 103 break;
105 } 104 }
@@ -129,12 +128,12 @@ public:
129class File : public Object { 128class File : public Object {
130public: 129public:
131 std::string GetTypeName() const override { return "File"; } 130 std::string GetTypeName() const override { return "File"; }
132 std::string GetName() const override { return path; } 131 std::string GetName() const override { return path.DebugStr(); }
133 132
134 static Kernel::HandleType GetStaticHandleType() { return HandleType::File; } 133 static Kernel::HandleType GetStaticHandleType() { return HandleType::File; }
135 Kernel::HandleType GetHandleType() const override { return HandleType::File; } 134 Kernel::HandleType GetHandleType() const override { return HandleType::File; }
136 135
137 std::string path; ///< Path of the file 136 FileSys::Path path; ///< Path of the file
138 std::unique_ptr<FileSys::File> backend; ///< File backend interface 137 std::unique_ptr<FileSys::File> backend; ///< File backend interface
139 138
140 /** 139 /**
@@ -221,12 +220,12 @@ public:
221class Directory : public Object { 220class Directory : public Object {
222public: 221public:
223 std::string GetTypeName() const override { return "Directory"; } 222 std::string GetTypeName() const override { return "Directory"; }
224 std::string GetName() const override { return path; } 223 std::string GetName() const override { return path.DebugStr(); }
225 224
226 static Kernel::HandleType GetStaticHandleType() { return HandleType::Directory; } 225 static Kernel::HandleType GetStaticHandleType() { return HandleType::Directory; }
227 Kernel::HandleType GetHandleType() const override { return HandleType::Directory; } 226 Kernel::HandleType GetHandleType() const override { return HandleType::Directory; }
228 227
229 std::string path; ///< Path of the directory 228 FileSys::Path path; ///< Path of the directory
230 std::unique_ptr<FileSys::Directory> backend; ///< File backend interface 229 std::unique_ptr<FileSys::Directory> backend; ///< File backend interface
231 230
232 /** 231 /**
@@ -304,8 +303,9 @@ Handle OpenArchive(FileSys::Archive::IdCode id_code) {
304 * @return Result of operation, 0 on success, otherwise error code 303 * @return Result of operation, 0 on success, otherwise error code
305 */ 304 */
306Result CloseArchive(FileSys::Archive::IdCode id_code) { 305Result CloseArchive(FileSys::Archive::IdCode id_code) {
307 if (1 != g_archive_map.erase(id_code)) { 306 auto itr = g_archive_map.find(id_code);
308 ERROR_LOG(KERNEL, "Cannot close archive %d", (int) id_code); 307 if (itr == g_archive_map.end()) {
308 ERROR_LOG(KERNEL, "Cannot close archive %d, does not exist!", (int)id_code);
309 return -1; 309 return -1;
310 } 310 }
311 311
@@ -366,7 +366,18 @@ Handle CreateArchive(FileSys::Archive* backend, const std::string& name) {
366 * @param mode Mode under which to open the File 366 * @param mode Mode under which to open the File
367 * @return Opened File object 367 * @return Opened File object
368 */ 368 */
369Handle OpenFileFromArchive(Handle archive_handle, const std::string& 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
@@ -386,7 +397,7 @@ Handle OpenFileFromArchive(Handle archive_handle, const std::string& path, const
386 * @param path Path to the Directory inside of the Archive 397 * @param path Path to the Directory inside of the Archive
387 * @return Opened Directory object 398 * @return Opened Directory object
388 */ 399 */
389Result CreateDirectoryFromArchive(Handle archive_handle, const std::string& path) { 400Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
390 Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle); 401 Archive* archive = Kernel::g_object_pool.GetFast<Archive>(archive_handle);
391 if (archive == nullptr) 402 if (archive == nullptr)
392 return -1; 403 return -1;
@@ -401,7 +412,7 @@ Result CreateDirectoryFromArchive(Handle archive_handle, const std::string& path
401 * @param path Path to the Directory inside of the Archive 412 * @param path Path to the Directory inside of the Archive
402 * @return Opened Directory object 413 * @return Opened Directory object
403 */ 414 */
404Handle OpenDirectoryFromArchive(Handle archive_handle, const std::string& path) { 415Handle OpenDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path) {
405 Directory* directory = new Directory; 416 Directory* directory = new Directory;
406 Handle handle = Kernel::g_object_pool.Create(directory); 417 Handle handle = Kernel::g_object_pool.Create(directory);
407 418
diff --git a/src/core/hle/kernel/archive.h b/src/core/hle/kernel/archive.h
index 0230996b6..9c6015506 100644
--- a/src/core/hle/kernel/archive.h
+++ b/src/core/hle/kernel/archive.h
@@ -43,7 +43,7 @@ Handle CreateArchive(FileSys::Archive* backend, const std::string& name);
43 * @param mode Mode under which to open the File 43 * @param mode Mode under which to open the File
44 * @return Opened File object 44 * @return Opened File object
45 */ 45 */
46Handle OpenFileFromArchive(Handle archive_handle, const std::string& name, const FileSys::Mode mode); 46Handle OpenFileFromArchive(Handle archive_handle, const FileSys::Path& path, const FileSys::Mode mode);
47 47
48/** 48/**
49 * Create a Directory from an Archive 49 * Create a Directory from an Archive
@@ -51,7 +51,7 @@ Handle OpenFileFromArchive(Handle archive_handle, const std::string& name, const
51 * @param path Path to the Directory inside of the Archive 51 * @param path Path to the Directory inside of the Archive
52 * @return Whether creation of directory succeeded 52 * @return Whether creation of directory succeeded
53 */ 53 */
54Result CreateDirectoryFromArchive(Handle archive_handle, const std::string& name); 54Result CreateDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
55 55
56/** 56/**
57 * Open a Directory from an Archive 57 * Open a Directory from an Archive
@@ -59,7 +59,7 @@ Result CreateDirectoryFromArchive(Handle archive_handle, const std::string& name
59 * @param path Path to the Directory inside of the Archive 59 * @param path Path to the Directory inside of the Archive
60 * @return Opened Directory object 60 * @return Opened Directory object
61 */ 61 */
62Handle OpenDirectoryFromArchive(Handle archive_handle, const std::string& name); 62Handle OpenDirectoryFromArchive(Handle archive_handle, const FileSys::Path& path);
63 63
64/// Initialize archives 64/// Initialize archives
65void ArchiveInit(); 65void ArchiveInit();
diff --git a/src/core/hle/service/fs_user.cpp b/src/core/hle/service/fs_user.cpp
index 9dc83291d..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_string, 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); 127 Handle handle = Kernel::OpenFileFromArchive(archive_handle, file_path, mode);
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_string, 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 }
@@ -163,7 +172,7 @@ void CreateDirectory(Service::Interface* self) {
163 172
164 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); 173 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
165 174
166 cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_string); 175 cmd_buff[1] = Kernel::CreateDirectoryFromArchive(archive_handle, dir_path);
167 176
168 DEBUG_LOG(KERNEL, "called"); 177 DEBUG_LOG(KERNEL, "called");
169} 178}
@@ -192,7 +201,7 @@ void OpenDirectory(Service::Interface* self) {
192 201
193 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str()); 202 DEBUG_LOG(KERNEL, "type=%d size=%d data=%s", dirname_type, dirname_size, dir_string.c_str());
194 203
195 Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_string); 204 Handle handle = Kernel::OpenDirectoryFromArchive(archive_handle, dir_path);
196 if (handle) { 205 if (handle) {
197 cmd_buff[1] = 0; 206 cmd_buff[1] = 0;
198 cmd_buff[3] = handle; 207 cmd_buff[3] = handle;
@@ -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;