libkernel debt: note how a title calls sceKernelFtruncate #10120

Closed
opened 2026-10-23 09:58:03 +00:00 by xXPBSXx · 0 comments
xXPBSXx commented 2026-10-23 09:58:03 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-23T09:58:03Z.


The debt entry in docs/dev/debt/libkernel.md does not record how a title calls the function. A title call site adds this (call-site addresses included so the reading can be checked).

The changed entry now reads:

ftruncate, truncate, sceKernelFtruncate (libkernel) extend a file on Windows with SetFileInformationByHandle (FileEndOfFileInfo), which reserves the clusters but writes no zero bytes, and report EFBIG for a length the volume cannot hold (ERROR_INVALID_PARAMETER on a disk file; seen with a length of INT64_MAX, the size from which NTFS refuses it was not measured) and ENOSPC when the free space is smaller. FreeBSD 11.4 makes the extension a hole on a file system that has them (ffs_truncate writes only the last block), so a length above the free space succeeds there. A write behind the end of the file still makes NTFS write zero bytes over the gap, as the file is not sparse. None of this was measured on a console. One title (PPSA04354) disassembled for this entry calls sceKernelFtruncate once (0xe9d4f2) with a 32-bit descriptor from an object field and a 64-bit length read from memory, and tests only the sign of the result: a negative one makes its function return 0 and store 14 in the object, whatever the error. Which lengths it passes was not examined.

Fix: branch docs/debt-kernel-ftruncate-title.

AI-assisted (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5995727635 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/10120). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-23T09:58:03Z. --- The debt entry in `docs/dev/debt/libkernel.md` does not record how a title calls the function. A title call site adds this (call-site addresses included so the reading can be checked). The changed entry now reads: > [ftruncate, truncate, sceKernelFtruncate](../../../core/libs/prx/libkernel/File/src/Stdio.cpp) (libkernel) extend a file on Windows with `SetFileInformationByHandle` (`FileEndOfFileInfo`), which reserves the clusters but writes no zero bytes, and report `EFBIG` for a length the volume cannot hold (`ERROR_INVALID_PARAMETER` on a disk file; seen with a length of `INT64_MAX`, the size from which NTFS refuses it was not measured) and `ENOSPC` when the free space is smaller. FreeBSD 11.4 makes the extension a hole on a file system that has them ([`ffs_truncate`](https://github.com/freebsd/freebsd-src/blob/release/11.4.0/sys/ufs/ffs/ffs_inode.c) writes only the last block), so a length above the free space succeeds there. A write behind the end of the file still makes NTFS write zero bytes over the gap, as the file is not sparse. None of this was measured on a console. One title (PPSA04354) disassembled for this entry calls `sceKernelFtruncate` once (0xe9d4f2) with a 32-bit descriptor from an object field and a 64-bit length read from memory, and tests only the sign of the result: a negative one makes its function return 0 and store 14 in the object, whatever the error. Which lengths it passes was not examined. Fix: branch `docs/debt-kernel-ftruncate-title`. AI-assisted (Claude Code).
Sign in to join this conversation.
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#10120
No description provided.