diff options
| author | 2016-11-29 00:52:11 +0200 | |
|---|---|---|
| committer | 2016-11-29 23:50:00 +0200 | |
| commit | 589b6427909dfc7a4b5ee1a64cb86d38d459b0f3 (patch) | |
| tree | b6ad186dd5d10ef0aa5db9153962a1c18060f417 /src/core/file_sys | |
| parent | FS: add missing MediaType (diff) | |
| download | yuzu-589b6427909dfc7a4b5ee1a64cb86d38d459b0f3.tar.gz yuzu-589b6427909dfc7a4b5ee1a64cb86d38d459b0f3.tar.xz yuzu-589b6427909dfc7a4b5ee1a64cb86d38d459b0f3.zip | |
FileSys: Implement OtherSaveData
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/archive_other_savedata.cpp | 145 | ||||
| -rw-r--r-- | src/core/file_sys/archive_other_savedata.h | 52 | ||||
| -rw-r--r-- | src/core/file_sys/errors.h | 3 |
3 files changed, 200 insertions, 0 deletions
diff --git a/src/core/file_sys/archive_other_savedata.cpp b/src/core/file_sys/archive_other_savedata.cpp new file mode 100644 index 000000000..d3cf080da --- /dev/null +++ b/src/core/file_sys/archive_other_savedata.cpp | |||
| @@ -0,0 +1,145 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <tuple> | ||
| 6 | #include "core/file_sys/archive_other_savedata.h" | ||
| 7 | #include "core/file_sys/errors.h" | ||
| 8 | #include "core/hle/kernel/process.h" | ||
| 9 | #include "core/hle/service/fs/archive.h" | ||
| 10 | |||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 12 | // FileSys namespace | ||
| 13 | |||
| 14 | namespace FileSys { | ||
| 15 | |||
| 16 | // TODO(wwylele): The storage info in exheader should be checked before accessing these archives | ||
| 17 | |||
| 18 | using Service::FS::MediaType; | ||
| 19 | |||
| 20 | namespace { | ||
| 21 | |||
| 22 | template <typename T> | ||
| 23 | ResultVal<std::tuple<MediaType, u64>> ParsePath(const Path& path, T program_id_reader) { | ||
| 24 | if (path.GetType() != Binary) { | ||
| 25 | LOG_ERROR(Service_FS, "Wrong path type %d", static_cast<int>(path.GetType())); | ||
| 26 | return ERROR_INVALID_PATH; | ||
| 27 | } | ||
| 28 | |||
| 29 | std::vector<u8> vec_data = path.AsBinary(); | ||
| 30 | |||
| 31 | if (vec_data.size() != 12) { | ||
| 32 | LOG_ERROR(Service_FS, "Wrong path length %zu", vec_data.size()); | ||
| 33 | return ERROR_INVALID_PATH; | ||
| 34 | } | ||
| 35 | |||
| 36 | const u32* data = reinterpret_cast<const u32*>(vec_data.data()); | ||
| 37 | auto media_type = static_cast<MediaType>(data[0]); | ||
| 38 | |||
| 39 | if (media_type != MediaType::SDMC && media_type != MediaType::GameCard) { | ||
| 40 | LOG_ERROR(Service_FS, "Unsupported media type %u", static_cast<u32>(media_type)); | ||
| 41 | |||
| 42 | // Note: this is strange, but the error code was verified with a real 3DS | ||
| 43 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 44 | } | ||
| 45 | |||
| 46 | return MakeResult<std::tuple<MediaType, u64>>(media_type, program_id_reader(data)); | ||
| 47 | } | ||
| 48 | |||
| 49 | ResultVal<std::tuple<MediaType, u64>> ParsePathPermitted(const Path& path) { | ||
| 50 | return ParsePath(path, | ||
| 51 | [](const u32* data) -> u64 { return (data[1] << 8) | 0x0004000000000000ULL; }); | ||
| 52 | } | ||
| 53 | |||
| 54 | ResultVal<std::tuple<MediaType, u64>> ParsePathGeneral(const Path& path) { | ||
| 55 | return ParsePath( | ||
| 56 | path, [](const u32* data) -> u64 { return data[1] | (static_cast<u64>(data[2]) << 32); }); | ||
| 57 | } | ||
| 58 | |||
| 59 | } // namespace | ||
| 60 | |||
| 61 | ArchiveFactory_OtherSaveDataPermitted::ArchiveFactory_OtherSaveDataPermitted( | ||
| 62 | std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata) | ||
| 63 | : sd_savedata_source(sd_savedata) {} | ||
| 64 | |||
| 65 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataPermitted::Open( | ||
| 66 | const Path& path) { | ||
| 67 | MediaType media_type; | ||
| 68 | u64 program_id; | ||
| 69 | CASCADE_RESULT(std::tie(media_type, program_id), ParsePathPermitted(path)); | ||
| 70 | |||
| 71 | if (media_type == MediaType::GameCard) { | ||
| 72 | LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||
| 73 | return ERROR_GAMECARD_NOT_INSERTED; | ||
| 74 | } | ||
| 75 | |||
| 76 | return sd_savedata_source->Open(program_id); | ||
| 77 | } | ||
| 78 | |||
| 79 | ResultCode ArchiveFactory_OtherSaveDataPermitted::Format( | ||
| 80 | const Path& path, const FileSys::ArchiveFormatInfo& format_info) { | ||
| 81 | LOG_ERROR(Service_FS, "Attempted to format a OtherSaveDataPermitted archive."); | ||
| 82 | return ERROR_INVALID_PATH; | ||
| 83 | } | ||
| 84 | |||
| 85 | ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataPermitted::GetFormatInfo( | ||
| 86 | const Path& path) const { | ||
| 87 | MediaType media_type; | ||
| 88 | u64 program_id; | ||
| 89 | CASCADE_RESULT(std::tie(media_type, program_id), ParsePathPermitted(path)); | ||
| 90 | |||
| 91 | if (media_type == MediaType::GameCard) { | ||
| 92 | LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||
| 93 | return ERROR_GAMECARD_NOT_INSERTED; | ||
| 94 | } | ||
| 95 | |||
| 96 | return sd_savedata_source->GetFormatInfo(program_id); | ||
| 97 | } | ||
| 98 | |||
| 99 | ArchiveFactory_OtherSaveDataGeneral::ArchiveFactory_OtherSaveDataGeneral( | ||
| 100 | std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata) | ||
| 101 | : sd_savedata_source(sd_savedata) {} | ||
| 102 | |||
| 103 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataGeneral::Open( | ||
| 104 | const Path& path) { | ||
| 105 | MediaType media_type; | ||
| 106 | u64 program_id; | ||
| 107 | CASCADE_RESULT(std::tie(media_type, program_id), ParsePathGeneral(path)); | ||
| 108 | |||
| 109 | if (media_type == MediaType::GameCard) { | ||
| 110 | LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||
| 111 | return ERROR_GAMECARD_NOT_INSERTED; | ||
| 112 | } | ||
| 113 | |||
| 114 | return sd_savedata_source->Open(program_id); | ||
| 115 | } | ||
| 116 | |||
| 117 | ResultCode ArchiveFactory_OtherSaveDataGeneral::Format( | ||
| 118 | const Path& path, const FileSys::ArchiveFormatInfo& format_info) { | ||
| 119 | MediaType media_type; | ||
| 120 | u64 program_id; | ||
| 121 | CASCADE_RESULT(std::tie(media_type, program_id), ParsePathGeneral(path)); | ||
| 122 | |||
| 123 | if (media_type == MediaType::GameCard) { | ||
| 124 | LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||
| 125 | return ERROR_GAMECARD_NOT_INSERTED; | ||
| 126 | } | ||
| 127 | |||
| 128 | return sd_savedata_source->Format(program_id, format_info); | ||
| 129 | } | ||
| 130 | |||
| 131 | ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataGeneral::GetFormatInfo( | ||
| 132 | const Path& path) const { | ||
| 133 | MediaType media_type; | ||
| 134 | u64 program_id; | ||
| 135 | CASCADE_RESULT(std::tie(media_type, program_id), ParsePathGeneral(path)); | ||
| 136 | |||
| 137 | if (media_type == MediaType::GameCard) { | ||
| 138 | LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||
| 139 | return ERROR_GAMECARD_NOT_INSERTED; | ||
| 140 | } | ||
| 141 | |||
| 142 | return sd_savedata_source->GetFormatInfo(program_id); | ||
| 143 | } | ||
| 144 | |||
| 145 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/archive_other_savedata.h b/src/core/file_sys/archive_other_savedata.h new file mode 100644 index 000000000..d80725158 --- /dev/null +++ b/src/core/file_sys/archive_other_savedata.h | |||
| @@ -0,0 +1,52 @@ | |||
| 1 | // Copyright 2016 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "core/file_sys/archive_source_sd_savedata.h" | ||
| 8 | |||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 10 | // FileSys namespace | ||
| 11 | |||
| 12 | namespace FileSys { | ||
| 13 | |||
| 14 | /// File system interface to the OtherSaveDataPermitted archive | ||
| 15 | class ArchiveFactory_OtherSaveDataPermitted final : public ArchiveFactory { | ||
| 16 | public: | ||
| 17 | explicit ArchiveFactory_OtherSaveDataPermitted( | ||
| 18 | std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source); | ||
| 19 | |||
| 20 | std::string GetName() const override { | ||
| 21 | return "OtherSaveDataPermitted"; | ||
| 22 | } | ||
| 23 | |||
| 24 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | ||
| 25 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; | ||
| 26 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | ||
| 27 | |||
| 28 | private: | ||
| 29 | std::string mount_point; | ||
| 30 | std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source; | ||
| 31 | }; | ||
| 32 | |||
| 33 | /// File system interface to the OtherSaveDataGeneral archive | ||
| 34 | class ArchiveFactory_OtherSaveDataGeneral final : public ArchiveFactory { | ||
| 35 | public: | ||
| 36 | explicit ArchiveFactory_OtherSaveDataGeneral( | ||
| 37 | std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source); | ||
| 38 | |||
| 39 | std::string GetName() const override { | ||
| 40 | return "OtherSaveDataGeneral"; | ||
| 41 | } | ||
| 42 | |||
| 43 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | ||
| 44 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; | ||
| 45 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | ||
| 46 | |||
| 47 | private: | ||
| 48 | std::string mount_point; | ||
| 49 | std::shared_ptr<ArchiveSource_SDSaveData> sd_savedata_source; | ||
| 50 | }; | ||
| 51 | |||
| 52 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h index fd1b07df0..4d5f62b08 100644 --- a/src/core/file_sys/errors.h +++ b/src/core/file_sys/errors.h | |||
| @@ -36,5 +36,8 @@ const ResultCode ERROR_ALREADY_EXISTS(ErrorDescription::FS_AlreadyExists, ErrorM | |||
| 36 | ErrorSummary::NothingHappened, ErrorLevel::Status); | 36 | ErrorSummary::NothingHappened, ErrorLevel::Status); |
| 37 | const ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrorDescription::FS_DirectoryNotEmpty, ErrorModule::FS, | 37 | const ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrorDescription::FS_DirectoryNotEmpty, ErrorModule::FS, |
| 38 | ErrorSummary::Canceled, ErrorLevel::Status); | 38 | ErrorSummary::Canceled, ErrorLevel::Status); |
| 39 | const ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrorDescription::FS_GameCardNotInserted, | ||
| 40 | ErrorModule::FS, ErrorSummary::NotFound, | ||
| 41 | ErrorLevel::Status); | ||
| 39 | 42 | ||
| 40 | } // namespace FileSys | 43 | } // namespace FileSys |