fix(libkernel): report Windows directory junctions #7273

Merged
mazen320 merged 7 commits from upstream-pr/7273 into main 2026-10-18 09:22:55 +00:00
mazen320 commented 2026-10-17 21:06:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-17T21:06:16Z.


What

lstat and readlink abort on a Windows directory junction. A junction is a directory reparse point, not a symbolic link, so the existing reader rejects it and NotImplemented ends the process. stat already follows the junction.

A directory junction is now reported like a symbolic link when the name left after removing a \??\ or \\?\ prefix is a drive path (X:\...). lstat uses symlink mode and the target length. readlink returns the print name when that is a drive path, and otherwise the substitute name, with / separators. A mounted volume uses the same reparse tag, but its substitute name is \??\Volume{GUID}\, so it still throws.

This builds on #7111. The junction reader uses that pull request's TextAt and WithoutNtPrefix. TextAt takes the start of the path buffer, because a mount point has no Flags field.

Tested

  • guest_filesystem and guest_kernel_sys on Windows, GCC 15.2, after creating a junction with mklink /J. lstat reports a symlink, stat follows it to the directory, and readlink names that directory. The filesystem test passes a relative mklink target; the substitute name is the drive path that is returned. guest_kernel_sys removes the junction and the target.
  • python tools/check_conventions.py --base upstream/main

Checklist

  • One topic. One bug, one fix.
  • Tests cover the change.
  • python tools/check_conventions.py --base upstream/main passes.
  • Docs updated where behavior changed.

Depends on: #7111
Unblocks: none
GPUs tested: n/a
AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4903928889 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7273). Originally posted by [mazen320](https://github.com/mazen320) on 2026-10-17T21:06:16Z. --- ### What `lstat` and `readlink` abort on a Windows directory junction. A junction is a directory reparse point, not a symbolic link, so the existing reader rejects it and `NotImplemented` ends the process. `stat` already follows the junction. A directory junction is now reported like a symbolic link when the name left after removing a `\??\` or `\\?\` prefix is a drive path (`X:\...`). `lstat` uses symlink mode and the target length. `readlink` returns the print name when that is a drive path, and otherwise the substitute name, with `/` separators. A mounted volume uses the same reparse tag, but its substitute name is `\??\Volume{GUID}\`, so it still throws. This builds on #7111. The junction reader uses that pull request's `TextAt` and `WithoutNtPrefix`. `TextAt` takes the start of the path buffer, because a mount point has no Flags field. ### Tested - `guest_filesystem` and `guest_kernel_sys` on Windows, GCC 15.2, after creating a junction with `mklink /J`. `lstat` reports a symlink, `stat` follows it to the directory, and `readlink` names that directory. The filesystem test passes a relative `mklink` target; the substitute name is the drive path that is returned. `guest_kernel_sys` removes the junction and the target. - `python tools/check_conventions.py --base upstream/main` ### Checklist - [x] One topic. One bug, one fix. - [x] Tests cover the change. - [x] `python tools/check_conventions.py --base upstream/main` passes. - [x] Docs updated where behavior changed. Depends on: #7111 Unblocks: none GPUs tested: n/a AI-assisted: yes
github-actions[bot] commented 2026-10-17 21:31:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T21:31:12Z.


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.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 7202 core/libs/prx/libkernel/File/src/NativeStat.cpp L54-56

Some 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.

Pull request Shared files not compared
PR 4630 docs/dev/debt/libkernel.md
PR 5021 core/libs/prx/libkernel/File/src/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel.md
PR 5918 docs/dev/debt/libkernel.md
PR 6044 core/libs/tests/GuestFilesystem.cpp
core/libs/tests/GuestKernelSys.cpp
PR 6222 core/libs/prx/libkernel/File/src/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel.md
PR 6447 core/libs/prx/libkernel_sys/Export.cpp
docs/dev/debt/libkernel_sys.md
PR 6510 docs/dev/debt/libkernel.md
PR 6534 docs/dev/debt/libkernel.md
PR 6879 core/libs/prx/libkernel/File/src/NativeStat.cpp
PR 6908 docs/dev/debt/libkernel.md
PR 6977 docs/dev/debt/libkernel.md
PR 7075 docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7121 docs/dev/debt/libkernel.md
PR 7129 docs/dev/debt/libkernel.md
PR 7135 docs/dev/debt/libkernel.md
PR 7192 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/File/src/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
PR 7332 core/libs/prx/libkernel/File/src/NativeStat.cpp
core/libs/prx/libkernel_sys/Export.cpp
core/libs/tests/GuestKernelSys.cpp
docs/dev/debt/libkernel.md
docs/dev/debt/libkernel_sys.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6241411236 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7273#issuecomment-6241411236). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-17T21:31:12Z. --- <!-- pr-overlap --> 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**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | [PR 7202](https://www.github.com/boykopovar/AnyPS5/pull/7202) | `core/libs/prx/libkernel/File/src/NativeStat.cpp` [L54-56](https://github.com/boykopovar/AnyPS5/blob/cb1d6e5bd642c496d01ac583c614c82a8c654a41/core/libs/prx/libkernel/File/src/NativeStat.cpp#L54-L56) | | | Some 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. | Pull request | Shared files not compared | |---|---| | [PR 4630](https://www.github.com/boykopovar/AnyPS5/pull/4630) | `docs/dev/debt/libkernel.md` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/File/src/NativeStat.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 5918](https://www.github.com/boykopovar/AnyPS5/pull/5918) | `docs/dev/debt/libkernel.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/tests/GuestFilesystem.cpp`<br>`core/libs/tests/GuestKernelSys.cpp` | | [PR 6222](https://www.github.com/boykopovar/AnyPS5/pull/6222) | `core/libs/prx/libkernel/File/src/NativeStat.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6447](https://www.github.com/boykopovar/AnyPS5/pull/6447) | `core/libs/prx/libkernel_sys/Export.cpp`<br>`docs/dev/debt/libkernel_sys.md` | | [PR 6510](https://www.github.com/boykopovar/AnyPS5/pull/6510) | `docs/dev/debt/libkernel.md` | | [PR 6534](https://www.github.com/boykopovar/AnyPS5/pull/6534) | `docs/dev/debt/libkernel.md` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libkernel/File/src/NativeStat.cpp` | | [PR 6908](https://www.github.com/boykopovar/AnyPS5/pull/6908) | `docs/dev/debt/libkernel.md` | | [PR 6977](https://www.github.com/boykopovar/AnyPS5/pull/6977) | `docs/dev/debt/libkernel.md` | | [PR 7075](https://www.github.com/boykopovar/AnyPS5/pull/7075) | `docs/dev/debt/libkernel.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `docs/dev/debt/libkernel.md` | | [PR 7121](https://www.github.com/boykopovar/AnyPS5/pull/7121) | `docs/dev/debt/libkernel.md` | | [PR 7129](https://www.github.com/boykopovar/AnyPS5/pull/7129) | `docs/dev/debt/libkernel.md` | | [PR 7135](https://www.github.com/boykopovar/AnyPS5/pull/7135) | `docs/dev/debt/libkernel.md` | | [PR 7192](https://www.github.com/boykopovar/AnyPS5/pull/7192) | `docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/File/src/NativeStat.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp` | | [PR 7332](https://www.github.com/boykopovar/AnyPS5/pull/7332) | `core/libs/prx/libkernel/File/src/NativeStat.cpp`<br>`core/libs/prx/libkernel_sys/Export.cpp`<br>`core/libs/tests/GuestKernelSys.cpp`<br>`docs/dev/debt/libkernel.md`<br>`docs/dev/debt/libkernel_sys.md` |
oneandonlydean commented 2026-10-17 21:40:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T21:40:27Z.


Thanks for this. Junctions aborting in lstat/readlink is worth fixing. Two things before it can go in:

  1. Volume mount points come back as a relative path. Mounted folders use the same IO_REPARSE_TAG_MOUNT_POINT tag as junctions. Their substitute name is \??\Volume{GUID}\ and the print name is usually empty, so ReadJunction returns Volume{GUID}/. The guest resolves that against the link's own directory, a silent wrong answer where main failed with NotImplemented. Please keep throwing unless the name left after removing \??\ / \\?\ is drive-absolute (X:\...), e.g. return false from ReadJunction so the existing NotImplemented fires, and mention mounted volumes in the two debt lines.

  2. Overlap with #7111. #7111 (also yours) adds TextAt, WithoutNtPrefix and Read to WindowsSymbolicLink.hpp, and this PR re-implements the same reparse-text and prefix handling inline. The two PRs conflict in NativeStat.cpp and libkernel_sys/Export.cpp. Could you either fold the junction case into #7111, or rebase this one on it (Depends on: #7111) and reuse its helpers? #7202 also conflicts here (NativeStat.cpp, GuestFilesystem.cpp); whichever lands second will need a rebase.

Minor: the new GuestKernelSys.cpp block doesn't remove its junction and target afterwards (the GuestFilesystem.cpp block does).

For the maintainers rather than a change request: junction targets are always host-absolute, so the guest now receives host text such as C:/.... The debt notes have said an absolute link "has no guest form". Linux already returns host-absolute targets through read_symlink, so this matches Linux.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6241581868 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7273#issuecomment-6241581868). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-17T21:40:27Z. --- Thanks for this. Junctions aborting in `lstat`/`readlink` is worth fixing. Two things before it can go in: 1. **Volume mount points come back as a relative path.** Mounted folders use the same `IO_REPARSE_TAG_MOUNT_POINT` tag as junctions. Their substitute name is `\??\Volume{GUID}\` and the print name is usually empty, so `ReadJunction` returns `Volume{GUID}/`. The guest resolves that against the link's own directory, a silent wrong answer where `main` failed with `NotImplemented`. Please keep throwing unless the name left after removing `\??\` / `\\?\` is drive-absolute (`X:\...`), e.g. return false from `ReadJunction` so the existing `NotImplemented` fires, and mention mounted volumes in the two debt lines. 2. **Overlap with #7111.** #7111 (also yours) adds `TextAt`, `WithoutNtPrefix` and `Read` to `WindowsSymbolicLink.hpp`, and this PR re-implements the same reparse-text and prefix handling inline. The two PRs conflict in `NativeStat.cpp` and `libkernel_sys/Export.cpp`. Could you either fold the junction case into #7111, or rebase this one on it (`Depends on: #7111`) and reuse its helpers? #7202 also conflicts here (`NativeStat.cpp`, `GuestFilesystem.cpp`); whichever lands second will need a rebase. Minor: the new `GuestKernelSys.cpp` block doesn't remove its junction and target afterwards (the `GuestFilesystem.cpp` block does). For the maintainers rather than a change request: junction targets are always host-absolute, so the guest now receives host text such as `C:/...`. The debt notes have said an absolute link "has no guest form". Linux already returns host-absolute targets through `read_symlink`, so this matches Linux.
mazen320 commented 2026-10-18 09:00:08 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mazen320 on 2026-10-18T09:00:08Z.


Addressed the review on bd0caa451.

  1. ReadJunction returns false unless the name left after removing \??\ or \\?\ is a drive path (X:\...). A mounted volume (\??\Volume{GUID}\) still hits the existing NotImplemented. The print name is used when it is a drive path; otherwise the substitute name, which is what mklink /J stores. Both debt lines mention mounted volumes.

  2. This branch now includes #7111. ReadJunction uses its TextAt and WithoutNtPrefix. Depends on: #7111. TextAt takes the start of the path buffer because a mount point has no Flags field, so the symbolic-link header size is four bytes too far.

  3. guest_kernel_sys removes the junction and the target.

guest_filesystem and guest_kernel_sys passed here on Windows GCC 15.2 without administrator rights. python tools/check_conventions.py --base upstream/main passed. A pull-request push does not start the full Windows job.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6247974951 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7273#issuecomment-6247974951). Originally posted by [mazen320](https://github.com/mazen320) on 2026-10-18T09:00:08Z. --- Addressed the review on bd0caa451. 1. `ReadJunction` returns false unless the name left after removing `\??\` or `\\?\` is a drive path (`X:\...`). A mounted volume (`\??\Volume{GUID}\`) still hits the existing `NotImplemented`. The print name is used when it is a drive path; otherwise the substitute name, which is what `mklink /J` stores. Both debt lines mention mounted volumes. 2. This branch now includes #7111. `ReadJunction` uses its `TextAt` and `WithoutNtPrefix`. Depends on: #7111. `TextAt` takes the start of the path buffer because a mount point has no Flags field, so the symbolic-link header size is four bytes too far. 3. `guest_kernel_sys` removes the junction and the target. `guest_filesystem` and `guest_kernel_sys` passed here on Windows GCC 15.2 without administrator rights. `python tools/check_conventions.py --base upstream/main` passed. A pull-request push does not start the full Windows job.
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!7273
No description provided.