diff --git a/Core/FileSystems/MetaFileSystem.cpp b/Core/FileSystems/MetaFileSystem.cpp index d1cb26a0a..9a16522e1 100644 --- a/Core/FileSystems/MetaFileSystem.cpp +++ b/Core/FileSystems/MetaFileSystem.cpp @@ -307,7 +307,7 @@ void MetaFileSystem::ThreadEnded(int threadID) currentDir.erase(threadID); } -void MetaFileSystem::ChDir(const std::string &dir) +int MetaFileSystem::ChDir(const std::string &dir) { int curThread = __KernelGetCurThread(); @@ -316,14 +316,24 @@ void MetaFileSystem::ChDir(const std::string &dir) if (MapFilePath(dir, of, &mountPoint)) { currentDir[curThread] = mountPoint->prefix + of; - //return true; + return 0; } else { - //TODO: PSP's sceIoChdir seems very forgiving, but does it always accept bad paths and what happens when it does? - WARN_LOG(HLE, "ChDir failed to map path \"%s\", saving as current directory anyway", dir.c_str()); - currentDir[curThread] = dir; - //return false; + for (size_t i = 0; i < fileSystems.size(); i++) + { + const std::string &prefix = fileSystems[i].prefix; + if (strncasecmp(prefix.c_str(), dir.c_str(), prefix.size()) == 0) + { + // The PSP is completely happy with invalid current dirs as long as they have a valid device. + WARN_LOG(HLE, "ChDir failed to map path \"%s\", saving as current directory anyway", dir.c_str()); + currentDir[curThread] = dir; + return 0; + } + } + + WARN_LOG(HLE, "ChDir failed to map device for \"%s\", failing", dir.c_str()); + return SCE_KERNEL_ERROR_NODEV; } } diff --git a/Core/FileSystems/MetaFileSystem.h b/Core/FileSystems/MetaFileSystem.h index b6bd5d995..d6c5a6808 100644 --- a/Core/FileSystems/MetaFileSystem.h +++ b/Core/FileSystems/MetaFileSystem.h @@ -84,7 +84,7 @@ public: return SeekFile(handle, 0, FILEMOVE_CURRENT); } - virtual void ChDir(const std::string &dir); + virtual int ChDir(const std::string &dir); virtual bool MkDir(const std::string &dirname); virtual bool RmDir(const std::string &dirname); diff --git a/Core/HLE/sceIo.cpp b/Core/HLE/sceIo.cpp index 130df94e1..3b80ac6ba 100644 --- a/Core/HLE/sceIo.cpp +++ b/Core/HLE/sceIo.cpp @@ -1149,8 +1149,7 @@ u32 sceIoRename(const char *from, const char *to) { u32 sceIoChdir(const char *dirname) { DEBUG_LOG(HLE, "sceIoChdir(%s)", dirname); - pspFileSystem.ChDir(dirname); - return 0; + return pspFileSystem.ChDir(dirname); } int sceIoChangeAsyncPriority(int id, int priority)