Skip to content

Report backing stores on Windows - #3859

Merged
dbwiddis merged 3 commits into
masterfrom
windows-backing-stores
Nov 1, 2026
Merged

dbwiddis merged 3 commits into
masterfrom
windows-backing-stores

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Fourth step of #3844, following #3855 (API), #3856 (Linux) and #3858 (macOS). Implements HWDiskStore.getBackingStores() on Windows.

Change

  • MSFT_Disk in the WMI Storage namespace identifies the two layered kinds by BusType:
    • File-backed virtual disk (15, a VHD or VHDX): Location is the backing file's path, and GetVolumePathName on it gives the volume holding it, reported as file:<mount> to match OSFileStore.getMount(). GetVolumePathName handles volumes mounted in a folder, which a drive-letter shortcut would not.
    • Storage Spaces disk (16): matched to its MSFT_VirtualDisk by UniqueId, then to the physical disks holding it through MSFT_VirtualDiskToPhysicalDisk, reported as disk:\\.\PHYSICALDRIVE<DeviceId>, sorted.
    • Any other disk reports an empty list. A disk that cannot be resolved (unreadable volume, unknown virtual disk, failed or pre-Windows 8 query, unexpected property type) reports Optional.empty().
  • Windows does not list pooled physical disks in Win32_DiskDrive, so a Storage Spaces disk's entries name disks absent from getDiskStores(). The HWDiskStore javadoc'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.
  • Cost: the Storage namespace is slow, so nothing is queried by 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 existing MSFT_PhysicalDisk fallback.
  • The correlation is in the common WindowsHWDiskStore; the twins only open the COM session and call GetVolumePathName, for which Kernel32FFM gains a binding. The SP/PD/VD object ID patterns move from WindowsLogicalVolumeGroup to MSFTStorage so both share them.

Testing

Verified on a windows-latest runner (fork CI) that attached three VHDXs with diskpart, pooled two into a Storage Space, and formatted the third. JNA and FFM report identically:

Disk Type getBackingStores()
PHYSICALDRIVE0, 1 (the runner's Hyper-V disks) Unknown []
PHYSICALDRIVE4 (VHDX at D:\oshi3.vhdx) Virtual [file:D:\]
PHYSICALDRIVE5 (Storage Space over the two pooled VHDXs) Virtual [disk:\\.\PHYSICALDRIVE2, disk:\\.\PHYSICALDRIVE3]

The pooled VHDXs (DeviceIds 2 and 3) do not appear in Win32_DiskDrive, as described above.

  • New WindowsHWDiskStoreBackingStoresTest replays 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.
  • Full gate with -Paggregate-coverage and -Perror-prone pass. The full-coverage label is set so the Windows jobs run.

Summary by CodeRabbit

  • New Features
    • Windows disk information now reports backing stores for file-backed virtual disks and Storage Spaces, including physical disks in a storage pool.
    • Backing-store details are retrieved on demand. Disks with unavailable or unresolved information may show no backing stores.
  • Documentation
    • Clarified support for Windows 8 and Windows Server 2012 or later.
    • Documented that Storage Spaces physical disks are not listed separately, so their transfers are reported on the Storage Spaces disk.
    • Added Windows to the platforms reported for disk backing stores.

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.
@dbwiddis dbwiddis added the full-coverage Add to a PR to execute more CI label Oct 31, 2026
@coderabbitai

coderabbitai Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ef4288c6-f514-4f1a-ae97-5b5a6301afab
Commits

Reviewing files that changed from the base of the PR and between 216e3ae and bad7f2b.

Files selected for processing: 6
  • 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-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java
  • oshi-core-ffm/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFMTest.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNATest.java
Files with no reviewable changes: 1
  • oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

Recent review details
Context from checks skipped due to timeout: 16
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, DragonFly BSD
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Test JDK 26, ubuntu-latest
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, ubuntu-latest
  • GitHub Check: Test JDK 21, ubuntu-latest
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Test JDK 25, macos-latest
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Analyze (java)
  • GitHub Check: Analyze (java-kotlin)
Additional context used
Code guidelines: 1
AGENTS.md — auto-discovered
Path-based instructions: 9
Source excerpt: **Language level.**

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java
Source excerpt: Nearly every class in `oshi-core` has a counterpart in `oshi-core-ffm` implementing the same `oshi-common` interface for the same platform.

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNATest.java
  • oshi-core-ffm/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFMTest.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java
Source excerpt: Any `oshi-core` test that allocates JNA needs `@DisabledIfSystemProperty(named = "os.name", matches = "(?i).*netbsd.*")`; the NetBSD CI runner has no `libjnidispatch`.

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNATest.java
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-core-ffm` may not reference `com.sun.jna.**`.

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core-ffm/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFMTest.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsHWDiskStoreBackingStoresTest.java
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `Integer.parseInt`, `Long.parseLong`, `Double.parseDouble`, `Integer.decode`, and relatives are banned.

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java
Source excerpt: **Their `src/test` compiles at `release 17`**, set by `maven.compiler.testRelease` in the root `pom.xml`.

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNATest.java
  • oshi-core-ffm/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFMTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsHWDiskStoreBackingStoresTest.java
Source excerpt: Text blocks strip incidental leading and trailing whitespace, and spotless applies `trimTrailingWhitespace` to Java sources, so a fixture whose real output carries trailing spaces or tab alignment needs explicit `\s` or `\t`...

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNATest.java
  • oshi-core-ffm/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFMTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsHWDiskStoreBackingStoresTest.java
  • oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
  • oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java
Source excerpt: **Adding a test in a package that no existing test uses means adding a line to that module's `module-info.test`:**

CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNATest.java
  • oshi-core-ffm/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFMTest.java
  • oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsHWDiskStoreBackingStoresTest.java
Additional comments: 5
oshi-common/src/test/java/oshi/hardware/common/platform/windows/WindowsHWDiskStoreBackingStoresTest.java: 1

113-118: LGTM!

Also applies to: 120-120, 122-122, 125-125, 181-195

oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java: 1

157-163: LGTM!

oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java: 1

153-159: LGTM!

oshi-core-ffm/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFMTest.java: 1

1-34: LGTM!

oshi-core/src/test/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNATest.java: 1

1-34: LGTM!

Walkthrough

Windows disk stores now report backing stores for file-backed virtual disks and Storage Spaces. The change adds Storage WMI queries and object-ID matching, integrates lazy lookups into the JNA and FFM implementations, and documents and tests the reported mappings.

Changes: Windows Backing-Store Reporting

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
Loading

Possibly related issues

Possibly related PRs

  • oshi/oshi#3855 — This PR uses the HWDiskStore.getBackingStores() API and StoreKind entries introduced there.
Merge Risk: Minimal · up to bad7f

Windows backing-store reporting adds no identified merge-blocking risk.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning 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. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed 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…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
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.

Share

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

codecov Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.91597% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.08%. Comparing base (99dfa23) to head (bad7f2b).

Files with missing lines Patch % Lines
...rdware/platform/windows/WindowsHWDiskStoreFFM.java 72.72% 3 Missing and 3 partials ⚠️
...rdware/platform/windows/WindowsHWDiskStoreJNA.java 68.42% 3 Missing and 3 partials ⚠️
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     
Flag Coverage Δ
dragonflybsd 37.58% <53.78%> (+0.05%) ⬆️
freebsd 38.16% <53.78%> (+0.08%) ⬆️
linux 42.02% <53.78%> (+0.05%) ⬆️
macos 43.09% <53.78%> (+0.01%) ⬆️
netbsd 37.46% <53.78%> (+0.06%) ⬆️
openbsd 38.02% <53.78%> (+0.08%) ⬆️
solaris 39.28% <53.78%> (+0.06%) ⬆️
windows 49.51% <89.91%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.
@dbwiddis
dbwiddis merged commit 119975b into master Nov 1, 2026
24 of 25 checks passed
@dbwiddis
dbwiddis deleted the windows-backing-stores branch November 1, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-coverage Add to a PR to execute more CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant