From 45516783f6597b05aef3aa08c2787b6df30a3cbf Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 20 Oct 2019 10:36:13 -0700 Subject: [PATCH 1/2] Io: Return error code for write attempt to UMD. Previously, we were returning file not found (because 0), which was not correct. We were also allowing write handles to sce_lbn. --- Core/FileSystems/ISOFileSystem.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index 3bb89cd304..4afa7e470e 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -335,6 +335,11 @@ u32 ISOFileSystem::OpenFile(std::string filename, FileAccess access, const char entry.isRawSector = false; entry.isBlockSectorMode = false; + if (access & FILEACCESS_WRITE) { + ERROR_LOG(FILESYS, "Can't open file %s with write access on an ISO partition", filename.c_str()); + return SCE_KERNEL_ERROR_ERRNO_INVALID_FLAG; + } + if (filename.compare(0, 8, "/sce_lbn") == 0) { // Raw sector read. u32 sectorStart = 0xFFFFFFFF, readSize = 0xFFFFFFFF; @@ -364,11 +369,6 @@ u32 ISOFileSystem::OpenFile(std::string filename, FileAccess access, const char return newHandle; } - if (access & FILEACCESS_WRITE) { - ERROR_LOG(FILESYS, "Can't open file %s with write access on an ISO partition", filename.c_str()); - return 0; - } - // May return entireISO for "umd0:" entry.file = GetFromPath(filename); if (!entry.file){ From 913121cf2bf809e9d84b4917c408cac9573bfd24 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 20 Oct 2019 11:03:37 -0700 Subject: [PATCH 2/2] Io: Consistently use error codes with OpenFile(). This gets rid of OpenWithError(), and just always returns a negative value on error for OpenFile(). Also fixed the sequence rollover, which could've returned 0. 0 should be considered a valid handle ideally, but left it never returning 0 to simplify cleanup in some areas. --- Core/Dialog/PSPGamedataInstallDialog.cpp | 14 +++-- Core/Dialog/SavedataParam.cpp | 6 +-- Core/FileSystems/BlobFileSystem.cpp | 2 +- Core/FileSystems/BlobFileSystem.h | 4 +- Core/FileSystems/DirectoryFileSystem.cpp | 8 +-- Core/FileSystems/DirectoryFileSystem.h | 4 +- Core/FileSystems/FileSystem.h | 7 +-- Core/FileSystems/ISOFileSystem.cpp | 6 +-- Core/FileSystems/ISOFileSystem.h | 4 +- Core/FileSystems/MetaFileSystem.cpp | 62 ++++++++-------------- Core/FileSystems/MetaFileSystem.h | 22 ++++---- Core/FileSystems/VirtualDiscFileSystem.cpp | 4 +- Core/FileSystems/VirtualDiscFileSystem.h | 2 +- Core/HLE/sceIo.cpp | 8 +-- Core/HLE/scePsmf.cpp | 4 +- Core/PSPLoaders.cpp | 2 +- Core/Util/GameManager.cpp | 5 +- UI/GameInfoCache.cpp | 2 +- 18 files changed, 80 insertions(+), 86 deletions(-) diff --git a/Core/Dialog/PSPGamedataInstallDialog.cpp b/Core/Dialog/PSPGamedataInstallDialog.cpp index 227ae76093..a51d8ccefb 100644 --- a/Core/Dialog/PSPGamedataInstallDialog.cpp +++ b/Core/Dialog/PSPGamedataInstallDialog.cpp @@ -129,18 +129,20 @@ void PSPGamedataInstallDialog::OpenNextFile() { std::string outputFileName = GetGameDataInstallFileName(&request, inFileNames[readFiles]); currentInputFile = pspFileSystem.OpenFile(inputFileName, FILEACCESS_READ); - if (!currentInputFile) { + if (currentInputFile < 0) { // TODO: Generate an error code? ERROR_LOG_REPORT(SCEUTILITY, "Unable to read from install file: %s", inFileNames[readFiles].c_str()); ++readFiles; + currentInputFile = 0; return; } currentOutputFile = pspFileSystem.OpenFile(outputFileName, (FileAccess)(FILEACCESS_WRITE | FILEACCESS_CREATE | FILEACCESS_TRUNCATE)); - if (!currentOutputFile) { + if (currentOutputFile < 0) { // TODO: Generate an error code? ERROR_LOG(SCEUTILITY, "Unable to write to install file: %s", inFileNames[readFiles].c_str()); pspFileSystem.CloseFile(currentInputFile); currentInputFile = 0; + currentOutputFile = 0; ++readFiles; return; } @@ -172,10 +174,12 @@ void PSPGamedataInstallDialog::CopyCurrentFileData() { } void PSPGamedataInstallDialog::CloseCurrentFile() { - pspFileSystem.CloseFile(currentOutputFile); + if (currentOutputFile >= 0) + pspFileSystem.CloseFile(currentOutputFile); currentOutputFile = 0; - pspFileSystem.CloseFile(currentInputFile); + if (currentInputFile >= 0) + pspFileSystem.CloseFile(currentInputFile); currentInputFile = 0; ++readFiles; @@ -208,7 +212,7 @@ void PSPGamedataInstallDialog::WriteSfoFile() { sfoFile.WriteSFO(&sfoData,&sfoSize); u32 handle = pspFileSystem.OpenFile(sfopath, (FileAccess)(FILEACCESS_WRITE | FILEACCESS_CREATE | FILEACCESS_TRUNCATE)); - if (handle != 0) { + if (handle >= 0) { pspFileSystem.WriteFile(handle, sfoData, sfoSize); pspFileSystem.CloseFile(handle); } diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index dadc46b1c4..646a6bd20c 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -62,7 +62,7 @@ namespace bool ReadPSPFile(std::string filename, u8 **data, s64 dataSize, s64 *readSize) { u32 handle = pspFileSystem.OpenFile(filename, FILEACCESS_READ); - if (handle == 0) + if (handle < 0) return false; if(dataSize == -1) @@ -82,7 +82,7 @@ namespace bool WritePSPFile(std::string filename, u8 *data, SceSize dataSize) { u32 handle = pspFileSystem.OpenFile(filename, (FileAccess)(FILEACCESS_WRITE | FILEACCESS_CREATE | FILEACCESS_TRUNCATE)); - if (handle == 0) + if (handle < 0) return false; size_t result = pspFileSystem.WriteFile(handle, data, dataSize); @@ -209,7 +209,7 @@ void SavedataParam::Init() // Create a nomedia file to hide save icons form Android image viewer #ifdef __ANDROID__ int handle = pspFileSystem.OpenFile(savePath + ".nomedia", (FileAccess)(FILEACCESS_CREATE | FILEACCESS_WRITE), 0); - if (handle) { + if (handle >= 0) { pspFileSystem.CloseFile(handle); } else { ELOG("Failed to create .nomedia file"); diff --git a/Core/FileSystems/BlobFileSystem.cpp b/Core/FileSystems/BlobFileSystem.cpp index 27b4113aa3..0f02bbd821 100644 --- a/Core/FileSystems/BlobFileSystem.cpp +++ b/Core/FileSystems/BlobFileSystem.cpp @@ -36,7 +36,7 @@ std::vector BlobFileSystem::GetDirListing(std::string path) { return listing; } -u32 BlobFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { +int BlobFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { u32 newHandle = alloc_->GetNewHandle(); entries_[newHandle] = 0; return newHandle; diff --git a/Core/FileSystems/BlobFileSystem.h b/Core/FileSystems/BlobFileSystem.h index 573fdacdd7..2a877918d9 100644 --- a/Core/FileSystems/BlobFileSystem.h +++ b/Core/FileSystems/BlobFileSystem.h @@ -1,4 +1,4 @@ -// Copyright (c) 2017- PPSSPP Project. +// Copyright (c) 2017- PPSSPP Project. // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -33,7 +33,7 @@ public: void DoState(PointerWrap &p) override; std::vector GetDirListing(std::string path) override; - u32 OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override; + int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override; void CloseFile(u32 handle) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override; diff --git a/Core/FileSystems/DirectoryFileSystem.cpp b/Core/FileSystems/DirectoryFileSystem.cpp index 07b8930abc..e6e97546e2 100644 --- a/Core/FileSystems/DirectoryFileSystem.cpp +++ b/Core/FileSystems/DirectoryFileSystem.cpp @@ -607,7 +607,7 @@ bool DirectoryFileSystem::RemoveFile(const std::string &filename) { return ReplayApplyDisk(ReplayAction::FILE_REMOVE, retValue, CoreTiming::GetGlobalTimeUs()) != 0; } -u32 DirectoryFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { +int DirectoryFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { OpenFileEntry entry; u32 err = 0; bool success = entry.hFile.Open(basePath, filename, access, err); @@ -1044,10 +1044,10 @@ bool VFSFileSystem::RemoveFile(const std::string &filename) { return false; } -u32 VFSFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { +int VFSFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { if (access != FILEACCESS_READ) { ERROR_LOG(FILESYS, "VFSFileSystem only supports plain reading"); - return 0; + return SCE_KERNEL_ERROR_ERRNO_INVALID_FLAG; } std::string fullName = GetLocalPath(filename); @@ -1058,7 +1058,7 @@ u32 VFSFileSystem::OpenFile(std::string filename, FileAccess access, const char u8 *data = VFSReadFile(fullNameC, &size); if (!data) { ERROR_LOG(FILESYS, "VFSFileSystem failed to open %s", filename.c_str()); - return 0; + return SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND; } OpenFileEntry entry; diff --git a/Core/FileSystems/DirectoryFileSystem.h b/Core/FileSystems/DirectoryFileSystem.h index 54742cd3a1..e00a4c4946 100644 --- a/Core/FileSystems/DirectoryFileSystem.h +++ b/Core/FileSystems/DirectoryFileSystem.h @@ -92,7 +92,7 @@ public: void DoState(PointerWrap &p) override; std::vector GetDirListing(std::string path) override; - u32 OpenFile(std::string filename, FileAccess access, const char *devicename=NULL) override; + int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override; void CloseFile(u32 handle) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override; @@ -137,7 +137,7 @@ public: void DoState(PointerWrap &p) override; std::vector GetDirListing(std::string path) override; - u32 OpenFile(std::string filename, FileAccess access, const char *devicename=NULL) override; + int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override; void CloseFile(u32 handle) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override; diff --git a/Core/FileSystems/FileSystem.h b/Core/FileSystems/FileSystem.h index a739f7197c..4f87736613 100644 --- a/Core/FileSystems/FileSystem.h +++ b/Core/FileSystems/FileSystem.h @@ -67,7 +67,8 @@ public: virtual u32 GetNewHandle() override { u32 res = handle_++; if (handle_ < 0) { - handle_ = 0; + // Some code assumes it'll never become 0. + handle_ = 1; } return res; } @@ -109,7 +110,7 @@ public: virtual void DoState(PointerWrap &p) = 0; virtual std::vector GetDirListing(std::string path) = 0; - virtual u32 OpenFile(std::string filename, FileAccess access, const char *devicename=nullptr) = 0; + virtual int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) = 0; virtual void CloseFile(u32 handle) = 0; virtual size_t ReadFile(u32 handle, u8 *pointer, s64 size) = 0; virtual size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) = 0; @@ -135,7 +136,7 @@ class EmptyFileSystem : public IFileSystem public: virtual void DoState(PointerWrap &p) override {} std::vector GetDirListing(std::string path) override {std::vector vec; return vec;} - u32 OpenFile(std::string filename, FileAccess access, const char *devicename=nullptr) override {return 0;} + int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override {return SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND;} void CloseFile(u32 handle) override {} size_t ReadFile(u32 handle, u8 *pointer, s64 size) override {return 0;} size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override {return 0;} diff --git a/Core/FileSystems/ISOFileSystem.cpp b/Core/FileSystems/ISOFileSystem.cpp index 4afa7e470e..39e54b8bb6 100644 --- a/Core/FileSystems/ISOFileSystem.cpp +++ b/Core/FileSystems/ISOFileSystem.cpp @@ -330,7 +330,7 @@ ISOFileSystem::TreeEntry *ISOFileSystem::GetFromPath(const std::string &path, bo } } -u32 ISOFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { +int ISOFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { OpenFileEntry entry; entry.isRawSector = false; entry.isBlockSectorMode = false; @@ -346,7 +346,7 @@ u32 ISOFileSystem::OpenFile(std::string filename, FileAccess access, const char parseLBN(filename, §orStart, &readSize); if (sectorStart > blockDevice->GetNumBlocks()) { WARN_LOG(FILESYS, "Unable to open raw sector, out of range: %s, sector %08x, max %08x", filename.c_str(), sectorStart, blockDevice->GetNumBlocks()); - return 0; + return SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND; } else if (sectorStart == blockDevice->GetNumBlocks()) { @@ -372,7 +372,7 @@ u32 ISOFileSystem::OpenFile(std::string filename, FileAccess access, const char // May return entireISO for "umd0:" entry.file = GetFromPath(filename); if (!entry.file){ - return 0; + return SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND; } if (entry.file == &entireISO) diff --git a/Core/FileSystems/ISOFileSystem.h b/Core/FileSystems/ISOFileSystem.h index 204615ea08..34b24bb081 100644 --- a/Core/FileSystems/ISOFileSystem.h +++ b/Core/FileSystems/ISOFileSystem.h @@ -33,7 +33,7 @@ public: void DoState(PointerWrap &p) override; std::vector GetDirListing(std::string path) override; - u32 OpenFile(std::string filename, FileAccess access, const char *devicename = NULL) override; + int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override; void CloseFile(u32 handle) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override; @@ -110,7 +110,7 @@ public: } std::vector GetDirListing(std::string path) override { return std::vector(); } - u32 OpenFile(std::string filename, FileAccess access, const char *devicename = NULL) override { + int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override { return isoFileSystem_->OpenFile("", access, devicename); } void CloseFile(u32 handle) override { diff --git a/Core/FileSystems/MetaFileSystem.cpp b/Core/FileSystems/MetaFileSystem.cpp index e85c514231..933f56f5b1 100644 --- a/Core/FileSystems/MetaFileSystem.cpp +++ b/Core/FileSystems/MetaFileSystem.cpp @@ -176,8 +176,9 @@ IFileSystem *MetaFileSystem::GetHandleOwner(u32 handle) return 0; } -bool MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpath, MountPoint **system) +int MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpath, MountPoint **system) { + int error = -1; std::lock_guard guard(lock); std::string realpath; @@ -216,7 +217,7 @@ bool MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpat //Attempt to emulate SCE_KERNEL_ERROR_NOCWD / 8002032C: may break things requiring fixes elsewhere if (inpath.find(':') == std::string::npos /* means path is relative */) { - lastOpenError = SCE_KERNEL_ERROR_NOCWD; + error = SCE_KERNEL_ERROR_NOCWD; WARN_LOG(FILESYS, "Path is relative, but current directory not set for thread %i. returning 8002032C(SCE_KERNEL_ERROR_NOCWD) instead.", currentThread); } } @@ -242,13 +243,13 @@ bool MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpat VERBOSE_LOG(FILESYS, "MapFilePath: mapped \"%s\" to prefix: \"%s\", path: \"%s\"", inpath.c_str(), fileSystems[i].prefix.c_str(), outpath.c_str()); - return true; + return 0; } } } DEBUG_LOG(FILESYS, "MapFilePath: failed mapping \"%s\", returning false", inpath.c_str()); - return false; + return error; } std::string MetaFileSystem::NormalizePrefix(std::string prefix) const { @@ -332,34 +333,16 @@ void MetaFileSystem::Shutdown() startingDirectory = ""; } -u32 MetaFileSystem::OpenWithError(int &error, std::string filename, FileAccess access, const char *devicename) +int MetaFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { std::lock_guard guard(lock); - u32 h = OpenFile(filename, access, devicename); - error = lastOpenError; - return h; -} - -u32 MetaFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) -{ - std::lock_guard guard(lock); - lastOpenError = 0; std::string of; MountPoint *mount; - if (MapFilePath(filename, of, &mount)) - { - s32 res = mount->system->OpenFile(of, access, mount->prefix.c_str()); - if (res < 0) - { - lastOpenError = res; - return 0; - } - return res; - } + int error = MapFilePath(filename, of, &mount); + if (error == 0) + return mount->system->OpenFile(of, access, mount->prefix.c_str()); else - { - return 0; - } + return error == -1 ? SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND : error; } PSPFileInfo MetaFileSystem::GetFileInfo(std::string filename) @@ -367,7 +350,7 @@ PSPFileInfo MetaFileSystem::GetFileInfo(std::string filename) std::lock_guard guard(lock); std::string of; IFileSystem *system; - if (MapFilePath(filename, of, &system)) + if (MapFilePath(filename, of, &system) == 0) { return system->GetFileInfo(of); } @@ -383,7 +366,7 @@ bool MetaFileSystem::GetHostPath(const std::string &inpath, std::string &outpath std::lock_guard guard(lock); std::string of; IFileSystem *system; - if (MapFilePath(inpath, of, &system)) { + if (MapFilePath(inpath, of, &system) == 0) { return system->GetHostPath(of, outpath); } else { return false; @@ -395,7 +378,7 @@ std::vector MetaFileSystem::GetDirListing(std::string path) std::lock_guard guard(lock); std::string of; IFileSystem *system; - if (MapFilePath(path, of, &system)) + if (MapFilePath(path, of, &system) == 0) { return system->GetDirListing(of); } @@ -423,7 +406,7 @@ int MetaFileSystem::ChDir(const std::string &dir) std::string of; MountPoint *mountPoint; - if (MapFilePath(dir, of, &mountPoint)) + if (MapFilePath(dir, of, &mountPoint) == 0) { currentDir[curThread] = mountPoint->prefix + of; return 0; @@ -452,7 +435,7 @@ bool MetaFileSystem::MkDir(const std::string &dirname) std::lock_guard guard(lock); std::string of; IFileSystem *system; - if (MapFilePath(dirname, of, &system)) + if (MapFilePath(dirname, of, &system) == 0) { return system->MkDir(of); } @@ -467,7 +450,7 @@ bool MetaFileSystem::RmDir(const std::string &dirname) std::lock_guard guard(lock); std::string of; IFileSystem *system; - if (MapFilePath(dirname, of, &system)) + if (MapFilePath(dirname, of, &system) == 0) { return system->RmDir(of); } @@ -484,7 +467,7 @@ int MetaFileSystem::RenameFile(const std::string &from, const std::string &to) std::string rf; IFileSystem *osystem; IFileSystem *rsystem = NULL; - if (MapFilePath(from, of, &osystem)) + if (MapFilePath(from, of, &osystem) == 0) { // If it's a relative path, it seems to always use from's filesystem. if (to.find(":/") != to.npos) @@ -514,7 +497,7 @@ bool MetaFileSystem::RemoveFile(const std::string &filename) std::lock_guard guard(lock); std::string of; IFileSystem *system; - if (MapFilePath(filename, of, &system)) + if (MapFilePath(filename, of, &system) == 0) { return system->RemoveFile(of); } @@ -601,10 +584,9 @@ size_t MetaFileSystem::SeekFile(u32 handle, s32 position, FileMove type) } int MetaFileSystem::ReadEntireFile(const std::string &filename, std::vector &data) { - int error = 0; - u32 handle = OpenWithError(error, filename, FILEACCESS_READ); - if (handle == 0) - return error; + int handle = OpenFile(filename, FILEACCESS_READ); + if (handle < 0) + return handle; size_t dataSize = (size_t)GetFileInfo(filename).size; data.resize(dataSize); @@ -622,7 +604,7 @@ u64 MetaFileSystem::FreeSpace(const std::string &path) std::lock_guard guard(lock); std::string of; IFileSystem *system; - if (MapFilePath(path, of, &system)) + if (MapFilePath(path, of, &system) == 0) return system->FreeSpace(of); else return 0; diff --git a/Core/FileSystems/MetaFileSystem.h b/Core/FileSystems/MetaFileSystem.h index c4fcee560a..cfc202b0d1 100644 --- a/Core/FileSystems/MetaFileSystem.h +++ b/Core/FileSystems/MetaFileSystem.h @@ -41,12 +41,13 @@ private: currentDir_t currentDir; std::string startingDirectory; - int lastOpenError; std::recursive_mutex lock; // must be recursive public: MetaFileSystem() { - current = 6; // what? + // This used to be 6, probably an attempt to replicate PSP handles. + // However, that's an artifact of using psplink anyway... + current = 1; } void Mount(std::string prefix, IFileSystem *system); @@ -63,7 +64,8 @@ public: u32 GetNewHandle() override { u32 res = current++; if (current < 0) { - current = 0; + // Some code assumes it'll never become 0. + current = 1; } return res; } @@ -72,16 +74,17 @@ public: void DoState(PointerWrap &p) override; IFileSystem *GetHandleOwner(u32 handle); - bool MapFilePath(const std::string &inpath, std::string &outpath, MountPoint **system); + int MapFilePath(const std::string &inpath, std::string &outpath, MountPoint **system); - inline bool MapFilePath(const std::string &_inpath, std::string &outpath, IFileSystem **system) { + inline int MapFilePath(const std::string &_inpath, std::string &outpath, IFileSystem **system) { MountPoint *mountPoint; - if (MapFilePath(_inpath, outpath, &mountPoint)) { + int error = MapFilePath(_inpath, outpath, &mountPoint); + if (error == 0) { *system = mountPoint->system; - return true; + return error; } - return false; + return error; } std::string NormalizePrefix(std::string prefix) const; @@ -90,8 +93,7 @@ public: bool GetHostPath(const std::string &inpath, std::string &outpath) override; std::vector GetDirListing(std::string path) override; - u32 OpenFile(std::string filename, FileAccess access, const char *devicename = NULL) override; - u32 OpenWithError(int &error, std::string filename, FileAccess access, const char *devicename = NULL); + int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override; void CloseFile(u32 handle) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override; diff --git a/Core/FileSystems/VirtualDiscFileSystem.cpp b/Core/FileSystems/VirtualDiscFileSystem.cpp index e76b5c4dee..7ff3dc07ed 100644 --- a/Core/FileSystems/VirtualDiscFileSystem.cpp +++ b/Core/FileSystems/VirtualDiscFileSystem.cpp @@ -321,7 +321,7 @@ int VirtualDiscFileSystem::getFileListIndex(u32 accessBlock, u32 accessSize, boo return -1; } -u32 VirtualDiscFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) +int VirtualDiscFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename) { OpenFileEntry entry; entry.curOffset = 0; @@ -396,7 +396,7 @@ u32 VirtualDiscFileSystem::OpenFile(std::string filename, FileAccess access, con ERROR_LOG(FILESYS, "VirtualDiscFileSystem::OpenFile: FAILED, access = %i", (int)access); #endif //wwwwaaaaahh!! - return 0; + return SCE_KERNEL_ERROR_ERRNO_FILE_NOT_FOUND; } else { u32 newHandle = hAlloc->GetNewHandle(); entries[newHandle] = entry; diff --git a/Core/FileSystems/VirtualDiscFileSystem.h b/Core/FileSystems/VirtualDiscFileSystem.h index e3699268ac..b4ad72924b 100644 --- a/Core/FileSystems/VirtualDiscFileSystem.h +++ b/Core/FileSystems/VirtualDiscFileSystem.h @@ -30,7 +30,7 @@ public: ~VirtualDiscFileSystem(); void DoState(PointerWrap &p) override; - u32 OpenFile(std::string filename, FileAccess access, const char *devicename=NULL) override; + int OpenFile(std::string filename, FileAccess access, const char *devicename = nullptr) override; size_t SeekFile(u32 handle, s32 position, FileMove type) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size) override; size_t ReadFile(u32 handle, u8 *pointer, s64 size, int &usec) override; diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index f933d88b04..3feb366a97 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -1425,10 +1425,12 @@ static FileNode *__IoOpen(int &error, const char* filename, int flags, int mode) PSPFileInfo info = pspFileSystem.GetFileInfo(filename); - u32 h = pspFileSystem.OpenWithError(error, filename, (FileAccess) access); - if (h == 0) { - return NULL; + int h = pspFileSystem.OpenFile(filename, (FileAccess)access); + if (h < 0) { + error = h; + return nullptr; } + error = 0; FileNode *f = new FileNode(); SceUID id = kernelObjects.Create(f); diff --git a/Core/HLE/scePsmf.cpp b/Core/HLE/scePsmf.cpp index c3a1bd2747..12782a02c1 100644 --- a/Core/HLE/scePsmf.cpp +++ b/Core/HLE/scePsmf.cpp @@ -1163,7 +1163,7 @@ static int scePsmfPlayerBreak(u32 psmfPlayer) } static int _PsmfPlayerFillRingbuffer(PsmfPlayer *psmfplayer) { - if (!psmfplayer->filehandle) + if (psmfplayer->filehandle <= 0) return -1; u8* buf = psmfplayer->tempbuf; int tempbufSize = (int)sizeof(psmfplayer->tempbuf); @@ -1207,7 +1207,7 @@ static int _PsmfPlayerSetPsmfOffset(u32 psmfPlayer, const char *filename, int of int delayUs = 1100; psmfplayer->filehandle = pspFileSystem.OpenFile(filename, (FileAccess) FILEACCESS_READ); - if (!psmfplayer->filehandle) { + if (psmfplayer->filehandle < 0) { return hleDelayResult(SCE_KERNEL_ERROR_ILLEGAL_ARGUMENT, "psmfplayer set", delayUs); } diff --git a/Core/PSPLoaders.cpp b/Core/PSPLoaders.cpp index b20bd8abd8..721d26d16e 100644 --- a/Core/PSPLoaders.cpp +++ b/Core/PSPLoaders.cpp @@ -221,7 +221,7 @@ bool Load_PSP_ISO(FileLoader *fileLoader, std::string *error_string) { bool hasEncrypted = false; u32 fd; - if ((fd = pspFileSystem.OpenFile(bootpath, FILEACCESS_READ)) != 0) + if ((fd = pspFileSystem.OpenFile(bootpath, FILEACCESS_READ)) >= 0) { u8 head[4]; pspFileSystem.ReadFile(fd, head, 4); diff --git a/Core/Util/GameManager.cpp b/Core/Util/GameManager.cpp index 7a5f08b732..d731de0476 100644 --- a/Core/Util/GameManager.cpp +++ b/Core/Util/GameManager.cpp @@ -413,10 +413,13 @@ std::string GameManager::GetISOGameID(FileLoader *loader) const { ISOFileSystem umd(&handles, bd); PSPFileInfo info = umd.GetFileInfo("/PSP_GAME/PARAM.SFO"); - int handle = 0; + int handle = -1; if (info.exists) { handle = umd.OpenFile("/PSP_GAME/PARAM.SFO", FILEACCESS_READ); } + if (handle < 0) { + return ""; + } std::string sfoData; sfoData.resize(info.size); diff --git a/UI/GameInfoCache.cpp b/UI/GameInfoCache.cpp index 8402eea6ee..117bb21c37 100644 --- a/UI/GameInfoCache.cpp +++ b/UI/GameInfoCache.cpp @@ -301,7 +301,7 @@ static bool ReadFileToString(IFileSystem *fs, const char *filename, std::string } int handle = fs->OpenFile(filename, FILEACCESS_READ); - if (!handle) { + if (handle < 0) { return false; }