feat(libc): support archive-backed stdio reads #7447

Closed
qpavyros wants to merge 2 commits from upstream-pr/7447 into main
qpavyros commented 2026-10-18 06:58:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by qpavyros on 2026-10-18T06:58:45Z.


What

Allow libc fopen and fopen_s to read entries found only in AnyPS5's optional app0.zar packaging layer, while preserving disk overrides and case-insensitive lookup.

Materialize each opened entry into a temporary file in 64 KiB chunks, reopen it with genuine read-only OS access, and use the existing native stdio implementation. This covers reads, seeking, EOF/error state, narrow scanning and wide input without a separate stdio backend. Independent opens have independent positions; duplicated descriptors share the native backing and preserve archive metadata. Close, reopen and descriptor replacement retire the metadata.

Add archive-aware access and lstat; preserve the existing archive-aware stat path. Prevent unsupported descriptor operations from acting on temporary-file metadata.

Opening decompresses the whole entry and needs temporary disk space equal to its uncompressed size for each independent open. No performance improvement or title bring-up is claimed. Directory merging, fdopen on the existing virtual kernel archive descriptors and freopen to an archive-only path remain unsupported. Host stdio buffering rules still apply when mixing streams and descriptor I/O. This is not support for the console's PFS format.

Integration follow-up: merged main 1a745ae38 without rewriting published history. Resolved the FileStream close conflict by retaining both archive metadata detachment and main's Windows directory-stream deregistration. Directory merging remains separate in #8520; it is not a prerequisite for stdio reads.

Merge order: agreed to #9478 landing first, as its author proposed. This PR lists it as a dependency and will take ResolvePathError_nid_no_patch(path, native, true, true) when integrating that change, retaining module lookup and archive lookup. Until #9478 lands this branch retains its existing archive resolver flags. #9474's author has agreed to land after #7447 and retain both the early archive access lookup and the Windows host symlink checks.

Tested

  • Updated head dead12eba, integrating main 1a745ae38.
  • Windows, MinGW GCC 15.2 Release: affected libraries and focused test targets rebuilt; 20/20 focused CTest cases passed (19 selected cases plus guest_filesystem).
  • Ubuntu under WSL, GCC 15 Release: affected libraries and focused test targets rebuilt; 20/20 focused CTest cases passed.
  • Includes all five archive stdio cases (basic reads, descriptor lifecycle, errors, absent archive and damaged archive), existing libc/kernel archive cases, ordinary file streams, all three standard-stream modes and host streams; Linux additionally covers fopen errors. Both hosts cover ordinary directory and access behavior; Windows additionally checks the directory fopen lifecycle in guest_filesystem.
  • Coverage includes compressed block boundaries, EOF/seek/tell/rewind/ungetc, empty entries, scanning and wide input, disk overrides, independent opens, descriptor duplication/replacement, positioned reads, metadata and denied mutation.
  • python tools/check_conventions.py --base origin/main: 0 errors, two debt-length warnings. git diff --check passed.
  • No PS5, game title, full-suite or performance validation is claimed.

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: #9478
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes; implementation, code review and local test execution assisted by Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4907105703 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7447). Originally posted by [qpavyros](https://github.com/qpavyros) on 2026-10-18T06:58:45Z. --- ### What Allow libc `fopen` and `fopen_s` to read entries found only in AnyPS5's optional `app0.zar` packaging layer, while preserving disk overrides and case-insensitive lookup. Materialize each opened entry into a temporary file in 64 KiB chunks, reopen it with genuine read-only OS access, and use the existing native stdio implementation. This covers reads, seeking, EOF/error state, narrow scanning and wide input without a separate stdio backend. Independent opens have independent positions; duplicated descriptors share the native backing and preserve archive metadata. Close, reopen and descriptor replacement retire the metadata. Add archive-aware `access` and `lstat`; preserve the existing archive-aware `stat` path. Prevent unsupported descriptor operations from acting on temporary-file metadata. Opening decompresses the whole entry and needs temporary disk space equal to its uncompressed size for each independent open. No performance improvement or title bring-up is claimed. Directory merging, `fdopen` on the existing virtual kernel archive descriptors and `freopen` to an archive-only path remain unsupported. Host stdio buffering rules still apply when mixing streams and descriptor I/O. This is not support for the console's PFS format. Integration follow-up: merged main `1a745ae38` without rewriting published history. Resolved the FileStream close conflict by retaining both archive metadata detachment and main's Windows directory-stream deregistration. Directory merging remains separate in #8520; it is not a prerequisite for stdio reads. Merge order: agreed to #9478 landing first, as its author proposed. This PR lists it as a dependency and will take `ResolvePathError_nid_no_patch(path, native, true, true)` when integrating that change, retaining module lookup and archive lookup. Until #9478 lands this branch retains its existing archive resolver flags. #9474's author has agreed to land after #7447 and retain both the early archive access lookup and the Windows host symlink checks. ### Tested - Updated head `dead12eba`, integrating main `1a745ae38`. - Windows, MinGW GCC 15.2 Release: affected libraries and focused test targets rebuilt; 20/20 focused CTest cases passed (19 selected cases plus guest_filesystem). - Ubuntu under WSL, GCC 15 Release: affected libraries and focused test targets rebuilt; 20/20 focused CTest cases passed. - Includes all five archive stdio cases (basic reads, descriptor lifecycle, errors, absent archive and damaged archive), existing libc/kernel archive cases, ordinary file streams, all three standard-stream modes and host streams; Linux additionally covers fopen errors. Both hosts cover ordinary directory and access behavior; Windows additionally checks the directory fopen lifecycle in guest_filesystem. - Coverage includes compressed block boundaries, EOF/seek/tell/rewind/ungetc, empty entries, scanning and wide input, disk overrides, independent opens, descriptor duplication/replacement, positioned reads, metadata and denied mutation. - `python tools/check_conventions.py --base origin/main`: 0 errors, two debt-length warnings. `git diff --check` passed. - No PS5, game title, full-suite or performance validation is claimed. <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ### 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: #9478 - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes; implementation, code review and local test execution assisted by Codex
copilot-pull-request-reviewer[bot] commented 2026-10-18 06:58:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by copilot-pull-request-reviewer[bot] on 2026-10-18T06:58:52Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5561843451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7447#pullrequestreview-5561843451). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-10-18T06:58:52Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
blawesom commented 2026-10-19 06:28:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by blawesom on 2026-10-19T06:28:46Z.


Rebase handoff — rebased onto current main (authorship unchanged). One docs-debt conflict, unioned with main's entries.

Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, BUILD_TESTING=ON, AMD RX 9070 XT / RADV): builds; conventions pass; full suite green apart from the two known main regressions (agc_driver_tessellation — Mesa, #5444; agc_driver_bda_device — #7584), neither from this PR.

To pick it up:

git fetch https://github.com/blawesom/AnyPS5 rebase/7447
git checkout <your branch>
git merge --ff-only FETCH_HEAD

Head is f725dfca4.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6261135874 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7447#issuecomment-6261135874). Originally posted by [blawesom](https://github.com/blawesom) on 2026-10-19T06:28:46Z. --- **Rebase handoff** — rebased onto current `main` (authorship unchanged). One docs-debt conflict, unioned with `main`'s entries. Verified on Linux (CachyOS, kernel 7.2.9, GCC 16.2.1, Ninja, Release, `BUILD_TESTING=ON`, AMD RX 9070 XT / RADV): builds; conventions pass; **full suite green apart from the two known `main` regressions** (`agc_driver_tessellation` — Mesa, #5444; `agc_driver_bda_device` — #7584), neither from this PR. **To pick it up:** ``` git fetch https://github.com/blawesom/AnyPS5 rebase/7447 git checkout <your branch> git merge --ff-only FETCH_HEAD ``` Head is `f725dfca4`.
qpavyros commented 2026-10-21 23:14:26 +00:00 (Migrated from github.com)

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


Updated the published branch to 86279a794 by merging main a6dcea927 without force-pushing. Resolved the libkernel debt conflict while retaining both the archive-stream limitations and main's module-loading entry.

Rebuilt and checked the focused archive/stream targets: Windows 17/17 and WSL Linux 18/18 passed, including all five archive stdio cases. Conventions reports 0 errors and diff checks pass. The description now records the current head, evidence and remaining limits; this is not a full-suite or console result.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6328662865 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7447#issuecomment-6328662865). Originally posted by [qpavyros](https://github.com/qpavyros) on 2026-10-21T23:14:26Z. --- Updated the published branch to 86279a794 by merging main a6dcea927 without force-pushing. Resolved the libkernel debt conflict while retaining both the archive-stream limitations and main's module-loading entry. Rebuilt and checked the focused archive/stream targets: Windows 17/17 and WSL Linux 18/18 passed, including all five archive stdio cases. Conventions reports 0 errors and diff checks pass. The description now records the current head, evidence and remaining limits; this is not a full-suite or console result.
EagleBearerYS commented 2026-10-22 00:50:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T00:50:09Z.


@qpavyros a merge-order note: #9478 changes the same ResolvePathError_nid_no_patch call in lstat. It sets the resolver's module flag, so lstat finds X.guest.prx for a relinked module as stat does, where this PR sets the archived flag. The two should compose as ResolvePathError_nid_no_patch(path, native, true, true), the call sceKernelCheckReachability makes on main. As #9478 is a one-line change, it proposes going first, and this PR would take true, true when it rebases. If you'd rather this one went first, say so and #9478 will list it under Depends on.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6329954319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7447#issuecomment-6329954319). Originally posted by [EagleBearerYS](https://github.com/EagleBearerYS) on 2026-10-22T00:50:09Z. --- @qpavyros a merge-order note: #9478 changes the same `ResolvePathError_nid_no_patch` call in `lstat`. It sets the resolver's `module` flag, so `lstat` finds `X.guest.prx` for a relinked module as `stat` does, where this PR sets the `archived` flag. The two should compose as `ResolvePathError_nid_no_patch(path, native, true, true)`, the call `sceKernelCheckReachability` makes on `main`. As #9478 is a one-line change, it proposes going first, and this PR would take `true, true` when it rebases. If you'd rather this one went first, say so and #9478 will list it under Depends on.
Gruzzberry commented 2026-10-22 06:49:10 +00:00 (Migrated from github.com)

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


#9474 changes the Windows host branch of access_nid_postfix (it follows a symbolic link before reading the attributes and the security descriptor), next to the archive lookup this PR adds at the start of the same function. The two compose: the archive branch returns before the host checks. Either order works for me; whichever lands second keeps both and reruns guest_access and your archive access checks. Happy to rebase #9474 onto this one if it lands first.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6334633017 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7447#issuecomment-6334633017). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T06:49:10Z. --- #9474 changes the Windows host branch of `access_nid_postfix` (it follows a symbolic link before reading the attributes and the security descriptor), next to the archive lookup this PR adds at the start of the same function. The two compose: the archive branch returns before the host checks. Either order works for me; whichever lands second keeps both and reruns `guest_access` and your archive `access` checks. Happy to rebase #9474 onto this one if it lands first.
Gruzzberry commented 2026-10-22 11:49:38 +00:00 (Migrated from github.com)

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


For the record: #9474 will go after this PR and rebase, keeping both the archive lookup and its link following; nothing is needed here. Its checklist now says so.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6340013216 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7447#issuecomment-6340013216). Originally posted by [Gruzzberry](https://github.com/Gruzzberry) on 2026-10-22T11:49:38Z. --- For the record: #9474 will go after this PR and rebase, keeping both the archive lookup and its link following; nothing is needed here. Its checklist now says so.
CnRJay commented 2026-11-01 20:04:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by CnRJay on 2026-11-01T20:04:18Z.

Review: COMMENTED


Correction (2026-11-01): the title-ID/log demand below is not a CONTRIBUTING requirement; Unblocks: none is allowed. The technical points below are unaffected.

1. No title reaches this on main. "No PS5, game title, full-suite or performance validation is claimed" and "Unblocks: none". A title ID with a log line showing a libc fopen of an app0.zar-only path would settle whether this is needed.

2. Cost model of the design. Every fopen of an archive-only entry decompresses the whole entry into a temp file (anyps5-app0-XXXXXX on POSIX, AnyPS5-app0-<pid>-<id>.tmp on Windows) before the first read returns, and each independent open does it again. For a title that opens a multi-hundred-MB asset to read a header, the stall and the disk traffic scale with the uncompressed size, not with the bytes read, and temporary space is needed per open. The body states this and does not size it. Two questions:

  • The libkernel side already has archive descriptors for sceKernelOpen/open. Why does libc not read the same entry on demand (chunked, as kChunkSize already is) instead of materializing it? "No separate stdio backend" is a reason of convenience, but the price is paid at runtime by every title.
  • What happens when the temp directory is full or read-only partway through the copy? The POSIX path unlinks the name on failure, but does fopen then return NULL with an errno that reflects ENOSPC, or a generic failure? A test for that case would pin it.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5729971378 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7447#pullrequestreview-5729971378). Originally posted by [CnRJay](https://github.com/CnRJay) on 2026-11-01T20:04:18Z. **Review:** COMMENTED --- **Correction (2026-11-01):** the title-ID/log demand below is not a CONTRIBUTING requirement; `Unblocks: none` is allowed. The technical points below are unaffected. **1. No title reaches this on `main`.** "No PS5, game title, full-suite or performance validation is claimed" and "Unblocks: none". A title ID with a log line showing a libc `fopen` of an `app0.zar`-only path would settle whether this is needed. **2. Cost model of the design.** Every `fopen` of an archive-only entry decompresses the whole entry into a temp file (`anyps5-app0-XXXXXX` on POSIX, `AnyPS5-app0-<pid>-<id>.tmp` on Windows) before the first read returns, and each independent open does it again. For a title that opens a multi-hundred-MB asset to read a header, the stall and the disk traffic scale with the uncompressed size, not with the bytes read, and temporary space is needed per open. The body states this and does not size it. Two questions: - The libkernel side already has archive descriptors for `sceKernelOpen`/`open`. Why does libc not read the same entry on demand (chunked, as `kChunkSize` already is) instead of materializing it? "No separate stdio backend" is a reason of convenience, but the price is paid at runtime by every title. - What happens when the temp directory is full or read-only partway through the copy? The POSIX path unlinks the name on failure, but does `fopen` then return `NULL` with an errno that reflects ENOSPC, or a generic failure? A test for that case would pin it.
MarcZX10 commented 2026-11-23 02:42:24 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-23T02:42:24Z.

Review: COMMENTED


Reviewed — comments

No blocking defect was verified in the code inspected, but the review is incomplete because tests were not run and not every changed file was read.

What I ran

Inspected the prepared diff for head 7faf2fff1fffad65690a893f489943616d129aaa and targeted source ranges using repo_read.py. No build or test command was run.

Results

Check Result Note
Change inspection passed Targeted implementation paths reviewed
Tests not run No commands were run
Full changed-file review not run Some files and ranges were not read

Negative control

Not run; no test command was run.

Findings

Blocking

None verified in the inspected code.

Non-blocking

None.

Sources

Reviewed the prepared diff and source at the pinned head. Inspected AppArchiveStream.cpp, AppArchive.hpp, AppArchive.cpp, FileAndHeap.cpp, Filesystem.cpp, ArchivedFile.cpp, Stdio.cpp, and FileStream.hpp in whole or in targeted ranges.

Not verified

Tests, builds, and runtime behavior were not verified. The changed files CMakeLists.txt, GuestArchiveStdio.cpp, docs/dev/debt/libc.md, and docs/dev/debt/libkernel.md were not read from their full head text; AppArchive.cpp, FileAndHeap.cpp, Stdio.cpp, and FileStream.hpp were only read in selected ranges. The manifest lists 12 changed files, all included; no exclusions were reported by the file listing.

To get this to a good state

Nothing is required. Optional: run the focused archive stdio tests on Windows and Linux, and review the changed files and ranges not inspected here.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6015988975 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7447#pullrequestreview-6015988975). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-23T02:42:24Z. **Review:** COMMENTED --- # Reviewed — comments No blocking defect was verified in the code inspected, but the review is incomplete because tests were not run and not every changed file was read. ## What I ran Inspected the prepared diff for head `7faf2fff1fffad65690a893f489943616d129aaa` and targeted source ranges using `repo_read.py`. No build or test command was run. ## Results | Check | Result | Note | |---|---|---| | Change inspection | passed | Targeted implementation paths reviewed | | Tests | not run | No commands were run | | Full changed-file review | not run | Some files and ranges were not read | ## Negative control Not run; no test command was run. ## Findings ### Blocking None verified in the inspected code. ### Non-blocking None. ## Sources Reviewed the prepared diff and source at the pinned head. Inspected `AppArchiveStream.cpp`, `AppArchive.hpp`, `AppArchive.cpp`, `FileAndHeap.cpp`, `Filesystem.cpp`, `ArchivedFile.cpp`, `Stdio.cpp`, and `FileStream.hpp` in whole or in targeted ranges. ## Not verified Tests, builds, and runtime behavior were not verified. The changed files `CMakeLists.txt`, `GuestArchiveStdio.cpp`, `docs/dev/debt/libc.md`, and `docs/dev/debt/libkernel.md` were not read from their full head text; `AppArchive.cpp`, `FileAndHeap.cpp`, `Stdio.cpp`, and `FileStream.hpp` were only read in selected ranges. The manifest lists 12 changed files, all included; no exclusions were reported by the file listing. ## To get this to a good state Nothing is required. Optional: run the focused archive stdio tests on Windows and Linux, and review the changed files and ranges not inspected here.

Pull request closed

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!7447
No description provided.