fix(libkernel): report ENAMETOOLONG and ELOOP from open, unlink and stat #6648
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6648"
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 NevesHenry on 2026-10-16T01:44:20Z.
What
SceErrorFromErrnoinFile/src/Open.cpppassed host errno values 1 to 34 through unchanged and turned every other value intoEIO. On Linux,ENAMETOOLONGis 36 andELOOPis 40, so both becameEIO(0x80020005). FreeBSD returnsENAMETOOLONG= 63 (0x8002003F) andELOOP= 62 (0x8002003E).sceKernelStatreturnedENOENTfor both, because a failedstd::filesystem::statusreads as "doesn't exist".sceKernelMkdiralready gets these right becauseStdio.cpphas its own copy of the mapping. The existing test shows the mismatch:sceKernelMkdiron a 300-character name returns 0x8002003F, andsceKernelOpenon the same path returns 0x80020005.Values on
mainand with this change (Linux; a 300-character leaf and a symlink that points to itself):mainsceKernelOpen(read, andO_CREAT), too-long nameopen, too-long namesceKernelUnlink/unlink, too-long namesceKernelStat/stat, too-long namesceKernelOpen/open, symlink loopsceKernelStat/stat, symlink loopsceKernelUnlink/unlink,loop/leafChange (
File/src/Open.cpp, 2 lines):SceErrorFromErrnostill passes 1 to 34 through. Other values now go throughFilesystemError(libc/include/FilesystemError.hpp), thestd::errcmapping thatResolvePathError_nid_no_patchalready uses for path errors. That maps name-too-long to 63, loop to 62 and not-empty to 66, and everything else toEIOas before. This affectssceKernelOpen,OpenInDirectory_nid_no_patch(openat),sceKernelUnlinkandSceIoErrorFromErrno.SceIoErrorFromErrnokeeps its ownEAGAIN,EDEADLK,EDQUOTandEOVERFLOWcases, and read, write and lseek can't fail with the three newly mapped values, so their results don't change.sceKernelStatreturnsENAMETOOLONGandELOOPwhen the status query fails with them. Other failures still returnENOENT. I kept this narrow so that host-only errors, such as an invalid-name error on Windows, don't start reaching titles.open,creat,unlinkandstatwrappers inStdio.cppconvert thesceKernel*results, so they get the same errno values.lstatandmkdiralready used the correct mapping.I didn't merge the two
SceErrorFromErrnocopies into one. That would mean editingStdio.cpp, which 11 open PRs change, and reusingFilesystemErroravoids adding a third copy of these values.Tested
Linux: WSL2, Ubuntu 22.04, glibc 2.35, GCC 13.4, Release. No title run.
guest_filesystem: the new checks are next to the existing 300-charactermkdircheck, inside its#ifndef _WIN32block (the symlinks and the long name are tested only off Windows). They cover each row of the table and end by removing the loop link withunlink.main: fails at the first new check (sceKernelOpenon the long name returns 0x80020005).sceKernelOpen/Unlink/Stat,open,unlink,stat,openatorfopen(guest_*,file_streams), run with-j86 times: 5 runs passed 50/50. In 1 runguest_kernel_fcntlaborted after 6.3 s while other builds were loading the machine. It passed alone and in the next 5 full runs. It only expects error codes below 35, so I don't think this change caused it.FilesystemErrorandSceKernelErrorwere already in scope inOpen.cpp. With MinGW's errno values,ENAMETOOLONG(38) andENOTEMPTY(41) now map to 63 and 66 instead ofEIO. That is untested.tools/check_conventions.py --base origin/mainpasses, andgit diff --checkis clean.Overlap:
tools/pr_overlap.pyneedsgit merge-tree --write-tree(git 2.38+), so I checked by hand withgit merge-treeagainst the open PRs that changeOpen.cpp,GuestFilesystem.cpporFilesystemError.hpp: #5831, #5835, #5938, #6132, #6228, #6234, #6484 and #6541. None of them changes this mapping, and this PR adds no conflicts. #5835 adds code above thestatuscall insceKernelStat, and the two merge cleanly.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T02:38:31Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/libs/prx/libkernel/File/src/Open.cppL362Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libkernel/File/src/Open.cppcore/libs/tests/GuestFilesystem.cppcore/libs/tests/GuestFilesystem.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Open.cppImported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-17T00:35:04Z.
Linux run of this head. Only the overlap bot has commented so far, so here is a second run on a different host.
Setup: head
c6aeb7002(merge-base withmain31cbb55d7),BUILD_TESTING=ON, Ninja, CachyOS (kernel 7.2.9), i9-11900K, GCC 16.2.1. Tests ran underenv -iwith onlyHOMEandPATHset. Each arm ranctest -V --no-tests=error -R '^guest_filesystem$'3 times.Open.cppas on31cbb55d7and the PR's test kept,guest_filesystemfails 3 of 3 (subprocess aborted). The last call logged before the abort issceKernelOpenon the 300-character name with flags 0, which is the first new check. The check's own failure message is not in the ctest log, so which check fired is inferred from that.mainate751dd205: clean merge, passes 3 of 3.tools/check_conventions.pypasses.mainhas since moved tof3263dfbf; it does not touch this PR's files and the PR still merges cleanly.By reading, the expected values match FreeBSD 11.4
errno.h:ELOOP62,ENAMETOOLONG63,ENOTEMPTY66.Not checked: Windows (the new checks are inside
#ifndef _WIN32, so the Windows open, unlink and stat paths for a name that is too long or a symlink loop are not tested), macOS, and PS5 hardware.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T01:40:13Z.
The new Windows repro in #6983 exposes a platform gap in the stat portion of this change: on Windows,
std::filesystem::statusdoes not return the loop error on this path, so execution reachesFillFileStatand the failing_wstat64throws an uncaughtstd::runtime_error. The added symlink-loop assertions are under#ifndef _WIN32, so this path is not exercised on Windows. Could you clarify whether you intend this PR to cover the self-referencing-linksceKernelStatcase? If not, I can keep the platform-specific follow-up separate and make the dependency explicit.Imported from boykopovar/AnyPS5. Originally posted by NevesHenry on 2026-10-17T02:00:45Z.
No, #6648 doesn't cover it. The abort is on main too (the control run in #6983 shows that), and the stat change here only handles the case where std::filesystem::status itself reports ENAMETOOLONG/ELOOP, which Windows doesn't reach for the self-link. Please go ahead with the follow-up as a separate PR; no ownership concern from me. The change here is the status error check just above the FillFileStat call in sceKernelStat, so it should merge with yours in either order.
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-18T16:44:29Z.
Windows run, since the description lists Windows as not built. Windows 11 26300, Ryzen AI 7 350, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. Build:main6efb7261bwith #6648, #7559, #7496, #7497 and #7498 merged together (each merge clean, built once).guest_filesystemandguest_kernel_fcntlpass 3 runs of 3.ENAMETOOLONGandELOOPchecks inGuestFilesystem.cppsit inside#ifndef _WIN32, so on Windows this covers the build and no regression in the existing checks, not the new error paths.AI-assisted
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T08:15:49Z.
Checked the
SceErrorFromErrnochange and thesceKernelStaterror check againstFilesystemError, and the newguest_filesystemchecks (they fail onmainat the firstsceKernelOpencheck, as the Linux revert run above also showed). Merging through the queue.