fix(libkernel): fail chflags through a dangling Windows symbolic link with ENOENT #9469

Merged
Gruzzberry merged 2 commits from upstream-pr/9469 into main 2026-10-25 23:13:51 +00:00
Gruzzberry commented 2026-10-21 22:52:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-21T22:52:47Z.


What

On Windows, chflags succeeded on a symbolic link whose target is missing and failed dangling/ with ENOTDIR. FreeBSD 11.4's kern_chflagsat looks the path up with FOLLOW, so both fail with ENOENT.

The cause is the lookup in LookupError: under MinGW, std::filesystem::status does not follow a Windows symbolic link and reports a dangling link as an existing regular file. When the last component (or the one before a trailing slash) is a reparse point, the lookup now goes through the target with File::TryFillFileStat, the guest stat, which already follows links: a missing target gives ENOENT, a link to a file followed by a slash gives ENOTDIR, a link to a directory is accepted. Linux is unchanged; chflags is the only caller of LookupError.

Measured on main with a standalone probe, the same dangling link: stat, truncate, utimes and open already fail with ENOENT; chflags returned 0.

Tested

Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, -DBUILD_TESTING=ON, on main 938812df1 (rebased; since #9109, chflags("dangling/") fails with ENOTDIR from the trailing-slash check before this lookup runs, so that check was dropped from the test; FreeBSD gives ENOENT there), Developer Mode on so links can be created.

  • guest_filesystem: new checks on a dangling link (ENOENT) and a link to a file (0, ENOTDIR with a trailing slash, EOPNOTSUPP for an unknown flag), then both links are removed with unlink. On main the test fails at the first new check (chflags on the dangling link returns 0); with this PR it passes. Without link permission the link checks are skipped with a message.
  • guest_kernel_sys: passes.
  • Full suite on main 938812df1 and on main with #9442, #9469, #9474, #9487, #9496, #9661 and #9682 merged together, same machine: 2029 tests each; on both, the 3 agc_driver_sample_order* tests fail and agc_driver_image_array_window_past_layer_limit is not built (its 64 KiB alignas is rejected by this MinGW toolchain). In the parallel run (ctest -j 12) one other test failed on the merged branch (guest_memory in one run, guest_kqueue in another, agc_driver_shutdown_threads_queued_prebuilds in both); each passes alone, three runs out of three.
  • python tools/check_conventions.py --base upstream/main: passes.
  • Not tested: Linux (the change is Windows only; the new checks use std::filesystem::create_symlink there), a console, a title run.

#9442 (lchflags) is independent of this PR; its dangling-link check passes with or without it.

Overlaps

  • tools/pr_overlap.py --branch on the rebased head lists no direct overlap; of the 12 pull requests it could not compare, none changes LookupError or chflags. #9423 edits the start of chflags_nid_postfix, not LookupError.
  • #6044 moves GuestFilesystem.cpp to tests/files/; if it lands first, the new cases move with the file in the rebase.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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); no silent stubs added
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source: none added
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4959432856 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9469). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-21T22:52:47Z. --- ### What On Windows, `chflags` succeeded on a symbolic link whose target is missing and failed `dangling/` with `ENOTDIR`. FreeBSD 11.4's [`kern_chflagsat`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/kern/vfs_syscalls.c#L2366-L2380) looks the path up with `FOLLOW`, so both fail with `ENOENT`. The cause is the lookup in `LookupError`: under MinGW, `std::filesystem::status` does not follow a Windows symbolic link and reports a dangling link as an existing regular file. When the last component (or the one before a trailing slash) is a reparse point, the lookup now goes through the target with `File::TryFillFileStat`, the guest `stat`, which already follows links: a missing target gives `ENOENT`, a link to a file followed by a slash gives `ENOTDIR`, a link to a directory is accepted. Linux is unchanged; `chflags` is the only caller of `LookupError`. Measured on `main` with a standalone probe, the same dangling link: `stat`, `truncate`, `utimes` and `open` already fail with `ENOENT`; `chflags` returned 0. ### Tested Windows 11 (10.0.26200), WinLibs MinGW-w64 GCC 15.2.0 r7, Ninja, Release, `-DBUILD_TESTING=ON`, on `main` 938812df1 (rebased; since #9109, `chflags("dangling/")` fails with `ENOTDIR` from the trailing-slash check before this lookup runs, so that check was dropped from the test; FreeBSD gives `ENOENT` there), Developer Mode on so links can be created. - `guest_filesystem`: new checks on a dangling link (`ENOENT`) and a link to a file (0, `ENOTDIR` with a trailing slash, `EOPNOTSUPP` for an unknown flag), then both links are removed with `unlink`. On `main` the test fails at the first new check (`chflags` on the dangling link returns 0); with this PR it passes. Without link permission the link checks are skipped with a message. - `guest_kernel_sys`: passes. - Full suite on `main` 938812df1 and on `main` with #9442, #9469, #9474, #9487, #9496, #9661 and #9682 merged together, same machine: 2029 tests each; on both, the 3 `agc_driver_sample_order*` tests fail and `agc_driver_image_array_window_past_layer_limit` is not built (its 64 KiB `alignas` is rejected by this MinGW toolchain). In the parallel run (`ctest -j 12`) one other test failed on the merged branch (`guest_memory` in one run, `guest_kqueue` in another, `agc_driver_shutdown_threads_queued_prebuilds` in both); each passes alone, three runs out of three. - `python tools/check_conventions.py --base upstream/main`: passes. - Not tested: Linux (the change is Windows only; the new checks use `std::filesystem::create_symlink` there), a console, a title run. #9442 (`lchflags`) is independent of this PR; its dangling-link check passes with or without it. ### Overlaps - `tools/pr_overlap.py --branch` on the rebased head lists no direct overlap; of the 12 pull requests it could not compare, none changes `LookupError` or `chflags`. #9423 edits the start of `chflags_nid_postfix`, not `LookupError`. - #6044 moves `GuestFilesystem.cpp` to `tests/files/`; if it lands first, the new cases move with the file in the rebase. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [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`); no silent stubs added - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source: none added - [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 AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-21 23:06:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T23:06:24Z.

Review: APPROVED


Reviewed the Windows-only lookup path and focused symlink tests. For reparse-point inputs the change follows the target through the existing guest stat helper, preserving ENOENT for a dangling target and checking directory type for trailing separators; the non-reparse path is unchanged. The debt note and limitations are explicit. Conventions, intake, eligibility, labels, and report pass; hosted Windows/Linux build and test jobs were skipped. The Windows 11 focused runs described in the PR are author-reported; I did not run them locally.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5607315841 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9469#pullrequestreview-5607315841). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T23:06:24Z. **Review:** APPROVED --- Reviewed the Windows-only lookup path and focused symlink tests. For reparse-point inputs the change follows the target through the existing guest stat helper, preserving `ENOENT` for a dangling target and checking directory type for trailing separators; the non-reparse path is unchanged. The debt note and limitations are explicit. Conventions, intake, eligibility, labels, and report pass; hosted Windows/Linux build and test jobs were skipped. The Windows 11 focused runs described in the PR are author-reported; I did not run them locally.
Gruzzberry commented 2026-10-21 23:14:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-21T23:14:06Z.


Full suite with this PR merged together with #9442, #9469, #9474 and #9487, against main on the same Windows 11 machine (MinGW-w64 GCC 15.2.0 r7, Release): 1875 tests, the same results except agc_import_settle_first_use, which also skips on main when its copies finish before the import returns (5 of 5 runs).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328658232 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9469#issuecomment-6328658232). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-21T23:14:06Z. --- Full suite with this PR merged together with #9442, #9469, #9474 and #9487, against `main` on the same Windows 11 machine (MinGW-w64 GCC 15.2.0 r7, Release): 1875 tests, the same results except `agc_import_settle_first_use`, which also skips on `main` when its copies finish before the import returns (5 of 5 runs).
MarcZX10 commented 2026-10-22 04:33:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-22T04:33:08Z.

Review: DISMISSED


The Windows-only path and focused symlink cases were reviewed previously, and the reported combined Windows run is useful. The tested commit and the current branch base are still 47 upstream commits behind current main (now 110a18ba01); the reported baseline is a6dcea927. Please rebase/update onto current main and rerun the focused guest_filesystem checks plus the relevant conventions and overlap checks on that base before treating the earlier results as current. I checked the overlap bot warnings: the listed Stdio.cpp PRs touch other areas, and #6044 does not list GuestFilesystem.cpp, so I found no direct conflict in those warnings. No local test was run for this follow-up.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5609294896 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9469#pullrequestreview-5609294896). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-22T04:33:08Z. **Review:** DISMISSED --- The Windows-only path and focused symlink cases were reviewed previously, and the reported combined Windows run is useful. The tested commit and the current branch base are still 47 upstream commits behind current main (now 110a18ba01); the reported baseline is a6dcea927. Please rebase/update onto current main and rerun the focused `guest_filesystem` checks plus the relevant conventions and overlap checks on that base before treating the earlier results as current. I checked the overlap bot warnings: the listed Stdio.cpp PRs touch other areas, and #6044 does not list GuestFilesystem.cpp, so I found no direct conflict in those warnings. No local test was run for this follow-up.
Gruzzberry commented 2026-10-22 06:49:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T06:49:01Z.


Rebased onto main d6eafa54d0. guest_filesystem and guest_kernel_sys pass on the new head, the new checks fail on that main without the change, and check_conventions.py passes. Full suite on main d6eafa54d0 and on main with #9442, #9469, #9474, #9487 and #9496 merged together: 1890 tests each, identical results. The overlap scan of the rebased head and a manual check of the pull requests it could not compare are in the description under Overlaps.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6334630574 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9469#issuecomment-6334630574). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T06:49:01Z. --- Rebased onto `main` d6eafa54d0. `guest_filesystem` and `guest_kernel_sys` pass on the new head, the new checks fail on that `main` without the change, and `check_conventions.py` passes. Full suite on `main` d6eafa54d0 and on `main` with #9442, #9469, #9474, #9487 and #9496 merged together: 1890 tests each, identical results. The overlap scan of the rebased head and a manual check of the pull requests it could not compare are in the description under Overlaps.
Gruzzberry commented 2026-10-22 11:40:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gruzzberry on 2026-10-22T11:40:55Z.


Holding this as a draft, following the direction on #5239: the open queue is above 700 and no named title needs this change on current main. I will only mark it ready again with a current-main title ID, its Game bring-up discussion and the log line where it stops on this, or once the queue is below 700. Thanks for the reviews so far; the requested fixes are being made on the branch in the meantime.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6339855445 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9469#issuecomment-6339855445). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T11:40:55Z. --- Holding this as a draft, following the direction on #5239: the open queue is above 700 and no named title needs this change on current `main`. I will only mark it ready again with a current-main title ID, its Game bring-up discussion and the log line where it stops on this, or once the queue is below 700. Thanks for the reviews so far; the requested fixes are being made on the branch in the meantime.
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!9469
No description provided.