fix(libkernel): support lstat on long Windows paths #7202

Merged
MarcZX10 merged 2 commits from upstream-pr/7202 into main 2026-11-01 06:19:38 +00:00
MarcZX10 commented 2026-10-17 16:12:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T16:12:24Z.


What

Prepare native Windows stat paths with the extended-length namespace before the lstat metadata calls. Add a Windows filesystem regression that creates a host file under a path longer than MAX_PATH, verifies guest lstat reports the regular file and its size through both ordinary and already-extended host aliases, and verifies missing long paths still report ENOENT.

Tested

  • Linux relinker-only build completed; all 187 registered CTest tests passed.
  • MinGW C++20 syntax checks passed for NativeStat.cpp and GuestFilesystem.cpp.
  • Windows runtime regression is included but could not be run in this Linux environment.
  • On rebased head 665e4cf540, git diff --check upstream/main...HEAD and python3 tools/check_conventions.py --base upstream/main --head HEAD pass. An independent MinGW syntax-only check passes for NativeStat.cpp; the GuestFilesystem.cpp attempt was blocked by the installed headers (_fflush_nolock and FILE_CS_FLAG_CASE_SENSITIVE_DIR are undeclared).
  • python3 tools/check_conventions.py --base upstream/main and git diff --check passed. pr_overlap.py reports shared files with #6897, #6992, #7111, #7196 and #7201; manual review found no duplicate long-path lstat implementation. #7196 handles sceKernelStat, #6992 handles symlink-loop errors, #7111 adds absolute-link support, and #7201 changes Apple-only timestamp fields. #7111 has merged; this branch is now rebased onto upstream/main at e7e3e9c1984c293f06bff08428b8c89b7b932ac2, preserving the compatible DoLstat change.

Checklist

  • Based on current main; no other open PR implements long-path lstat support
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Codex); author responsible.
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4901736972 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T16:12:24Z. --- ### What Prepare native Windows stat paths with the extended-length namespace before the `lstat` metadata calls. Add a Windows filesystem regression that creates a host file under a path longer than `MAX_PATH`, verifies guest `lstat` reports the regular file and its size through both ordinary and already-extended host aliases, and verifies missing long paths still report `ENOENT`. ### Tested - Linux relinker-only build completed; all 187 registered CTest tests passed. - MinGW C++20 syntax checks passed for `NativeStat.cpp` and `GuestFilesystem.cpp`. - Windows runtime regression is included but could not be run in this Linux environment. - On rebased head `665e4cf540`, `git diff --check upstream/main...HEAD` and `python3 tools/check_conventions.py --base upstream/main --head HEAD` pass. An independent MinGW syntax-only check passes for `NativeStat.cpp`; the `GuestFilesystem.cpp` attempt was blocked by the installed headers (`_fflush_nolock` and `FILE_CS_FLAG_CASE_SENSITIVE_DIR` are undeclared). - `python3 tools/check_conventions.py --base upstream/main` and `git diff --check` passed. `pr_overlap.py` reports shared files with #6897, #6992, #7111, #7196 and #7201; manual review found no duplicate long-path `lstat` implementation. #7196 handles `sceKernelStat`, #6992 handles symlink-loop errors, #7111 adds absolute-link support, and #7201 changes Apple-only timestamp fields. #7111 has merged; this branch is now rebased onto upstream/main at `e7e3e9c1984c293f06bff08428b8c89b7b932ac2`, preserving the compatible `DoLstat` change. ### Checklist - [x] Based on current `main`; no other open PR implements long-path `lstat` support - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Codex); author responsible.
oneandonlydean commented 2026-10-17 16:21:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T16:21:46Z.


Thanks, this looks good in review. One note on ordering: we plan to merge #7196 first. After it lands, this PR will need a small rebase. The only conflict is the test in core/libs/tests/GuestFilesystem.cpp; production code merges cleanly. We'll run full CI on the rebased head.

Non-blocking, for a later follow-up if you're interested: with #7187, #7196 and this PR there are now three copies of the \\?\ path-preparation helper. A single shared helper would keep them from drifting.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6236538656 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6236538656). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T16:21:46Z. --- Thanks, this looks good in review. One note on ordering: we plan to merge #7196 first. After it lands, this PR will need a small rebase. The only conflict is the test in `core/libs/tests/GuestFilesystem.cpp`; production code merges cleanly. We'll run full CI on the rebased head. Non-blocking, for a later follow-up if you're interested: with #7187, #7196 and this PR there are now three copies of the `\\?\` path-preparation helper. A single shared helper would keep them from drifting.
MarcZX10 commented 2026-10-17 16:57:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T16:57:19Z.


Yes, a shared helper is a useful follow-up. These three PRs have separate filesystem call sites, and keeping their current changes focused avoids adding cross-PR conflicts while their fixes are reviewed and rebased. After #7187, #7196 and #7202 land, I can map the common path-normalization rules and propose one internal helper with shared tests, preserving each call site’s existing error behavior.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6237120352 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6237120352). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T16:57:19Z. --- Yes, a shared helper is a useful follow-up. These three PRs have separate filesystem call sites, and keeping their current changes focused avoids adding cross-PR conflicts while their fixes are reviewed and rebased. After #7187, #7196 and #7202 land, I can map the common path-normalization rules and propose one internal helper with shared tests, preserving each call site’s existing error behavior.
MarcZX10 commented 2026-10-17 23:56:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T23:56:53Z.


Rebased onto current main bd5856170. The GuestFilesystem.cpp conflict came from #6992 adding its long-path stat coverage; I combined the cases so the Windows test now covers both stat and lstat through ordinary and already-extended paths, including missing-path errors. The long-path preparation and symlink-loop errno mapping are separate behaviors; #7111/#7273 change which reparse-point types lstat recognizes, while this change prepares the path used by those lookups. check_conventions.py --base upstream/main, git diff --check, and MinGW C++20 syntax checks of NativeStat.cpp and GuestFilesystem.cpp pass. Full CMake configuration could not run in this worktree because its SDL2 submodule is absent; no hosted checks have reported yet on the rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243422497 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6243422497). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T23:56:53Z. --- Rebased onto current main `bd5856170`. The `GuestFilesystem.cpp` conflict came from #6992 adding its long-path `stat` coverage; I combined the cases so the Windows test now covers both `stat` and `lstat` through ordinary and already-extended paths, including missing-path errors. The long-path preparation and symlink-loop errno mapping are separate behaviors; #7111/#7273 change which reparse-point types `lstat` recognizes, while this change prepares the path used by those lookups. `check_conventions.py --base upstream/main`, `git diff --check`, and MinGW C++20 syntax checks of `NativeStat.cpp` and `GuestFilesystem.cpp` pass. Full CMake configuration could not run in this worktree because its SDL2 submodule is absent; no hosted checks have reported yet on the rebased head.
MarcZX10 commented 2026-10-17 23:57:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-17T23:57:38Z.


CI update for rebased head 946c44103: eligibility, conventions, and report checks have passed. Windows and broader platform build/test jobs are skipped by the repository path filters, so the MinGW syntax checks remain the Windows compile evidence for this update.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6243429303 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6243429303). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-17T23:57:38Z. --- CI update for rebased head `946c44103`: eligibility, conventions, and report checks have passed. Windows and broader platform build/test jobs are skipped by the repository path filters, so the MinGW syntax checks remain the Windows compile evidence for this update.
Bonjourcestmatt commented 2026-10-18 05:43:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Bonjourcestmatt on 2026-10-18T05:43:33Z.


Independent Windows run, since the PR description says the Windows runtime regression could not be run on Linux.

Setup: Windows 11 (MinGW64, native), WinLibs GCC 15.2.0 UCRT, origin/main 66e71b63d with this PR head bbec884ce merged.

guest_filesystem (3 runs each) Result
main NativeStat.cpp + this PR's test fails every run: "Filesystem check failed at line 289 (guest errno 2, Win32 error 3)", the lstat_nid_postfix check on the path longer than MAX_PATH
this PR (code + test) passes every run
guest_posix_filesystem with this PR passes (3 runs)

So the new regression does fail without the NativeStat.cpp change on Windows and passes with it.

Not checked: the full non-GPU suite, Linux, macOS, and the stat/sceKernelStat paths (covered by other PRs).

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6246213123 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6246213123). Originally posted by [Bonjourcestmatt](https://github.com/Bonjourcestmatt) on 2026-10-18T05:43:33Z. --- Independent Windows run, since the PR description says the Windows runtime regression could not be run on Linux. Setup: Windows 11 (MinGW64, native), WinLibs GCC 15.2.0 UCRT, `origin/main` 66e71b63d with this PR head bbec884ce merged. | `guest_filesystem` (3 runs each) | Result | |---|---| | `main` NativeStat.cpp + this PR's test | fails every run: "Filesystem check failed at line 289 (guest errno 2, Win32 error 3)", the `lstat_nid_postfix` check on the path longer than MAX_PATH | | this PR (code + test) | passes every run | | `guest_posix_filesystem` with this PR | passes (3 runs) | So the new regression does fail without the `NativeStat.cpp` change on Windows and passes with it. Not checked: the full non-GPU suite, Linux, macOS, and the `stat`/`sceKernelStat` paths (covered by other PRs). Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-18 05:45:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T05:45:28Z.


Thanks for running the Windows regression independently. Your three repeated runs confirm that the long-path lstat case fails without the change and passes with it, and that guest_posix_filesystem remains green. I have added this platform validation to my review notes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6246227399 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6246227399). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T05:45:28Z. --- Thanks for running the Windows regression independently. Your three repeated runs confirm that the long-path `lstat` case fails without the change and passes with it, and that `guest_posix_filesystem` remains green. I have added this platform validation to my review notes.
MarcZX10 commented 2026-10-18 12:15:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T12:15:34Z.


Rebased onto current main at 0d078f75d and pushed 6b3486eed. I resolved the NativeStat.cpp conflict by keeping the current symlink and junction handling while passing the prepared extended path to each Windows API call. git diff --check upstream/main...HEAD and python3 tools/check_conventions.py --base upstream/main pass. I could not run the Windows-only path regression locally on this Linux host; the updated PR checks are pending.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6249797688 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6249797688). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T12:15:34Z. --- Rebased onto current `main` at `0d078f75d` and pushed `6b3486eed`. I resolved the `NativeStat.cpp` conflict by keeping the current symlink and junction handling while passing the prepared extended path to each Windows API call. `git diff --check upstream/main...HEAD` and `python3 tools/check_conventions.py --base upstream/main` pass. I could not run the Windows-only path regression locally on this Linux host; the updated PR checks are pending.
MarcZX10 commented 2026-10-18 12:44:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T12:44:44Z.


Rebased #7202 onto current main after #7196 merged; the branch now includes the additional long-path lstat changes and tests from NativeStat.cpp / GuestFilesystem.cpp. The updated commits retain MarcZX100 as author. git diff --check passes, and the local Linux configure/build completed. This checkout exposes no guest_filesystem target on Linux, so I could not rerun the Windows-only regression here. The independent Windows run above passed guest_filesystem 3/3 and guest_posix_filesystem 3/3 on the prior implementation; hosted checks are running for this rebased head.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250069384 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6250069384). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T12:44:44Z. --- Rebased #7202 onto current `main` after #7196 merged; the branch now includes the additional long-path `lstat` changes and tests from `NativeStat.cpp` / `GuestFilesystem.cpp`. The updated commits retain `MarcZX100` as author. `git diff --check` passes, and the local Linux configure/build completed. This checkout exposes no `guest_filesystem` target on Linux, so I could not rerun the Windows-only regression here. The independent Windows run above passed `guest_filesystem` 3/3 and `guest_posix_filesystem` 3/3 on the prior implementation; hosted checks are running for this rebased head.
MarcZX10 commented 2026-10-18 12:45:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-18T12:45:30Z.


Hosted checks for rebased head d815a192: eligibility, conventions, and report all pass. The Linux and Windows build jobs were skipped by path filtering for this Windows-only change. The independent Windows run above remains the runtime validation: guest_filesystem and guest_posix_filesystem each passed 3/3 after the implementation change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6250076354 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6250076354). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-18T12:45:30Z. --- Hosted checks for rebased head `d815a192`: eligibility, conventions, and report all pass. The Linux and Windows build jobs were skipped by path filtering for this Windows-only change. The independent Windows run above remains the runtime validation: `guest_filesystem` and `guest_posix_filesystem` each passed 3/3 after the implementation change.
ycbuzi commented 2026-10-20 15:57:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ycbuzi on 2026-10-20T15:57:35Z.


A heads-up from the #8534 side, since the overlap bot pairs the two: #8534 adds IsNameSurrogate(p, "lstat") to DoLstat, and when the two are merged git keeps that line on the raw path without a conflict marker. With this PR's long-path preparation everywhere else, a reparse point beyond MAX_PATH then throws std::system_error from that call (lstat: CreateFileW: The system cannot find the path specified). The fix is to pass prepared there and to Read/ReadJunction, which is what I measured passing on Windows (main 4036fab1b + this PR + #8534: guest_filesystem, guest_kernel_sys, guest_posix_filesystem, plus a long-path name-surrogate case in your long-path block). If this one lands first I'll do that rebase on #8534; if #8534 lands first, the same one-line change applies here. Details on #8534.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6295161988 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6295161988). Originally posted by [ycbuzi](https://github.com/ycbuzi) on 2026-10-20T15:57:35Z. --- A heads-up from the #8534 side, since the overlap bot pairs the two: #8534 adds `IsNameSurrogate(p, "lstat")` to `DoLstat`, and when the two are merged git keeps that line on the raw path without a conflict marker. With this PR's long-path preparation everywhere else, a reparse point beyond `MAX_PATH` then throws `std::system_error` from that call (`lstat: CreateFileW: The system cannot find the path specified`). The fix is to pass `prepared` there and to `Read`/`ReadJunction`, which is what I measured passing on Windows (`main` 4036fab1b + this PR + #8534: `guest_filesystem`, `guest_kernel_sys`, `guest_posix_filesystem`, plus a long-path name-surrogate case in your long-path block). If this one lands first I'll do that rebase on #8534; if #8534 lands first, the same one-line change applies here. Details on #8534.
MarcZX10 commented 2026-10-20 19:49:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T19:49:34Z.


Thanks, that composition issue is real. After #8534's IsNameSurrogate check is combined with #7202, it must receive the prepared extended path, and the subsequent Read/ReadJunction calls need that same path as well. I have not changed #7202 yet because IsNameSurrogate is introduced by #8534 and is not on this PR's base. If #8534 lands first, I will rebase #7202 and update all three calls with the prepared path; if #7202 lands first, please carry the preparation into #8534's DoLstat. The long-path name-surrogate case you measured is the right regression to keep in the combined change.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6299992491 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7202#issuecomment-6299992491). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T19:49:34Z. --- Thanks, that composition issue is real. After #8534's `IsNameSurrogate` check is combined with #7202, it must receive the prepared extended path, and the subsequent `Read`/`ReadJunction` calls need that same path as well. I have not changed #7202 yet because `IsNameSurrogate` is introduced by #8534 and is not on this PR's base. If #8534 lands first, I will rebase #7202 and update all three calls with the prepared path; if #7202 lands first, please carry the preparation into #8534's `DoLstat`. The long-path name-surrogate case you measured is the right regression to keep in the combined change.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!7202
No description provided.