mirror of
https://github.com/izzy2lost/ppsspp.git
synced 2026-03-10 12:43:04 -07:00
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.
This commit is contained in:
@@ -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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<PSPFileInfo> MetaFileSystem::GetDirListing(std::string path)
|
||||
std::lock_guard<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<std::recursive_mutex> 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<u8> &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<std::recursive_mutex> 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;
|
||||
|
||||
Reference in New Issue
Block a user