fsp_srv.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  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. for (const auto& new_entry : new_data) {
  162. FileSys::Entry entry;
  163. entry.filename[0] = '\0';
  164. std::strncat(entry.filename, new_entry->GetName().c_str(), FileSys::FILENAME_LENGTH - 1);
  165. entry.type = type;
  166. entry.file_size = new_entry->GetSize();
  167. entries.emplace_back(std::move(entry));
  168. }
  169. }
  170. class IDirectory final : public ServiceFramework<IDirectory> {
  171. public:
  172. explicit IDirectory(FileSys::VirtualDir backend_)
  173. : ServiceFramework("IDirectory"), backend(std::move(backend_)) {
  174. static const FunctionInfo functions[] = {
  175. {0, &IDirectory::Read, "Read"},
  176. {1, &IDirectory::GetEntryCount, "GetEntryCount"},
  177. };
  178. RegisterHandlers(functions);
  179. // TODO(DarkLordZach): Verify that this is the correct behavior.
  180. // Build entry index now to save time later.
  181. BuildEntryIndex(entries, backend->GetFiles(), FileSys::File);
  182. BuildEntryIndex(entries, backend->GetSubdirectories(), FileSys::Directory);
  183. }
  184. private:
  185. FileSys::VirtualDir backend;
  186. std::vector<FileSys::Entry> entries;
  187. u64 next_entry_index = 0;
  188. void Read(Kernel::HLERequestContext& ctx) {
  189. IPC::RequestParser rp{ctx};
  190. const u64 unk = rp.Pop<u64>();
  191. LOG_DEBUG(Service_FS, "called, unk=0x{:X}", unk);
  192. // Calculate how many entries we can fit in the output buffer
  193. const u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry);
  194. // Cap at total number of entries.
  195. const u64 actual_entries = std::min(count_entries, entries.size() - next_entry_index);
  196. // Determine data start and end
  197. const auto* begin = reinterpret_cast<u8*>(entries.data() + next_entry_index);
  198. const auto* end = reinterpret_cast<u8*>(entries.data() + next_entry_index + actual_entries);
  199. const auto range_size = static_cast<std::size_t>(std::distance(begin, end));
  200. next_entry_index += actual_entries;
  201. // Write the data to memory
  202. ctx.WriteBuffer(begin, range_size);
  203. IPC::ResponseBuilder rb{ctx, 4};
  204. rb.Push(RESULT_SUCCESS);
  205. rb.Push(actual_entries);
  206. }
  207. void GetEntryCount(Kernel::HLERequestContext& ctx) {
  208. LOG_DEBUG(Service_FS, "called");
  209. u64 count = entries.size() - next_entry_index;
  210. IPC::ResponseBuilder rb{ctx, 4};
  211. rb.Push(RESULT_SUCCESS);
  212. rb.Push(count);
  213. }
  214. };
  215. class IFileSystem final : public ServiceFramework<IFileSystem> {
  216. public:
  217. explicit IFileSystem(FileSys::VirtualDir backend)
  218. : ServiceFramework("IFileSystem"), backend(std::move(backend)) {
  219. static const FunctionInfo functions[] = {
  220. {0, &IFileSystem::CreateFile, "CreateFile"},
  221. {1, &IFileSystem::DeleteFile, "DeleteFile"},
  222. {2, &IFileSystem::CreateDirectory, "CreateDirectory"},
  223. {3, nullptr, "DeleteDirectory"},
  224. {4, nullptr, "DeleteDirectoryRecursively"},
  225. {5, &IFileSystem::RenameFile, "RenameFile"},
  226. {6, nullptr, "RenameDirectory"},
  227. {7, &IFileSystem::GetEntryType, "GetEntryType"},
  228. {8, &IFileSystem::OpenFile, "OpenFile"},
  229. {9, &IFileSystem::OpenDirectory, "OpenDirectory"},
  230. {10, &IFileSystem::Commit, "Commit"},
  231. {11, nullptr, "GetFreeSpaceSize"},
  232. {12, nullptr, "GetTotalSpaceSize"},
  233. {13, nullptr, "CleanDirectoryRecursively"},
  234. {14, nullptr, "GetFileTimeStampRaw"},
  235. {15, nullptr, "QueryEntry"},
  236. };
  237. RegisterHandlers(functions);
  238. }
  239. void CreateFile(Kernel::HLERequestContext& ctx) {
  240. IPC::RequestParser rp{ctx};
  241. auto file_buffer = ctx.ReadBuffer();
  242. std::string name = Common::StringFromBuffer(file_buffer);
  243. u64 mode = rp.Pop<u64>();
  244. u32 size = rp.Pop<u32>();
  245. LOG_DEBUG(Service_FS, "called file {} mode 0x{:X} size 0x{:08X}", name, mode, size);
  246. IPC::ResponseBuilder rb{ctx, 2};
  247. rb.Push(backend.CreateFile(name, size));
  248. }
  249. void DeleteFile(Kernel::HLERequestContext& ctx) {
  250. IPC::RequestParser rp{ctx};
  251. auto file_buffer = ctx.ReadBuffer();
  252. std::string name = Common::StringFromBuffer(file_buffer);
  253. LOG_DEBUG(Service_FS, "called file {}", name);
  254. IPC::ResponseBuilder rb{ctx, 2};
  255. rb.Push(backend.DeleteFile(name));
  256. }
  257. void CreateDirectory(Kernel::HLERequestContext& ctx) {
  258. IPC::RequestParser rp{ctx};
  259. auto file_buffer = ctx.ReadBuffer();
  260. std::string name = Common::StringFromBuffer(file_buffer);
  261. LOG_DEBUG(Service_FS, "called directory {}", name);
  262. IPC::ResponseBuilder rb{ctx, 2};
  263. rb.Push(backend.CreateDirectory(name));
  264. }
  265. void RenameFile(Kernel::HLERequestContext& ctx) {
  266. IPC::RequestParser rp{ctx};
  267. std::vector<u8> buffer;
  268. buffer.resize(ctx.BufferDescriptorX()[0].Size());
  269. Memory::ReadBlock(ctx.BufferDescriptorX()[0].Address(), buffer.data(), buffer.size());
  270. std::string src_name = Common::StringFromBuffer(buffer);
  271. buffer.resize(ctx.BufferDescriptorX()[1].Size());
  272. Memory::ReadBlock(ctx.BufferDescriptorX()[1].Address(), buffer.data(), buffer.size());
  273. std::string dst_name = Common::StringFromBuffer(buffer);
  274. LOG_DEBUG(Service_FS, "called file '{}' to file '{}'", src_name, dst_name);
  275. IPC::ResponseBuilder rb{ctx, 2};
  276. rb.Push(backend.RenameFile(src_name, dst_name));
  277. }
  278. void OpenFile(Kernel::HLERequestContext& ctx) {
  279. IPC::RequestParser rp{ctx};
  280. auto file_buffer = ctx.ReadBuffer();
  281. std::string name = Common::StringFromBuffer(file_buffer);
  282. auto mode = static_cast<FileSys::Mode>(rp.Pop<u32>());
  283. LOG_DEBUG(Service_FS, "called file {} mode {}", name, static_cast<u32>(mode));
  284. auto result = backend.OpenFile(name, mode);
  285. if (result.Failed()) {
  286. IPC::ResponseBuilder rb{ctx, 2};
  287. rb.Push(result.Code());
  288. return;
  289. }
  290. IFile file(result.Unwrap());
  291. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  292. rb.Push(RESULT_SUCCESS);
  293. rb.PushIpcInterface<IFile>(std::move(file));
  294. }
  295. void OpenDirectory(Kernel::HLERequestContext& ctx) {
  296. IPC::RequestParser rp{ctx};
  297. auto file_buffer = ctx.ReadBuffer();
  298. std::string name = Common::StringFromBuffer(file_buffer);
  299. // TODO(Subv): Implement this filter.
  300. u32 filter_flags = rp.Pop<u32>();
  301. LOG_DEBUG(Service_FS, "called directory {} filter {}", name, filter_flags);
  302. auto result = backend.OpenDirectory(name);
  303. if (result.Failed()) {
  304. IPC::ResponseBuilder rb{ctx, 2};
  305. rb.Push(result.Code());
  306. return;
  307. }
  308. IDirectory directory(result.Unwrap());
  309. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  310. rb.Push(RESULT_SUCCESS);
  311. rb.PushIpcInterface<IDirectory>(std::move(directory));
  312. }
  313. void GetEntryType(Kernel::HLERequestContext& ctx) {
  314. IPC::RequestParser rp{ctx};
  315. auto file_buffer = ctx.ReadBuffer();
  316. std::string name = Common::StringFromBuffer(file_buffer);
  317. LOG_DEBUG(Service_FS, "called file {}", name);
  318. auto result = backend.GetEntryType(name);
  319. if (result.Failed()) {
  320. IPC::ResponseBuilder rb{ctx, 2};
  321. rb.Push(result.Code());
  322. return;
  323. }
  324. IPC::ResponseBuilder rb{ctx, 3};
  325. rb.Push(RESULT_SUCCESS);
  326. rb.Push<u32>(static_cast<u32>(*result));
  327. }
  328. void Commit(Kernel::HLERequestContext& ctx) {
  329. LOG_WARNING(Service_FS, "(STUBBED) called");
  330. IPC::ResponseBuilder rb{ctx, 2};
  331. rb.Push(RESULT_SUCCESS);
  332. }
  333. private:
  334. VfsDirectoryServiceWrapper backend;
  335. };
  336. FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") {
  337. static const FunctionInfo functions[] = {
  338. {0, nullptr, "MountContent"},
  339. {1, &FSP_SRV::Initialize, "Initialize"},
  340. {2, nullptr, "OpenDataFileSystemByCurrentProcess"},
  341. {7, nullptr, "OpenFileSystemWithPatch"},
  342. {8, nullptr, "OpenFileSystemWithId"},
  343. {9, nullptr, "OpenDataFileSystemByApplicationId"},
  344. {11, nullptr, "OpenBisFileSystem"},
  345. {12, nullptr, "OpenBisStorage"},
  346. {13, nullptr, "InvalidateBisCache"},
  347. {17, nullptr, "OpenHostFileSystem"},
  348. {18, &FSP_SRV::MountSdCard, "MountSdCard"},
  349. {19, nullptr, "FormatSdCardFileSystem"},
  350. {21, nullptr, "DeleteSaveDataFileSystem"},
  351. {22, &FSP_SRV::CreateSaveData, "CreateSaveData"},
  352. {23, nullptr, "CreateSaveDataFileSystemBySystemSaveDataId"},
  353. {24, nullptr, "RegisterSaveDataFileSystemAtomicDeletion"},
  354. {25, nullptr, "DeleteSaveDataFileSystemBySaveDataSpaceId"},
  355. {26, nullptr, "FormatSdCardDryRun"},
  356. {27, nullptr, "IsExFatSupported"},
  357. {28, nullptr, "DeleteSaveDataFileSystemBySaveDataAttribute"},
  358. {30, nullptr, "OpenGameCardStorage"},
  359. {31, nullptr, "OpenGameCardFileSystem"},
  360. {32, nullptr, "ExtendSaveDataFileSystem"},
  361. {33, nullptr, "DeleteCacheStorage"},
  362. {34, nullptr, "GetCacheStorageSize"},
  363. {51, &FSP_SRV::MountSaveData, "MountSaveData"},
  364. {52, nullptr, "OpenSaveDataFileSystemBySystemSaveDataId"},
  365. {53, nullptr, "OpenReadOnlySaveDataFileSystem"},
  366. {57, nullptr, "ReadSaveDataFileSystemExtraDataBySaveDataSpaceId"},
  367. {58, nullptr, "ReadSaveDataFileSystemExtraData"},
  368. {59, nullptr, "WriteSaveDataFileSystemExtraData"},
  369. {60, nullptr, "OpenSaveDataInfoReader"},
  370. {61, nullptr, "OpenSaveDataInfoReaderBySaveDataSpaceId"},
  371. {62, nullptr, "OpenCacheStorageList"},
  372. {64, nullptr, "OpenSaveDataInternalStorageFileSystem"},
  373. {65, nullptr, "UpdateSaveDataMacForDebug"},
  374. {66, nullptr, "WriteSaveDataFileSystemExtraData2"},
  375. {80, nullptr, "OpenSaveDataMetaFile"},
  376. {81, nullptr, "OpenSaveDataTransferManager"},
  377. {82, nullptr, "OpenSaveDataTransferManagerVersion2"},
  378. {100, nullptr, "OpenImageDirectoryFileSystem"},
  379. {110, nullptr, "OpenContentStorageFileSystem"},
  380. {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"},
  381. {201, nullptr, "OpenDataStorageByProgramId"},
  382. {202, nullptr, "OpenDataStorageByDataId"},
  383. {203, &FSP_SRV::OpenRomStorage, "OpenRomStorage"},
  384. {400, nullptr, "OpenDeviceOperator"},
  385. {500, nullptr, "OpenSdCardDetectionEventNotifier"},
  386. {501, nullptr, "OpenGameCardDetectionEventNotifier"},
  387. {510, nullptr, "OpenSystemDataUpdateEventNotifier"},
  388. {511, nullptr, "NotifySystemDataUpdateEvent"},
  389. {600, nullptr, "SetCurrentPosixTime"},
  390. {601, nullptr, "QuerySaveDataTotalSize"},
  391. {602, nullptr, "VerifySaveDataFileSystem"},
  392. {603, nullptr, "CorruptSaveDataFileSystem"},
  393. {604, nullptr, "CreatePaddingFile"},
  394. {605, nullptr, "DeleteAllPaddingFiles"},
  395. {606, nullptr, "GetRightsId"},
  396. {607, nullptr, "RegisterExternalKey"},
  397. {608, nullptr, "UnregisterAllExternalKey"},
  398. {609, nullptr, "GetRightsIdByPath"},
  399. {610, nullptr, "GetRightsIdAndKeyGenerationByPath"},
  400. {611, nullptr, "SetCurrentPosixTimeWithTimeDifference"},
  401. {612, nullptr, "GetFreeSpaceSizeForSaveData"},
  402. {613, nullptr, "VerifySaveDataFileSystemBySaveDataSpaceId"},
  403. {614, nullptr, "CorruptSaveDataFileSystemBySaveDataSpaceId"},
  404. {615, nullptr, "QuerySaveDataInternalStorageTotalSize"},
  405. {620, nullptr, "SetSdCardEncryptionSeed"},
  406. {630, nullptr, "SetSdCardAccessibility"},
  407. {631, nullptr, "IsSdCardAccessible"},
  408. {640, nullptr, "IsSignedSystemPartitionOnSdCardValid"},
  409. {700, nullptr, "OpenAccessFailureResolver"},
  410. {701, nullptr, "GetAccessFailureDetectionEvent"},
  411. {702, nullptr, "IsAccessFailureDetected"},
  412. {710, nullptr, "ResolveAccessFailure"},
  413. {720, nullptr, "AbandonAccessFailure"},
  414. {800, nullptr, "GetAndClearFileSystemProxyErrorInfo"},
  415. {1000, nullptr, "SetBisRootForHost"},
  416. {1001, nullptr, "SetSaveDataSize"},
  417. {1002, nullptr, "SetSaveDataRootPath"},
  418. {1003, nullptr, "DisableAutoSaveDataCreation"},
  419. {1004, nullptr, "SetGlobalAccessLogMode"},
  420. {1005, &FSP_SRV::GetGlobalAccessLogMode, "GetGlobalAccessLogMode"},
  421. {1006, nullptr, "OutputAccessLogToSdCard"},
  422. {1007, nullptr, "RegisterUpdatePartition"},
  423. {1008, nullptr, "OpenRegisteredUpdatePartition"},
  424. {1009, nullptr, "GetAndClearMemoryReportInfo"},
  425. {1100, nullptr, "OverrideSaveDataTransferTokenSignVerificationKey"},
  426. };
  427. RegisterHandlers(functions);
  428. }
  429. void FSP_SRV::Initialize(Kernel::HLERequestContext& ctx) {
  430. LOG_WARNING(Service_FS, "(STUBBED) called");
  431. IPC::ResponseBuilder rb{ctx, 2};
  432. rb.Push(RESULT_SUCCESS);
  433. }
  434. void FSP_SRV::MountSdCard(Kernel::HLERequestContext& ctx) {
  435. LOG_DEBUG(Service_FS, "called");
  436. IFileSystem filesystem(OpenSDMC().Unwrap());
  437. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  438. rb.Push(RESULT_SUCCESS);
  439. rb.PushIpcInterface<IFileSystem>(std::move(filesystem));
  440. }
  441. void FSP_SRV::CreateSaveData(Kernel::HLERequestContext& ctx) {
  442. IPC::RequestParser rp{ctx};
  443. auto save_struct = rp.PopRaw<FileSys::SaveDataDescriptor>();
  444. auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>();
  445. u128 uid = rp.PopRaw<u128>();
  446. LOG_WARNING(Service_FS, "(STUBBED) called save_struct = {}, uid = {:016X}{:016X}",
  447. save_struct.DebugInfo(), uid[1], uid[0]);
  448. IPC::ResponseBuilder rb{ctx, 2};
  449. rb.Push(RESULT_SUCCESS);
  450. }
  451. void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) {
  452. IPC::RequestParser rp{ctx};
  453. auto space_id = rp.PopRaw<FileSys::SaveDataSpaceId>();
  454. auto unk = rp.Pop<u32>();
  455. LOG_INFO(Service_FS, "called with unknown={:08X}", unk);
  456. auto save_struct = rp.PopRaw<FileSys::SaveDataDescriptor>();
  457. auto dir = OpenSaveData(space_id, save_struct);
  458. if (dir.Failed()) {
  459. IPC::ResponseBuilder rb{ctx, 2, 0, 0};
  460. rb.Push(ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound));
  461. return;
  462. }
  463. IFileSystem filesystem(std::move(dir.Unwrap()));
  464. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  465. rb.Push(RESULT_SUCCESS);
  466. rb.PushIpcInterface<IFileSystem>(std::move(filesystem));
  467. }
  468. void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) {
  469. LOG_WARNING(Service_FS, "(STUBBED) called");
  470. IPC::ResponseBuilder rb{ctx, 3};
  471. rb.Push(RESULT_SUCCESS);
  472. rb.Push<u32>(5);
  473. }
  474. void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) {
  475. LOG_DEBUG(Service_FS, "called");
  476. auto romfs = OpenRomFS(Core::System::GetInstance().CurrentProcess()->program_id);
  477. if (romfs.Failed()) {
  478. // TODO (bunnei): Find the right error code to use here
  479. LOG_CRITICAL(Service_FS, "no file system interface available!");
  480. IPC::ResponseBuilder rb{ctx, 2};
  481. rb.Push(ResultCode(-1));
  482. return;
  483. }
  484. IStorage storage(std::move(romfs.Unwrap()));
  485. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  486. rb.Push(RESULT_SUCCESS);
  487. rb.PushIpcInterface<IStorage>(std::move(storage));
  488. }
  489. void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) {
  490. IPC::RequestParser rp{ctx};
  491. auto storage_id = rp.PopRaw<StorageId>();
  492. auto title_id = rp.PopRaw<u64>();
  493. LOG_DEBUG(Service_FS, "called with storage_id={:02X}, title_id={:016X}",
  494. static_cast<u8>(storage_id), title_id);
  495. IPC::ResponseBuilder rb{ctx, 2};
  496. rb.Push(ResultCode(ErrorModule::FS, FileSys::ErrCodes::TitleNotFound));
  497. }
  498. } // namespace Service::FileSystem