16

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?

5
  • 5
    There is no standard interface, so you'll have to do something OS specific across the board. It would be nice if there was a simple cross-platform way of determining it. For Linux, IIRC rotational will also be 0 for usb pen-drives. Commented May 5, 2014 at 12:03
  • @Petesh It would be hard to get it into the POSIX standard if there is no reliable way of detecting SSD storage devices, though. Commented May 8, 2014 at 7:36
  • 6
    Your application would likely benefit from a humble user-set option, maybe a nice table of all disks and whether they are to be used in "SSD mode", "spinner mode", or possibly "RAM disk mode", "unknown NAS device mode", "funny special filesystem mode", and so on. I wouldn't waste time on developing a detection feature which would probably need manual review and override in any case. Commented May 8, 2014 at 7:49
  • @LorenzoGatti Good idea, I will go for that unless someone comes up with a pretty foolproof way of detecting SSD storage devices. Commented May 8, 2014 at 8:00
  • 1
    Please list target OS you have in mind. en.wikipedia.org/wiki/POSIX is a family of standards and in itself doesn't even have a concept of disk. Commented May 9, 2014 at 9:40

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

I'll echo Lorenzo Gatti's comment above in saying that the best way to do this is almost certainly an option exposed to the user. There is no portable way of doing this, and I'd not be surprised if other OSs (particularly older ones, which are a problem unless you have some guarantee that your users are using a somewhat current OS) had no way of doing this.

Really, a checkbox along the lines of "I am using a solid-state drive", defaulting to off, would probably be the best option, especially since the ones likely to have an SSD are (for now, at least) tech-savvy enough to know what they have.

Comments