Skip to content

Add macOS disk type detection via IOKit - #3231

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:feature/disk-type-macos
May 6, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:feature/disk-type-macos

Conversation

@dbwiddis

@dbwiddis dbwiddis commented May 6, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #3230 — adds macOS disk type detection for both JNA and FFM backends.

Implementation

Traverses the IOKit registry hierarchy:

IOMedia (has 'Removable' property)
  └── IOBlockStorageDriver
      └── IOBlockStorageDevice (has 'Device Characteristics' -> 'Medium Type')
  • Removable: Detected from IOMedia.Removable boolean property
  • SSD: Medium Type contains "Solid State" or "SSD"
  • HDD: Medium Type contains "Rotational"
  • Unknown: If properties are unavailable

Changes

  • MacHWDiskStore.java: Added 5-arg constructor with diskType
  • MacHWDiskStoreJNA.java: Added detectDiskType() using JNA IOKit bindings
  • MacHWDiskStoreFFM.java: Added detectDiskType() using FFM IOKit bindings

Summary by CodeRabbit

  • New Features
    • macOS disk detection now classifies disk types (SSD, HDD, Removable, Unknown) and includes this info in hardware reports.
  • Tests
    • Added a test to validate disk type classification is consistent across native implementations.

@coderabbitai

coderabbitai Bot commented May 6, 2026 •

Copy link
Copy Markdown
Contributor

Caution

Review failed

Failed to post review comments

📝 Walkthrough

Walkthrough

Adds disk-type support for macOS disk stores by introducing a diskType constructor in the Mac disk store base class and wiring platform-specific detection into FFM and JNA implementations. New detectDiskType functions inspect IOKit/CoreFoundation properties to classify disks as SSD, HDD, Removable, or Unknown.

Changes

Disk Type Detection Across Mac Implementations

Layer / File(s) Summary
Base Constructor
oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacHWDiskStore.java
Adds protected overload MacHWDiskStore(String name, String model, String serial, long size, String diskType) that forwards diskType to the superclass.
FFM: Constructor & Wiring
oshi-core-ffm/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreFFM.java
Adds private constructor accepting diskType, calls superclass with it, and invokes updateDiskStats. Updates disk creation in getDisks() to pass detectDiskType(bsdName).
FFM: Detection Logic
oshi-core-ffm/src/main/java/.../MacHWDiskStoreFFM.java
Adds private static String detectDiskType(String bsdName) that queries IOKit/CoreFoundation (DA/IORegistry/CF properties) and returns SSD, HDD, Removable, or Unknown.
JNA: Constructor Signature & Wiring
oshi-core/src/main/java/oshi/hardware/platform/mac/MacHWDiskStoreJNA.java
Updates constructor to accept diskType and passes it to superclass; getDisks() now supplies detectDiskType(bsdName) when instantiating disk objects.
JNA: Detection Logic
oshi-core/src/main/java/.../MacHWDiskStoreJNA.java
Adds private static String detectDiskType(String bsdName) that inspects IOKit/DA properties (removable, medium type, etc.) and returns SSD, HDD, Removable, or Unknown.
Tests
oshi-benchmark/src/test/java/oshi/comparison/NativeComparisonTest.java
Adds assertion in diskStores test to compare DiskType between JNA and FFM results for each disk store.

Sequence Diagram(s)

sequenceDiagram
  participant App as Java getDisks()
  participant Detect as detectDiskType()
  participant IOKit as IOKit/CoreFoundation
  participant Store as MacHWDiskStoreFFM/JNA

  App->>Detect: request disk type for bsdName
  Detect->>IOKit: query DA / IORegistry / CF properties
  IOKit-->>Detect: return properties (mediumType, removable, etc.)
  Detect-->>App: return "SSD"/"HDD"/"Removable"/"Unknown"
  App->>Store: construct MacHWDiskStore with diskType
  Store-->>App: disk object created (with diskType)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • oshi/oshi#3230: Complements this PR by adding diskType parameter support to the base HWDiskStore class and cross-platform getDiskType() API; strongly related.

Poem

🍎 On macOS we probe the registry's art,
Reading medium signs to play our part.
Constructors widened, detectors set free,
Now disks get labeled—SSD, HDD, or Removable, you see! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 accurately summarizes the main change: adding macOS disk type detection via IOKit, which is the core feature across all modified files.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented May 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 65.47619% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.74%. Comparing base (7830542) to head (fdf8e4a).

Files with missing lines Patch % Lines
.../oshi/hardware/platform/mac/MacHWDiskStoreFFM.java 65.11% 5 Missing and 10 partials ⚠️
.../oshi/hardware/platform/mac/MacHWDiskStoreJNA.java 64.10% 4 Missing and 10 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #3231      +/-   ##
============================================
- Coverage     63.77%   63.74%   -0.03%     
  Complexity       73       73              
============================================
  Files           421      421              
  Lines         19358    19439      +81     
  Branches       3366     3390      +24     
============================================
+ Hits          12346    12392      +46     
- Misses         5302     5315      +13     
- Partials       1710     1732      +22     
Flag Coverage Δ
linux 29.97% <0.00%> (-0.12%) ⬇️
macos 33.08% <65.47%> (+0.09%) ⬆️
windows 40.70% <0.00%> (-0.18%) ⬇️

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

☔ View full report in Codecov by Sentry.
📢 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.

Reads IOBlockStorageDevice 'Device Characteristics' -> 'Medium Type'
to detect SSD vs HDD. Also checks IOMedia 'Removable' property.

Traverses IOKit hierarchy: IOMedia -> IOBlockStorageDriver -> IOBlockStorageDevice
to find the Device Characteristics dictionary containing Medium Type.
@dbwiddis
dbwiddis force-pushed the feature/disk-type-macos branch from 13f99ee to fdf8e4a Compare May 6, 2026 16:50
@oshi oshi deleted a comment from coderabbitai Bot May 6, 2026
@dbwiddis
dbwiddis merged commit 195502c into oshi:master May 6, 2026
18 of 19 checks passed
@dbwiddis
dbwiddis deleted the feature/disk-type-macos branch May 6, 2026 17:25
dbwiddis added a commit that referenced this pull request May 9, 2026
- Add native-free Linux SystemInfoProvider and Apple Silicon fix to 7.2.0
- Fix issue links to point to implementing PRs (#3230, #3232, #3227)
- Add macOS disk type (#3231) and OSFileStore fast path (#3195)
- Mention native-free Linux option in README Usage section
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