Add locks to all the pspFileSystem methods.

This commit is contained in:
Unknown W. Brackets 2013-08-10 09:27:06 -07:00
parent 1b838c4403
commit b5ac31bbea
2 changed files with 23 additions and 1 deletions

View File

@ -162,6 +162,7 @@ static bool RealPath(const std::string &currentDirectory, const std::string &inP
IFileSystem *MetaFileSystem::GetHandleOwner(u32 handle)
{
lock_guard guard(lock);
for (size_t i = 0; i < fileSystems.size(); i++)
{
if (fileSystems[i].system->OwnsHandle(handle))
@ -174,6 +175,7 @@ IFileSystem *MetaFileSystem::GetHandleOwner(u32 handle)
extern u32 ioErrorCode;
bool MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpath, MountPoint **system)
{
lock_guard guard(lock);
std::string realpath;
// Special handling: host0:command.txt (as seen in Super Monkey Ball Adventures, for example)
@ -225,6 +227,7 @@ bool MetaFileSystem::MapFilePath(const std::string &_inpath, std::string &outpat
void MetaFileSystem::Mount(std::string prefix, IFileSystem *system)
{
lock_guard guard(lock);
MountPoint x;
x.prefix=prefix;
x.system=system;
@ -233,6 +236,7 @@ void MetaFileSystem::Mount(std::string prefix, IFileSystem *system)
void MetaFileSystem::Shutdown()
{
lock_guard guard(lock);
current = 6;
// Ownership is a bit convoluted. Let's just delete everything once.
@ -254,6 +258,7 @@ void MetaFileSystem::Shutdown()
u32 MetaFileSystem::OpenFile(std::string filename, FileAccess access, const char *devicename)
{
lock_guard guard(lock);
std::string of;
MountPoint *mount;
if (MapFilePath(filename, of, &mount))
@ -268,6 +273,7 @@ u32 MetaFileSystem::OpenFile(std::string filename, FileAccess access, const char
PSPFileInfo MetaFileSystem::GetFileInfo(std::string filename)
{
lock_guard guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(filename, of, &system))
@ -283,6 +289,7 @@ PSPFileInfo MetaFileSystem::GetFileInfo(std::string filename)
bool MetaFileSystem::GetHostPath(const std::string &inpath, std::string &outpath)
{
lock_guard guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(inpath, of, &system)) {
@ -294,6 +301,7 @@ bool MetaFileSystem::GetHostPath(const std::string &inpath, std::string &outpath
std::vector<PSPFileInfo> MetaFileSystem::GetDirListing(std::string path)
{
lock_guard guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(path, of, &system))
@ -309,11 +317,13 @@ std::vector<PSPFileInfo> MetaFileSystem::GetDirListing(std::string path)
void MetaFileSystem::ThreadEnded(int threadID)
{
lock_guard guard(lock);
currentDir.erase(threadID);
}
int MetaFileSystem::ChDir(const std::string &dir)
{
lock_guard guard(lock);
// Retain the old path and fail if the arg is 1023 bytes or longer.
if (dir.size() >= 1023)
return SCE_KERNEL_ERROR_NAMETOOLONG;
@ -348,6 +358,7 @@ int MetaFileSystem::ChDir(const std::string &dir)
bool MetaFileSystem::MkDir(const std::string &dirname)
{
lock_guard guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(dirname, of, &system))
@ -362,6 +373,7 @@ bool MetaFileSystem::MkDir(const std::string &dirname)
bool MetaFileSystem::RmDir(const std::string &dirname)
{
lock_guard guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(dirname, of, &system))
@ -376,6 +388,7 @@ bool MetaFileSystem::RmDir(const std::string &dirname)
int MetaFileSystem::RenameFile(const std::string &from, const std::string &to)
{
lock_guard guard(lock);
std::string of;
std::string rf;
IFileSystem *osystem;
@ -407,6 +420,7 @@ int MetaFileSystem::RenameFile(const std::string &from, const std::string &to)
bool MetaFileSystem::RemoveFile(const std::string &filename)
{
lock_guard guard(lock);
std::string of;
IFileSystem *system;
if (MapFilePath(filename, of, &system))
@ -421,6 +435,7 @@ bool MetaFileSystem::RemoveFile(const std::string &filename)
void MetaFileSystem::CloseFile(u32 handle)
{
lock_guard guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
sys->CloseFile(handle);
@ -428,6 +443,7 @@ void MetaFileSystem::CloseFile(u32 handle)
size_t MetaFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size)
{
lock_guard guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->ReadFile(handle,pointer,size);
@ -437,6 +453,7 @@ size_t MetaFileSystem::ReadFile(u32 handle, u8 *pointer, s64 size)
size_t MetaFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size)
{
lock_guard guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->WriteFile(handle,pointer,size);
@ -446,6 +463,7 @@ size_t MetaFileSystem::WriteFile(u32 handle, const u8 *pointer, s64 size)
size_t MetaFileSystem::SeekFile(u32 handle, s32 position, FileMove type)
{
lock_guard guard(lock);
IFileSystem *sys = GetHandleOwner(handle);
if (sys)
return sys->SeekFile(handle,position,type);
@ -455,6 +473,7 @@ size_t MetaFileSystem::SeekFile(u32 handle, s32 position, FileMove type)
void MetaFileSystem::DoState(PointerWrap &p)
{
lock_guard guard(lock);
p.Do(current);
// Save/load per-thread current directory map

View File

@ -17,7 +17,8 @@
#pragma once
#include "FileSystem.h"
#include "native/base/mutex.h"
#include "Core/FileSystems/FileSystem.h"
class MetaFileSystem : public IHandleAllocator, public IFileSystem
{
@ -34,6 +35,7 @@ private:
currentDir_t currentDir;
std::string startingDirectory;
recursive_mutex lock;
public:
MetaFileSystem()
@ -94,6 +96,7 @@ public:
// TODO: void IoCtl(...)
void SetStartingDirectory(const std::string &dir) {
lock_guard guard(lock);
startingDirectory = dir;
}
};