Is there any way of detecting if a drive is a SSD?

前端 未结 9 2068
面向向阳花
面向向阳花 2020-11-30 03:02

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

9条回答
  •  星月不相逢
    2020-11-30 03:56

    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;
    }
    

提交回复
热议问题