diff options
| author | 2016-03-20 16:11:49 -0400 | |
|---|---|---|
| committer | 2016-03-20 16:11:49 -0400 | |
| commit | b83e95727f95fa6fe35d436be3e821605244a6a8 (patch) | |
| tree | 64255c7432e882205a2dbea1fe962025863664ee /src/core/file_sys | |
| parent | Merge pull request #1550 from LittleWhite-tb/gdbstub_include_fix (diff) | |
| parent | HLE/FS: Change the error code returned when an ExtSaveData archive is not found. (diff) | |
| download | yuzu-b83e95727f95fa6fe35d436be3e821605244a6a8.tar.gz yuzu-b83e95727f95fa6fe35d436be3e821605244a6a8.tar.xz yuzu-b83e95727f95fa6fe35d436be3e821605244a6a8.zip | |
Merge pull request #1302 from Subv/save_fix
HLE/FS: Fixed many corner cases in our file handling
Diffstat (limited to 'src/core/file_sys')
| -rw-r--r-- | src/core/file_sys/archive_backend.h | 29 | ||||
| -rw-r--r-- | src/core/file_sys/archive_extsavedata.cpp | 48 | ||||
| -rw-r--r-- | src/core/file_sys/archive_extsavedata.h | 12 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 8 | ||||
| -rw-r--r-- | src/core/file_sys/archive_romfs.h | 3 | ||||
| -rw-r--r-- | src/core/file_sys/archive_savedata.cpp | 36 | ||||
| -rw-r--r-- | src/core/file_sys/archive_savedata.h | 4 | ||||
| -rw-r--r-- | src/core/file_sys/archive_savedatacheck.cpp | 8 | ||||
| -rw-r--r-- | src/core/file_sys/archive_savedatacheck.h | 3 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.cpp | 7 | ||||
| -rw-r--r-- | src/core/file_sys/archive_sdmc.h | 3 | ||||
| -rw-r--r-- | src/core/file_sys/archive_systemsavedata.cpp | 8 | ||||
| -rw-r--r-- | src/core/file_sys/archive_systemsavedata.h | 3 | ||||
| -rw-r--r-- | src/core/file_sys/disk_archive.cpp | 80 | ||||
| -rw-r--r-- | src/core/file_sys/disk_archive.h | 12 | ||||
| -rw-r--r-- | src/core/file_sys/file_backend.h | 13 | ||||
| -rw-r--r-- | src/core/file_sys/ivfc_archive.cpp | 21 | ||||
| -rw-r--r-- | src/core/file_sys/ivfc_archive.h | 12 |
18 files changed, 236 insertions, 74 deletions
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 601e95d8c..5d91e47f3 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h | |||
| @@ -11,6 +11,7 @@ | |||
| 11 | 11 | ||
| 12 | #include "common/bit_field.h" | 12 | #include "common/bit_field.h" |
| 13 | #include "common/common_types.h" | 13 | #include "common/common_types.h" |
| 14 | #include "common/swap.h" | ||
| 14 | 15 | ||
| 15 | #include "core/hle/result.h" | 16 | #include "core/hle/result.h" |
| 16 | 17 | ||
| @@ -62,6 +63,14 @@ private: | |||
| 62 | std::u16string u16str; | 63 | std::u16string u16str; |
| 63 | }; | 64 | }; |
| 64 | 65 | ||
| 66 | struct ArchiveFormatInfo { | ||
| 67 | u32_le total_size; ///< The pre-defined size of the archive, as specified in the Create or Format call | ||
| 68 | u32_le number_directories; ///< The pre-defined number of directories in the archive, as specified in the Create or Format call | ||
| 69 | u32_le number_files; ///< The pre-defined number of files in the archive, as specified in the Create or Format call | ||
| 70 | u8 duplicate_data; ///< Whether the archive should duplicate the data, as specified in the Create or Format call | ||
| 71 | }; | ||
| 72 | static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD"); | ||
| 73 | |||
| 65 | class ArchiveBackend : NonCopyable { | 74 | class ArchiveBackend : NonCopyable { |
| 66 | public: | 75 | public: |
| 67 | virtual ~ArchiveBackend() { | 76 | virtual ~ArchiveBackend() { |
| @@ -76,16 +85,16 @@ public: | |||
| 76 | * Open a file specified by its path, using the specified mode | 85 | * Open a file specified by its path, using the specified mode |
| 77 | * @param path Path relative to the archive | 86 | * @param path Path relative to the archive |
| 78 | * @param mode Mode to open the file with | 87 | * @param mode Mode to open the file with |
| 79 | * @return Opened file, or nullptr | 88 | * @return Opened file, or error code |
| 80 | */ | 89 | */ |
| 81 | virtual std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const = 0; | 90 | virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode mode) const = 0; |
| 82 | 91 | ||
| 83 | /** | 92 | /** |
| 84 | * Delete a file specified by its path | 93 | * Delete a file specified by its path |
| 85 | * @param path Path relative to the archive | 94 | * @param path Path relative to the archive |
| 86 | * @return Whether the file could be deleted | 95 | * @return Result of the operation |
| 87 | */ | 96 | */ |
| 88 | virtual bool DeleteFile(const Path& path) const = 0; | 97 | virtual ResultCode DeleteFile(const Path& path) const = 0; |
| 89 | 98 | ||
| 90 | /** | 99 | /** |
| 91 | * Rename a File specified by its path | 100 | * Rename a File specified by its path |
| @@ -108,7 +117,7 @@ public: | |||
| 108 | * @param size The size of the new file, filled with zeroes | 117 | * @param size The size of the new file, filled with zeroes |
| 109 | * @return File creation result code | 118 | * @return File creation result code |
| 110 | */ | 119 | */ |
| 111 | virtual ResultCode CreateFile(const Path& path, u32 size) const = 0; | 120 | virtual ResultCode CreateFile(const Path& path, u64 size) const = 0; |
| 112 | 121 | ||
| 113 | /** | 122 | /** |
| 114 | * Create a directory specified by its path | 123 | * Create a directory specified by its path |
| @@ -159,9 +168,17 @@ public: | |||
| 159 | /** | 168 | /** |
| 160 | * Deletes the archive contents and then re-creates the base folder | 169 | * Deletes the archive contents and then re-creates the base folder |
| 161 | * @param path Path to the archive | 170 | * @param path Path to the archive |
| 171 | * @param format_info Format information for the new archive | ||
| 162 | * @return ResultCode of the operation, 0 on success | 172 | * @return ResultCode of the operation, 0 on success |
| 163 | */ | 173 | */ |
| 164 | virtual ResultCode Format(const Path& path) = 0; | 174 | virtual ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) = 0; |
| 175 | |||
| 176 | /** | ||
| 177 | * Retrieves the format info about the archive with the specified path | ||
| 178 | * @param path Path to the archive | ||
| 179 | * @return Format information about the archive or error code | ||
| 180 | */ | ||
| 181 | virtual ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const = 0; | ||
| 165 | }; | 182 | }; |
| 166 | 183 | ||
| 167 | } // namespace FileSys | 184 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index 92dad8e6f..961264fe5 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp | |||
| @@ -58,7 +58,7 @@ Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) { | |||
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, bool shared) | 60 | ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, bool shared) |
| 61 | : mount_point(GetExtDataContainerPath(mount_location, shared)) { | 61 | : shared(shared), mount_point(GetExtDataContainerPath(mount_location, shared)) { |
| 62 | LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str()); | 62 | LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str()); |
| 63 | } | 63 | } |
| 64 | 64 | ||
| @@ -74,21 +74,59 @@ bool ArchiveFactory_ExtSaveData::Initialize() { | |||
| 74 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(const Path& path) { | 74 | ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(const Path& path) { |
| 75 | std::string fullpath = GetExtSaveDataPath(mount_point, path) + "user/"; | 75 | std::string fullpath = GetExtSaveDataPath(mount_point, path) + "user/"; |
| 76 | if (!FileUtil::Exists(fullpath)) { | 76 | if (!FileUtil::Exists(fullpath)) { |
| 77 | // TODO(Subv): Check error code, this one is probably wrong | 77 | // TODO(Subv): Verify the archive behavior of SharedExtSaveData compared to ExtSaveData. |
| 78 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, | 78 | // ExtSaveData seems to return FS_NotFound (120) when the archive doesn't exist. |
| 79 | ErrorSummary::InvalidState, ErrorLevel::Status); | 79 | if (!shared) { |
| 80 | return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, | ||
| 81 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 82 | } else { | ||
| 83 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, | ||
| 84 | ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 85 | } | ||
| 80 | } | 86 | } |
| 81 | auto archive = Common::make_unique<DiskArchive>(fullpath); | 87 | auto archive = Common::make_unique<DiskArchive>(fullpath); |
| 82 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | 88 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); |
| 83 | } | 89 | } |
| 84 | 90 | ||
| 85 | ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path) { | 91 | ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { |
| 86 | // These folders are always created with the ExtSaveData | 92 | // These folders are always created with the ExtSaveData |
| 87 | std::string user_path = GetExtSaveDataPath(mount_point, path) + "user/"; | 93 | std::string user_path = GetExtSaveDataPath(mount_point, path) + "user/"; |
| 88 | std::string boss_path = GetExtSaveDataPath(mount_point, path) + "boss/"; | 94 | std::string boss_path = GetExtSaveDataPath(mount_point, path) + "boss/"; |
| 89 | FileUtil::CreateFullPath(user_path); | 95 | FileUtil::CreateFullPath(user_path); |
| 90 | FileUtil::CreateFullPath(boss_path); | 96 | FileUtil::CreateFullPath(boss_path); |
| 97 | |||
| 98 | // Write the format metadata | ||
| 99 | std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; | ||
| 100 | FileUtil::IOFile file(metadata_path, "wb"); | ||
| 101 | |||
| 102 | if (!file.IsOpen()) { | ||
| 103 | // TODO(Subv): Find the correct error code | ||
| 104 | return ResultCode(-1); | ||
| 105 | } | ||
| 106 | |||
| 107 | file.WriteBytes(&format_info, sizeof(format_info)); | ||
| 91 | return RESULT_SUCCESS; | 108 | return RESULT_SUCCESS; |
| 92 | } | 109 | } |
| 93 | 110 | ||
| 111 | ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Path& path) const { | ||
| 112 | std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; | ||
| 113 | FileUtil::IOFile file(metadata_path, "rb"); | ||
| 114 | |||
| 115 | if (!file.IsOpen()) { | ||
| 116 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); | ||
| 117 | // TODO(Subv): Verify error code | ||
| 118 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 119 | } | ||
| 120 | |||
| 121 | ArchiveFormatInfo info = {}; | ||
| 122 | file.ReadBytes(&info, sizeof(info)); | ||
| 123 | return MakeResult<ArchiveFormatInfo>(info); | ||
| 124 | } | ||
| 125 | |||
| 126 | void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, size_t icon_size) { | ||
| 127 | std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path); | ||
| 128 | FileUtil::IOFile icon_file(game_path + "icon", "wb"); | ||
| 129 | icon_file.WriteBytes(icon_data, icon_size); | ||
| 130 | } | ||
| 131 | |||
| 94 | } // namespace FileSys | 132 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h index ec8d770fc..287a6fee1 100644 --- a/src/core/file_sys/archive_extsavedata.h +++ b/src/core/file_sys/archive_extsavedata.h | |||
| @@ -31,10 +31,19 @@ public: | |||
| 31 | std::string GetName() const override { return "ExtSaveData"; } | 31 | std::string GetName() const override { return "ExtSaveData"; } |
| 32 | 32 | ||
| 33 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | 33 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; |
| 34 | ResultCode Format(const Path& path) override; | 34 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; |
| 35 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | ||
| 35 | 36 | ||
| 36 | const std::string& GetMountPoint() const { return mount_point; } | 37 | const std::string& GetMountPoint() const { return mount_point; } |
| 37 | 38 | ||
| 39 | /** | ||
| 40 | * Writes the SMDH icon of the ExtSaveData to file | ||
| 41 | * @param path Path of this ExtSaveData | ||
| 42 | * @param icon_data Binary data of the icon | ||
| 43 | * @param icon_size Size of the icon data | ||
| 44 | */ | ||
| 45 | void WriteIcon(const Path& path, const u8* icon_data, size_t icon_size); | ||
| 46 | |||
| 38 | private: | 47 | private: |
| 39 | /** | 48 | /** |
| 40 | * This holds the full directory path for this archive, it is only set after a successful call | 49 | * This holds the full directory path for this archive, it is only set after a successful call |
| @@ -42,6 +51,7 @@ private: | |||
| 42 | * See GetExtSaveDataPath for the code that extracts this data from an archive path. | 51 | * See GetExtSaveDataPath for the code that extracts this data from an archive path. |
| 43 | */ | 52 | */ |
| 44 | std::string mount_point; | 53 | std::string mount_point; |
| 54 | bool shared; ///< Whether this archive represents an ExtSaveData archive or a SharedExtSaveData archive | ||
| 45 | }; | 55 | }; |
| 46 | 56 | ||
| 47 | /** | 57 | /** |
diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp index 696b51a94..a9a29ebde 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp | |||
| @@ -29,11 +29,17 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path | |||
| 29 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | 29 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | ResultCode ArchiveFactory_RomFS::Format(const Path& path) { | 32 | ResultCode ArchiveFactory_RomFS::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { |
| 33 | LOG_ERROR(Service_FS, "Attempted to format a RomFS archive."); | 33 | LOG_ERROR(Service_FS, "Attempted to format a RomFS archive."); |
| 34 | // TODO: Verify error code | 34 | // TODO: Verify error code |
| 35 | return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, | 35 | return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, |
| 36 | ErrorSummary::NotSupported, ErrorLevel::Permanent); | 36 | ErrorSummary::NotSupported, ErrorLevel::Permanent); |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | ResultVal<ArchiveFormatInfo> ArchiveFactory_RomFS::GetFormatInfo(const Path& path) const { | ||
| 40 | // TODO(Subv): Implement | ||
| 41 | LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str()); | ||
| 42 | return ResultCode(-1); | ||
| 43 | } | ||
| 44 | |||
| 39 | } // namespace FileSys | 45 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h index 2bedfa9c6..c5a329122 100644 --- a/src/core/file_sys/archive_romfs.h +++ b/src/core/file_sys/archive_romfs.h | |||
| @@ -26,7 +26,8 @@ public: | |||
| 26 | 26 | ||
| 27 | std::string GetName() const override { return "RomFS"; } | 27 | std::string GetName() const override { return "RomFS"; } |
| 28 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | 28 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; |
| 29 | ResultCode Format(const Path& path) override; | 29 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; |
| 30 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | ||
| 30 | 31 | ||
| 31 | private: | 32 | private: |
| 32 | std::shared_ptr<FileUtil::IOFile> romfs_file; | 33 | std::shared_ptr<FileUtil::IOFile> romfs_file; |
diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp index 12876899f..fe020d21c 100644 --- a/src/core/file_sys/archive_savedata.cpp +++ b/src/core/file_sys/archive_savedata.cpp | |||
| @@ -26,11 +26,17 @@ static std::string GetSaveDataContainerPath(const std::string& sdmc_directory) { | |||
| 26 | } | 26 | } |
| 27 | 27 | ||
| 28 | static std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) { | 28 | static std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) { |
| 29 | u32 high = program_id >> 32; | 29 | u32 high = (u32)(program_id >> 32); |
| 30 | u32 low = program_id & 0xFFFFFFFF; | 30 | u32 low = (u32)(program_id & 0xFFFFFFFF); |
| 31 | return Common::StringFromFormat("%s%08x/%08x/data/00000001/", mount_location.c_str(), high, low); | 31 | return Common::StringFromFormat("%s%08x/%08x/data/00000001/", mount_location.c_str(), high, low); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | static std::string GetSaveDataMetadataPath(const std::string& mount_location, u64 program_id) { | ||
| 35 | u32 high = (u32)(program_id >> 32); | ||
| 36 | u32 low = (u32)(program_id & 0xFFFFFFFF); | ||
| 37 | return Common::StringFromFormat("%s%08x/%08x/data/00000001.metadata", mount_location.c_str(), high, low); | ||
| 38 | } | ||
| 39 | |||
| 34 | ArchiveFactory_SaveData::ArchiveFactory_SaveData(const std::string& sdmc_directory) | 40 | ArchiveFactory_SaveData::ArchiveFactory_SaveData(const std::string& sdmc_directory) |
| 35 | : mount_point(GetSaveDataContainerPath(sdmc_directory)) { | 41 | : mount_point(GetSaveDataContainerPath(sdmc_directory)) { |
| 36 | LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str()); | 42 | LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str()); |
| @@ -51,11 +57,35 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const P | |||
| 51 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | 57 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); |
| 52 | } | 58 | } |
| 53 | 59 | ||
| 54 | ResultCode ArchiveFactory_SaveData::Format(const Path& path) { | 60 | ResultCode ArchiveFactory_SaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { |
| 55 | std::string concrete_mount_point = GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id); | 61 | std::string concrete_mount_point = GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id); |
| 56 | FileUtil::DeleteDirRecursively(concrete_mount_point); | 62 | FileUtil::DeleteDirRecursively(concrete_mount_point); |
| 57 | FileUtil::CreateFullPath(concrete_mount_point); | 63 | FileUtil::CreateFullPath(concrete_mount_point); |
| 64 | |||
| 65 | // Write the format metadata | ||
| 66 | std::string metadata_path = GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); | ||
| 67 | FileUtil::IOFile file(metadata_path, "wb"); | ||
| 68 | |||
| 69 | if (file.IsOpen()) { | ||
| 70 | file.WriteBytes(&format_info, sizeof(format_info)); | ||
| 71 | return RESULT_SUCCESS; | ||
| 72 | } | ||
| 58 | return RESULT_SUCCESS; | 73 | return RESULT_SUCCESS; |
| 59 | } | 74 | } |
| 60 | 75 | ||
| 76 | ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveData::GetFormatInfo(const Path& path) const { | ||
| 77 | std::string metadata_path = GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); | ||
| 78 | FileUtil::IOFile file(metadata_path, "rb"); | ||
| 79 | |||
| 80 | if (!file.IsOpen()) { | ||
| 81 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); | ||
| 82 | // TODO(Subv): Verify error code | ||
| 83 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); | ||
| 84 | } | ||
| 85 | |||
| 86 | ArchiveFormatInfo info = {}; | ||
| 87 | file.ReadBytes(&info, sizeof(info)); | ||
| 88 | return MakeResult<ArchiveFormatInfo>(info); | ||
| 89 | } | ||
| 90 | |||
| 61 | } // namespace FileSys | 91 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_savedata.h b/src/core/file_sys/archive_savedata.h index 1f65297dd..7a5a24089 100644 --- a/src/core/file_sys/archive_savedata.h +++ b/src/core/file_sys/archive_savedata.h | |||
| @@ -23,7 +23,9 @@ public: | |||
| 23 | std::string GetName() const override { return "SaveData"; } | 23 | std::string GetName() const override { return "SaveData"; } |
| 24 | 24 | ||
| 25 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | 25 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; |
| 26 | ResultCode Format(const Path& path) override; | 26 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; |
| 27 | |||
| 28 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | ||
| 27 | 29 | ||
| 28 | private: | 30 | private: |
| 29 | std::string mount_point; | 31 | std::string mount_point; |
diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp index ea1dfe2c7..3db11c500 100644 --- a/src/core/file_sys/archive_savedatacheck.cpp +++ b/src/core/file_sys/archive_savedatacheck.cpp | |||
| @@ -48,11 +48,17 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(co | |||
| 48 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | 48 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); |
| 49 | } | 49 | } |
| 50 | 50 | ||
| 51 | ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path) { | 51 | ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { |
| 52 | LOG_ERROR(Service_FS, "Attempted to format a SaveDataCheck archive."); | 52 | LOG_ERROR(Service_FS, "Attempted to format a SaveDataCheck archive."); |
| 53 | // TODO: Verify error code | 53 | // TODO: Verify error code |
| 54 | return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, | 54 | return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, |
| 55 | ErrorSummary::NotSupported, ErrorLevel::Permanent); | 55 | ErrorSummary::NotSupported, ErrorLevel::Permanent); |
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveDataCheck::GetFormatInfo(const Path& path) const { | ||
| 59 | // TODO(Subv): Implement | ||
| 60 | LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str()); | ||
| 61 | return ResultCode(-1); | ||
| 62 | } | ||
| 63 | |||
| 58 | } // namespace FileSys | 64 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_savedatacheck.h b/src/core/file_sys/archive_savedatacheck.h index b14aefe8b..ea2624d64 100644 --- a/src/core/file_sys/archive_savedatacheck.h +++ b/src/core/file_sys/archive_savedatacheck.h | |||
| @@ -23,7 +23,8 @@ public: | |||
| 23 | std::string GetName() const override { return "SaveDataCheck"; } | 23 | std::string GetName() const override { return "SaveDataCheck"; } |
| 24 | 24 | ||
| 25 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | 25 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; |
| 26 | ResultCode Format(const Path& path) override; | 26 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; |
| 27 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | ||
| 27 | 28 | ||
| 28 | private: | 29 | private: |
| 29 | std::string mount_point; | 30 | std::string mount_point; |
diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index 5c825f429..657221cbf 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp | |||
| @@ -40,9 +40,14 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMC::Open(const Path& | |||
| 40 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | 40 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | ResultCode ArchiveFactory_SDMC::Format(const Path& path) { | 43 | ResultCode ArchiveFactory_SDMC::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { |
| 44 | // This is kind of an undesirable operation, so let's just ignore it. :) | 44 | // This is kind of an undesirable operation, so let's just ignore it. :) |
| 45 | return RESULT_SUCCESS; | 45 | return RESULT_SUCCESS; |
| 46 | } | 46 | } |
| 47 | 47 | ||
| 48 | ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMC::GetFormatInfo(const Path& path) const { | ||
| 49 | // TODO(Subv): Implement | ||
| 50 | LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str()); | ||
| 51 | return ResultCode(-1); | ||
| 52 | } | ||
| 48 | } // namespace FileSys | 53 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h index 10b273bdb..35c0f3725 100644 --- a/src/core/file_sys/archive_sdmc.h +++ b/src/core/file_sys/archive_sdmc.h | |||
| @@ -29,7 +29,8 @@ public: | |||
| 29 | std::string GetName() const override { return "SDMC"; } | 29 | std::string GetName() const override { return "SDMC"; } |
| 30 | 30 | ||
| 31 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | 31 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; |
| 32 | ResultCode Format(const Path& path) override; | 32 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; |
| 33 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | ||
| 33 | 34 | ||
| 34 | private: | 35 | private: |
| 35 | std::string sdmc_directory; | 36 | std::string sdmc_directory; |
diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp index 896f89529..e1780de2f 100644 --- a/src/core/file_sys/archive_systemsavedata.cpp +++ b/src/core/file_sys/archive_systemsavedata.cpp | |||
| @@ -63,11 +63,17 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c | |||
| 63 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); | 63 | return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); |
| 64 | } | 64 | } |
| 65 | 65 | ||
| 66 | ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path) { | 66 | ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { |
| 67 | std::string fullpath = GetSystemSaveDataPath(base_path, path); | 67 | std::string fullpath = GetSystemSaveDataPath(base_path, path); |
| 68 | FileUtil::DeleteDirRecursively(fullpath); | 68 | FileUtil::DeleteDirRecursively(fullpath); |
| 69 | FileUtil::CreateFullPath(fullpath); | 69 | FileUtil::CreateFullPath(fullpath); |
| 70 | return RESULT_SUCCESS; | 70 | return RESULT_SUCCESS; |
| 71 | } | 71 | } |
| 72 | 72 | ||
| 73 | ResultVal<ArchiveFormatInfo> ArchiveFactory_SystemSaveData::GetFormatInfo(const Path& path) const { | ||
| 74 | // TODO(Subv): Implement | ||
| 75 | LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive %s", GetName().c_str()); | ||
| 76 | return ResultCode(-1); | ||
| 77 | } | ||
| 78 | |||
| 73 | } // namespace FileSys | 79 | } // namespace FileSys |
diff --git a/src/core/file_sys/archive_systemsavedata.h b/src/core/file_sys/archive_systemsavedata.h index afc689848..2bc13d4ee 100644 --- a/src/core/file_sys/archive_systemsavedata.h +++ b/src/core/file_sys/archive_systemsavedata.h | |||
| @@ -23,7 +23,8 @@ public: | |||
| 23 | ArchiveFactory_SystemSaveData(const std::string& mount_point); | 23 | ArchiveFactory_SystemSaveData(const std::string& mount_point); |
| 24 | 24 | ||
| 25 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; | 25 | ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; |
| 26 | ResultCode Format(const Path& path) override; | 26 | ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; |
| 27 | ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; | ||
| 27 | 28 | ||
| 28 | std::string GetName() const override { return "SystemSaveData"; } | 29 | std::string GetName() const override { return "SystemSaveData"; } |
| 29 | 30 | ||
diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index a51416774..8e4ea01c5 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp | |||
| @@ -17,16 +17,28 @@ | |||
| 17 | 17 | ||
| 18 | namespace FileSys { | 18 | namespace FileSys { |
| 19 | 19 | ||
| 20 | std::unique_ptr<FileBackend> DiskArchive::OpenFile(const Path& path, const Mode mode) const { | 20 | ResultVal<std::unique_ptr<FileBackend>> DiskArchive::OpenFile(const Path& path, const Mode mode) const { |
| 21 | LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex); | 21 | LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex); |
| 22 | auto file = Common::make_unique<DiskFile>(*this, path, mode); | 22 | auto file = Common::make_unique<DiskFile>(*this, path, mode); |
| 23 | if (!file->Open()) | 23 | ResultCode result = file->Open(); |
| 24 | return nullptr; | 24 | if (result.IsError()) |
| 25 | return std::move(file); | 25 | return result; |
| 26 | return MakeResult<std::unique_ptr<FileBackend>>(std::move(file)); | ||
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | bool DiskArchive::DeleteFile(const Path& path) const { | 29 | ResultCode DiskArchive::DeleteFile(const Path& path) const { |
| 29 | return FileUtil::Delete(mount_point + path.AsString()); | 30 | std::string file_path = mount_point + path.AsString(); |
| 31 | |||
| 32 | if (FileUtil::IsDirectory(file_path)) | ||
| 33 | return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 34 | |||
| 35 | if (!FileUtil::Exists(file_path)) | ||
| 36 | return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); | ||
| 37 | |||
| 38 | if (FileUtil::Delete(file_path)) | ||
| 39 | return RESULT_SUCCESS; | ||
| 40 | |||
| 41 | return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 30 | } | 42 | } |
| 31 | 43 | ||
| 32 | bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | 44 | bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const { |
| @@ -37,11 +49,14 @@ bool DiskArchive::DeleteDirectory(const Path& path) const { | |||
| 37 | return FileUtil::DeleteDir(mount_point + path.AsString()); | 49 | return FileUtil::DeleteDir(mount_point + path.AsString()); |
| 38 | } | 50 | } |
| 39 | 51 | ||
| 40 | ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u32 size) const { | 52 | ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const { |
| 41 | std::string full_path = mount_point + path.AsString(); | 53 | std::string full_path = mount_point + path.AsString(); |
| 42 | 54 | ||
| 55 | if (FileUtil::IsDirectory(full_path)) | ||
| 56 | return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 57 | |||
| 43 | if (FileUtil::Exists(full_path)) | 58 | if (FileUtil::Exists(full_path)) |
| 44 | return ResultCode(ErrorDescription::AlreadyExists, ErrorModule::FS, ErrorSummary::NothingHappened, ErrorLevel::Info); | 59 | return ResultCode(ErrorDescription::FS_AlreadyExists, ErrorModule::FS, ErrorSummary::NothingHappened, ErrorLevel::Status); |
| 45 | 60 | ||
| 46 | if (size == 0) { | 61 | if (size == 0) { |
| 47 | FileUtil::CreateEmptyFile(full_path); | 62 | FileUtil::CreateEmptyFile(full_path); |
| @@ -89,38 +104,57 @@ DiskFile::DiskFile(const DiskArchive& archive, const Path& path, const Mode mode | |||
| 89 | this->mode.hex = mode.hex; | 104 | this->mode.hex = mode.hex; |
| 90 | } | 105 | } |
| 91 | 106 | ||
| 92 | bool DiskFile::Open() { | 107 | ResultCode DiskFile::Open() { |
| 93 | if (!mode.create_flag && !FileUtil::Exists(path)) { | 108 | if (FileUtil::IsDirectory(path)) |
| 94 | LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.", path.c_str()); | 109 | return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); |
| 95 | return false; | 110 | |
| 111 | // Specifying only the Create flag is invalid | ||
| 112 | if (mode.create_flag && !mode.read_flag && !mode.write_flag) { | ||
| 113 | return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 114 | } | ||
| 115 | |||
| 116 | if (!FileUtil::Exists(path)) { | ||
| 117 | if (!mode.create_flag) { | ||
| 118 | LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.", path.c_str()); | ||
| 119 | return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); | ||
| 120 | } else { | ||
| 121 | // Create the file | ||
| 122 | FileUtil::CreateEmptyFile(path); | ||
| 123 | } | ||
| 96 | } | 124 | } |
| 97 | 125 | ||
| 98 | std::string mode_string; | 126 | std::string mode_string = ""; |
| 99 | if (mode.create_flag) | 127 | if (mode.write_flag) |
| 100 | mode_string = "w+"; | 128 | mode_string += "r+"; // Files opened with Write access can be read from |
| 101 | else if (mode.write_flag) | ||
| 102 | mode_string = "r+"; // Files opened with Write access can be read from | ||
| 103 | else if (mode.read_flag) | 129 | else if (mode.read_flag) |
| 104 | mode_string = "r"; | 130 | mode_string += "r"; |
| 105 | 131 | ||
| 106 | // Open the file in binary mode, to avoid problems with CR/LF on Windows systems | 132 | // Open the file in binary mode, to avoid problems with CR/LF on Windows systems |
| 107 | mode_string += "b"; | 133 | mode_string += "b"; |
| 108 | 134 | ||
| 109 | file = Common::make_unique<FileUtil::IOFile>(path, mode_string.c_str()); | 135 | file = Common::make_unique<FileUtil::IOFile>(path, mode_string.c_str()); |
| 110 | return file->IsOpen(); | 136 | if (file->IsOpen()) |
| 137 | return RESULT_SUCCESS; | ||
| 138 | return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); | ||
| 111 | } | 139 | } |
| 112 | 140 | ||
| 113 | size_t DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { | 141 | ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { |
| 142 | if (!mode.read_flag && !mode.write_flag) | ||
| 143 | return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 144 | |||
| 114 | file->Seek(offset, SEEK_SET); | 145 | file->Seek(offset, SEEK_SET); |
| 115 | return file->ReadBytes(buffer, length); | 146 | return MakeResult<size_t>(file->ReadBytes(buffer, length)); |
| 116 | } | 147 | } |
| 117 | 148 | ||
| 118 | size_t DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { | 149 | ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { |
| 150 | if (!mode.write_flag) | ||
| 151 | return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 152 | |||
| 119 | file->Seek(offset, SEEK_SET); | 153 | file->Seek(offset, SEEK_SET); |
| 120 | size_t written = file->WriteBytes(buffer, length); | 154 | size_t written = file->WriteBytes(buffer, length); |
| 121 | if (flush) | 155 | if (flush) |
| 122 | file->Flush(); | 156 | file->Flush(); |
| 123 | return written; | 157 | return MakeResult<size_t>(written); |
| 124 | } | 158 | } |
| 125 | 159 | ||
| 126 | u64 DiskFile::GetSize() const { | 160 | u64 DiskFile::GetSize() const { |
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h index ef9a98057..b4cc2f702 100644 --- a/src/core/file_sys/disk_archive.h +++ b/src/core/file_sys/disk_archive.h | |||
| @@ -33,11 +33,11 @@ public: | |||
| 33 | 33 | ||
| 34 | virtual std::string GetName() const override { return "DiskArchive: " + mount_point; } | 34 | virtual std::string GetName() const override { return "DiskArchive: " + mount_point; } |
| 35 | 35 | ||
| 36 | std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override; | 36 | ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode mode) const override; |
| 37 | bool DeleteFile(const Path& path) const override; | 37 | ResultCode DeleteFile(const Path& path) const override; |
| 38 | bool RenameFile(const Path& src_path, const Path& dest_path) const override; | 38 | bool RenameFile(const Path& src_path, const Path& dest_path) const override; |
| 39 | bool DeleteDirectory(const Path& path) const override; | 39 | bool DeleteDirectory(const Path& path) const override; |
| 40 | ResultCode CreateFile(const Path& path, u32 size) const override; | 40 | ResultCode CreateFile(const Path& path, u64 size) const override; |
| 41 | bool CreateDirectory(const Path& path) const override; | 41 | bool CreateDirectory(const Path& path) const override; |
| 42 | bool RenameDirectory(const Path& src_path, const Path& dest_path) const override; | 42 | bool RenameDirectory(const Path& src_path, const Path& dest_path) const override; |
| 43 | std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; | 43 | std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; |
| @@ -54,9 +54,9 @@ class DiskFile : public FileBackend { | |||
| 54 | public: | 54 | public: |
| 55 | DiskFile(const DiskArchive& archive, const Path& path, const Mode mode); | 55 | DiskFile(const DiskArchive& archive, const Path& path, const Mode mode); |
| 56 | 56 | ||
| 57 | bool Open() override; | 57 | ResultCode Open() override; |
| 58 | size_t Read(u64 offset, size_t length, u8* buffer) const override; | 58 | ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override; |
| 59 | size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; | 59 | ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; |
| 60 | u64 GetSize() const override; | 60 | u64 GetSize() const override; |
| 61 | bool SetSize(u64 size) const override; | 61 | bool SetSize(u64 size) const override; |
| 62 | bool Close() const override; | 62 | bool Close() const override; |
diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h index df7165df3..9137bbbad 100644 --- a/src/core/file_sys/file_backend.h +++ b/src/core/file_sys/file_backend.h | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | #include <cstddef> | 7 | #include <cstddef> |
| 8 | 8 | ||
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "core/hle/result.h" | ||
| 10 | 11 | ||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 12 | // FileSys namespace | 13 | // FileSys namespace |
| @@ -20,18 +21,18 @@ public: | |||
| 20 | 21 | ||
| 21 | /** | 22 | /** |
| 22 | * Open the file | 23 | * Open the file |
| 23 | * @return true if the file opened correctly | 24 | * @return Result of the file operation |
| 24 | */ | 25 | */ |
| 25 | virtual bool Open() = 0; | 26 | virtual ResultCode Open() = 0; |
| 26 | 27 | ||
| 27 | /** | 28 | /** |
| 28 | * Read data from the file | 29 | * Read data from the file |
| 29 | * @param offset Offset in bytes to start reading data from | 30 | * @param offset Offset in bytes to start reading data from |
| 30 | * @param length Length in bytes of data to read from file | 31 | * @param length Length in bytes of data to read from file |
| 31 | * @param buffer Buffer to read data into | 32 | * @param buffer Buffer to read data into |
| 32 | * @return Number of bytes read | 33 | * @return Number of bytes read, or error code |
| 33 | */ | 34 | */ |
| 34 | virtual size_t Read(u64 offset, size_t length, u8* buffer) const = 0; | 35 | virtual ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const = 0; |
| 35 | 36 | ||
| 36 | /** | 37 | /** |
| 37 | * Write data to the file | 38 | * Write data to the file |
| @@ -39,9 +40,9 @@ public: | |||
| 39 | * @param length Length in bytes of data to write to file | 40 | * @param length Length in bytes of data to write to file |
| 40 | * @param flush The flush parameters (0 == do not flush) | 41 | * @param flush The flush parameters (0 == do not flush) |
| 41 | * @param buffer Buffer to read data from | 42 | * @param buffer Buffer to read data from |
| 42 | * @return Number of bytes written | 43 | * @return Number of bytes written, or error code |
| 43 | */ | 44 | */ |
| 44 | virtual size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0; | 45 | virtual ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0; |
| 45 | 46 | ||
| 46 | /** | 47 | /** |
| 47 | * Get the size of the file in bytes | 48 | * Get the size of the file in bytes |
diff --git a/src/core/file_sys/ivfc_archive.cpp b/src/core/file_sys/ivfc_archive.cpp index 2efc31a8c..a8e9a72ef 100644 --- a/src/core/file_sys/ivfc_archive.cpp +++ b/src/core/file_sys/ivfc_archive.cpp | |||
| @@ -20,13 +20,15 @@ std::string IVFCArchive::GetName() const { | |||
| 20 | return "IVFC"; | 20 | return "IVFC"; |
| 21 | } | 21 | } |
| 22 | 22 | ||
| 23 | std::unique_ptr<FileBackend> IVFCArchive::OpenFile(const Path& path, const Mode mode) const { | 23 | ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path, const Mode mode) const { |
| 24 | return Common::make_unique<IVFCFile>(romfs_file, data_offset, data_size); | 24 | return MakeResult<std::unique_ptr<FileBackend>>(Common::make_unique<IVFCFile>(romfs_file, data_offset, data_size)); |
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | bool IVFCArchive::DeleteFile(const Path& path) const { | 27 | ResultCode IVFCArchive::DeleteFile(const Path& path) const { |
| 28 | LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).", GetName().c_str()); | 28 | LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).", GetName().c_str()); |
| 29 | return false; | 29 | // TODO(Subv): Verify error code |
| 30 | return ResultCode(ErrorDescription::NoData, ErrorModule::FS, | ||
| 31 | ErrorSummary::Canceled, ErrorLevel::Status); | ||
| 30 | } | 32 | } |
| 31 | 33 | ||
| 32 | bool IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | 34 | bool IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { |
| @@ -39,7 +41,7 @@ bool IVFCArchive::DeleteDirectory(const Path& path) const { | |||
| 39 | return false; | 41 | return false; |
| 40 | } | 42 | } |
| 41 | 43 | ||
| 42 | ResultCode IVFCArchive::CreateFile(const Path& path, u32 size) const { | 44 | ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const { |
| 43 | LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).", GetName().c_str()); | 45 | LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).", GetName().c_str()); |
| 44 | // TODO: Verify error code | 46 | // TODO: Verify error code |
| 45 | return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, ErrorLevel::Permanent); | 47 | return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, ErrorLevel::Permanent); |
| @@ -66,17 +68,18 @@ u64 IVFCArchive::GetFreeBytes() const { | |||
| 66 | 68 | ||
| 67 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 69 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 68 | 70 | ||
| 69 | size_t IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const { | 71 | ResultVal<size_t> IVFCFile::Read(const u64 offset, const size_t length, u8* buffer) const { |
| 70 | LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length); | 72 | LOG_TRACE(Service_FS, "called offset=%llu, length=%zu", offset, length); |
| 71 | romfs_file->Seek(data_offset + offset, SEEK_SET); | 73 | romfs_file->Seek(data_offset + offset, SEEK_SET); |
| 72 | size_t read_length = (size_t)std::min((u64)length, data_size - offset); | 74 | size_t read_length = (size_t)std::min((u64)length, data_size - offset); |
| 73 | 75 | ||
| 74 | return romfs_file->ReadBytes(buffer, read_length); | 76 | return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length)); |
| 75 | } | 77 | } |
| 76 | 78 | ||
| 77 | size_t IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { | 79 | ResultVal<size_t> IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { |
| 78 | LOG_ERROR(Service_FS, "Attempted to write to IVFC file"); | 80 | LOG_ERROR(Service_FS, "Attempted to write to IVFC file"); |
| 79 | return 0; | 81 | // TODO(Subv): Find error code |
| 82 | return MakeResult<size_t>(0); | ||
| 80 | } | 83 | } |
| 81 | 84 | ||
| 82 | u64 IVFCFile::GetSize() const { | 85 | u64 IVFCFile::GetSize() const { |
diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h index f3fd82de4..19d32dcca 100644 --- a/src/core/file_sys/ivfc_archive.h +++ b/src/core/file_sys/ivfc_archive.h | |||
| @@ -34,11 +34,11 @@ public: | |||
| 34 | 34 | ||
| 35 | std::string GetName() const override; | 35 | std::string GetName() const override; |
| 36 | 36 | ||
| 37 | std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override; | 37 | ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode mode) const override; |
| 38 | bool DeleteFile(const Path& path) const override; | 38 | ResultCode DeleteFile(const Path& path) const override; |
| 39 | bool RenameFile(const Path& src_path, const Path& dest_path) const override; | 39 | bool RenameFile(const Path& src_path, const Path& dest_path) const override; |
| 40 | bool DeleteDirectory(const Path& path) const override; | 40 | bool DeleteDirectory(const Path& path) const override; |
| 41 | ResultCode CreateFile(const Path& path, u32 size) const override; | 41 | ResultCode CreateFile(const Path& path, u64 size) const override; |
| 42 | bool CreateDirectory(const Path& path) const override; | 42 | bool CreateDirectory(const Path& path) const override; |
| 43 | bool RenameDirectory(const Path& src_path, const Path& dest_path) const override; | 43 | bool RenameDirectory(const Path& src_path, const Path& dest_path) const override; |
| 44 | std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; | 44 | std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; |
| @@ -55,9 +55,9 @@ public: | |||
| 55 | IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) | 55 | IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) |
| 56 | : romfs_file(file), data_offset(offset), data_size(size) {} | 56 | : romfs_file(file), data_offset(offset), data_size(size) {} |
| 57 | 57 | ||
| 58 | bool Open() override { return true; } | 58 | ResultCode Open() override { return RESULT_SUCCESS; } |
| 59 | size_t Read(u64 offset, size_t length, u8* buffer) const override; | 59 | ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override; |
| 60 | size_t Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; | 60 | ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; |
| 61 | u64 GetSize() const override; | 61 | u64 GetSize() const override; |
| 62 | bool SetSize(u64 size) const override; | 62 | bool SetSize(u64 size) const override; |
| 63 | bool Close() const override { return false; } | 63 | bool Close() const override { return false; } |