diff options
| author | 2018-08-20 20:17:57 -0400 | |
|---|---|---|
| committer | 2018-08-20 20:17:57 -0400 | |
| commit | dd70ddad7edb7cfbdddaed0ac657544a613d46e2 (patch) | |
| tree | 76145c48a1f92f64ef53ef8527df392b0fac10a6 /src | |
| parent | Merge pull request #1127 from yuzu-emu/revert-838-port-3616 (diff) | |
| parent | registration: Add Data_Unknown5 NCAContentType (diff) | |
| download | yuzu-dd70ddad7edb7cfbdddaed0ac657544a613d46e2.tar.gz yuzu-dd70ddad7edb7cfbdddaed0ac657544a613d46e2.tar.xz yuzu-dd70ddad7edb7cfbdddaed0ac657544a613d46e2.zip | |
Merge pull request #1095 from DarkLordZach/sysarchives
filesystem: Add support for loading of system archives
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/content_archive.h | 1 | ||||
| -rw-r--r-- | src/core/file_sys/registered_cache.cpp | 3 | ||||
| -rw-r--r-- | src/core/file_sys/romfs_factory.cpp | 38 | ||||
| -rw-r--r-- | src/core/file_sys/romfs_factory.h | 12 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/filesystem.cpp | 19 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/filesystem.h | 4 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp_srv.cpp | 42 | ||||
| -rw-r--r-- | src/core/hle/service/filesystem/fsp_srv.h | 1 |
8 files changed, 100 insertions, 20 deletions
diff --git a/src/core/file_sys/content_archive.h b/src/core/file_sys/content_archive.h index b82e65ad5..4b74c54ec 100644 --- a/src/core/file_sys/content_archive.h +++ b/src/core/file_sys/content_archive.h | |||
| @@ -27,6 +27,7 @@ enum class NCAContentType : u8 { | |||
| 27 | Control = 2, | 27 | Control = 2, |
| 28 | Manual = 3, | 28 | Manual = 3, |
| 29 | Data = 4, | 29 | Data = 4, |
| 30 | Data_Unknown5 = 5, ///< Seems to be used on some system archives | ||
| 30 | }; | 31 | }; |
| 31 | 32 | ||
| 32 | enum class NCASectionCryptoType : u8 { | 33 | enum class NCASectionCryptoType : u8 { |
diff --git a/src/core/file_sys/registered_cache.cpp b/src/core/file_sys/registered_cache.cpp index d25eeee34..e90dc6695 100644 --- a/src/core/file_sys/registered_cache.cpp +++ b/src/core/file_sys/registered_cache.cpp | |||
| @@ -77,12 +77,13 @@ static ContentRecordType GetCRTypeFromNCAType(NCAContentType type) { | |||
| 77 | case NCAContentType::Control: | 77 | case NCAContentType::Control: |
| 78 | return ContentRecordType::Control; | 78 | return ContentRecordType::Control; |
| 79 | case NCAContentType::Data: | 79 | case NCAContentType::Data: |
| 80 | case NCAContentType::Data_Unknown5: | ||
| 80 | return ContentRecordType::Data; | 81 | return ContentRecordType::Data; |
| 81 | case NCAContentType::Manual: | 82 | case NCAContentType::Manual: |
| 82 | // TODO(DarkLordZach): Peek at NCA contents to differentiate Manual and Legal. | 83 | // TODO(DarkLordZach): Peek at NCA contents to differentiate Manual and Legal. |
| 83 | return ContentRecordType::Manual; | 84 | return ContentRecordType::Manual; |
| 84 | default: | 85 | default: |
| 85 | UNREACHABLE(); | 86 | UNREACHABLE_MSG("Invalid NCAContentType={:02X}", static_cast<u8>(type)); |
| 86 | } | 87 | } |
| 87 | } | 88 | } |
| 88 | 89 | ||
diff --git a/src/core/file_sys/romfs_factory.cpp b/src/core/file_sys/romfs_factory.cpp index 54fbd3267..1b3824a61 100644 --- a/src/core/file_sys/romfs_factory.cpp +++ b/src/core/file_sys/romfs_factory.cpp | |||
| @@ -6,7 +6,9 @@ | |||
| 6 | #include <memory> | 6 | #include <memory> |
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.h" |
| 9 | #include "core/core.h" | ||
| 9 | #include "core/file_sys/romfs_factory.h" | 10 | #include "core/file_sys/romfs_factory.h" |
| 11 | #include "core/hle/kernel/process.h" | ||
| 10 | 12 | ||
| 11 | namespace FileSys { | 13 | namespace FileSys { |
| 12 | 14 | ||
| @@ -17,9 +19,41 @@ RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader) { | |||
| 17 | } | 19 | } |
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id) { | 22 | ResultVal<VirtualFile> RomFSFactory::OpenCurrentProcess() { |
| 21 | // TODO(DarkLordZach): Use title id. | ||
| 22 | return MakeResult<VirtualFile>(file); | 23 | return MakeResult<VirtualFile>(file); |
| 23 | } | 24 | } |
| 24 | 25 | ||
| 26 | ResultVal<VirtualFile> RomFSFactory::Open(u64 title_id, StorageId storage, ContentRecordType type) { | ||
| 27 | switch (storage) { | ||
| 28 | case StorageId::NandSystem: { | ||
| 29 | const auto res = Service::FileSystem::GetSystemNANDContents()->GetEntry(title_id, type); | ||
| 30 | if (res == nullptr) { | ||
| 31 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 32 | return ResultCode(-1); | ||
| 33 | } | ||
| 34 | const auto romfs = res->GetRomFS(); | ||
| 35 | if (romfs == nullptr) { | ||
| 36 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 37 | return ResultCode(-1); | ||
| 38 | } | ||
| 39 | return MakeResult<VirtualFile>(romfs); | ||
| 40 | } | ||
| 41 | case StorageId::NandUser: { | ||
| 42 | const auto res = Service::FileSystem::GetUserNANDContents()->GetEntry(title_id, type); | ||
| 43 | if (res == nullptr) { | ||
| 44 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 45 | return ResultCode(-1); | ||
| 46 | } | ||
| 47 | const auto romfs = res->GetRomFS(); | ||
| 48 | if (romfs == nullptr) { | ||
| 49 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 50 | return ResultCode(-1); | ||
| 51 | } | ||
| 52 | return MakeResult<VirtualFile>(romfs); | ||
| 53 | } | ||
| 54 | default: | ||
| 55 | UNIMPLEMENTED_MSG("Unimplemented storage_id={:02X}", static_cast<u8>(storage)); | ||
| 56 | } | ||
| 57 | } | ||
| 58 | |||
| 25 | } // namespace FileSys | 59 | } // namespace FileSys |
diff --git a/src/core/file_sys/romfs_factory.h b/src/core/file_sys/romfs_factory.h index c19787cd4..455cd4159 100644 --- a/src/core/file_sys/romfs_factory.h +++ b/src/core/file_sys/romfs_factory.h | |||
| @@ -11,12 +11,22 @@ | |||
| 11 | 11 | ||
| 12 | namespace FileSys { | 12 | namespace FileSys { |
| 13 | 13 | ||
| 14 | enum class StorageId : u8 { | ||
| 15 | None = 0, | ||
| 16 | Host = 1, | ||
| 17 | GameCard = 2, | ||
| 18 | NandSystem = 3, | ||
| 19 | NandUser = 4, | ||
| 20 | SdCard = 5, | ||
| 21 | }; | ||
| 22 | |||
| 14 | /// File system interface to the RomFS archive | 23 | /// File system interface to the RomFS archive |
| 15 | class RomFSFactory { | 24 | class RomFSFactory { |
| 16 | public: | 25 | public: |
| 17 | explicit RomFSFactory(Loader::AppLoader& app_loader); | 26 | explicit RomFSFactory(Loader::AppLoader& app_loader); |
| 18 | 27 | ||
| 19 | ResultVal<VirtualFile> Open(u64 title_id); | 28 | ResultVal<VirtualFile> OpenCurrentProcess(); |
| 29 | ResultVal<VirtualFile> Open(u64 title_id, StorageId storage, ContentRecordType type); | ||
| 20 | 30 | ||
| 21 | private: | 31 | private: |
| 22 | VirtualFile file; | 32 | VirtualFile file; |
diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index da658cbe6..f374111c1 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp | |||
| @@ -256,15 +256,28 @@ ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory) { | |||
| 256 | return RESULT_SUCCESS; | 256 | return RESULT_SUCCESS; |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id) { | 259 | ResultVal<FileSys::VirtualFile> OpenRomFSCurrentProcess() { |
| 260 | LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}", title_id); | 260 | LOG_TRACE(Service_FS, "Opening RomFS for current process"); |
| 261 | 261 | ||
| 262 | if (romfs_factory == nullptr) { | 262 | if (romfs_factory == nullptr) { |
| 263 | // TODO(bunnei): Find a better error code for this | 263 | // TODO(bunnei): Find a better error code for this |
| 264 | return ResultCode(-1); | 264 | return ResultCode(-1); |
| 265 | } | 265 | } |
| 266 | 266 | ||
| 267 | return romfs_factory->Open(title_id); | 267 | return romfs_factory->OpenCurrentProcess(); |
| 268 | } | ||
| 269 | |||
| 270 | ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id, | ||
| 271 | FileSys::ContentRecordType type) { | ||
| 272 | LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}, storage_id={:02X}, type={:02X}", | ||
| 273 | title_id, static_cast<u8>(storage_id), static_cast<u8>(type)); | ||
| 274 | |||
| 275 | if (romfs_factory == nullptr) { | ||
| 276 | // TODO(bunnei): Find a better error code for this | ||
| 277 | return ResultCode(-1); | ||
| 278 | } | ||
| 279 | |||
| 280 | return romfs_factory->Open(title_id, storage_id, type); | ||
| 268 | } | 281 | } |
| 269 | 282 | ||
| 270 | ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space, | 283 | ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space, |
diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index 1d6f922dd..37a2878b0 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h | |||
| @@ -27,7 +27,9 @@ ResultCode RegisterSaveData(std::unique_ptr<FileSys::SaveDataFactory>&& factory) | |||
| 27 | ResultCode RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory); | 27 | ResultCode RegisterSDMC(std::unique_ptr<FileSys::SDMCFactory>&& factory); |
| 28 | ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory); | 28 | ResultCode RegisterBIS(std::unique_ptr<FileSys::BISFactory>&& factory); |
| 29 | 29 | ||
| 30 | ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id); | 30 | ResultVal<FileSys::VirtualFile> OpenRomFSCurrentProcess(); |
| 31 | ResultVal<FileSys::VirtualFile> OpenRomFS(u64 title_id, FileSys::StorageId storage_id, | ||
| 32 | FileSys::ContentRecordType type); | ||
| 31 | ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space, | 33 | ResultVal<FileSys::VirtualDir> OpenSaveData(FileSys::SaveDataSpaceId space, |
| 32 | FileSys::SaveDataDescriptor save_struct); | 34 | FileSys::SaveDataDescriptor save_struct); |
| 33 | ResultVal<FileSys::VirtualDir> OpenSDMC(); | 35 | ResultVal<FileSys::VirtualDir> OpenSDMC(); |
diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 1470f9017..2f8a7a3c1 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp | |||
| @@ -23,15 +23,6 @@ | |||
| 23 | 23 | ||
| 24 | namespace Service::FileSystem { | 24 | namespace Service::FileSystem { |
| 25 | 25 | ||
| 26 | enum class StorageId : u8 { | ||
| 27 | None = 0, | ||
| 28 | Host = 1, | ||
| 29 | GameCard = 2, | ||
| 30 | NandSystem = 3, | ||
| 31 | NandUser = 4, | ||
| 32 | SdCard = 5, | ||
| 33 | }; | ||
| 34 | |||
| 35 | class IStorage final : public ServiceFramework<IStorage> { | 26 | class IStorage final : public ServiceFramework<IStorage> { |
| 36 | public: | 27 | public: |
| 37 | explicit IStorage(FileSys::VirtualFile backend_) | 28 | explicit IStorage(FileSys::VirtualFile backend_) |
| @@ -467,7 +458,7 @@ FSP_SRV::FSP_SRV() : ServiceFramework("fsp-srv") { | |||
| 467 | {110, nullptr, "OpenContentStorageFileSystem"}, | 458 | {110, nullptr, "OpenContentStorageFileSystem"}, |
| 468 | {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"}, | 459 | {200, &FSP_SRV::OpenDataStorageByCurrentProcess, "OpenDataStorageByCurrentProcess"}, |
| 469 | {201, nullptr, "OpenDataStorageByProgramId"}, | 460 | {201, nullptr, "OpenDataStorageByProgramId"}, |
| 470 | {202, nullptr, "OpenDataStorageByDataId"}, | 461 | {202, &FSP_SRV::OpenDataStorageByDataId, "OpenDataStorageByDataId"}, |
| 471 | {203, &FSP_SRV::OpenRomStorage, "OpenRomStorage"}, | 462 | {203, &FSP_SRV::OpenRomStorage, "OpenRomStorage"}, |
| 472 | {400, nullptr, "OpenDeviceOperator"}, | 463 | {400, nullptr, "OpenDeviceOperator"}, |
| 473 | {500, nullptr, "OpenSdCardDetectionEventNotifier"}, | 464 | {500, nullptr, "OpenSdCardDetectionEventNotifier"}, |
| @@ -580,7 +571,7 @@ void FSP_SRV::GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx) { | |||
| 580 | void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { | 571 | void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { |
| 581 | LOG_DEBUG(Service_FS, "called"); | 572 | LOG_DEBUG(Service_FS, "called"); |
| 582 | 573 | ||
| 583 | auto romfs = OpenRomFS(Core::System::GetInstance().CurrentProcess()->program_id); | 574 | auto romfs = OpenRomFSCurrentProcess(); |
| 584 | if (romfs.Failed()) { | 575 | if (romfs.Failed()) { |
| 585 | // TODO (bunnei): Find the right error code to use here | 576 | // TODO (bunnei): Find the right error code to use here |
| 586 | LOG_CRITICAL(Service_FS, "no file system interface available!"); | 577 | LOG_CRITICAL(Service_FS, "no file system interface available!"); |
| @@ -596,10 +587,37 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx) { | |||
| 596 | rb.PushIpcInterface<IStorage>(std::move(storage)); | 587 | rb.PushIpcInterface<IStorage>(std::move(storage)); |
| 597 | } | 588 | } |
| 598 | 589 | ||
| 590 | void FSP_SRV::OpenDataStorageByDataId(Kernel::HLERequestContext& ctx) { | ||
| 591 | IPC::RequestParser rp{ctx}; | ||
| 592 | const auto storage_id = rp.PopRaw<FileSys::StorageId>(); | ||
| 593 | const auto unknown = rp.PopRaw<u32>(); | ||
| 594 | const auto title_id = rp.PopRaw<u64>(); | ||
| 595 | |||
| 596 | LOG_DEBUG(Service_FS, "called with storage_id={:02X}, unknown={:08X}, title_id={:016X}", | ||
| 597 | static_cast<u8>(storage_id), unknown, title_id); | ||
| 598 | |||
| 599 | auto data = OpenRomFS(title_id, storage_id, FileSys::ContentRecordType::Data); | ||
| 600 | if (data.Failed()) { | ||
| 601 | // TODO(DarkLordZach): Find the right error code to use here | ||
| 602 | LOG_ERROR(Service_FS, | ||
| 603 | "could not open data storage with title_id={:016X}, storage_id={:02X}", title_id, | ||
| 604 | static_cast<u8>(storage_id)); | ||
| 605 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 606 | rb.Push(ResultCode(-1)); | ||
| 607 | return; | ||
| 608 | } | ||
| 609 | |||
| 610 | IStorage storage(std::move(data.Unwrap())); | ||
| 611 | |||
| 612 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | ||
| 613 | rb.Push(RESULT_SUCCESS); | ||
| 614 | rb.PushIpcInterface<IStorage>(std::move(storage)); | ||
| 615 | } | ||
| 616 | |||
| 599 | void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) { | 617 | void FSP_SRV::OpenRomStorage(Kernel::HLERequestContext& ctx) { |
| 600 | IPC::RequestParser rp{ctx}; | 618 | IPC::RequestParser rp{ctx}; |
| 601 | 619 | ||
| 602 | auto storage_id = rp.PopRaw<StorageId>(); | 620 | auto storage_id = rp.PopRaw<FileSys::StorageId>(); |
| 603 | auto title_id = rp.PopRaw<u64>(); | 621 | auto title_id = rp.PopRaw<u64>(); |
| 604 | 622 | ||
| 605 | LOG_DEBUG(Service_FS, "called with storage_id={:02X}, title_id={:016X}", | 623 | LOG_DEBUG(Service_FS, "called with storage_id={:02X}, title_id={:016X}", |
diff --git a/src/core/hle/service/filesystem/fsp_srv.h b/src/core/hle/service/filesystem/fsp_srv.h index 07f99c93d..f073ac523 100644 --- a/src/core/hle/service/filesystem/fsp_srv.h +++ b/src/core/hle/service/filesystem/fsp_srv.h | |||
| @@ -25,6 +25,7 @@ private: | |||
| 25 | void MountSaveData(Kernel::HLERequestContext& ctx); | 25 | void MountSaveData(Kernel::HLERequestContext& ctx); |
| 26 | void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); | 26 | void GetGlobalAccessLogMode(Kernel::HLERequestContext& ctx); |
| 27 | void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); | 27 | void OpenDataStorageByCurrentProcess(Kernel::HLERequestContext& ctx); |
| 28 | void OpenDataStorageByDataId(Kernel::HLERequestContext& ctx); | ||
| 28 | void OpenRomStorage(Kernel::HLERequestContext& ctx); | 29 | void OpenRomStorage(Kernel::HLERequestContext& ctx); |
| 29 | 30 | ||
| 30 | FileSys::VirtualFile romfs; | 31 | FileSys::VirtualFile romfs; |