fsp_srv.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cinttypes>
  5. #include <cstring>
  6. #include <iterator>
  7. #include <string>
  8. #include <utility>
  9. #include <vector>
  10. #include "common/assert.h"
  11. #include "common/common_types.h"
  12. #include "common/logging/log.h"
  13. #include "common/string_util.h"
  14. #include "core/core.h"
  15. #include "core/file_sys/directory.h"
  16. #include "core/file_sys/errors.h"
  17. #include "core/hle/ipc_helpers.h"
  18. #include "core/hle/kernel/process.h"
  19. #include "core/hle/service/filesystem/filesystem.h"
  20. #include "core/hle/service/filesystem/fsp_srv.h"
  21. namespace Service::FileSystem {
  22. enum class StorageId : u8 {
  23. None = 0,
  24. Host = 1,
  25. GameCard = 2,
  26. NandSystem = 3,
  27. NandUser = 4,
  28. SdCard = 5,
  29. };
  30. class IStorage final : public ServiceFramework<IStorage> {
  31. public:
  32. explicit IStorage(FileSys::VirtualFile backend_)
  33. : ServiceFramework("IStorage"), backend(std::move(backend_)) {
  34. static const FunctionInfo functions[] = {
  35. {0, &IStorage::Read, "Read"}, {1, nullptr, "Write"}, {2, nullptr, "Flush"},
  36. {3, nullptr, "SetSize"}, {4, nullptr, "GetSize"}, {5, nullptr, "OperateRange"},
  37. };
  38. RegisterHandlers(functions);
  39. }
  40. private:
  41. FileSys::VirtualFile backend;
  42. void Read(Kernel::HLERequestContext& ctx) {
  43. IPC::RequestParser rp{ctx};
  44. const s64 offset = rp.Pop<s64>();
  45. const s64 length = rp.Pop<s64>();
  46. LOG_DEBUG(Service_FS, "called, offset=0x{:X}, length={}", offset, length);
  47. // Error checking
  48. if (length < 0) {
  49. IPC::ResponseBuilder rb{ctx, 2};
  50. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength));
  51. return;
  52. }
  53. if (offset < 0) {
  54. IPC::ResponseBuilder rb{ctx, 2};
  55. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset));
  56. return;
  57. }
  58. // Read the data from the Storage backend
  59. std::vector<u8> output = backend->ReadBytes(length, offset);
  60. // Write the data to memory
  61. ctx.WriteBuffer(output);
  62. IPC::ResponseBuilder rb{ctx, 2};
  63. rb.Push(RESULT_SUCCESS);
  64. }
  65. };
  66. class IFile final : public ServiceFramework<IFile> {
  67. public:
  68. explicit IFile(FileSys::VirtualFile backend_)
  69. : ServiceFramework("IFile"), backend(std::move(backend_)) {
  70. static const FunctionInfo functions[] = {
  71. {0, &IFile::Read, "Read"}, {1, &IFile::Write, "Write"},
  72. {2, &IFile::Flush, "Flush"}, {3, &IFile::SetSize, "SetSize"},
  73. {4, &IFile::GetSize, "GetSize"}, {5, nullptr, "OperateRange"},
  74. };
  75. RegisterHandlers(functions);
  76. }
  77. private:
  78. FileSys::VirtualFile backend;
  79. void Read(Kernel::HLERequestContext& ctx) {
  80. IPC::RequestParser rp{ctx};
  81. const u64 unk = rp.Pop<u64>();
  82. const s64 offset = rp.Pop<s64>();
  83. const s64 length = rp.Pop<s64>();
  84. LOG_DEBUG(Service_FS, "called, offset=0x{:X}, length={}", offset, length);
  85. // Error checking
  86. if (length < 0) {
  87. IPC::ResponseBuilder rb{ctx, 2};
  88. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength));
  89. return;
  90. }
  91. if (offset < 0) {
  92. IPC::ResponseBuilder rb{ctx, 2};
  93. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset));
  94. return;
  95. }
  96. // Read the data from the Storage backend
  97. std::vector<u8> output = backend->ReadBytes(length, offset);
  98. // Write the data to memory
  99. ctx.WriteBuffer(output);
  100. IPC::ResponseBuilder rb{ctx, 4};
  101. rb.Push(RESULT_SUCCESS);
  102. rb.Push(static_cast<u64>(output.size()));
  103. }
  104. void Write(Kernel::HLERequestContext& ctx) {
  105. IPC::RequestParser rp{ctx};
  106. const u64 unk = rp.Pop<u64>();
  107. const s64 offset = rp.Pop<s64>();
  108. const s64 length = rp.Pop<s64>();
  109. LOG_DEBUG(Service_FS, "called, offset=0x{:X}, length={}", offset, length);
  110. // Error checking
  111. if (length < 0) {
  112. IPC::ResponseBuilder rb{ctx, 2};
  113. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength));
  114. return;
  115. }
  116. if (offset < 0) {
  117. IPC::ResponseBuilder rb{ctx, 2};
  118. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset));
  119. return;
  120. }
  121. const std::vector<u8> data = ctx.ReadBuffer();
  122. ASSERT_MSG(
  123. static_cast<s64>(data.size()) <= length,
  124. "Attempting to write more data than requested (requested={:016X}, actual={:016X}).",
  125. length, data.size());
  126. // Write the data to the Storage backend
  127. const auto write_size =
  128. static_cast<std::size_t>(std::distance(data.begin(), data.begin() + length));
  129. const std::size_t written = backend->Write(data.data(), write_size, offset);
  130. ASSERT_MSG(static_cast<s64>(written) == length,
  131. "Could not write all bytes to file (requested={:016X}, actual={:016X}).", length,
  132. written);
  133. IPC::ResponseBuilder rb{ctx, 2};
  134. rb.Push(RESULT_SUCCESS);
  135. }
  136. void Flush(Kernel::HLERequestContext& ctx) {
  137. LOG_DEBUG(Service_FS, "called");
  138. // Exists for SDK compatibiltity -- No need to flush file.
  139. IPC::ResponseBuilder rb{ctx, 2};
  140. rb.Push(RESULT_SUCCESS);
  141. }
  142. void SetSize(Kernel::HLERequestContext& ctx) {
  143. IPC::RequestParser rp{ctx};
  144. const u64 size = rp.Pop<u64>();
  145. backend->Resize(size);
  146. LOG_DEBUG(Service_FS, "called, size={}", size);
  147. IPC::ResponseBuilder rb{ctx, 2};
  148. rb.Push(RESULT_SUCCESS);
  149. }
  150. void GetSize(Kernel::HLERequestContext& ctx) {
  151. const u64 size = backend->GetSize();
  152. LOG_DEBUG(Service_FS, "called, size={}", size);
  153. IPC::ResponseBuilder rb{ctx, 4};
  154. rb.Push(RESULT_SUCCESS);
  155. rb.Push<u64>(size);
  156. }
  157. };
  158. template <typename T>
  159. static void BuildEntryIndex(std::vector<FileSys::Entry>& entries, const std::vector<T>& new_data,
  160. FileSys::EntryType type) {
  161. entries.reserve(entries.size() + new_data.size());
  162. for (const auto& new_entry : new_data) {
  163. entries.emplace_back(new_entry->GetName(), type, new_entry->GetSize());
  164. }
  165. }
  166. class IDirectory final : public ServiceFramework<IDirectory> {
  167. public:
  168. explicit IDirectory(FileSys::VirtualDir backend_)
  169. : ServiceFramework("IDirectory"), backend(std::move(backend_)) {
  170. static const FunctionInfo functions[] = {
  171. {0, &IDirectory::Read, "Read"},
  172. {1, &IDirectory::GetEntryCount, "GetEntryCount"},
  173. };
  174. RegisterHandlers(functions);
  175. // TODO(DarkLordZach): Verify that this is the correct behavior.
  176. // Build entry index now to save time later.
  177. BuildEntryIndex(entries, backend->GetFiles(), FileSys::File);
  178. BuildEntryIndex(entries, backend->GetSubdirectories(), FileSys::Directory);
  179. }
  180. private:
  181. FileSys::VirtualDir backend;
  182. std::vector<FileSys::Entry> entries;
  183. u64 next_entry_index = 0;
  184. void Read(Kernel::HLERequestContext& ctx) {
  185. IPC::RequestParser rp{ctx};
  186. const u64 unk = rp.Pop<u64>();
  187. LOG_DEBUG(Service_FS, "called, unk=0x{:X}", unk);
  188. // Calculate how many entries we can fit in the output buffer
  189. const u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry);
  190. // Cap at total number of entries.
  191. const u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index);
  192. // Determine data start and end
  193. const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index);
  194. const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries);
  195. const auto range_size = static_cast<std::size_t>(std::distance(begin, end));
  196. next_entry_index += actual_entries;
  197. // Write the data to memory
  198. ctx.WriteBuffer(begin, range_size);
  199. IPC::ResponseBuilder rb{ctx, 4};
  200. rb.Push(RESULT_SUCCESS);
  201. rb.Push(actual_entries);
  202. }
  203. void GetEntryCount(Kernel::HLERequestContext& ctx) {
  204. LOG_DEBUG(Service_FS, "called");
  205. u64 count = entries.size() - next_entry_index;
  206. IPC::ResponseBuilder rb{ctx, 4};
  207. rb.Push(RESULT_SUCCESS);
  208. rb.Push(count);
  209. }
  210. };
  211. class IFileSystem final : public ServiceFramework<IFileSystem> {
  212. public:
  213. explicit IFileSystem(FileSys::VirtualDir backend)
  214. : ServiceFramework("IFileSystem"), backend(std::move(backend)) {
  215. static const FunctionInfo functions[] = {
  216. {0, &IFileSystem::CreateFile, "CreateFile"},
  217. {1, &IFileSystem::DeleteFile, "DeleteFile"},
  218. {2, &IFileSystem::CreateDirectory, "CreateDirectory"},
  219. {3, nullptr, "DeleteDirectory"},
  220. {4, nullptr, "DeleteDirectoryRecursively"},
  221. {5, &IFileSystem::RenameFile, "RenameFile"},
  222. {6, nullptr, "RenameDirectory"},
  223. {7, &IFileSystem::GetEntryType, "GetEntryType"},
  224. {8, &IFileSystem::OpenFile, "OpenFile"},
  225. {9, &IFileSystem::OpenDirectory, "OpenDirectory"},
  226. {10, &IFileSystem::Commit, "Commit"},
  227. {11, nullptr, "GetFreeSpaceSize"},
  228. {12, nullptr, "GetTotalSpaceSize"},
  229. {13, nullptr, "CleanDirectoryRecursively"},
  230. {14, nullptr, "GetFileTimeStampRaw"},
  231. {15, nullptr, "QueryEntry"},
  232. };
  233. RegisterHandlers(functions);
  234. }
  235. void CreateFile(Kernel::HLERequestContext& ctx) {
  236. IPC::RequestParser rp{ctx};
  237. auto file_buffer = ctx.ReadBuffer();
  238. std::string name = Common::StringFromBuffer(file_buffer);
  239. u64 mode = rp.Pop<u64>();
  240. u32 size = rp.Pop<u32>();
  241. LOG_DEBUG(Service_FS, "called file {} mode 0x{:X} size 0x{:08X}", name, mode, size);
  242. IPC::ResponseBuilder rb{ctx, 2};
  243. rb.Push(backend.CreateFile(name, size));
  244. }
  245. void DeleteFile(Kernel::HLERequestContext& ctx) {
  246. IPC::RequestParser rp{ctx};
  247. auto file_buffer = ctx.ReadBuffer();
  248. std::string name = Common::StringFromBuffer(file_buffer);
  249. LOG_DEBUG(Service_FS, "called file {}", name);
  250. IPC::ResponseBuilder rb{ctx, 2};
  251. rb.Push(backend.DeleteFile(name));
  252. }
  253. void CreateDirectory(Kernel::HLERequestContext& ctx) {
  254. IPC::RequestParser rp{ctx};
  255. auto file_buffer = ctx.ReadBuffer();
  256. std::string name = Common::StringFromBuffer(file_buffer);
  257. LOG_DEBUG(Service_FS, "called directory {}", name);
  258. IPC::ResponseBuilder rb{ctx, 2};
  259. rb.Push(backend.CreateDirectory(name));
  260. }
  261. void RenameFile(Kernel::HLERequestContext& ctx) {
  262. IPC::RequestParser rp{ctx};
  263. std::vector<u8> buffer;
  264. buffer.resize(ctx.BufferDescriptorX()[0].Size());
  265. Memory::ReadBlock(ctx.BufferDescriptorX()[0].Address(), buffer.data(), buffer.size());
  266. std::string src_name = Common::StringFromBuffer(buffer);
  267. buffer.resize(ctx.BufferDescriptorX()[1].Size());
  268. Memory::ReadBlock(ctx.BufferDescriptorX()[1].Address(), buffer.data(), buffer.size());
  269. std::string dst_name = Common::StringFromBuffer(buffer);
  270. LOG_DEBUG(Service_FS, "called file '{}' to file '{}'", src_name, dst_name);
  271. IPC::ResponseBuilder rb{ctx, 2};
  272. rb.Push(backend.RenameFile(src_name, dst_name));
  273. }
  274. void OpenFile(Kernel::HLERequestContext& ctx) {
  275. IPC::RequestParser rp{ctx};
  276. auto file_buffer = ctx.ReadBuffer();
  277. std::string name = Common::StringFromBuffer(file_buffer);
  278. auto mode = static_cast<FileSys::Mode>(rp.Pop<u32>());
  279. LOG_DEBUG(Service_FS, "called file {} mode {}", name, static_cast<u32>(mode));
  280. auto result = backend.OpenFile(name, mode);
  281. if (result.Failed()) {
  282. IPC::ResponseBuilder rb{ctx, 2};
  283. rb.Push(result.Code());
  284. return;
  285. }
  286. IFile file(result.Unwrap());
  287. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  288. rb.Push(RESULT_SUCCESS);
  289. rb.PushIpcInterface<IFile>(std::move(file));
  290. }
  291. void OpenDirectory(Kernel::HLERequestContext& ctx) {
  292. IPC::RequestParser rp{ctx};
  293. auto file_buffer = ctx.ReadBuffer();
  294. std::string name = Common::StringFromBuffer(file_buffer);
  295. // TODO(Subv): Implement this filter.
  296. u32 filter_flags = rp.Pop<u32>();
  297. LOG_DEBUG(Service_FS, "called directory {} filter {}", name, filter_flags);
  298. auto result = backend.OpenDirectory(name);
  299. if (result.Failed()) {
  300. IPC::ResponseBuilder rb{ctx, 2};
  301. rb.Push(result.Code());
  302. return;
  303. }
  304. IDirectory directory(result.Unwrap());
  305. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  306. rb.Push(RESULT_SUCCESS);
  307. rb.PushIpcInterface<IDirectory>(std::move(directory));
  308. }
  309. void GetEntryType(Kernel::HLERequestContext& ctx) {
  310. IPC::RequestParser rp{ctx};
  311. auto file_buffer = ctx.ReadBuffer();
  312. std::string name = Common::StringFromBuffer(file_buffer);
  313. LOG_DEBUG(Service_FS, "called file {}", name);
  314. auto result = backend.GetEntryType(name);
  315. if (result.Failed()) {
  316. IPC::ResponseBuilder rb{ctx, 2};
  317. rb.Push(result.Code());
  318. return;
  319. }
  320. IPC::ResponseBuilder rb{ctx, 3};
  321. rb.Push(RESULT_SUCCESS);
  322. rb.Push<u32>(static_cast<u32>(*result));
  323. }
  324. void Commit(Kernel::HLERequestContext& ctx) {
  325. LOG_WARNING(Service_FS, "(STUBBED) called");
  326. IPC::ResponseBuilder rb{ctx, 2};
  327. rb.Push(RESULT_SUCCESS);
  328. }
  329. private:
  330. VfsDirectoryServiceWrapper backend;
  331. };
  332. FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") {
  333. static const FunctionInfo functions[] = {
  334. {0, nullptr, "MountContent"},
  335. {1, &FSP_SRV::Initialize, "Initialize"},
  336. {2, nullptr, "OpenDataFileSystemByCurrentProcess"},
  337. {7, nullptr, "OpenFileSystemWithPatch"},
  338. {8, nullptr, "OpenFileSystemWithId"},
  339. {9, nullptr, "OpenDataFileSystemByApplicationId"},
  340. {11, nullptr, "OpenBisFileSystem"},
  341. {12, nullptr, "OpenBisStorage"},
  342. {13, nullptr, "InvalidateBisCache"},
  343. {17, nullptr, "OpenHostFileSystem"},
  344. {18, &FSP_SRV::MountSdCard, "MountSdCard"},
  345. {19, nullptr, "FormatSdCardFileSystem"},
  346. {21, nullptr, "DeleteSaveDataFileSystem"},
  347. {22, &FSP_SRV::CreateSaveData, "CreateSaveData"},
  348. {23, nullptr, "CreateSaveDataFileSystemBySystemSaveDataId"},
  349. {24, nullptr, "RegisterSaveDataFileSystemAtomicDeletion"},
  350. {25, nullptr, "DeleteSaveDataFileSystemBySaveDataSpaceId"},
  351. {26, nullptr, "FormatSdCardDryRun"},
  352. {27, nullptr, "IsExFatSupported"},
  353. {28, nullptr, "DeleteSaveDataFileSystemBySaveDataAttribute"},
  354. {30, nullptr, "OpenGameCardStorage"},
  355. {31, nullptr, "OpenGameCardFileSystem"},
  356. {32, nullptr, "ExtendSaveDataFileSystem"},
  357. {33, nullptr, "DeleteCacheStorage"},
  358. {34, nullptr, "GetCacheStorageSize"},
  359. {51, &FSP_SRV::MountSaveData, "MountSaveData"},
  360. {52, nullptr, "OpenSaveDataFileSystemBySystemSaveDataId"},
  361. {53, nullptr, "OpenReadOnlySaveDataFileSystem"},
  362. {57, nullptr, "ReadSaveDataFileSystemExtraDataBySaveDataSpaceId"},
  363. {58, nullptr, "ReadSaveDataFileSystemExtraData"},
  364. {59, nullptr, "WriteSaveDataFileSystemExtraData"},
  365. {60, nullptr, "OpenSaveDataInfoReader"},
  366. {61, nullptr, "OpenSaveDataInfoReaderBySaveDataSpaceId"},
  367. {62, nullptr, "OpenCacheStorageList"},
  368. {64, nullptr, "OpenSaveDataInternalStorageFileSystem"},
  369. {65, nullptr, "UpdateSaveDataMacForDebug"},
  370. {66, nullptr, "WriteSaveDataFileSystemExtraData2"},
  371. {80, nullptr, "OpenSaveDataMetaFile"},
  372. {81, nullptr, "OpenSaveDataTransferManager"},
  373. {82, nullptr, "OpenSaveDataTransferManagerVersion2"},
  374. {100, nullptr, "OpenImageDirectoryFileSystem"},
  375. {110, nullptr, "OpenContentStorageFileSystem"},
  376. {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"},
  377. {201, nullptr, "OpenDataStorageByProgramId"},
  378. {202, nullptr, "OpenDataStorageByDataId"},
  379. {203, &FSP_SRV::OpenRomStorage, "OpenRomStorage"},
  380. {400, nullptr, "OpenDeviceOperator"},
  381. {500, nullptr, "OpenSdCardDetectionEventNotifier"},
  382. {501, nullptr, "OpenGameCardDetectionEventNotifier"},
  383. {510, nullptr, "OpenSystemDataUpdateEventNotifier"},
  384. {511, nullptr, "NotifySystemDataUpdateEvent"},
  385. {600, nullptr, "SetCurrentPosixTime"},
  386. {601, nullptr, "QuerySaveDataTotalSize"},
  387. {602, nullptr, "VerifySaveDataFileSystem"},
  388. {603, nullptr, "CorruptSaveDataFileSystem"},
  389. {604, nullptr, "CreatePaddingFile"},
  390. {605, nullptr, "DeleteAllPaddingFiles"},
  391. {606, nullptr, "GetRightsId"},
  392. {607, nullptr, "RegisterExternalKey"},
  393. {608, nullptr, "UnregisterAllExternalKey"},
  394. {609, nullptr, "GetRightsIdByPath"},
  395. {610, nullptr, "GetRightsIdAndKeyGenerationByPath"},
  396. {611, nullptr, "SetCurrentPosixTimeWithTimeDifference"},
  397. {612, nullptr, "GetFreeSpaceSizeForSaveData"},
  398. {613, nullptr, "VerifySaveDataFileSystemBySaveDataSpaceId"},
  399. {614, nullptr, "CorruptSaveDataFileSystemBySaveDataSpaceId"},
  400. {615, nullptr, "QuerySaveDataInternalStorageTotalSize"},
  401. {620, nullptr, "SetSdCardEncryptionSeed"},
  402. {630, nullptr, "SetSdCardAccessibility"},
  403. {631, nullptr, "IsSdCardAccessible"},
  404. {640, nullptr, "IsSignedSystemPartitionOnSdCardValid"},
  405. {700, nullptr, "OpenAccessFailureResolver"},
  406. {701, nullptr, "GetAccessFailureDetectionEvent"},
  407. {702, nullptr, "IsAccessFailureDetected"},
  408. {710, nullptr, "ResolveAccessFailure"},
  409. {720, nullptr, "AbandonAccessFailure"},
  410. {800, nullptr, "GetAndClearFileSystemProxyErrorInfo"},
  411. {1000, nullptr, "SetBisRootForHost"},
  412. {1001, nullptr, "SetSaveDataSize"},
  413. {1002, nullptr, "SetSaveDataRootPath"},
  414. {1003, nullptr, "DisableAutoSaveDataCreation"},
  415. {1004, nullptr, "SetGlobalAccessLogMode"},
  416. {1005, &FSP_SRV::GetGlobalAccessLogMode, "GetGlobalAccessLogMode"},
  417. {1006, nullptr, "OutputAccessLogToSdCard"},
  418. {1007, nullptr, "RegisterUpdatePartition"},
  419. {1008, nullptr, "OpenRegisteredUpdatePartition"},
  420. {1009, nullptr, "GetAndClearMemoryReportInfo"},
  421. {1100, nullptr, "OverrideSaveDataTransferTokenSignVerificationKey"},
  422. };
  423. RegisterHandlers(functions);
  424. }
  425. void FSP_SRV::Initialize(Kernel::HLERequestContext& ctx) {
  426. LOG_WARNING(Service_FS, "(STUBBED) called");
  427. IPC::ResponseBuilder rb{ctx, 2};
  428. rb.Push(RESULT_SUCCESS);
  429. }
  430. void FSP_SRV::MountSdCard(Kernel::HLERequestContext& ctx) {
  431. LOG_DEBUG(Service_FS, "called");
  432. IFileSystem filesystem(OpenSDMC().Unwrap());
  433. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  434. rb.Push(RESULT_SUCCESS);
  435. rb.PushIpcInterface<IFileSystem>(std::move(filesystem));
  436. }
  437. void FSP_SRV::CreateSaveData(Kernel::HLERequestContext& ctx) {
  438. IPC::RequestParser rp{ctx};
  439. auto save_struct = rp.PopRaw<FileSys::SaveDataDescriptor>();
  440. auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>();
  441. u128 uid = rp.PopRaw<u128>();
  442. LOG_WARNING(Service_FS, "(STUBBED) called save_struct = {}, uid = {:016X}{:016X}",
  443. save_struct.DebugInfo(), uid[1], uid[0]);
  444. IPC::ResponseBuilder rb{ctx, 2};
  445. rb.Push(RESULT_SUCCESS);
  446. }
  447. void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) {
  448. IPC::RequestParser rp{ctx};
  449. auto space_id = rp.PopRaw<FileSys::SaveDataSpaceId>();
  450. auto unk = rp.Pop<u32>();
  451. LOG_INFO(Service_FS, "called with unknown={:08X}", unk);
  452. auto save_struct = rp.PopRaw<FileSys::SaveDataDescriptor>();
  453. auto dir = OpenSaveData(space_id, save_struct);
  454. if (dir.Failed()) {
  455. IPC::ResponseBuilder rb{ctx, 2, 0, 0};
  456. rb.Push(ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound));
  457. return;
  458. }
  459. IFileSystem filesystem(std::move(dir.Unwrap()));
  460. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  461. rb.Push(RESULT_SUCCESS);
  462. rb.PushIpcInterface<IFileSystem>(std::move(filesystem));
  463. }
  464. void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) {
  465. LOG_WARNING(Service_FS, "(STUBBED) called");
  466. IPC::ResponseBuilder rb{ctx, 3};
  467. rb.Push(RESULT_SUCCESS);
  468. rb.Push<u32>(5);
  469. }
  470. void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) {
  471. LOG_DEBUG(Service_FS, "called");
  472. auto romfs = OpenRomFS(Core::System::GetInstance().CurrentProcess()->program_id);
  473. if (romfs.Failed()) {
  474. // TODO (bunnei): Find the right error code to use here
  475. LOG_CRITICAL(Service_FS, "no file system interface available!");
  476. IPC::ResponseBuilder rb{ctx, 2};
  477. rb.Push(ResultCode(-1));
  478. return;
  479. }
  480. IStorage storage(std::move(romfs.Unwrap()));
  481. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  482. rb.Push(RESULT_SUCCESS);
  483. rb.PushIpcInterface<IStorage>(std::move(storage));
  484. }
  485. void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) {
  486. IPC::RequestParser rp{ctx};
  487. auto storage_id = rp.PopRaw<StorageId>();
  488. auto title_id = rp.PopRaw<u64>();
  489. LOG_DEBUG(Service_FS, "called with storage_id={:02X}, title_id={:016X}",
  490. static_cast<u8>(storage_id), title_id);
  491. IPC::ResponseBuilder rb{ctx, 2};
  492. rb.Push(ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound));
  493. }
  494. } // namespace Service::FileSystem