Skip to content

fix(libkernel): answer mkdir and file creation on app0.zar paths with EEXIST and EROFS - #28117

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
leskal:fix/libkernel-app0-zar-mkdir
Dec 3, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
leskal:fix/libkernel-app0-zar-mkdir

Conversation

@leskal

@leskal leskal commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

What

sceKernelMkdir and mkdir threw "reading /app0/engine in app0.zar not implemented" for a path that exists only in app0.zar: the path lookup refused archive-only entries before mkdir could answer. Creating a file directly inside an archive-only directory, through sceKernelOpen with O_CREAT or libc fopen in a w or a mode, answered ENOENT because the host has no such directory; the console's read-only mount answers EROFS. All of them now see the archive and answer as FreeBSD 11.4 does on a read-only mount, without creating anything on the host:

Path Result Why
mkdir of a path in the archive (/app0/engine, /app0/engine/) EEXIST kern_mkdirat returns it once the lookup finds the entry, before any write check, as AnyPS5 already does for a directory on disk
mkdir, O_CREAT or fopen w/a of a new name inside an archive-only directory EROFS the lookup refuses a create on a read-only mount; archived files already give EROFS when opened for writing
the same with an archived file as parent ENOTDIR
opening a missing name there without creating it (sceKernelOpen without O_CREAT, fopen r+) ENOENT unchanged: the lookup finds nothing and nothing is created

An existing archived file keeps its answers (EEXIST with O_EXCL, EROFS for writing), and paths that also exist on disk keep today's behaviour. The check lives in one libc helper, AppArchiveCreateError_nid_no_patch, used by all three. The console's /app0 PFS answers are not measured; the debt fragment says so.

Title Path Call that stopped
CUSA12982 /app0/engine sceKernelMkdir, creating the directories for engine/saved/config/ps4/manifest.ini

Overlaps #18190 at mkdir_nid_postfix in Stdio.cpp, which it renames to mkdir_nid_no_patch with a wrapper, and #27855 in OpenNative, which renames its flags parameter to requestedFlags where the new O_CREAT check reads it. Neither does the same work; whichever lands second keeps the other's rename and these lines.

Tested

Windows 10, WinLibs GCC 15.2.0 r7: guest_kernel_app_archive_* (5 modes) and guest_app_archive pass, with the new sceKernelMkdir, mkdir, O_CREAT and fopen cases and checks that nothing was created. CUSA12982, packed in app0.zar and built with #28088, #28089, #27342 and #27937, now gets past /app0/engine, tries its config files and reads title.json, then stops on its own "PSN: Failed to initialize the np toolkit" assertion, which is unrelated to the archive.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: CUSA12982
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • File and directory creation in archived content now returns appropriate errors: existing paths report EEXIST, attempts to create new items in read-only archive directories report EROFS, and invalid paths report errors such as ENOTDIR or ENOENT.
    • Opening an existing archived file with create mode continues to work, while attempts to create files or directories no longer leave entries in the archive.

… EEXIST and EROFS

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

Verified on Linux (Ubuntu 24.04, GCC 13.3, Ninja, Release) against 9acd90797b:

  • Conventions: tools/check_conventions.py passed.
  • Build: guest_app_archive_tests, guest_kernel_app_archive_tests built cleanly.
  • CTest (guest_app_archive_present, guest_app_archive_absent, guest_app_archive_damaged, guest_app_archive_invalid, guest_kernel_app_archive_archive, guest_kernel_app_archive_plain, guest_kernel_app_archive_mmap, guest_kernel_app_archive_mmap-failure, guest_kernel_app_archive_mmap-damaged):
    1/9 Test #1261: guest_app_archive_absent ................   Passed    0.00 sec
    2/9 Test #1260: guest_app_archive_present ...............   Passed    0.01 sec
    3/9 Test #1262: guest_app_archive_damaged ...............   Passed    0.01 sec
    4/9 Test #1263: guest_app_archive_invalid ...............   Passed    0.01 sec
    5/9 Test #6709: guest_kernel_app_archive_plain ..........   Passed    0.01 sec
    6/9 Test #6708: guest_kernel_app_archive_archive ........   Passed    0.01 sec
    7/9 Test #6711: guest_kernel_app_archive_mmap-failure ...   Passed    0.01 sec
    8/9 Test #6712: guest_kernel_app_archive_mmap-damaged ...   Passed    0.01 sec
    9/9 Test #6710: guest_kernel_app_archive_mmap ...........   Passed    0.49 sec
    100% tests passed, 0 tests failed out of 9
    
  • Negative control: with core/libs/prx/libc/include/AppArchive.hpp, core/libs/prx/libc/src/AppArchive.cpp, core/libs/prx/libc/src/FileAndHeap.cpp, core/libs/prx/libkernel/File/src/Open.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp reverted to main and the new tests kept, the suite fails:
    3/9 Test #6711: guest_kernel_app_archive_mmap-failure ...   Passed    0.01 sec
    4/9 Test #6709: guest_kernel_app_archive_plain ..........   Passed    0.01 sec
    5/9 Test #1260: guest_app_archive_present ...............***Failed    0.01 sec
    6/9 Test #1262: guest_app_archive_damaged ...............   Passed    0.01 sec
    7/9 Test #1263: guest_app_archive_invalid ...............   Passed    0.01 sec
    8/9 Test #1261: guest_app_archive_absent ................   Passed    0.00 sec
    9/9 Test #6710: guest_kernel_app_archive_mmap ...........   Passed    0.53 sec
    78% tests passed, 2 tests failed out of 9
    
    Restoring the change makes it pass again.
  • Code reading:
    • Verified AppArchiveCreateError_nid_no_patch normalizes path components and trailing separators via parent_path() loop, correctly identifying archive parent directory vs file.
    • Verified error codes (EROFS = 30 / SCE_KERNEL_ERROR_EROFS, ENOTDIR = 20 / SCE_KERNEL_ERROR_ENOTDIR, EEXIST = 17 / SCE_KERNEL_ERROR_EEXIST) match FreeBSD 11.4 VFS lookup specifications.
    • Verified sceKernelMkdir, mkdir, sceKernelOpen, and fopen integration across libc and libkernel without introducing unhandled exceptions or thread-safety issues.
    • Verified AGENTS.md compliance: debt documentation fragments in docs/dev/debt/changes/ added with proper structure, no forbidden code comments, and no title-specific hardcoding.

Looks Good To Me

@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: Archive creation error handling

Layer / File(s) Summary
Classify archive paths for file opens
core/libs/prx/libc/..., core/libs/prx/libkernel/File/src/Open.cpp, core/libs/tests/GuestAppArchive.cpp, docs/dev/debt/changes/fix-libkernel-app0-zar-mkdir.md
A shared helper classifies archive-only parent paths. libc write-capable fopen modes and libkernel opens with O_CREAT check the result. Tests cover archive-related fopen errors. The documentation records the stated fopen outcomes and console measurement limitation.
Check archive paths before directory creation
core/libs/prx/libkernel/File/src/Stdio.cpp, core/libs/tests/GuestKernelAppArchive.cpp, docs/dev/debt/changes/fix-libkernel-app0-zar-mkdir.md
Both mkdir paths check archive-specific errors before directory creation. Tests cover mkdir and open outcomes and confirm attempted entries remain absent. The documentation records the stated libkernel outcomes and examples.

Suggested reviewers: alexoftheforest, xxpbsxx, boykopovar

Change: Bug fix

Merge Risk: Minimal · up to 9acd9

This change makes archive-only app0 paths return read-only-mount-style errors without creating anything on the host. The tests cover the new cases. One small error-code difference remains for a trailing-separator edge case, which does not block merging.

Security architecture risk: Minimal · up to 9acd9

The inspected changes make creation requests fail earlier on archive-only paths. They change the errors applications receive without granting new write access or changing how existing host-backed writes are handled.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The new refusal affects guest-controlled create requests that reach the existing file and directory paths, including directory-relative opens that reuse OpenNative. It adds no new native write operation or archive mutation.

Trust Boundaries and Controls

  • observed — Both mkdir resolver variants use the same locked, archive-aware path resolution. The new check uses the existing archive lookup, which matches paths against the configured app0 root, and preserves host-entry precedence when classifying a target or parent as archive-only.

Resilience and Maintainability Implications

  • observed — The new refusal branches return before native creation, handle registration, or write tracking. A refused request therefore leaves no newly created object or handle to clean up or recover on retry.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2bd5c3bb-e2dd-4221-abd3-b23ca5aba2ac
Commits

Reviewing files that changed from the base of the PR and between bb89b8a and 9acd907.

Files selected for processing: 8

  • core/libs/prx/libc/include/AppArchive.hpp
  • core/libs/prx/libc/src/AppArchive.cpp
  • core/libs/prx/libc/src/FileAndHeap.cpp
  • core/libs/prx/libkernel/File/src/Open.cpp
  • core/libs/prx/libkernel/File/src/Stdio.cpp
  • core/libs/tests/GuestAppArchive.cpp
  • core/libs/tests/GuestKernelAppArchive.cpp
  • docs/dev/debt/changes/fix-libkernel-app0-zar-mkdir.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@JJenkx

JJenkx commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Linux check of the exact head 9acd90797b4c; the description has no Linux results. Arch Linux 7.3.5 x86-64, GCC 16.2.1, Release, -DBUILD_TESTING=ON:

  • ctest -R 'guest_(kernel_)?app_archive' (this PR's GuestAppArchive.cpp and GuestKernelAppArchive.cpp, every mode): 9 pass, 0 skipped.

AI-assisted: yes

@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 — no blocking findings

Nothing blocks this change based on the source reviewed; the test commands were not run.

What I ran

Inspected the prepared diff and all eight changed files at head 9acd90797b4c443f5ff2e53263125b84abcb7224. No test or build command was run.

Results

Check Result Note
Changed source review passed All changed files read
Tests and build not run No execution environment available

Negative control

Not run; no test execution was available.

Findings

Blocking

None identified in the source reviewed.

Non-blocking

None.

Sources

The implementation routes mkdir, O_CREAT and fopen creation attempts through the shared archive-parent check, while preserving archived-file lookup first. The added tests cover existing archive entries, archive-only parents, file parents, missing paths and host-side non-creation.

Not verified

The author-reported Windows and title runs were not independently verified. Changed files read: core/libs/prx/libc/include/AppArchive.hpp, core/libs/prx/libc/src/AppArchive.cpp, core/libs/prx/libc/src/FileAndHeap.cpp, core/libs/prx/libkernel/File/src/Open.cpp, core/libs/prx/libkernel/File/src/Stdio.cpp, core/libs/tests/GuestAppArchive.cpp, core/libs/tests/GuestKernelAppArchive.cpp, and docs/dev/debt/changes/fix-libkernel-app0-zar-mkdir.md. All eight files listed as reviewed in the manifest were read; files.json was not available in the prepared bundle.

To get this to a good state

Nothing is required.

@github-actions

github-actions Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

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 18190 core/libs/prx/libkernel/File/src/Stdio.cpp L1395-1397
PR 27855 core/libs/prx/libkernel/File/src/Open.cpp L349

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 6936 core/libs/prx/libkernel/File/src/Open.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
core/libs/tests/GuestKernelAppArchive.cpp
PR 7121 core/libs/prx/libkernel/File/src/Open.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 7447 core/libs/prx/libc/include/AppArchive.hpp
core/libs/prx/libc/src/AppArchive.cpp
core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9293 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9297 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 9302 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12682 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libkernel/File/src/Open.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12688 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libkernel/File/src/Open.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12700 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libkernel/File/src/Open.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 12965 core/libs/prx/libc/src/FileAndHeap.cpp
core/libs/prx/libkernel/File/src/Open.cpp
core/libs/prx/libkernel/File/src/Stdio.cpp
PR 15037 core/libs/prx/libkernel/File/src/Stdio.cpp
PR 24406 core/libs/prx/libc/src/FileAndHeap.cpp

@github-actions github-actions Bot added unblocks title Names a title ID on the Unblocks line review queue Next in the maintainer review queue: checks pass, no open change request, no conflict and removed review queue Next in the maintainer review queue: checks pass, no open change request, no conflict labels Nov 28, 2026
@B-Howell

B-Howell commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Windows check of head 9acd90797b, merged onto main 4131f5185a (clean merge).

Setup: Windows 11 Pro 10.0.26300, Ryzen 7 7800X3D, WinLibs GCC 15.2.0 r7, Ninja, Release, -DBUILD_TESTING=ON. No GPU used.

ctest --test-dir build -R "^guest_(app_archive|kernel_app_archive)" --repeat until-fail:3 --output-on-failure
  • With the change: guest_app_archive_present/absent/damaged/invalid and guest_kernel_app_archive_archive/plain/mmap-failure/mmap-damaged pass, 3/3 runs each.
  • guest_kernel_app_archive_mmap fails, but it fails the same way on plain main 4131f5185a on this machine: app0.zar kernel check failed at line 1048 on main, line 1067 here, which is the same TryMapping comparison moved down by the 19 new lines. Not caused by this PR.
  • Control (merge with AppArchive.hpp, AppArchive.cpp, FileAndHeap.cpp, Open.cpp and Stdio.cpp from main, tests kept): guest_app_archive_present fails with fopen creating a file in an archived directory did not report EROFS, and guest_kernel_app_archive_archive ends with reading /app0/Data in app0.zar not implemented.

Not run: any title.

AI-assisted: yes

@coderabbitai coderabbitai Bot mentioned this pull request Dec 2, 2026
12 tasks done
@oneandonlydean
oneandonlydean merged commit f8431d5 into boykopovar:main Dec 3, 2026
23 of 25 checks passed
@leskal
leskal deleted the fix/libkernel-app0-zar-mkdir branch December 3, 2026 22:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs libc libkernel unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants