fix(libkernel): preserve directory identity across Windows renames #6228
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6228"
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 Ondra97 on 2026-10-15T05:30:31Z.
What
I reproduced a wrong-file read on main
d92a8dad390af1807cc91622b924252141816a5a: open a directory, duplicate its descriptor, close the original descriptor, rename the directory, then create a replacement at its old path.openat(dirfd, "marker", ...)reads the replacement's content andgetdents(dirfd, ...)lists the replacement's entries. Windows directory descriptors held aNULdescriptor and the original pathname. POSIX openat resolves relative to the directory associated with the descriptor.Directory descriptors now hold a real Windows directory handle with read/write/delete sharing. The CRT owns and duplicates that handle through the existing descriptor lifecycle, following the _open_osfhandle ownership contract. Cursor snapshots remain shared across aliases. Metadata uses the handle, and path-based operations and snapshot reloads query its current name through the existing native-path helper. Directory classification no longer depends on a pathname lookup succeeding.
The shared path helper normalizes Windows DOS/UNC prefixes for filesystem consumers and preserves native lookup errors.
fchdiralso verifies an equivalent root ancestor when Windows returns different pathname casing, then retains the virtual root's spelling for subsequent relative paths andgetcwd.Rebased onto main
11acfdd84e801a2eff6e76555df80a2fd1a68f95. The only manual conflict was the adjacent technical-debt entries: main'ssceKernelWriteThrottlingStatusnull-pointerEFAULTdescription is preserved together with the directory-identity changes. All 10 files retain the original 184 added and 33 removed lines; the source and regression-test changes are unchanged.Tested
Validation at head
739e451332fbe284b5395993f9189354774be326on main11acfdd84e801a2eff6e76555df80a2fd1a68f95.Windows (native host): Windows 11 Pro 10.0.26300, AMD Ryzen 9 7900X, 32 GB RAM, NVIDIA GeForce RTX 4070 Ti SUPER; WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, bundled dependencies, ccache. Graphics: not exercised.
cmake --build build_tools/b6228-739e --parallel 4).Linux (VirtualBox): Ubuntu 24.04.5 LTS, kernel 7.0.0-38-generic, VirtualBox 7.2.20 r175154 on the Windows host above, 4 vCPU, 8 GiB VM RAM; GCC 13.3.0, Ninja, Release, bundled dependencies, ext4. Graphics: not exercised.
relinker libs) and every selected test executable built successfully with two build jobs, including compilation of the graphics components.The same filter was used on both platforms; platform-specific tests account for the counts. Windows used
--parallel 2; Linux (VirtualBox) used the serial command below:The selection covers the directory identity regression, alias lifetime/cursor sharing, enumeration/rewind,
openat/mkdirat/unlinkat,fchdir, directory read errors, metadata after removal, vector and append I/O, close/truncate, and application archives. Conventions, whitespace and test-registration checks passed.Static review covered the original patch, upstream delta
ca82d7d882b0ac17d955f6e107fe2eb0cae244af..11acfdd84e801a2eff6e76555df80a2fd1a68f95, build/test inputs, and the complete rebased patch. Independent line comparison confirmed preservation of both the original changes and the upstream changes in the overlapping sources.Overlap review: #6302, #6525 and #6897 are complementary changes with textual conflicts; there is no functional dependency. A future combination must retain both the directory check and transfer lock in
NativeFtruncate, both independent test groups, and #6897's invalid-descriptor guard without restoring the pathname-based stat fallback. Combined runtime validation was not performed.Linux graphics/Vulkan tests: NOT RUN — intentionally excluded from VirtualBox validation. Native/bare-metal Linux was not tested. Native Linux GPU validation: not tested. Retail titles, SMB/UNC execution and removed-directory enumeration were not tested. Path-based
*atoperations and enumeration reloads remain non-atomic with a concurrent rename, as recorded in technical debt. The Windows ancestor-rename restriction reported in the PR cross-check remains unchanged. No title compatibility or performance claim.Windows symbolic-link success branches in
guest_kernel_sysreport links unavailable; those branches are not claimed as covered.Original negative controls before rebase
At main
d92a8dad390af1807cc91622b924252141816a5a, the public API probe read the replacement marker and listed the replacement entries after rename. With original fix64eae5ab55f7a9fa0fdd4f3d777de009dd48a370, it retained the original marker and entries. The expandedguest_kernel_sysfailed on main at the replacement-content assertion. Restoring only main'sGeneral.cppalso made the fixture fail atfchdirwith guest errno 45. These are historical controls, separate from the current-head validation above.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T06:43:27Z.
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/tests/GuestKernelSys.cppL112-113core/libs/prx/libkernel/File/src/NativeStat.cppL46docs/dev/debt/libkernel.mdL125Some 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/libc/src/General.cppcore/libs/prx/libkernel/File/src/NativeStat.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestKernelSys.cppcore/libs/prx/libc/src/General.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libc/src/General.cppcore/libs/prx/libkernel/File/src/NativeStat.cppcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/tests/GuestKernelSys.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/include/File.hppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdcore/libs/prx/libc/src/General.cppcore/libs/prx/libkernel/File/src/DirectoryDescriptor.cppcore/libs/prx/libkernel/File/src/NativeStat.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Stdio.cppcore/libs/prx/libkernel/File/src/Open.cppcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mdcore/libs/prx/libkernel/File/src/Stdio.cppdocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mddocs/dev/debt/libkernel.mdImported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-15T08:24:33Z.
Cross-check on Windows: #6228 head
64eae5ab5onmaind92a8dad3(fast-forward, no conflict).Host: Windows 11 Pro 26220, Ryzen 7 5700X, RTX 4070 (driver 596.21), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release.
Build: full build and
libsboth succeed, with no new warnings. The one warning in a touched file,General.cpp:426(u8pathis deprecated), ismain's unchanged line 410.Tests,
--repeat until-fail:3:guest_kernel_sysand 48 more file-system tests pass 3/3, 147 of 147 runs:guest_directory*andguest_file_lock_*tests;guest_fdopendir,guest_working_directory,guest_realpath,guest_path_case,guest_filesystem,guest_posix_filesystemandguest_kernel_rename;guest_dup,guest_kernel_fcntl,guest_fstatfs,guest_aio,guest_sendfileandguest_shm_open;guest_savedata_*anddownload_data_mount_*tests.guest_kernel_sysprintsdirectory marker after rename/replacement: o, expected o. Symbolic links are unavailable on this host (Developer Mode off), so those branches did not run.Negative control: the same test binary run with
main's libraries aborts at the replacement-content check:Suite,
ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip': 814 of 814 pass, including the 2 skipped.check_conventions.py --base origin/mainandgit diff --checkare clean.Titles. Catalog releases, relinked once with
main's relinker, so only the libraries differ. Each ran 60 s with the display on,app0/eboot.binstaged andHOMEunset.mainProspero Explorer opens every mount as a directory descriptor at startup, with the same lines from both builds:
The logged
open/statlines are the same for each title on both builds, and no error appears on this PR alone:/app0/assets/hui/../celeste/....kodi.loghas the same 14 error lines and 59Found addonlines, and both builds log the same 222 SQLite version-probecannot open filelines.One behaviour change, found with a small guest-API probe (
sceKernelOpenwithO_DIRECTORY, then rename and rmdir):mainA/Bas a directory, then renameAtoA2getdentson the descriptor lists only. ..0x80020005(EIO);getdentslists. .. fH/I/f, then renameH0x800200050x80020005With the real handle, Windows refuses to rename an ancestor of an open directory, as it already does for an open file. FreeBSD would allow the rename. This could be one sentence in the
Windows directory descriptorsdebt bullet.Verdict: confirmed. The stale-path read is fixed, the test fails on
mainand passes here, and there is no regression in the tests, the suite or the three file-I/O titles. The only new behaviour is that renaming an ancestor of an open directory descriptor now fails with EIO, as it already does for files.AI-assisted (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by screamm on 2026-10-17T14:06:42Z.
Rechecked on head
02371ec4a(rebased), scratch-merged ontomainc9e6c45de(clean, no conflict).Host: Windows 11 Pro 26220, Ryzen 7 5700X, RTX 4070 (driver 596.21), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release.
What changed since my run on
64eae5ab5. Comparing the PR's diff against its base (d92a8dad3..64eae5ab5vsca82d7d88..02371ec4a): the same 10 files, 184 insertions and 33 deletions (was 183 and 33). The source follows the rebase (Classifykeeps the newIsArchivedFilebranch, theftruncate/TransferIovecscontext), and the test gained one line,Require(sceKernelLseek(target, 0, 0) == 0);, before the read-error assertions. The two debt bullets the PR edits are unchanged. I did not see any new comment or review. My earlier remark is still open: renaming an ancestor of an open directory descriptor fails with EIO on Windows (probe below), and theWindows directory descriptorsbullet does not mention it.libssucceed (the old MinGWalignas(65536)failure is gone on current main). The one warning in a touched file,u8pathdeprecated inGeneral.cpp, exists onmaintoo.--repeat until-fail:3: 59 tests (guest_kernel_sysand the filesystem selection from the PR body, plus the other file-system tests): 177 of 177 runs pass.guest_kernel_sysprintsdirectory marker after rename/replacement: o, expected o; symbolic links are unavailable on this host (Developer Mode off), so those branches did not run.mainand the PR's test kept,guest_kernel_sysaborts at the replacement-content check; with the PR's sources it passes again.ctest -j8 --timeout 120 -E '^agc_driver_|^video_out_flip': 883 tests; 13 timed out in the first pass while other builds were running (theconventions_function_bodies*shards,check_main_sync,configure_seed,debt_split,hardware_oracle_compare,conventions_bom_shebang,tls_function_coverage*,guest_file_lock_process). All pass on serial reruns (conventions_function_bodies, at its 30 s limit, on the second rerun); 2 skipped as before.check_conventions.py --base origin/mainandgit diff origin/main --checkare clean.Probe with the guest API (
sceKernelOpenwithO_DIRECTORY, then rename and rmdir), same result as on64eae5ab5:mainA/Bas a directory, renameAtoA2getdentson the descriptor lists only. ..0x80020005(EIO),Astays,getdentslists. .. fH/I/f, renameH0x800200050x80020005Overlap.
b062366e5) conflicts with this PR inStdio.cpp, inNativeFtruncate, one hunk. Both lines are needed: this PR'sif (File::IsDirectoryDescriptor(descriptor)) return EINVAL;and #6302'sconst auto positioned = File::LockPositionedTransfer(descriptor);.557e777cb) and #6992 (03418d7c3) merge cleanly on top of this PR.Titles. Catalog releases relinked once, so only the libraries differ; "main" is the same tree with only this PR's source files reverted. Each ran 60 s with the display on; other builds were running on the host, so frame counts are only indicative.
I first looked for titles that rename a directory.
sceKernelRenamehas call sites in the executables of PPSA99002, PPSA99082, PPSA99109, PPSA99110 and PPSA99600,fchdironly in PPSA99764, and libcrenamein many. I logged rename and directory-open calls with a local diagnostic (removed afterwards) on 9 titles (RetroArch PPSA99169 60 s, the others 45 s). The only renames are log files: PPSA99600 renames/download0/debug.log.tmptodebug.log188 times, PPSA99002 and PPSA99008 rotate their logs to.prevnames. No title renamed a directory, so none reaches the path this PR fixes. Titles do open and list directories withO_DIRECTORYthrough the new handle (RetroArch, Prospero Explorer, OpenNOW).mainNo run has a stop line. For RetroArch the logs have the same 971
O_DIRECTORYopens and 1047 normalized file-system lines on both sides, with the same 2 error-like lines; PPSA99600 and Prospero Explorer have the same file-system lines on both sides and no error-like line.Not checked: Linux, symbolic-link branches, UNC paths, removed-directory enumeration, GPU tests.
Verdict: confirmed again. The test fails on
main's sources and passes here, nothing regresses in the suite or the four titles, and no local title exercises the fixed path.Written with Claude Code assistance (validation by a subagent, reviewed in this session).