fix(disk): skip drives returning ERROR_INVALID_FUNCTION or ERROR_NOT_SUPPORTED in IOCounters on Windows#2003
Merged
shirou merged 1 commit intoshirou:masterfrom Feb 19, 2026
Conversation
…SUPPORTED in IOCounters on Windows DeviceIoControl with IOCTL_DISK_PERFORMANCE may return ERROR_INVALID_FUNCTION or ERROR_NOT_SUPPORTED for drives that do not support disk performance counters (e.g. virtual drives like Google Drive, or Windows Server 2016 with disk performance counters disabled). Previously this caused IOCountersWithContext to return a fatal error, discarding IO stats already collected for other drives. This change skips the unsupported drive and continues iterating, matching the behavior of Python psutil: https://github.com/giampaolo/psutil/blob/master/psutil/arch/windows/disk.c#L146-L163 Fixes shirou#1461
6 tasks
shirou
approved these changes
Feb 19, 2026
Owner
shirou
left a comment
There was a problem hiding this comment.
LGTM!
Great fix — clean, minimal, and nicely aligned with psutil's behavior. The comment and reference to the psutil source are much appreciated. Thanks for tracking this down and fixing it!
This was referenced Apr 23, 2026
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
On Windows,
IOCountersWithContextcallsDeviceIoControlwithIOCTL_DISK_PERFORMANCEfor each fixed drive. If the call fails with any error, the function immediately returns, discarding all IO counters collected so far — including those from drives that succeeded.This causes
disk.IOCounters()to fail entirely on systems where at least one drive does not supportIOCTL_DISK_PERFORMANCE, such as:disk.IOCounters()returnsERROR_INVALID_FUNCTIONwhen Google Drive is mounted as a disk in Windows. #1461Fix
Skip drives that return
ERROR_INVALID_FUNCTIONorERROR_NOT_SUPPORTEDfromDeviceIoControland continue to the next drive. This matches the behavior of Python'spsutil, which this code references:Reference: https://github.com/giampaolo/psutil/blob/544e9daa4f66a9f80d7bf6c7886d693ee42f0a13/psutil/arch/windows/disk.c#L146-L163
Fixes #1461