diff options
| author | 2016-10-18 17:27:51 +0800 | |
|---|---|---|
| committer | 2016-11-19 18:55:34 +0200 | |
| commit | 098778369962f8ec5eba6ccc91b2846c72cb0005 (patch) | |
| tree | a07c47167884f8837448efb9ff7de9fe3f5c0f61 | |
| parent | FileSys: add SDMCArchive (diff) | |
| download | yuzu-098778369962f8ec5eba6ccc91b2846c72cb0005.tar.gz yuzu-098778369962f8ec5eba6ccc91b2846c72cb0005.tar.xz yuzu-098778369962f8ec5eba6ccc91b2846c72cb0005.zip | |
FileSys: add SDMCWriteOnlyArchive
Diffstat (limited to '')
| -rw-r--r-- | src/core/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmcwriteonly.cpp | 70 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmcwriteonly.h | 57 | ||||
| -rw-r--r-- | src/core/file_sys/errors.h | 2 | ||||
| -rw-r--r-- | src/core/hle/result.h | 1 | ||||
| -rw-r--r-- | src/core/hle/service/fs/archive.cpp | 8 |
6 files changed, 140 insertions, 0 deletions
diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index 63a402ad0..1ecd1c431 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt | |||
| @@ -21,6 +21,7 @@ set(SRCS | |||
| 21 | file_sys/archive_savedata.cpp | 21 | file_sys/archive_savedata.cpp |
| 22 | file_sys/archive_savedatacheck.cpp | 22 | file_sys/archive_savedatacheck.cpp |
| 23 | file_sys/archive_sdmc.cpp | 23 | file_sys/archive_sdmc.cpp |
| 24 | file_sys/archive_sdmcwriteonly.cpp | ||
| 24 | file_sys/archive_systemsavedata.cpp | 25 | file_sys/archive_systemsavedata.cpp |
| 25 | file_sys/disk_archive.cpp | 26 | file_sys/disk_archive.cpp |
| 26 | file_sys/ivfc_archive.cpp | 27 | file_sys/ivfc_archive.cpp |
| @@ -165,6 +166,7 @@ set(HEADERS | |||
| 165 | file_sys/archive_savedata.h | 166 | file_sys/archive_savedata.h |
| 166 | file_sys/archive_savedatacheck.h | 167 | file_sys/archive_savedatacheck.h |
| 167 | file_sys/archive_sdmc.h | 168 | file_sys/archive_sdmc.h |
| 169 | file_sys/archive_sdmcwriteonly.h | ||
| 168 | file_sys/archive_systemsavedata.h | 170 | file_sys/archive_systemsavedata.h |
| 169 | file_sys/directory_backend.h | 171 | file_sys/directory_backend.h |
| 170 | file_sys/disk_archive.h | 172 | file_sys/disk_archive.h |
diff --git a/src/core/file_sys/archive_sdmcwriteonly.cpp b/src/core/file_sys/archive_sdmcwriteonly.cpp new file mode 100644 index 000000000..64ae49b86 --- /dev/null +++ b/src/core/file_sys/archive_sdmcwriteonly.cpp | |||
| @@ -0,0 +1,70 @@ | |||
| 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 <memory> | ||
| 6 | #include "common/file_util.h" | ||
| 7 | #include "core/file_sys/archive_sdmcwriteonly.h" | ||
| 8 | #include "core/file_sys/directory_backend.h" | ||
| 9 | #include "core/file_sys/errors.h" | ||
| 10 | #include "core/file_sys/file_backend.h" | ||
| 11 | #include "core/settings.h" | ||
| 12 | |||
| 13 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 14 | // FileSys namespace | ||
| 15 | |||
| 16 | namespace FileSys { | ||
| 17 | |||
| 18 | ResultVal<std::unique_ptr<FileBackend>> SDMCWriteOnlyArchive::OpenFile(const Path& path, | ||
| 19 | const Mode& mode) const { | ||
| 20 | if (mode.read_flag) { | ||
| 21 | LOG_ERROR(Service_FS, "Read flag is not supported"); | ||
| 22 | return ERROR_INVALID_READ_FLAG; | ||
| 23 | } | ||
| 24 | return SDMCArchive::OpenFile(path, mode); | ||
| 25 | } | ||
| 26 | |||
| 27 | ResultVal<std::unique_ptr<DirectoryBackend>> SDMCWriteOnlyArchive::OpenDirectory( | ||
| 28 | const Path& path) const { | ||
| 29 | LOG_ERROR(Service_FS, "Not supported"); | ||
| 30 | return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||
| 31 | } | ||
| 32 | |||
| 33 | ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly(const std::string& mount_point) | ||
| 34 | : sdmc_directory(mount_point) { | ||
| 35 | LOG_INFO(Service_FS, "Directory %s set as SDMCWriteOnly.", sdmc_directory.c_str()); | ||
| 36 | } | ||
| 37 | |||
| 38 | bool ArchiveFactory_SDMCWriteOnly::Initialize() { | ||
| 39 | if (!Settings::values.use_virtual_sd) { | ||
| 40 | LOG_WARNING(Service_FS, "SDMC disabled by config."); | ||
| 41 | return false; | ||
| 42 | } | ||
| 43 | |||
| 44 | if (!FileUtil::CreateFullPath(sdmc_directory)) { | ||
| 45 | LOG_ERROR(Service_FS, "Unable to create SDMC path."); | ||
| 46 | return false; | ||
| 47 | } | ||
| 48 | |||
| 49 | return true; | ||
| 50 | } | ||
| 51 | |||
| 52 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMCWriteOnly::Open(const Path& path) { | ||
| 53 | auto archive = std::make_unique<SDMCWriteOnlyArchive>(sdmc_directory); | ||
| 54 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | ||
| 55 | } | ||
| 56 | |||
| 57 | ResultCode ArchiveFactory_SDMCWriteOnly::Format(const Path& path, | ||
| 58 | const FileSys::ArchiveFormatInfo& format_info) { | ||
| 59 | // TODO(wwylele): hwtest this | ||
| 60 | LOG_ERROR(Service_FS, "Attempted to format a SDMC write-only archive."); | ||
| 61 | return ResultCode(-1); | ||
| 62 | } | ||
| 63 | |||
| 64 | ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMCWriteOnly::GetFormatInfo(const Path& path) const { | ||
| 65 | // TODO(Subv): Implement | ||
| 66 | LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str()); | ||
| 67 | return ResultCode(-1); | ||
| 68 | } | ||
| 69 | |||
| 70 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/archive_sdmcwriteonly.h b/src/core/file_sys/archive_sdmcwriteonly.h new file mode 100644 index 000000000..ed977485a --- /dev/null +++ b/src/core/file_sys/archive_sdmcwriteonly.h | |||
| @@ -0,0 +1,57 @@ | |||
| 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_sdmc.h" | ||
| 8 | |||
| 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// | ||
| 10 | // FileSys namespace | ||
| 11 | |||
| 12 | namespace FileSys { | ||
| 13 | |||
| 14 | /** | ||
| 15 | * Archive backend for SDMC write-only archive. | ||
| 16 | * The behaviour of SDMCWriteOnlyArchive is almost the same as SDMCArchive, except for | ||
| 17 | * - OpenDirectory is unsupported; | ||
| 18 | * - OpenFile with read flag is unsupported. | ||
| 19 | */ | ||
| 20 | class SDMCWriteOnlyArchive : public SDMCArchive { | ||
| 21 | public: | ||
| 22 | SDMCWriteOnlyArchive(const std::string& mount_point) : SDMCArchive(mount_point) {} | ||
| 23 | |||
| 24 | std::string GetName() const override { | ||
| 25 | return "SDMCWriteOnlyArchive: " + mount_point; | ||
| 26 | } | ||
| 27 | |||
| 28 | ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, | ||
| 29 | const Mode& mode) const override; | ||
| 30 | |||
| 31 | ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override; | ||
| 32 | }; | ||
| 33 | |||
| 34 | /// File system interface to the SDMC write-only archive | ||
| 35 | class ArchiveFactory_SDMCWriteOnly final : public ArchiveFactory { | ||
| 36 | public: | ||
| 37 | ArchiveFactory_SDMCWriteOnly(const std::string& mount_point); | ||
| 38 | |||
| 39 | /** | ||
| 40 | * Initialize the archive. | ||
| 41 | * @return true if it initialized successfully | ||
| 42 | */ | ||
| 43 | bool Initialize(); | ||
| 44 | |||
| 45 | std::string GetName() const override { | ||
| 46 | return "SDMCWriteOnly"; | ||
| 47 | } | ||
| 48 | |||
| 49 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | ||
| 50 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; | ||
| 51 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | ||
| 52 | |||
| 53 | private: | ||
| 54 | std::string sdmc_directory; | ||
| 55 | }; | ||
| 56 | |||
| 57 | } // namespace FileSys | ||
diff --git a/src/core/file_sys/errors.h b/src/core/file_sys/errors.h index f9299364c..fd1b07df0 100644 --- a/src/core/file_sys/errors.h +++ b/src/core/file_sys/errors.h | |||
| @@ -13,6 +13,8 @@ const ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ErrorDescription::FS_UnsupportedOp | |||
| 13 | ErrorLevel::Usage); | 13 | ErrorLevel::Usage); |
| 14 | const ResultCode ERROR_INVALID_OPEN_FLAGS(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, | 14 | const ResultCode ERROR_INVALID_OPEN_FLAGS(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, |
| 15 | ErrorSummary::Canceled, ErrorLevel::Status); | 15 | ErrorSummary::Canceled, ErrorLevel::Status); |
| 16 | const ResultCode ERROR_INVALID_READ_FLAG(ErrorDescription::FS_InvalidReadFlag, ErrorModule::FS, | ||
| 17 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 16 | const ResultCode ERROR_FILE_NOT_FOUND(ErrorDescription::FS_FileNotFound, ErrorModule::FS, | 18 | const ResultCode ERROR_FILE_NOT_FOUND(ErrorDescription::FS_FileNotFound, ErrorModule::FS, |
| 17 | ErrorSummary::NotFound, ErrorLevel::Status); | 19 | ErrorSummary::NotFound, ErrorLevel::Status); |
| 18 | const ResultCode ERROR_PATH_NOT_FOUND(ErrorDescription::FS_PathNotFound, ErrorModule::FS, | 20 | const ResultCode ERROR_PATH_NOT_FOUND(ErrorDescription::FS_PathNotFound, ErrorModule::FS, |
diff --git a/src/core/hle/result.h b/src/core/hle/result.h index a355f970a..f7356f9d8 100644 --- a/src/core/hle/result.h +++ b/src/core/hle/result.h | |||
| @@ -33,6 +33,7 @@ enum class ErrorDescription : u32 { | |||
| 33 | OutofRangeOrMisalignedAddress = | 33 | OutofRangeOrMisalignedAddress = |
| 34 | 513, // TODO(purpasmart): Check if this name fits its actual usage | 34 | 513, // TODO(purpasmart): Check if this name fits its actual usage |
| 35 | GPU_FirstInitialization = 519, | 35 | GPU_FirstInitialization = 519, |
| 36 | FS_InvalidReadFlag = 700, | ||
| 36 | FS_InvalidPath = 702, | 37 | FS_InvalidPath = 702, |
| 37 | FS_WriteBeyondEnd = 705, | 38 | FS_WriteBeyondEnd = 705, |
| 38 | FS_UnsupportedOpenFlags = 760, | 39 | FS_UnsupportedOpenFlags = 760, |
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 891d7bc84..62cf2c249 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp | |||
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "core/file_sys/archive_savedata.h" | 18 | #include "core/file_sys/archive_savedata.h" |
| 19 | #include "core/file_sys/archive_savedatacheck.h" | 19 | #include "core/file_sys/archive_savedatacheck.h" |
| 20 | #include "core/file_sys/archive_sdmc.h" | 20 | #include "core/file_sys/archive_sdmc.h" |
| 21 | #include "core/file_sys/archive_sdmcwriteonly.h" | ||
| 21 | #include "core/file_sys/archive_systemsavedata.h" | 22 | #include "core/file_sys/archive_systemsavedata.h" |
| 22 | #include "core/file_sys/directory_backend.h" | 23 | #include "core/file_sys/directory_backend.h" |
| 23 | #include "core/file_sys/file_backend.h" | 24 | #include "core/file_sys/file_backend.h" |
| @@ -526,6 +527,13 @@ void RegisterArchiveTypes() { | |||
| 526 | LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", | 527 | LOG_ERROR(Service_FS, "Can't instantiate SDMC archive with path %s", |
| 527 | sdmc_directory.c_str()); | 528 | sdmc_directory.c_str()); |
| 528 | 529 | ||
| 530 | auto sdmcwo_factory = std::make_unique<FileSys::ArchiveFactory_SDMCWriteOnly>(sdmc_directory); | ||
| 531 | if (sdmcwo_factory->Initialize()) | ||
| 532 | RegisterArchiveType(std::move(sdmcwo_factory), ArchiveIdCode::SDMCWriteOnly); | ||
| 533 | else | ||
| 534 | LOG_ERROR(Service_FS, "Can't instantiate SDMCWriteOnly archive with path %s", | ||
| 535 | sdmc_directory.c_str()); | ||
| 536 | |||
| 529 | // Create the SaveData archive | 537 | // Create the SaveData archive |
| 530 | auto savedata_factory = std::make_unique<FileSys::ArchiveFactory_SaveData>(sdmc_directory); | 538 | auto savedata_factory = std::make_unique<FileSys::ArchiveFactory_SaveData>(sdmc_directory); |
| 531 | RegisterArchiveType(std::move(savedata_factory), ArchiveIdCode::SaveData); | 539 | RegisterArchiveType(std::move(savedata_factory), ArchiveIdCode::SaveData); |