From aeab525a7fc66bedbb449ac7e6986fc922d36e5b Mon Sep 17 00:00:00 2001 From: Stephen Miller <56742918+StevenMiller123@users.noreply.github.com> Date: Wed, 16 Jul 2025 04:30:20 -0500 Subject: [PATCH] Fix create flag handling in open (#3255) If the create flag is specified, but the file already exists, then the file should open successfully, regardless of permissions. This fixes a crash seen in Phantasy Star Online 2 New Genesis (CUSA29813) --- src/core/libraries/kernel/file_system.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index 76d1a3339..9dd70afc6 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -118,14 +118,16 @@ s32 PS4_SYSV_ABI open(const char* raw_path, s32 flags, u16 mode) { return -1; } - if (read_only) { - // Can't create files in a read only directory - h->DeleteHandle(handle); - *__Error() = POSIX_EROFS; - return -1; + if (!exists) { + if (read_only) { + // Can't create files in a read only directory + h->DeleteHandle(handle); + *__Error() = POSIX_EROFS; + return -1; + } + // Create a file if it doesn't exist + Common::FS::IOFile out(file->m_host_name, Common::FS::FileAccessMode::Write); } - // Create a file if it doesn't exist - Common::FS::IOFile out(file->m_host_name, Common::FS::FileAccessMode::Write); } else if (!exists) { // If we're not creating a file, and it doesn't exist, return ENOENT h->DeleteHandle(handle);