archive.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <cstddef>
  5. #include <system_error>
  6. #include <type_traits>
  7. #include <memory>
  8. #include <unordered_map>
  9. #include <utility>
  10. #include <boost/container/flat_map.hpp>
  11. #include "common/assert.h"
  12. #include "common/common_types.h"
  13. #include "common/file_util.h"
  14. #include "common/logging/log.h"
  15. #include "common/make_unique.h"
  16. #include "core/file_sys/archive_backend.h"
  17. #include "core/file_sys/archive_extsavedata.h"
  18. #include "core/file_sys/archive_savedata.h"
  19. #include "core/file_sys/archive_savedatacheck.h"
  20. #include "core/file_sys/archive_sdmc.h"
  21. #include "core/file_sys/archive_systemsavedata.h"
  22. #include "core/file_sys/directory_backend.h"
  23. #include "core/file_sys/file_backend.h"
  24. #include "core/hle/hle.h"
  25. #include "core/hle/service/service.h"
  26. #include "core/hle/service/fs/archive.h"
  27. #include "core/hle/service/fs/fs_user.h"
  28. #include "core/hle/result.h"
  29. #include "core/memory.h"
  30. // Specializes std::hash for ArchiveIdCode, so that we can use it in std::unordered_map.
  31. // Workaroung for libstdc++ bug: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60970
  32. namespace std {
  33. template <>
  34. struct hash<Service::FS::ArchiveIdCode> {
  35. typedef Service::FS::ArchiveIdCode argument_type;
  36. typedef std::size_t result_type;
  37. result_type operator()(const argument_type& id_code) const {
  38. typedef std::underlying_type<argument_type>::type Type;
  39. return std::hash<Type>()(static_cast<Type>(id_code));
  40. }
  41. };
  42. }
  43. /// TODO(Subv): Confirm length of these strings
  44. const std::string SYSTEM_ID = "00000000000000000000000000000000";
  45. const std::string SDCARD_ID = "00000000000000000000000000000000";
  46. namespace Service {
  47. namespace FS {
  48. // TODO: Verify code
  49. /// Returned when a function is passed an invalid handle.
  50. const ResultCode ERR_INVALID_HANDLE(ErrorDescription::InvalidHandle, ErrorModule::FS,
  51. ErrorSummary::InvalidArgument, ErrorLevel::Permanent);
  52. // Command to access archive file
  53. enum class FileCommand : u32 {
  54. Dummy1 = 0x000100C6,
  55. Control = 0x040100C4,
  56. OpenSubFile = 0x08010100,
  57. Read = 0x080200C2,
  58. Write = 0x08030102,
  59. GetSize = 0x08040000,
  60. SetSize = 0x08050080,
  61. GetAttributes = 0x08060000,
  62. SetAttributes = 0x08070040,
  63. Close = 0x08080000,
  64. Flush = 0x08090000,
  65. SetPriority = 0x080A0040,
  66. GetPriority = 0x080B0000,
  67. OpenLinkFile = 0x080C0000,
  68. };
  69. // Command to access directory
  70. enum class DirectoryCommand : u32 {
  71. Dummy1 = 0x000100C6,
  72. Control = 0x040100C4,
  73. Read = 0x08010042,
  74. Close = 0x08020000,
  75. };
  76. File::File(std::unique_ptr<FileSys::FileBackend>&& backend, const FileSys::Path & path)
  77. : path(path), priority(0), backend(std::move(backend)) {}
  78. File::~File() {}
  79. ResultVal<bool> File::SyncRequest() {
  80. u32* cmd_buff = Kernel::GetCommandBuffer();
  81. FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
  82. switch (cmd) {
  83. // Read from file...
  84. case FileCommand::Read:
  85. {
  86. u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32;
  87. u32 length = cmd_buff[3];
  88. u32 address = cmd_buff[5];
  89. LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x",
  90. GetTypeName().c_str(), GetName().c_str(), offset, length, address);
  91. cmd_buff[2] = static_cast<u32>(backend->Read(offset, length, Memory::GetPointer(address)));
  92. break;
  93. }
  94. // Write to file...
  95. case FileCommand::Write:
  96. {
  97. u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32;
  98. u32 length = cmd_buff[3];
  99. u32 flush = cmd_buff[4];
  100. u32 address = cmd_buff[6];
  101. LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x",
  102. GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush);
  103. cmd_buff[2] = static_cast<u32>(backend->Write(offset, length, flush != 0, Memory::GetPointer(address)));
  104. break;
  105. }
  106. case FileCommand::GetSize:
  107. {
  108. LOG_TRACE(Service_FS, "GetSize %s %s", GetTypeName().c_str(), GetName().c_str());
  109. u64 size = backend->GetSize();
  110. cmd_buff[2] = (u32)size;
  111. cmd_buff[3] = size >> 32;
  112. break;
  113. }
  114. case FileCommand::SetSize:
  115. {
  116. u64 size = cmd_buff[1] | ((u64)cmd_buff[2] << 32);
  117. LOG_TRACE(Service_FS, "SetSize %s %s size=%llu",
  118. GetTypeName().c_str(), GetName().c_str(), size);
  119. backend->SetSize(size);
  120. break;
  121. }
  122. case FileCommand::Close:
  123. {
  124. LOG_TRACE(Service_FS, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
  125. backend->Close();
  126. break;
  127. }
  128. case FileCommand::Flush:
  129. {
  130. LOG_TRACE(Service_FS, "Flush");
  131. backend->Flush();
  132. break;
  133. }
  134. case FileCommand::OpenLinkFile:
  135. {
  136. LOG_WARNING(Service_FS, "(STUBBED) File command OpenLinkFile %s", GetName().c_str());
  137. cmd_buff[3] = Kernel::g_handle_table.Create(this).ValueOr(INVALID_HANDLE);
  138. break;
  139. }
  140. case FileCommand::SetPriority:
  141. {
  142. priority = cmd_buff[1];
  143. LOG_TRACE(Service_FS, "SetPriority %u", priority);
  144. break;
  145. }
  146. case FileCommand::GetPriority:
  147. {
  148. cmd_buff[2] = priority;
  149. LOG_TRACE(Service_FS, "GetPriority");
  150. break;
  151. }
  152. // Unknown command...
  153. default:
  154. LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd);
  155. ResultCode error = UnimplementedFunction(ErrorModule::FS);
  156. cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
  157. return error;
  158. }
  159. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  160. return MakeResult<bool>(false);
  161. }
  162. Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path & path)
  163. : path(path), backend(std::move(backend)) {}
  164. Directory::~Directory() {}
  165. ResultVal<bool> Directory::SyncRequest() {
  166. u32* cmd_buff = Kernel::GetCommandBuffer();
  167. DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
  168. switch (cmd) {
  169. // Read from directory...
  170. case DirectoryCommand::Read:
  171. {
  172. u32 count = cmd_buff[1];
  173. u32 address = cmd_buff[3];
  174. auto entries = reinterpret_cast<FileSys::Entry*>(Memory::GetPointer(address));
  175. LOG_TRACE(Service_FS, "Read %s %s: count=%d",
  176. GetTypeName().c_str(), GetName().c_str(), count);
  177. // Number of entries actually read
  178. cmd_buff[2] = backend->Read(count, entries);
  179. break;
  180. }
  181. case DirectoryCommand::Close:
  182. {
  183. LOG_TRACE(Service_FS, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
  184. backend->Close();
  185. break;
  186. }
  187. // Unknown command...
  188. default:
  189. LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd);
  190. ResultCode error = UnimplementedFunction(ErrorModule::FS);
  191. cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
  192. return MakeResult<bool>(false);
  193. }
  194. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  195. return MakeResult<bool>(false);
  196. }
  197. ////////////////////////////////////////////////////////////////////////////////////////////////////
  198. using FileSys::ArchiveBackend;
  199. using FileSys::ArchiveFactory;
  200. /**
  201. * Map of registered archives, identified by id code. Once an archive is registered here, it is
  202. * never removed until the FS service is shut down.
  203. */
  204. static boost::container::flat_map<ArchiveIdCode, std::unique_ptr<ArchiveFactory>> id_code_map;
  205. /**
  206. * Map of active archive handles. Values are pointers to the archives in `idcode_map`.
  207. */
  208. static std::unordered_map<ArchiveHandle, std::unique_ptr<ArchiveBackend>> handle_map;
  209. static ArchiveHandle next_handle;
  210. static ArchiveBackend* GetArchive(ArchiveHandle handle) {
  211. auto itr = handle_map.find(handle);
  212. return (itr == handle_map.end()) ? nullptr : itr->second.get();
  213. }
  214. ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path) {
  215. LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code);
  216. auto itr = id_code_map.find(id_code);
  217. if (itr == id_code_map.end()) {
  218. // TODO: Verify error against hardware
  219. return ResultCode(ErrorDescription::NotFound, ErrorModule::FS,
  220. ErrorSummary::NotFound, ErrorLevel::Permanent);
  221. }
  222. CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path));
  223. // This should never even happen in the first place with 64-bit handles,
  224. while (handle_map.count(next_handle) != 0) {
  225. ++next_handle;
  226. }
  227. handle_map.emplace(next_handle, std::move(res));
  228. return MakeResult<ArchiveHandle>(next_handle++);
  229. }
  230. ResultCode CloseArchive(ArchiveHandle handle) {
  231. if (handle_map.erase(handle) == 0)
  232. return ERR_INVALID_HANDLE;
  233. else
  234. return RESULT_SUCCESS;
  235. }
  236. // TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in
  237. // http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22
  238. ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factory, ArchiveIdCode id_code) {
  239. auto result = id_code_map.emplace(id_code, std::move(factory));
  240. bool inserted = result.second;
  241. ASSERT_MSG(inserted, "Tried to register more than one archive with same id code");
  242. auto& archive = result.first->second;
  243. LOG_DEBUG(Service_FS, "Registered archive %s with id code 0x%08X", archive->GetName().c_str(), id_code);
  244. return RESULT_SUCCESS;
  245. }
  246. ResultVal<Kernel::SharedPtr<File>> OpenFileFromArchive(ArchiveHandle archive_handle,
  247. const FileSys::Path& path, const FileSys::Mode mode) {
  248. ArchiveBackend* archive = GetArchive(archive_handle);
  249. if (archive == nullptr)
  250. return ERR_INVALID_HANDLE;
  251. std::unique_ptr<FileSys::FileBackend> backend = archive->OpenFile(path, mode);
  252. if (backend == nullptr) {
  253. return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS,
  254. ErrorSummary::NotFound, ErrorLevel::Status);
  255. }
  256. auto file = Kernel::SharedPtr<File>(new File(std::move(backend), path));
  257. return MakeResult<Kernel::SharedPtr<File>>(std::move(file));
  258. }
  259. ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
  260. ArchiveBackend* archive = GetArchive(archive_handle);
  261. if (archive == nullptr)
  262. return ERR_INVALID_HANDLE;
  263. if (archive->DeleteFile(path))
  264. return RESULT_SUCCESS;
  265. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
  266. ErrorSummary::Canceled, ErrorLevel::Status);
  267. }
  268. ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path,
  269. ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path) {
  270. ArchiveBackend* src_archive = GetArchive(src_archive_handle);
  271. ArchiveBackend* dest_archive = GetArchive(dest_archive_handle);
  272. if (src_archive == nullptr || dest_archive == nullptr)
  273. return ERR_INVALID_HANDLE;
  274. if (src_archive == dest_archive) {
  275. if (src_archive->RenameFile(src_path, dest_path))
  276. return RESULT_SUCCESS;
  277. } else {
  278. // TODO: Implement renaming across archives
  279. return UnimplementedFunction(ErrorModule::FS);
  280. }
  281. // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
  282. // exist or similar. Verify.
  283. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
  284. ErrorSummary::NothingHappened, ErrorLevel::Status);
  285. }
  286. ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
  287. ArchiveBackend* archive = GetArchive(archive_handle);
  288. if (archive == nullptr)
  289. return ERR_INVALID_HANDLE;
  290. if (archive->DeleteDirectory(path))
  291. return RESULT_SUCCESS;
  292. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
  293. ErrorSummary::Canceled, ErrorLevel::Status);
  294. }
  295. ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path, u64 file_size) {
  296. ArchiveBackend* archive = GetArchive(archive_handle);
  297. if (archive == nullptr)
  298. return ERR_INVALID_HANDLE;
  299. return archive->CreateFile(path, file_size);
  300. }
  301. ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
  302. ArchiveBackend* archive = GetArchive(archive_handle);
  303. if (archive == nullptr)
  304. return ERR_INVALID_HANDLE;
  305. if (archive->CreateDirectory(path))
  306. return RESULT_SUCCESS;
  307. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
  308. ErrorSummary::Canceled, ErrorLevel::Status);
  309. }
  310. ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path,
  311. ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path) {
  312. ArchiveBackend* src_archive = GetArchive(src_archive_handle);
  313. ArchiveBackend* dest_archive = GetArchive(dest_archive_handle);
  314. if (src_archive == nullptr || dest_archive == nullptr)
  315. return ERR_INVALID_HANDLE;
  316. if (src_archive == dest_archive) {
  317. if (src_archive->RenameDirectory(src_path, dest_path))
  318. return RESULT_SUCCESS;
  319. } else {
  320. // TODO: Implement renaming across archives
  321. return UnimplementedFunction(ErrorModule::FS);
  322. }
  323. // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
  324. // exist or similar. Verify.
  325. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
  326. ErrorSummary::NothingHappened, ErrorLevel::Status);
  327. }
  328. ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
  329. const FileSys::Path& path) {
  330. ArchiveBackend* archive = GetArchive(archive_handle);
  331. if (archive == nullptr)
  332. return ERR_INVALID_HANDLE;
  333. std::unique_ptr<FileSys::DirectoryBackend> backend = archive->OpenDirectory(path);
  334. if (backend == nullptr) {
  335. return ResultCode(ErrorDescription::NotFound, ErrorModule::FS,
  336. ErrorSummary::NotFound, ErrorLevel::Permanent);
  337. }
  338. auto directory = Kernel::SharedPtr<Directory>(new Directory(std::move(backend), path));
  339. return MakeResult<Kernel::SharedPtr<Directory>>(std::move(directory));
  340. }
  341. ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle) {
  342. ArchiveBackend* archive = GetArchive(archive_handle);
  343. if (archive == nullptr)
  344. return ERR_INVALID_HANDLE;
  345. return MakeResult<u64>(archive->GetFreeBytes());
  346. }
  347. ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::Path& path) {
  348. auto archive_itr = id_code_map.find(id_code);
  349. if (archive_itr == id_code_map.end()) {
  350. return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
  351. }
  352. return archive_itr->second->Format(path);
  353. }
  354. ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer, u32 icon_size) {
  355. // Construct the binary path to the archive first
  356. FileSys::Path path = FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
  357. std::string media_type_directory;
  358. if (media_type == MediaType::NAND) {
  359. media_type_directory = FileUtil::GetUserPath(D_NAND_IDX);
  360. } else if (media_type == MediaType::SDMC) {
  361. media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
  362. } else {
  363. LOG_ERROR(Service_FS, "Unsupported media type %u", media_type);
  364. return ResultCode(-1); // TODO(Subv): Find the right error code
  365. }
  366. std::string base_path = FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND);
  367. std::string game_path = FileSys::GetExtSaveDataPath(base_path, path);
  368. // These two folders are always created with the ExtSaveData
  369. std::string user_path = game_path + "user/";
  370. std::string boss_path = game_path + "boss/";
  371. if (!FileUtil::CreateFullPath(user_path))
  372. return ResultCode(-1); // TODO(Subv): Find the right error code
  373. if (!FileUtil::CreateFullPath(boss_path))
  374. return ResultCode(-1); // TODO(Subv): Find the right error code
  375. u8* smdh_icon = Memory::GetPointer(icon_buffer);
  376. if (!smdh_icon)
  377. return ResultCode(-1); // TODO(Subv): Find the right error code
  378. // Create the icon
  379. FileUtil::IOFile icon_file(game_path + "icon", "wb+");
  380. if (!icon_file.IsGood())
  381. return ResultCode(-1); // TODO(Subv): Find the right error code
  382. icon_file.WriteBytes(smdh_icon, icon_size);
  383. return RESULT_SUCCESS;
  384. }
  385. ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low) {
  386. // Construct the binary path to the archive first
  387. FileSys::Path path = FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
  388. std::string media_type_directory;
  389. if (media_type == MediaType::NAND) {
  390. media_type_directory = FileUtil::GetUserPath(D_NAND_IDX);
  391. } else if (media_type == MediaType::SDMC) {
  392. media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
  393. } else {
  394. LOG_ERROR(Service_FS, "Unsupported media type %u", media_type);
  395. return ResultCode(-1); // TODO(Subv): Find the right error code
  396. }
  397. // Delete all directories (/user, /boss) and the icon file.
  398. std::string base_path = FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND);
  399. std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path);
  400. if (!FileUtil::DeleteDirRecursively(extsavedata_path))
  401. return ResultCode(-1); // TODO(Subv): Find the right error code
  402. return RESULT_SUCCESS;
  403. }
  404. ResultCode DeleteSystemSaveData(u32 high, u32 low) {
  405. // Construct the binary path to the archive first
  406. FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
  407. std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
  408. std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
  409. std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
  410. if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
  411. return ResultCode(-1); // TODO(Subv): Find the right error code
  412. return RESULT_SUCCESS;
  413. }
  414. ResultCode CreateSystemSaveData(u32 high, u32 low) {
  415. // Construct the binary path to the archive first
  416. FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
  417. std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
  418. std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
  419. std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
  420. if (!FileUtil::CreateFullPath(systemsavedata_path))
  421. return ResultCode(-1); // TODO(Subv): Find the right error code
  422. return RESULT_SUCCESS;
  423. }
  424. /// Initialize archives
  425. void ArchiveInit() {
  426. next_handle = 1;
  427. AddService(new FS::Interface);
  428. // TODO(Subv): Add the other archive types (see here for the known types:
  429. // http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes).
  430. std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX);
  431. std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
  432. auto sdmc_factory = Common::make_unique<FileSys::ArchiveFactory_SDMC>(sdmc_directory);
  433. if (sdmc_factory->Initialize())
  434. RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC);
  435. else
  436. LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str());
  437. // Create the SaveData archive
  438. auto savedata_factory = Common::make_unique<FileSys::ArchiveFactory_SaveData>(sdmc_directory);
  439. RegisterArchiveType(std::move(savedata_factory), ArchiveIdCode::SaveData);
  440. auto extsavedata_factory = Common::make_unique<FileSys::ArchiveFactory_ExtSaveData>(sdmc_directory, false);
  441. if (extsavedata_factory->Initialize())
  442. RegisterArchiveType(std::move(extsavedata_factory), ArchiveIdCode::ExtSaveData);
  443. else
  444. LOG_ERROR(Service_FS, "Can't instantiate ExtSaveData archive with path %s", extsavedata_factory->GetMountPoint().c_str());
  445. auto sharedextsavedata_factory = Common::make_unique<FileSys::ArchiveFactory_ExtSaveData>(nand_directory, true);
  446. if (sharedextsavedata_factory->Initialize())
  447. RegisterArchiveType(std::move(sharedextsavedata_factory), ArchiveIdCode::SharedExtSaveData);
  448. else
  449. LOG_ERROR(Service_FS, "Can't instantiate SharedExtSaveData archive with path %s",
  450. sharedextsavedata_factory->GetMountPoint().c_str());
  451. // Create the SaveDataCheck archive, basically a small variation of the RomFS archive
  452. auto savedatacheck_factory = Common::make_unique<FileSys::ArchiveFactory_SaveDataCheck>(nand_directory);
  453. RegisterArchiveType(std::move(savedatacheck_factory), ArchiveIdCode::SaveDataCheck);
  454. auto systemsavedata_factory = Common::make_unique<FileSys::ArchiveFactory_SystemSaveData>(nand_directory);
  455. RegisterArchiveType(std::move(systemsavedata_factory), ArchiveIdCode::SystemSaveData);
  456. }
  457. /// Shutdown archives
  458. void ArchiveShutdown() {
  459. handle_map.clear();
  460. id_code_map.clear();
  461. }
  462. } // namespace FS
  463. } // namespace Service