summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2018-02-19 00:33:48 -0500
committerGravatar Subv2018-03-01 19:03:53 -0500
commitcc6e4ae6cf496f787c5277135aaa3e63cb98b780 (patch)
treecf223fd16ae5a410a0b7d63cf818112b9b7c6595 /src
parentFilesystem: Added a SaveData Factory and associated Disk_FileSystem. (diff)
downloadyuzu-cc6e4ae6cf496f787c5277135aaa3e63cb98b780.tar.gz
yuzu-cc6e4ae6cf496f787c5277135aaa3e63cb98b780.tar.xz
yuzu-cc6e4ae6cf496f787c5277135aaa3e63cb98b780.zip
FS: Implement MountSaveData and some of the IFile interface.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.cpp188
-rw-r--r--src/core/hle/service/filesystem/fsp_srv.h1
2 files changed, 189 insertions, 0 deletions
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp
index 87a07e457..3ac5a96cb 100644
--- a/src/core/hle/service/filesystem/fsp_srv.cpp
+++ b/src/core/hle/service/filesystem/fsp_srv.cpp
@@ -2,6 +2,7 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <cinttypes>
5#include "common/logging/log.h" 6#include "common/logging/log.h"
6#include "core/core.h" 7#include "core/core.h"
7#include "core/file_sys/filesystem.h" 8#include "core/file_sys/filesystem.h"
@@ -65,10 +66,186 @@ private:
65 } 66 }
66}; 67};
67 68
69class IFile final : public ServiceFramework<IFile> {
70public:
71 explicit IFile(std::unique_ptr<FileSys::StorageBackend>&& backend)
72 : ServiceFramework("IFile"), backend(std::move(backend)) {
73 static const FunctionInfo functions[] = {
74 {0, &IFile::Read, "Read"}, {1, &IFile::Write, "Write"}, {2, nullptr, "Flush"},
75 {3, nullptr, "SetSize"}, {4, nullptr, "GetSize"},
76 };
77 RegisterHandlers(functions);
78 }
79
80private:
81 std::unique_ptr<FileSys::StorageBackend> backend;
82
83 void Read(Kernel::HLERequestContext& ctx) {
84 IPC::RequestParser rp{ctx};
85 const u64 unk = rp.Pop<u64>();
86 const s64 offset = rp.Pop<s64>();
87 const s64 length = rp.Pop<s64>();
88
89 LOG_DEBUG(Service_FS, "called, offset=0x%llx, length=0x%llx", offset, length);
90
91 // Error checking
92 if (length < 0) {
93 IPC::ResponseBuilder rb{ctx, 2};
94 rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength));
95 return;
96 }
97 if (offset < 0) {
98 IPC::ResponseBuilder rb{ctx, 2};
99 rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset));
100 return;
101 }
102
103 // Read the data from the Storage backend
104 std::vector<u8> output(length);
105 ResultVal<size_t> res = backend->Read(offset, length, output.data());
106 if (res.Failed()) {
107 IPC::ResponseBuilder rb{ctx, 2};
108 rb.Push(res.Code());
109 return;
110 }
111
112 // Write the data to memory
113 ctx.WriteBuffer(output);
114
115 IPC::ResponseBuilder rb{ctx, 4};
116 rb.Push(RESULT_SUCCESS);
117 rb.Push(static_cast<u64>(*res));
118 }
119
120 void Write(Kernel::HLERequestContext& ctx) {
121 IPC::RequestParser rp{ctx};
122 const u64 unk = rp.Pop<u64>();
123 const s64 offset = rp.Pop<s64>();
124 const s64 length = rp.Pop<s64>();
125
126 LOG_DEBUG(Service_FS, "called, offset=0x%llx, length=0x%llx", offset, length);
127
128 // Error checking
129 if (length < 0) {
130 IPC::ResponseBuilder rb{ctx, 2};
131 rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength));
132 return;
133 }
134 if (offset < 0) {
135 IPC::ResponseBuilder rb{ctx, 2};
136 rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset));
137 return;
138 }
139
140 // Write the data to the Storage backend
141 std::vector<u8> data = ctx.ReadBuffer();
142 ResultVal<size_t> res = backend->Write(offset, length, true, data.data());
143 if (res.Failed()) {
144 IPC::ResponseBuilder rb{ctx, 2};
145 rb.Push(res.Code());
146 return;
147 }
148
149 IPC::ResponseBuilder rb{ctx, 2};
150 rb.Push(RESULT_SUCCESS);
151 }
152};
153
154class IFileSystem final : public ServiceFramework<IFileSystem> {
155public:
156 explicit IFileSystem(std::unique_ptr<FileSys::FileSystemBackend>&& backend)
157 : ServiceFramework("IFileSystem"), backend(std::move(backend)) {
158 static const FunctionInfo functions[] = {
159 {0, &IFileSystem::CreateFile, "CreateFile"},
160 {7, &IFileSystem::GetEntryType, "GetEntryType"},
161 {8, &IFileSystem::OpenFile, "OpenFile"},
162 {10, &IFileSystem::Commit, "Commit"},
163 };
164 RegisterHandlers(functions);
165 }
166
167 void CreateFile(Kernel::HLERequestContext& ctx) {
168 IPC::RequestParser rp{ctx};
169
170 auto file_buffer = ctx.ReadBuffer();
171 auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0');
172
173 std::string name(file_buffer.begin(), end);
174
175 u64 mode = rp.Pop<u64>();
176 u32 size = rp.Pop<u32>();
177
178 LOG_DEBUG(Service_FS, "called file %s mode 0x%" PRIX64 " size 0x%08X", name.c_str(), mode,
179 size);
180
181 IPC::ResponseBuilder rb{ctx, 2};
182 rb.Push(backend->CreateFile(name, size));
183 }
184
185 void OpenFile(Kernel::HLERequestContext& ctx) {
186 IPC::RequestParser rp{ctx};
187
188 auto file_buffer = ctx.ReadBuffer();
189 auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0');
190
191 std::string name(file_buffer.begin(), end);
192
193 auto mode = static_cast<FileSys::Mode>(rp.Pop<u32>());
194
195 LOG_DEBUG(Service_FS, "called file %s mode %u", name.c_str(), static_cast<u32>(mode));
196
197 auto result = backend->OpenFile(name, mode);
198 if (result.Failed()) {
199 IPC::ResponseBuilder rb{ctx, 2};
200 rb.Push(result.Code());
201 return;
202 }
203
204 auto file = std::move(result.Unwrap());
205
206 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
207 rb.Push(RESULT_SUCCESS);
208 rb.PushIpcInterface<IFile>(std::move(file));
209 }
210
211 void GetEntryType(Kernel::HLERequestContext& ctx) {
212 IPC::RequestParser rp{ctx};
213
214 auto file_buffer = ctx.ReadBuffer();
215 auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0');
216
217 std::string name(file_buffer.begin(), end);
218
219 LOG_DEBUG(Service_FS, "called file %s", name.c_str());
220
221 auto result = backend->GetEntryType(name);
222 if (result.Failed()) {
223 IPC::ResponseBuilder rb{ctx, 2};
224 rb.Push(result.Code());
225 return;
226 }
227
228 IPC::ResponseBuilder rb{ctx, 3};
229 rb.Push(RESULT_SUCCESS);
230 rb.Push<u32>(static_cast<u32>(*result));
231 }
232
233 void Commit(Kernel::HLERequestContext& ctx) {
234 LOG_WARNING(Service_FS, "(STUBBED) called");
235
236 IPC::ResponseBuilder rb{ctx, 2};
237 rb.Push(RESULT_SUCCESS);
238 }
239
240private:
241 std::unique_ptr<FileSys::FileSystemBackend> backend;
242};
243
68FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { 244FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") {
69 static const FunctionInfo functions[] = { 245 static const FunctionInfo functions[] = {
70 {1, &FSP_SRV::Initalize, "Initalize"}, 246 {1, &FSP_SRV::Initalize, "Initalize"},
71 {18, &FSP_SRV::MountSdCard, "MountSdCard"}, 247 {18, &FSP_SRV::MountSdCard, "MountSdCard"},
248 {51, &FSP_SRV::MountSaveData, "MountSaveData"},
72 {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"}, 249 {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"},
73 {202, nullptr, "OpenDataStorageByDataId"}, 250 {202, nullptr, "OpenDataStorageByDataId"},
74 {203, &FSP_SRV::OpenRomStorage, "OpenRomStorage"}, 251 {203, &FSP_SRV::OpenRomStorage, "OpenRomStorage"},
@@ -102,6 +279,17 @@ void FSP_SRV::MountSdCard(Kernel::HLERequestContext& ctx) {
102 rb.Push(RESULT_SUCCESS); 279 rb.Push(RESULT_SUCCESS);
103} 280}
104 281
282void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) {
283 LOG_WARNING(Service_FS, "(STUBBED) called");
284
285 FileSys::Path unused;
286 auto filesystem = OpenFileSystem(Type::SaveData, unused).Unwrap();
287
288 IPC::ResponseBuilder rb{ctx, 2, 0, 1};
289 rb.Push(RESULT_SUCCESS);
290 rb.PushIpcInterface<IFileSystem>(std::move(filesystem));
291}
292
105void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { 293void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) {
106 LOG_WARNING(Service_FS, "(STUBBED) called"); 294 LOG_WARNING(Service_FS, "(STUBBED) called");
107 295
diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h
index 56afc4b90..f19b2f2c4 100644
--- a/src/core/hle/service/filesystem/fsp_srv.h
+++ b/src/core/hle/service/filesystem/fsp_srv.h
@@ -24,6 +24,7 @@ private:
24 24
25 void Initalize(Kernel::HLERequestContext& ctx); 25 void Initalize(Kernel::HLERequestContext& ctx);
26 void MountSdCard(Kernel::HLERequestContext& ctx); 26 void MountSdCard(Kernel::HLERequestContext& ctx);
27 void MountSaveData(Kernel::HLERequestContext& ctx);
27 void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); 28 void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx);
28 void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); 29 void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx);
29 void OpenRomStorage(Kernel::HLERequestContext& ctx); 30 void OpenRomStorage(Kernel::HLERequestContext& ctx);