fix(libkernel): open directories whose host path ends in a separator on Windows #4513
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4513"
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 winstrex on 2026-10-12T14:00:48Z.
What
On Windows,
sceKernelOpenwithO_DIRECTORYfails with0x80020002(ENOENT) on an existing directory when the resolved host path ends in a separator. That covers the guest root/,.,<dir>/and<dir>/... Only<dir>without a trailing separator opens.Found with The Pathless (PPSA01825). At boot, Unreal calls
sceKernelOpen("/app0/..", O_DIRECTORY)to list the parent of the content root. On Windows the call returned ENOENT andgetdentswas never reached:Cause: in
OpenNative(core/libs/prx/libkernel/File/src/Open.cpp), the CRT_wopenfails on a path ending in\with ENOENT, and the fallback toFile::OpenDirectoryDescriptoronly runs whenerrno != ENOENT. A directory whose host path ends in a separator never reaches it.Fix: when the host path has no filename, the fallback runs regardless of the errno. Trailing separators are stripped with the same loop
sceKernelMkdiruses since #2819 (while (!path.has_filename() && path.has_relative_path()) path = path.parent_path()), so a host drive root such asC:\is kept as is. The directory descriptor is then opened on the stripped path. A missing path without a trailing separator still returns ENOENT without an extrastat, and theEEXIST/EISDIRchecks are unchanged. Linux is unaffected becauseopen(2)accepts a trailing slash on a directory.This follows the earlier trailing-separator fixes in libkernel: #2743/#2819 (
sceKernelMkdir) and #2300 (sceKernelStat).Tested
Windows 11, WinLibs GCC 15.2.
guest_filesystemnow opens/,.,<dir>/and<dir>/..withO_DIRECTORYand callssceKernelGetdentsuntil it returns 0. Without the change inOpen.cppthe test fails at the first open (guest errno 2); with it, it passes.ctest -R "guest_|file|kernel": 346 tests passed.open("/app0/..", O_DIRECTORY)now returns a descriptor and the listing completes (getdentsreturns 88 bytes, then 0). The title still stops right after it, in the same place as before:Project file not found: ../../../Pathless/Pathless.uproject, thenPS5 Out of Memory/LowLevelFatalError ... Ran out of memory allocating 5565054976 bytes. That stop has a different cause and is not addressed here: it is the PlayGo chunk enumeration described for Sifu on #3209 and #3238 (the dump has no chunk table, the title queries ever-increasing chunk ids, and the request size is the same).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-12T16:31:33Z.
Windows test: head
a47178b86merged onto currentmaind592d54e1(clean merge, no conflicts). Windows 10, MinGW GCC (WinLibs), Ninja Release,-j2: full build 0 errors; ctest with the filterguest_filesystem: guest_filesystem passed (1 test(s), 0 failed);python tools/check_conventions.py --base upstream/mainpassed. I did not run the new tests againstmainwithout the change.AI-assisted (Claude Code).