Repository navigation
Report backing stores on Windows - #3859
Conversation
Windows disk stores now implement getBackingStores() from the Storage namespace of WMI. MSFT_Disk's BusType identifies the two layered kinds: a file-backed virtual disk (15) reports the volume holding its backing file, read from Location with GetVolumePathName, and a Storage Spaces disk (16) reports the physical disks holding its virtual disk, matched by UniqueId and then MSFT_VirtualDiskToPhysicalDisk. Any other disk reports an empty list, and one that cannot be resolved reports nothing. Windows stops listing physical disks once they are pooled, so a Storage Spaces disk's entries name disks that are not in getDiskStores(); the javadoc's counting rule now says so. The queries are slow, so they run only when a disk is first asked for its backing stores, once per enumeration: the disks of one getDiskStores() call share a memoized result, queried in its own COM session with the same default timeout as the MSFT_PhysicalDisk fallback. The correlation is in the common WindowsHWDiskStore; the JNA and FFM twins only open the COM session and call GetVolumePathName, for which Kernel32FFM gains a binding. The object ID patterns move from WindowsLogicalVolumeGroup to MSFTStorage so both share them.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Storage WMI queries and object IDs oshi-common/src/main/java/oshi/driver/common/windows/wmi/MSFTStorage.java, oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsLogicalVolumeGroup.java |
MSFTStorage adds Storage WMI properties, queries, and object-ID patterns. WindowsLogicalVolumeGroup now uses the shared patterns. |
Backing-store correlation oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java, oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsHWDiskStoreBackingStoresTest.java, oshi-common/src/main/java/oshi/hardware/HWDiskStore.java, CHANGELOG.md |
WindowsHWDiskStore maps file-backed virtual disks to their containing volume and Storage Spaces disks to their physical members. Tests cover valid, unresolved, and malformed data. The documentation and changelog describe Windows reporting. |
JNA and FFM enumeration integration oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java, oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java, oshi-core-ffm/src/main/java/oshi/ffm/platform/windows/Kernel32FFM.java |
Both implementations pass a shared memoized lookup to enumerated disks and run the WMI query on demand. The FFM implementation adds a GetVolumePathNameW binding. |
Estimated code review effort: 3 (Moderate) | ~25 minutes
Change: Feature
Sequence Diagram(s)
sequenceDiagram
participant DiskEnumeration
participant MemoizedLookup
participant WindowsHWDiskStore
participant StorageWMI
participant VolumePathAPI
DiskEnumeration->>MemoizedLookup: Create shared lazy query
WindowsHWDiskStore->>MemoizedLookup: Request backing stores
MemoizedLookup->>WindowsHWDiskStore: Run queryBackingStores
WindowsHWDiskStore->>StorageWMI: Query disks and associations
WindowsHWDiskStore->>VolumePathAPI: Resolve file-backed disk location
WindowsHWDiskStore-->>MemoizedLookup: Return backing-store mappings
Possibly related issues
- Relate a Virtual or mapped HWDiskStore to its backing devices #3844 — This PR implements the Windows backing-store mappings and overlap documentation described in the issue. Its Linux and macOS cases are not covered here.
Possibly related PRs
- oshi/oshi#3855 — This PR uses the
HWDiskStore.getBackingStores()API andStoreKindentries introduced there.
Merge Risk: 
Minimal · up to bad7f
-
Windows backing-store reporting adds no identified merge-blocking risk.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title "Report backing stores on Windows" matches the main change. The PR adds Windows support for HWDiskStore.getBackingStores(). It covers VHD/VHDX file backings and Storage Spaces members, which the diff implements in WindowsHWDiskStore, the JNA and FFM disk store classes, and the new MSFTStorage queries. The title is short, specific, and free of noise.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 68.75% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 16 functions across 12 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks the disks at night,
Finds file-backed volumes tucked from sight.
Storage Spaces reveal their crew,
In sorted rows of disks, two by two.
The Windows list now tells what lies beneath.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3859 +/- ##
==========================================
Coverage 81.07% 81.08%
+ Complexity 864 659 -205
==========================================
Files 726 726
Lines 26564 26673 +109
Branches 4529 4548 +19
==========================================
+ Hits 21538 21629 +91
- Misses 2795 2805 +10
- Partials 2231 2239 +8
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
DisksTest checks every entry names a known StoreKind, and NativeComparisonTest checks the JNA and FFM twins agree. Until now no test reached the Windows queries, so the twins' backing-store code went uncovered.
Test GetVolumePathName in both twins against %SystemRoot%, which CI never reached because its runners have no file-backed disk, and add a fixture for a Storage Space whose members have no DeviceId or an unrecognized reference. Remove the four- and five-argument WindowsHWDiskStore constructors, which no subclass calls any more.
Fourth step of #3844, following #3855 (API), #3856 (Linux) and #3858 (macOS). Implements
HWDiskStore.getBackingStores()on Windows.Change
MSFT_Diskin the WMI Storage namespace identifies the two layered kinds byBusType:Locationis the backing file's path, andGetVolumePathNameon it gives the volume holding it, reported asfile:<mount>to matchOSFileStore.getMount().GetVolumePathNamehandles volumes mounted in a folder, which a drive-letter shortcut would not.MSFT_VirtualDiskbyUniqueId, then to the physical disks holding it throughMSFT_VirtualDiskToPhysicalDisk, reported asdisk:\\.\PHYSICALDRIVE<DeviceId>, sorted.Optional.empty().Win32_DiskDrive, so a Storage Spaces disk's entries name disks absent fromgetDiskStores(). TheHWDiskStorejavadoc's counting rule now says so: on Windows the Storage Spaces disk is the only entry carrying its pool's transfers. Reporting the members anyway keeps the method truthful; whether to treat this differently is open for review.getDiskStores(). The disks of one enumeration share a memoized result, queried the first time any of them is asked for its backing stores, in its own COM session with the same default timeout as the existingMSFT_PhysicalDiskfallback.WindowsHWDiskStore; the twins only open the COM session and callGetVolumePathName, for whichKernel32FFMgains a binding. TheSP/PD/VDobject ID patterns move fromWindowsLogicalVolumeGrouptoMSFTStorageso both share them.Testing
Verified on a
windows-latestrunner (fork CI) that attached three VHDXs withdiskpart, pooled two into a Storage Space, and formatted the third. JNA and FFM report identically:getBackingStores()[]D:\oshi3.vhdx)[file:D:\][disk:\\.\PHYSICALDRIVE2, disk:\\.\PHYSICALDRIVE3]The pooled VHDXs (DeviceIds 2 and 3) do not appear in
Win32_DiskDrive, as described above.WindowsHWDiskStoreBackingStoresTestreplays that runner's WMI values: a physical disk, the VHD, the Storage Space (members sorted), unresolvable disks, and a property published with an unexpected type.-Paggregate-coverageand-Perror-pronepass. Thefull-coveragelabel is set so the Windows jobs run.Summary by CodeRabbit