core: backport some ResultCode updates (#6645)

Co-authored-by: Lioncash <mathew1800@gmail.com>
Co-authored-by: Morph <39850852+Morph1984@users.noreply.github.com>
This commit is contained in:
GPUCode 2023-07-03 03:23:53 +03:00 committed by GitHub
parent 0b37c1da57
commit 2126c240cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 1204 additions and 277 deletions

View file

@ -42,7 +42,7 @@ public:
if (offset > size) {
return ERR_WRITE_BEYOND_END;
} else if (offset == size) {
return MakeResult<std::size_t>(0);
return 0ULL;
}
if (offset + length > size) {
@ -150,11 +150,9 @@ public:
Mode rwmode;
rwmode.write_flag.Assign(1);
rwmode.read_flag.Assign(1);
std::unique_ptr<DelayGenerator> delay_generator =
std::make_unique<ExtSaveDataDelayGenerator>();
auto disk_file =
std::make_unique<FixSizeDiskFile>(std::move(file), rwmode, std::move(delay_generator));
return MakeResult<std::unique_ptr<FileBackend>>(std::move(disk_file));
auto delay_generator = std::make_unique<ExtSaveDataDelayGenerator>();
return std::make_unique<FixSizeDiskFile>(std::move(file), rwmode,
std::move(delay_generator));
}
ResultCode CreateFile(const Path& path, u64 size) const override {
@ -255,8 +253,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_ExtSaveData::Open(cons
}
}
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<ExtSaveDataDelayGenerator>();
auto archive = std::make_unique<ExtSaveDataArchive>(fullpath, std::move(delay_generator));
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
return std::make_unique<ExtSaveDataArchive>(fullpath, std::move(delay_generator));
}
ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path,
@ -276,7 +273,7 @@ ResultCode ArchiveFactory_ExtSaveData::Format(const Path& path,
if (!file.IsOpen()) {
// TODO(Subv): Find the correct error code
return ResultCode(-1);
return RESULT_UNKNOWN;
}
file.WriteBytes(&format_info, sizeof(format_info));
@ -296,7 +293,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_ExtSaveData::GetFormatInfo(const Pat
ArchiveFormatInfo info = {};
file.ReadBytes(&info, sizeof(info));
return MakeResult<ArchiveFormatInfo>(info);
return info;
}
void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data,

View file

@ -170,16 +170,14 @@ ResultVal<std::unique_ptr<FileBackend>> NCCHArchive::OpenFile(const Path& path,
if (!archive_data.empty()) {
u64 romfs_offset = 0;
u64 romfs_size = archive_data.size();
std::unique_ptr<DelayGenerator> delay_generator =
std::make_unique<RomFSDelayGenerator>();
file = std::make_unique<IVFCFileInMemory>(std::move(archive_data), romfs_offset,
auto delay_generator = std::make_unique<RomFSDelayGenerator>();
return std::make_unique<IVFCFileInMemory>(std::move(archive_data), romfs_offset,
romfs_size, std::move(delay_generator));
return MakeResult<std::unique_ptr<FileBackend>>(std::move(file));
}
return ERROR_NOT_FOUND;
}
return MakeResult<std::unique_ptr<FileBackend>>(std::move(file));
return file;
}
ResultCode NCCHArchive::DeleteFile(const Path& path) const {
@ -192,21 +190,21 @@ ResultCode NCCHArchive::DeleteFile(const Path& path) const {
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultCode NCCHArchive::CreateFile(const Path& path, u64 size) const {
@ -219,20 +217,20 @@ ResultCode NCCHArchive::CreateFile(const Path& path, u64 size) const {
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
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 ResultCode(-1);
return RESULT_UNKNOWN;
}
u64 NCCHArchive::GetFreeBytes() const {
@ -253,14 +251,14 @@ ResultVal<std::size_t> NCCHFile::Read(const u64 offset, const std::size_t length
std::size_t copy_size = std::min(length, available_size);
memcpy(buffer, file_buffer.data() + offset, copy_size);
return MakeResult<std::size_t>(copy_size);
return copy_size;
}
ResultVal<std::size_t> NCCHFile::Write(const u64 offset, const std::size_t length, const bool flush,
const u8* buffer) {
LOG_ERROR(Service_FS, "Attempted to write to NCCH file");
// TODO(shinyquagsire23): Find error code
return MakeResult<std::size_t>(0);
return 0ULL;
}
u64 NCCHFile::GetSize() const {
@ -290,9 +288,8 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path&
NCCHArchivePath open_path;
std::memcpy(&open_path, binary.data(), sizeof(NCCHArchivePath));
auto archive = std::make_unique<NCCHArchive>(
return std::make_unique<NCCHArchive>(
open_path.tid, static_cast<Service::FS::MediaType>(open_path.media_type & 0xFF));
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
}
ResultCode ArchiveFactory_NCCH::Format(const Path& path,
@ -308,7 +305,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_NCCH::GetFormatInfo(const Path& path
u64 program_id) const {
// TODO(Subv): Implement
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
return ResultCode(-1);
return RESULT_UNKNOWN;
}
} // namespace FileSys

View file

@ -45,7 +45,7 @@ ResultVal<std::tuple<MediaType, u64>> ParsePath(const Path& path, T program_id_r
return ERROR_UNSUPPORTED_OPEN_FLAGS;
}
return MakeResult<std::tuple<MediaType, u64>>(media_type, program_id_reader(data));
return std::make_tuple(media_type, program_id_reader(data));
}
ResultVal<std::tuple<MediaType, u64>> ParsePathPermitted(const Path& path) {

View file

@ -108,8 +108,7 @@ ResultVal<std::unique_ptr<FileBackend>> SDMCArchive::OpenFileBase(const Path& pa
}
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<SDMCDelayGenerator>();
auto disk_file = std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator));
return MakeResult<std::unique_ptr<FileBackend>>(std::move(disk_file));
return std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator));
}
ResultCode SDMCArchive::DeleteFile(const Path& path) const {
@ -358,8 +357,7 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SDMCArchive::OpenDirectory(const Pa
break; // Expected 'success' case
}
auto directory = std::make_unique<DiskDirectory>(full_path);
return MakeResult<std::unique_ptr<DirectoryBackend>>(std::move(directory));
return std::make_unique<DiskDirectory>(full_path);
}
u64 SDMCArchive::GetFreeBytes() const {
@ -390,8 +388,7 @@ bool ArchiveFactory_SDMC::Initialize() {
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMC::Open(const Path& path,
u64 program_id) {
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<SDMCDelayGenerator>();
auto archive = std::make_unique<SDMCArchive>(sdmc_directory, std::move(delay_generator));
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
return std::make_unique<SDMCArchive>(sdmc_directory, std::move(delay_generator));
}
ResultCode ArchiveFactory_SDMC::Format(const Path& path,
@ -405,7 +402,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMC::GetFormatInfo(const Path& path
u64 program_id) const {
// TODO(Subv): Implement
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
return ResultCode(-1);
return RESULT_UNKNOWN;
}
} // namespace FileSys

View file

@ -78,9 +78,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SDMCWriteOnly::Open(co
u64 program_id) {
std::unique_ptr<DelayGenerator> delay_generator =
std::make_unique<SDMCWriteOnlyDelayGenerator>();
auto archive =
std::make_unique<SDMCWriteOnlyArchive>(sdmc_directory, std::move(delay_generator));
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
return std::make_unique<SDMCWriteOnlyArchive>(sdmc_directory, std::move(delay_generator));
}
ResultCode ArchiveFactory_SDMCWriteOnly::Format(const Path& path,
@ -88,14 +86,14 @@ ResultCode ArchiveFactory_SDMCWriteOnly::Format(const Path& path,
u64 program_id) {
// TODO(wwylele): hwtest this
LOG_ERROR(Service_FS, "Attempted to format a SDMC write-only archive.");
return ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultVal<ArchiveFormatInfo> ArchiveFactory_SDMCWriteOnly::GetFormatInfo(const Path& path,
u64 program_id) const {
// TODO(Subv): Implement
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
return ResultCode(-1);
return RESULT_UNKNOWN;
}
} // namespace FileSys

View file

@ -48,7 +48,7 @@ public:
}
std::memcpy(buffer, data->data(), data->size());
return MakeResult<std::size_t>(data->size());
return data->size();
}
ResultVal<std::size_t> Write(u64 offset, std::size_t length, bool flush,
@ -183,8 +183,7 @@ private:
if (ncch_data.romfs_file) {
std::unique_ptr<DelayGenerator> delay_generator =
std::make_unique<RomFSDelayGenerator>();
return MakeResult<std::unique_ptr<FileBackend>>(
std::make_unique<IVFCFile>(ncch_data.romfs_file, std::move(delay_generator)));
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;
@ -195,8 +194,8 @@ private:
if (ncch_data.update_romfs_file) {
std::unique_ptr<DelayGenerator> delay_generator =
std::make_unique<RomFSDelayGenerator>();
return MakeResult<std::unique_ptr<FileBackend>>(std::make_unique<IVFCFile>(
ncch_data.update_romfs_file, std::move(delay_generator)));
return std::make_unique<IVFCFile>(ncch_data.update_romfs_file,
std::move(delay_generator));
} else {
LOG_INFO(Service_FS, "Unable to read update RomFS");
return ERROR_ROMFS_NOT_FOUND;
@ -206,8 +205,7 @@ private:
ResultVal<std::unique_ptr<FileBackend>> OpenExeFS(const std::string& filename) const {
if (filename == "icon") {
if (ncch_data.icon) {
return MakeResult<std::unique_ptr<FileBackend>>(
std::make_unique<ExeFSSectionFile>(ncch_data.icon));
return std::make_unique<ExeFSSectionFile>(ncch_data.icon);
}
LOG_WARNING(Service_FS, "Unable to read icon");
@ -216,8 +214,7 @@ private:
if (filename == "logo") {
if (ncch_data.logo) {
return MakeResult<std::unique_ptr<FileBackend>>(
std::make_unique<ExeFSSectionFile>(ncch_data.logo));
return std::make_unique<ExeFSSectionFile>(ncch_data.logo);
}
LOG_WARNING(Service_FS, "Unable to read logo");
@ -226,8 +223,7 @@ private:
if (filename == "banner") {
if (ncch_data.banner) {
return MakeResult<std::unique_ptr<FileBackend>>(
std::make_unique<ExeFSSectionFile>(ncch_data.banner));
return std::make_unique<ExeFSSectionFile>(ncch_data.banner);
}
LOG_WARNING(Service_FS, "Unable to read banner");
@ -297,8 +293,7 @@ void ArchiveFactory_SelfNCCH::Register(Loader::AppLoader& app_loader) {
ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SelfNCCH::Open(const Path& path,
u64 program_id) {
auto archive = std::make_unique<SelfNCCHArchive>(ncch_data[program_id]);
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
return std::make_unique<SelfNCCHArchive>(ncch_data[program_id]);
}
ResultCode ArchiveFactory_SelfNCCH::Format(const Path&, const FileSys::ArchiveFormatInfo&,

View file

@ -50,8 +50,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveSource_SDSaveData::Open(u64 pr
return ERR_NOT_FORMATTED;
}
auto archive = std::make_unique<SaveDataArchive>(std::move(concrete_mount_point));
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
return std::make_unique<SaveDataArchive>(std::move(concrete_mount_point));
}
ResultCode ArchiveSource_SDSaveData::Format(u64 program_id,
@ -83,7 +82,7 @@ ResultVal<ArchiveFormatInfo> ArchiveSource_SDSaveData::GetFormatInfo(u64 program
ArchiveFormatInfo info = {};
file.ReadBytes(&info, sizeof(info));
return MakeResult<ArchiveFormatInfo>(info);
return info;
}
std::string ArchiveSource_SDSaveData::GetSaveDataPathFor(const std::string& mount_point,

View file

@ -59,8 +59,7 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_SystemSaveData::Open(c
// TODO(Subv): Check error code, this one is probably wrong
return ERROR_NOT_FOUND;
}
auto archive = std::make_unique<SaveDataArchive>(fullpath);
return MakeResult<std::unique_ptr<ArchiveBackend>>(std::move(archive));
return std::make_unique<SaveDataArchive>(fullpath);
}
ResultCode ArchiveFactory_SystemSaveData::Format(const Path& path,
@ -76,7 +75,7 @@ ResultVal<ArchiveFormatInfo> ArchiveFactory_SystemSaveData::GetFormatInfo(const
u64 program_id) const {
// TODO(Subv): Implement
LOG_ERROR(Service_FS, "Unimplemented GetFormatInfo archive {}", GetName());
return ResultCode(-1);
return RESULT_UNKNOWN;
}
} // namespace FileSys

View file

@ -22,7 +22,7 @@ ResultVal<std::size_t> DiskFile::Read(const u64 offset, const std::size_t length
return ERROR_INVALID_OPEN_FLAGS;
file->Seek(offset, SEEK_SET);
return MakeResult<std::size_t>(file->ReadBytes(buffer, length));
return file->ReadBytes(buffer, length);
}
ResultVal<std::size_t> DiskFile::Write(const u64 offset, const std::size_t length, const bool flush,
@ -34,7 +34,7 @@ ResultVal<std::size_t> DiskFile::Write(const u64 offset, const std::size_t lengt
std::size_t written = file->WriteBytes(buffer, length);
if (flush)
file->Flush();
return MakeResult<std::size_t>(written);
return written;
}
u64 DiskFile::GetSize() const {

View file

@ -31,8 +31,7 @@ std::string IVFCArchive::GetName() const {
ResultVal<std::unique_ptr<FileBackend>> IVFCArchive::OpenFile(const Path& path,
const Mode& mode) const {
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<IVFCDelayGenerator>();
return MakeResult<std::unique_ptr<FileBackend>>(
std::make_unique<IVFCFile>(romfs_file, std::move(delay_generator)));
return std::make_unique<IVFCFile>(romfs_file, std::move(delay_generator));
}
ResultCode IVFCArchive::DeleteFile(const Path& path) const {
@ -45,21 +44,21 @@ ResultCode IVFCArchive::DeleteFile(const Path& path) const {
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
@ -72,17 +71,17 @@ ResultCode IVFCArchive::CreateFile(const Path& path, u64 size) const {
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultCode 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 ResultCode(-1);
return RESULT_UNKNOWN;
}
ResultVal<std::unique_ptr<DirectoryBackend>> IVFCArchive::OpenDirectory(const Path& path) const {
return MakeResult<std::unique_ptr<DirectoryBackend>>(std::make_unique<IVFCDirectory>());
return std::make_unique<IVFCDirectory>();
}
u64 IVFCArchive::GetFreeBytes() const {
@ -99,14 +98,14 @@ IVFCFile::IVFCFile(std::shared_ptr<RomFSReader> file,
ResultVal<std::size_t> IVFCFile::Read(const u64 offset, const std::size_t length,
u8* buffer) const {
LOG_TRACE(Service_FS, "called offset={}, length={}", offset, length);
return MakeResult<std::size_t>(romfs_file->ReadFile(offset, length, buffer));
return romfs_file->ReadFile(offset, length, buffer);
}
ResultVal<std::size_t> IVFCFile::Write(const u64 offset, const std::size_t length, const bool flush,
const u8* buffer) {
LOG_ERROR(Service_FS, "Attempted to write to IVFC file");
// TODO(Subv): Find error code
return MakeResult<std::size_t>(0);
return 0ULL;
}
u64 IVFCFile::GetSize() const {
@ -130,14 +129,14 @@ ResultVal<std::size_t> IVFCFileInMemory::Read(const u64 offset, const std::size_
std::size_t read_length = (std::size_t)std::min((u64)length, data_size - offset);
std::memcpy(buffer, romfs_file.data() + data_offset + offset, read_length);
return MakeResult<std::size_t>(read_length);
return read_length;
}
ResultVal<std::size_t> IVFCFileInMemory::Write(const u64 offset, const std::size_t length,
const bool flush, const u8* buffer) {
LOG_ERROR(Service_FS, "Attempted to write to IVFC file");
// TODO(Subv): Find error code
return MakeResult<std::size_t>(0);
return 0ULL;
}
u64 IVFCFileInMemory::GetSize() const {

View file

@ -90,8 +90,7 @@ ResultVal<std::unique_ptr<FileBackend>> SaveDataArchive::OpenFile(const Path& pa
}
std::unique_ptr<DelayGenerator> delay_generator = std::make_unique<SaveDataDelayGenerator>();
auto disk_file = std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator));
return MakeResult<std::unique_ptr<FileBackend>>(std::move(disk_file));
return std::make_unique<DiskFile>(std::move(file), mode, std::move(delay_generator));
}
ResultCode SaveDataArchive::DeleteFile(const Path& path) const {
@ -343,8 +342,7 @@ ResultVal<std::unique_ptr<DirectoryBackend>> SaveDataArchive::OpenDirectory(
break; // Expected 'success' case
}
auto directory = std::make_unique<DiskDirectory>(full_path);
return MakeResult<std::unique_ptr<DirectoryBackend>>(std::move(directory));
return std::make_unique<DiskDirectory>(full_path);
}
u64 SaveDataArchive::GetFreeBytes() const {