Add Windows raw disk support and image inspection#1
Merged
Conversation
Boot fixes: - Warn before burning images that cannot boot from a raw copy (no MBR/GPT), with a specific message for Windows installer ISOs - the classic case where a dd-style copy silently produces a non-booting stick. - Windows: actually lock and dismount every volume on the target disk (FSCTL_LOCK_VOLUME + FSCTL_DISMOUNT_VOLUME) before raw writes; without the lock Windows rejects writes to sectors under mounted volumes and the stick ends up corrupt. The old code only claimed to do this in a comment. - Windows: open \\.\PhysicalDriveN via CreateFile with OPEN_EXISTING and check token elevation instead of os.Stat, which cannot handle raw device paths. Performance and verification: - Hash the ISO while it streams to the device (TeeReader), removing the second full read pass over the source during verification. - Evict the page cache (posix_fadvise DONTNEED) before the verify readback so verification reads the physical medium, not the RAM copy of the write. - Bound dirty page cache during writes with windowed sync_file_range waits (32 MiB windows, two in flight) instead of only kicking async writeback - keeps the progress bar honest and avoids the multi-minute final fsync stall. - Coalesce short reads into full 4 MiB blocks in flash.Copy so devices always see large aligned writes (also required by Windows raw-disk handles). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RYHBqMpwXrHodFDVWD7FQJ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds proper Windows support for raw disk writes and implements image inspection to warn users when burning non-bootable images. The changes enable Brenner to safely write to physical drives on Windows by locking and dismounting volumes, and provide early feedback when an image cannot boot from a raw byte-for-byte copy.
Key Changes
Windows raw disk handling (
cmd/rawdisk_windows.go): Implements volume locking and dismounting viaFSCTL_LOCK_VOLUMEandFSCTL_DISMOUNT_VOLUMEbefore writing to physical drives. This is essential because Windows blocks direct writes to sectors belonging to mounted volumes. The implementation:\\.\PhysicalDriveN)Image inspection (
internal/flash/inspect.go,internal/flash/inspect_test.go): NewInspect()function analyzes image headers to detect:BootableRaw()andWindowsInstaller()helper methodsPre-write warnings (
cmd/exec.go): AddedwarnIfRawWriteWontBoot()to alert users before burning images that cannot boot from raw copies (e.g., Windows installer ISOs). Warnings are shown in both interactive and CLI modes.Improved verification (
cmd/exec.go,internal/flash/writer.go):io.TeeReader) to avoid re-reading the sourcedropCache()on Linux to evict pages before verification, ensuring the readback actually hits the physical mediumBetter write coalescing (
internal/flash/writer.go): Useio.ReadFull()instead of singleRead()calls to handle short reads from pipes and tee chains, ensuring full-sized aligned writes required by Windows raw disk handles.Linux writeback tuning (
cmd/devicewriter_linux.go): Enhanced dirty page cache management by waiting on writeback windows to keep the page cache bounded and prevent stalls during final fsync.Platform-specific stubs (
cmd/rawdisk_other.go,cmd/dropcache_other.go,cmd/dropcache_linux.go): Build-tagged implementations for non-Windows platforms.Notable Implementation Details
os.Stat()which cannot handle raw device pathshttps://claude.ai/code/session_01RYHBqMpwXrHodFDVWD7FQJ