Skip to content

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

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

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

Conversation

@MarcZX10

Copy link
Copy Markdown
Contributor

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

Checklist

@github-actions

github-actions Bot commented Oct 14, 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 L232, L235

@MarcZX10

Copy link
Copy Markdown
Contributor Author

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.

@MarcZX10 MarcZX10 closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

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

2 participants