From 6c2329eadfe3501b0c756ac7eb9a9c2d526dab22 Mon Sep 17 00:00:00 2001 From: Stephen Miller Date: Thu, 20 Feb 2025 17:57:31 -0600 Subject: [PATCH] Check if file exists before calling platform-specific code Bloodborne checks if a file doesn't exist using open, checking if it specifically failed with error code ENOENT. To avoid working with platform-specific errnos, add a proper error return for if the file doesn't exist. Fixes a regression in Bloodborne. --- src/core/libraries/kernel/file_system.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index 6c2397085..cefb2aa38 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -118,10 +118,11 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) { } else { file->m_guest_name = path; file->m_host_name = mnt->GetHostPath(file->m_guest_name); + bool exists = std::filesystem::exists(file->m_host_name); int e = 0; if (create) { - if (excl && std::filesystem::exists(file->m_host_name)) { + if (excl && exists) { // Error if file exists h->DeleteHandle(handle); *__Error() = POSIX_EEXIST; @@ -131,6 +132,13 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) { Common::FS::IOFile out(file->m_host_name, Common::FS::FileAccessMode::Write); } + if (!exists) { + // File to open doesn't exist, return ENOENT + h->DeleteHandle(handle); + *__Error() = POSIX_ENOENT; + return -1; + } + if (read) { // Read only e = file->f.Open(file->m_host_name, Common::FS::FileAccessMode::Read);