feat(libkernel_sys): implement link #3403

Merged
babyhuey merged 1 commit from upstream-pr/3403 into main 2026-10-11 10:06:52 +00:00
babyhuey commented 2026-10-11 09:44:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by babyhuey on 2026-10-11T09:44:19Z.


What

Exports link (Pd7KtJ1gybk) from libkernel_sys, the module the title imports it from, next to readlink. It maps both guest paths like the other path functions and creates a hard link on the host (std::filesystem::create_hard_link). Errors follow FreeBSD's link(2), returned as -1 with errno:

  • a null path gives EFAULT and an empty one ENOENT, as for readlink
  • a missing existing path, or a missing directory for the new name, gives ENOENT
  • a directory as the existing path gives EPERM
  • a new name that already exists gives EEXIST
  • a link across devices gives EXDEV

A symbolic link as the existing path throws, since FreeBSD's link follows it and the host call may not; any other host failure throws as well.

PS5VR (PPSA99177) stops at it on main a73a1af9 (catalog build, eboot.bin and sce_module/libc.prx unwrapped as #2605 requires; tracked in #1578):

  • Linux: app.elf: symbol lookup error: app.elf: undefined symbol: Pd7KtJ1gybk
  • Windows: FAIL: unresolved ELF import Pd7KtJ1gybk (link) from libkernel_sys.prx
  • with this PR, Linux: app.elf: symbol lookup error: app.elf: undefined symbol: +rWFNYiNaEM (fstatfs)
  • with this PR, Windows: FAIL: unresolved ELF import +rWFNYiNaEM (fstatfs) from libkernel_sys.prx

Tested

Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs, NTFS), Release: guest_kernel_sys passes 5/5 (--repeat until-fail:5) on both, with no warnings in Export.cpp or GuestKernelSys.cpp. The new cases link a 3-byte file, check the link count is 2 and the new name has the same size, truncate through the new name and check the original is truncated too, then check each error above (except EXDEV) through errno, and that removing the new name brings the count back to 1. check_conventions.py passes. The first version exported link from libkernel; a Windows run showed the title imports it from libkernel_sys, so it moved there.

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:4818138697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3403). Originally posted by [babyhuey](https://github.com/babyhuey) on 2026-10-11T09:44:19Z. --- ### What Exports `link` (`Pd7KtJ1gybk`) from libkernel_sys, the module the title imports it from, next to `readlink`. It maps both guest paths like the other path functions and creates a hard link on the host (`std::filesystem::create_hard_link`). Errors follow FreeBSD's `link(2)`, returned as -1 with `errno`: - a null path gives `EFAULT` and an empty one `ENOENT`, as for `readlink` - a missing existing path, or a missing directory for the new name, gives `ENOENT` - a directory as the existing path gives `EPERM` - a new name that already exists gives `EEXIST` - a link across devices gives `EXDEV` A symbolic link as the existing path throws, since FreeBSD's `link` follows it and the host call may not; any other host failure throws as well. PS5VR (PPSA99177) stops at it on `main` a73a1af9 (catalog build, `eboot.bin` and `sce_module/libc.prx` unwrapped as #2605 requires; tracked in #1578): - Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: Pd7KtJ1gybk` - Windows: `FAIL: unresolved ELF import Pd7KtJ1gybk (link) from libkernel_sys.prx` - with this PR, Linux: `app.elf: symbol lookup error: app.elf: undefined symbol: +rWFNYiNaEM` (`fstatfs`) - with this PR, Windows: `FAIL: unresolved ELF import +rWFNYiNaEM (fstatfs) from libkernel_sys.prx` ### Tested Linux (Ubuntu 24.04, GCC 13) and Windows 11 (MinGW-w64 GCC 15.2 from WinLibs, NTFS), Release: `guest_kernel_sys` passes 5/5 (`--repeat until-fail:5`) on both, with no warnings in `Export.cpp` or `GuestKernelSys.cpp`. The new cases link a 3-byte file, check the link count is 2 and the new name has the same size, truncate through the new name and check the original is truncated too, then check each error above (except `EXDEV`) through `errno`, and that removing the new name brings the count back to 1. `check_conventions.py` passes. The first version exported `link` from libkernel; a Windows run showed the title imports it from libkernel_sys, so it moved there. ### 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 09:47:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T09:47:09Z.


Progress report (a73a1af → 0e8dc6f)

📈 System libraries: 85.45% (+0.01%, +1 implemented functions)

✅ 1 implemented
Library Name
libkernel_sys link_nid_postfix
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107727930 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3403#issuecomment-6107727930). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T09:47:09Z. --- <!-- progress-report --> ### Progress report (a73a1af → 0e8dc6f) 📈 **System libraries**: 85.45% (+0.01%, +1 implemented functions) <details> <summary>✅ 1 implemented</summary> | Library | Name | | - | - | | libkernel_sys | `link_nid_postfix` | </details>
github-actions[bot] commented 2026-10-11 09:52:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-11T09:52:01Z.


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
#3392 core/libs/prx/libkernel_sys/Export.cpp L18-19, L67
core/libs/tests/GuestKernelSys.cpp L13-14, L61
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107762893 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3403#issuecomment-6107762893). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-11T09:52:01Z. --- <!-- pr-overlap --> 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 | |---|---|---|---| | #3392 | `core/libs/prx/libkernel_sys/Export.cpp` [L18-19](https://github.com/boykopovar/AnyPS5/blob/8ec0e13109f5cacee0d69bd4195f4ef25060d007/core/libs/prx/libkernel_sys/Export.cpp#L18-L19), [L67](https://github.com/boykopovar/AnyPS5/blob/8ec0e13109f5cacee0d69bd4195f4ef25060d007/core/libs/prx/libkernel_sys/Export.cpp#L67)<br>`core/libs/tests/GuestKernelSys.cpp` [L13-14](https://github.com/boykopovar/AnyPS5/blob/8ec0e13109f5cacee0d69bd4195f4ef25060d007/core/libs/tests/GuestKernelSys.cpp#L13-L14), [L61](https://github.com/boykopovar/AnyPS5/blob/8ec0e13109f5cacee0d69bd4195f4ef25060d007/core/libs/tests/GuestKernelSys.cpp#L61) | | |
adriadam10 commented 2026-10-11 10:06:48 +00:00 (Migrated from github.com)

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


Checked build and guest_kernel_sys on Linux (libs scope, 17/17 pass); the new cases don't link without the change. Errors match FreeBSD link(2) (EPERM on directories, EEXIST, ENOENT, EFAULT); symlink source and other host failures throw. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6107891646 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/3403#issuecomment-6107891646). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-11T10:06:48Z. --- Checked build and `guest_kernel_sys` on Linux (libs scope, 17/17 pass); the new cases don't link without the change. Errors match FreeBSD `link(2)` (EPERM on directories, EEXIST, ENOENT, EFAULT); symlink source and other host failures throw. 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!3403
No description provided.