feat(libkernel_sys): implement fpathconf and _fpathconf #6525

Closed
QuentinRemond wants to merge 1 commit from upstream-pr/6525 into main
QuentinRemond commented 2026-10-15 18:45:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by QuentinRemond on 2026-10-15T18:45:03Z.


What

Implement fpathconf and _fpathconf in libkernel_sys. They validate the descriptor using DescriptorIsOpen_nid_no_patch (EBADF if invalid or closed) and report the FreeBSD 11 UFS constants matching pathconf (_PC_LINK_MAX 32767, _PC_NAME_MAX 255, _PC_PATH_MAX and _PC_SYMLINK_MAX 1024, _PC_PIPE_BUF 512, _PC_CHOWN_RESTRICTED and _PC_NO_TRUNC 1, _PC_FILESIZEBITS 64, _PC_REC_MAX_XFER_SIZE -1, _PC_PRIO_IO and _PC_SYNC_IO 0). Mount- or kernel-dependent names throw, and unknown names fail with EINVAL.

Tested

Linux x86_64 (Fedora): configured with -DBUILD_TESTING=ON; built libs (all 126 PRXs patched OK) and guest_kernel_sys_tests. ctest guest_kernel_sys passed (asserting values on open file descriptor, open directory descriptor, invalid descriptor, and closed descriptor). python3 tools/check_conventions.py --base origin/main passed.

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
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4878194634 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6525). Originally posted by [QuentinRemond](https://github.com/QuentinRemond) on 2026-10-15T18:45:03Z. --- ### What Implement `fpathconf` and `_fpathconf` in `libkernel_sys`. They validate the descriptor using `DescriptorIsOpen_nid_no_patch` (`EBADF` if invalid or closed) and report the FreeBSD 11 UFS constants matching `pathconf` (`_PC_LINK_MAX` 32767, `_PC_NAME_MAX` 255, `_PC_PATH_MAX` and `_PC_SYMLINK_MAX` 1024, `_PC_PIPE_BUF` 512, `_PC_CHOWN_RESTRICTED` and `_PC_NO_TRUNC` 1, `_PC_FILESIZEBITS` 64, `_PC_REC_MAX_XFER_SIZE` -1, `_PC_PRIO_IO` and `_PC_SYNC_IO` 0). Mount- or kernel-dependent names throw, and unknown names fail with `EINVAL`. ### Tested Linux x86_64 (Fedora): configured with `-DBUILD_TESTING=ON`; built `libs` (all 126 PRXs patched OK) and `guest_kernel_sys_tests`. ctest `guest_kernel_sys` passed (asserting values on open file descriptor, open directory descriptor, invalid descriptor, and closed descriptor). `python3 tools/check_conventions.py --base origin/main` passed. ### 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 - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's technical 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] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes
jotitadev commented 2026-10-19 01:27:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T01:27:47Z.

Review: COMMENTED


Linux run of 8c2943089 on current main. Two problems: the merge no longer compiles, and once that is fixed libkernel_sys.prx no longer loads.

Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, BUILD_TESTING=ON, full build. Head 8c2943089 merged onto main ad502d717. Git merges it without conflicts.

  • The merge does not compile. libkernel_sys/Export.cpp:60: error: redefinition of 'constexpr const int {anonymous}::GuestEbadf'. #6411 (fchown, merged as ce8c71a78) added the same constexpr int GuestEbadf = 9; two lines above, so the branch needs a rebase that drops its copy. #6411 also added a local GuestFstat(fd) helper in the same file, which could be useful for the next point.
  • With the duplicate line removed, patched_libraries fails (main passes):
    /.../build/core/libs/libs/libkernel_sys.prx: undefined symbol: _Z29DescriptorIsOpen_nid_no_patchi
    129 patched libraries loaded, 1 failed
    
    DescriptorIsOpen_nid_no_patch is declared in File.hpp as a plain C++ function (no extern "C") and lives in libkernel (Stdio.cpp). nm -D --defined-only finds it in libs/unpatched/libkernel.prx but not in the patched libs/libkernel.prx. The other cross-library helpers that libkernel_sys already uses, like GetDirectoryDescriptorPath_nid_no_patch, are extern "C" and are still exported after patching. This PR doesn't touch libkernel, so the same unresolved symbol should be there on its own base too. guest_kernel_sys still passes because it loads the unpatched libs/unpatched/libkernel_sys.prx and libkernel.prx (per ldd), so the new test doesn't catch this. One way out is to check the descriptor with something libkernel_sys can already reach, such as #6411's GuestFstat.
  • Everything else is green. guest_kernel_sys passes, and the rest of the non-GPU suite (ctest -E "^agc|gpu|vulkan|video_out" -j6) matches main: 746/747, and the only failure is patched_libraries. The test file alone on main does not link (undefined reference to fpathconf_nid_postfix), as expected.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5566073114 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6525#pullrequestreview-5566073114). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T01:27:47Z. **Review:** COMMENTED --- Linux run of `8c2943089` on current `main`. Two problems: the merge no longer compiles, and once that is fixed `libkernel_sys.prx` no longer loads. Machine: Linux x86_64, i7-8700, Ubuntu 26.04, GCC 15.2, Release, `BUILD_TESTING=ON`, full build. Head `8c2943089` merged onto `main` `ad502d717`. Git merges it without conflicts. - **The merge does not compile.** `libkernel_sys/Export.cpp:60: error: redefinition of 'constexpr const int {anonymous}::GuestEbadf'`. #6411 (`fchown`, merged as `ce8c71a78`) added the same `constexpr int GuestEbadf = 9;` two lines above, so the branch needs a rebase that drops its copy. #6411 also added a local `GuestFstat(fd)` helper in the same file, which could be useful for the next point. - **With the duplicate line removed, `patched_libraries` fails** (`main` passes): ``` /.../build/core/libs/libs/libkernel_sys.prx: undefined symbol: _Z29DescriptorIsOpen_nid_no_patchi 129 patched libraries loaded, 1 failed ``` `DescriptorIsOpen_nid_no_patch` is declared in `File.hpp` as a plain C++ function (no `extern "C"`) and lives in `libkernel` (`Stdio.cpp`). `nm -D --defined-only` finds it in `libs/unpatched/libkernel.prx` but not in the patched `libs/libkernel.prx`. The other cross-library helpers that `libkernel_sys` already uses, like `GetDirectoryDescriptorPath_nid_no_patch`, are `extern "C"` and are still exported after patching. This PR doesn't touch `libkernel`, so the same unresolved symbol should be there on its own base too. `guest_kernel_sys` still passes because it loads the unpatched `libs/unpatched/libkernel_sys.prx` and `libkernel.prx` (per `ldd`), so the new test doesn't catch this. One way out is to check the descriptor with something `libkernel_sys` can already reach, such as #6411's `GuestFstat`. - Everything else is green. `guest_kernel_sys` passes, and the rest of the non-GPU suite (`ctest -E "^agc|gpu|vulkan|video_out" -j6`) matches `main`: 746/747, and the only failure is `patched_libraries`. The test file alone on `main` does not link (`undefined reference to fpathconf_nid_postfix`), as expected. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
github-actions[bot] commented 2026-10-19 03:39:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-19T03:39:36Z.


Progress report (e8ad642 → 8c29430)

📈 System libraries: 90.77% (+0.01%, +2 implemented functions)

✅ 2 implemented
Library Name
libkernel_sys _fpathconf_nid_postfix
libkernel_sys fpathconf_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6259131585 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6525#issuecomment-6259131585). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-19T03:39:36Z. --- <!-- progress-report --> ### Progress report (e8ad642 → 8c29430) 📈 **System libraries**: 90.77% (+0.01%, +2 implemented functions) <details> <summary>✅ 2 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `_fpathconf_nid_postfix` | | libkernel_sys | `fpathconf_nid_postfix` | </details>
adriadam10 commented 2026-10-19 03:39:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T03:39:49Z.

Review: CHANGES_REQUESTED


Thanks, the refactor into PathConfigurationValue is clean. Two blocking problems on the merged tree (confirmed against current main, and matching @jotitadev's run):

  • core/libs/prx/libkernel_sys/Export.cpp:60: constexpr int GuestEbadf = 9; is already defined at line 58 since #6411 (fchown), so the merge fails with redefinition of 'GuestEbadf'. Rebase on main and drop your copy.
  • core/libs/prx/libkernel_sys/Export.cpp:343: DescriptorIsOpen_nid_no_patch is a plain C++ function in libkernel (not extern "C"), so it is not exported by the patched libkernel.prx and libkernel_sys.prx fails to load (undefined symbol: _Z29DescriptorIsOpen_nid_no_patchi, patched_libraries fails; guest_kernel_sys does not catch it because it loads the unpatched PRXs). Validate the descriptor with something libkernel_sys already reaches, as fchown does: GuestFstat(fd) != 0 on Windows and ::fstat(fd, &status) != 0 on Linux, returning EBADF. The test's closed/invalid descriptor cases already cover it.

Once it builds and patched_libraries passes, this looks good to merge.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5566644784 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6525#pullrequestreview-5566644784). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T03:39:49Z. **Review:** CHANGES_REQUESTED --- Thanks, the refactor into `PathConfigurationValue` is clean. Two blocking problems on the merged tree (confirmed against current `main`, and matching @jotitadev's run): - `core/libs/prx/libkernel_sys/Export.cpp:60`: `constexpr int GuestEbadf = 9;` is already defined at line 58 since #6411 (`fchown`), so the merge fails with `redefinition of 'GuestEbadf'`. Rebase on `main` and drop your copy. - `core/libs/prx/libkernel_sys/Export.cpp:343`: `DescriptorIsOpen_nid_no_patch` is a plain C++ function in `libkernel` (not `extern "C"`), so it is not exported by the patched `libkernel.prx` and `libkernel_sys.prx` fails to load (`undefined symbol: _Z29DescriptorIsOpen_nid_no_patchi`, `patched_libraries` fails; `guest_kernel_sys` does not catch it because it loads the unpatched PRXs). Validate the descriptor with something `libkernel_sys` already reaches, as `fchown` does: `GuestFstat(fd) != 0` on Windows and `::fstat(fd, &status) != 0` on Linux, returning `EBADF`. The test's closed/invalid descriptor cases already cover it. Once it builds and `patched_libraries` passes, this looks good to merge.

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