archive.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  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. if (offset + length > backend->GetSize()) {
  92. LOG_ERROR(Service_FS, "Reading from out of bounds offset=0x%llX length=0x%08X file_size=0x%llX",
  93. offset, length, backend->GetSize());
  94. }
  95. ResultVal<size_t> read = backend->Read(offset, length, Memory::GetPointer(address));
  96. if (read.Failed()) {
  97. cmd_buff[1] = read.Code().raw;
  98. return read.Code();
  99. }
  100. cmd_buff[2] = static_cast<u32>(*read);
  101. break;
  102. }
  103. // Write to file...
  104. case FileCommand::Write:
  105. {
  106. u64 offset = cmd_buff[1] | ((u64)cmd_buff[2]) << 32;
  107. u32 length = cmd_buff[3];
  108. u32 flush = cmd_buff[4];
  109. u32 address = cmd_buff[6];
  110. LOG_TRACE(Service_FS, "Write %s %s: offset=0x%llx length=%d address=0x%x, flush=0x%x",
  111. GetTypeName().c_str(), GetName().c_str(), offset, length, address, flush);
  112. ResultVal<size_t> written = backend->Write(offset, length, flush != 0, Memory::GetPointer(address));
  113. if (written.Failed()) {
  114. cmd_buff[1] = written.Code().raw;
  115. return written.Code();
  116. }
  117. cmd_buff[2] = static_cast<u32>(*written);
  118. break;
  119. }
  120. case FileCommand::GetSize:
  121. {
  122. LOG_TRACE(Service_FS, "GetSize %s %s", GetTypeName().c_str(), GetName().c_str());
  123. u64 size = backend->GetSize();
  124. cmd_buff[2] = (u32)size;
  125. cmd_buff[3] = size >> 32;
  126. break;
  127. }
  128. case FileCommand::SetSize:
  129. {
  130. u64 size = cmd_buff[1] | ((u64)cmd_buff[2] << 32);
  131. LOG_TRACE(Service_FS, "SetSize %s %s size=%llu",
  132. GetTypeName().c_str(), GetName().c_str(), size);
  133. backend->SetSize(size);
  134. break;
  135. }
  136. case FileCommand::Close:
  137. {
  138. LOG_TRACE(Service_FS, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
  139. backend->Close();
  140. break;
  141. }
  142. case FileCommand::Flush:
  143. {
  144. LOG_TRACE(Service_FS, "Flush");
  145. backend->Flush();
  146. break;
  147. }
  148. case FileCommand::OpenLinkFile:
  149. {
  150. LOG_WARNING(Service_FS, "(STUBBED) File command OpenLinkFile %s", GetName().c_str());
  151. cmd_buff[3] = Kernel::g_handle_table.Create(this).ValueOr(INVALID_HANDLE);
  152. break;
  153. }
  154. case FileCommand::SetPriority:
  155. {
  156. priority = cmd_buff[1];
  157. LOG_TRACE(Service_FS, "SetPriority %u", priority);
  158. break;
  159. }
  160. case FileCommand::GetPriority:
  161. {
  162. cmd_buff[2] = priority;
  163. LOG_TRACE(Service_FS, "GetPriority");
  164. break;
  165. }
  166. // Unknown command...
  167. default:
  168. LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd);
  169. ResultCode error = UnimplementedFunction(ErrorModule::FS);
  170. cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
  171. return error;
  172. }
  173. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  174. return MakeResult<bool>(false);
  175. }
  176. Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path & path)
  177. : path(path), backend(std::move(backend)) {}
  178. Directory::~Directory() {}
  179. ResultVal<bool> Directory::SyncRequest() {
  180. u32* cmd_buff = Kernel::GetCommandBuffer();
  181. DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]);
  182. switch (cmd) {
  183. // Read from directory...
  184. case DirectoryCommand::Read:
  185. {
  186. u32 count = cmd_buff[1];
  187. u32 address = cmd_buff[3];
  188. auto entries = reinterpret_cast<FileSys::Entry*>(Memory::GetPointer(address));
  189. LOG_TRACE(Service_FS, "Read %s %s: count=%d",
  190. GetTypeName().c_str(), GetName().c_str(), count);
  191. // Number of entries actually read
  192. cmd_buff[2] = backend->Read(count, entries);
  193. break;
  194. }
  195. case DirectoryCommand::Close:
  196. {
  197. LOG_TRACE(Service_FS, "Close %s %s", GetTypeName().c_str(), GetName().c_str());
  198. backend->Close();
  199. break;
  200. }
  201. // Unknown command...
  202. default:
  203. LOG_ERROR(Service_FS, "Unknown command=0x%08X!", cmd);
  204. ResultCode error = UnimplementedFunction(ErrorModule::FS);
  205. cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
  206. return MakeResult<bool>(false);
  207. }
  208. cmd_buff[1] = RESULT_SUCCESS.raw; // No error
  209. return MakeResult<bool>(false);
  210. }
  211. ////////////////////////////////////////////////////////////////////////////////////////////////////
  212. using FileSys::ArchiveBackend;
  213. using FileSys::ArchiveFactory;
  214. /**
  215. * Map of registered archives, identified by id code. Once an archive is registered here, it is
  216. * never removed until the FS service is shut down.
  217. */
  218. static boost::container::flat_map<ArchiveIdCode, std::unique_ptr<ArchiveFactory>> id_code_map;
  219. /**
  220. * Map of active archive handles. Values are pointers to the archives in `idcode_map`.
  221. */
  222. static std::unordered_map<ArchiveHandle, std::unique_ptr<ArchiveBackend>> handle_map;
  223. static ArchiveHandle next_handle;
  224. static ArchiveBackend* GetArchive(ArchiveHandle handle) {
  225. auto itr = handle_map.find(handle);
  226. return (itr == handle_map.end()) ? nullptr : itr->second.get();
  227. }
  228. ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archive_path) {
  229. LOG_TRACE(Service_FS, "Opening archive with id code 0x%08X", id_code);
  230. auto itr = id_code_map.find(id_code);
  231. if (itr == id_code_map.end()) {
  232. // TODO: Verify error against hardware
  233. return ResultCode(ErrorDescription::NotFound, ErrorModule::FS,
  234. ErrorSummary::NotFound, ErrorLevel::Permanent);
  235. }
  236. CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path));
  237. // This should never even happen in the first place with 64-bit handles,
  238. while (handle_map.count(next_handle) != 0) {
  239. ++next_handle;
  240. }
  241. handle_map.emplace(next_handle, std::move(res));
  242. return MakeResult<ArchiveHandle>(next_handle++);
  243. }
  244. ResultCode CloseArchive(ArchiveHandle handle) {
  245. if (handle_map.erase(handle) == 0)
  246. return ERR_INVALID_HANDLE;
  247. else
  248. return RESULT_SUCCESS;
  249. }
  250. // TODO(yuriks): This might be what the fs:REG service is for. See the Register/Unregister calls in
  251. // http://3dbrew.org/wiki/Filesystem_services#ProgramRegistry_service_.22fs:REG.22
  252. ResultCode RegisterArchiveType(std::unique_ptr<FileSys::ArchiveFactory>&& factory, ArchiveIdCode id_code) {
  253. auto result = id_code_map.emplace(id_code, std::move(factory));
  254. bool inserted = result.second;
  255. ASSERT_MSG(inserted, "Tried to register more than one archive with same id code");
  256. auto& archive = result.first->second;
  257. LOG_DEBUG(Service_FS, "Registered archive %s with id code 0x%08X", archive->GetName().c_str(), id_code);
  258. return RESULT_SUCCESS;
  259. }
  260. ResultVal<Kernel::SharedPtr<File>> OpenFileFromArchive(ArchiveHandle archive_handle,
  261. const FileSys::Path& path, const FileSys::Mode mode) {
  262. ArchiveBackend* archive = GetArchive(archive_handle);
  263. if (archive == nullptr)
  264. return ERR_INVALID_HANDLE;
  265. auto backend = archive->OpenFile(path, mode);
  266. if (backend.Failed())
  267. return backend.Code();
  268. auto file = Kernel::SharedPtr<File>(new File(backend.MoveFrom(), path));
  269. return MakeResult<Kernel::SharedPtr<File>>(std::move(file));
  270. }
  271. ResultCode DeleteFileFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
  272. ArchiveBackend* archive = GetArchive(archive_handle);
  273. if (archive == nullptr)
  274. return ERR_INVALID_HANDLE;
  275. return archive->DeleteFile(path);
  276. }
  277. ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path,
  278. ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path) {
  279. ArchiveBackend* src_archive = GetArchive(src_archive_handle);
  280. ArchiveBackend* dest_archive = GetArchive(dest_archive_handle);
  281. if (src_archive == nullptr || dest_archive == nullptr)
  282. return ERR_INVALID_HANDLE;
  283. if (src_archive == dest_archive) {
  284. if (src_archive->RenameFile(src_path, dest_path))
  285. return RESULT_SUCCESS;
  286. } else {
  287. // TODO: Implement renaming across archives
  288. return UnimplementedFunction(ErrorModule::FS);
  289. }
  290. // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
  291. // exist or similar. Verify.
  292. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
  293. ErrorSummary::NothingHappened, ErrorLevel::Status);
  294. }
  295. ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
  296. ArchiveBackend* archive = GetArchive(archive_handle);
  297. if (archive == nullptr)
  298. return ERR_INVALID_HANDLE;
  299. if (archive->DeleteDirectory(path))
  300. return RESULT_SUCCESS;
  301. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
  302. ErrorSummary::Canceled, ErrorLevel::Status);
  303. }
  304. ResultCode CreateFileInArchive(ArchiveHandle archive_handle, const FileSys::Path& path, u64 file_size) {
  305. ArchiveBackend* archive = GetArchive(archive_handle);
  306. if (archive == nullptr)
  307. return ERR_INVALID_HANDLE;
  308. return archive->CreateFile(path, file_size);
  309. }
  310. ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) {
  311. ArchiveBackend* archive = GetArchive(archive_handle);
  312. if (archive == nullptr)
  313. return ERR_INVALID_HANDLE;
  314. if (archive->CreateDirectory(path))
  315. return RESULT_SUCCESS;
  316. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
  317. ErrorSummary::Canceled, ErrorLevel::Status);
  318. }
  319. ResultCode RenameDirectoryBetweenArchives(ArchiveHandle src_archive_handle, const FileSys::Path& src_path,
  320. ArchiveHandle dest_archive_handle, const FileSys::Path& dest_path) {
  321. ArchiveBackend* src_archive = GetArchive(src_archive_handle);
  322. ArchiveBackend* dest_archive = GetArchive(dest_archive_handle);
  323. if (src_archive == nullptr || dest_archive == nullptr)
  324. return ERR_INVALID_HANDLE;
  325. if (src_archive == dest_archive) {
  326. if (src_archive->RenameDirectory(src_path, dest_path))
  327. return RESULT_SUCCESS;
  328. } else {
  329. // TODO: Implement renaming across archives
  330. return UnimplementedFunction(ErrorModule::FS);
  331. }
  332. // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
  333. // exist or similar. Verify.
  334. return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
  335. ErrorSummary::NothingHappened, ErrorLevel::Status);
  336. }
  337. ResultVal<Kernel::SharedPtr<Directory>> OpenDirectoryFromArchive(ArchiveHandle archive_handle,
  338. const FileSys::Path& path) {
  339. ArchiveBackend* archive = GetArchive(archive_handle);
  340. if (archive == nullptr)
  341. return ERR_INVALID_HANDLE;
  342. std::unique_ptr<FileSys::DirectoryBackend> backend = archive->OpenDirectory(path);
  343. if (backend == nullptr) {
  344. return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS,
  345. ErrorSummary::NotFound, ErrorLevel::Permanent);
  346. }
  347. auto directory = Kernel::SharedPtr<Directory>(new Directory(std::move(backend), path));
  348. return MakeResult<Kernel::SharedPtr<Directory>>(std::move(directory));
  349. }
  350. ResultVal<u64> GetFreeBytesInArchive(ArchiveHandle archive_handle) {
  351. ArchiveBackend* archive = GetArchive(archive_handle);
  352. if (archive == nullptr)
  353. return ERR_INVALID_HANDLE;
  354. return MakeResult<u64>(archive->GetFreeBytes());
  355. }
  356. ResultCode FormatArchive(ArchiveIdCode id_code, const FileSys::ArchiveFormatInfo& format_info, const FileSys::Path& path) {
  357. auto archive_itr = id_code_map.find(id_code);
  358. if (archive_itr == id_code_map.end()) {
  359. return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
  360. }
  361. return archive_itr->second->Format(path, format_info);
  362. }
  363. ResultVal<FileSys::ArchiveFormatInfo> GetArchiveFormatInfo(ArchiveIdCode id_code, FileSys::Path& archive_path) {
  364. auto archive = id_code_map.find(id_code);
  365. if (archive == id_code_map.end()) {
  366. return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
  367. }
  368. return archive->second->GetFormatInfo(archive_path);
  369. }
  370. ResultCode CreateExtSaveData(MediaType media_type, u32 high, u32 low, VAddr icon_buffer, u32 icon_size, const FileSys::ArchiveFormatInfo& format_info) {
  371. // Construct the binary path to the archive first
  372. FileSys::Path path = FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
  373. auto archive = id_code_map.find(media_type == MediaType::NAND ? ArchiveIdCode::SharedExtSaveData : ArchiveIdCode::ExtSaveData);
  374. if (archive == id_code_map.end()) {
  375. return UnimplementedFunction(ErrorModule::FS); // TODO(Subv): Find the right error
  376. }
  377. auto ext_savedata = static_cast<FileSys::ArchiveFactory_ExtSaveData*>(archive->second.get());
  378. ResultCode result = ext_savedata->Format(path, format_info);
  379. if (result.IsError())
  380. return result;
  381. u8* smdh_icon = Memory::GetPointer(icon_buffer);
  382. if (!smdh_icon)
  383. return ResultCode(-1); // TODO(Subv): Find the right error code
  384. ext_savedata->WriteIcon(path, smdh_icon, icon_size);
  385. return RESULT_SUCCESS;
  386. }
  387. ResultCode DeleteExtSaveData(MediaType media_type, u32 high, u32 low) {
  388. // Construct the binary path to the archive first
  389. FileSys::Path path = FileSys::ConstructExtDataBinaryPath(static_cast<u32>(media_type), high, low);
  390. std::string media_type_directory;
  391. if (media_type == MediaType::NAND) {
  392. media_type_directory = FileUtil::GetUserPath(D_NAND_IDX);
  393. } else if (media_type == MediaType::SDMC) {
  394. media_type_directory = FileUtil::GetUserPath(D_SDMC_IDX);
  395. } else {
  396. LOG_ERROR(Service_FS, "Unsupported media type %u", media_type);
  397. return ResultCode(-1); // TODO(Subv): Find the right error code
  398. }
  399. // Delete all directories (/user, /boss) and the icon file.
  400. std::string base_path = FileSys::GetExtDataContainerPath(media_type_directory, media_type == MediaType::NAND);
  401. std::string extsavedata_path = FileSys::GetExtSaveDataPath(base_path, path);
  402. if (FileUtil::Exists(extsavedata_path) && !FileUtil::DeleteDirRecursively(extsavedata_path))
  403. return ResultCode(-1); // TODO(Subv): Find the right error code
  404. return RESULT_SUCCESS;
  405. }
  406. ResultCode DeleteSystemSaveData(u32 high, u32 low) {
  407. // Construct the binary path to the archive first
  408. FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
  409. std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
  410. std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
  411. std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
  412. if (!FileUtil::DeleteDirRecursively(systemsavedata_path))
  413. return ResultCode(-1); // TODO(Subv): Find the right error code
  414. return RESULT_SUCCESS;
  415. }
  416. ResultCode CreateSystemSaveData(u32 high, u32 low) {
  417. // Construct the binary path to the archive first
  418. FileSys::Path path = FileSys::ConstructSystemSaveDataBinaryPath(high, low);
  419. std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
  420. std::string base_path = FileSys::GetSystemSaveDataContainerPath(nand_directory);
  421. std::string systemsavedata_path = FileSys::GetSystemSaveDataPath(base_path, path);
  422. if (!FileUtil::CreateFullPath(systemsavedata_path))
  423. return ResultCode(-1); // TODO(Subv): Find the right error code
  424. return RESULT_SUCCESS;
  425. }
  426. /// Initialize archives
  427. void ArchiveInit() {
  428. next_handle = 1;
  429. AddService(new FS::Interface);
  430. // TODO(Subv): Add the other archive types (see here for the known types:
  431. // http://3dbrew.org/wiki/FS:OpenArchive#Archive_idcodes).
  432. std::string sdmc_directory = FileUtil::GetUserPath(D_SDMC_IDX);
  433. std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
  434. auto sdmc_factory = Common::make_unique<FileSys::ArchiveFactory_SDMC>(sdmc_directory);
  435. if (sdmc_factory->Initialize())
  436. RegisterArchiveType(std::move(sdmc_factory), ArchiveIdCode::SDMC);
  437. else
  438. LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", sdmc_directory.c_str());
  439. // Create the SaveData archive
  440. auto savedata_factory = Common::make_unique<FileSys::ArchiveFactory_SaveData>(sdmc_directory);
  441. RegisterArchiveType(std::move(savedata_factory), ArchiveIdCode::SaveData);
  442. auto extsavedata_factory = Common::make_unique<FileSys::ArchiveFactory_ExtSaveData>(sdmc_directory, false);
  443. if (extsavedata_factory->Initialize())
  444. RegisterArchiveType(std::move(extsavedata_factory), ArchiveIdCode::ExtSaveData);
  445. else
  446. LOG_ERROR(Service_FS, "Can't instantiate ExtSaveData archive with path %s", extsavedata_factory->GetMountPoint().c_str());
  447. auto sharedextsavedata_factory = Common::make_unique<FileSys::ArchiveFactory_ExtSaveData>(nand_directory, true);
  448. if (sharedextsavedata_factory->Initialize())
  449. RegisterArchiveType(std::move(sharedextsavedata_factory), ArchiveIdCode::SharedExtSaveData);
  450. else
  451. LOG_ERROR(Service_FS, "Can't instantiate SharedExtSaveData archive with path %s",
  452. sharedextsavedata_factory->GetMountPoint().c_str());
  453. // Create the SaveDataCheck archive, basically a small variation of the RomFS archive
  454. auto savedatacheck_factory = Common::make_unique<FileSys::ArchiveFactory_SaveDataCheck>(nand_directory);
  455. RegisterArchiveType(std::move(savedatacheck_factory), ArchiveIdCode::SaveDataCheck);
  456. auto systemsavedata_factory = Common::make_unique<FileSys::ArchiveFactory_SystemSaveData>(nand_directory);
  457. RegisterArchiveType(std::move(systemsavedata_factory), ArchiveIdCode::SystemSaveData);
  458. }
  459. /// Shutdown archives
  460. void ArchiveShutdown() {
  461. handle_map.clear();
  462. id_code_map.clear();
  463. }
  464. } // namespace FS
  465. } // namespace Service