I want to get disk type (SSD or HDD) in QT. I’ve checked QStorageInfo
but I could not find anything useful for my purpose. By the way I need a solution that’s work on both Windows and Linux.
Advertisement
Answer
For linux, you can tell whether the kernel has detected a SSD disk by reading special file
/sys/block/<disk>/queue/rotational
For instance, cat /sys/block/sda/queue/rotational
writes 1
if sda disk is HDD and 0
if it’s SSD.
For Windows, you can open a drive by opening special file \.PhysicalDrive<number>
, for instance \.PhysicalDrive0
. It can the be used with DeviceIOControl
to query properties, using IOCTL_STORAGE_QUERY_PROPERTY
IO control. It seems StorageDeviceSeekPenaltyProperty
may be what you’re after, as HDD have a seek penalty while SSD don’t. Alas I don’t have a windows environment around to test right now.
For portability, I highly doubt such system-dependent information is available in a portable way. You’ll have to use #ifdef
/#else
/#endif
macros to select an implementation depending on current target.