libkernel: unlink of "file/" deletes the file on Windows, where FreeBSD fails with ENOTDIR; fix branch ready #5164
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by DavidSamir on 2026-10-13T13:21:29Z.
On Windows,
unlink("file/")andsceKernelUnlink("file/")delete the file. On FreeBSD a name with a trailing slash must be a directory:lookupfails withENOTDIRwhen the path ends in a slash and the result is not a directory, and the Linux build returnsENOTDIRand keeps the file. The same happens forfile//,file/.andfile/./.A program that removes "the directory entry
name/" expecting it to fail on anything that is not a directory loses the file instead.Cause.
sceKernelUnlinkpasses the resolved path, which keeps the trailing separator, to_wunlink. The Win32 delete accepts a separator after a file's name: on this machine_wunlink(L"a/")on a regular fileareturns 0 and the file is gone.file/.is the same path after the resolver normalizes it.Observed on
main5d50886ee, Windows 11 (10.0.26300), WinLibs GCC 15.2.0 r7, Release.fileis a regular file:mainon WindowssceKernelUnlink("file/")0x80020014(ENOTDIR), file keptunlink("file/")file//,file/.,file/./,dir/file/,dir/sub/../file/sceKernelUnlink("file/"), file has mode 04440x8002000D(EACCES)0x80020014sceKernelUnlink("file/"), file open through a descriptor0x8002000D0x80020014remove("file/")I have not found a title that stops on this. It came out of running one probe of the path functions on the Windows build and on the Linux build and comparing the two outputs.
Fix, ready to cherry-pick.
DavidSamir:fix/libkernel-unlink-trailing-slash-windows(91a1855b3, two commits onmain5d50886ee, two files, +21). I can't open it as a PR while #4532 is open (one open PR without a merged one).fix(libkernel): fail unlink of a file named with a trailing slash on Windows:Open.cpp.test(libkernel): unlink a file named with a trailing slash:guest_filesystem.Windows only, in
sceKernelUnlink, whichunlinkcalls. When the resolved path ends in a separator, the name without it is looked up, and if it exists and is not a directory the call returnsENOTDIRbefore anything is deleted. The check runs only for such paths, so an ordinaryunlinkmakes the same host calls as before. A directory named with a trailing slash still returnsEPERMand a missing nameENOENT, as onmain.Not changed, and still different from FreeBSD: a path that runs through a regular file (
file/x) givesENOENTon Windows where FreeBSD givesENOTDIR, inunlinkand in most other path functions; andopen,rename,truncate,utimesandlstatalso acceptfile/on Windows. I kept this change to the call that destroys data.guest_filesystemgains checks next to the existing unlink ones: for a file named with/,//,/.and/./,sceKernelUnlinkmust return0x80020014andunlinkmust fail with errno 20, and the file must keep its four bytes; a second file with a trailing slash must giveENOTDIRand still exist; a directory with a trailing slash must giveEPERMand a missing nameENOENT; and the plain name must then unlink.Checked on Windows (
91a1855b3onmain5d50886ee, Windows 11 10.0.26300, WinLibs GCC 15.2.0 r7, Release, full builds):Open.cppas onmainand the test kept,guest_filesystemfails (exit 0xc0000409,Filesystem check failed at line 715). With the fix it passes 5/5 (--repeat until-fail:5), andguest_kernel_fcntl,guest_truncate,guest_dup,guest_file_vector,file_streams,guest_standard_streams,guest_posix_filesystem,guest_fdopendir,guest_kernel_renameandguest_path_casepass 3/3.main's libraries, the branch's and on the Linux build:sceKernelUnlink,unlinkandremoveon each of 26 names (a file, a directory with contents, an empty directory and a missing name, each plain, with/, with/.and under..), printing the result and which of the files and directories are left; then a 0444 file and a file held open, each plain and with the slash. 34 lines change againstmain: the calls in the table and the files they no longer delete. Against the Linux build, every remaining difference is one of two kinds that are the same onmain:sceKernelUnlinkreturns thesceKernelerror without setting errno, and the threefile/xlines above.flock, 44 over pipe streams, 15 overfcntlstatus flags, 127 overfreopen, 130 over directory descriptors, 117 over streams used the other way, 144 over truncating opens, 313 overfdopenand 198 over paths that run through a regular file, run with both sets of libraries: the only lines that differ are the four in the last probe that unlinkfile/andfile/., and a file size in thefdopenprobe that changes from run to run with either set.main's libraries and 424 to 598 µs with the branch's; unlink of a missing name 270 to 332 µs and 272 to 320 µs (both include the call log the probe build prints). No difference I can separate from the spread.poll: POLLPRI is not supported by WSAPollin both (#4478).ctest --parallel 4: 1061 of 1061 pass, as withmain5d50886eebuilt without this change.ea57b4c1d): full build, andguest_filesystem,guest_kernel_fcntl,guest_truncate,guest_posix_filesystemandfile_streamspass 3/3.tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.py --branchreports no overlap with open pull requests.Checked on Linux (same commit, WSL2 Ubuntu 24.04, GCC 13.3.0, Release):
libsbuilds, andguest_filesystemandguest_kernel_fcntlpass 3/3, so the new checks match the existing Linux behaviour. The changed code is Windows only.Not checked on a console or with a commercial title.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T06:54:07Z.
Closing: no title is known to reach this, and functions are only changed when a title needs them. The catalog titles in the report run the same with and without the change. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.