summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2018-03-21 09:36:26 -0500
committerGravatar Subv2018-03-21 09:55:59 -0500
commiteff3f60b73343365ad65638f55591965df6f7e25 (patch)
tree9b2d61666ff0f516b06d3a6cfda144afb5fb72e7 /src
parentFS: Implemented IFileSystem's OpenDirectory function. (diff)
downloadyuzu-eff3f60b73343365ad65638f55591965df6f7e25.tar.gz
yuzu-eff3f60b73343365ad65638f55591965df6f7e25.tar.xz
yuzu-eff3f60b73343365ad65638f55591965df6f7e25.zip
FS: Implemented IFileSystem::CreateDirectory.
Diffstat (limited to 'src')
-rw-r--r--src/core/file_sys/disk_filesystem.cpp13
-rw-r--r--src/core/file_sys/disk_filesystem.h2
-rw-r--r--src/core/file_sys/filesystem.h2
-rw-r--r--src/core/file_sys/romfs_filesystem.cpp2
-rw-r--r--src/core/file_sys/romfs_filesystem.h2
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp15
6 files changed, 29 insertions, 7 deletions
diff --git a/src/core/file_sys/disk_filesystem.cpp b/src/core/file_sys/disk_filesystem.cpp
index f620b7961..9383bf856 100644
--- a/src/core/file_sys/disk_filesystem.cpp
+++ b/src/core/file_sys/disk_filesystem.cpp
@@ -18,7 +18,7 @@ std::string Disk_FileSystem::GetName() const {
18ResultVal<std::unique_ptr<StorageBackend>> Disk_FileSystem::OpenFile(const std::string& path, 18ResultVal<std::unique_ptr<StorageBackend>> Disk_FileSystem::OpenFile(const std::string& path,
19 Mode mode) const { 19 Mode mode) const {
20 20
21 std::string mode_str = ""; 21 std::string mode_str;
22 u32 mode_flags = static_cast<u32>(mode); 22 u32 mode_flags = static_cast<u32>(mode);
23 23
24 // Calculate the correct open mode for the file. 24 // Calculate the correct open mode for the file.
@@ -95,8 +95,15 @@ ResultCode Disk_FileSystem::CreateFile(const std::string& path, u64 size) const
95 return ResultCode(-1); 95 return ResultCode(-1);
96} 96}
97 97
98ResultCode Disk_FileSystem::CreateDirectory(const Path& path) const { 98ResultCode Disk_FileSystem::CreateDirectory(const std::string& path) const {
99 LOG_WARNING(Service_FS, "(STUBBED) called"); 99 // TODO(Subv): Perform path validation to prevent escaping the emulator sandbox.
100 std::string full_path = base_directory + path;
101
102 if (FileUtil::CreateDir(full_path)) {
103 return RESULT_SUCCESS;
104 }
105
106 LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating %s", full_path.c_str());
100 // TODO(wwylele): Use correct error code 107 // TODO(wwylele): Use correct error code
101 return ResultCode(-1); 108 return ResultCode(-1);
102} 109}
diff --git a/src/core/file_sys/disk_filesystem.h b/src/core/file_sys/disk_filesystem.h
index 72a0afedf..742d7db1a 100644
--- a/src/core/file_sys/disk_filesystem.h
+++ b/src/core/file_sys/disk_filesystem.h
@@ -30,7 +30,7 @@ public:
30 ResultCode DeleteDirectory(const Path& path) const override; 30 ResultCode DeleteDirectory(const Path& path) const override;
31 ResultCode DeleteDirectoryRecursively(const Path& path) const override; 31 ResultCode DeleteDirectoryRecursively(const Path& path) const override;
32 ResultCode CreateFile(const std::string& path, u64 size) const override; 32 ResultCode CreateFile(const std::string& path, u64 size) const override;
33 ResultCode CreateDirectory(const Path& path) const override; 33 ResultCode CreateDirectory(const std::string& path) const override;
34 ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; 34 ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
35 ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory( 35 ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(
36 const std::string& path) const override; 36 const std::string& path) const override;
diff --git a/src/core/file_sys/filesystem.h b/src/core/file_sys/filesystem.h
index 22ad24143..399427ca2 100644
--- a/src/core/file_sys/filesystem.h
+++ b/src/core/file_sys/filesystem.h
@@ -104,7 +104,7 @@ public:
104 * @param path Path relative to the archive 104 * @param path Path relative to the archive
105 * @return Result of the operation 105 * @return Result of the operation
106 */ 106 */
107 virtual ResultCode CreateDirectory(const Path& path) const = 0; 107 virtual ResultCode CreateDirectory(const std::string& path) const = 0;
108 108
109 /** 109 /**
110 * Delete a directory specified by its path 110 * Delete a directory specified by its path
diff --git a/src/core/file_sys/romfs_filesystem.cpp b/src/core/file_sys/romfs_filesystem.cpp
index 169f0d4f6..0c6cc3157 100644
--- a/src/core/file_sys/romfs_filesystem.cpp
+++ b/src/core/file_sys/romfs_filesystem.cpp
@@ -55,7 +55,7 @@ ResultCode RomFS_FileSystem::CreateFile(const std::string& path, u64 size) const
55 return ResultCode(-1); 55 return ResultCode(-1);
56} 56}
57 57
58ResultCode RomFS_FileSystem::CreateDirectory(const Path& path) const { 58ResultCode RomFS_FileSystem::CreateDirectory(const std::string& path) const {
59 LOG_CRITICAL(Service_FS, "Attempted to create a directory in an ROMFS archive (%s).", 59 LOG_CRITICAL(Service_FS, "Attempted to create a directory in an ROMFS archive (%s).",
60 GetName().c_str()); 60 GetName().c_str());
61 // TODO(wwylele): Use correct error code 61 // TODO(wwylele): Use correct error code
diff --git a/src/core/file_sys/romfs_filesystem.h b/src/core/file_sys/romfs_filesystem.h
index ee41c2d02..3f94c04d0 100644
--- a/src/core/file_sys/romfs_filesystem.h
+++ b/src/core/file_sys/romfs_filesystem.h
@@ -36,7 +36,7 @@ public:
36 ResultCode DeleteDirectory(const Path& path) const override; 36 ResultCode DeleteDirectory(const Path& path) const override;
37 ResultCode DeleteDirectoryRecursively(const Path& path) const override; 37 ResultCode DeleteDirectoryRecursively(const Path& path) const override;
38 ResultCode CreateFile(const std::string& path, u64 size) const override; 38 ResultCode CreateFile(const std::string& path, u64 size) const override;
39 ResultCode CreateDirectory(const Path& path) const override; 39 ResultCode CreateDirectory(const std::string& path) const override;
40 ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; 40 ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override;
41 ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory( 41 ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(
42 const std::string& path) const override; 42 const std::string& path) const override;
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 6f539316e..cbb7552d9 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -208,6 +208,7 @@ public:
208 : ServiceFramework("IFileSystem"), backend(std::move(backend)) { 208 : ServiceFramework("IFileSystem"), backend(std::move(backend)) {
209 static const FunctionInfo functions[] = { 209 static const FunctionInfo functions[] = {
210 {0, &IFileSystem::CreateFile, "CreateFile"}, 210 {0, &IFileSystem::CreateFile, "CreateFile"},
211 {2, &IFileSystem::CreateDirectory, "CreateDirectory"},
211 {7, &IFileSystem::GetEntryType, "GetEntryType"}, 212 {7, &IFileSystem::GetEntryType, "GetEntryType"},
212 {8, &IFileSystem::OpenFile, "OpenFile"}, 213 {8, &IFileSystem::OpenFile, "OpenFile"},
213 {9, &IFileSystem::OpenDirectory, "OpenDirectory"}, 214 {9, &IFileSystem::OpenDirectory, "OpenDirectory"},
@@ -234,6 +235,20 @@ public:
234 rb.Push(backend->CreateFile(name, size)); 235 rb.Push(backend->CreateFile(name, size));
235 } 236 }
236 237
238 void CreateDirectory(Kernel::HLERequestContext& ctx) {
239 IPC::RequestParser rp{ctx};
240
241 auto file_buffer = ctx.ReadBuffer();
242 auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0');
243
244 std::string name(file_buffer.begin(), end);
245
246 LOG_DEBUG(Service_FS, "called directory %s", name.c_str());
247
248 IPC::ResponseBuilder rb{ctx, 2};
249 rb.Push(backend->CreateDirectory(name));
250 }
251
237 void OpenFile(Kernel::HLERequestContext& ctx) { 252 void OpenFile(Kernel::HLERequestContext& ctx) {
238 IPC::RequestParser rp{ctx}; 253 IPC::RequestParser rp{ctx};
239 254