Skip to content

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

Open
qpavyros wants to merge 2 commits into
boykopovar:mainfrom
qpavyros:codex/archive-stdio
Open

qpavyros wants to merge 2 commits into
boykopovar:mainfrom
qpavyros:codex/archive-stdio

Conversation

@qpavyros

@qpavyros qpavyros commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

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: fix(libkernel): resolve original .prx names to relinked .guest.prx in lstat #9478
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes; implementation, code review and local test execution assisted by Codex

Copilot AI balanced review requested due to automatic review settings October 18, 2026 06:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@github-actions

github-actions Bot commented Oct 18, 2026 •

Copy link
Copy Markdown

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 6149 docs/dev/debt/libkernel.md
PR 6936 core/libs/prx/libkernel/File/src/ArchivedFile.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 7088 docs/dev/debt/libkernel.md
PR 7121 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 7149 docs/dev/debt/libkernel.md
PR 7544 docs/dev/debt/libc.md
PR 7715 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8150 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 8605 docs/dev/debt/libkernel.md
PR 8965 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 9087 docs/dev/debt/libc.md
PR 9156 docs/dev/debt/libkernel.md
PR 9293 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 9297 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 9302 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 9340 docs/dev/debt/libc.md
PR 9371 docs/dev/debt/libc.md
PR 9389 docs/dev/debt/libkernel.md
PR 9557 docs/dev/debt/libkernel.md
PR 9566 docs/dev/debt/libkernel.md
PR 9584 core/libs/prx/libc/CMakeLists.txt
PR 9773 core/libs/prx/libc/CMakeLists.txt
PR 9938 docs/dev/debt/libkernel.md
PR 10007 docs/dev/debt/libc.md
PR 10113 core/libs/prx/libc/CMakeLists.txt
PR 10226 core/libs/prx/libc/CMakeLists.txt
PR 10409 docs/dev/debt/libc.md
PR 10558 docs/dev/debt/libkernel.md
PR 10645 docs/dev/debt/libkernel.md
PR 11109 docs/dev/debt/libc.md
PR 11172 docs/dev/debt/libc.md
PR 11215 docs/dev/debt/libkernel.md
PR 11332 docs/dev/debt/libc.md
PR 11628 docs/dev/debt/libkernel.md
PR 11661 docs/dev/debt/libc.md
docs/dev/debt/libkernel.md
PR 11689 docs/dev/debt/libc.md
docs/dev/debt/libkernel.md
PR 11698 docs/dev/debt/libc.md
docs/dev/debt/libkernel.md
PR 11831 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/FileStream.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
PR 11896 docs/dev/debt/libkernel.md
PR 12184 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 12682 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/FileStream.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12688 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/FileStream.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12700 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/FileStream.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12717 core/libs/prx/libc/CMakeLists.txt
PR 12849 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 12965 core/libs/prx/libc/CMakeLists.txt
core/libs/prx/libc/include/FileStream.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 13449 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 13794 docs/dev/debt/libc.md
PR 13804 docs/dev/debt/libc.md
PR 14103 docs/dev/debt/libkernel.md
PR 14108 docs/dev/debt/libkernel.md
PR 15037 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 15040 docs/dev/debt/libkernel.md
PR 15973 docs/dev/debt/libc.md
PR 16214 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16516 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16560 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16790 docs/dev/debt/libkernel.md
PR 16791 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16826 docs/dev/debt/libkernel.md
PR 16919 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16924 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16944 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16949 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 16975 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17259 docs/dev/debt/libc.md
PR 17261 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17277 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17296 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17331 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17484 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 17539 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17555 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17556 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17557 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17558 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17568 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17578 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17607 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17610 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libc.md
PR 17638 docs/dev/debt/libkernel.md
PR 18112 core/libs/prx/libc/src/Filesystem.cpp
PR 18190 core/libs/prx/libc/src/Filesystem.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 18197 docs/dev/debt/libkernel.md
PR 18324 docs/dev/debt/libkernel.md
PR 18347 docs/dev/debt/libc.md
PR 18462 docs/dev/debt/libkernel.md
PR 18693 core/libs/prx/libc/CMakeLists.txt
PR 18915 docs/dev/debt/libc.md
PR 19181 core/libs/prx/libc/CMakeLists.txt
PR 19433 core/libs/prx/libkernel/File/src/Stdio.cpp
docs/dev/debt/libkernel.md
PR 20021 docs/dev/debt/libkernel.md
PR 20161 docs/dev/debt/libkernel.md
PR 20349 docs/dev/debt/libkernel.md
PR 20899 core/libs/prx/libc/CMakeLists.txt
PR 21236 core/libs/prx/libc/CMakeLists.txt
PR 21237 core/libs/prx/libc/CMakeLists.txt
PR 21930 core/libs/prx/libc/CMakeLists.txt
PR 22047 core/libs/prx/libc/src/FileAndHeap.cpp
PR 22143 core/libs/prx/libc/include/FileStream.hpp
PR 22191 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 22696 core/libs/prx/libc/include/FileStream.hpp
PR 23395 core/libs/prx/libc/CMakeLists.txt
PR 24217 core/libs/prx/libc/CMakeLists.txt
PR 24306 core/libs/prx/libc/CMakeLists.txt
PR 24322 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 24360 core/libs/prx/libc/CMakeLists.txt
PR 24377 core/libs/prx/libc/src/FileAndHeap.cpp
docs/dev/debt/libc.md
PR 24406 core/libs/prx/libc/include/FileStream.hpp
core/libs/prx/libc/src/FileAndHeap.cpp
PR 24487 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 24488 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 24641 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 24910 core/libs/prx/libc/CMakeLists.txt
PR 24917 core/libs/prx/libc/CMakeLists.txt
docs/dev/debt/libkernel.md
PR 24960 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 25087 core/libs/prx/libc/CMakeLists.txt
PR 25090 core/libs/prx/libc/CMakeLists.txt
PR 25289 core/libs/prx/libc/CMakeLists.txt
PR 25420 core/libs/prx/libc/CMakeLists.txt
PR 25426 core/libs/prx/libc/CMakeLists.txt
PR 25468 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 25479 core/libs/prx/libc/CMakeLists.txt
PR 25491 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 25495 core/libs/prx/libc/src/FileAndHeap.cpp
PR 25497 core/libs/prx/libc/CMakeLists.txt
PR 25515 core/libs/prx/libc/src/FileAndHeap.cpp
PR 25674 core/libs/prx/libc/CMakeLists.txt
PR 25708 core/libs/prx/libc/CMakeLists.txt
PR 25744 core/libs/prx/libc/CMakeLists.txt
PR 25750 core/libs/prx/libc/CMakeLists.txt
PR 25759 core/libs/prx/libc/CMakeLists.txt
PR 25763 core/libs/prx/libc/CMakeLists.txt
PR 25766 core/libs/prx/libc/CMakeLists.txt
PR 25935 core/libs/prx/libc/CMakeLists.txt
PR 25956 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 26214 core/libs/prx/libc/CMakeLists.txt
PR 26215 core/libs/prx/libc/CMakeLists.txt
PR 26224 core/libs/prx/libc/CMakeLists.txt
PR 26228 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 26235 core/libs/prx/libc/CMakeLists.txt
PR 26252 core/libs/prx/libc/CMakeLists.txt
PR 26300 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 26364 core/libs/prx/libc/CMakeLists.txt
PR 26453 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 26520 core/libs/prx/libc/CMakeLists.txt
PR 26618 core/libs/prx/libc/CMakeLists.txt
PR 26763 core/libs/prx/libc/CMakeLists.txt
PR 26764 core/libs/prx/libc/CMakeLists.txt
PR 26796 core/libs/prx/libc/CMakeLists.txt

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 18, 2026
@qpavyros
qpavyros force-pushed the codex/archive-stdio branch from e8c4d03 to 073343e Compare October 18, 2026 20:21
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 18, 2026
@blawesom

Copy link
Copy Markdown
Contributor

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.

@adriadam10 adriadam10 self-assigned this Oct 19, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 20, 2026
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 20, 2026
@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@Felipebmaitan Felipebmaitan mentioned this pull request Oct 21, 2026
12 tasks done
@qpavyros

Copy link
Copy Markdown
Contributor Author

Updated the published branch to 86279a7 by merging main a6dcea9 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.

@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 21, 2026
@EagleBearerYS

Copy link
Copy Markdown
Contributor

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

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 22, 2026
@adriadam10 adriadam10 removed their assignment Nov 17, 2026

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build docs libc libkernel needs rebase Conflicts with main, rebase needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants