fix(libkernel): truncate with O_RDONLY on Windows #5112

Closed
MarcZX10 wants to merge 3 commits from upstream-pr/5112 into main
MarcZX10 commented 2026-10-13 12:02:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T12:02:02Z.


Closes #5095

What

Carry the three commits from David Samir's ready fix branch, preserving their original commit authorship. On Windows, opening an existing file with O_RDONLY | O_TRUNC currently passes GENERIC_READ with TRUNCATE_EXISTING, which CreateFileW rejects. For this flag combination, open with read/write access so truncation succeeds, then duplicate the handle with read-only access and close the original. Other flag combinations are unchanged.

Add TestReadOnlyTruncatingOpen to guest_filesystem to verify truncation through another open descriptor, read-only behavior of the returned descriptor, missing-file and directory errors, and EACCES for a read-only file. Record the remaining Windows host sharing limitation in technical debt.

Tested

  • Linux x86-64, GCC 12.2.0, Release: configured the full build, built guest_filesystem_tests, and ran guest_filesystem three times; all three passed.
  • tools/check_conventions.py --base upstream/main and git diff --check pass.
  • The issue author reports Windows 11 / WinLibs GCC 15.2.0 validation on the original branch: the regression failed on the baseline and passed five consecutive runs with the fix; full ctest --parallel 4 passed 1051/1051. That Windows run predates this rebase and was not repeated here.

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 or are recorded in technical debt
  • No investigation notes or images added
  • No new third-party code
  • Generic behavior, not title-specific
  • Depends on: none
  • Unblocks: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4842904641 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5112). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T12:02:02Z. --- Closes #5095 ### What Carry the three commits from David Samir's ready fix branch, preserving their original commit authorship. On Windows, opening an existing file with `O_RDONLY | O_TRUNC` currently passes `GENERIC_READ` with `TRUNCATE_EXISTING`, which `CreateFileW` rejects. For this flag combination, open with read/write access so truncation succeeds, then duplicate the handle with read-only access and close the original. Other flag combinations are unchanged. Add `TestReadOnlyTruncatingOpen` to `guest_filesystem` to verify truncation through another open descriptor, read-only behavior of the returned descriptor, missing-file and directory errors, and `EACCES` for a read-only file. Record the remaining Windows host sharing limitation in technical debt. ### Tested - Linux x86-64, GCC 12.2.0, Release: configured the full build, built `guest_filesystem_tests`, and ran `guest_filesystem` three times; all three passed. - `tools/check_conventions.py --base upstream/main` and `git diff --check` pass. - The issue author reports Windows 11 / WinLibs GCC 15.2.0 validation on the original branch: the regression failed on the baseline and passed five consecutive runs with the fix; full `ctest --parallel 4` passed 1051/1051. That Windows run predates this rebase and was not repeated here. ### 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 or are recorded in technical debt - [x] No investigation notes or images added - [x] No new third-party code - [x] Generic behavior, not title-specific - [x] Depends on: none - [x] Unblocks: none - [x] AI-assisted: yes
likecrank-dotcom commented 2026-10-13 13:57:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by likecrank-dotcom on 2026-10-13T13:57:07Z.


Independent Windows validation of the current PR head 8ac4ae7a2a735872f5bc47393083b3461c2e863a (Windows native, WinLibs MinGW GCC 15.2.0, CMake 4.4.4):

  • Built guest_filesystem_tests and the adjacent truncate, dup, file-vector, fcntl, and file-lock test executables.
  • guest_filesystem passed 5/5 with --repeat until-fail:5.
  • The focused selection guest_filesystem, guest_truncate, guest_dup, guest_file_vector, guest_kernel_fcntl, and all six guest_file_lock_* cases passed 11/11, each repeated three times (33 executions).
  • tools/check_conventions.py --base origin/main --head HEAD and git diff --check origin/main...HEAD passed.

This was a targeted test build only; no full native build or title runtime was run. No changes were made to the PR branch.

AI-assisted verification: OpenAI Codex. The PR author remains responsible for the submitted implementation.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6147218082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5112#issuecomment-6147218082). Originally posted by [likecrank-dotcom](https://github.com/likecrank-dotcom) on 2026-10-13T13:57:07Z. --- Independent Windows validation of the current PR head `8ac4ae7a2a735872f5bc47393083b3461c2e863a` (Windows native, WinLibs MinGW GCC 15.2.0, CMake 4.4.4): - Built `guest_filesystem_tests` and the adjacent truncate, dup, file-vector, fcntl, and file-lock test executables. - `guest_filesystem` passed 5/5 with `--repeat until-fail:5`. - The focused selection `guest_filesystem`, `guest_truncate`, `guest_dup`, `guest_file_vector`, `guest_kernel_fcntl`, and all six `guest_file_lock_*` cases passed 11/11, each repeated three times (33 executions). - `tools/check_conventions.py --base origin/main --head HEAD` and `git diff --check origin/main...HEAD` passed. This was a targeted test build only; no full native build or title runtime was run. No changes were made to the PR branch. AI-assisted verification: OpenAI Codex. The PR author remains responsible for the submitted implementation.
github-actions[bot] commented 2026-10-13 15:18:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-13T15:18:53Z.


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 L219, L222
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148886697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5112#issuecomment-6148886697). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-13T15:18:53Z. --- <!-- 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` [L219](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/core/libs/tests/GuestFilesystem.cpp#L219), [L222](https://github.com/boykopovar/AnyPS5/blob/0df6e295c52e7cd6afa394ed35513bd252045c74/core/libs/tests/GuestFilesystem.cpp#L222) | | |
oneandonlydean commented 2026-10-14 02:33:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:33:19Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159592076 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5112#issuecomment-6159592076). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:33:19Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

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