Repository navigation
Add disk type information (SSD, HDD, Removable, Virtual) - #3230
Conversation
📝 WalkthroughWalkthroughThis PR adds disk type classification across the hardware layer: a new default ChangesDisk Type Support
Sequence Diagram(s)sequenceDiagram
participant Consumer
participant Enumerator as Platform Enumerator
participant Detector as DiskType Detector
participant Store as HWDiskStore (ctor)
participant Source as Sys/WMI (udev / WMI)
Consumer->>Enumerator: request disk list
Enumerator->>Source: enumerate devices (sysfs / WMI)
Note right of Source: returns device attributes (removable, rotational, MEDIATYPE...)
Enumerator->>Detector: ask detectDiskType(device attrs)
Detector->>Source: read attributes (removable, queue/rotational, MEDIATYPE)
Detector-->>Enumerator: return diskType ("SSD"/"HDD"/"Removable"/"Virtual"/"Unknown")
Enumerator->>Store: instantiate HWDiskStore(name, model, serial, size, diskType)
Store-->>Consumer: return disk object with getDiskType() available
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📋 Issue PlannerLet us write the prompt for your AI agent so you can ship faster (with fewer bugs). View plan for ticket: ✨ Finishing Touches✨ Simplify 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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (3)
oshi-common/src/main/java/oshi/hardware/HWDiskStore.java (1)
54-61: ⚡ Quick winConsider exposing the type values as public constants (or an enum) and aligning the Javadoc with what's actually returned today.
Two small things on this new API surface:
- The Javadoc lists
Networkas a possible return value, but no implementation in this PR ever returns"Network". Either drop it from the doc until it's implemented, or keep it but explicitly note that it's reserved for future use so consumers don't write code branches that will never trigger.- The valid return values are part of the public API contract, but they're only documented as free-form strings. Callers will have to hardcode
"SSD","HDD", etc., which is easy to mistype and a pain to evolve. Exposing them as public constants onHWDiskStore(or, better, as aDiskTypeenum with anUNKNOWNdefault and afromString/getTypeaccessor) would make consumer code typo-proof and keep the platform implementations honest.♻️ Sketch of a constants-based variant (least invasive)
+ /** Disk is a solid-state drive. */ + String TYPE_SSD = "SSD"; + /** Disk is a rotational hard disk drive. */ + String TYPE_HDD = "HDD"; + /** Disk is a removable medium (USB stick, SD card, optical, floppy, etc.). */ + String TYPE_REMOVABLE = "Removable"; + /** Disk is a virtual/device-mapper backed device (e.g. LVM). */ + String TYPE_VIRTUAL = "Virtual"; + /** Disk type could not be determined. */ + String TYPE_UNKNOWN = "Unknown"; + /** - * The type of the disk, such as SSD, HDD, Removable, Network, Virtual, or Unknown. + * The type of the disk. Returns one of {`@link` `#TYPE_SSD`}, {`@link` `#TYPE_HDD`}, + * {`@link` `#TYPE_REMOVABLE`}, {`@link` `#TYPE_VIRTUAL`}, or {`@link` `#TYPE_UNKNOWN`}. + * Additional values (e.g. for network or optical media) may be added in the future. * * `@return` the disk type string */ default String getDiskType() { - return "Unknown"; + return TYPE_UNKNOWN; }An enum would be even nicer long-term, but introduces a slightly bigger API change for
AbstractHWDiskStoreand the platform classes.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-common/src/main/java/oshi/hardware/HWDiskStore.java` around lines 54 - 61, The Javadoc for HWDiskStore.getDiskType lists values (e.g., "Network") that aren't actually returned and the API exposes free-form strings that invite typos; add a well-defined set of return values by introducing either public constants on HWDiskStore (e.g., SSD/HDD/REMOVABLE/VIRTUAL/UNKNOWN) or, preferably, a DiskType enum with values (SSD, HDD, REMOVABLE, VIRTUAL, NETWORK, UNKNOWN) and a DiskType.fromString/getType helper; update HWDiskStore.getDiskType signature/documentation to reference the constants/enum and adjust implementations (and AbstractHWDiskStore) to return the canonical constant/enum value and align the Javadoc to mention which values are reserved (e.g., NETWORK reserved) if not yet returned.oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java (2)
168-180: 💤 Low valueOptional: lift the classification logic into a shared helper.
The body of
detectDiskTypehere is identical to the one inLinuxHWDiskStoreFFMonce you ignore thedevice.getSysattrValue(...)vsUdevFunctions.getSysattrValue(device, ..., arena)wrappers. You could extract a small package-private helper inLinuxHWDiskStore(oshi-common) that takes the two already-read strings, e.g.classifyDiskType(String removable, String rotational), and call it from both subclasses with the platform-specific sysattr reads inlined. Keeps the policy in one place if you ever extend it (e.g. for SD/optical/network).Not blocking — happy to leave for a follow-up given how small the helper is.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java` around lines 168 - 180, Both subclasses duplicate the disk-type decision logic; extract a package-private helper classifyDiskType(String removable, String rotational) into LinuxHWDiskStore (oshi-common) and replace the bodies of LinuxHWDiskStoreJNA.detectDiskType and the equivalent in LinuxHWDiskStoreFFM to simply call LinuxHWDiskStore.classifyDiskType(removable, rotational) after they read their platform-specific sysattr strings (device.getSysattrValue(...) or UdevFunctions.getSysattrValue(..., arena)); preserve the existing return values ("Removable", "SSD", "HDD", "Unknown") and behavior when inputs are null or different.
168-180: 💤 Low valueHeads-up:
Removableprecedence hides SSD/HDD classification for hot-pluggable media.A USB-attached SSD or an external HDD will report
"Removable"rather than"SSD"/"HDD"becauseremovable=1short-circuits the rotational check. That's a defensible choice (it matches the PR's "Removable" bucket and the wording in issue#2857), but it does mean callers can't ask "is this disk solid-state?" purely fromgetDiskType()for external drives.A couple of options if you'd rather preserve that signal:
- Document in the Javadoc that
Removabletakes precedence over the rotational classification.- Or only return
Removablewhen rotational is unknown/missing, otherwise fall through toSSD/HDD.Either is fine — just worth being explicit since this is the API contract going forward.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java` around lines 168 - 180, The current detectDiskType(UdevDevice device) returns "Removable" whenever removable="1", hiding SSD/HDD info for external drives; change the logic so detectDiskType first checks the rotational sysattr (device.getSysattrValue("queue/rotational")) and returns "SSD" for "0" or "HDD" for "1" when that value is present, and only return "Removable" if rotational is missing/empty (or unknown), and update the Javadoc for detectDiskType/getDiskType to state that removable is only used when rotational info is unavailable.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@oshi-common/src/main/java/oshi/hardware/HWDiskStore.java`:
- Around line 54-61: The Javadoc for HWDiskStore.getDiskType lists values (e.g.,
"Network") that aren't actually returned and the API exposes free-form strings
that invite typos; add a well-defined set of return values by introducing either
public constants on HWDiskStore (e.g., SSD/HDD/REMOVABLE/VIRTUAL/UNKNOWN) or,
preferably, a DiskType enum with values (SSD, HDD, REMOVABLE, VIRTUAL, NETWORK,
UNKNOWN) and a DiskType.fromString/getType helper; update
HWDiskStore.getDiskType signature/documentation to reference the constants/enum
and adjust implementations (and AbstractHWDiskStore) to return the canonical
constant/enum value and align the Javadoc to mention which values are reserved
(e.g., NETWORK reserved) if not yet returned.
In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java`:
- Around line 168-180: Both subclasses duplicate the disk-type decision logic;
extract a package-private helper classifyDiskType(String removable, String
rotational) into LinuxHWDiskStore (oshi-common) and replace the bodies of
LinuxHWDiskStoreJNA.detectDiskType and the equivalent in LinuxHWDiskStoreFFM to
simply call LinuxHWDiskStore.classifyDiskType(removable, rotational) after they
read their platform-specific sysattr strings (device.getSysattrValue(...) or
UdevFunctions.getSysattrValue(..., arena)); preserve the existing return values
("Removable", "SSD", "HDD", "Unknown") and behavior when inputs are null or
different.
- Around line 168-180: The current detectDiskType(UdevDevice device) returns
"Removable" whenever removable="1", hiding SSD/HDD info for external drives;
change the logic so detectDiskType first checks the rotational sysattr
(device.getSysattrValue("queue/rotational")) and returns "SSD" for "0" or "HDD"
for "1" when that value is present, and only return "Removable" if rotational is
missing/empty (or unknown), and update the Javadoc for
detectDiskType/getDiskType to state that removable is only used when rotational
info is unavailable.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: a717292e-b4b6-4870-924c-92148e4fadf8
📒 Files selected for processing (6)
CHANGELOG.mdoshi-common/src/main/java/oshi/hardware/HWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/hardware/HWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java
🔇 Additional comments (7)
oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (2)
200-212: Mirrors the JNA implementation as expected.Behaviorally identical to
LinuxHWDiskStoreJNA.detectDiskType. The "Removable beats SSD/HDD" precedence note and the optional-shared-helper suggestion on the JNA side both apply here as well — no need to re-discuss.
40-42: FFM constructor wiring matches the JNA path.The new constructor, the
"Virtual"literal for DM devices, and thedetectDiskType(device, arena)call for non-DM devices line up cleanly withLinuxHWDiskStoreJNA, which is what we want for FFM/JNA parity.Also applies to: 104-104, 127-130
CHANGELOG.md (1)
5-5: Changelog entry looks good.Properly placed under the in-progress 7.1.0 section and references issue
#2857with the correct attribution.oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java (2)
21-33: Clean addition with backward-compatible constructor.Delegating the 4-arg constructor to the 5-arg one with
"Unknown"keeps existing subclasses working without changes. If you adopt the constants suggestion onHWDiskStore, the literal here can be replaced byHWDiskStore.TYPE_UNKNOWNfor a single source of truth.
60-75: toString update looks good.Including the disk type in the existing
(model: ... - S/N: ... - type: ...)block is consistent with the surrounding format.oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java (1)
86-88: Straightforward pass-through constructor.Forwards correctly to the new 5-arg superclass constructor; the old 4-arg constructor is preserved for compatibility.
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java (1)
90-91: DM → "Virtual" classification looks correct.Hardcoding
"Virtual"for/dev/dm-*devices matches the PR's documented behavior for device-mapper/LVM targets.
09b042e to
03796dd
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #3230 +/- ##
============================================
- Coverage 63.79% 63.67% -0.13%
Complexity 73 73
============================================
Files 420 421 +1
Lines 19307 19358 +51
Branches 3358 3366 +8
============================================
+ Hits 12317 12326 +9
- Misses 5289 5320 +31
- Partials 1701 1712 +11
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java (1)
157-170: ⚡ Quick win
parseWindowsMediaTypeis identical inWindowsHWDiskStoreFFM— extract to the common base class.The method operates purely on a
Stringwith no JNA-specific types, so it can (and should) live inWindowsHWDiskStoreas aprotected staticmethod, removing the duplication. As a bonus, the explanatory comment about the SSD/HDD ambiguity (present here) would then also cover the FFM path, which currently omits it.♻️ Suggested refactor
Move the method to
WindowsHWDiskStore.java:+ /** + * Maps a WMI Win32_DiskDrive MediaType string to a simplified disk type. + * Note: WMI MediaType cannot distinguish SSD from HDD for fixed disks. + * + * `@param` mediaType the WMI MediaType string + * `@return` "Removable", "HDD", or "Unknown" + */ + protected static String parseWindowsMediaType(String mediaType) { + if (mediaType == null || mediaType.isEmpty()) { + return "Unknown"; + } + String lower = mediaType.toLowerCase(Locale.ROOT); + if (lower.contains("removable")) { + return "Removable"; + } else if (lower.contains("fixed") || lower.contains("external")) { + // WMI doesn't distinguish SSD from HDD via MediaType alone; + // "Fixed hard disk media" could be either. Return HDD as default for fixed. + return "HDD"; + } + return "Unknown"; + }Then remove the identical private copies from
WindowsHWDiskStoreJNAandWindowsHWDiskStoreFFM.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java` around lines 157 - 170, Extract the duplicate private method parseWindowsMediaType(String) from WindowsHWDiskStoreJNA and WindowsHWDiskStoreFFM into the common superclass WindowsHWDiskStore as a protected static method (retain the existing logic and the SSD/HDD ambiguity comment), then delete the private copies in WindowsHWDiskStoreJNA and WindowsHWDiskStoreFFM so both subclasses call WindowsHWDiskStore.parseWindowsMediaType(...).oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (1)
200-216: ⚡ Quick winSilent
Throwablecatch makesdetectDiskTypefailures invisible — add a trace/debug log.When
getSysattrValuethrows (e.g., due to an unexpected FFM error or a pathological device), the catch block discards the exception entirely. Adding even aLOG.trace(...)orLOG.debug(...)call makes it possible to diagnose why devices end up as"Unknown"in production without any other code change.📋 Suggested change
} catch (Throwable t) { // NOSONAR - // Unable to read sysattr, return Unknown + LOG.debug("Unable to read sysattr for disk type detection: {}", t.getMessage()); }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java` around lines 200 - 216, The catch in detectDiskType currently swallows all Throwables from UdevFunctions.getSysattrValue; update that catch to log the throwable at trace or debug level (e.g., LOG.trace or LOG.debug) including a brief message and the exception to aid diagnosis, then continue returning "Unknown"; ensure you reference detectDiskType and the calls to UdevFunctions.getSysattrValue("removable", arena) and ("queue/rotational", arena) so the logged message identifies which sysattr failed.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@oshi-common/src/main/java/oshi/hardware/HWDiskStore.java`:
- Around line 54-61: The Javadoc for HWDiskStore.getDiskType mentions "Network"
as a possible return value even though the default implementation returns
"Unknown" and no platform implementations return "Network"; update the Javadoc
for the getDiskType method to either remove "Network" from the enumerated values
or explicitly mark it as reserved/for-future-use so docs match actual
behavior—edit the Javadoc on the HWDiskStore.getDiskType declaration to reflect
this change.
---
Nitpick comments:
In
`@oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java`:
- Around line 200-216: The catch in detectDiskType currently swallows all
Throwables from UdevFunctions.getSysattrValue; update that catch to log the
throwable at trace or debug level (e.g., LOG.trace or LOG.debug) including a
brief message and the exception to aid diagnosis, then continue returning
"Unknown"; ensure you reference detectDiskType and the calls to
UdevFunctions.getSysattrValue("removable", arena) and ("queue/rotational",
arena) so the logged message identifies which sysattr failed.
In
`@oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java`:
- Around line 157-170: Extract the duplicate private method
parseWindowsMediaType(String) from WindowsHWDiskStoreJNA and
WindowsHWDiskStoreFFM into the common superclass WindowsHWDiskStore as a
protected static method (retain the existing logic and the SSD/HDD ambiguity
comment), then delete the private copies in WindowsHWDiskStoreJNA and
WindowsHWDiskStoreFFM so both subclasses call
WindowsHWDiskStore.parseWindowsMediaType(...).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 47fe5d56-72a5-4c2b-a570-0b6b373295a2
📒 Files selected for processing (10)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.javaoshi-common/src/main/java/oshi/hardware/HWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
✅ Files skipped from review due to trivial changes (1)
- CHANGELOG.md
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (10)
- GitHub Check: Codacy Static Code Analysis
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: Analyze (java)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.javaoshi-common/src/main/java/oshi/hardware/HWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
🔇 Additional comments (7)
oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java (1)
172-183: Duplicate of theparseWindowsMediaTypeinWindowsHWDiskStoreJNA— covered by the refactor comment there.Also note that the SSD/HDD ambiguity comment present in the JNA copy is absent here, which could lead to maintainers diverging the logic between the two copies in future. Extracting to the common base resolves both.
oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.java (1)
23-25: LGTM —MEDIATYPEcorrectly added in alphabetical order.The OSHI WMI result maps use enum constants as keys (not ordinals), so inserting
MEDIATYPEbetweenMANUFACTURERandMODELhas no impact on existing lookups. WMI property matching is case-insensitive, soMEDIATYPEmaps correctly to the WMIMediaTypecolumn.oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java (1)
21-33: Clean implementation — immutablediskTypefield with proper constructor delegation.The
finalfield together with the delegating 4-arg constructor ensures backward-compatible defaults and thread safety. No issues.oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java (1)
53-55: LGTM — straightforward delegation to the newAbstractHWDiskStore5-arg constructor.oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java (1)
86-88: LGTM — mirrors the same pattern applied toLinuxHWDiskStore.oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java (1)
168-180:detectDiskTypelogic is correct and well-ordered.Checking
removablebeforequeue/rotationalcorrectly classifies USB-attached SSDs as"Removable"rather than"SSD", which matches the PR's stated intent. The"Unknown"fallback for unexpectedqueue/rotationalvalues is appropriately defensive.oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (1)
36-42: ⚡ Quick winThe review comment's concern has been verified and found to be resolved by design.
AbstractHWDiskStoreincludes a 4-arg constructor (lines 23–25 in AbstractHWDiskStore.java) that chains to the 5-arg constructor with"Unknown"as the diskType value:protected AbstractHWDiskStore(String name, String model, String serial, long size) { this(name, model, serial, size, "Unknown"); }This means the old 4-arg constructor in
LinuxHWDiskStoreFFM(line 36) correctly delegates to the parent and guarantees thatgetDiskType()returns"Unknown"rather thannull. No issue here—the code is already correct!
Resolves #2857 Adds getDiskType() to HWDiskStore interface with a default of 'Unknown'. Linux implementation reads sysfs attributes: - /sys/block/<name>/removable (1 = Removable) - /sys/block/<name>/queue/rotational (0 = SSD, 1 = HDD) - Device-mapper devices report 'Virtual' Implemented for both JNA and FFM Linux backends. Other platforms return 'Unknown' (can be enhanced in follow-up PRs).
03796dd to
b7fb13b
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (3)
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java (2)
39-45: 💤 Low valueConsider dropping the unused 4-arg constructor.
After this PR every construction site goes through the 5-arg form (DM branch passes
"Virtual", non-DM passesdetectDiskType(device)). The legacy 4-arg constructor is effectively dead and just defers to the parent's"Unknown"default — fine to keep if symmetry with the FFM variant matters, but otherwise easy to remove.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java` around lines 39 - 45, Remove the unused 4-argument constructor in class LinuxHWDiskStoreJNA (the method LinuxHWDiskStoreJNA(String name, String model, String serial, long size)) since all call sites now use the 5-arg constructor; delete that constructor, ensure no remaining references expect the 4-arg form, and update any tests or usages to call the 5-arg constructor LinuxHWDiskStoreJNA(String name, String model, String serial, long size, String diskType) (passing "Unknown" or an appropriate detected diskType where needed).
168-180: ⚡ Quick winMirror the FFM twin's defensive handling.
The FFM
detectDiskTypewraps the sysattr reads intry { … } catch (Throwable t) { LOG.debug(…); }and falls back to"Unknown". This JNA version doesn't, andgetDisks()has no surrounding catch in the disk-iteration block (it only relies ondevice.unref()infinally), so an unexpected exception here would abort the entire disk enumeration rather than just leaving one device's type asUnknown. Aligning the two helpers keeps the platform behavior symmetric.♻️ Suggested change
private static String detectDiskType(UdevDevice device) { - String removable = device.getSysattrValue("removable"); - if ("1".equals(removable)) { - return "Removable"; - } - String rotational = device.getSysattrValue("queue/rotational"); - if ("0".equals(rotational)) { - return "SSD"; - } else if ("1".equals(rotational)) { - return "HDD"; - } - return "Unknown"; + try { + String removable = device.getSysattrValue("removable"); + if ("1".equals(removable)) { + return "Removable"; + } + String rotational = device.getSysattrValue("queue/rotational"); + if ("0".equals(rotational)) { + return "SSD"; + } else if ("1".equals(rotational)) { + return "HDD"; + } + } catch (RuntimeException e) { + LOG.debug("Unable to read disk type sysattr", e); + } + return "Unknown"; }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java` around lines 168 - 180, The detectDiskType(UdevDevice device) method should defensively wrap the sysattr reads in a try/catch (catch Throwable) similar to the FFM twin: surround the calls to device.getSysattrValue("removable") and device.getSysattrValue("queue/rotational") with a try block, on any thrown Throwable log a debug-level message identifying the device and exception (use the existing LOG) and return "Unknown"; this prevents exceptions from aborting getDisks() and keeps behavior symmetric with the FFM helper.oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java (1)
21-33: ⚡ Quick winConsider centralizing disk-type values as constants or an enum.
Across the PR the strings
"Unknown","SSD","HDD","Removable", and"Virtual"are repeated as literals inAbstractHWDiskStore, the Linux FFM/JNAdetectDiskTypehelpers, the DM branches, andparseWindowsMediaType. A small typo in any platform-specific path would silently produce a value the rest of the system doesn't recognize. Defining them once (e.g., public string constants onHWDiskStore, or an enum likeHWDiskStore.Typethat exposes a stable display name) would make the contract explicit and easier to extend toward the broader categories described in#2857(optical, network, flash, etc.).Also a small consistency nit: the 4-arg constructor uses the literal
"Unknown"here whileLinuxHWDiskStoreFFM/JNAalready useConstants.UNKNOWNfornullmodel/serial fallbacks. Worth aligning regardless of whether the broader enum suggestion lands.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java` around lines 21 - 33, Introduce a single centralized set of disk-type identifiers (either public constants or an enum) and replace all string literals with those identifiers; specifically add a public enum or public static final Strings (e.g., HWDiskStore.Type { UNKNOWN, SSD, HDD, REMOVABLE, VIRTUAL } or HWDiskStore.UNKNOWN/SSD/etc.), update AbstractHWDiskStore to use that UNKNOWN identifier in the 4-arg constructor and set diskType to the enum/constant in the 5-arg constructor, and refactor all platform helpers (detectDiskType methods in LinuxFFM/JNA, DM branches, parseWindowsMediaType) to return/compare the centralized values instead of repeating literals so every path uses the same canonical identifiers.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java`:
- Around line 21-33: Introduce a single centralized set of disk-type identifiers
(either public constants or an enum) and replace all string literals with those
identifiers; specifically add a public enum or public static final Strings
(e.g., HWDiskStore.Type { UNKNOWN, SSD, HDD, REMOVABLE, VIRTUAL } or
HWDiskStore.UNKNOWN/SSD/etc.), update AbstractHWDiskStore to use that UNKNOWN
identifier in the 4-arg constructor and set diskType to the enum/constant in the
5-arg constructor, and refactor all platform helpers (detectDiskType methods in
LinuxFFM/JNA, DM branches, parseWindowsMediaType) to return/compare the
centralized values instead of repeating literals so every path uses the same
canonical identifiers.
In
`@oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.java`:
- Around line 39-45: Remove the unused 4-argument constructor in class
LinuxHWDiskStoreJNA (the method LinuxHWDiskStoreJNA(String name, String model,
String serial, long size)) since all call sites now use the 5-arg constructor;
delete that constructor, ensure no remaining references expect the 4-arg form,
and update any tests or usages to call the 5-arg constructor
LinuxHWDiskStoreJNA(String name, String model, String serial, long size, String
diskType) (passing "Unknown" or an appropriate detected diskType where needed).
- Around line 168-180: The detectDiskType(UdevDevice device) method should
defensively wrap the sysattr reads in a try/catch (catch Throwable) similar to
the FFM twin: surround the calls to device.getSysattrValue("removable") and
device.getSysattrValue("queue/rotational") with a try block, on any thrown
Throwable log a debug-level message identifying the device and exception (use
the existing LOG) and return "Unknown"; this prevents exceptions from aborting
getDisks() and keeps behavior symmetric with the FFM helper.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 0a32c986-2502-420c-adcc-18b67504bd1e
📒 Files selected for processing (10)
CHANGELOG.mdoshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.javaoshi-common/src/main/java/oshi/hardware/HWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.javaoshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.javaoshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
🚧 Files skipped from review as they are similar to previous changes (2)
- oshi-common/src/main/java/oshi/hardware/common/platform/windows/WindowsHWDiskStore.java
- oshi-common/src/main/java/oshi/hardware/HWDiskStore.java
📜 Review details
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (12)
- GitHub Check: Analyze (java)
- GitHub Check: Test JDK 21, windows-latest
- GitHub Check: Test JDK 25, macos-latest (+ JNA==FFM)
- GitHub Check: JMH Benchmarks, ubuntu-latest
- GitHub Check: Test JDK 11, macos-latest
- GitHub Check: Test JDK 11, windows-latest
- GitHub Check: Test JDK 21, macos-latest
- GitHub Check: Test JDK 25, windows-latest (+ JNA==FFM)
- GitHub Check: Lint (Spotless, Checkstyle, ForbiddenAPIs, Javadoc)
- GitHub Check: JMH Benchmarks, windows-latest
- GitHub Check: JMH Benchmarks, macos-latest
- GitHub Check: Codacy Static Code Analysis
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2026-04-06T04:45:47.644Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3121
File: oshi-core/src/main/java/oshi/software/os/linux/LinuxOperatingSystem.java:53-53
Timestamp: 2026-04-06T04:45:47.644Z
Learning: In the oshi/oshi project, only interfaces and classes in the root packages `oshi`, `oshi.hardware`, and `oshi.software.os` are considered the public API. Code in subpackages that represent specific implementations/platforms (e.g., `oshi.software.os.linux`, `oshi.hardware.platform.linux`, and similar subpackages) is implementation detail. When reviewing, do not treat changes to classes in these platform-specific subpackages as public API breaks (for example: making `LinuxOperatingSystem` abstract, narrowing constructor visibility, or adding/removing abstract methods should not be flagged as breaking public API).
Applied to files:
oshi-core/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreJNA.javaoshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java
📚 Learning: 2026-04-12T19:22:09.716Z
Learnt from: dbwiddis
Repo: oshi/oshi PR: 3149
File: oshi-common/src/main/java/oshi/hardware/common/platform/mac/MacCentralProcessor.java:159-163
Timestamp: 2026-04-12T19:22:09.716Z
Learning: When reviewing OSHI hardware platform code that uses or implements `CentralProcessor`/`PhysicalProcessor.getEfficiency()`, remember the API’s counterintuitive semantics: a *higher* efficiency-class value indicates *greater performance* (lower efficiency). P-cores/“performance cores” should therefore have higher values (e.g., 1) than E-cores/“efficiency cores” (e.g., 0), as documented in the `CentralProcessor` Javadoc. Do not flag code as incorrect solely because ARM_P_CORES or Intel P-cores are assigned higher efficiency values.
Applied to files:
oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.javaoshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.javaoshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java
🔇 Additional comments (9)
CHANGELOG.md (1)
5-5: LGTM!Entry format and placement match the existing 7.1.0 in-progress section.
oshi-common/src/main/java/oshi/hardware/common/platform/linux/LinuxHWDiskStore.java (1)
86-89: LGTM!Straightforward forwarding constructor that lines up with the new
AbstractHWDiskStore(String, String, String, long, String)signature.oshi-core-ffm/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreFFM.java (2)
80-92: LGTM — wiring matches the JNA variant.The MEDIATYPE →
parseWindowsMediaTypepath mirrorsWindowsHWDiskStoreJNA.getDisks(), which keeps the two implementations in lockstep. Just make sure (per the JNA-file comment) that there's a single canonicalparseWindowsMediaTypeto avoid drift between FFM and JNA.
51-57: 💤 Low valueSame observation as the JNA variant: 4-arg constructor likely unused.
getDisks()now only constructs via the 5-arg form. Worth checking whether the 4-arg constructor still has callers, and removing it (or routing it through the 5-arg with"Unknown") so the two paths can't drift.oshi-core/src/main/java/oshi/hardware/platform/windows/WindowsHWDiskStoreJNA.java (2)
46-52: 💤 Low valueCheck whether the 4-arg constructor is still reachable.
getDisks()now exclusively uses the 5-arg form. If nothing else callsWindowsHWDiskStoreJNAwith the 4-arg signature, it's dead code that just delegates to a parent constructor that defaultsdiskTypeto"Unknown". You could remove it or have it call the 5-arg form with"Unknown"to keep the code cleaner.
75-80: ⚡ Quick winVerify parseWindowsMediaType definition locations before proceeding.
Unable to confirm the shadowing concern due to access limitations—shell execution failed repeatedly, and web search of public OSHI sources found no evidence of
parseWindowsMediaType. However, this doesn't confirm the method doesn't exist in the working codebase or that shadowing isn't occurring. Manual inspection of the actual source files is needed to verify:
- Whether
parseWindowsMediaTypeexists in both the parent class (WindowsHWDiskStore) asprotected staticand inWindowsHWDiskStoreJNAasprivate static- If both definitions exist, whether they can drift apart or if one intentionally shadows the other
- If only one canonical definition should exist (the protected one in the parent for shared behavior across JNA and FFM subclasses)
oshi-common/src/main/java/oshi/hardware/common/AbstractHWDiskStore.java (1)
60-75: 💤 Low valueCheck for downstream dependencies on the toString() format change.
The toString() method format has changed from
(model: <m>) S/N: <s>, size: …to(model: <m> - S/N: <s> - type: <t>) size: …. While this is a reasonable layout improvement, any code that parses or asserts against this string representation (in tests, demo code, or log analysis) should be re-checked to ensure compatibility with the new format.oshi-common/src/main/java/oshi/driver/common/windows/wmi/Win32DiskDrive.java (1)
24-24: 💤 Low valueVerify that no code depends on
DiskDrivePropertyenum ordinals.The insertion of
MEDIATYPEbetweenMANUFACTURERandMODELshifts the ordinal positions of subsequent enum constants. While WMI lookups safely usename()rather than ordinals, if any code elsewhere uses.ordinal()directly or indexes intovalues()by position, this change could break that logic. A quick search of the codebase for ordinal-dependent usage of this enum would confirm it's safe.oshi-core-ffm/src/main/java/oshi/hardware/platform/linux/LinuxHWDiskStoreFFM.java (1)
200-216: ⚡ Quick winThe nested sysattr path handling is correct.
The FFM wrapper's implementation directly allocates the sysattr string as-is via
arena.allocateFrom(sysattr)without sanitizing or stripping "/" characters. This means"queue/rotational"is passed correctly to the nativeudev_device_get_sysattr_valuecall, matching the documented udev behavior. The defensive try/catch around sysattr reads is a reasonable design choice in the FFM variant and will gracefully return "Unknown" if udev fails.
Summary
Resolves #2857
Adds a
getDiskType()method to theHWDiskStoreinterface that reports the physical media type of a disk drive.Returned values
SSDHDDRemovableVirtualUnknownImplementation
Linux (JNA + FFM)
Reads sysfs attributes via udev:
/sys/block/<name>/removable— 1 indicates removable media/sys/block/<name>/queue/rotational— 0 = SSD, 1 = HDD/dev/dm-*) are reported asVirtualOther platforms
Returns
Unknownvia the interface default method. Windows (WMI MediaType) and macOS (IOKit) support can be added in follow-up PRs.API
Changes
HWDiskStore.java: Addeddefault String getDiskType()returning"Unknown"AbstractHWDiskStore.java: AddeddiskTypefield, 5-arg constructor,getDiskType()override, updatedtoString()LinuxHWDiskStore.java: Added 5-arg constructorLinuxHWDiskStoreJNA.java: AddeddetectDiskType()using udev sysattr readsLinuxHWDiskStoreFFM.java: Same detection logic using FFM udev functionsCHANGELOG.md: Entry for this PRSummary by CodeRabbit
New Features
Documentation