fix(libkernel): truncate Windows files opened read-only #5684

Closed
MarcZX10 wants to merge 3 commits from upstream-pr/5684 into main
MarcZX10 commented 2026-10-14 06:27:36 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T06:27:36Z.


Fixes #5095.

What

On Windows, CreateFileW rejects TRUNCATE_EXISTING with GENERIC_READ alone, so open(path, O_RDONLY | O_TRUNC) fails instead of truncating. For that flag combination, open with the access needed to truncate, then narrow the resulting handle to read-only. This matches the FreeBSD/Linux behavior while keeping the guest descriptor read-only. The implementation records the remaining Windows host sharing difference in technical debt.

The three commits carry David’s implementation, regression, and debt update with his original commit authorship preserved.

Tested

  • Linux, GCC 12.2, Release: build succeeded; guest_filesystem and guest_kernel_fcntl passed (2/2).
  • tools/check_conventions.py --base upstream/main passed.
  • Windows-specific regression matrix is documented in #5095; it was not rerun locally.

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-path policy: not applicable; no new unimplemented path
  • No notes, investigation files, or images added
  • No third-party code added
  • Generic behavior, not title-specific
  • Depends on: none
  • Unblocks: none identified in #5095
  • GPUs tested: n/a
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4853894128 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5684). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T06:27:36Z. --- Fixes #5095. ### What On Windows, `CreateFileW` rejects `TRUNCATE_EXISTING` with `GENERIC_READ` alone, so `open(path, O_RDONLY | O_TRUNC)` fails instead of truncating. For that flag combination, open with the access needed to truncate, then narrow the resulting handle to read-only. This matches the FreeBSD/Linux behavior while keeping the guest descriptor read-only. The implementation records the remaining Windows host sharing difference in technical debt. The three commits carry David’s implementation, regression, and debt update with his original commit authorship preserved. ### Tested - Linux, GCC 12.2, Release: build succeeded; `guest_filesystem` and `guest_kernel_fcntl` passed (2/2). - `tools/check_conventions.py --base upstream/main` passed. - Windows-specific regression matrix is documented in #5095; it was not rerun locally. ### 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-path policy: not applicable; no new unimplemented path - [x] No notes, investigation files, or images added - [x] No third-party code added - [x] Generic behavior, not title-specific - [x] Depends on: none - [x] Unblocks: none identified in #5095 - [x] GPUs tested: n/a - [x] AI-assisted: yes
github-actions[bot] commented 2026-10-14 06:32:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T06:32:19Z.


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
#5434 core/libs/tests/GuestFilesystem.cpp L232, L235
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6162404907 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5684#issuecomment-6162404907). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T06:32:19Z. --- <!-- 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 | |---|---|---|---| | #5434 | `core/libs/tests/GuestFilesystem.cpp` [L232](https://github.com/boykopovar/AnyPS5/blob/1e7272196389c30eff9af9e91a51c72d781f46c6/core/libs/tests/GuestFilesystem.cpp#L232), [L235](https://github.com/boykopovar/AnyPS5/blob/1e7272196389c30eff9af9e91a51c72d781f46c6/core/libs/tests/GuestFilesystem.cpp#L235) | | |
MarcZX10 commented 2026-10-14 06:33:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-14T06:33:05Z.


Closing this duplicate: it carries the same Windows O_RDONLY|O_TRUNC fix already reviewed in #5112. The maintainer closed #5112 because no title-specific failure was identified and asked contributors to hold generic PRs while the queue is high. I should have found that history before opening this PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6162416329 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5684#issuecomment-6162416329). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-14T06:33:05Z. --- Closing this duplicate: it carries the same Windows O_RDONLY|O_TRUNC fix already reviewed in #5112. The maintainer closed #5112 because no title-specific failure was identified and asked contributors to hold generic PRs while the queue is high. I should have found that history before opening this PR.

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