Skip to content

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

Closed
MarcZX10 wants to merge 3 commits into
boykopovar:mainfrom
MarcZX10:codex/carry-open-rdonly-trunc-5095
Closed

MarcZX10 wants to merge 3 commits into
boykopovar:mainfrom
MarcZX10:codex/carry-open-rdonly-trunc-5095

Conversation

@MarcZX10

Copy link
Copy Markdown
Contributor

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

@likecrank-dotcom

Copy link
Copy Markdown

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

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

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

@oneandonlydean

Copy link
Copy Markdown
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libkernel: open with O_RDONLY|O_TRUNC fails with EINVAL on Windows, where FreeBSD truncates the file; fix branch ready

4 participants