From 84cb20bc72031947ac9e625b4a2b5e0059dda441 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 14 Jul 2023 20:16:39 -0400 Subject: core: remove ResultVal type --- src/core/hle/service/filesystem/filesystem.cpp | 126 +++++++++++++++---------- src/core/hle/service/filesystem/filesystem.h | 43 +++++---- src/core/hle/service/filesystem/fsp_srv.cpp | 75 ++++++++------- 3 files changed, 140 insertions(+), 104 deletions(-) (limited to 'src/core/hle/service/filesystem') diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index dfcdd3ada..d9b569789 100644 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -57,8 +57,8 @@ Result VfsDirectoryServiceWrapper::CreateFile(const std::string& path_, u64 size return FileSys::ERROR_PATH_NOT_FOUND; } - const auto entry_type = GetEntryType(path); - if (entry_type.Code() == ResultSuccess) { + FileSys::EntryType entry_type; + if (GetEntryType(&entry_type, path) == ResultSuccess) { return FileSys::ERROR_PATH_ALREADY_EXISTS; } @@ -210,8 +210,8 @@ Result VfsDirectoryServiceWrapper::RenameDirectory(const std::string& src_path_, return ResultUnknown; } -ResultVal VfsDirectoryServiceWrapper::OpenFile(const std::string& path_, - FileSys::Mode mode) const { +Result VfsDirectoryServiceWrapper::OpenFile(FileSys::VirtualFile* out_file, + const std::string& path_, FileSys::Mode mode) const { const std::string path(Common::FS::SanitizePath(path_)); std::string_view npath = path; while (!npath.empty() && (npath[0] == '/' || npath[0] == '\\')) { @@ -224,50 +224,68 @@ ResultVal VfsDirectoryServiceWrapper::OpenFile(const std:: } if (mode == FileSys::Mode::Append) { - return std::make_shared(file, 0, file->GetSize()); + *out_file = std::make_shared(file, 0, file->GetSize()); + } else { + *out_file = file; } - return file; + return ResultSuccess; } -ResultVal VfsDirectoryServiceWrapper::OpenDirectory(const std::string& path_) { +Result VfsDirectoryServiceWrapper::OpenDirectory(FileSys::VirtualDir* out_directory, + const std::string& path_) { std::string path(Common::FS::SanitizePath(path_)); auto dir = GetDirectoryRelativeWrapped(backing, path); if (dir == nullptr) { // TODO(DarkLordZach): Find a better error code for this return FileSys::ERROR_PATH_NOT_FOUND; } - return dir; + *out_directory = dir; + return ResultSuccess; } -ResultVal VfsDirectoryServiceWrapper::GetEntryType( - const std::string& path_) const { +Result VfsDirectoryServiceWrapper::GetEntryType(FileSys::EntryType* out_entry_type, + const std::string& path_) const { std::string path(Common::FS::SanitizePath(path_)); auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path)); - if (dir == nullptr) + if (dir == nullptr) { return FileSys::ERROR_PATH_NOT_FOUND; + } + auto filename = Common::FS::GetFilename(path); // TODO(Subv): Some games use the '/' path, find out what this means. - if (filename.empty()) - return FileSys::EntryType::Directory; + if (filename.empty()) { + *out_entry_type = FileSys::EntryType::Directory; + return ResultSuccess; + } + + if (dir->GetFile(filename) != nullptr) { + *out_entry_type = FileSys::EntryType::File; + return ResultSuccess; + } + + if (dir->GetSubdirectory(filename) != nullptr) { + *out_entry_type = FileSys::EntryType::Directory; + return ResultSuccess; + } - if (dir->GetFile(filename) != nullptr) - return FileSys::EntryType::File; - if (dir->GetSubdirectory(filename) != nullptr) - return FileSys::EntryType::Directory; return FileSys::ERROR_PATH_NOT_FOUND; } -ResultVal VfsDirectoryServiceWrapper::GetFileTimeStampRaw( - const std::string& path) const { +Result VfsDirectoryServiceWrapper::GetFileTimeStampRaw( + FileSys::FileTimeStampRaw* out_file_time_stamp_raw, const std::string& path) const { auto dir = GetDirectoryRelativeWrapped(backing, Common::FS::GetParentPath(path)); if (dir == nullptr) { return FileSys::ERROR_PATH_NOT_FOUND; } - if (GetEntryType(path).Failed()) { + + FileSys::EntryType entry_type; + if (GetEntryType(&entry_type, path) != ResultSuccess) { return FileSys::ERROR_PATH_NOT_FOUND; } - return dir->GetFileTimeStamp(Common::FS::GetFilename(path)); + + *out_file_time_stamp_raw = dir->GetFileTimeStamp(Common::FS::GetFilename(path)); + return ResultSuccess; } FileSystemController::FileSystemController(Core::System& system_) : system{system_} {} @@ -310,57 +328,54 @@ void FileSystemController::SetPackedUpdate(FileSys::VirtualFile update_raw) { romfs_factory->SetPackedUpdate(std::move(update_raw)); } -ResultVal FileSystemController::OpenRomFSCurrentProcess() const { +FileSys::VirtualFile FileSystemController::OpenRomFSCurrentProcess() const { LOG_TRACE(Service_FS, "Opening RomFS for current process"); if (romfs_factory == nullptr) { - // TODO(bunnei): Find a better error code for this - return ResultUnknown; + return nullptr; } return romfs_factory->OpenCurrentProcess(system.GetApplicationProcessProgramID()); } -ResultVal FileSystemController::OpenPatchedRomFS( - u64 title_id, FileSys::ContentRecordType type) const { +FileSys::VirtualFile FileSystemController::OpenPatchedRomFS(u64 title_id, + FileSys::ContentRecordType type) const { LOG_TRACE(Service_FS, "Opening patched RomFS for title_id={:016X}", title_id); if (romfs_factory == nullptr) { - // TODO: Find a better error code for this - return ResultUnknown; + return nullptr; } return romfs_factory->OpenPatchedRomFS(title_id, type); } -ResultVal FileSystemController::OpenPatchedRomFSWithProgramIndex( +FileSys::VirtualFile FileSystemController::OpenPatchedRomFSWithProgramIndex( u64 title_id, u8 program_index, FileSys::ContentRecordType type) const { LOG_TRACE(Service_FS, "Opening patched RomFS for title_id={:016X}, program_index={}", title_id, program_index); if (romfs_factory == nullptr) { - // TODO: Find a better error code for this - return ResultUnknown; + return nullptr; } return romfs_factory->OpenPatchedRomFSWithProgramIndex(title_id, program_index, type); } -ResultVal FileSystemController::OpenRomFS( - u64 title_id, FileSys::StorageId storage_id, FileSys::ContentRecordType type) const { +FileSys::VirtualFile FileSystemController::OpenRomFS(u64 title_id, FileSys::StorageId storage_id, + FileSys::ContentRecordType type) const { LOG_TRACE(Service_FS, "Opening RomFS for title_id={:016X}, storage_id={:02X}, type={:02X}", title_id, storage_id, type); if (romfs_factory == nullptr) { - // TODO(bunnei): Find a better error code for this - return ResultUnknown; + return nullptr; } return romfs_factory->Open(title_id, storage_id, type); } -ResultVal FileSystemController::CreateSaveData( - FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const { +Result FileSystemController::CreateSaveData(FileSys::VirtualDir* out_save_data, + FileSys::SaveDataSpaceId space, + const FileSys::SaveDataAttribute& save_struct) const { LOG_TRACE(Service_FS, "Creating Save Data for space_id={:01X}, save_struct={}", space, save_struct.DebugInfo()); @@ -368,11 +383,13 @@ ResultVal FileSystemController::CreateSaveData( return FileSys::ERROR_ENTITY_NOT_FOUND; } - return save_data_factory->Create(space, save_struct); + *out_save_data = save_data_factory->Create(space, save_struct); + return ResultSuccess; } -ResultVal FileSystemController::OpenSaveData( - FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& attribute) const { +Result FileSystemController::OpenSaveData(FileSys::VirtualDir* out_save_data, + FileSys::SaveDataSpaceId space, + const FileSys::SaveDataAttribute& attribute) const { LOG_TRACE(Service_FS, "Opening Save Data for space_id={:01X}, save_struct={}", space, attribute.DebugInfo()); @@ -380,32 +397,35 @@ ResultVal FileSystemController::OpenSaveData( return FileSys::ERROR_ENTITY_NOT_FOUND; } - return save_data_factory->Open(space, attribute); + *out_save_data = save_data_factory->Open(space, attribute); + return ResultSuccess; } -ResultVal FileSystemController::OpenSaveDataSpace( - FileSys::SaveDataSpaceId space) const { +Result FileSystemController::OpenSaveDataSpace(FileSys::VirtualDir* out_save_data_space, + FileSys::SaveDataSpaceId space) const { LOG_TRACE(Service_FS, "Opening Save Data Space for space_id={:01X}", space); if (save_data_factory == nullptr) { return FileSys::ERROR_ENTITY_NOT_FOUND; } - return save_data_factory->GetSaveDataSpaceDirectory(space); + *out_save_data_space = save_data_factory->GetSaveDataSpaceDirectory(space); + return ResultSuccess; } -ResultVal FileSystemController::OpenSDMC() const { +Result FileSystemController::OpenSDMC(FileSys::VirtualDir* out_sdmc) const { LOG_TRACE(Service_FS, "Opening SDMC"); if (sdmc_factory == nullptr) { return FileSys::ERROR_SD_CARD_NOT_FOUND; } - return sdmc_factory->Open(); + *out_sdmc = sdmc_factory->Open(); + return ResultSuccess; } -ResultVal FileSystemController::OpenBISPartition( - FileSys::BisPartitionId id) const { +Result FileSystemController::OpenBISPartition(FileSys::VirtualDir* out_bis_partition, + FileSys::BisPartitionId id) const { LOG_TRACE(Service_FS, "Opening BIS Partition with id={:08X}", id); if (bis_factory == nullptr) { @@ -417,11 +437,12 @@ ResultVal FileSystemController::OpenBISPartition( return FileSys::ERROR_INVALID_ARGUMENT; } - return part; + *out_bis_partition = part; + return ResultSuccess; } -ResultVal FileSystemController::OpenBISPartitionStorage( - FileSys::BisPartitionId id) const { +Result FileSystemController::OpenBISPartitionStorage( + FileSys::VirtualFile* out_bis_partition_storage, FileSys::BisPartitionId id) const { LOG_TRACE(Service_FS, "Opening BIS Partition Storage with id={:08X}", id); if (bis_factory == nullptr) { @@ -433,7 +454,8 @@ ResultVal FileSystemController::OpenBISPartitionStorage( return FileSys::ERROR_INVALID_ARGUMENT; } - return part; + *out_bis_partition_storage = part; + return ResultSuccess; } u64 FileSystemController::GetFreeSpaceSize(FileSys::StorageId id) const { diff --git a/src/core/hle/service/filesystem/filesystem.h b/src/core/hle/service/filesystem/filesystem.h index a5c1c9d3e..fd991f976 100644 --- a/src/core/hle/service/filesystem/filesystem.h +++ b/src/core/hle/service/filesystem/filesystem.h @@ -64,21 +64,24 @@ public: Result RegisterBIS(std::unique_ptr&& factory); void SetPackedUpdate(FileSys::VirtualFile update_raw); - ResultVal OpenRomFSCurrentProcess() const; - ResultVal OpenPatchedRomFS(u64 title_id, - FileSys::ContentRecordType type) const; - ResultVal OpenPatchedRomFSWithProgramIndex( - u64 title_id, u8 program_index, FileSys::ContentRecordType type) const; - ResultVal OpenRomFS(u64 title_id, FileSys::StorageId storage_id, - FileSys::ContentRecordType type) const; - ResultVal CreateSaveData( - FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const; - ResultVal OpenSaveData( - FileSys::SaveDataSpaceId space, const FileSys::SaveDataAttribute& save_struct) const; - ResultVal OpenSaveDataSpace(FileSys::SaveDataSpaceId space) const; - ResultVal OpenSDMC() const; - ResultVal OpenBISPartition(FileSys::BisPartitionId id) const; - ResultVal OpenBISPartitionStorage(FileSys::BisPartitionId id) const; + FileSys::VirtualFile OpenRomFSCurrentProcess() const; + FileSys::VirtualFile OpenPatchedRomFS(u64 title_id, FileSys::ContentRecordType type) const; + FileSys::VirtualFile OpenPatchedRomFSWithProgramIndex(u64 title_id, u8 program_index, + FileSys::ContentRecordType type) const; + FileSys::VirtualFile OpenRomFS(u64 title_id, FileSys::StorageId storage_id, + FileSys::ContentRecordType type) const; + + Result CreateSaveData(FileSys::VirtualDir* out_save_data, FileSys::SaveDataSpaceId space, + const FileSys::SaveDataAttribute& save_struct) const; + Result OpenSaveData(FileSys::VirtualDir* out_save_data, FileSys::SaveDataSpaceId space, + const FileSys::SaveDataAttribute& save_struct) const; + Result OpenSaveDataSpace(FileSys::VirtualDir* out_save_data_space, + FileSys::SaveDataSpaceId space) const; + Result OpenSDMC(FileSys::VirtualDir* out_sdmc) const; + Result OpenBISPartition(FileSys::VirtualDir* out_bis_partition, + FileSys::BisPartitionId id) const; + Result OpenBISPartitionStorage(FileSys::VirtualFile* out_bis_partition_storage, + FileSys::BisPartitionId id) const; u64 GetFreeSpaceSize(FileSys::StorageId id) const; u64 GetTotalSpaceSize(FileSys::StorageId id) const; @@ -224,26 +227,28 @@ public: * @param mode Mode to open the file with * @return Opened file, or error code */ - ResultVal OpenFile(const std::string& path, FileSys::Mode mode) const; + Result OpenFile(FileSys::VirtualFile* out_file, const std::string& path, + FileSys::Mode mode) const; /** * Open a directory specified by its path * @param path Path relative to the archive * @return Opened directory, or error code */ - ResultVal OpenDirectory(const std::string& path); + Result OpenDirectory(FileSys::VirtualDir* out_directory, const std::string& path); /** * Get the type of the specified path * @return The type of the specified path or error code */ - ResultVal GetEntryType(const std::string& path) const; + Result GetEntryType(FileSys::EntryType* out_entry_type, const std::string& path) const; /** * Get the timestamp of the specified path * @return The timestamp of the specified path or error code */ - ResultVal GetFileTimeStampRaw(const std::string& path) const; + Result GetFileTimeStampRaw(FileSys::FileTimeStampRaw* out_time_stamp_raw, + const std::string& path) const; private: FileSys::VirtualDir backing; diff --git a/src/core/hle/service/filesystem/fsp_srv.cpp b/src/core/hle/service/filesystem/fsp_srv.cpp index 427dbc8b3..423a814cb 100644 --- a/src/core/hle/service/filesystem/fsp_srv.cpp +++ b/src/core/hle/service/filesystem/fsp_srv.cpp @@ -419,14 +419,15 @@ public: LOG_DEBUG(Service_FS, "called. file={}, mode={}", name, mode); - auto result = backend.OpenFile(name, mode); - if (result.Failed()) { + FileSys::VirtualFile vfs_file{}; + auto result = backend.OpenFile(&vfs_file, name, mode); + if (result != ResultSuccess) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result.Code()); + rb.Push(result); return; } - auto file = std::make_shared(system, result.Unwrap()); + auto file = std::make_shared(system, vfs_file); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -444,14 +445,15 @@ public: LOG_DEBUG(Service_FS, "called. directory={}, filter={}", name, filter_flags); - auto result = backend.OpenDirectory(name); - if (result.Failed()) { + FileSys::VirtualDir vfs_dir{}; + auto result = backend.OpenDirectory(&vfs_dir, name); + if (result != ResultSuccess) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result.Code()); + rb.Push(result); return; } - auto directory = std::make_shared(system, result.Unwrap()); + auto directory = std::make_shared(system, vfs_dir); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -464,16 +466,17 @@ public: LOG_DEBUG(Service_FS, "called. file={}", name); - auto result = backend.GetEntryType(name); - if (result.Failed()) { + FileSys::EntryType vfs_entry_type{}; + auto result = backend.GetEntryType(&vfs_entry_type, name); + if (result != ResultSuccess) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result.Code()); + rb.Push(result); return; } IPC::ResponseBuilder rb{ctx, 3}; rb.Push(ResultSuccess); - rb.Push(static_cast(*result)); + rb.Push(static_cast(vfs_entry_type)); } void Commit(HLERequestContext& ctx) { @@ -505,16 +508,17 @@ public: LOG_WARNING(Service_FS, "(Partial Implementation) called. file={}", name); - auto result = backend.GetFileTimeStampRaw(name); - if (result.Failed()) { + FileSys::FileTimeStampRaw vfs_timestamp{}; + auto result = backend.GetFileTimeStampRaw(&vfs_timestamp, name); + if (result != ResultSuccess) { IPC::ResponseBuilder rb{ctx, 2}; - rb.Push(result.Code()); + rb.Push(result); return; } IPC::ResponseBuilder rb{ctx, 10}; rb.Push(ResultSuccess); - rb.PushRaw(*result); + rb.PushRaw(vfs_timestamp); } private: @@ -572,14 +576,15 @@ private: } void FindAllSaves(FileSys::SaveDataSpaceId space) { - const auto save_root = fsc.OpenSaveDataSpace(space); + FileSys::VirtualDir save_root{}; + const auto result = fsc.OpenSaveDataSpace(&save_root, space); - if (save_root.Failed() || *save_root == nullptr) { + if (result != ResultSuccess || save_root == nullptr) { LOG_ERROR(Service_FS, "The save root for the space_id={:02X} was invalid!", space); return; } - for (const auto& type : (*save_root)->GetSubdirectories()) { + for (const auto& type : save_root->GetSubdirectories()) { if (type->GetName() == "save") { for (const auto& save_id : type->GetSubdirectories()) { for (const auto& user_id : save_id->GetSubdirectories()) { @@ -837,9 +842,11 @@ void FSP_SRV::OpenFileSystemWithPatch(HLERequestContext& ctx) { void FSP_SRV::OpenSdCardFileSystem(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called"); - auto filesystem = - std::make_shared(system, fsc.OpenSDMC().Unwrap(), - SizeGetter::FromStorageId(fsc, FileSys::StorageId::SdCard)); + FileSys::VirtualDir sdmc_dir{}; + fsc.OpenSDMC(&sdmc_dir); + + auto filesystem = std::make_shared( + system, sdmc_dir, SizeGetter::FromStorageId(fsc, FileSys::StorageId::SdCard)); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -856,7 +863,8 @@ void FSP_SRV::CreateSaveDataFileSystem(HLERequestContext& ctx) { LOG_DEBUG(Service_FS, "called save_struct = {}, uid = {:016X}{:016X}", save_struct.DebugInfo(), uid[1], uid[0]); - fsc.CreateSaveData(FileSys::SaveDataSpaceId::NandUser, save_struct); + FileSys::VirtualDir save_data_dir{}; + fsc.CreateSaveData(&save_data_dir, FileSys::SaveDataSpaceId::NandUser, save_struct); IPC::ResponseBuilder rb{ctx, 2}; rb.Push(ResultSuccess); @@ -874,8 +882,9 @@ void FSP_SRV::OpenSaveDataFileSystem(HLERequestContext& ctx) { LOG_INFO(Service_FS, "called."); - auto dir = fsc.OpenSaveData(parameters.space_id, parameters.attribute); - if (dir.Failed()) { + FileSys::VirtualDir dir{}; + auto result = fsc.OpenSaveData(&dir, parameters.space_id, parameters.attribute); + if (result != ResultSuccess) { IPC::ResponseBuilder rb{ctx, 2, 0, 0}; rb.Push(FileSys::ERROR_ENTITY_NOT_FOUND); return; @@ -899,8 +908,8 @@ void FSP_SRV::OpenSaveDataFileSystem(HLERequestContext& ctx) { ASSERT(false); } - auto filesystem = std::make_shared(system, std::move(dir.Unwrap()), - SizeGetter::FromStorageId(fsc, id)); + auto filesystem = + std::make_shared(system, std::move(dir), SizeGetter::FromStorageId(fsc, id)); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -970,7 +979,7 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(HLERequestContext& ctx) { if (!romfs) { auto current_romfs = fsc.OpenRomFSCurrentProcess(); - if (current_romfs.Failed()) { + if (!current_romfs) { // TODO (bunnei): Find the right error code to use here LOG_CRITICAL(Service_FS, "no file system interface available!"); IPC::ResponseBuilder rb{ctx, 2}; @@ -978,7 +987,7 @@ void FSP_SRV::OpenDataStorageByCurrentProcess(HLERequestContext& ctx) { return; } - romfs = current_romfs.Unwrap(); + romfs = current_romfs; } auto storage = std::make_shared(system, romfs); @@ -999,7 +1008,7 @@ void FSP_SRV::OpenDataStorageByDataId(HLERequestContext& ctx) { auto data = fsc.OpenRomFS(title_id, storage_id, FileSys::ContentRecordType::Data); - if (data.Failed()) { + if (!data) { const auto archive = FileSys::SystemArchive::SynthesizeSystemArchive(title_id); if (archive != nullptr) { @@ -1021,7 +1030,7 @@ void FSP_SRV::OpenDataStorageByDataId(HLERequestContext& ctx) { const FileSys::PatchManager pm{title_id, fsc, content_provider}; auto storage = std::make_shared( - system, pm.PatchRomFS(std::move(data.Unwrap()), 0, FileSys::ContentRecordType::Data)); + system, pm.PatchRomFS(std::move(data), 0, FileSys::ContentRecordType::Data)); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); @@ -1051,7 +1060,7 @@ void FSP_SRV::OpenDataStorageWithProgramIndex(HLERequestContext& ctx) { fsc.OpenPatchedRomFSWithProgramIndex(system.GetApplicationProcessProgramID(), program_index, FileSys::ContentRecordType::Program); - if (patched_romfs.Failed()) { + if (!patched_romfs) { // TODO: Find the right error code to use here LOG_ERROR(Service_FS, "could not open storage with program_index={}", program_index); @@ -1060,7 +1069,7 @@ void FSP_SRV::OpenDataStorageWithProgramIndex(HLERequestContext& ctx) { return; } - auto storage = std::make_shared(system, std::move(patched_romfs.Unwrap())); + auto storage = std::make_shared(system, std::move(patched_romfs)); IPC::ResponseBuilder rb{ctx, 2, 0, 1}; rb.Push(ResultSuccess); -- cgit v1.2.3