fix(libkernel): report EISDIR for path truncation #2086

Closed
STUPIDCONTEM wants to merge 1 commit from upstream-pr/2086 into main
STUPIDCONTEM commented 2026-10-09 07:33:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by STUPIDCONTEM on 2026-10-09T07:33:48Z.


Evidence review (2026-10-09)

Game/title evidence has not been established. Validation below is host regression/build evidence only; it does not establish title compatibility. Older checked items and test results describe their stated revisions, not current merge readiness.

Game/title ID: none verified. No PS5 title execution is claimed.

What

Path-based sceKernelTruncate now returns encoded EISDIR for an existing directory instead of collapsing the resize failure to EIO. On Windows, filesystem resize reports a generic permission error for this case, so recognize a directory only after a successful status query. Keep the existing negative-length check first and leave other resize-error mappings unchanged.

The behavior and negative-length precedence are verified in FreeBSD stable/11 kern_truncate: negative lengths fail before path lookup; a resolved directory is rejected with EISDIR before ordinary write checks. This is a narrow directory classification fix, not a complete rewrite of path-truncation error handling or host filesystem race semantics.

Tested

Windows 10 Pro 19045, WinLibs GCC 15.2.0 UCRT posix SEH r7, Release, BUILD_TESTING=ON; independent branch from main f145139676.

  • GuestFilesystem verifies directory truncation returns encoded EISDIR, preserves guest errno and leaves the directory intact. Negative length still takes precedence with encoded EINVAL and unchanged guest errno.
  • Regular-file path truncation covers shrinking, preserved prefix bytes, growth size and zero-filled new bytes. Existing missing-path behavior is retained.
  • The directory-error regression fails on unchanged upstream. Parent corrected temporary-directory cleanup so the pre-existing root-removal test remains meaningful. Three focused runs passed, default and explicit libs builds passed, and full CTest passed 488/488 in 25.55 seconds.
  • Parent reviewed the kernel source and final change; independent review checked status-query failure guarding, symlink-following behavior and test lifetime. Conventions, whitespace and test registration passed.

No Linux or title run was performed for this branch. #2041 fixes descriptor-based ftruncate and uses a different path; #2001 removes write-watch recording in the same function but does not implement this directory-error behavior. No open PR duplicating this change was found.

Checklist

  • Based on current main; no other open PR implements the same change (historical base; current readiness not asserted)
  • One topic per PR; follow-ups go in a new PR
  • No comments added to code
  • No silent stubs added
  • No investigation notes, reports or images added to the repository
  • No third-party code added
  • Generic behavior, not specific to one title
  • Depends on: none
  • AI-assisted: yes; parent independently reviewed and tested the final change
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4797501078 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2086). Originally posted by [STUPIDCONTEM](https://github.com/STUPIDCONTEM) on 2026-10-09T07:33:48Z. --- ### Evidence review (2026-10-09) Game/title evidence has not been established. Validation below is host regression/build evidence only; it does not establish title compatibility. Older checked items and test results describe their stated revisions, not current merge readiness. Game/title ID: **none verified**. No PS5 title execution is claimed. ### What Path-based sceKernelTruncate now returns encoded EISDIR for an existing directory instead of collapsing the resize failure to EIO. On Windows, filesystem resize reports a generic permission error for this case, so recognize a directory only after a successful status query. Keep the existing negative-length check first and leave other resize-error mappings unchanged. The behavior and negative-length precedence are verified in [FreeBSD stable/11 kern_truncate](https://github.com/freebsd/freebsd-src/blob/stable/11/sys/kern/vfs_syscalls.c#L3022-L3061): negative lengths fail before path lookup; a resolved directory is rejected with EISDIR before ordinary write checks. This is a narrow directory classification fix, not a complete rewrite of path-truncation error handling or host filesystem race semantics. ### Tested Windows 10 Pro 19045, WinLibs GCC 15.2.0 UCRT posix SEH r7, Release, BUILD_TESTING=ON; independent branch from main f145139676a48306681d3a4d5fabf83938759daf. - GuestFilesystem verifies directory truncation returns encoded EISDIR, preserves guest errno and leaves the directory intact. Negative length still takes precedence with encoded EINVAL and unchanged guest errno. - Regular-file path truncation covers shrinking, preserved prefix bytes, growth size and zero-filled new bytes. Existing missing-path behavior is retained. - The directory-error regression fails on unchanged upstream. Parent corrected temporary-directory cleanup so the pre-existing root-removal test remains meaningful. Three focused runs passed, default and explicit libs builds passed, and full CTest passed 488/488 in 25.55 seconds. - Parent reviewed the kernel source and final change; independent review checked status-query failure guarding, symlink-following behavior and test lifetime. Conventions, whitespace and test registration passed. No Linux or title run was performed for this branch. #2041 fixes descriptor-based ftruncate and uses a different path; #2001 removes write-watch recording in the same function but does not implement this directory-error behavior. No open PR duplicating this change was found. ### Checklist - [ ] Based on current main; no other open PR implements the same change (historical base; current readiness not asserted) - [x] One topic per PR; follow-ups go in a new PR - [x] No comments added to code - [x] No silent stubs added - [x] No investigation notes, reports or images added to the repository - [x] No third-party code added - [x] Generic behavior, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes; parent independently reviewed and tested the final change

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