Skip to content

Skip optical drive volumes during volume extent lookups - #22

Open
warioji wants to merge 1 commit into
Blacktempel:masterfrom
warioji:fix/skip-optical-volumes
Open

warioji wants to merge 1 commit into
Blacktempel:masterfrom
warioji:fix/skip-optical-volumes

Conversation

@warioji

@warioji warioji commented Oct 24, 2026

Copy link
Copy Markdown

Summary

When LibreHardwareMonitor (DiskInfoToolkit 2.2.2) is running, swapping discs in an internal Blu-ray drive fails: the first disc reads fine, but the second disc is ejected again and Windows shows "Please insert a disk into drive F:". Disabling the drive in Device Manager is also refused. The System log shows Kernel-PnP event 225 (an application stopped the removal or ejection of the device) for the LibreHardwareMonitor process. Closing LibreHardwareMonitor fixes it immediately.

Cause

StoragePartitionReader.AssignDriveLettersAndFreeSpace checks every drive letter from A: to Z: through WindowsVolumeExtentMap.TryGet, which opens \\.\X: and sends IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS. This includes optical drives.

This scan runs on the partition refresh interval and after every DBT_DEVICEARRIVAL / DBT_DEVNODES_CHANGED, so it also runs right after a disc is inserted. While the optical volume handle is open, or while CreateFile is blocked because the drive is spinning up, Windows vetoes the eject or removal.

Optical drives are not GUID_DEVINTERFACE_DISK devices, so their volumes can never contain extents of a disk that DiskInfoToolkit monitors. Opening them gains nothing.

WindowsStorageSpaceVolumeReader.ReadVolumeDiskNumbers has the same pattern: it opens every volume returned by FindFirstVolume / FindNextVolume.

Changes

  • New Utilities/OpticalDeviceHelper: detects optical volumes with QueryDosDevice (target starts with \Device\CdRom). This only reads the object manager symbolic link and never opens the device.
  • WindowsVolumeExtentMap.TryGet: optical drive letters return an unsuccessful lookup without opening the volume. The result is not reported as severe or failed, so a partition refresh is never aborted because of an optical drive.
  • WindowsStorageSpaceVolumeReader.ReadVolumeDiskNumbers: skips volumes whose NT device name (already resolved via QueryDosDevice) is an optical device.
  • Tests: OpticalDeviceHelperTest covers device name matching and unknown DOS device names.

Testing

  • dotnet build DiskInfoToolkit.sln -c Release: all targets (net472, net481, netstandard2.0, net8.0, net9.0, net10.0) build with 0 warnings and 0 errors.
  • dotnet test: 59 passed, 0 failed (12 new).
  • On a Windows 11 machine with 6 SATA/NVMe SSDs and an internal HL-DT-ST BD-RE BH14NS58 (F: → \Device\CdRom0), F: is detected as optical and every disk still gets its drive letters (C:, D:/E:, I:, M:, N:, S:).
  • LibreHardwareMonitor (current master) builds against this branch via a project reference.
  • With LibreHardwareMonitor built against this branch running, swapping discs in the Blu-ray drive now works: the second disc is read normally (previously it was ejected again with "Please insert a disk into drive F:").

Note

This change was written with the help of an AI coding assistant (Claude Opus in Claude Code). I reviewed it and verified it myself on the machine where the problem occurred: with LibreHardwareMonitor built against this branch running, the Blu-ray disc swap issue no longer occurs, and the existing disks still show their drive letters and sensor data.

🤖 Generated with Claude Code

The partition refresh opened every drive letter from A: to Z: to read
IOCTL_VOLUME_GET_VOLUME_DISK_EXTENTS, including CD/DVD/BD drives. This
runs every partition refresh interval and on every device change, so it
also runs right after a disc is inserted. While the optical volume is
open (or the open is blocked while the drive spins up), Windows vetoes
ejects and device removal (Kernel-PnP event 225), and a newly inserted
disc can be ejected again with "Please insert a disk into drive X:".

Optical drives are not GUID_DEVINTERFACE_DISK devices, so their volumes
never contain extents of a monitored disk. Detect them through
QueryDosDevice (\Device\CdRom*), which only reads the object manager
symbolic link and does not touch the device, and skip them in both the
drive-letter scan and the Storage Spaces volume enumeration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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