Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine storage type (SSD drive or HHD .mechanical drive), using C language

How can I, from a C program, read the hardware information of a drive? (I.e. to determine if the drive is an SSD or a mechanical disk.)

like image 759
Shaobo Wang Avatar asked Dec 07 '22 05:12

Shaobo Wang


1 Answers

SSD are supposed to identify themselves as non-rotative. For linux, as example, you can get the info via sysfs:

cat /sys/block/sda/queue/rotational

If it returns 0, you have SSD...

like image 192
pan1nx Avatar answered Dec 09 '22 18:12

pan1nx