tags:

views:

501

answers:

4

I'm getting ready to release a tool that is only effective with regular hard drives, not SSD (solid state drive). In fact, it shouldn't be used with SSD's because it will result in a lot of read/writes with no real effectiveness.

Anyone knows of a way of detecting if a given drive is solid-state?

+1  A: 

SSD devices emulate a hard disk device interface, so they can just be used like hard disks. This also means that there is no general way to detect what they are.

You probably could use some characteristics of the drive (latency, speed, size), though this won't be accurate for all drives. Another possibility may be to look at the S.M.A.R.T. data and see whether you can determine the type of disk through this (by model name, certain values), however unless you keep a database of all drives out there, this is not gonna be 100% accurate either.

dseifert
I agree, I think the only way is figure out how manufacturers generate the serial key for their SSD devices as opposed to HDD ones. Then build a list of all manufacturers and their SSD string patterns. I used to have to look for some devices serial numbers to determine if they are right for my needs (iPods for US market, Linksys routers with Linux fw)
Mihaela
It's not right to say the serial key is the only possible way. Some drives do usefully report their RPM as 1 or 0 (http://linux.derkeiler.com/Mailing-Lists/Kernel/2009-04/msg02562.html)
Matthew Flaschen
Maybe you are right, but I'm not sure. "Some drives" --> there's the problem, it has to be all drives, no speculation.
Mihaela
+4  A: 

You can actually fairly easily determine the rotational latency -- I did this once as part of a university project. It is described in this report. You'll want to skip to page 7 where you see some nice graphs of the latency. It goes from about 9.3 ms to 1.1 ms -- a drop of 8.2 ms. That corresponds directly to 60 s / 8.2 ms = 7317 RPM.

It was done with simple C code -- here's the part that measures the between positions aand b in a scratch file. We did this with larger and larger b values until we have been wandered all the way around a cylinder:

/* Measure the difference in access time between a and b.  The result
 * is measured in nanoseconds. */
int measure_latency(off_t a, off_t b) {
  cycles_t ta, tb;

  overflow_disk_buffer();

  lseek(work_file, a, SEEK_SET);
  read(work_file, buf, KiB/2);

  ta = get_cycles();
  lseek(work_file, b, SEEK_SET);
  read(work_file, buf, KiB/2);
  tb = get_cycles();

  int diff = (tb - ta)/cycles_per_ns;
  fprintf(stderr, "%i KiB to %i KiB: %i nsec\n", a / KiB, b / KiB, diff);
  return diff;
}
Martin Geisler
Not C code! Jeff with never be able to handle that! PS: Get this mentioned on the pod cast and we get to drink!
geoffc
Hehe :-) I just saw the "delphi" tag... sorry about that :-) I trust you guy guys to convert it to Pascal, I haven't used Delphi in many years.
Martin Geisler
A: 

You could get lucky by running

smartctl -i sda

from Smartmontools. Almost all SSDs has SSD in the Model field. No guarantee though.

Jonas Elfström
+4  A: 

Detecting SSDs is not as impossible as dseifert makes out. There is already some progress in linux's libata (http://linux.derkeiler.com/Mailing-Lists/Kernel/2009-04/msg03625.html), though it doesn't seem user-ready yet.

And I definitely understand why this needs to be done. It's basically the difference between a linked list and an array. Defragmentation and such is usefully counter-productive on a SSD.

Matthew Flaschen