Skip to content

fix(locallibrary): wait for a new Windows volume before writing FAT32 - #496

Merged
botandbang merged 5 commits into
mainfrom
bnb/loc-255-disk-image-windows
Nov 10, 2026
Merged

botandbang merged 5 commits into
mainfrom
bnb/loc-255-disk-image-windows

Conversation

@botandbang

@botandbang botandbang commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Fixes LOC-255.

Both Windows disk-image tests failed in the weekly run of 11-02, for two separate reasons.

formats_the_image_it_attached_as_planned failed in format::apply with Io { path: "\\.\E:", source: Os { code: 21, message: "The device is not ready." } }. write_fat32 dismounts the volume, writes FAT32 over it, then calls sync_all (FlushFileBuffers) on the same handle. After FSCTL_DISMOUNT_VOLUME the file system lets that handle read and write, but answers other requests with STATUS_VOLUME_DISMOUNTED (see the FAT driver's dismount handler and write path). Win32 reports that status as ERROR_NOT_READY (Wine's table). A real USB drive gets the same error, so this is a fix to format, not only to the test.

an_image_is_detached_when_its_test_ends panicked in the harness's os::attached after the guard dropped the image. The guard deletes the image's temp folder, and Get-DiskImage -ImagePath for a file that doesn't exist fails with exit 1 and no output, even with -ErrorAction SilentlyContinue.

Changed

  • format/windows.rs: write_fat32 opens the volume with FILE_FLAG_WRITE_THROUGH and no longer flushes it. Writes to a volume handle skip the cache already (write.c), and write-through gets each one past the drive's own cache before it returns.
  • format/tests/disk_image.rs: on Windows, os::attached answers None for an image file that's gone, without running PowerShell. Windows keeps an attached image's file open, so a file that's gone can't be attached.
  • A changelog line in apps/locallibrary/changes/.

How it was tested

  • Run 42647818703 on this branch, with a 10 second wait before the open, failed the same way in 29.8 s, against 28.3 s with no wait. The open wasn't what failed.
  • cargo nextest run -p locallibrary --lib -E 'test(/^format::/)': 127 passed on macOS.
  • cargo clippy -p locallibrary --all-targets -- -D warnings, for the host and for x86_64-pc-windows-gnu, and cargo fmt --check.
  • The disk-image tests need a Windows runner with administrator rights. A manual run of locallibrary scheduled on this branch tests them: run 42719843889.

Format-Volume returns, and the partition gets its letter, a moment
before Windows can open the volume, so write_fat32's open failed with
ERROR_NOT_READY. It now retries that error for up to 10 seconds, as the
volume lock after it already does.

The disk-image test harness asked Get-DiskImage about an image whose
folder was gone, which fails even with SilentlyContinue. A file that's
gone isn't attached, since Windows holds an attached image's file open.

Fixes LOC-255
@botandbang
botandbang requested a review from bnb as a code owner November 7, 2026 18:37
@linear-code

linear-code Bot commented Nov 7, 2026

Copy link
Copy Markdown

LOC-255

@github-actions github-actions Bot added documentation Improvements or additions to documentation locallibrary locallibrary and the loclib-* crates locallibrary: core The core crate, the data model and rekordbox's formats tests Tests, fixtures and test harnesses labels Nov 7, 2026
bnb
bnb previously approved these changes Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Rust coverage

From run 620. Both are held to the thresholds in .cargo/config.toml.

Tests Lines Functions Regions
All 98.08% (90236/92007) 97.56% (14711/15079) 96.74% (200107/206852)
Hegel property tests alone 96.83% (89092/92007) 96.31% (14522/15079) 95.37% (197269/206852)

@botandbang
botandbang added this pull request to the merge queue Nov 7, 2026
@botandbang
botandbang removed this pull request from the merge queue due to a manual request Nov 7, 2026
bnb
bnb previously approved these changes Nov 9, 2026
…g a dismounted volume

write_fat32 flushed the volume after dismounting it. Once a volume is
dismounted, the file system answers anything but reads and writes on
that handle with STATUS_VOLUME_DISMOUNTED, which Windows reports as
ERROR_NOT_READY: "The device is not ready". The open was never the
problem, so the wait before it goes, with its test.

Writes to a volume handle skip the cache already, so the volume is now
opened with FILE_FLAG_WRITE_THROUGH, which takes over the flush's other
job of getting each write past the drive's own cache.
@botandbang
botandbang added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 4c1a6bc Nov 10, 2026
54 of 60 checks passed
@botandbang
botandbang deleted the bnb/loc-255-disk-image-windows branch November 10, 2026 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation locallibrary: core The core crate, the data model and rekordbox's formats locallibrary locallibrary and the loclib-* crates tests Tests, fixtures and test harnesses

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants