diff options
Diffstat (limited to 'src/core/file_sys')
-rw-r--r-- | src/core/file_sys/archive_backend.cpp | 33 | ||||
-rw-r--r-- | src/core/file_sys/archive_backend.h | 37 | ||||
-rw-r--r-- | src/core/file_sys/archive_extsavedata.cpp | 21 | ||||
-rw-r--r-- | src/core/file_sys/archive_extsavedata.h | 14 | ||||
-rw-r--r-- | src/core/file_sys/archive_romfs.cpp | 7 | ||||
-rw-r--r-- | src/core/file_sys/archive_romfs.h | 4 | ||||
-rw-r--r-- | src/core/file_sys/archive_savedata.cpp | 33 | ||||
-rw-r--r-- | src/core/file_sys/archive_savedata.h | 4 | ||||
-rw-r--r-- | src/core/file_sys/archive_savedatacheck.cpp | 15 | ||||
-rw-r--r-- | src/core/file_sys/archive_savedatacheck.h | 4 | ||||
-rw-r--r-- | src/core/file_sys/archive_sdmc.cpp | 6 | ||||
-rw-r--r-- | src/core/file_sys/archive_sdmc.h | 4 | ||||
-rw-r--r-- | src/core/file_sys/archive_systemsavedata.cpp | 9 | ||||
-rw-r--r-- | src/core/file_sys/archive_systemsavedata.h | 7 | ||||
-rw-r--r-- | src/core/file_sys/directory_backend.h | 21 | ||||
-rw-r--r-- | src/core/file_sys/disk_archive.cpp | 49 | ||||
-rw-r--r-- | src/core/file_sys/disk_archive.h | 10 | ||||
-rw-r--r-- | src/core/file_sys/file_backend.h | 9 | ||||
-rw-r--r-- | src/core/file_sys/ivfc_archive.cpp | 34 | ||||
-rw-r--r-- | src/core/file_sys/ivfc_archive.h | 32 |
20 files changed, 217 insertions, 136 deletions
diff --git a/src/core/file_sys/archive_backend.cpp b/src/core/file_sys/archive_backend.cpp index cc0aa7022..6ea920ec1 100644 --- a/src/core/file_sys/archive_backend.cpp +++ b/src/core/file_sys/archive_backend.cpp @@ -12,27 +12,23 @@ #include "core/file_sys/archive_backend.h" #include "core/memory.h" - namespace FileSys { Path::Path(LowPathType type, u32 size, u32 pointer) : type(type) { switch (type) { - case Binary: - { + case Binary: { binary.resize(size); Memory::ReadBlock(pointer, binary.data(), binary.size()); break; } - case Char: - { + case Char: { string.resize(size - 1); // Data is always null-terminated. Memory::ReadBlock(pointer, &string[0], string.size()); break; } - case Wchar: - { + case Wchar: { u16str.resize(size / 2 - 1); // Data is always null-terminated. Memory::ReadBlock(pointer, &u16str[0], u16str.size() * sizeof(char16_t)); break; @@ -50,8 +46,7 @@ std::string Path::DebugStr() const { return "[Invalid]"; case Empty: return "[Empty]"; - case Binary: - { + case Binary: { std::stringstream res; res << "[Binary: "; for (unsigned byte : binary) @@ -73,13 +68,13 @@ std::string Path::AsString() const { case Wchar: return Common::UTF16ToUTF8(u16str); case Empty: - return{}; + return {}; case Invalid: case Binary: default: // TODO(yuriks): Add assert LOG_ERROR(Service_FS, "LowPathType cannot be converted to string!"); - return{}; + return {}; } } @@ -90,12 +85,12 @@ std::u16string Path::AsU16Str() const { case Wchar: return u16str; case Empty: - return{}; + return {}; case Invalid: case Binary: // TODO(yuriks): Add assert LOG_ERROR(Service_FS, "LowPathType cannot be converted to u16string!"); - return{}; + return {}; } } @@ -105,25 +100,23 @@ std::vector<u8> Path::AsBinary() const { return binary; case Char: return std::vector<u8>(string.begin(), string.end()); - case Wchar: - { + case Wchar: { // use two u8 for each character of u16str std::vector<u8> to_return(u16str.size() * 2); for (size_t i = 0; i < u16str.size(); ++i) { u16 tmp_char = u16str.at(i); - to_return[i*2] = (tmp_char & 0xFF00) >> 8; - to_return[i*2 + 1] = (tmp_char & 0x00FF); + to_return[i * 2] = (tmp_char & 0xFF00) >> 8; + to_return[i * 2 + 1] = (tmp_char & 0x00FF); } return to_return; } case Empty: - return{}; + return {}; case Invalid: default: // TODO(yuriks): Add assert LOG_ERROR(Service_FS, "LowPathType cannot be converted to binary!"); - return{}; + return {}; } } - } diff --git a/src/core/file_sys/archive_backend.h b/src/core/file_sys/archive_backend.h index 5d91e47f3..79fde9710 100644 --- a/src/core/file_sys/archive_backend.h +++ b/src/core/file_sys/archive_backend.h @@ -15,20 +15,13 @@ #include "core/hle/result.h" - namespace FileSys { class FileBackend; class DirectoryBackend; // Path string type -enum LowPathType : u32 { - Invalid = 0, - Empty = 1, - Binary = 2, - Char = 3, - Wchar = 4 -}; +enum LowPathType : u32 { Invalid = 0, Empty = 1, Binary = 2, Char = 3, Wchar = 4 }; union Mode { u32 hex; @@ -39,12 +32,17 @@ union Mode { class Path { public: - Path() : type(Invalid) {} - Path(const char* path) : type(Char), string(path) {} - Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) {} + Path() : type(Invalid) { + } + Path(const char* path) : type(Char), string(path) { + } + Path(std::vector<u8> binary_data) : type(Binary), binary(std::move(binary_data)) { + } Path(LowPathType type, u32 size, u32 pointer); - LowPathType GetType() const { return type; } + LowPathType GetType() const { + return type; + } /** * Gets the string representation of the path for debugging @@ -64,10 +62,14 @@ private: }; struct ArchiveFormatInfo { - u32_le total_size; ///< The pre-defined size of the archive, as specified in the Create or Format call - u32_le number_directories; ///< The pre-defined number of directories in the archive, as specified in the Create or Format call - u32_le number_files; ///< The pre-defined number of files in the archive, as specified in the Create or Format call - u8 duplicate_data; ///< Whether the archive should duplicate the data, as specified in the Create or Format call + u32_le total_size; ///< The pre-defined size of the archive, as specified in the Create or + /// Format call + u32_le number_directories; ///< The pre-defined number of directories in the archive, as + /// specified in the Create or Format call + u32_le number_files; ///< The pre-defined number of files in the archive, as specified in the + /// Create or Format call + u8 duplicate_data; ///< Whether the archive should duplicate the data, as specified in the + /// Create or Format call }; static_assert(std::is_pod<ArchiveFormatInfo>::value, "ArchiveFormatInfo is not POD"); @@ -87,7 +89,8 @@ public: * @param mode Mode to open the file with * @return Opened file, or error code */ - virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode mode) const = 0; + virtual ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, + const Mode mode) const = 0; /** * Delete a file specified by its path diff --git a/src/core/file_sys/archive_extsavedata.cpp b/src/core/file_sys/archive_extsavedata.cpp index 1d9eaefcb..6b4af28bf 100644 --- a/src/core/file_sys/archive_extsavedata.cpp +++ b/src/core/file_sys/archive_extsavedata.cpp @@ -30,10 +30,11 @@ std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path) std::string GetExtDataContainerPath(const std::string& mount_point, bool shared) { if (shared) - return Common::StringFromFormat("%sdata/%s/extdata/", mount_point.c_str(), SYSTEM_ID.c_str()); + return Common::StringFromFormat("%sdata/%s/extdata/", mount_point.c_str(), + SYSTEM_ID.c_str()); return Common::StringFromFormat("%sNintendo 3DS/%s/%s/extdata/", mount_point.c_str(), - SYSTEM_ID.c_str(), SDCARD_ID.c_str()); + SYSTEM_ID.c_str(), SDCARD_ID.c_str()); } Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) { @@ -54,11 +55,12 @@ Path ConstructExtDataBinaryPath(u32 media_type, u32 high, u32 low) { for (unsigned i = 0; i < 4; ++i) binary_path.push_back((high >> (8 * i)) & 0xFF); - return { binary_path }; + return {binary_path}; } -ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, bool shared) - : shared(shared), mount_point(GetExtDataContainerPath(mount_location, shared)) { +ArchiveFactory_ExtSaveData::ArchiveFactory_ExtSaveData(const std::string& mount_location, + bool shared) + : shared(shared), mount_point(GetExtDataContainerPath(mount_location, shared)) { LOG_INFO(Service_FS, "Directory %s set as base for ExtSaveData.", mount_point.c_str()); } @@ -88,7 +90,8 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(cons return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); } -ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { +ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path, + const FileSys::ArchiveFormatInfo& format_info) { // These folders are always created with the ExtSaveData std::string user_path = GetExtSaveDataPath(mount_point, path) + "user/"; std::string boss_path = GetExtSaveDataPath(mount_point, path) + "boss/"; @@ -115,7 +118,8 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat if (!file.IsOpen()) { LOG_ERROR(Service_FS, "Could not open metadata information for archive"); // TODO(Subv): Verify error code - return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, + ErrorSummary::InvalidState, ErrorLevel::Status); } ArchiveFormatInfo info = {}; @@ -123,7 +127,8 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat return MakeResult<ArchiveFormatInfo>(info); } -void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, size_t icon_size) { +void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data, + size_t icon_size) { std::string game_path = FileSys::GetExtSaveDataPath(GetMountPoint(), path); FileUtil::IOFile icon_file(game_path + "icon", "wb"); icon_file.WriteBytes(icon_data, icon_size); diff --git a/src/core/file_sys/archive_extsavedata.h b/src/core/file_sys/archive_extsavedata.h index e9a72850d..2b942817e 100644 --- a/src/core/file_sys/archive_extsavedata.h +++ b/src/core/file_sys/archive_extsavedata.h @@ -28,13 +28,17 @@ public: */ bool Initialize(); - std::string GetName() const override { return "ExtSaveData"; } + std::string GetName() const override { + return "ExtSaveData"; + } ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; - const std::string& GetMountPoint() const { return mount_point; } + const std::string& GetMountPoint() const { + return mount_point; + } /** * Writes the SMDH icon of the ExtSaveData to file @@ -45,7 +49,8 @@ public: void WriteIcon(const Path& path, const u8* icon_data, size_t icon_size); private: - bool shared; ///< Whether this archive represents an ExtSaveData archive or a SharedExtSaveData archive + bool shared; ///< Whether this archive represents an ExtSaveData archive or a SharedExtSaveData + /// archive /** * This holds the full directory path for this archive, it is only set after a successful call @@ -65,7 +70,8 @@ private: std::string GetExtSaveDataPath(const std::string& mount_point, const Path& path); /** - * Constructs a path to the base folder to hold concrete ExtSaveData archives in the host file system. + * Constructs a path to the base folder to hold concrete ExtSaveData archives in the host file + * system. * @param mount_point The base folder where this folder resides, ie. SDMC or NAND. * @param shared Whether this ExtSaveData container is for SharedExtSaveDatas or not. * @returns The path to the base ExtSaveData archives' folder in the host file system diff --git a/src/core/file_sys/archive_romfs.cpp b/src/core/file_sys/archive_romfs.cpp index 38828b546..87455eb95 100644 --- a/src/core/file_sys/archive_romfs.cpp +++ b/src/core/file_sys/archive_romfs.cpp @@ -28,11 +28,12 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_RomFS::Open(const Path return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); } -ResultCode ArchiveFactory_RomFS::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { +ResultCode ArchiveFactory_RomFS::Format(const Path& path, + const FileSys::ArchiveFormatInfo& format_info) { LOG_ERROR(Service_FS, "Attempted to format a RomFS archive."); // TODO: Verify error code - return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, - ErrorSummary::NotSupported, ErrorLevel::Permanent); + return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, + ErrorLevel::Permanent); } ResultVal<ArchiveFormatInfo> ArchiveFactory_RomFS::GetFormatInfo(const Path& path) const { diff --git a/src/core/file_sys/archive_romfs.h b/src/core/file_sys/archive_romfs.h index c5a329122..3c68a6b1c 100644 --- a/src/core/file_sys/archive_romfs.h +++ b/src/core/file_sys/archive_romfs.h @@ -24,7 +24,9 @@ class ArchiveFactory_RomFS final : public ArchiveFactory { public: ArchiveFactory_RomFS(Loader::AppLoader& app_loader); - std::string GetName() const override { return "RomFS"; } + std::string GetName() const override { + return "RomFS"; + } ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; diff --git a/src/core/file_sys/archive_savedata.cpp b/src/core/file_sys/archive_savedata.cpp index fd5711e14..9a264091f 100644 --- a/src/core/file_sys/archive_savedata.cpp +++ b/src/core/file_sys/archive_savedata.cpp @@ -22,48 +22,55 @@ namespace FileSys { static std::string GetSaveDataContainerPath(const std::string& sdmc_directory) { return Common::StringFromFormat("%sNintendo 3DS/%s/%s/title/", sdmc_directory.c_str(), - SYSTEM_ID.c_str(), SDCARD_ID.c_str()); + SYSTEM_ID.c_str(), SDCARD_ID.c_str()); } static std::string GetSaveDataPath(const std::string& mount_location, u64 program_id) { u32 high = (u32)(program_id >> 32); u32 low = (u32)(program_id & 0xFFFFFFFF); - return Common::StringFromFormat("%s%08x/%08x/data/00000001/", mount_location.c_str(), high, low); + return Common::StringFromFormat("%s%08x/%08x/data/00000001/", mount_location.c_str(), high, + low); } static std::string GetSaveDataMetadataPath(const std::string& mount_location, u64 program_id) { u32 high = (u32)(program_id >> 32); u32 low = (u32)(program_id & 0xFFFFFFFF); - return Common::StringFromFormat("%s%08x/%08x/data/00000001.metadata", mount_location.c_str(), high, low); + return Common::StringFromFormat("%s%08x/%08x/data/00000001.metadata", mount_location.c_str(), + high, low); } ArchiveFactory_SaveData::ArchiveFactory_SaveData(const std::string& sdmc_directory) - : mount_point(GetSaveDataContainerPath(sdmc_directory)) { + : mount_point(GetSaveDataContainerPath(sdmc_directory)) { LOG_INFO(Service_FS, "Directory %s set as SaveData.", this->mount_point.c_str()); } ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const Path& path) { - std::string concrete_mount_point = GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id); + std::string concrete_mount_point = + GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id); if (!FileUtil::Exists(concrete_mount_point)) { // When a SaveData archive is created for the first time, it is not yet formatted // and the save file/directory structure expected by the game has not yet been initialized. - // Returning the NotFormatted error code will signal the game to provision the SaveData archive + // Returning the NotFormatted error code will signal the game to provision the SaveData + // archive // with the files and folders that it expects. return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, - ErrorSummary::InvalidState, ErrorLevel::Status); + ErrorSummary::InvalidState, ErrorLevel::Status); } auto archive = std::make_unique<DiskArchive>(std::move(concrete_mount_point)); return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); } -ResultCode ArchiveFactory_SaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { - std::string concrete_mount_point = GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id); +ResultCode ArchiveFactory_SaveData::Format(const Path& path, + const FileSys::ArchiveFormatInfo& format_info) { + std::string concrete_mount_point = + GetSaveDataPath(mount_point, Kernel::g_current_process->codeset->program_id); FileUtil::DeleteDirRecursively(concrete_mount_point); FileUtil::CreateFullPath(concrete_mount_point); // Write the format metadata - std::string metadata_path = GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); + std::string metadata_path = + GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); FileUtil::IOFile file(metadata_path, "wb"); if (file.IsOpen()) { @@ -74,13 +81,15 @@ ResultCode ArchiveFactory_SaveData::Format(const Path& path, const FileSys::Arch } ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveData::GetFormatInfo(const Path& path) const { - std::string metadata_path = GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); + std::string metadata_path = + GetSaveDataMetadataPath(mount_point, Kernel::g_current_process->codeset->program_id); FileUtil::IOFile file(metadata_path, "rb"); if (!file.IsOpen()) { LOG_ERROR(Service_FS, "Could not open metadata information for archive"); // TODO(Subv): Verify error code - return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, ErrorSummary::InvalidState, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, + ErrorSummary::InvalidState, ErrorLevel::Status); } ArchiveFormatInfo info = {}; diff --git a/src/core/file_sys/archive_savedata.h b/src/core/file_sys/archive_savedata.h index 7a5a24089..4ac324985 100644 --- a/src/core/file_sys/archive_savedata.h +++ b/src/core/file_sys/archive_savedata.h @@ -20,7 +20,9 @@ class ArchiveFactory_SaveData final : public ArchiveFactory { public: ArchiveFactory_SaveData(const std::string& mount_point); - std::string GetName() const override { return "SaveData"; } + std::string GetName() const override { + return "SaveData"; + } ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; diff --git a/src/core/file_sys/archive_savedatacheck.cpp b/src/core/file_sys/archive_savedatacheck.cpp index 9f65e5455..fd9b84302 100644 --- a/src/core/file_sys/archive_savedatacheck.cpp +++ b/src/core/file_sys/archive_savedatacheck.cpp @@ -25,12 +25,12 @@ static std::string GetSaveDataCheckContainerPath(const std::string& nand_directo } static std::string GetSaveDataCheckPath(const std::string& mount_point, u32 high, u32 low) { - return Common::StringFromFormat("%s%08x/%08x/content/00000000.app.romfs", - mount_point.c_str(), high, low); + return Common::StringFromFormat("%s%08x/%08x/content/00000000.app.romfs", mount_point.c_str(), + high, low); } -ArchiveFactory_SaveDataCheck::ArchiveFactory_SaveDataCheck(const std::string& nand_directory) : - mount_point(GetSaveDataCheckContainerPath(nand_directory)) { +ArchiveFactory_SaveDataCheck::ArchiveFactory_SaveDataCheck(const std::string& nand_directory) + : mount_point(GetSaveDataCheckContainerPath(nand_directory)) { } ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(const Path& path) { @@ -48,11 +48,12 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveDataCheck::Open(co return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); } -ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { +ResultCode ArchiveFactory_SaveDataCheck::Format(const Path& path, + const FileSys::ArchiveFormatInfo& format_info) { LOG_ERROR(Service_FS, "Attempted to format a SaveDataCheck archive."); // TODO: Verify error code - return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, - ErrorSummary::NotSupported, ErrorLevel::Permanent); + return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, + ErrorLevel::Permanent); } ResultVal<ArchiveFormatInfo> ArchiveFactory_SaveDataCheck::GetFormatInfo(const Path& path) const { diff --git a/src/core/file_sys/archive_savedatacheck.h b/src/core/file_sys/archive_savedatacheck.h index ea2624d64..4a4259260 100644 --- a/src/core/file_sys/archive_savedatacheck.h +++ b/src/core/file_sys/archive_savedatacheck.h @@ -20,7 +20,9 @@ class ArchiveFactory_SaveDataCheck final : public ArchiveFactory { public: ArchiveFactory_SaveDataCheck(const std::string& mount_point); - std::string GetName() const override { return "SaveDataCheck"; } + std::string GetName() const override { + return "SaveDataCheck"; + } ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; diff --git a/src/core/file_sys/archive_sdmc.cpp b/src/core/file_sys/archive_sdmc.cpp index 9b218af58..c1a28df6c 100644 --- a/src/core/file_sys/archive_sdmc.cpp +++ b/src/core/file_sys/archive_sdmc.cpp @@ -17,7 +17,8 @@ namespace FileSys { -ArchiveFactory_SDMC::ArchiveFactory_SDMC(const std::string& sdmc_directory) : sdmc_directory(sdmc_directory) { +ArchiveFactory_SDMC::ArchiveFactory_SDMC(const std::string& sdmc_directory) + : sdmc_directory(sdmc_directory) { LOG_INFO(Service_FS, "Directory %s set as SDMC.", sdmc_directory.c_str()); } @@ -40,7 +41,8 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMC::Open(const Path& return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); } -ResultCode ArchiveFactory_SDMC::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { +ResultCode ArchiveFactory_SDMC::Format(const Path& path, + const FileSys::ArchiveFormatInfo& format_info) { // This is kind of an undesirable operation, so let's just ignore it. :) return RESULT_SUCCESS; } diff --git a/src/core/file_sys/archive_sdmc.h b/src/core/file_sys/archive_sdmc.h index 35c0f3725..2523c3979 100644 --- a/src/core/file_sys/archive_sdmc.h +++ b/src/core/file_sys/archive_sdmc.h @@ -26,7 +26,9 @@ public: */ bool Initialize(); - std::string GetName() const override { return "SDMC"; } + std::string GetName() const override { + return "SDMC"; + } ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path) override; ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; diff --git a/src/core/file_sys/archive_systemsavedata.cpp b/src/core/file_sys/archive_systemsavedata.cpp index 1bcc228a1..1fb858247 100644 --- a/src/core/file_sys/archive_systemsavedata.cpp +++ b/src/core/file_sys/archive_systemsavedata.cpp @@ -45,11 +45,11 @@ Path ConstructSystemSaveDataBinaryPath(u32 high, u32 low) { for (unsigned i = 0; i < 4; ++i) binary_path.push_back((low >> (8 * i)) & 0xFF); - return { binary_path }; + return {binary_path}; } ArchiveFactory_SystemSaveData::ArchiveFactory_SystemSaveData(const std::string& nand_path) - : base_path(GetSystemSaveDataContainerPath(nand_path)) { + : base_path(GetSystemSaveDataContainerPath(nand_path)) { } ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(const Path& path) { @@ -57,13 +57,14 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c if (!FileUtil::Exists(fullpath)) { // TODO(Subv): Check error code, this one is probably wrong return ResultCode(ErrorDescription::FS_NotFormatted, ErrorModule::FS, - ErrorSummary::InvalidState, ErrorLevel::Status); + ErrorSummary::InvalidState, ErrorLevel::Status); } auto archive = std::make_unique<DiskArchive>(fullpath); return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive)); } -ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) { +ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path, + const FileSys::ArchiveFormatInfo& format_info) { std::string fullpath = GetSystemSaveDataPath(base_path, path); FileUtil::DeleteDirRecursively(fullpath); FileUtil::CreateFullPath(fullpath); diff --git a/src/core/file_sys/archive_systemsavedata.h b/src/core/file_sys/archive_systemsavedata.h index 2bc13d4ee..61a002a7d 100644 --- a/src/core/file_sys/archive_systemsavedata.h +++ b/src/core/file_sys/archive_systemsavedata.h @@ -26,7 +26,9 @@ public: ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info) override; ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path) const override; - std::string GetName() const override { return "SystemSaveData"; } + std::string GetName() const override { + return "SystemSaveData"; + } private: std::string base_path; @@ -42,7 +44,8 @@ private: std::string GetSystemSaveDataPath(const std::string& mount_point, const Path& path); /** - * Constructs a path to the base folder to hold concrete SystemSaveData archives in the host file system. + * Constructs a path to the base folder to hold concrete SystemSaveData archives in the host file + * system. * @param mount_point The base folder where this folder resides, ie. SDMC or NAND. * @returns The path to the base SystemSaveData archives' folder in the host file system */ diff --git a/src/core/file_sys/directory_backend.h b/src/core/file_sys/directory_backend.h index a25dc0cfa..c402ee60b 100644 --- a/src/core/file_sys/directory_backend.h +++ b/src/core/file_sys/directory_backend.h @@ -19,15 +19,16 @@ const size_t FILENAME_LENGTH = 0x20C / 2; struct Entry { char16_t filename[FILENAME_LENGTH]; // Entry name (UTF-16, null-terminated) std::array<char, 9> short_name; // 8.3 file name ('longfilename' -> 'LONGFI~1', null-terminated) - char unknown1; // unknown (observed values: 0x0A, 0x70, 0xFD) - std::array<char, 4> extension; // 8.3 file extension (set to spaces for directories, null-terminated) - char unknown2; // unknown (always 0x01) - char unknown3; // unknown (0x00 or 0x08) + char unknown1; // unknown (observed values: 0x0A, 0x70, 0xFD) + std::array<char, 4> + extension; // 8.3 file extension (set to spaces for directories, null-terminated) + char unknown2; // unknown (always 0x01) + char unknown3; // unknown (0x00 or 0x08) char is_directory; // directory flag - char is_hidden; // hidden flag - char is_archive; // archive flag + char is_hidden; // hidden flag + char is_archive; // archive flag char is_read_only; // read-only flag - u64 file_size; // file size (for files only) + u64 file_size; // file size (for files only) }; static_assert(sizeof(Entry) == 0x228, "Directory Entry struct isn't exactly 0x228 bytes long!"); static_assert(offsetof(Entry, short_name) == 0x20C, "Wrong offset for short_name in Entry."); @@ -37,8 +38,10 @@ static_assert(offsetof(Entry, file_size) == 0x220, "Wrong offset for file_size i class DirectoryBackend : NonCopyable { public: - DirectoryBackend() { } - virtual ~DirectoryBackend() { } + DirectoryBackend() { + } + virtual ~DirectoryBackend() { + } /** * Open the directory diff --git a/src/core/file_sys/disk_archive.cpp b/src/core/file_sys/disk_archive.cpp index 489cc96fb..c084303c1 100644 --- a/src/core/file_sys/disk_archive.cpp +++ b/src/core/file_sys/disk_archive.cpp @@ -17,7 +17,8 @@ namespace FileSys { -ResultVal<std::unique_ptr<FileBackend>> DiskArchive::OpenFile(const Path& path, const Mode mode) const { +ResultVal<std::unique_ptr<FileBackend>> DiskArchive::OpenFile(const Path& path, + const Mode mode) const { LOG_DEBUG(Service_FS, "called path=%s mode=%01X", path.DebugStr().c_str(), mode.hex); auto file = std::make_unique<DiskFile>(*this, path, mode); ResultCode result = file->Open(); @@ -30,15 +31,18 @@ ResultCode DiskArchive::DeleteFile(const Path& path) const { std::string file_path = mount_point + path.AsString(); if (FileUtil::IsDirectory(file_path)) - return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, + ErrorLevel::Status); if (!FileUtil::Exists(file_path)) - return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, + ErrorLevel::Status); if (FileUtil::Delete(file_path)) return RESULT_SUCCESS; - return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, + ErrorLevel::Status); } bool DiskArchive::RenameFile(const Path& src_path, const Path& dest_path) const { @@ -53,10 +57,12 @@ ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const { std::string full_path = mount_point + path.AsString(); if (FileUtil::IsDirectory(full_path)) - return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, + ErrorLevel::Status); if (FileUtil::Exists(full_path)) - return ResultCode(ErrorDescription::FS_AlreadyExists, ErrorModule::FS, ErrorSummary::NothingHappened, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_AlreadyExists, ErrorModule::FS, + ErrorSummary::NothingHappened, ErrorLevel::Status); if (size == 0) { FileUtil::CreateEmptyFile(full_path); @@ -69,10 +75,10 @@ ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u64 size) const { if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) return RESULT_SUCCESS; - return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, ErrorLevel::Info); + return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, + ErrorLevel::Info); } - bool DiskArchive::CreateDirectory(const Path& path) const { return FileUtil::CreateDir(mount_point + path.AsString()); } @@ -106,17 +112,21 @@ DiskFile::DiskFile(const DiskArchive& archive, const Path& path, const Mode mode ResultCode DiskFile::Open() { if (FileUtil::IsDirectory(path)) - return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_NotAFile, ErrorModule::FS, ErrorSummary::Canceled, + ErrorLevel::Status); // Specifying only the Create flag is invalid if (mode.create_flag && !mode.read_flag && !mode.write_flag) { - return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, + ErrorSummary::Canceled, ErrorLevel::Status); } if (!FileUtil::Exists(path)) { if (!mode.create_flag) { - LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.", path.c_str()); - return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); + LOG_ERROR(Service_FS, "Non-existing file %s can't be open without mode create.", + path.c_str()); + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, + ErrorSummary::NotFound, ErrorLevel::Status); } else { // Create the file FileUtil::CreateEmptyFile(path); @@ -135,20 +145,24 @@ ResultCode DiskFile::Open() { file = std::make_unique<FileUtil::IOFile>(path, mode_string.c_str()); if (file->IsOpen()) return RESULT_SUCCESS; - return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_NotFound, ErrorModule::FS, ErrorSummary::NotFound, + ErrorLevel::Status); } ResultVal<size_t> DiskFile::Read(const u64 offset, const size_t length, u8* buffer) const { if (!mode.read_flag && !mode.write_flag) - return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, + ErrorSummary::Canceled, ErrorLevel::Status); file->Seek(offset, SEEK_SET); return MakeResult<size_t>(file->ReadBytes(buffer, length)); } -ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { +ResultVal<size_t> DiskFile::Write(const u64 offset, const size_t length, const bool flush, + const u8* buffer) const { if (!mode.write_flag) - return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, ErrorSummary::Canceled, ErrorLevel::Status); + return ResultCode(ErrorDescription::FS_InvalidOpenFlags, ErrorModule::FS, + ErrorSummary::Canceled, ErrorLevel::Status); file->Seek(offset, SEEK_SET); size_t written = file->WriteBytes(buffer, length); @@ -198,7 +212,8 @@ u32 DiskDirectory::Read(const u32 count, Entry* entries) { const std::string& filename = file.virtualName; Entry& entry = entries[entries_read]; - LOG_TRACE(Service_FS, "File %s: size=%llu dir=%d", filename.c_str(), file.size, file.isDirectory); + LOG_TRACE(Service_FS, "File %s: size=%llu dir=%d", filename.c_str(), file.size, + file.isDirectory); // TODO(Link Mauve): use a proper conversion to UTF-16. for (size_t j = 0; j < FILENAME_LENGTH; ++j) { diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h index b4cc2f702..3f620128f 100644 --- a/src/core/file_sys/disk_archive.h +++ b/src/core/file_sys/disk_archive.h @@ -29,11 +29,15 @@ namespace FileSys { */ class DiskArchive : public ArchiveBackend { public: - DiskArchive(const std::string& mount_point_) : mount_point(mount_point_) {} + DiskArchive(const std::string& mount_point_) : mount_point(mount_point_) { + } - virtual std::string GetName() const override { return "DiskArchive: " + mount_point; } + virtual std::string GetName() const override { + return "DiskArchive: " + mount_point; + } - ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode mode) const override; + ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, + const Mode mode) const override; ResultCode DeleteFile(const Path& path) const override; bool RenameFile(const Path& src_path, const Path& dest_path) const override; bool DeleteDirectory(const Path& path) const override; diff --git a/src/core/file_sys/file_backend.h b/src/core/file_sys/file_backend.h index 9137bbbad..9eae697c2 100644 --- a/src/core/file_sys/file_backend.h +++ b/src/core/file_sys/file_backend.h @@ -16,8 +16,10 @@ namespace FileSys { class FileBackend : NonCopyable { public: - FileBackend() { } - virtual ~FileBackend() { } + FileBackend() { + } + virtual ~FileBackend() { + } /** * Open the file @@ -42,7 +44,8 @@ public: * @param buffer Buffer to read data from * @return Number of bytes written, or error code */ - virtual ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const = 0; + virtual ResultVal<size_t> Write(u64 offset, size_t length, bool flush, + const u8* buffer) const = 0; /** * 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 c61791ef7..235a962e9 100644 --- a/src/core/file_sys/ivfc_archive.cpp +++ b/src/core/file_sys/ivfc_archive.cpp @@ -19,40 +19,49 @@ std::string IVFCArchive::GetName() const { return "IVFC"; } -ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path, const Mode mode) const { - return MakeResult<std::unique_ptr<FileBackend>>(std::make_unique<IVFCFile>(romfs_file, data_offset, data_size)); +ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path, + const Mode mode) const { + return MakeResult<std::unique_ptr<FileBackend>>( + std::make_unique<IVFCFile>(romfs_file, data_offset, data_size)); } ResultCode IVFCArchive::DeleteFile(const Path& path) const { - LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).", GetName().c_str()); + LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive (%s).", + GetName().c_str()); // TODO(Subv): Verify error code - return ResultCode(ErrorDescription::NoData, ErrorModule::FS, - ErrorSummary::Canceled, ErrorLevel::Status); + return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, + ErrorLevel::Status); } bool IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { - LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).", GetName().c_str()); + LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).", + GetName().c_str()); return false; } bool IVFCArchive::DeleteDirectory(const Path& path) const { - LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).", GetName().c_str()); + LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive (%s).", + GetName().c_str()); return false; } ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const { - LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).", GetName().c_str()); + LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive (%s).", + GetName().c_str()); // TODO: Verify error code - return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, ErrorLevel::Permanent); + return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, + ErrorLevel::Permanent); } bool IVFCArchive::CreateDirectory(const Path& path) const { - LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive (%s).", GetName().c_str()); + LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive (%s).", + GetName().c_str()); return false; } bool IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { - LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).", GetName().c_str()); + LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive (%s).", + GetName().c_str()); return false; } @@ -75,7 +84,8 @@ ResultVal<size_t> IVFCFile::Read(const u64 offset, const size_t length, u8* buff return MakeResult<size_t>(romfs_file->ReadBytes(buffer, read_length)); } -ResultVal<size_t> IVFCFile::Write(const u64 offset, const size_t length, const bool flush, const u8* buffer) const { +ResultVal<size_t> IVFCFile::Write(const u64 offset, const size_t length, const bool flush, + const u8* buffer) const { LOG_ERROR(Service_FS, "Attempted to write to IVFC file"); // TODO(Subv): Find error code return MakeResult<size_t>(0); diff --git a/src/core/file_sys/ivfc_archive.h b/src/core/file_sys/ivfc_archive.h index 19d32dcca..dab1958f6 100644 --- a/src/core/file_sys/ivfc_archive.h +++ b/src/core/file_sys/ivfc_archive.h @@ -30,11 +30,13 @@ namespace FileSys { class IVFCArchive : public ArchiveBackend { public: IVFCArchive(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) - : romfs_file(file), data_offset(offset), data_size(size) {} + : romfs_file(file), data_offset(offset), data_size(size) { + } std::string GetName() const override; - ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, const Mode mode) const override; + ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, + const Mode mode) const override; ResultCode DeleteFile(const Path& path) const override; bool RenameFile(const Path& src_path, const Path& dest_path) const override; bool DeleteDirectory(const Path& path) const override; @@ -53,15 +55,21 @@ protected: class IVFCFile : public FileBackend { public: IVFCFile(std::shared_ptr<FileUtil::IOFile> file, u64 offset, u64 size) - : romfs_file(file), data_offset(offset), data_size(size) {} + : romfs_file(file), data_offset(offset), data_size(size) { + } - ResultCode Open() override { return RESULT_SUCCESS; } + ResultCode Open() override { + return RESULT_SUCCESS; + } ResultVal<size_t> Read(u64 offset, size_t length, u8* buffer) const override; ResultVal<size_t> Write(u64 offset, size_t length, bool flush, const u8* buffer) const override; u64 GetSize() const override; bool SetSize(u64 size) const override; - bool Close() const override { return false; } - void Flush() const override { } + bool Close() const override { + return false; + } + void Flush() const override { + } private: std::shared_ptr<FileUtil::IOFile> romfs_file; @@ -71,9 +79,15 @@ private: class IVFCDirectory : public DirectoryBackend { public: - bool Open() override { return false; } - u32 Read(const u32 count, Entry* entries) override { return 0; } - bool Close() const override { return false; } + bool Open() override { + return false; + } + u32 Read(const u32 count, Entry* entries) override { + return 0; + } + bool Close() const override { + return false; + } }; } // namespace FileSys |