fsp_srv.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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 "common/logging/log.h"
  6. #include "core/core.h"
  7. #include "core/file_sys/directory.h"
  8. #include "core/file_sys/filesystem.h"
  9. #include "core/file_sys/storage.h"
  10. #include "core/hle/ipc_helpers.h"
  11. #include "core/hle/kernel/client_port.h"
  12. #include "core/hle/kernel/client_session.h"
  13. #include "core/hle/service/filesystem/filesystem.h"
  14. #include "core/hle/service/filesystem/fsp_srv.h"
  15. namespace Service {
  16. namespace FileSystem {
  17. class IStorage final : public ServiceFramework<IStorage> {
  18. public:
  19. IStorage(std::unique_ptr<FileSys::StorageBackend>&& backend)
  20. : ServiceFramework("IStorage"), backend(std::move(backend)) {
  21. static const FunctionInfo functions[] = {
  22. {0, &IStorage::Read, "Read"},
  23. {1, nullptr, "Write"},
  24. {2, nullptr, "Flush"},
  25. {3, nullptr, "SetSize"},
  26. {4, nullptr, "GetSize"},
  27. {5, nullptr, "OperateRange"},
  28. };
  29. RegisterHandlers(functions);
  30. }
  31. private:
  32. std::unique_ptr<FileSys::StorageBackend> backend;
  33. void Read(Kernel::HLERequestContext& ctx) {
  34. IPC::RequestParser rp{ctx};
  35. const s64 offset = rp.Pop<s64>();
  36. const s64 length = rp.Pop<s64>();
  37. LOG_DEBUG(Service_FS, "called, offset=0x%ld, length=0x%ld", offset, length);
  38. // Error checking
  39. if (length < 0) {
  40. IPC::ResponseBuilder rb{ctx, 2};
  41. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength));
  42. return;
  43. }
  44. if (offset < 0) {
  45. IPC::ResponseBuilder rb{ctx, 2};
  46. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset));
  47. return;
  48. }
  49. // Read the data from the Storage backend
  50. std::vector<u8> output(length);
  51. ResultVal<size_t> res = backend->Read(offset, length, output.data());
  52. if (res.Failed()) {
  53. IPC::ResponseBuilder rb{ctx, 2};
  54. rb.Push(res.Code());
  55. return;
  56. }
  57. // Write the data to memory
  58. ctx.WriteBuffer(output);
  59. IPC::ResponseBuilder rb{ctx, 2};
  60. rb.Push(RESULT_SUCCESS);
  61. }
  62. };
  63. class IFile final : public ServiceFramework<IFile> {
  64. public:
  65. explicit IFile(std::unique_ptr<FileSys::StorageBackend>&& backend)
  66. : ServiceFramework("IFile"), backend(std::move(backend)) {
  67. static const FunctionInfo functions[] = {
  68. {0, &IFile::Read, "Read"},
  69. {1, &IFile::Write, "Write"},
  70. {2, nullptr, "Flush"},
  71. {3, &IFile::SetSize, "SetSize"},
  72. {4, &IFile::GetSize, "GetSize"},
  73. {5, nullptr, "OperateRange"},
  74. };
  75. RegisterHandlers(functions);
  76. }
  77. private:
  78. std::unique_ptr<FileSys::StorageBackend> 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%ld, length=0x%ld", 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(length);
  98. ResultVal<size_t> res = backend->Read(offset, length, output.data());
  99. if (res.Failed()) {
  100. IPC::ResponseBuilder rb{ctx, 2};
  101. rb.Push(res.Code());
  102. return;
  103. }
  104. // Write the data to memory
  105. ctx.WriteBuffer(output);
  106. IPC::ResponseBuilder rb{ctx, 4};
  107. rb.Push(RESULT_SUCCESS);
  108. rb.Push(static_cast<u64>(*res));
  109. }
  110. void Write(Kernel::HLERequestContext& ctx) {
  111. IPC::RequestParser rp{ctx};
  112. const u64 unk = rp.Pop<u64>();
  113. const s64 offset = rp.Pop<s64>();
  114. const s64 length = rp.Pop<s64>();
  115. LOG_DEBUG(Service_FS, "called, offset=0x%ld, length=0x%ld", offset, length);
  116. // Error checking
  117. if (length < 0) {
  118. IPC::ResponseBuilder rb{ctx, 2};
  119. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidLength));
  120. return;
  121. }
  122. if (offset < 0) {
  123. IPC::ResponseBuilder rb{ctx, 2};
  124. rb.Push(ResultCode(ErrorModule::FS, ErrorDescription::InvalidOffset));
  125. return;
  126. }
  127. // Write the data to the Storage backend
  128. std::vector<u8> data = ctx.ReadBuffer();
  129. ResultVal<size_t> res = backend->Write(offset, length, true, data.data());
  130. if (res.Failed()) {
  131. IPC::ResponseBuilder rb{ctx, 2};
  132. rb.Push(res.Code());
  133. return;
  134. }
  135. IPC::ResponseBuilder rb{ctx, 2};
  136. rb.Push(RESULT_SUCCESS);
  137. }
  138. void SetSize(Kernel::HLERequestContext& ctx) {
  139. IPC::RequestParser rp{ctx};
  140. const u64 size = rp.Pop<u64>();
  141. backend->SetSize(size);
  142. LOG_DEBUG(Service_FS, "called, size=%" PRIu64, size);
  143. IPC::ResponseBuilder rb{ctx, 2};
  144. rb.Push(RESULT_SUCCESS);
  145. }
  146. void GetSize(Kernel::HLERequestContext& ctx) {
  147. const u64 size = backend->GetSize();
  148. LOG_DEBUG(Service_FS, "called, size=%" PRIu64, size);
  149. IPC::ResponseBuilder rb{ctx, 4};
  150. rb.Push(RESULT_SUCCESS);
  151. rb.Push<u64>(size);
  152. }
  153. };
  154. class IDirectory final : public ServiceFramework<IDirectory> {
  155. public:
  156. explicit IDirectory(std::unique_ptr<FileSys::DirectoryBackend>&& backend)
  157. : ServiceFramework("IDirectory"), backend(std::move(backend)) {
  158. static const FunctionInfo functions[] = {
  159. {0, &IDirectory::Read, "Read"},
  160. {1, &IDirectory::GetEntryCount, "GetEntryCount"},
  161. };
  162. RegisterHandlers(functions);
  163. }
  164. private:
  165. std::unique_ptr<FileSys::DirectoryBackend> backend;
  166. void Read(Kernel::HLERequestContext& ctx) {
  167. IPC::RequestParser rp{ctx};
  168. const u64 unk = rp.Pop<u64>();
  169. LOG_DEBUG(Service_FS, "called, unk=0x%llx", unk);
  170. // Calculate how many entries we can fit in the output buffer
  171. u64 count_entries = ctx.GetWriteBufferSize() / sizeof(FileSys::Entry);
  172. // Read the data from the Directory backend
  173. std::vector<FileSys::Entry> entries(count_entries);
  174. u64 read_entries = backend->Read(count_entries, entries.data());
  175. // Convert the data into a byte array
  176. std::vector<u8> output(entries.size() * sizeof(FileSys::Entry));
  177. std::memcpy(output.data(), entries.data(), output.size());
  178. // Write the data to memory
  179. ctx.WriteBuffer(output);
  180. IPC::ResponseBuilder rb{ctx, 4};
  181. rb.Push(RESULT_SUCCESS);
  182. rb.Push(read_entries);
  183. }
  184. void GetEntryCount(Kernel::HLERequestContext& ctx) {
  185. LOG_DEBUG(Service_FS, "called");
  186. u64 count = backend->GetEntryCount();
  187. IPC::ResponseBuilder rb{ctx, 4};
  188. rb.Push(RESULT_SUCCESS);
  189. rb.Push(count);
  190. }
  191. };
  192. class IFileSystem final : public ServiceFramework<IFileSystem> {
  193. public:
  194. explicit IFileSystem(std::unique_ptr<FileSys::FileSystemBackend>&& backend)
  195. : ServiceFramework("IFileSystem"), backend(std::move(backend)) {
  196. static const FunctionInfo functions[] = {
  197. {0, &IFileSystem::CreateFile, "CreateFile"},
  198. {1, nullptr, "DeleteFile"},
  199. {2, &IFileSystem::CreateDirectory, "CreateDirectory"},
  200. {3, nullptr, "DeleteDirectory"},
  201. {4, nullptr, "DeleteDirectoryRecursively"},
  202. {5, nullptr, "RenameFile"},
  203. {6, nullptr, "RenameDirectory"},
  204. {7, &IFileSystem::GetEntryType, "GetEntryType"},
  205. {8, &IFileSystem::OpenFile, "OpenFile"},
  206. {9, &IFileSystem::OpenDirectory, "OpenDirectory"},
  207. {10, &IFileSystem::Commit, "Commit"},
  208. {11, nullptr, "GetFreeSpaceSize"},
  209. {12, nullptr, "GetTotalSpaceSize"},
  210. {13, nullptr, "CleanDirectoryRecursively"},
  211. {14, nullptr, "GetFileTimeStampRaw"},
  212. {15, nullptr, "QueryEntry"},
  213. };
  214. RegisterHandlers(functions);
  215. }
  216. void CreateFile(Kernel::HLERequestContext& ctx) {
  217. IPC::RequestParser rp{ctx};
  218. auto file_buffer = ctx.ReadBuffer();
  219. auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0');
  220. std::string name(file_buffer.begin(), end);
  221. u64 mode = rp.Pop<u64>();
  222. u32 size = rp.Pop<u32>();
  223. LOG_DEBUG(Service_FS, "called file %s mode 0x%" PRIX64 " size 0x%08X", name.c_str(), mode,
  224. size);
  225. IPC::ResponseBuilder rb{ctx, 2};
  226. rb.Push(backend->CreateFile(name, size));
  227. }
  228. void CreateDirectory(Kernel::HLERequestContext& ctx) {
  229. IPC::RequestParser rp{ctx};
  230. auto file_buffer = ctx.ReadBuffer();
  231. auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0');
  232. std::string name(file_buffer.begin(), end);
  233. LOG_DEBUG(Service_FS, "called directory %s", name.c_str());
  234. IPC::ResponseBuilder rb{ctx, 2};
  235. rb.Push(backend->CreateDirectory(name));
  236. }
  237. void OpenFile(Kernel::HLERequestContext& ctx) {
  238. IPC::RequestParser rp{ctx};
  239. auto file_buffer = ctx.ReadBuffer();
  240. auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0');
  241. std::string name(file_buffer.begin(), end);
  242. auto mode = static_cast<FileSys::Mode>(rp.Pop<u32>());
  243. LOG_DEBUG(Service_FS, "called file %s mode %u", name.c_str(), static_cast<u32>(mode));
  244. auto result = backend->OpenFile(name, mode);
  245. if (result.Failed()) {
  246. IPC::ResponseBuilder rb{ctx, 2};
  247. rb.Push(result.Code());
  248. return;
  249. }
  250. auto file = std::move(result.Unwrap());
  251. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  252. rb.Push(RESULT_SUCCESS);
  253. rb.PushIpcInterface<IFile>(std::move(file));
  254. }
  255. void OpenDirectory(Kernel::HLERequestContext& ctx) {
  256. IPC::RequestParser rp{ctx};
  257. auto file_buffer = ctx.ReadBuffer();
  258. auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0');
  259. std::string name(file_buffer.begin(), end);
  260. // TODO(Subv): Implement this filter.
  261. u32 filter_flags = rp.Pop<u32>();
  262. LOG_DEBUG(Service_FS, "called directory %s filter %u", name.c_str(), filter_flags);
  263. auto result = backend->OpenDirectory(name);
  264. if (result.Failed()) {
  265. IPC::ResponseBuilder rb{ctx, 2};
  266. rb.Push(result.Code());
  267. return;
  268. }
  269. auto directory = std::move(result.Unwrap());
  270. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  271. rb.Push(RESULT_SUCCESS);
  272. rb.PushIpcInterface<IDirectory>(std::move(directory));
  273. }
  274. void GetEntryType(Kernel::HLERequestContext& ctx) {
  275. IPC::RequestParser rp{ctx};
  276. auto file_buffer = ctx.ReadBuffer();
  277. auto end = std::find(file_buffer.begin(), file_buffer.end(), '\0');
  278. std::string name(file_buffer.begin(), end);
  279. LOG_DEBUG(Service_FS, "called file %s", name.c_str());
  280. auto result = backend->GetEntryType(name);
  281. if (result.Failed()) {
  282. IPC::ResponseBuilder rb{ctx, 2};
  283. rb.Push(result.Code());
  284. return;
  285. }
  286. IPC::ResponseBuilder rb{ctx, 3};
  287. rb.Push(RESULT_SUCCESS);
  288. rb.Push<u32>(static_cast<u32>(*result));
  289. }
  290. void Commit(Kernel::HLERequestContext& ctx) {
  291. LOG_WARNING(Service_FS, "(STUBBED) called");
  292. IPC::ResponseBuilder rb{ctx, 2};
  293. rb.Push(RESULT_SUCCESS);
  294. }
  295. private:
  296. std::unique_ptr<FileSys::FileSystemBackend> backend;
  297. };
  298. FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") {
  299. static const FunctionInfo functions[] = {
  300. {0, nullptr, "MountContent"},
  301. {1, &FSP_SRV::Initialize, "Initialize"},
  302. {2, nullptr, "OpenDataFileSystemByCurrentProcess"},
  303. {7, nullptr, "OpenFileSystemWithPatch"},
  304. {8, nullptr, "OpenFileSystemWithId"},
  305. {9, nullptr, "OpenDataFileSystemByApplicationId"},
  306. {11, nullptr, "OpenBisFileSystem"},
  307. {12, nullptr, "OpenBisStorage"},
  308. {13, nullptr, "InvalidateBisCache"},
  309. {17, nullptr, "OpenHostFileSystem"},
  310. {18, &FSP_SRV::MountSdCard, "MountSdCard"},
  311. {19, nullptr, "FormatSdCardFileSystem"},
  312. {21, nullptr, "DeleteSaveDataFileSystem"},
  313. {22, &FSP_SRV::CreateSaveData, "CreateSaveData"},
  314. {23, nullptr, "CreateSaveDataFileSystemBySystemSaveDataId"},
  315. {24, nullptr, "RegisterSaveDataFileSystemAtomicDeletion"},
  316. {25, nullptr, "DeleteSaveDataFileSystemBySaveDataSpaceId"},
  317. {26, nullptr, "FormatSdCardDryRun"},
  318. {27, nullptr, "IsExFatSupported"},
  319. {28, nullptr, "DeleteSaveDataFileSystemBySaveDataAttribute"},
  320. {30, nullptr, "OpenGameCardStorage"},
  321. {31, nullptr, "OpenGameCardFileSystem"},
  322. {32, nullptr, "ExtendSaveDataFileSystem"},
  323. {33, nullptr, "DeleteCacheStorage"},
  324. {34, nullptr, "GetCacheStorageSize"},
  325. {51, &FSP_SRV::MountSaveData, "MountSaveData"},
  326. {52, nullptr, "OpenSaveDataFileSystemBySystemSaveDataId"},
  327. {53, nullptr, "OpenReadOnlySaveDataFileSystem"},
  328. {57, nullptr, "ReadSaveDataFileSystemExtraDataBySaveDataSpaceId"},
  329. {58, nullptr, "ReadSaveDataFileSystemExtraData"},
  330. {59, nullptr, "WriteSaveDataFileSystemExtraData"},
  331. {60, nullptr, "OpenSaveDataInfoReader"},
  332. {61, nullptr, "OpenSaveDataInfoReaderBySaveDataSpaceId"},
  333. {62, nullptr, "OpenCacheStorageList"},
  334. {64, nullptr, "OpenSaveDataInternalStorageFileSystem"},
  335. {65, nullptr, "UpdateSaveDataMacForDebug"},
  336. {66, nullptr, "WriteSaveDataFileSystemExtraData2"},
  337. {80, nullptr, "OpenSaveDataMetaFile"},
  338. {81, nullptr, "OpenSaveDataTransferManager"},
  339. {82, nullptr, "OpenSaveDataTransferManagerVersion2"},
  340. {100, nullptr, "OpenImageDirectoryFileSystem"},
  341. {110, nullptr, "OpenContentStorageFileSystem"},
  342. {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"},
  343. {201, nullptr, "OpenDataStorageByProgramId"},
  344. {202, nullptr, "OpenDataStorageByDataId"},
  345. {203, &FSP_SRV::OpenRomStorage, "OpenRomStorage"},
  346. {400, nullptr, "OpenDeviceOperator"},
  347. {500, nullptr, "OpenSdCardDetectionEventNotifier"},
  348. {501, nullptr, "OpenGameCardDetectionEventNotifier"},
  349. {510, nullptr, "OpenSystemDataUpdateEventNotifier"},
  350. {511, nullptr, "NotifySystemDataUpdateEvent"},
  351. {600, nullptr, "SetCurrentPosixTime"},
  352. {601, nullptr, "QuerySaveDataTotalSize"},
  353. {602, nullptr, "VerifySaveDataFileSystem"},
  354. {603, nullptr, "CorruptSaveDataFileSystem"},
  355. {604, nullptr, "CreatePaddingFile"},
  356. {605, nullptr, "DeleteAllPaddingFiles"},
  357. {606, nullptr, "GetRightsId"},
  358. {607, nullptr, "RegisterExternalKey"},
  359. {608, nullptr, "UnregisterAllExternalKey"},
  360. {609, nullptr, "GetRightsIdByPath"},
  361. {610, nullptr, "GetRightsIdAndKeyGenerationByPath"},
  362. {611, nullptr, "SetCurrentPosixTimeWithTimeDifference"},
  363. {612, nullptr, "GetFreeSpaceSizeForSaveData"},
  364. {613, nullptr, "VerifySaveDataFileSystemBySaveDataSpaceId"},
  365. {614, nullptr, "CorruptSaveDataFileSystemBySaveDataSpaceId"},
  366. {615, nullptr, "QuerySaveDataInternalStorageTotalSize"},
  367. {620, nullptr, "SetSdCardEncryptionSeed"},
  368. {630, nullptr, "SetSdCardAccessibility"},
  369. {631, nullptr, "IsSdCardAccessible"},
  370. {640, nullptr, "IsSignedSystemPartitionOnSdCardValid"},
  371. {700, nullptr, "OpenAccessFailureResolver"},
  372. {701, nullptr, "GetAccessFailureDetectionEvent"},
  373. {702, nullptr, "IsAccessFailureDetected"},
  374. {710, nullptr, "ResolveAccessFailure"},
  375. {720, nullptr, "AbandonAccessFailure"},
  376. {800, nullptr, "GetAndClearFileSystemProxyErrorInfo"},
  377. {1000, nullptr, "SetBisRootForHost"},
  378. {1001, nullptr, "SetSaveDataSize"},
  379. {1002, nullptr, "SetSaveDataRootPath"},
  380. {1003, nullptr, "DisableAutoSaveDataCreation"},
  381. {1004, nullptr, "SetGlobalAccessLogMode"},
  382. {1005, &FSP_SRV::GetGlobalAccessLogMode, "GetGlobalAccessLogMode"},
  383. {1006, nullptr, "OutputAccessLogToSdCard"},
  384. {1007, nullptr, "RegisterUpdatePartition"},
  385. {1008, nullptr, "OpenRegisteredUpdatePartition"},
  386. {1009, nullptr, "GetAndClearMemoryReportInfo"},
  387. {1100, nullptr, "OverrideSaveDataTransferTokenSignVerificationKey"},
  388. };
  389. RegisterHandlers(functions);
  390. }
  391. void FSP_SRV::TryLoadRomFS() {
  392. if (romfs) {
  393. return;
  394. }
  395. FileSys::Path unused;
  396. auto res = OpenFileSystem(Type::RomFS, unused);
  397. if (res.Succeeded()) {
  398. romfs = std::move(res.Unwrap());
  399. }
  400. }
  401. void FSP_SRV::Initialize(Kernel::HLERequestContext& ctx) {
  402. LOG_WARNING(Service_FS, "(STUBBED) called");
  403. IPC::ResponseBuilder rb{ctx, 2};
  404. rb.Push(RESULT_SUCCESS);
  405. }
  406. void FSP_SRV::MountSdCard(Kernel::HLERequestContext& ctx) {
  407. LOG_DEBUG(Service_FS, "called");
  408. FileSys::Path unused;
  409. auto filesystem = OpenFileSystem(Type::SDMC, unused).Unwrap();
  410. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  411. rb.Push(RESULT_SUCCESS);
  412. rb.PushIpcInterface<IFileSystem>(std::move(filesystem));
  413. }
  414. void FSP_SRV::CreateSaveData(Kernel::HLERequestContext& ctx) {
  415. IPC::RequestParser rp{ctx};
  416. auto save_struct = rp.PopRaw<std::array<u8, 0x40>>();
  417. auto save_create_struct = rp.PopRaw<std::array<u8, 0x40>>();
  418. u128 uid = rp.PopRaw<u128>();
  419. LOG_WARNING(Service_FS, "(STUBBED) called uid = %016" PRIX64 "%016" PRIX64, uid[1], uid[0]);
  420. IPC::ResponseBuilder rb{ctx, 2};
  421. rb.Push(RESULT_SUCCESS);
  422. }
  423. void FSP_SRV::MountSaveData(Kernel::HLERequestContext& ctx) {
  424. LOG_WARNING(Service_FS, "(STUBBED) called");
  425. FileSys::Path unused;
  426. auto filesystem = OpenFileSystem(Type::SaveData, unused).Unwrap();
  427. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  428. rb.Push(RESULT_SUCCESS);
  429. rb.PushIpcInterface<IFileSystem>(std::move(filesystem));
  430. }
  431. void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) {
  432. LOG_WARNING(Service_FS, "(STUBBED) called");
  433. IPC::ResponseBuilder rb{ctx, 3};
  434. rb.Push(RESULT_SUCCESS);
  435. rb.Push<u32>(5);
  436. }
  437. void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) {
  438. LOG_DEBUG(Service_FS, "called");
  439. TryLoadRomFS();
  440. if (!romfs) {
  441. // TODO (bunnei): Find the right error code to use here
  442. LOG_CRITICAL(Service_FS, "no file system interface available!");
  443. IPC::ResponseBuilder rb{ctx, 2};
  444. rb.Push(ResultCode(-1));
  445. return;
  446. }
  447. // Attempt to open a StorageBackend interface to the RomFS
  448. auto storage = romfs->OpenFile({}, {});
  449. if (storage.Failed()) {
  450. LOG_CRITICAL(Service_FS, "no storage interface available!");
  451. IPC::ResponseBuilder rb{ctx, 2};
  452. rb.Push(storage.Code());
  453. return;
  454. }
  455. IPC::ResponseBuilder rb{ctx, 2, 0, 1};
  456. rb.Push(RESULT_SUCCESS);
  457. rb.PushIpcInterface<IStorage>(std::move(storage.Unwrap()));
  458. }
  459. void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) {
  460. LOG_WARNING(Service_FS, "(STUBBED) called, using OpenDataStorageByCurrentProcess");
  461. OpenDataStorageByCurrentProcess(ctx);
  462. }
  463. } // namespace FileSystem
  464. } // namespace Service