fix(libkernel): report app0 symlinks as their target type in getdirentries #9303

Merged
oneandonlydean merged 1 commit from upstream-pr/9303 into main 2026-10-22 13:19:26 +00:00
oneandonlydean commented 2026-10-21 17:51:29 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T17:51:29Z.


What

On Linux, sceKernelGetdirentries (and sceKernelGetdents, which calls it) copied the host d_type into the guest record. A directory under app0/ that is a host symbolic link was therefore listed as DT_LNK (10). A title that walks its own tree and descends only into DT_DIR entries skipped it.

Inside the app0/ tree, a symbolic link (or an entry whose type the host reports as DT_UNKNOWN) is now reported as the type of its target, DT_DIR or DT_REG, using fstatat. A console app0 contains no links, so links there come from how the title was unpacked. Outside app0/, links keep DT_LNK (a guest-made link in /data stays a link), and a dangling link, a link loop or a link to anything other than a file or directory stays DT_LNK too. DT_UNKNOWN outside app0/ is resolved without following links. errno is preserved around both new host calls.

Whether a directory is inside app0/ is decided from the open descriptor's host path (/proc/self/fd) against the canonical app0 path, so it also works when app0 itself is a link. One case stays as before, and the debt line says so: a directory opened through a link resolves to the link's target, so links nested inside a linked directory whose target is outside app0/ keep DT_LNK.

docs/user/USAGE.md no longer says that app0/ must not contain symbolic links on Linux (#7592 documented the old behaviour). It now describes the new behaviour and that one case.

Tested

Linux (CachyOS), GCC, Release.

  • New guest_directory_link_types: a temporary app0 with a real directory, a linked directory, a linked file and a dangling link, plus a linked directory under /data. Without the Stdio.cpp change it fails at the linked-directory check; with it, it passes. guest_directory*, guest_filesystem and guest_kernel_app_archive ctests: 7 of 7 passed.
  • PPSA04263 with the four top-level app0 directories as symbolic links into the unpacked dump: on main 8727ddb2 it exits with SIGSEGV at about 0 s, after listing /app0 and never opening the linked directories. With this change it ran the full 120 s test window with no crash and opened files under all four linked directories (102 under update/). The unfixed run was on main 8727ddb2; this branch is on 745b39462.

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); 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: PPSA04263 with a linked app0 layout
  • GPUs tested: n/a
  • AI-assisted: yes

Related: #8726 changes the Windows listing so junctions report DT_LNK. Without the same app0 exception, a junction-built app0 would hit this problem on Windows. #7201 (macOS port) adds a macOS branch to the same function that also copies d_type unchanged.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4955956793 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9303). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T17:51:29Z. --- ### What On Linux, `sceKernelGetdirentries` (and `sceKernelGetdents`, which calls it) copied the host `d_type` into the guest record. A directory under `app0/` that is a host symbolic link was therefore listed as `DT_LNK` (10). A title that walks its own tree and descends only into `DT_DIR` entries skipped it. Inside the `app0/` tree, a symbolic link (or an entry whose type the host reports as `DT_UNKNOWN`) is now reported as the type of its target, `DT_DIR` or `DT_REG`, using `fstatat`. A console `app0` contains no links, so links there come from how the title was unpacked. Outside `app0/`, links keep `DT_LNK` (a guest-made link in `/data` stays a link), and a dangling link, a link loop or a link to anything other than a file or directory stays `DT_LNK` too. `DT_UNKNOWN` outside `app0/` is resolved without following links. `errno` is preserved around both new host calls. Whether a directory is inside `app0/` is decided from the open descriptor's host path (`/proc/self/fd`) against the canonical `app0` path, so it also works when `app0` itself is a link. One case stays as before, and the debt line says so: a directory opened through a link resolves to the link's target, so links nested inside a linked directory whose target is outside `app0/` keep `DT_LNK`. `docs/user/USAGE.md` no longer says that `app0/` must not contain symbolic links on Linux (#7592 documented the old behaviour). It now describes the new behaviour and that one case. ### Tested Linux (CachyOS), GCC, Release. - New `guest_directory_link_types`: a temporary `app0` with a real directory, a linked directory, a linked file and a dangling link, plus a linked directory under `/data`. Without the `Stdio.cpp` change it fails at the linked-directory check; with it, it passes. `guest_directory*`, `guest_filesystem` and `guest_kernel_app_archive` ctests: 7 of 7 passed. - PPSA04263 with the four top-level `app0` directories as symbolic links into the unpacked dump: on main 8727ddb2 it exits with SIGSEGV at about 0 s, after listing `/app0` and never opening the linked directories. With this change it ran the full 120 s test window with no crash and opened files under all four linked directories (102 under `update/`). The unfixed run was on main 8727ddb2; this branch is on 745b39462. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [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`); 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: PPSA04263 with a linked `app0` layout - [x] GPUs tested: n/a - [x] AI-assisted: yes Related: #8726 changes the Windows listing so junctions report `DT_LNK`. Without the same `app0` exception, a junction-built `app0` would hit this problem on Windows. #7201 (macOS port) adds a macOS branch to the same function that also copies `d_type` unchanged.
github-actions[bot] commented 2026-10-21 18:15:51 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-21T18:15:51Z.


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 8658 core/libs/prx/libkernel/File/src/Stdio.cpp L1137
PR 9239 docs/dev/debt/libkernel.md L138

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 4563 core/libs/prx/libkernel/CMakeLists.txt
PR 5021 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
docs/user/USAGE.md
PR 5925 docs/user/USAGE.md
PR 6044 core/libs/prx/libkernel/CMakeLists.txt
PR 6149 docs/dev/debt/libkernel.md
PR 6171 docs/user/USAGE.md
PR 6469 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6740 docs/dev/debt/libkernel.md
PR 6788 docs/user/USAGE.md
PR 6830 core/libs/prx/libkernel/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 6879 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 6924 docs/user/USAGE.md
PR 6946 docs/user/USAGE.md
PR 7088 docs/dev/debt/libkernel.md
PR 7105 docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7201 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7447 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 7509 docs/dev/debt/libkernel.md
PR 7565 docs/dev/debt/libkernel.md
PR 7642 docs/user/USAGE.md
PR 7653 docs/dev/debt/libkernel.md
PR 7918 docs/user/USAGE.md
PR 8520 core/libs/prx/libkernel/CMakeLists.txt
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 8547 docs/dev/debt/libkernel.md
PR 8553 docs/dev/debt/libkernel.md
PR 9019 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9382 core/libs/prx/libkernel/CMakeLists.txt
PR 9408 docs/user/USAGE.md
PR 9508 docs/user/USAGE.md
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6323231417 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/9303#issuecomment-6323231417). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-21T18:15:51Z. --- <!-- 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 8658](https://www.github.com/boykopovar/AnyPS5/pull/8658) | `core/libs/prx/libkernel/File/src/Stdio.cpp` [L1137](https://github.com/boykopovar/AnyPS5/blob/3ca07d086d5f44fbe3c00370e7f03953ab46ca1b/core/libs/prx/libkernel/File/src/Stdio.cpp#L1137) | | | | [PR 9239](https://www.github.com/boykopovar/AnyPS5/pull/9239) | `docs/dev/debt/libkernel.md` [L138](https://github.com/boykopovar/AnyPS5/blob/3ca07d086d5f44fbe3c00370e7f03953ab46ca1b/docs/dev/debt/libkernel.md#L138) | | | 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 4563](https://www.github.com/boykopovar/AnyPS5/pull/4563) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 5021](https://www.github.com/boykopovar/AnyPS5/pull/5021) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp`<br>`docs/dev/debt/libkernel.md`<br>`docs/user/USAGE.md` | | [PR 5925](https://www.github.com/boykopovar/AnyPS5/pull/5925) | `docs/user/USAGE.md` | | [PR 6044](https://www.github.com/boykopovar/AnyPS5/pull/6044) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 6149](https://www.github.com/boykopovar/AnyPS5/pull/6149) | `docs/dev/debt/libkernel.md` | | [PR 6171](https://www.github.com/boykopovar/AnyPS5/pull/6171) | `docs/user/USAGE.md` | | [PR 6469](https://www.github.com/boykopovar/AnyPS5/pull/6469) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6740](https://www.github.com/boykopovar/AnyPS5/pull/6740) | `docs/dev/debt/libkernel.md` | | [PR 6788](https://www.github.com/boykopovar/AnyPS5/pull/6788) | `docs/user/USAGE.md` | | [PR 6830](https://www.github.com/boykopovar/AnyPS5/pull/6830) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`docs/dev/debt/libkernel.md` | | [PR 6879](https://www.github.com/boykopovar/AnyPS5/pull/6879) | `core/libs/prx/libkernel/File/src/Stdio.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 6924](https://www.github.com/boykopovar/AnyPS5/pull/6924) | `docs/user/USAGE.md` | | [PR 6946](https://www.github.com/boykopovar/AnyPS5/pull/6946) | `docs/user/USAGE.md` | | [PR 7088](https://www.github.com/boykopovar/AnyPS5/pull/7088) | `docs/dev/debt/libkernel.md` | | [PR 7105](https://www.github.com/boykopovar/AnyPS5/pull/7105) | `docs/dev/debt/libkernel.md` | | [PR 7149](https://www.github.com/boykopovar/AnyPS5/pull/7149) | `docs/dev/debt/libkernel.md` | | [PR 7201](https://www.github.com/boykopovar/AnyPS5/pull/7201) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 7447](https://www.github.com/boykopovar/AnyPS5/pull/7447) | `core/libs/prx/libkernel/File/src/Stdio.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 7509](https://www.github.com/boykopovar/AnyPS5/pull/7509) | `docs/dev/debt/libkernel.md` | | [PR 7565](https://www.github.com/boykopovar/AnyPS5/pull/7565) | `docs/dev/debt/libkernel.md` | | [PR 7642](https://www.github.com/boykopovar/AnyPS5/pull/7642) | `docs/user/USAGE.md` | | [PR 7653](https://www.github.com/boykopovar/AnyPS5/pull/7653) | `docs/dev/debt/libkernel.md` | | [PR 7918](https://www.github.com/boykopovar/AnyPS5/pull/7918) | `docs/user/USAGE.md` | | [PR 8520](https://www.github.com/boykopovar/AnyPS5/pull/8520) | `core/libs/prx/libkernel/CMakeLists.txt`<br>`core/libs/prx/libkernel/File/src/Stdio.cpp`<br>`docs/dev/debt/libkernel.md` | | [PR 8547](https://www.github.com/boykopovar/AnyPS5/pull/8547) | `docs/dev/debt/libkernel.md` | | [PR 8553](https://www.github.com/boykopovar/AnyPS5/pull/8553) | `docs/dev/debt/libkernel.md` | | [PR 9019](https://www.github.com/boykopovar/AnyPS5/pull/9019) | `core/libs/prx/libkernel/File/src/Stdio.cpp` | | [PR 9382](https://www.github.com/boykopovar/AnyPS5/pull/9382) | `core/libs/prx/libkernel/CMakeLists.txt` | | [PR 9408](https://www.github.com/boykopovar/AnyPS5/pull/9408) | `docs/user/USAGE.md` | | [PR 9508](https://www.github.com/boykopovar/AnyPS5/pull/9508) | `docs/user/USAGE.md` |
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!9303
No description provided.