You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is generally available using the OSFileStore class with either getName(), getDescription(), or you can sometimes infer things from getType(). Here's the output for Windows, for example (from the latest CI run):
File System:
File Descriptors: 39889/16711680
3 1/2 Inch Floppy Drive (A:) (Removable drive) [] 0 bytes of 0 bytes free (NaN%), 0 of 0 files free (NaN%) is \\?Voolume{6bae4c43-08f7-11f0-9f62-806e6f6e6963}\ and is mounted at A:\
Local Fixed Disk (C:) (Fixed drive) [NTFS] 79.6 GiB of 255.5 GiB free (31.1%), 0 of 0 files free (NaN%) is \\?\Volume{5340b4dc-0000-0000-0000-501f00000000}\ and is mounted at C:\
Local Fixed Disk (D:) (Fixed drive) [NTFS] 147.0 GiB of 150.0 GiB free (98.0%), 0 of 0 files free (NaN%) is \\?\Volume{3230d594-0000-0000-0000-100000000000}\ and is mounted at D:\
You'd have to correlate the filesystem to the hardware to match it up. See example here.
@dbwiddis When creating this issue, I was specifically trying to avoid any kind of parsing to determine the disk type. What I meant is an enum with predefined disk types, so that each user wouldn't have to reinvent the wheel, but simply select icons for the existing disk types.
When creating this issue, I was specifically trying to avoid any kind of parsing to determine the disk type.
Fair enough, but operating systems don't provide this information in any standard format other than name or description. Here's what the OS provides on Windows, for example, which goes into "type":
I could tell you it's a "removable drive" with that type "2", but not whether it's a floppy or thumb drive, without the name or description. And that's Windows-only, not cross-platform.
You might consider just using Java's FileSystemView class. FileSystemView.getFileSystemView().isFloppyDrive() can tell you if you have a floppy drive, for example. isComputerNode() probably identifies a network drive, etc.
I'm happy to consider adding something to the OSHI API if you can tell me where I can get the information cross-platform other than in the name or description.
This is all I found I can do in Java to check if the disk is optical, floppy, or a network drive.
At the same time, I thought that by using native code, it would be possible to determine the type of any disk on all platforms. If that's not possible, it would be very sad.
To check if it is a network drive, I use the output of (windows):
Process process = new ProcessBuilder("cmd", "/c", "net use").start();
At the same time, I thought that by using native code, it would be possible to determine the type of any disk on all platforms. If that's not possible, it would be very sad.
It is possible using native code on Windows: see the snippet above using Kernel32.INSTANCE.GetDriveType(). This is a native function mapped on JNA which, as a dependency, is available to you to use, if you know you're on Windows. Here are the return values.
Other than Windows, however, this information is difficult to get. While we try to use native methods (such as udev) to collect information we're still limited to strings describing the disk, or device paths.
On macOS, we use a regex to match the volume name (/dev/disk for local disk, localhost: or smb: for network, etc., for example). I don't know of any other way.
On Linux, and Unix we do a similar match of /dev in the volume, parse the volume name, or match filesystem types. I don't know of any other way.
Compared to the individual parsing on all the *nix systems, OSHI at least standardizes the types in the "Description" which has a more limited set of Strings you can try to match (and matches them to the Windows output as well). I honestly think that, or the FileSystemView methods, are the best you can do cross-platform.
If you think you can improve OSHI's parsing (such as using /dev/fd for floppies) feel free to submit a PR; I do not consider floppy disks a high priority. I think the FileSystemView methods are sufficient for the overwhelming majority of real world use cases.
I'm going to close this issue as I think I've outlined the options. Other than the OSHI API which does its best to use standardized cross-platform strings (for easier parsing) you can directly use the native call on Windows using the already-included JNA dependency, or the FileSystemView methods in Java. Beyond that, parsing strings is really the only option.
Revisiting this idea. While a fully cross-platform disk type enum may not be feasible, we could expose what the OS does provide:
Linux:/sys/block/<device>/queue/rotational reliably distinguishes SSD (0) vs HDD (1). This is what lsblk -d -o NAME,ROTA uses. Additionally, /sys/block/<device>/device/type provides SCSI device type codes, and the transport (/sys/block/<device>/device/transport) can identify NVMe, USB, etc.
Windows:IOCTL_STORAGE_QUERY_PROPERTY with StorageDeviceProperty returns a STORAGE_DEVICE_DESCRIPTOR containing BusType (NVMe, SATA, USB, etc.) and RemovableMedia. WMI MSFT_PhysicalDisk has a MediaType field (0=Unspecified, 3=HDD, 4=SSD). Both are accessible via JNA/FFM.
macOS:IOKit provides IOMedia properties including Whole, Removable, and the device characteristics dictionary which can indicate solid-state vs. rotational.
Proposal
Add to HWDiskStore:
/** * Whether this disk is a solid-state drive (non-rotational media). * Returns true for SSDs and NVMe drives, false for HDDs, * or false if the information is unavailable. */booleanisSolidState();
/** * Whether this disk uses removable media. */booleanisRemovable();
These are simple booleans rather than an enum, avoiding the "what categories do we define" problem. They cover the most common use case (SSD vs HDD distinction for performance tuning and monitoring dashboards) and are implementable on Linux, Windows, and macOS.
Returning false as a default when the information is unavailable is consistent with OSHI's existing pattern for optional hardware details.
Introduce two boolean properties (solidState, removable) as orthogonal, independently-determinable characteristics rather than forcing a single enum categorization
Extend the immutable field pattern established by AbstractHWDiskStore and HWPartition, maintaining backward compatibility via constructor overloading with false defaults
Implement platform-specific detection: MSFT_PhysicalDisk/IOCTL_STORAGE_QUERY_PROPERTY for Windows, sysfs queue/rotational and removable for Linux, IOKit Solid State and Removable properties for macOS
Default to false for platforms or devices where properties cannot be determined, consistent with OSHI patterns
Design ChoicesDesign Choice 1: Boolean Properties vs Enum for Disk Type Classification
Options Considered:
Enum (DiskType) — Single field with values like HDD, SSD, OPTICAL, FLOPPY, NETWORK, UNKNOWN; forces categorization into exactly one type
Two Booleans (solidState, removable) — Orthogonal properties that can be independently determined; avoids forced categorization; covers primary use cases
Chosen Option: 2
Rationale: Two boolean fields provide independent answers to the most common questions: "Is this an SSD or HDD?" and "Is this removable?" This avoids forcing devices into artificial categories (e.g., a removable SSD would need to be one or the other with an enum). Using false as the default is consistent with OSHI patterns for unknown/unsupported values, and booleans are simpler to extend if additional properties are needed in the future.
💡 User Tips
Regenerate the plan with different choices with @coderabbitai <feedback>.
Implementation Steps
Phase 1: API and Core Infrastructure
Extend the public API and base classes to support the two new boolean properties. This establishes the contract that all platform implementations will fulfill.
Task 1: Extend HWDiskStore Interface
Add the two new boolean methods to the public disk store interface.
Add boolean isSolidState(); method to HWDiskStore.java in oshi-common
Add boolean isRemovable(); method to HWDiskStore.java in oshi-common
Add Javadoc: isSolidState() returns true for solid-state storage (SSD, NVMe, flash), false for rotational (HDD) or if unknown
Add Javadoc: isRemovable() returns true for removable media (USB drives, SD cards, optical), false otherwise or if unknown
Task 2: Extend AbstractHWDiskStore Base Class
Add the two booleans as immutable fields in the base abstract class, following the established pattern.
Add private final boolean solidState; field to AbstractHWDiskStore.java
Add private final boolean removable; field to AbstractHWDiskStore.java
Create new 6-parameter constructor: (String name, String model, String serial, long size, boolean solidState, boolean removable)
Modify existing 4-parameter constructor to delegate to new constructor with false, false as defaults
Add @Override public boolean isSolidState() getter
Add @Override public boolean isRemovable() getter
Update toString() to include solidState and removable values
Task 3: Update Intermediate Common Classes
Extend the constructor chains in the platform-specific common base classes to accept and pass through both boolean properties.
Update WindowsHWDiskStore.java in oshi-common: add 6-param constructor calling super(..., solidState, removable), keep 4-param delegating with false, false
Update LinuxHWDiskStore.java in oshi-common: same pattern
Update MacHWDiskStore.java in oshi-common: same pattern
🤖 Prompt for AI agents
This phase wires the two new boolean properties (`solidState`, `removable`)
through the public API and base class hierarchy — great first step, and a really
important foundation for everything that follows!
- **Update `HWDiskStore.java`** in oshi-common:
- Add method declaration: `boolean isSolidState();`
- Add method declaration: `boolean isRemovable();`
- Add Javadoc for `isSolidState()`: returns true for solid-state storage (SSD,
NVMe, flash), false for rotational (HDD) or if unknown
- Add Javadoc for `isRemovable()`: returns true for removable media (USB drives,
SD cards, optical), false otherwise or if unknown
- **Update `AbstractHWDiskStore.java`**:
- Add `private final boolean solidState;` field
- Add `private final boolean removable;` field
- Add new 6-parameter constructor: `(String name, String model, String serial,
long size, boolean solidState, boolean removable)`
- Update existing 4-parameter constructor to delegate to the new constructor
with `false, false` as defaults
- Add `@Override public boolean isSolidState()` getter returning the field
- Add `@Override public boolean isRemovable()` getter returning the field
- Update `toString()` to include solidState and removable values
- **Update intermediate common classes** (`WindowsHWDiskStore.java`,
`LinuxHWDiskStore.java`, `MacHWDiskStore.java` in oshi-common):
- For each: add a 6-param constructor that calls `super(..., solidState,
removable)`
- Keep the existing 4-param constructor delegating to the new one with `false,
false`
Phase 2: Major Platform Detection Implementation
Implement detection for the three major platforms (Windows, Linux, macOS) where reliable detection mechanisms exist.
Task 1: Windows Disk Type Detection
Implement solid-state and removable detection using WMI and storage device properties.
For solid-state detection: Query MSFT_PhysicalDisk WMI class MediaType property (value 4 = SSD, value 3 = HDD) via a new driver in oshi-common/src/main/java/oshi/driver/common/windows/wmi/
Alternatively, use IOCTL_STORAGE_QUERY_PROPERTY with StorageDeviceSeekPenaltyProperty — no seek penalty indicates SSD
For removable detection: Query Win32_DiskDriveMediaType property containing "Removable" or use STORAGE_DEVICE_DESCRIPTOR.RemovableMedia field
Update WindowsHWDiskStoreJNA.java in oshi-core to query both properties and pass booleans to constructor
Update WindowsHWDiskStoreFFM.java in oshi-core-ffm with equivalent logic
Task 2: Linux Disk Type Detection
Implement solid-state and removable detection using sysfs and udev properties.
Add constant ROTATIONAL = "queue/rotational" to LinuxHWDiskStore.java for sysfs attribute path
Add constant REMOVABLE = "removable" for sysfs attribute
Update LinuxHWDiskStoreJNA.java in oshi-core:
Read /sys/block/<device>/queue/rotational via device.getSysattrValue("queue/rotational") — value "0" = solidState true, "1" = solidState false
Read /sys/block/<device>/removable via device.getSysattrValue("removable") — value "1" = removable true
For LVM/DM devices: default both to false (underlying device type not easily accessible)
Update LinuxHWDiskStoreFFM.java in oshi-core-ffm with equivalent logic
Task 3: macOS Disk Type Detection
Implement solid-state and removable detection using IOKit properties.
Add SOLID_STATE("Solid State") to CFKey enum in MacHWDiskStore.java
Add REMOVABLE("Removable") to CFKey enum in MacHWDiskStore.java
Update MacHWDiskStoreJNA.java in oshi-core:
Query IOKit IOMedia or parent IOBlockStorageDevice for "Solid State" boolean property → solidState
Query IOKit IOMedia for "Removable" boolean property → removable
Update MacHWDiskStoreFFM.java in oshi-core-ffm with equivalent logic
🤖 Prompt for AI agents
This phase implements the actual disk type detection for Windows, Linux, and
macOS — the three platforms where reliable detection mechanisms exist. Each
platform has its own detection strategy, and both booleans (`solidState`,
`removable`) need to be populated.
**Windows** (`WindowsHWDiskStoreJNA.java` in oshi-core,
`WindowsHWDiskStoreFFM.java` in oshi-core-ffm):
- For solid-state detection: Add a new WMI driver in
`oshi-common/src/main/java/oshi/driver/common/windows/wmi/` to query the
`MSFT_PhysicalDisk` WMI class `MediaType` property:
- Value 4 → solidState = true (SSD)
- Value 3 → solidState = false (HDD)
- Alternatively, use `IOCTL_STORAGE_QUERY_PROPERTY` with
`StorageDeviceSeekPenaltyProperty` — no seek penalty indicates SSD
- For removable detection: Query `Win32_DiskDrive` `MediaType` property for
"Removable", or use `STORAGE_DEVICE_DESCRIPTOR.RemovableMedia` field
- Pass both booleans to the 6-param constructor
- Apply equivalent logic in both JNA and FFM implementations
**Linux** (`LinuxHWDiskStoreJNA.java` in oshi-core, `LinuxHWDiskStoreFFM.java`
in oshi-core-ffm):
- Add constants to `LinuxHWDiskStore.java`: `ROTATIONAL = "queue/rotational"`
and `REMOVABLE = "removable"`
- Read `/sys/block/<device>/queue/rotational` via
`device.getSysattrValue("queue/rotational")`:
- `"0"` → solidState = true
- `"1"` → solidState = false
- Read `/sys/block/<device>/removable` via
`device.getSysattrValue("removable")`:
- `"1"` → removable = true
- For LVM/DM devices: default both to false (underlying device type not easily
accessible)
- Apply equivalent logic in both JNA and FFM implementations
**macOS** (`MacHWDiskStoreJNA.java` in oshi-core, `MacHWDiskStoreFFM.java` in
oshi-core-ffm):
- Add `SOLID_STATE("Solid State")` to the `CFKey` enum in `MacHWDiskStore.java`
- Add `REMOVABLE("Removable")` to the `CFKey` enum in `MacHWDiskStore.java`
- Query IOKit `IOMedia` or parent `IOBlockStorageDevice` for the `"Solid State"`
boolean property → solidState
- Query IOKit `IOMedia` for the `"Removable"` boolean property → removable
- Apply equivalent logic in both JNA and FFM implementations
Phase 3: Unix Platform Implementations
Update the remaining Unix platform implementations to support the new fields, defaulting to false where detection is not straightforward.
Task 1: FreeBSD Disk Type Support
Update FreeBSD implementation with basic detection or false defaults.
Update FreeBsdHWDiskStore.java in oshi-core to call the 6-param super constructor
Check if GEOM provides rotational info via geom disk list output; if "rotationrate: 0" → solidState true, if > 0 → solidState false
Default removable to false (can be enhanced in future)
Default both to false if not determinable
Task 2: OpenBSD Disk Type Support
Update OpenBSD implementation with false defaults.
Update OpenBsdHWDiskStore.java in oshi-core to call the 6-param super constructor with false, false
Limited detection available; can be enhanced in future PRs
Task 3: Solaris Disk Type Support
Update Solaris implementation with false defaults.
Update SolarisHWDiskStore.java in oshi-core to call the 6-param super constructor with false, false
Detection can be added in future enhancement if iostat -En provides reliable hints
Task 4: AIX Disk Type Support
Update AIX implementation with false defaults.
Update AixHWDiskStore.java in oshi-core to call the 6-param super constructor with false, false
perfstat_disk_t type field could be mapped in future enhancement
🤖 Prompt for AI agents
This phase updates the remaining Unix platform implementations (FreeBSD,
OpenBSD, Solaris, AIX) to support the new `solidState` and `removable` fields.
Most will default to `false`, with basic detection where it's feasible — every
platform contributing something is a wonderful step forward, and these can
always be improved in follow-up contributions!
**FreeBSD** (`FreeBsdHWDiskStore.java` in oshi-core):
- Update to call the 6-param super constructor
- Attempt to parse GEOM output from `geom disk list`:
- `"rotationrate: 0"` → solidState = true
- rotation rate > 0 → solidState = false
- Default removable to false (can be enhanced in future)
- Default both to false if not determinable
**OpenBSD** (`OpenBsdHWDiskStore.java` in oshi-core):
- Update to call the 6-param super constructor passing `false, false`
- No additional detection logic at this time (can be enhanced in future PRs)
**Solaris** (`SolarisHWDiskStore.java` in oshi-core):
- Update to call the 6-param super constructor passing `false, false`
- No additional detection logic at this time (`iostat -En` parsing can be added
in a future enhancement)
**AIX** (`AixHWDiskStore.java` in oshi-core):
- Update to call the 6-param super constructor passing `false, false`
- No additional detection logic at this time (`perfstat_disk_t` type field
mapping can be added in a future enhancement)
Phase 4: Testing and Documentation
Validate the new functionality and ensure documentation is updated.
Task 1: Update Disk Store Tests
Add test coverage for the new boolean properties.
Update DisksTest.java in oshi-core test directory
Add assertion: assertThat(disk.isSolidState(), is(notNullValue())) (boolean is never null, but validates method exists)
Verify toString() output includes solidState and removable values
Task 2: Update Changelog
Document the new feature in the changelog.
Add entry to CHANGELOG.md under the appropriate version section
Note the new isSolidState() and isRemovable() methods on HWDiskStore
🤖 Prompt for AI agents
This phase adds test coverage and updates the changelog — a wonderful way to
wrap things up and make sure everything is well-documented for future
contributors!
**Update `DisksTest.java`** in the oshi-core test directory:
- Add assertion: `assertThat(disk.isSolidState(), is(notNullValue()))` to verify
the method exists and is always populated (boolean is never null)
- Add assertion: `assertThat(disk.isRemovable(), is(notNullValue()))` for the
same reason
- Verify that the `toString()` output includes the solidState and removable
values
**Update `CHANGELOG.md`**:
- Add an entry under the appropriate version section
- Note the addition of the new `isSolidState()` and `isRemovable()` methods on
`HWDiskStore`
Research
OSHI has a clean three-tier architecture for disk stores: the HWDiskStore interface (oshi-common), AbstractHWDiskStore abstract base class holding immutable identity fields (oshi-common), platform-specific intermediate common classes for Windows/Linux/macOS (oshi-common), and concrete JNA implementations (oshi-core) plus FFM implementations (oshi-core-ffm). Unix platforms (FreeBSD, OpenBSD, Solaris, AIX) extend AbstractHWDiskStore directly. The established pattern for adding immutable fields—demonstrated by HWPartition.label—involves adding a new constructor parameter while maintaining a backward-compatible overload that delegates with a default value.
🚀 Next Steps
🤖 All AI agent prompts combined
Task: 1
This phase wires the two new boolean properties (`solidState`, `removable`)
through the public API and base class hierarchy — great first step, and a really
important foundation for everything that follows!
- **Update `HWDiskStore.java`** in oshi-common:
- Add method declaration: `boolean isSolidState();`
- Add method declaration: `boolean isRemovable();`
- Add Javadoc for `isSolidState()`: returns true for solid-state storage (SSD,
NVMe, flash), false for rotational (HDD) or if unknown
- Add Javadoc for `isRemovable()`: returns true for removable media (USB drives,
SD cards, optical), false otherwise or if unknown
- **Update `AbstractHWDiskStore.java`**:
- Add `private final boolean solidState;` field
- Add `private final boolean removable;` field
- Add new 6-parameter constructor: `(String name, String model, String serial,
long size, boolean solidState, boolean removable)`
- Update existing 4-parameter constructor to delegate to the new constructor
with `false, false` as defaults
- Add `@Override public boolean isSolidState()` getter returning the field
- Add `@Override public boolean isRemovable()` getter returning the field
- Update `toString()` to include solidState and removable values
- **Update intermediate common classes** (`WindowsHWDiskStore.java`,
`LinuxHWDiskStore.java`, `MacHWDiskStore.java` in oshi-common):
- For each: add a 6-param constructor that calls `super(..., solidState,
removable)`
- Keep the existing 4-param constructor delegating to the new one with `false,
false`
===============================================================================
Task: 2
This phase implements the actual disk type detection for Windows, Linux, and
macOS — the three platforms where reliable detection mechanisms exist. Each
platform has its own detection strategy, and both booleans (`solidState`,
`removable`) need to be populated.
**Windows** (`WindowsHWDiskStoreJNA.java` in oshi-core,
`WindowsHWDiskStoreFFM.java` in oshi-core-ffm):
- For solid-state detection: Add a new WMI driver in
`oshi-common/src/main/java/oshi/driver/common/windows/wmi/` to query the
`MSFT_PhysicalDisk` WMI class `MediaType` property:
- Value 4 → solidState = true (SSD)
- Value 3 → solidState = false (HDD)
- Alternatively, use `IOCTL_STORAGE_QUERY_PROPERTY` with
`StorageDeviceSeekPenaltyProperty` — no seek penalty indicates SSD
- For removable detection: Query `Win32_DiskDrive` `MediaType` property for
"Removable", or use `STORAGE_DEVICE_DESCRIPTOR.RemovableMedia` field
- Pass both booleans to the 6-param constructor
- Apply equivalent logic in both JNA and FFM implementations
**Linux** (`LinuxHWDiskStoreJNA.java` in oshi-core, `LinuxHWDiskStoreFFM.java`
in oshi-core-ffm):
- Add constants to `LinuxHWDiskStore.java`: `ROTATIONAL = "queue/rotational"`
and `REMOVABLE = "removable"`
- Read `/sys/block/<device>/queue/rotational` via
`device.getSysattrValue("queue/rotational")`:
- `"0"` → solidState = true
- `"1"` → solidState = false
- Read `/sys/block/<device>/removable` via
`device.getSysattrValue("removable")`:
- `"1"` → removable = true
- For LVM/DM devices: default both to false (underlying device type not easily
accessible)
- Apply equivalent logic in both JNA and FFM implementations
**macOS** (`MacHWDiskStoreJNA.java` in oshi-core, `MacHWDiskStoreFFM.java` in
oshi-core-ffm):
- Add `SOLID_STATE("Solid State")` to the `CFKey` enum in `MacHWDiskStore.java`
- Add `REMOVABLE("Removable")` to the `CFKey` enum in `MacHWDiskStore.java`
- Query IOKit `IOMedia` or parent `IOBlockStorageDevice` for the `"Solid State"`
boolean property → solidState
- Query IOKit `IOMedia` for the `"Removable"` boolean property → removable
- Apply equivalent logic in both JNA and FFM implementations
===============================================================================
Task: 3
This phase updates the remaining Unix platform implementations (FreeBSD,
OpenBSD, Solaris, AIX) to support the new `solidState` and `removable` fields.
Most will default to `false`, with basic detection where it's feasible — every
platform contributing something is a wonderful step forward, and these can
always be improved in follow-up contributions!
**FreeBSD** (`FreeBsdHWDiskStore.java` in oshi-core):
- Update to call the 6-param super constructor
- Attempt to parse GEOM output from `geom disk list`:
- `"rotationrate: 0"` → solidState = true
- rotation rate > 0 → solidState = false
- Default removable to false (can be enhanced in future)
- Default both to false if not determinable
**OpenBSD** (`OpenBsdHWDiskStore.java` in oshi-core):
- Update to call the 6-param super constructor passing `false, false`
- No additional detection logic at this time (can be enhanced in future PRs)
**Solaris** (`SolarisHWDiskStore.java` in oshi-core):
- Update to call the 6-param super constructor passing `false, false`
- No additional detection logic at this time (`iostat -En` parsing can be added
in a future enhancement)
**AIX** (`AixHWDiskStore.java` in oshi-core):
- Update to call the 6-param super constructor passing `false, false`
- No additional detection logic at this time (`perfstat_disk_t` type field
mapping can be added in a future enhancement)
===============================================================================
Task: 4
This phase adds test coverage and updates the changelog — a wonderful way to
wrap things up and make sure everything is well-documented for future
contributors!
**Update `DisksTest.java`** in the oshi-core test directory:
- Add assertion: `assertThat(disk.isSolidState(), is(notNullValue()))` to verify
the method exists and is always populated (boolean is never null)
- Add assertion: `assertThat(disk.isRemovable(), is(notNullValue()))` for the
same reason
- Verify that the `toString()` output includes the solidState and removable
values
**Update `CHANGELOG.md`**:
- Add an entry under the appropriate version section
- Note the addition of the new `isSolidState()` and `isRemovable()` methods on
`HWDiskStore`
💡 Iterate on the plan with:
@coderabbitai <feedback>
Example Feedback
- @coderabbitai You can skip phase 3. Add a simple unit test case for phase 2.
- @coderabbitai For design choice 1 go ahead with option 3 and replan.
💬 Have feedback or questions? Drop into our discord!
@coderabbitai You generated a plan based on the original proposal. As an alternative to enum, I suggested two new API methods returning booleans that provide the essential information in #2857 (comment). Please update your coding plan to reflect that proposal.
Activity
dbwiddis commentedon Mar 29, 2025
This is generally available using the
OSFileStoreclass with eithergetName(),getDescription(), or you can sometimes infer things fromgetType(). Here's the output for Windows, for example (from the latest CI run):You'd have to correlate the filesystem to the hardware to match it up. See example here.
See also #146.
PavelTurk commentedon Mar 29, 2025
@dbwiddis When creating this issue, I was specifically trying to avoid any kind of parsing to determine the disk type. What I meant is an
enumwith predefined disk types, so that each user wouldn't have to reinvent the wheel, but simply select icons for the existing disk types.dbwiddis commentedon Mar 29, 2025
Fair enough, but operating systems don't provide this information in any standard format other than name or description. Here's what the OS provides on Windows, for example, which goes into "type":
oshi/oshi-core/src/main/java/oshi/software/os/windows/WindowsFileSystem.java
Lines 251 to 266 in 3bd8eaa
I could tell you it's a "removable drive" with that type "2", but not whether it's a floppy or thumb drive, without the name or description. And that's Windows-only, not cross-platform.
You might consider just using Java's
FileSystemViewclass.FileSystemView.getFileSystemView().isFloppyDrive()can tell you if you have a floppy drive, for example.isComputerNode()probably identifies a network drive, etc.I'm happy to consider adding something to the OSHI API if you can tell me where I can get the information cross-platform other than in the name or description.
PavelTurk commentedon Mar 29, 2025
@dbwiddis Thank you for your suggestion. I am already using
to check if a disk is a floppy. To check if it is a network drive, I use the output of (windows):
To check for an optical disk, I use the following code:
This is all I found I can do in Java to check if the disk is optical, floppy, or a network drive.
At the same time, I thought that by using native code, it would be possible to determine the type of any disk on all platforms. If that's not possible, it would be very sad.
dbwiddis commentedon Mar 29, 2025
It is possible using native code on Windows: see the snippet above using
Kernel32.INSTANCE.GetDriveType(). This is a native function mapped on JNA which, as a dependency, is available to you to use, if you know you're on Windows. Here are the return values.Other than Windows, however, this information is difficult to get. While we try to use native methods (such as udev) to collect information we're still limited to strings describing the disk, or device paths.
On macOS, we use a regex to match the volume name (
/dev/diskfor local disk,localhost:orsmb:for network, etc., for example). I don't know of any other way.On Linux, and Unix we do a similar match of
/devin the volume, parse the volume name, or match filesystem types. I don't know of any other way.Compared to the individual parsing on all the *nix systems, OSHI at least standardizes the types in the "Description" which has a more limited set of Strings you can try to match (and matches them to the Windows output as well). I honestly think that, or the
FileSystemViewmethods, are the best you can do cross-platform.If you think you can improve OSHI's parsing (such as using
/dev/fdfor floppies) feel free to submit a PR; I do not consider floppy disks a high priority. I think theFileSystemViewmethods are sufficient for the overwhelming majority of real world use cases.dbwiddis commentedon Apr 15, 2025
I'm going to close this issue as I think I've outlined the options. Other than the OSHI API which does its best to use standardized cross-platform strings (for easier parsing) you can directly use the native call on Windows using the already-included JNA dependency, or the FileSystemView methods in Java. Beyond that, parsing strings is really the only option.
dbwiddis commentedon May 3, 2026
Revisiting this idea. While a fully cross-platform disk type enum may not be feasible, we could expose what the OS does provide:
Linux:
/sys/block/<device>/queue/rotationalreliably distinguishes SSD (0) vs HDD (1). This is whatlsblk -d -o NAME,ROTAuses. Additionally,/sys/block/<device>/device/typeprovides SCSI device type codes, and the transport (/sys/block/<device>/device/transport) can identify NVMe, USB, etc.Windows:
IOCTL_STORAGE_QUERY_PROPERTYwithStorageDevicePropertyreturns aSTORAGE_DEVICE_DESCRIPTORcontainingBusType(NVMe, SATA, USB, etc.) andRemovableMedia. WMIMSFT_PhysicalDiskhas aMediaTypefield (0=Unspecified, 3=HDD, 4=SSD). Both are accessible via JNA/FFM.macOS:
IOKitprovidesIOMediaproperties includingWhole,Removable, and the device characteristics dictionary which can indicate solid-state vs. rotational.Proposal
Add to
HWDiskStore:These are simple booleans rather than an enum, avoiding the "what categories do we define" problem. They cover the most common use case (SSD vs HDD distinction for performance tuning and monitoring dashboards) and are implementable on Linux, Windows, and macOS.
Returning
falseas a default when the information is unavailable is consistent with OSHI's existing pattern for optional hardware details.coderabbitai commentedon May 3, 2026
Coding Plan
Summary
solidState,removable) as orthogonal, independently-determinable characteristics rather than forcing a single enum categorizationAbstractHWDiskStoreandHWPartition, maintaining backward compatibility via constructor overloading withfalsedefaultsMSFT_PhysicalDisk/IOCTL_STORAGE_QUERY_PROPERTYfor Windows, sysfsqueue/rotationalandremovablefor Linux, IOKitSolid StateandRemovableproperties for macOSfalsefor platforms or devices where properties cannot be determined, consistent with OSHI patternsDesign Choices
Design Choice 1: Boolean Properties vs Enum for Disk Type Classification
Options Considered:
Chosen Option: 2
Rationale: Two boolean fields provide independent answers to the most common questions: "Is this an SSD or HDD?" and "Is this removable?" This avoids forcing devices into artificial categories (e.g., a removable SSD would need to be one or the other with an enum). Using
falseas the default is consistent with OSHI patterns for unknown/unsupported values, and booleans are simpler to extend if additional properties are needed in the future.💡 User Tips
Regenerate the plan with different choices with
@coderabbitai <feedback>.Implementation Steps
Phase 1: API and Core Infrastructure
Extend the public API and base classes to support the two new boolean properties. This establishes the contract that all platform implementations will fulfill.
Task 1: Extend HWDiskStore Interface
Add the two new boolean methods to the public disk store interface.
boolean isSolidState();method toHWDiskStore.javain oshi-commonboolean isRemovable();method toHWDiskStore.javain oshi-commonisSolidState()returns true for solid-state storage (SSD, NVMe, flash), false for rotational (HDD) or if unknownisRemovable()returns true for removable media (USB drives, SD cards, optical), false otherwise or if unknownTask 2: Extend AbstractHWDiskStore Base Class
Add the two booleans as immutable fields in the base abstract class, following the established pattern.
private final boolean solidState;field toAbstractHWDiskStore.javaprivate final boolean removable;field toAbstractHWDiskStore.java(String name, String model, String serial, long size, boolean solidState, boolean removable)false, falseas defaults@Override public boolean isSolidState()getter@Override public boolean isRemovable()gettertoString()to include solidState and removable valuesTask 3: Update Intermediate Common Classes
Extend the constructor chains in the platform-specific common base classes to accept and pass through both boolean properties.
WindowsHWDiskStore.javain oshi-common: add 6-param constructor callingsuper(..., solidState, removable), keep 4-param delegating withfalse, falseLinuxHWDiskStore.javain oshi-common: same patternMacHWDiskStore.javain oshi-common: same pattern🤖 Prompt for AI agents
Phase 2: Major Platform Detection Implementation
Implement detection for the three major platforms (Windows, Linux, macOS) where reliable detection mechanisms exist.
Task 1: Windows Disk Type Detection
Implement solid-state and removable detection using WMI and storage device properties.
MSFT_PhysicalDiskWMI classMediaTypeproperty (value 4 = SSD, value 3 = HDD) via a new driver inoshi-common/src/main/java/oshi/driver/common/windows/wmi/IOCTL_STORAGE_QUERY_PROPERTYwithStorageDeviceSeekPenaltyProperty— no seek penalty indicates SSDWin32_DiskDriveMediaTypeproperty containing "Removable" or useSTORAGE_DEVICE_DESCRIPTOR.RemovableMediafieldWindowsHWDiskStoreJNA.javain oshi-core to query both properties and pass booleans to constructorWindowsHWDiskStoreFFM.javain oshi-core-ffm with equivalent logicTask 2: Linux Disk Type Detection
Implement solid-state and removable detection using sysfs and udev properties.
ROTATIONAL = "queue/rotational"toLinuxHWDiskStore.javafor sysfs attribute pathREMOVABLE = "removable"for sysfs attributeLinuxHWDiskStoreJNA.javain oshi-core:/sys/block/<device>/queue/rotationalviadevice.getSysattrValue("queue/rotational")— value"0"= solidState true,"1"= solidState false/sys/block/<device>/removableviadevice.getSysattrValue("removable")— value"1"= removable trueLinuxHWDiskStoreFFM.javain oshi-core-ffm with equivalent logicTask 3: macOS Disk Type Detection
Implement solid-state and removable detection using IOKit properties.
SOLID_STATE("Solid State")toCFKeyenum inMacHWDiskStore.javaREMOVABLE("Removable")toCFKeyenum inMacHWDiskStore.javaMacHWDiskStoreJNA.javain oshi-core:IOMediaor parentIOBlockStorageDevicefor"Solid State"boolean property → solidStateIOMediafor"Removable"boolean property → removableMacHWDiskStoreFFM.javain oshi-core-ffm with equivalent logic🤖 Prompt for AI agents
Phase 3: Unix Platform Implementations
Update the remaining Unix platform implementations to support the new fields, defaulting to false where detection is not straightforward.
Task 1: FreeBSD Disk Type Support
Update FreeBSD implementation with basic detection or false defaults.
FreeBsdHWDiskStore.javain oshi-core to call the 6-param super constructorgeom disk listoutput; if"rotationrate: 0"→ solidState true, if > 0 → solidState falseTask 2: OpenBSD Disk Type Support
Update OpenBSD implementation with false defaults.
OpenBsdHWDiskStore.javain oshi-core to call the 6-param super constructor withfalse, falseTask 3: Solaris Disk Type Support
Update Solaris implementation with false defaults.
SolarisHWDiskStore.javain oshi-core to call the 6-param super constructor withfalse, falseiostat -Enprovides reliable hintsTask 4: AIX Disk Type Support
Update AIX implementation with false defaults.
AixHWDiskStore.javain oshi-core to call the 6-param super constructor withfalse, falseperfstat_disk_ttype field could be mapped in future enhancement🤖 Prompt for AI agents
Phase 4: Testing and Documentation
Validate the new functionality and ensure documentation is updated.
Task 1: Update Disk Store Tests
Add test coverage for the new boolean properties.
DisksTest.javain oshi-core test directoryassertThat(disk.isSolidState(), is(notNullValue()))(boolean is never null, but validates method exists)assertThat(disk.isRemovable(), is(notNullValue()))toString()output includes solidState and removable valuesTask 2: Update Changelog
Document the new feature in the changelog.
CHANGELOG.mdunder the appropriate version sectionisSolidState()andisRemovable()methods onHWDiskStore🤖 Prompt for AI agents
Research
OSHI has a clean three-tier architecture for disk stores: the
HWDiskStoreinterface (oshi-common),AbstractHWDiskStoreabstract base class holding immutable identity fields (oshi-common), platform-specific intermediate common classes for Windows/Linux/macOS (oshi-common), and concrete JNA implementations (oshi-core) plus FFM implementations (oshi-core-ffm). Unix platforms (FreeBSD, OpenBSD, Solaris, AIX) extendAbstractHWDiskStoredirectly. The established pattern for adding immutable fields—demonstrated byHWPartition.label—involves adding a new constructor parameter while maintaining a backward-compatible overload that delegates with a default value.🚀 Next Steps
🤖 All AI agent prompts combined
💡 Iterate on the plan with:
@coderabbitai <feedback>💬 Have feedback or questions? Drop into our discord!
dbwiddis commentedon May 3, 2026
@coderabbitai You generated a plan based on the original proposal. As an alternative to enum, I suggested two new API methods returning booleans that provide the essential information in #2857 (comment). Please update your coding plan to reflect that proposal.
coderabbitai commentedon May 3, 2026
I've updated the plan above based on your feedback. Ready to proceed when you are!
Add disk type information (SSD, HDD, Removable, Virtual) (#3230)