Search code examples
c++hard-drivesolid-state-drive

Detecting SSD storage devices on POSIX OS'es


I'm working on a OS portable program that would benefit from detecting if a physical storage device is a SSD or a plain old spin-disk.

On Linux there is:

/sys/block/sdX/queue/rotational

which return 0 or 1 if SSD, but I'm not sure if this is the best way.

On Windows and UNIX I have not found any way of detecting it, perhaps I should use ioctl DEVICE_SEEK_PENALTY_DESCRIPTOR and check the seek penelty (which should be very low on a SSD storage device), or perhaps use DeviceIoControl to check the nominal media rotation rate (which also should be very low on a SSD storage device).

Any recommendations for me on how to proceed with detecting SSD disks on POSIX compatible OS'es?


Solution

  • Related: https://unix.stackexchange.com/questions/65595/how-to-know-if-a-disk-is-an-ssd-or-an-hdd

    IMO though. You could use the POSIX method of determining the OS, and have various methods to detect SSD, and when it can't be determined, simply ask the end-user, and if they don't know, have a safe default. I guess that is what I would do if there wasn't a POSIX compliant method (but I would probably check the POSIX mailing list first though too). I hope this helps.