Skip to content

Share the disk engines' common loops - #28

Merged
NitroDiesel merged 1 commit into
mainfrom
share-engine-loops
Nov 14, 2026
Merged

NitroDiesel merged 1 commit into
mainfrom
share-engine-loops

Conversation

@NitroDiesel

Copy link
Copy Markdown
Owner

The udisks2 (Linux) and Windows disk engines each had their own copy of the same logic, so a fix in one could be missed in the other.

Now shared in engine.rs:

  • the bad-block test (badblocks -w patterns, write, flush, read back, count bad sectors);
  • read-back hash verification;
  • the blocking-risk check after revalidation (also used by the polkit helper path);
  • the boot-record start arithmetic;
  • the platform-neutral steps of Windows installer media: pre-write checks and layout, file copy with customization, and copied-file verification.

The shared code reaches the device only through closures and buffers the engine supplies. Windows keeps its sector-aligned buffers and volume locks; Linux keeps sync_all plus the page-cache drop before reading back.

Behavior is unchanged: same patterns, chunk sizes, flush-before-read order, cancellation points, progress stages and error messages.

Left separate on purpose:

  • The polkit helper path's verify_device_hash reads sequentially in 1 MiB chunks and has its own short-read error, and its bad-block test runs the external badblocks tool.
  • Image writing, partitioning, formatting, locking and mounting differ by platform.

Verification: cargo fmt --check, cargo test --workspace on Windows (including 7 new tests of the shared loops on an in-memory device), and cargo clippy -D warnings for both the Windows and Linux targets pass locally. The Linux engines run only in CI, and the elevated VHD tests were not run locally (this shell is not elevated); CI runs both.

🤖 Generated with Claude Code

The udisks2 and Windows engines each carried the same bad-block test,
read-back hash verification, blocking-risk check, boot-record start
arithmetic, and the platform-neutral steps of Windows installer media
(pre-write checks and layout, file copy with customization, copied-file
verification). They now live once in engine.rs and reach the device
through closures and buffers the engine supplies, so Windows keeps its
sector-aligned buffers and Linux its page-cache drop.

Behavior is unchanged: same patterns, chunk sizes, flush-before-read
order, cancellation points, progress stages, and error messages. The
older polkit helper path keeps its own verification (1 MiB sequential
reads, a distinct short-read error) and uses the external badblocks tool.

Tests cover the shared loops on an in-memory device.

Co-Authored-By: Claude <noreply@anthropic.com>
@NitroDiesel
NitroDiesel merged commit 3a4dca7 into main Nov 14, 2026
11 checks passed
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.

1 participant