feat(libkernel): export truncate and report EISDIR for a directory #3433

Merged
Feuris merged 1 commit from upstream-pr/3433 into main 2026-10-11 10:36:20 +00:00
Feuris commented 2026-10-11 10:29:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Feuris on 2026-10-11T10:29:49Z.


What

Carries @Mouad-Scriptz-0's #3181 (the author is under the intake threshold). The commit is theirs, unchanged (a584bc6a).

libkernel does not export the POSIX truncate (ayrtszI7GBg, confirmed against aerolib). An import audit of the homebrew catalog on main lists it as an absent import of three titles (PS5MC PPSA99420, XPSemu PPSA97358, Porpoise PPSA99764).

  • truncate_nid_postfix(path, length) in File/src/Stdio.cpp validates the path (EFAULT for null, ENOENT for empty) and resolves through sceKernelTruncate_nid_postfix.
  • sceKernelTruncate now returns EISDIR for a directory and the host errno for other failures instead of EIO, as FreeBSD 11 kern_truncate does (EINVAL for a negative length, EISDIR for a directory).
  • Native helpers: ::truncate on POSIX; _wopen(_O_WRONLY | _O_BINARY) + _chsize_s + _close on Windows.
  • New guest_truncate test covering shrinking, growing with zero-fill, truncate to 0, negative length (EINVAL), missing path (ENOENT), empty path (ENOENT), null path (EFAULT), directory (EISDIR), and read-only file (EACCES).

Closes #3181.

Tested

  • Windows 11, MinGW-w64 GCC 15.2.0: syntax and compilation verified; tools/check_conventions.py --base origin/main and git diff --check pass cleanly.
  • Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release, by original author): guest_truncate and guest_filesystem pass 3/3 (--repeat until-fail:3).
  • Import audit: absent count drops by exactly 1 for PS5MC, XPSemu, and Porpoise.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4818402311 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3433). Originally posted by [Feuris](https://github.com/Feuris) on 2026-10-11T10:29:49Z. --- ### What Carries @Mouad-Scriptz-0's #3181 (the author is under the intake threshold). The commit is theirs, unchanged (`a584bc6a`). libkernel does not export the POSIX `truncate` (`ayrtszI7GBg`, confirmed against aerolib). An import audit of the homebrew catalog on `main` lists it as an absent import of three titles (PS5MC PPSA99420, XPSemu PPSA97358, Porpoise PPSA99764). - `truncate_nid_postfix(path, length)` in `File/src/Stdio.cpp` validates the path (`EFAULT` for null, `ENOENT` for empty) and resolves through `sceKernelTruncate_nid_postfix`. - `sceKernelTruncate` now returns `EISDIR` for a directory and the host errno for other failures instead of `EIO`, as FreeBSD 11 `kern_truncate` does (`EINVAL` for a negative length, `EISDIR` for a directory). - Native helpers: `::truncate` on POSIX; `_wopen(_O_WRONLY | _O_BINARY)` + `_chsize_s` + `_close` on Windows. - New `guest_truncate` test covering shrinking, growing with zero-fill, truncate to 0, negative length (`EINVAL`), missing path (`ENOENT`), empty path (`ENOENT`), null path (`EFAULT`), directory (`EISDIR`), and read-only file (`EACCES`). Closes #3181. ### Tested - Windows 11, MinGW-w64 GCC 15.2.0: syntax and compilation verified; `tools/check_conventions.py --base origin/main` and `git diff --check` pass cleanly. - Fedora 44 (kernel 7.2.8, GCC 16.2.1, Ninja, Release, by original author): `guest_truncate` and `guest_filesystem` pass 3/3 (`--repeat until-fail:3`). - Import audit: absent count drops by exactly 1 for PS5MC, XPSemu, and Porpoise. ### Checklist - [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 in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [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] AI-assisted: yes
github-actions[bot] commented 2026-10-11 10:30:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T10:30:12Z.


Progress report (99c1c26 → a584bc6)

➖ System libraries: 85.76% (+0.0%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel truncate_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108090330 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3433#issuecomment-6108090330). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T10:30:12Z. --- <!-- progress-report --> ### Progress report (99c1c26 → a584bc6) ➖ **System libraries**: 85.76% (+0.0%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel | `truncate_nid_postfix` | </details>
adriadam10 commented 2026-10-11 10:36:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-11T10:36:17Z.


Checked on Linux (PR merged onto current main): guest_truncate and guest_filesystem pass, and guest_truncate fails to link without the Stdio.cpp change. EISDIR/host errno mapping matches FreeBSD kern_truncate; Windows path covered by danzaio's MinGW run. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6108136680 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3433#issuecomment-6108136680). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T10:36:17Z. --- Checked on Linux (PR merged onto current main): `guest_truncate` and `guest_filesystem` pass, and `guest_truncate` fails to link without the Stdio.cpp change. `EISDIR`/host errno mapping matches FreeBSD `kern_truncate`; Windows path covered by danzaio's MinGW run. Merging.
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!3433
No description provided.