From ab94de0eb6b77ae3f870f97b70d7ac8d466e5fd4 Mon Sep 17 00:00:00 2001 From: Henrique Reis Neves <39978017+NevesHenry@users.noreply.github.com> Date: Tue, 20 Oct 2026 08:52:06 -0300 Subject: [PATCH] kernel: return ENOENT from unlink when the file does not exist (#5393) posix_unlink never checked that the path exists. For a missing file it opened the host path, the open failed, IOFile::Unlink returned early because the file was not open, and the call still returned 0. On the console unlink(2) fails with ENOENT, so sceKernelUnlink should return 0x80020002. Check the path with MntPoints::Exists first, as posix_truncate already does. Also check for a null path before calling strlen on it, and report EFAULT like the other path functions in this file instead of crashing. --- src/core/libraries/kernel/file_system.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/libraries/kernel/file_system.cpp b/src/core/libraries/kernel/file_system.cpp index 6c50248b4..253a3a0fa 100644 --- a/src/core/libraries/kernel/file_system.cpp +++ b/src/core/libraries/kernel/file_system.cpp @@ -1648,18 +1648,23 @@ s64 PS4_SYSV_ABI sceKernelPwritev(s32 fd, const OrbisKernelIovec* iov, s32 iovcn } s32 PS4_SYSV_ABI posix_unlink(const char* path) { - if (strlen(path) > 255) { - *__Error() = POSIX_ENAMETOOLONG; + if (path == nullptr) { + *__Error() = POSIX_EFAULT; return -1; } - if (path == nullptr) { - *__Error() = POSIX_EINVAL; + if (strlen(path) > 255) { + *__Error() = POSIX_ENAMETOOLONG; return -1; } auto* h = Common::Singleton::Instance(); auto* mnt = Common::Singleton::Instance(); + if (!mnt->Exists(path)) { + *__Error() = POSIX_ENOENT; + return -1; + } + bool ro = false; const auto host_path = mnt->GetHostPath(path, &ro); if (host_path.empty()) {