mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	kernel: Update to use atmosphere macros and correct Result (#7242)
* kernel: Switch to atmosphere style macros * code: Rename ResultCode to Result * code: Result constants are lower case * Address review comments * core: Remove CASCADE_CODE * R_TRY replaces completely * core: Run clang format
This commit is contained in:
		
							parent
							
								
									811303ea54
								
							
						
					
					
						commit
						5a7f615da1
					
				
					 132 changed files with 2807 additions and 2995 deletions
				
			
		|  | @ -127,7 +127,7 @@ public: | |||
|      * @param path Path relative to the archive | ||||
|      * @return Result of the operation | ||||
|      */ | ||||
|     virtual ResultCode DeleteFile(const Path& path) const = 0; | ||||
|     virtual Result DeleteFile(const Path& path) const = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Rename a File specified by its path | ||||
|  | @ -135,21 +135,21 @@ public: | |||
|      * @param dest_path Destination path relative to the archive | ||||
|      * @return Result of the operation | ||||
|      */ | ||||
|     virtual ResultCode RenameFile(const Path& src_path, const Path& dest_path) const = 0; | ||||
|     virtual Result RenameFile(const Path& src_path, const Path& dest_path) const = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Delete a directory specified by its path | ||||
|      * @param path Path relative to the archive | ||||
|      * @return Result of the operation | ||||
|      */ | ||||
|     virtual ResultCode DeleteDirectory(const Path& path) const = 0; | ||||
|     virtual Result DeleteDirectory(const Path& path) const = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Delete a directory specified by its path and anything under it | ||||
|      * @param path Path relative to the archive | ||||
|      * @return Result of the operation | ||||
|      */ | ||||
|     virtual ResultCode DeleteDirectoryRecursively(const Path& path) const = 0; | ||||
|     virtual Result DeleteDirectoryRecursively(const Path& path) const = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Create a file specified by its path | ||||
|  | @ -157,14 +157,14 @@ public: | |||
|      * @param size The size of the new file, filled with zeroes | ||||
|      * @return Result of the operation | ||||
|      */ | ||||
|     virtual ResultCode CreateFile(const Path& path, u64 size) const = 0; | ||||
|     virtual Result CreateFile(const Path& path, u64 size) const = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Create a directory specified by its path | ||||
|      * @param path Path relative to the archive | ||||
|      * @return Result of the operation | ||||
|      */ | ||||
|     virtual ResultCode CreateDirectory(const Path& path) const = 0; | ||||
|     virtual Result CreateDirectory(const Path& path) const = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Rename a Directory specified by its path | ||||
|  | @ -172,7 +172,7 @@ public: | |||
|      * @param dest_path Destination path relative to the archive | ||||
|      * @return Result of the operation | ||||
|      */ | ||||
|     virtual ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const = 0; | ||||
|     virtual Result RenameDirectory(const Path& src_path, const Path& dest_path) const = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Open a directory specified by its path | ||||
|  | @ -229,10 +229,10 @@ public: | |||
|      * @param path Path to the archive | ||||
|      * @param format_info Format information for the new archive | ||||
|      * @param program_id the program ID of the client that requests the operation | ||||
|      * @return ResultCode of the operation, 0 on success | ||||
|      * @return Result of the operation, 0 on success | ||||
|      */ | ||||
|     virtual ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                               u64 program_id) = 0; | ||||
|     virtual Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                           u64 program_id) = 0; | ||||
| 
 | ||||
|     /**
 | ||||
|      * Retrieves the format info about the archive with the specified path | ||||
|  |  | |||
|  | @ -40,7 +40,7 @@ public: | |||
|     ResultVal<std::size_t> Write(u64 offset, std::size_t length, bool flush, | ||||
|                                  const u8* buffer) override { | ||||
|         if (offset > size) { | ||||
|             return ERR_WRITE_BEYOND_END; | ||||
|             return ResultWriteBeyondEnd; | ||||
|         } else if (offset == size) { | ||||
|             return 0ULL; | ||||
|         } | ||||
|  | @ -108,17 +108,17 @@ public: | |||
| 
 | ||||
|         if (!path_parser.IsValid()) { | ||||
|             LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|             return ERROR_INVALID_PATH; | ||||
|             return ResultInvalidPath; | ||||
|         } | ||||
| 
 | ||||
|         if (mode.hex == 0) { | ||||
|             LOG_ERROR(Service_FS, "Empty open mode"); | ||||
|             return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|             return ResultUnsupportedOpenFlags; | ||||
|         } | ||||
| 
 | ||||
|         if (mode.create_flag) { | ||||
|             LOG_ERROR(Service_FS, "Create flag is not supported"); | ||||
|             return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|             return ResultUnsupportedOpenFlags; | ||||
|         } | ||||
| 
 | ||||
|         const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -126,17 +126,17 @@ public: | |||
|         switch (path_parser.GetHostStatus(mount_point)) { | ||||
|         case PathParser::InvalidMountPoint: | ||||
|             LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|             return ERROR_FILE_NOT_FOUND; | ||||
|             return ResultFileNotFound; | ||||
|         case PathParser::PathNotFound: | ||||
|             LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|             return ERROR_PATH_NOT_FOUND; | ||||
|             return ResultPathNotFound; | ||||
|         case PathParser::FileInPath: | ||||
|         case PathParser::DirectoryFound: | ||||
|             LOG_ERROR(Service_FS, "Unexpected file or directory in {}", full_path); | ||||
|             return ERROR_UNEXPECTED_FILE_OR_DIRECTORY; | ||||
|             return ResultUnexpectedFileOrDirectory; | ||||
|         case PathParser::NotFound: | ||||
|             LOG_ERROR(Service_FS, "{} not found", full_path); | ||||
|             return ERROR_FILE_NOT_FOUND; | ||||
|             return ResultFileNotFound; | ||||
|         case PathParser::FileFound: | ||||
|             break; // Expected 'success' case
 | ||||
|         } | ||||
|  | @ -144,7 +144,7 @@ public: | |||
|         FileUtil::IOFile file(full_path, "r+b"); | ||||
|         if (!file.IsOpen()) { | ||||
|             LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path); | ||||
|             return ERROR_FILE_NOT_FOUND; | ||||
|             return ResultFileNotFound; | ||||
|         } | ||||
| 
 | ||||
|         Mode rwmode; | ||||
|  | @ -155,10 +155,10 @@ public: | |||
|                                                  std::move(delay_generator)); | ||||
|     } | ||||
| 
 | ||||
|     ResultCode CreateFile(const Path& path, u64 size) const override { | ||||
|     Result CreateFile(const Path& path, u64 size) const override { | ||||
|         if (size == 0) { | ||||
|             LOG_ERROR(Service_FS, "Zero-size file is not supported"); | ||||
|             return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|             return ResultUnsupportedOpenFlags; | ||||
|         } | ||||
|         return SaveDataArchive::CreateFile(path, size); | ||||
|     } | ||||
|  | @ -250,18 +250,18 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(cons | |||
|         // TODO(Subv): Verify the archive behavior of SharedExtSaveData compared to ExtSaveData.
 | ||||
|         // ExtSaveData seems to return FS_NotFound (120) when the archive doesn't exist.
 | ||||
|         if (type != ExtSaveDataType::Shared) { | ||||
|             return ERR_NOT_FOUND_INVALID_STATE; | ||||
|             return ResultNotFoundInvalidState; | ||||
|         } else { | ||||
|             return ERR_NOT_FORMATTED; | ||||
|             return ResultNotFormatted; | ||||
|         } | ||||
|     } | ||||
|     std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<ExtSaveDataDelayGenerator>(); | ||||
|     return std::make_unique<ExtSaveDataArchive>(fullpath, std::move(delay_generator)); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path, | ||||
|                                               const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                               u64 program_id) { | ||||
| Result ArchiveFactory_ExtSaveData::Format(const Path& path, | ||||
|                                           const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                           u64 program_id) { | ||||
|     auto corrected_path = GetCorrectedPath(path); | ||||
| 
 | ||||
|     // These folders are always created with the ExtSaveData
 | ||||
|  | @ -276,11 +276,11 @@ ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path, | |||
| 
 | ||||
|     if (!file.IsOpen()) { | ||||
|         // TODO(Subv): Find the correct error code
 | ||||
|         return RESULT_UNKNOWN; | ||||
|         return ResultUnknown; | ||||
|     } | ||||
| 
 | ||||
|     file.WriteBytes(&format_info, sizeof(format_info)); | ||||
|     return RESULT_SUCCESS; | ||||
|     return ResultSuccess; | ||||
| } | ||||
| 
 | ||||
| ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Path& path, | ||||
|  | @ -291,7 +291,7 @@ 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 ERR_NOT_FORMATTED; | ||||
|         return ResultNotFormatted; | ||||
|     } | ||||
| 
 | ||||
|     ArchiveFormatInfo info = {}; | ||||
|  |  | |||
|  | @ -31,8 +31,8 @@ public: | |||
|     } | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; | ||||
|     ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                       u64 program_id) override; | ||||
|     Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                   u64 program_id) override; | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; | ||||
| 
 | ||||
|     const std::string& GetMountPoint() const { | ||||
|  |  | |||
|  | @ -73,13 +73,13 @@ ResultVal<std::unique_ptr<FileBackend>> NCCHArchive::OpenFile(const Path& path, | |||
|                                                               const Mode& mode) const { | ||||
|     if (path.GetType() != LowPathType::Binary) { | ||||
|         LOG_ERROR(Service_FS, "Path need to be Binary"); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     std::vector<u8> binary = path.AsBinary(); | ||||
|     if (binary.size() != sizeof(NCCHFilePath)) { | ||||
|         LOG_ERROR(Service_FS, "Wrong path size {}", binary.size()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     NCCHFilePath openfile_path; | ||||
|  | @ -174,63 +174,63 @@ ResultVal<std::unique_ptr<FileBackend>> NCCHArchive::OpenFile(const Path& path, | |||
|             return std::make_unique<IVFCFileInMemory>(std::move(archive_data), romfs_offset, | ||||
|                                                       romfs_size, std::move(delay_generator)); | ||||
|         } | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     } | ||||
| 
 | ||||
|     return file; | ||||
| } | ||||
| 
 | ||||
| ResultCode NCCHArchive::DeleteFile(const Path& path) const { | ||||
| Result NCCHArchive::DeleteFile(const Path& path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to delete a file from an NCCH archive ({}).", GetName()); | ||||
|     // TODO(Subv): Verify error code
 | ||||
|     return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, | ||||
|                       ErrorLevel::Status); | ||||
|     return Result(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, | ||||
|                   ErrorLevel::Status); | ||||
| } | ||||
| 
 | ||||
| ResultCode NCCHArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | ||||
| Result NCCHArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to rename a file within an NCCH archive ({}).", GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultCode NCCHArchive::DeleteDirectory(const Path& path) const { | ||||
| Result NCCHArchive::DeleteDirectory(const Path& path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an NCCH archive ({}).", | ||||
|                  GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultCode NCCHArchive::DeleteDirectoryRecursively(const Path& path) const { | ||||
| Result NCCHArchive::DeleteDirectoryRecursively(const Path& path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an NCCH archive ({}).", | ||||
|                  GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultCode NCCHArchive::CreateFile(const Path& path, u64 size) const { | ||||
| Result NCCHArchive::CreateFile(const Path& path, u64 size) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to create a file in an NCCH archive ({}).", GetName()); | ||||
|     // TODO: Verify error code
 | ||||
|     return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, | ||||
|                       ErrorLevel::Permanent); | ||||
|     return Result(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, | ||||
|                   ErrorLevel::Permanent); | ||||
| } | ||||
| 
 | ||||
| ResultCode NCCHArchive::CreateDirectory(const Path& path) const { | ||||
| Result NCCHArchive::CreateDirectory(const Path& path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to create a directory in an NCCH archive ({}).", GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultCode NCCHArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | ||||
| Result NCCHArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to rename a file within an NCCH archive ({}).", GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultVal<std::unique_ptr<DirectoryBackend>> NCCHArchive::OpenDirectory(const Path& path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to open a directory within an NCCH archive ({}).", | ||||
|                  GetName().c_str()); | ||||
|     // TODO(shinyquagsire23): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| u64 NCCHArchive::GetFreeBytes() const { | ||||
|  | @ -276,13 +276,13 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path& | |||
|                                                                      u64 program_id) { | ||||
|     if (path.GetType() != LowPathType::Binary) { | ||||
|         LOG_ERROR(Service_FS, "Path need to be Binary"); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     std::vector<u8> binary = path.AsBinary(); | ||||
|     if (binary.size() != sizeof(NCCHArchivePath)) { | ||||
|         LOG_ERROR(Service_FS, "Wrong path size {}", binary.size()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     NCCHArchivePath open_path; | ||||
|  | @ -292,20 +292,19 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path& | |||
|         open_path.tid, static_cast<Service::FS::MediaType>(open_path.media_type & 0xFF)); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveFactory_NCCH::Format(const Path& path, | ||||
|                                        const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                        u64 program_id) { | ||||
| Result ArchiveFactory_NCCH::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                    u64 program_id) { | ||||
|     LOG_ERROR(Service_FS, "Attempted to format a NCCH archive."); | ||||
|     // TODO: Verify error code
 | ||||
|     return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, | ||||
|                       ErrorLevel::Permanent); | ||||
|     return Result(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, | ||||
|                   ErrorLevel::Permanent); | ||||
| } | ||||
| 
 | ||||
| ResultVal<ArchiveFormatInfo> ArchiveFactory_NCCH::GetFormatInfo(const Path& path, | ||||
|                                                                 u64 program_id) const { | ||||
|     // TODO(Subv): Implement
 | ||||
|     LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName()); | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| } // namespace FileSys
 | ||||
|  |  | |||
|  | @ -50,13 +50,13 @@ public: | |||
| 
 | ||||
|     ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, | ||||
|                                                      const Mode& mode) const override; | ||||
|     ResultCode DeleteFile(const Path& path) const override; | ||||
|     ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; | ||||
|     ResultCode DeleteDirectory(const Path& path) const override; | ||||
|     ResultCode DeleteDirectoryRecursively(const Path& path) const override; | ||||
|     ResultCode CreateFile(const Path& path, u64 size) const override; | ||||
|     ResultCode CreateDirectory(const Path& path) const override; | ||||
|     ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; | ||||
|     Result DeleteFile(const Path& path) const override; | ||||
|     Result RenameFile(const Path& src_path, const Path& dest_path) const override; | ||||
|     Result DeleteDirectory(const Path& path) const override; | ||||
|     Result DeleteDirectoryRecursively(const Path& path) const override; | ||||
|     Result CreateFile(const Path& path, u64 size) const override; | ||||
|     Result CreateDirectory(const Path& path) const override; | ||||
|     Result RenameDirectory(const Path& src_path, const Path& dest_path) const override; | ||||
|     ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override; | ||||
|     u64 GetFreeBytes() const override; | ||||
| 
 | ||||
|  | @ -114,8 +114,8 @@ public: | |||
|     } | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; | ||||
|     ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                       u64 program_id) override; | ||||
|     Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                   u64 program_id) override; | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -25,14 +25,14 @@ template <typename T> | |||
| ResultVal<std::tuple<MediaType, u64>> ParsePath(const Path& path, T program_id_reader) { | ||||
|     if (path.GetType() != LowPathType::Binary) { | ||||
|         LOG_ERROR(Service_FS, "Wrong path type {}", path.GetType()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     std::vector<u8> vec_data = path.AsBinary(); | ||||
| 
 | ||||
|     if (vec_data.size() != 12) { | ||||
|         LOG_ERROR(Service_FS, "Wrong path length {}", vec_data.size()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const u32* data = reinterpret_cast<const u32*>(vec_data.data()); | ||||
|  | @ -42,7 +42,7 @@ ResultVal<std::tuple<MediaType, u64>> ParsePath(const Path& path, T program_id_r | |||
|         LOG_ERROR(Service_FS, "Unsupported media type {}", media_type); | ||||
| 
 | ||||
|         // Note: this is strange, but the error code was verified with a real 3DS
 | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     return std::make_tuple(media_type, program_id_reader(data)); | ||||
|  | @ -72,16 +72,17 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataPermitted | |||
| 
 | ||||
|     if (media_type == MediaType::GameCard) { | ||||
|         LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||||
|         return ERROR_GAMECARD_NOT_INSERTED; | ||||
|         return ResultGamecardNotInserted; | ||||
|     } | ||||
| 
 | ||||
|     return sd_savedata_source->Open(program_id); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveFactory_OtherSaveDataPermitted::Format( | ||||
|     const Path& path, const FileSys::ArchiveFormatInfo& format_info, u64 program_id) { | ||||
| Result ArchiveFactory_OtherSaveDataPermitted::Format(const Path& path, | ||||
|                                                      const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                                      u64 program_id) { | ||||
|     LOG_ERROR(Service_FS, "Attempted to format a OtherSaveDataPermitted archive."); | ||||
|     return ERROR_INVALID_PATH; | ||||
|     return ResultInvalidPath; | ||||
| } | ||||
| 
 | ||||
| ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataPermitted::GetFormatInfo( | ||||
|  | @ -92,7 +93,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataPermitted::GetFormatInf | |||
| 
 | ||||
|     if (media_type == MediaType::GameCard) { | ||||
|         LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||||
|         return ERROR_GAMECARD_NOT_INSERTED; | ||||
|         return ResultGamecardNotInserted; | ||||
|     } | ||||
| 
 | ||||
|     return sd_savedata_source->GetFormatInfo(program_id); | ||||
|  | @ -110,21 +111,22 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_OtherSaveDataGeneral:: | |||
| 
 | ||||
|     if (media_type == MediaType::GameCard) { | ||||
|         LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||||
|         return ERROR_GAMECARD_NOT_INSERTED; | ||||
|         return ResultGamecardNotInserted; | ||||
|     } | ||||
| 
 | ||||
|     return sd_savedata_source->Open(program_id); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveFactory_OtherSaveDataGeneral::Format( | ||||
|     const Path& path, const FileSys::ArchiveFormatInfo& format_info, u64 /*client_program_id*/) { | ||||
| Result ArchiveFactory_OtherSaveDataGeneral::Format(const Path& path, | ||||
|                                                    const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                                    u64 /*client_program_id*/) { | ||||
|     MediaType media_type; | ||||
|     u64 program_id; | ||||
|     CASCADE_RESULT(std::tie(media_type, program_id), ParsePathGeneral(path)); | ||||
| 
 | ||||
|     if (media_type == MediaType::GameCard) { | ||||
|         LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||||
|         return ERROR_GAMECARD_NOT_INSERTED; | ||||
|         return ResultGamecardNotInserted; | ||||
|     } | ||||
| 
 | ||||
|     return sd_savedata_source->Format(program_id, format_info); | ||||
|  | @ -138,7 +140,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_OtherSaveDataGeneral::GetFormatInfo( | |||
| 
 | ||||
|     if (media_type == MediaType::GameCard) { | ||||
|         LOG_WARNING(Service_FS, "(stubbed) Unimplemented media type GameCard"); | ||||
|         return ERROR_GAMECARD_NOT_INSERTED; | ||||
|         return ResultGamecardNotInserted; | ||||
|     } | ||||
| 
 | ||||
|     return sd_savedata_source->GetFormatInfo(program_id); | ||||
|  |  | |||
|  | @ -22,8 +22,8 @@ public: | |||
|     } | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; | ||||
|     ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                       u64 program_id) override; | ||||
|     Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                   u64 program_id) override; | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; | ||||
| 
 | ||||
| private: | ||||
|  | @ -49,8 +49,8 @@ public: | |||
|     } | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; | ||||
|     ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                       u64 program_id) override; | ||||
|     Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                   u64 program_id) override; | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -21,9 +21,9 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SaveData::Open(const P | |||
|     return sd_savedata_source->Open(program_id); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveFactory_SaveData::Format(const Path& path, | ||||
|                                            const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                            u64 program_id) { | ||||
| Result ArchiveFactory_SaveData::Format(const Path& path, | ||||
|                                        const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                        u64 program_id) { | ||||
|     return sd_savedata_source->Format(program_id, format_info); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -20,8 +20,8 @@ public: | |||
|     } | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; | ||||
|     ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                       u64 program_id) override; | ||||
|     Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                   u64 program_id) override; | ||||
| 
 | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; | ||||
| 
 | ||||
|  |  | |||
|  | @ -62,17 +62,17 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCArchive::OpenFileBase(const Path& pa | |||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     if (mode.hex == 0) { | ||||
|         LOG_ERROR(Service_FS, "Empty open mode"); | ||||
|         return ERROR_INVALID_OPEN_FLAGS; | ||||
|         return ResultInvalidOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     if (mode.create_flag && !mode.write_flag) { | ||||
|         LOG_ERROR(Service_FS, "Create flag set but write flag not set"); | ||||
|         return ERROR_INVALID_OPEN_FLAGS; | ||||
|         return ResultInvalidOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -80,19 +80,19 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCArchive::OpenFileBase(const Path& pa | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|     case PathParser::FileInPath: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::DirectoryFound: | ||||
|         LOG_ERROR(Service_FS, "{} is not a file", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC; | ||||
|         return ResultUnexpectedFileOrDirectorySdmc; | ||||
|     case PathParser::NotFound: | ||||
|         if (!mode.create_flag) { | ||||
|             LOG_ERROR(Service_FS, "Non-existing file {} can't be open without mode create.", | ||||
|                       full_path); | ||||
|             return ERROR_NOT_FOUND; | ||||
|             return ResultNotFound; | ||||
|         } else { | ||||
|             // Create the file
 | ||||
|             FileUtil::CreateEmptyFile(full_path); | ||||
|  | @ -105,19 +105,19 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCArchive::OpenFileBase(const Path& pa | |||
|     FileUtil::IOFile file(full_path, mode.write_flag ? "r+b" : "rb"); | ||||
|     if (!file.IsOpen()) { | ||||
|         LOG_CRITICAL(Service_FS, "Error opening {}: {}", full_path, Common::GetLastErrorMsg()); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     } | ||||
| 
 | ||||
|     std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<SDMCDelayGenerator>(); | ||||
|     return std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator)); | ||||
| } | ||||
| 
 | ||||
| ResultCode SDMCArchive::DeleteFile(const Path& path) const { | ||||
| Result SDMCArchive::DeleteFile(const Path& path) const { | ||||
|     const PathParser path_parser(path); | ||||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -125,110 +125,109 @@ ResultCode SDMCArchive::DeleteFile(const Path& path) const { | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|     case PathParser::FileInPath: | ||||
|     case PathParser::NotFound: | ||||
|         LOG_DEBUG(Service_FS, "{} not found", full_path); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::DirectoryFound: | ||||
|         LOG_ERROR(Service_FS, "{} is not a file", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC; | ||||
|         return ResultUnexpectedFileOrDirectorySdmc; | ||||
|     case PathParser::FileFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
| 
 | ||||
|     if (FileUtil::Delete(full_path)) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     LOG_CRITICAL(Service_FS, "(unreachable) Unknown error deleting {}", full_path); | ||||
|     return ERROR_NOT_FOUND; | ||||
|     return ResultNotFound; | ||||
| } | ||||
| 
 | ||||
| ResultCode SDMCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | ||||
| Result SDMCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | ||||
|     const PathParser path_parser_src(src_path); | ||||
| 
 | ||||
|     // TODO: Verify these return codes with HW
 | ||||
|     if (!path_parser_src.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const PathParser path_parser_dest(dest_path); | ||||
| 
 | ||||
|     if (!path_parser_dest.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto src_path_full = path_parser_src.BuildHostPath(mount_point); | ||||
|     const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point); | ||||
| 
 | ||||
|     if (FileUtil::Rename(src_path_full, dest_path_full)) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
 | ||||
|     // exist or similar. Verify.
 | ||||
|     return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
 | ||||
|                       ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
|     return Result(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
 | ||||
|                   ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
| } | ||||
| 
 | ||||
| template <typename T> | ||||
| static ResultCode DeleteDirectoryHelper(const Path& path, const std::string& mount_point, | ||||
|                                         T deleter) { | ||||
| static Result DeleteDirectoryHelper(const Path& path, const std::string& mount_point, T deleter) { | ||||
|     const PathParser path_parser(path); | ||||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     if (path_parser.IsRootDirectory()) | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
| 
 | ||||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|     case PathParser::NotFound: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::FileInPath: | ||||
|     case PathParser::FileFound: | ||||
|         LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC; | ||||
|         return ResultUnexpectedFileOrDirectorySdmc; | ||||
|     case PathParser::DirectoryFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
| 
 | ||||
|     if (deleter(full_path)) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     LOG_ERROR(Service_FS, "Directory not empty {}", full_path); | ||||
|     return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC; | ||||
|     return ResultUnexpectedFileOrDirectorySdmc; | ||||
| } | ||||
| 
 | ||||
| ResultCode SDMCArchive::DeleteDirectory(const Path& path) const { | ||||
| Result SDMCArchive::DeleteDirectory(const Path& path) const { | ||||
|     return DeleteDirectoryHelper(path, mount_point, FileUtil::DeleteDir); | ||||
| } | ||||
| 
 | ||||
| ResultCode SDMCArchive::DeleteDirectoryRecursively(const Path& path) const { | ||||
| Result SDMCArchive::DeleteDirectoryRecursively(const Path& path) const { | ||||
|     return DeleteDirectoryHelper( | ||||
|         path, mount_point, [](const std::string& p) { return FileUtil::DeleteDirRecursively(p); }); | ||||
| } | ||||
| 
 | ||||
| ResultCode SDMCArchive::CreateFile(const FileSys::Path& path, u64 size) const { | ||||
| Result SDMCArchive::CreateFile(const FileSys::Path& path, u64 size) const { | ||||
|     const PathParser path_parser(path); | ||||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -236,44 +235,44 @@ ResultCode SDMCArchive::CreateFile(const FileSys::Path& path, u64 size) const { | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|     case PathParser::FileInPath: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::DirectoryFound: | ||||
|         LOG_ERROR(Service_FS, "{} already exists", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC; | ||||
|         return ResultUnexpectedFileOrDirectorySdmc; | ||||
|     case PathParser::FileFound: | ||||
|         LOG_ERROR(Service_FS, "{} already exists", full_path); | ||||
|         return ERROR_ALREADY_EXISTS; | ||||
|         return ResultAlreadyExists; | ||||
|     case PathParser::NotFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
| 
 | ||||
|     if (size == 0) { | ||||
|         FileUtil::CreateEmptyFile(full_path); | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     FileUtil::IOFile file(full_path, "wb"); | ||||
|     // Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
 | ||||
|     // We do this by seeking to the right size, then writing a single null byte.
 | ||||
|     if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     LOG_ERROR(Service_FS, "Too large file"); | ||||
|     return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, | ||||
|                       ErrorLevel::Info); | ||||
|     return Result(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, | ||||
|                   ErrorLevel::Info); | ||||
| } | ||||
| 
 | ||||
| ResultCode SDMCArchive::CreateDirectory(const Path& path) const { | ||||
| Result SDMCArchive::CreateDirectory(const Path& path) const { | ||||
|     const PathParser path_parser(path); | ||||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -281,55 +280,55 @@ ResultCode SDMCArchive::CreateDirectory(const Path& path) const { | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|     case PathParser::FileInPath: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::DirectoryFound: | ||||
|     case PathParser::FileFound: | ||||
|         LOG_DEBUG(Service_FS, "{} already exists", full_path); | ||||
|         return ERROR_ALREADY_EXISTS; | ||||
|         return ResultAlreadyExists; | ||||
|     case PathParser::NotFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
| 
 | ||||
|     if (FileUtil::CreateDir(mount_point + path.AsString())) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating {}", mount_point); | ||||
|     return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, | ||||
|                       ErrorLevel::Status); | ||||
|     return Result(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, | ||||
|                   ErrorLevel::Status); | ||||
| } | ||||
| 
 | ||||
| ResultCode SDMCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | ||||
| Result SDMCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | ||||
|     const PathParser path_parser_src(src_path); | ||||
| 
 | ||||
|     // TODO: Verify these return codes with HW
 | ||||
|     if (!path_parser_src.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const PathParser path_parser_dest(dest_path); | ||||
| 
 | ||||
|     if (!path_parser_dest.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto src_path_full = path_parser_src.BuildHostPath(mount_point); | ||||
|     const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point); | ||||
| 
 | ||||
|     if (FileUtil::Rename(src_path_full, dest_path_full)) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
 | ||||
|     // exist or similar. Verify.
 | ||||
|     return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
 | ||||
|                       ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
|     return Result(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
 | ||||
|                   ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
| } | ||||
| 
 | ||||
| ResultVal<std::unique_ptr<DirectoryBackend>> SDMCArchive::OpenDirectory(const Path& path) const { | ||||
|  | @ -337,7 +336,7 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SDMCArchive::OpenDirectory(const Pa | |||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -345,15 +344,15 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SDMCArchive::OpenDirectory(const Pa | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|     case PathParser::NotFound: | ||||
|     case PathParser::FileFound: | ||||
|         LOG_ERROR(Service_FS, "{} not found", full_path); | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     case PathParser::FileInPath: | ||||
|         LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC; | ||||
|         return ResultUnexpectedFileOrDirectorySdmc; | ||||
|     case PathParser::DirectoryFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
|  | @ -392,18 +391,17 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMC::Open(const Path& | |||
|     return std::make_unique<SDMCArchive>(sdmc_directory, std::move(delay_generator)); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveFactory_SDMC::Format(const Path& path, | ||||
|                                        const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                        u64 program_id) { | ||||
| Result ArchiveFactory_SDMC::Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                    u64 program_id) { | ||||
|     // This is kind of an undesirable operation, so let's just ignore it. :)
 | ||||
|     return RESULT_SUCCESS; | ||||
|     return ResultSuccess; | ||||
| } | ||||
| 
 | ||||
| ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMC::GetFormatInfo(const Path& path, | ||||
|                                                                 u64 program_id) const { | ||||
|     // TODO(Subv): Implement
 | ||||
|     LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName()); | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| } // namespace FileSys
 | ||||
| 
 | ||||
|  |  | |||
|  | @ -29,13 +29,13 @@ public: | |||
| 
 | ||||
|     ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, | ||||
|                                                      const Mode& mode) const override; | ||||
|     ResultCode DeleteFile(const Path& path) const override; | ||||
|     ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; | ||||
|     ResultCode DeleteDirectory(const Path& path) const override; | ||||
|     ResultCode DeleteDirectoryRecursively(const Path& path) const override; | ||||
|     ResultCode CreateFile(const Path& path, u64 size) const override; | ||||
|     ResultCode CreateDirectory(const Path& path) const override; | ||||
|     ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; | ||||
|     Result DeleteFile(const Path& path) const override; | ||||
|     Result RenameFile(const Path& src_path, const Path& dest_path) const override; | ||||
|     Result DeleteDirectory(const Path& path) const override; | ||||
|     Result DeleteDirectoryRecursively(const Path& path) const override; | ||||
|     Result CreateFile(const Path& path, u64 size) const override; | ||||
|     Result CreateDirectory(const Path& path) const override; | ||||
|     Result RenameDirectory(const Path& src_path, const Path& dest_path) const override; | ||||
|     ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override; | ||||
|     u64 GetFreeBytes() const override; | ||||
| 
 | ||||
|  | @ -68,8 +68,8 @@ public: | |||
|     } | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; | ||||
|     ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                       u64 program_id) override; | ||||
|     Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                   u64 program_id) override; | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -44,7 +44,7 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCWriteOnlyArchive::OpenFile(const Pat | |||
|                                                                        const Mode& mode) const { | ||||
|     if (mode.read_flag) { | ||||
|         LOG_ERROR(Service_FS, "Read flag is not supported"); | ||||
|         return ERROR_INVALID_READ_FLAG; | ||||
|         return ResultInvalidReadFlag; | ||||
|     } | ||||
|     return SDMCArchive::OpenFileBase(path, mode); | ||||
| } | ||||
|  | @ -52,7 +52,7 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCWriteOnlyArchive::OpenFile(const Pat | |||
| ResultVal<std::unique_ptr<DirectoryBackend>> SDMCWriteOnlyArchive::OpenDirectory( | ||||
|     const Path& path) const { | ||||
|     LOG_ERROR(Service_FS, "Not supported"); | ||||
|     return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|     return ResultUnsupportedOpenFlags; | ||||
| } | ||||
| 
 | ||||
| ArchiveFactory_SDMCWriteOnly::ArchiveFactory_SDMCWriteOnly(const std::string& mount_point) | ||||
|  | @ -81,19 +81,19 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMCWriteOnly::Open(co | |||
|     return std::make_unique<SDMCWriteOnlyArchive>(sdmc_directory, std::move(delay_generator)); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveFactory_SDMCWriteOnly::Format(const Path& path, | ||||
|                                                 const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                                 u64 program_id) { | ||||
| Result ArchiveFactory_SDMCWriteOnly::Format(const Path& path, | ||||
|                                             const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                             u64 program_id) { | ||||
|     // TODO(wwylele): hwtest this
 | ||||
|     LOG_ERROR(Service_FS, "Attempted to format a SDMC write-only archive."); | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMCWriteOnly::GetFormatInfo(const Path& path, | ||||
|                                                                          u64 program_id) const { | ||||
|     // TODO(Subv): Implement
 | ||||
|     LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName()); | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| } // namespace FileSys
 | ||||
|  |  | |||
|  | @ -54,8 +54,8 @@ public: | |||
|     } | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; | ||||
|     ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                       u64 program_id) override; | ||||
|     Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                   u64 program_id) override; | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -39,12 +39,12 @@ public: | |||
|     ResultVal<std::size_t> Read(u64 offset, std::size_t length, u8* buffer) const override { | ||||
|         if (offset != 0) { | ||||
|             LOG_ERROR(Service_FS, "offset must be zero!"); | ||||
|             return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|             return ResultUnsupportedOpenFlags; | ||||
|         } | ||||
| 
 | ||||
|         if (length != data->size()) { | ||||
|             LOG_ERROR(Service_FS, "size must match the file size!"); | ||||
|             return ERROR_INCORRECT_EXEFS_READ_SIZE; | ||||
|             return ResultIncorrectExefsReadSize; | ||||
|         } | ||||
| 
 | ||||
|         std::memcpy(buffer, data->data(), data->size()); | ||||
|  | @ -54,7 +54,7 @@ public: | |||
|     ResultVal<std::size_t> Write(u64 offset, std::size_t length, bool flush, | ||||
|                                  const u8* buffer) override { | ||||
|         LOG_ERROR(Service_FS, "The file is read-only!"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     u64 GetSize() const override { | ||||
|  | @ -99,13 +99,13 @@ public: | |||
| 
 | ||||
|         if (path.GetType() != LowPathType::Binary) { | ||||
|             LOG_ERROR(Service_FS, "Path need to be Binary"); | ||||
|             return ERROR_INVALID_PATH; | ||||
|             return ResultInvalidPath; | ||||
|         } | ||||
| 
 | ||||
|         std::vector<u8> binary = path.AsBinary(); | ||||
|         if (binary.size() != sizeof(SelfNCCHFilePath)) { | ||||
|             LOG_ERROR(Service_FS, "Wrong path size {}", binary.size()); | ||||
|             return ERROR_INVALID_PATH; | ||||
|             return ResultInvalidPath; | ||||
|         } | ||||
| 
 | ||||
|         SelfNCCHFilePath file_path; | ||||
|  | @ -120,7 +120,7 @@ public: | |||
| 
 | ||||
|         case SelfNCCHFilePathType::Code: | ||||
|             LOG_ERROR(Service_FS, "Reading the code section is not supported!"); | ||||
|             return ERROR_COMMAND_NOT_ALLOWED; | ||||
|             return ResultCommandNotAllowed; | ||||
| 
 | ||||
|         case SelfNCCHFilePathType::ExeFS: { | ||||
|             const auto& raw = file_path.exefs_filename; | ||||
|  | @ -130,48 +130,48 @@ public: | |||
|         } | ||||
|         default: | ||||
|             LOG_ERROR(Service_FS, "Unknown file type {}!", file_path.type); | ||||
|             return ERROR_INVALID_PATH; | ||||
|             return ResultInvalidPath; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     ResultCode DeleteFile(const Path& path) const override { | ||||
|     Result DeleteFile(const Path& path) const override { | ||||
|         LOG_ERROR(Service_FS, "Unsupported"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override { | ||||
|     Result RenameFile(const Path& src_path, const Path& dest_path) const override { | ||||
|         LOG_ERROR(Service_FS, "Unsupported"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     ResultCode DeleteDirectory(const Path& path) const override { | ||||
|     Result DeleteDirectory(const Path& path) const override { | ||||
|         LOG_ERROR(Service_FS, "Unsupported"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     ResultCode DeleteDirectoryRecursively(const Path& path) const override { | ||||
|     Result DeleteDirectoryRecursively(const Path& path) const override { | ||||
|         LOG_ERROR(Service_FS, "Unsupported"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     ResultCode CreateFile(const Path& path, u64 size) const override { | ||||
|     Result CreateFile(const Path& path, u64 size) const override { | ||||
|         LOG_ERROR(Service_FS, "Unsupported"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     ResultCode CreateDirectory(const Path& path) const override { | ||||
|     Result CreateDirectory(const Path& path) const override { | ||||
|         LOG_ERROR(Service_FS, "Unsupported"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override { | ||||
|     Result RenameDirectory(const Path& src_path, const Path& dest_path) const override { | ||||
|         LOG_ERROR(Service_FS, "Unsupported"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override { | ||||
|         LOG_ERROR(Service_FS, "Unsupported"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     u64 GetFreeBytes() const override { | ||||
|  | @ -186,7 +186,7 @@ private: | |||
|             return std::make_unique<IVFCFile>(ncch_data.romfs_file, std::move(delay_generator)); | ||||
|         } else { | ||||
|             LOG_INFO(Service_FS, "Unable to read RomFS"); | ||||
|             return ERROR_ROMFS_NOT_FOUND; | ||||
|             return ResultRomfsNotFound; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -198,7 +198,7 @@ private: | |||
|                                               std::move(delay_generator)); | ||||
|         } else { | ||||
|             LOG_INFO(Service_FS, "Unable to read update RomFS"); | ||||
|             return ERROR_ROMFS_NOT_FOUND; | ||||
|             return ResultRomfsNotFound; | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|  | @ -209,7 +209,7 @@ private: | |||
|             } | ||||
| 
 | ||||
|             LOG_WARNING(Service_FS, "Unable to read icon"); | ||||
|             return ERROR_EXEFS_SECTION_NOT_FOUND; | ||||
|             return ResultExefsSectionNotFound; | ||||
|         } | ||||
| 
 | ||||
|         if (filename == "logo") { | ||||
|  | @ -218,7 +218,7 @@ private: | |||
|             } | ||||
| 
 | ||||
|             LOG_WARNING(Service_FS, "Unable to read logo"); | ||||
|             return ERROR_EXEFS_SECTION_NOT_FOUND; | ||||
|             return ResultExefsSectionNotFound; | ||||
|         } | ||||
| 
 | ||||
|         if (filename == "banner") { | ||||
|  | @ -227,11 +227,11 @@ private: | |||
|             } | ||||
| 
 | ||||
|             LOG_WARNING(Service_FS, "Unable to read banner"); | ||||
|             return ERROR_EXEFS_SECTION_NOT_FOUND; | ||||
|             return ResultExefsSectionNotFound; | ||||
|         } | ||||
| 
 | ||||
|         LOG_ERROR(Service_FS, "Unknown ExeFS section {}!", filename); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     NCCHData ncch_data; | ||||
|  | @ -296,16 +296,16 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SelfNCCH::Open(const P | |||
|     return std::make_unique<SelfNCCHArchive>(ncch_data[program_id]); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveFactory_SelfNCCH::Format(const Path&, const FileSys::ArchiveFormatInfo&, | ||||
|                                            u64 program_id) { | ||||
| Result ArchiveFactory_SelfNCCH::Format(const Path&, const FileSys::ArchiveFormatInfo&, | ||||
|                                        u64 program_id) { | ||||
|     LOG_ERROR(Service_FS, "Attempted to format a SelfNCCH archive."); | ||||
|     return ERROR_INVALID_PATH; | ||||
|     return ResultInvalidPath; | ||||
| } | ||||
| 
 | ||||
| ResultVal<ArchiveFormatInfo> ArchiveFactory_SelfNCCH::GetFormatInfo(const Path&, | ||||
|                                                                     u64 program_id) const { | ||||
|     LOG_ERROR(Service_FS, "Attempted to get format info of a SelfNCCH archive"); | ||||
|     return ERROR_INVALID_PATH; | ||||
|     return ResultInvalidPath; | ||||
| } | ||||
| 
 | ||||
| } // namespace FileSys
 | ||||
|  |  | |||
|  | @ -50,8 +50,8 @@ public: | |||
|         return "SelfNCCH"; | ||||
|     } | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; | ||||
|     ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                       u64 program_id) override; | ||||
|     Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                   u64 program_id) override; | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; | ||||
| 
 | ||||
| private: | ||||
|  |  | |||
|  | @ -47,14 +47,14 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveSource_SDSaveData::Open(u64 pr | |||
|         // 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 with the files and folders that it expects.
 | ||||
|         return ERR_NOT_FORMATTED; | ||||
|         return ResultNotFormatted; | ||||
|     } | ||||
| 
 | ||||
|     return std::make_unique<SaveDataArchive>(std::move(concrete_mount_point)); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveSource_SDSaveData::Format(u64 program_id, | ||||
|                                             const FileSys::ArchiveFormatInfo& format_info) { | ||||
| Result ArchiveSource_SDSaveData::Format(u64 program_id, | ||||
|                                         const FileSys::ArchiveFormatInfo& format_info) { | ||||
|     std::string concrete_mount_point = GetSaveDataPath(mount_point, program_id); | ||||
|     FileUtil::DeleteDirRecursively(concrete_mount_point); | ||||
|     FileUtil::CreateFullPath(concrete_mount_point); | ||||
|  | @ -65,9 +65,9 @@ ResultCode ArchiveSource_SDSaveData::Format(u64 program_id, | |||
| 
 | ||||
|     if (file.IsOpen()) { | ||||
|         file.WriteBytes(&format_info, sizeof(format_info)); | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
|     return RESULT_SUCCESS; | ||||
|     return ResultSuccess; | ||||
| } | ||||
| 
 | ||||
| ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program_id) const { | ||||
|  | @ -77,7 +77,7 @@ ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program | |||
|     if (!file.IsOpen()) { | ||||
|         LOG_ERROR(Service_FS, "Could not open metadata information for archive"); | ||||
|         // TODO(Subv): Verify error code
 | ||||
|         return ERR_NOT_FORMATTED; | ||||
|         return ResultNotFormatted; | ||||
|     } | ||||
| 
 | ||||
|     ArchiveFormatInfo info = {}; | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ public: | |||
|     explicit ArchiveSource_SDSaveData(const std::string& mount_point); | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(u64 program_id); | ||||
|     ResultCode Format(u64 program_id, const FileSys::ArchiveFormatInfo& format_info); | ||||
|     Result Format(u64 program_id, const FileSys::ArchiveFormatInfo& format_info); | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(u64 program_id) const; | ||||
| 
 | ||||
|     static std::string GetSaveDataPathFor(const std::string& mount_point, u64 program_id); | ||||
|  |  | |||
|  | @ -57,25 +57,25 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c | |||
|     std::string fullpath = GetSystemSaveDataPath(base_path, path); | ||||
|     if (!FileUtil::Exists(fullpath)) { | ||||
|         // TODO(Subv): Check error code, this one is probably wrong
 | ||||
|         return ERROR_NOT_FOUND; | ||||
|         return ResultNotFound; | ||||
|     } | ||||
|     return std::make_unique<SaveDataArchive>(fullpath); | ||||
| } | ||||
| 
 | ||||
| ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path, | ||||
|                                                  const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                                  u64 program_id) { | ||||
| Result ArchiveFactory_SystemSaveData::Format(const Path& path, | ||||
|                                              const FileSys::ArchiveFormatInfo& format_info, | ||||
|                                              u64 program_id) { | ||||
|     std::string fullpath = GetSystemSaveDataPath(base_path, path); | ||||
|     FileUtil::DeleteDirRecursively(fullpath); | ||||
|     FileUtil::CreateFullPath(fullpath); | ||||
|     return RESULT_SUCCESS; | ||||
|     return ResultSuccess; | ||||
| } | ||||
| 
 | ||||
| ResultVal<ArchiveFormatInfo> ArchiveFactory_SystemSaveData::GetFormatInfo(const Path& path, | ||||
|                                                                           u64 program_id) const { | ||||
|     // TODO(Subv): Implement
 | ||||
|     LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName()); | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| } // namespace FileSys
 | ||||
|  |  | |||
|  | @ -20,8 +20,8 @@ public: | |||
|     explicit ArchiveFactory_SystemSaveData(const std::string& mount_point); | ||||
| 
 | ||||
|     ResultVal<std::unique_ptr<ArchiveBackend>> Open(const Path& path, u64 program_id) override; | ||||
|     ResultCode Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                       u64 program_id) override; | ||||
|     Result Format(const Path& path, const FileSys::ArchiveFormatInfo& format_info, | ||||
|                   u64 program_id) override; | ||||
|     ResultVal<ArchiveFormatInfo> GetFormatInfo(const Path& path, u64 program_id) const override; | ||||
| 
 | ||||
|     std::string GetName() const override { | ||||
|  |  | |||
|  | @ -19,7 +19,7 @@ namespace FileSys { | |||
| ResultVal<std::size_t> DiskFile::Read(const u64 offset, const std::size_t length, | ||||
|                                       u8* buffer) const { | ||||
|     if (!mode.read_flag) | ||||
|         return ERROR_INVALID_OPEN_FLAGS; | ||||
|         return ResultInvalidOpenFlags; | ||||
| 
 | ||||
|     file->Seek(offset, SEEK_SET); | ||||
|     return file->ReadBytes(buffer, length); | ||||
|  | @ -28,7 +28,7 @@ ResultVal<std::size_t> DiskFile::Read(const u64 offset, const std::size_t length | |||
| ResultVal<std::size_t> DiskFile::Write(const u64 offset, const std::size_t length, const bool flush, | ||||
|                                        const u8* buffer) { | ||||
|     if (!mode.write_flag) | ||||
|         return ERROR_INVALID_OPEN_FLAGS; | ||||
|         return ResultInvalidOpenFlags; | ||||
| 
 | ||||
|     file->Seek(offset, SEEK_SET); | ||||
|     std::size_t written = file->WriteBytes(buffer, length); | ||||
|  |  | |||
|  | @ -35,63 +35,60 @@ enum { | |||
| }; | ||||
| } | ||||
| 
 | ||||
| constexpr ResultCode ERROR_INVALID_PATH(ErrCodes::InvalidPath, ErrorModule::FS, | ||||
|                                         ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||||
| constexpr ResultCode ERROR_UNSUPPORTED_OPEN_FLAGS(ErrCodes::UnsupportedOpenFlags, ErrorModule::FS, | ||||
|                                                   ErrorSummary::NotSupported, ErrorLevel::Usage); | ||||
| constexpr ResultCode ERROR_INVALID_OPEN_FLAGS(ErrCodes::InvalidOpenFlags, ErrorModule::FS, | ||||
|                                               ErrorSummary::Canceled, ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_INVALID_READ_FLAG(ErrCodes::InvalidReadFlag, ErrorModule::FS, | ||||
|                                              ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||||
| constexpr ResultCode ERROR_FILE_NOT_FOUND(ErrCodes::FileNotFound, ErrorModule::FS, | ||||
|                                           ErrorSummary::NotFound, ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_PATH_NOT_FOUND(ErrCodes::PathNotFound, ErrorModule::FS, | ||||
|                                           ErrorSummary::NotFound, ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_NOT_FOUND(ErrCodes::NotFound, ErrorModule::FS, ErrorSummary::NotFound, | ||||
|                                      ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY(ErrCodes::UnexpectedFileOrDirectory, | ||||
|                                                         ErrorModule::FS, ErrorSummary::NotSupported, | ||||
|                                                         ErrorLevel::Usage); | ||||
| constexpr ResultCode ERROR_UNEXPECTED_FILE_OR_DIRECTORY_SDMC(ErrCodes::NotAFile, ErrorModule::FS, | ||||
|                                                              ErrorSummary::Canceled, | ||||
|                                                              ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_DIRECTORY_ALREADY_EXISTS(ErrCodes::DirectoryAlreadyExists, | ||||
|                                                     ErrorModule::FS, ErrorSummary::NothingHappened, | ||||
|                                                     ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_FILE_ALREADY_EXISTS(ErrCodes::FileAlreadyExists, ErrorModule::FS, | ||||
|                                                ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_ALREADY_EXISTS(ErrCodes::AlreadyExists, ErrorModule::FS, | ||||
|                                           ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_DIRECTORY_NOT_EMPTY(ErrCodes::DirectoryNotEmpty, ErrorModule::FS, | ||||
|                                                ErrorSummary::Canceled, ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_GAMECARD_NOT_INSERTED(ErrCodes::GameCardNotInserted, ErrorModule::FS, | ||||
|                                                  ErrorSummary::NotFound, ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_INCORRECT_EXEFS_READ_SIZE(ErrCodes::IncorrectExeFSReadSize, | ||||
|                                                      ErrorModule::FS, ErrorSummary::NotSupported, | ||||
|                                                      ErrorLevel::Usage); | ||||
| constexpr ResultCode ERROR_ROMFS_NOT_FOUND(ErrCodes::RomFSNotFound, ErrorModule::FS, | ||||
| constexpr Result ResultInvalidPath(ErrCodes::InvalidPath, ErrorModule::FS, | ||||
|                                    ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||||
| constexpr Result ResultUnsupportedOpenFlags(ErrCodes::UnsupportedOpenFlags, ErrorModule::FS, | ||||
|                                             ErrorSummary::NotSupported, ErrorLevel::Usage); | ||||
| constexpr Result ResultInvalidOpenFlags(ErrCodes::InvalidOpenFlags, ErrorModule::FS, | ||||
|                                         ErrorSummary::Canceled, ErrorLevel::Status); | ||||
| constexpr Result ResultInvalidReadFlag(ErrCodes::InvalidReadFlag, ErrorModule::FS, | ||||
|                                        ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||||
| constexpr Result ResultFileNotFound(ErrCodes::FileNotFound, ErrorModule::FS, ErrorSummary::NotFound, | ||||
|                                     ErrorLevel::Status); | ||||
| constexpr Result ResultPathNotFound(ErrCodes::PathNotFound, ErrorModule::FS, ErrorSummary::NotFound, | ||||
|                                     ErrorLevel::Status); | ||||
| constexpr Result ResultNotFound(ErrCodes::NotFound, ErrorModule::FS, ErrorSummary::NotFound, | ||||
|                                 ErrorLevel::Status); | ||||
| constexpr Result ResultUnexpectedFileOrDirectory(ErrCodes::UnexpectedFileOrDirectory, | ||||
|                                                  ErrorModule::FS, ErrorSummary::NotSupported, | ||||
|                                                  ErrorLevel::Usage); | ||||
| constexpr Result ResultUnexpectedFileOrDirectorySdmc(ErrCodes::NotAFile, ErrorModule::FS, | ||||
|                                                      ErrorSummary::Canceled, ErrorLevel::Status); | ||||
| constexpr Result ResultDirectoryAlreadyExists(ErrCodes::DirectoryAlreadyExists, ErrorModule::FS, | ||||
|                                               ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
| constexpr Result ResultFileAlreadyExists(ErrCodes::FileAlreadyExists, ErrorModule::FS, | ||||
|                                          ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
| constexpr Result ResultAlreadyExists(ErrCodes::AlreadyExists, ErrorModule::FS, | ||||
|                                      ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
| constexpr Result ResultDirectoryNotEmpty(ErrCodes::DirectoryNotEmpty, ErrorModule::FS, | ||||
|                                          ErrorSummary::Canceled, ErrorLevel::Status); | ||||
| constexpr Result ResultGamecardNotInserted(ErrCodes::GameCardNotInserted, ErrorModule::FS, | ||||
|                                            ErrorSummary::NotFound, ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_COMMAND_NOT_ALLOWED(ErrCodes::CommandNotAllowed, ErrorModule::FS, | ||||
|                                                ErrorSummary::WrongArgument, ErrorLevel::Permanent); | ||||
| constexpr ResultCode ERROR_EXEFS_SECTION_NOT_FOUND(ErrCodes::ExeFSSectionNotFound, ErrorModule::FS, | ||||
|                                                    ErrorSummary::NotFound, ErrorLevel::Status); | ||||
| constexpr ResultCode ERROR_INSUFFICIENT_SPACE(ErrCodes::InsufficientSpace, ErrorModule::FS, | ||||
|                                               ErrorSummary::OutOfResource, ErrorLevel::Status); | ||||
| constexpr Result ResultIncorrectExefsReadSize(ErrCodes::IncorrectExeFSReadSize, ErrorModule::FS, | ||||
|                                               ErrorSummary::NotSupported, ErrorLevel::Usage); | ||||
| constexpr Result ResultRomfsNotFound(ErrCodes::RomFSNotFound, ErrorModule::FS, | ||||
|                                      ErrorSummary::NotFound, ErrorLevel::Status); | ||||
| constexpr Result ResultCommandNotAllowed(ErrCodes::CommandNotAllowed, ErrorModule::FS, | ||||
|                                          ErrorSummary::WrongArgument, ErrorLevel::Permanent); | ||||
| constexpr Result ResultExefsSectionNotFound(ErrCodes::ExeFSSectionNotFound, ErrorModule::FS, | ||||
|                                             ErrorSummary::NotFound, ErrorLevel::Status); | ||||
| constexpr Result ResultInsufficientSpace(ErrCodes::InsufficientSpace, ErrorModule::FS, | ||||
|                                          ErrorSummary::OutOfResource, ErrorLevel::Status); | ||||
| 
 | ||||
| /// Returned when a function is passed an invalid archive handle.
 | ||||
| constexpr ResultCode ERR_INVALID_ARCHIVE_HANDLE(ErrCodes::ArchiveNotMounted, ErrorModule::FS, | ||||
|                                                 ErrorSummary::NotFound, | ||||
|                                                 ErrorLevel::Status); // 0xC8804465
 | ||||
| constexpr ResultCode ERR_WRITE_BEYOND_END(ErrCodes::WriteBeyondEnd, ErrorModule::FS, | ||||
|                                           ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||||
| constexpr Result ResultInvalidArchiveHandle(ErrCodes::ArchiveNotMounted, ErrorModule::FS, | ||||
|                                             ErrorSummary::NotFound, | ||||
|                                             ErrorLevel::Status); // 0xC8804465
 | ||||
| constexpr Result ResultWriteBeyondEnd(ErrCodes::WriteBeyondEnd, ErrorModule::FS, | ||||
|                                       ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||||
| 
 | ||||
| /**
 | ||||
|  * Variant of ERROR_NOT_FOUND returned in some places in the code. Unknown if these usages are | ||||
|  * Variant of ResultNotFound returned in some places in the code. Unknown if these usages are | ||||
|  * correct or a bug. | ||||
|  */ | ||||
| constexpr ResultCode ERR_NOT_FOUND_INVALID_STATE(ErrCodes::NotFound, ErrorModule::FS, | ||||
|                                                  ErrorSummary::InvalidState, ErrorLevel::Status); | ||||
| constexpr ResultCode ERR_NOT_FORMATTED(ErrCodes::NotFormatted, ErrorModule::FS, | ||||
|                                        ErrorSummary::InvalidState, ErrorLevel::Status); | ||||
| constexpr Result ResultNotFoundInvalidState(ErrCodes::NotFound, ErrorModule::FS, | ||||
|                                             ErrorSummary::InvalidState, ErrorLevel::Status); | ||||
| constexpr Result ResultNotFormatted(ErrCodes::NotFormatted, ErrorModule::FS, | ||||
|                                     ErrorSummary::InvalidState, ErrorLevel::Status); | ||||
| 
 | ||||
| } // namespace FileSys
 | ||||
|  |  | |||
|  | @ -34,50 +34,50 @@ ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path, | |||
|     return std::make_unique<IVFCFile>(romfs_file, std::move(delay_generator)); | ||||
| } | ||||
| 
 | ||||
| ResultCode IVFCArchive::DeleteFile(const Path& path) const { | ||||
| Result IVFCArchive::DeleteFile(const Path& path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to delete a file from an IVFC archive ({}).", GetName()); | ||||
|     // TODO(Subv): Verify error code
 | ||||
|     return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, | ||||
|                       ErrorLevel::Status); | ||||
|     return Result(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, | ||||
|                   ErrorLevel::Status); | ||||
| } | ||||
| 
 | ||||
| ResultCode IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | ||||
| Result IVFCArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive ({}).", GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultCode IVFCArchive::DeleteDirectory(const Path& path) const { | ||||
| Result IVFCArchive::DeleteDirectory(const Path& path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive ({}).", | ||||
|                  GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultCode IVFCArchive::DeleteDirectoryRecursively(const Path& path) const { | ||||
| Result IVFCArchive::DeleteDirectoryRecursively(const Path& path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to delete a directory from an IVFC archive ({}).", | ||||
|                  GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const { | ||||
| Result IVFCArchive::CreateFile(const Path& path, u64 size) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to create a file in an IVFC archive ({}).", GetName()); | ||||
|     // TODO: Verify error code
 | ||||
|     return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, | ||||
|                       ErrorLevel::Permanent); | ||||
|     return Result(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, | ||||
|                   ErrorLevel::Permanent); | ||||
| } | ||||
| 
 | ||||
| ResultCode IVFCArchive::CreateDirectory(const Path& path) const { | ||||
| Result IVFCArchive::CreateDirectory(const Path& path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to create a directory in an IVFC archive ({}).", GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultCode IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | ||||
| Result IVFCArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | ||||
|     LOG_CRITICAL(Service_FS, "Attempted to rename a file within an IVFC archive ({}).", GetName()); | ||||
|     // TODO(wwylele): Use correct error code
 | ||||
|     return RESULT_UNKNOWN; | ||||
|     return ResultUnknown; | ||||
| } | ||||
| 
 | ||||
| ResultVal<std::unique_ptr<DirectoryBackend>> IVFCArchive::OpenDirectory(const Path& path) const { | ||||
|  |  | |||
|  | @ -103,13 +103,13 @@ public: | |||
| 
 | ||||
|     ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, | ||||
|                                                      const Mode& mode) const override; | ||||
|     ResultCode DeleteFile(const Path& path) const override; | ||||
|     ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; | ||||
|     ResultCode DeleteDirectory(const Path& path) const override; | ||||
|     ResultCode DeleteDirectoryRecursively(const Path& path) const override; | ||||
|     ResultCode CreateFile(const Path& path, u64 size) const override; | ||||
|     ResultCode CreateDirectory(const Path& path) const override; | ||||
|     ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; | ||||
|     Result DeleteFile(const Path& path) const override; | ||||
|     Result RenameFile(const Path& src_path, const Path& dest_path) const override; | ||||
|     Result DeleteDirectory(const Path& path) const override; | ||||
|     Result DeleteDirectoryRecursively(const Path& path) const override; | ||||
|     Result CreateFile(const Path& path, u64 size) const override; | ||||
|     Result CreateDirectory(const Path& path) const override; | ||||
|     Result RenameDirectory(const Path& src_path, const Path& dest_path) const override; | ||||
|     ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override; | ||||
|     u64 GetFreeBytes() const override; | ||||
| 
 | ||||
|  |  | |||
|  | @ -43,17 +43,17 @@ ResultVal<std::unique_ptr<FileBackend>> SaveDataArchive::OpenFile(const Path& pa | |||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     if (mode.hex == 0) { | ||||
|         LOG_ERROR(Service_FS, "Empty open mode"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     if (mode.create_flag && !mode.write_flag) { | ||||
|         LOG_ERROR(Service_FS, "Create flag set but write flag not set"); | ||||
|         return ERROR_UNSUPPORTED_OPEN_FLAGS; | ||||
|         return ResultUnsupportedOpenFlags; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -61,19 +61,19 @@ ResultVal<std::unique_ptr<FileBackend>> SaveDataArchive::OpenFile(const Path& pa | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_FILE_NOT_FOUND; | ||||
|         return ResultFileNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_PATH_NOT_FOUND; | ||||
|         return ResultPathNotFound; | ||||
|     case PathParser::FileInPath: | ||||
|     case PathParser::DirectoryFound: | ||||
|         LOG_ERROR(Service_FS, "Unexpected file or directory in {}", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY; | ||||
|         return ResultUnexpectedFileOrDirectory; | ||||
|     case PathParser::NotFound: | ||||
|         if (!mode.create_flag) { | ||||
|             LOG_ERROR(Service_FS, "Non-existing file {} can't be open without mode create.", | ||||
|                       full_path); | ||||
|             return ERROR_FILE_NOT_FOUND; | ||||
|             return ResultFileNotFound; | ||||
|         } else { | ||||
|             // Create the file
 | ||||
|             FileUtil::CreateEmptyFile(full_path); | ||||
|  | @ -86,19 +86,19 @@ ResultVal<std::unique_ptr<FileBackend>> SaveDataArchive::OpenFile(const Path& pa | |||
|     FileUtil::IOFile file(full_path, mode.write_flag ? "r+b" : "rb"); | ||||
|     if (!file.IsOpen()) { | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Unknown error opening {}", full_path); | ||||
|         return ERROR_FILE_NOT_FOUND; | ||||
|         return ResultFileNotFound; | ||||
|     } | ||||
| 
 | ||||
|     std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<SaveDataDelayGenerator>(); | ||||
|     return std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator)); | ||||
| } | ||||
| 
 | ||||
| ResultCode SaveDataArchive::DeleteFile(const Path& path) const { | ||||
| Result SaveDataArchive::DeleteFile(const Path& path) const { | ||||
|     const PathParser path_parser(path); | ||||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -106,110 +106,109 @@ ResultCode SaveDataArchive::DeleteFile(const Path& path) const { | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_FILE_NOT_FOUND; | ||||
|         return ResultFileNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_PATH_NOT_FOUND; | ||||
|         return ResultPathNotFound; | ||||
|     case PathParser::FileInPath: | ||||
|     case PathParser::DirectoryFound: | ||||
|     case PathParser::NotFound: | ||||
|         LOG_ERROR(Service_FS, "File not found {}", full_path); | ||||
|         return ERROR_FILE_NOT_FOUND; | ||||
|         return ResultFileNotFound; | ||||
|     case PathParser::FileFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
| 
 | ||||
|     if (FileUtil::Delete(full_path)) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     LOG_CRITICAL(Service_FS, "(unreachable) Unknown error deleting {}", full_path); | ||||
|     return ERROR_FILE_NOT_FOUND; | ||||
|     return ResultFileNotFound; | ||||
| } | ||||
| 
 | ||||
| ResultCode SaveDataArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | ||||
| Result SaveDataArchive::RenameFile(const Path& src_path, const Path& dest_path) const { | ||||
|     const PathParser path_parser_src(src_path); | ||||
| 
 | ||||
|     // TODO: Verify these return codes with HW
 | ||||
|     if (!path_parser_src.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const PathParser path_parser_dest(dest_path); | ||||
| 
 | ||||
|     if (!path_parser_dest.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto src_path_full = path_parser_src.BuildHostPath(mount_point); | ||||
|     const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point); | ||||
| 
 | ||||
|     if (FileUtil::Rename(src_path_full, dest_path_full)) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
 | ||||
|     // exist or similar. Verify.
 | ||||
|     return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
 | ||||
|                       ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
|     return Result(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
 | ||||
|                   ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
| } | ||||
| 
 | ||||
| template <typename T> | ||||
| static ResultCode DeleteDirectoryHelper(const Path& path, const std::string& mount_point, | ||||
|                                         T deleter) { | ||||
| static Result DeleteDirectoryHelper(const Path& path, const std::string& mount_point, T deleter) { | ||||
|     const PathParser path_parser(path); | ||||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     if (path_parser.IsRootDirectory()) | ||||
|         return ERROR_DIRECTORY_NOT_EMPTY; | ||||
|         return ResultDirectoryNotEmpty; | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
| 
 | ||||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_PATH_NOT_FOUND; | ||||
|         return ResultPathNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|     case PathParser::NotFound: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_PATH_NOT_FOUND; | ||||
|         return ResultPathNotFound; | ||||
|     case PathParser::FileInPath: | ||||
|     case PathParser::FileFound: | ||||
|         LOG_ERROR(Service_FS, "Unexpected file or directory {}", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY; | ||||
|         return ResultUnexpectedFileOrDirectory; | ||||
|     case PathParser::DirectoryFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
| 
 | ||||
|     if (deleter(full_path)) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     LOG_ERROR(Service_FS, "Directory not empty {}", full_path); | ||||
|     return ERROR_DIRECTORY_NOT_EMPTY; | ||||
|     return ResultDirectoryNotEmpty; | ||||
| } | ||||
| 
 | ||||
| ResultCode SaveDataArchive::DeleteDirectory(const Path& path) const { | ||||
| Result SaveDataArchive::DeleteDirectory(const Path& path) const { | ||||
|     return DeleteDirectoryHelper(path, mount_point, FileUtil::DeleteDir); | ||||
| } | ||||
| 
 | ||||
| ResultCode SaveDataArchive::DeleteDirectoryRecursively(const Path& path) const { | ||||
| Result SaveDataArchive::DeleteDirectoryRecursively(const Path& path) const { | ||||
|     return DeleteDirectoryHelper( | ||||
|         path, mount_point, [](const std::string& p) { return FileUtil::DeleteDirRecursively(p); }); | ||||
| } | ||||
| 
 | ||||
| ResultCode SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) const { | ||||
| Result SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) const { | ||||
|     const PathParser path_parser(path); | ||||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -217,44 +216,44 @@ ResultCode SaveDataArchive::CreateFile(const FileSys::Path& path, u64 size) cons | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_FILE_NOT_FOUND; | ||||
|         return ResultFileNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_PATH_NOT_FOUND; | ||||
|         return ResultPathNotFound; | ||||
|     case PathParser::FileInPath: | ||||
|         LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY; | ||||
|         return ResultUnexpectedFileOrDirectory; | ||||
|     case PathParser::DirectoryFound: | ||||
|     case PathParser::FileFound: | ||||
|         LOG_ERROR(Service_FS, "{} already exists", full_path); | ||||
|         return ERROR_FILE_ALREADY_EXISTS; | ||||
|         return ResultFileAlreadyExists; | ||||
|     case PathParser::NotFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
| 
 | ||||
|     if (size == 0) { | ||||
|         FileUtil::CreateEmptyFile(full_path); | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     FileUtil::IOFile file(full_path, "wb"); | ||||
|     // Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
 | ||||
|     // We do this by seeking to the right size, then writing a single null byte.
 | ||||
|     if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     LOG_ERROR(Service_FS, "Too large file"); | ||||
|     return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, | ||||
|                       ErrorLevel::Info); | ||||
|     return Result(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, | ||||
|                   ErrorLevel::Info); | ||||
| } | ||||
| 
 | ||||
| ResultCode SaveDataArchive::CreateDirectory(const Path& path) const { | ||||
| Result SaveDataArchive::CreateDirectory(const Path& path) const { | ||||
|     const PathParser path_parser(path); | ||||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -262,57 +261,57 @@ ResultCode SaveDataArchive::CreateDirectory(const Path& path) const { | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_FILE_NOT_FOUND; | ||||
|         return ResultFileNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_PATH_NOT_FOUND; | ||||
|         return ResultPathNotFound; | ||||
|     case PathParser::FileInPath: | ||||
|         LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY; | ||||
|         return ResultUnexpectedFileOrDirectory; | ||||
|     case PathParser::DirectoryFound: | ||||
|     case PathParser::FileFound: | ||||
|         LOG_ERROR(Service_FS, "{} already exists", full_path); | ||||
|         return ERROR_DIRECTORY_ALREADY_EXISTS; | ||||
|         return ResultDirectoryAlreadyExists; | ||||
|     case PathParser::NotFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
| 
 | ||||
|     if (FileUtil::CreateDir(mount_point + path.AsString())) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     LOG_CRITICAL(Service_FS, "(unreachable) Unknown error creating {}", mount_point); | ||||
|     return ResultCode(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, | ||||
|                       ErrorLevel::Status); | ||||
|     return Result(ErrorDescription::NoData, ErrorModule::FS, ErrorSummary::Canceled, | ||||
|                   ErrorLevel::Status); | ||||
| } | ||||
| 
 | ||||
| ResultCode SaveDataArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | ||||
| Result SaveDataArchive::RenameDirectory(const Path& src_path, const Path& dest_path) const { | ||||
|     const PathParser path_parser_src(src_path); | ||||
| 
 | ||||
|     // TODO: Verify these return codes with HW
 | ||||
|     if (!path_parser_src.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid src path {}", src_path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const PathParser path_parser_dest(dest_path); | ||||
| 
 | ||||
|     if (!path_parser_dest.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid dest path {}", dest_path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto src_path_full = path_parser_src.BuildHostPath(mount_point); | ||||
|     const auto dest_path_full = path_parser_dest.BuildHostPath(mount_point); | ||||
| 
 | ||||
|     if (FileUtil::Rename(src_path_full, dest_path_full)) { | ||||
|         return RESULT_SUCCESS; | ||||
|         return ResultSuccess; | ||||
|     } | ||||
| 
 | ||||
|     // TODO(yuriks): This code probably isn't right, it'll return a Status even if the file didn't
 | ||||
|     // exist or similar. Verify.
 | ||||
|     return ResultCode(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
 | ||||
|                       ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
|     return Result(ErrorDescription::NoData, ErrorModule::FS, // TODO: verify description
 | ||||
|                   ErrorSummary::NothingHappened, ErrorLevel::Status); | ||||
| } | ||||
| 
 | ||||
| ResultVal<std::unique_ptr<DirectoryBackend>> SaveDataArchive::OpenDirectory( | ||||
|  | @ -321,7 +320,7 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SaveDataArchive::OpenDirectory( | |||
| 
 | ||||
|     if (!path_parser.IsValid()) { | ||||
|         LOG_ERROR(Service_FS, "Invalid path {}", path.DebugStr()); | ||||
|         return ERROR_INVALID_PATH; | ||||
|         return ResultInvalidPath; | ||||
|     } | ||||
| 
 | ||||
|     const auto full_path = path_parser.BuildHostPath(mount_point); | ||||
|  | @ -329,15 +328,15 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SaveDataArchive::OpenDirectory( | |||
|     switch (path_parser.GetHostStatus(mount_point)) { | ||||
|     case PathParser::InvalidMountPoint: | ||||
|         LOG_CRITICAL(Service_FS, "(unreachable) Invalid mount point {}", mount_point); | ||||
|         return ERROR_FILE_NOT_FOUND; | ||||
|         return ResultFileNotFound; | ||||
|     case PathParser::PathNotFound: | ||||
|     case PathParser::NotFound: | ||||
|         LOG_ERROR(Service_FS, "Path not found {}", full_path); | ||||
|         return ERROR_PATH_NOT_FOUND; | ||||
|         return ResultPathNotFound; | ||||
|     case PathParser::FileInPath: | ||||
|     case PathParser::FileFound: | ||||
|         LOG_ERROR(Service_FS, "Unexpected file in path {}", full_path); | ||||
|         return ERROR_UNEXPECTED_FILE_OR_DIRECTORY; | ||||
|         return ResultUnexpectedFileOrDirectory; | ||||
|     case PathParser::DirectoryFound: | ||||
|         break; // Expected 'success' case
 | ||||
|     } | ||||
|  |  | |||
|  | @ -23,13 +23,13 @@ public: | |||
| 
 | ||||
|     ResultVal<std::unique_ptr<FileBackend>> OpenFile(const Path& path, | ||||
|                                                      const Mode& mode) const override; | ||||
|     ResultCode DeleteFile(const Path& path) const override; | ||||
|     ResultCode RenameFile(const Path& src_path, const Path& dest_path) const override; | ||||
|     ResultCode DeleteDirectory(const Path& path) const override; | ||||
|     ResultCode DeleteDirectoryRecursively(const Path& path) const override; | ||||
|     ResultCode CreateFile(const Path& path, u64 size) const override; | ||||
|     ResultCode CreateDirectory(const Path& path) const override; | ||||
|     ResultCode RenameDirectory(const Path& src_path, const Path& dest_path) const override; | ||||
|     Result DeleteFile(const Path& path) const override; | ||||
|     Result RenameFile(const Path& src_path, const Path& dest_path) const override; | ||||
|     Result DeleteDirectory(const Path& path) const override; | ||||
|     Result DeleteDirectoryRecursively(const Path& path) const override; | ||||
|     Result CreateFile(const Path& path, u64 size) const override; | ||||
|     Result CreateDirectory(const Path& path) const override; | ||||
|     Result RenameDirectory(const Path& src_path, const Path& dest_path) const override; | ||||
|     ResultVal<std::unique_ptr<DirectoryBackend>> OpenDirectory(const Path& path) const override; | ||||
|     u64 GetFreeBytes() const override; | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue