diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/archive_backend.h | 7 | ||||
| -rw-r--r-- | src/core/file_sys/archive_extsavedata.cpp | 42 | ||||
| -rw-r--r-- | src/core/file_sys/archive_extsavedata.h | 3 | ||||
| -rw-r--r-- | src/core/file_sys/archive_savedata.cpp | 14 | ||||
| -rw-r--r-- | src/core/hle/service/fs/archive.cpp | 12 |
5 files changed, 45 insertions, 33 deletions
diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 94cda172f..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 | ||
| @@ -63,9 +64,9 @@ private: | |||
| 63 | }; | 64 | }; |
| 64 | 65 | ||
| 65 | struct ArchiveFormatInfo { | 66 | struct ArchiveFormatInfo { |
| 66 | u32 total_size; ///< The pre-defined size of the archive, as specified in the Create or Format call | 67 | u32_le total_size; ///< The pre-defined size of the archive, as specified in the Create or Format call |
| 67 | u32 number_directories; ///< The pre-defined number of directories in 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 |
| 68 | u32 number_files; ///< The pre-defined number of files 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 |
| 69 | u8 duplicate_data; ///< Whether the archive should duplicate the data, 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 |
| 70 | }; | 71 | }; |
| 71 | static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD"); | 72 | static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD"); |
diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index ca7fd5c5e..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,9 +74,15 @@ 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)); |
| @@ -93,33 +99,33 @@ ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path, const FileSys::A | |||
| 93 | std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; | 99 | std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; |
| 94 | FileUtil::IOFile file(metadata_path, "wb"); | 100 | FileUtil::IOFile file(metadata_path, "wb"); |
| 95 | 101 | ||
| 96 | if (file.IsOpen()) { | 102 | if (!file.IsOpen()) { |
| 97 | file.WriteBytes(&format_info, sizeof(format_info)); | 103 | // TODO(Subv): Find the correct error code |
| 98 | return RESULT_SUCCESS; | 104 | return ResultCode(-1); |
| 99 | } | 105 | } |
| 100 | 106 | ||
| 101 | // TODO(Subv): Find the correct error code | 107 | file.WriteBytes(&format_info, sizeof(format_info)); |
| 102 | return ResultCode(-1); | 108 | return RESULT_SUCCESS; |
| 103 | } | 109 | } |
| 104 | 110 | ||
| 105 | ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Path& path) const { | 111 | ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Path& path) const { |
| 106 | std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; | 112 | std::string metadata_path = GetExtSaveDataPath(mount_point, path) + "metadata"; |
| 107 | FileUtil::IOFile file(metadata_path, "rb"); | 113 | FileUtil::IOFile file(metadata_path, "rb"); |
| 108 | 114 | ||
| 109 | if (file.IsOpen()) { | 115 | if (!file.IsOpen()) { |
| 110 | ArchiveFormatInfo info; | 116 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); |
| 111 | file.ReadBytes(&info, sizeof(info)); | 117 | // TODO(Subv): Verify error code |
| 112 | return MakeResult<ArchiveFormatInfo>(info); | 118 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); |
| 113 | } | 119 | } |
| 114 | 120 | ||
| 115 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); | 121 | ArchiveFormatInfo info = {}; |
| 116 | // TODO(Subv): Verify error code | 122 | file.ReadBytes(&info, sizeof(info)); |
| 117 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); | 123 | return MakeResult<ArchiveFormatInfo>(info); |
| 118 | } | 124 | } |
| 119 | 125 | ||
| 120 | void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, u32 icon_size) { | 126 | void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, size_t icon_size) { |
| 121 | std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path); | 127 | std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path); |
| 122 | FileUtil::IOFile icon_file(game_path + "icon", "wb+"); | 128 | FileUtil::IOFile icon_file(game_path + "icon", "wb"); |
| 123 | icon_file.WriteBytes(icon_data, icon_size); | 129 | icon_file.WriteBytes(icon_data, icon_size); |
| 124 | } | 130 | } |
| 125 | 131 | ||
diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h index 1ebe0529f..287a6fee1 100644 --- a/src/core/file_sys/archive_extsavedata.h +++ b/src/core/file_sys/archive_extsavedata.h | |||
| @@ -42,7 +42,7 @@ public: | |||
| 42 | * @param icon_data Binary data of the icon | 42 | * @param icon_data Binary data of the icon |
| 43 | * @param icon_size Size of the icon data | 43 | * @param icon_size Size of the icon data |
| 44 | */ | 44 | */ |
| 45 | void WriteIcon(const Path& path, const u8* icon_data, u32 icon_size); | 45 | void WriteIcon(const Path& path, const u8* icon_data, size_t icon_size); |
| 46 | 46 | ||
| 47 | private: | 47 | private: |
| 48 | /** | 48 | /** |
| @@ -51,6 +51,7 @@ private: | |||
| 51 | * 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. |
| 52 | */ | 52 | */ |
| 53 | std::string mount_point; | 53 | std::string mount_point; |
| 54 | bool shared; ///< Whether this archive represents an ExtSaveData archive or a SharedExtSaveData archive | ||
| 54 | }; | 55 | }; |
| 55 | 56 | ||
| 56 | /** | 57 | /** |
diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp index c2d32ed7e..fe020d21c 100644 --- a/src/core/file_sys/archive_savedata.cpp +++ b/src/core/file_sys/archive_savedata.cpp | |||
| @@ -77,15 +77,15 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveData::GetFormatInfo(const Path& | |||
| 77 | std::string metadata_path = GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); | 77 | std::string metadata_path = GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); |
| 78 | FileUtil::IOFile file(metadata_path, "rb"); | 78 | FileUtil::IOFile file(metadata_path, "rb"); |
| 79 | 79 | ||
| 80 | if (file.IsOpen()) { | 80 | if (!file.IsOpen()) { |
| 81 | ArchiveFormatInfo info; | 81 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); |
| 82 | file.ReadBytes(&info, sizeof(info)); | 82 | // TODO(Subv): Verify error code |
| 83 | return MakeResult<ArchiveFormatInfo>(info); | 83 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); |
| 84 | } | 84 | } |
| 85 | 85 | ||
| 86 | LOG_ERROR(Service_FS, "Could not open metadata information for archive"); | 86 | ArchiveFormatInfo info = {}; |
| 87 | // TODO(Subv): Verify error code | 87 | file.ReadBytes(&info, sizeof(info)); |
| 88 | return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); | 88 | return MakeResult<ArchiveFormatInfo>(info); |
| 89 | } | 89 | } |
| 90 | 90 | ||
| 91 | } // namespace FileSys | 91 | } // namespace FileSys |
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp index 676a2ee56..590697e76 100644 --- a/src/core/hle/service/fs/archive.cpp +++ b/src/core/hle/service/fs/archive.cpp | |||
| @@ -103,14 +103,18 @@ ResultVal<bool> File::SyncRequest() { | |||
| 103 | u32 address = cmd_buff[5]; | 103 | u32 address = cmd_buff[5]; |
| 104 | LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x", | 104 | LOG_TRACE(Service_FS, "Read %s %s: offset=0x%llx length=%d address=0x%x", |
| 105 | GetTypeName().c_str(), GetName().c_str(), offset, length, address); | 105 | GetTypeName().c_str(), GetName().c_str(), offset, length, address); |
| 106 | if (offset + length > backend->GetSize()) | 106 | |
| 107 | LOG_ERROR(Service_FS, "Reading from out of bounds offset=0x%llX length=0x%08X file_size=0x%llX", offset, length, backend->GetSize()); | 107 | if (offset + length > backend->GetSize()) { |
| 108 | LOG_ERROR(Service_FS, "Reading from out of bounds offset=0x%llX length=0x%08X file_size=0x%llX", | ||
| 109 | offset, length, backend->GetSize()); | ||
| 110 | } | ||
| 111 | |||
| 108 | ResultVal<size_t> read = backend->Read(offset, length, Memory::GetPointer(address)); | 112 | ResultVal<size_t> read = backend->Read(offset, length, Memory::GetPointer(address)); |
| 109 | if (read.Failed()) { | 113 | if (read.Failed()) { |
| 110 | cmd_buff[1] = read.Code().raw; | 114 | cmd_buff[1] = read.Code().raw; |
| 111 | return read.Code(); | 115 | return read.Code(); |
| 112 | } | 116 | } |
| 113 | cmd_buff[2] = static_cast<u32>(read.MoveFrom()); | 117 | cmd_buff[2] = static_cast<u32>(*read); |
| 114 | break; | 118 | break; |
| 115 | } | 119 | } |
| 116 | 120 | ||
| @@ -129,7 +133,7 @@ ResultVal<bool> File::SyncRequest() { | |||
| 129 | cmd_buff[1] = written.Code().raw; | 133 | cmd_buff[1] = written.Code().raw; |
| 130 | return written.Code(); | 134 | return written.Code(); |
| 131 | } | 135 | } |
| 132 | cmd_buff[2] = static_cast<u32>(written.MoveFrom()); | 136 | cmd_buff[2] = static_cast<u32>(*written); |
| 133 | break; | 137 | break; |
| 134 | } | 138 | } |
| 135 | 139 | ||