CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Ideas to tell HDD apart from SSD?

    Anyone has an idea how to tell apart a spinning HDD drive from a Flash-based SSD drive by a drive path?

    For those who's interested, I need this for my diagnostics tool.

    So far the most promising code sample I was able to find is this (it's in some Asian language, but the code is still readable.) And here's a C# rewrite of the same thing.

    It basically presents two methods: HasNoSeekPenalty and HasNominalMediaRotationRate. I tested it on my 3 SSD drives and on one internal HDD, and I wasn't able to get any consistency with their implementation. HasNoSeekPenalty failed with the error code ERROR_GEN_FAILURE on my main PCIe SSD and on the spinning HDD, and returned IncursSeekPenalty as 0 on the other two SSDs. HasNoSeekPenalty also failed on any plugged in USB flash sticks.

    As for HasNominalMediaRotationRate, I couldn't use it because my code cannot run elevated and that method requires elevation to open the drive.

    So in my opinion both methods fail, unless there's something that needs to be corrected in the code.

    I then found this half-baked example, which also didn't work for me. It seems that that method also requires elevation. I kept getting ERROR_ACCESS_DENIED, so I couldn't conclude anything.

    So I'm curious if anyone else can contribute to my search?

    PS. From what I understand if there was a way to determine the spin rate of the drive it would be enough to tell a spinning drive from a solid state drive.

  2. #2
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: Ideas to tell HDD apart from SSD?

    I think getting a 100% working method will be either impossible, or would require such lengthy diagnostics that anyone using the program would ragequit.

    * Some drives are actually hybrid drivers with a few GB flash paired with a mechanical setup.
    * Some SSDs have firmware bugs that give latency that may resemble that of a mechanical drive.

    Your best bet: Try to open the entire drive in "raw" mode and read very small blocks from random positions on the drive.
    This will be fast with most SSDs, but incredibly slow on any mechanical drive.
    If the drive is small and the entire drive is cached by the OS, the method may still fail.
    You may need to look for a way to invalidate the cache, maybe force dismount the drive and re-mount it?
    Nobody cares how it works as long as it works

  3. #3
    Join Date
    Apr 2000
    Location
    Belgium (Europe)
    Posts
    4,626

    Re: Ideas to tell HDD apart from SSD?

    Any kind of timing heuristic is destined for failure on at least some of the harddisk or sdd's.

    Harddisks are becoming faster, and are getting more elaborate firmware and caching that can on some tests make it appear faster than any SDD ever could.
    Direct head movement requests without actual reading/writing will often do nothing.

    SDD's may not work the way you expect, an SDD may still be processing a write request and cause a subsequent read to be stalled. It may be in a refresh/optimize cycle and cause reads and writes to be stalled.
    Firmware tends to be written well enough to minimize the effects, but it'll still happen.

    then there's technologies like out of order processing of disk requests...

    And maybe you haven't yet heard of the hybrid disks which are part SDD and part HDD, storing the frequently read/updated bits and small file data in SDD and actual /large data on the HDD

    And do I need to mention RAID that may totally hide any kind of test result.


    The thing to remember is that SDD's were designed to be 'indistinguishable' from a HDD at the hardware level. They're just devices hooked onto the SATA, Firewire, USB or whatever type interface.


    your best bet is to either have a database of SDD/HDD type ID numbers
    or to somehow try to derive whether it's HDD or SDD from the description.
    but typically speaking, you should'nt have to care whether it's a HDD, an SDD... or future's Crystal latice reader or a superoptronicquantumspecialultrafastthingamajig.

  4. #4
    Join Date
    Jun 2002
    Location
    Stockholm, Sweden
    Posts
    1,641

    Re: Ideas to tell HDD apart from SSD?

    One more typical characteristic of SSD is that erasing the disk (by overwriting it with zeroes) will be hundreds of times faster than if you would write random data.
    The reason, IIRC, is that the SSD memory cells have a special "clear" command that can erase an entire chunk very quickly.
    This is also why you can "full format" your 1TB disk in a matter of seconds.

    But again, you cannot rely on it because some early models may not have that feature.

    Any kind of timing heuristic is destined for failure on at least some of the harddisk or sdd's.
    Indeed, and not only for SSD. Relying on timers is recipe for disaster for many aspects of programming.
    Nobody cares how it works as long as it works

  5. #5
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    894

    Re: Ideas to tell HDD apart from SSD?

    Yes, I agree timing an I/O operation will not do the trick. That is why I went with the distinctive hardware feature of spinning drives.

    As for OReubens concerns, definitely RAID and hybrid SSDs need to be in a separate category. But from what I see there's no clear way of defining it in Windows.

    And again, this is needed purely for a diagnostic/informational purpose. (And for my knowledge of the subject.)

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Ideas to tell HDD apart from SSD?

    Quote Originally Posted by dc_2000 View Post
    Anyone has an idea how to tell apart a spinning HDD drive from a Flash-based SSD drive by a drive path?

    For those who's interested, I need this for my diagnostics tool.

    So far the most promising code sample I was able to find is this (it's in some Asian language, but the code is still readable.)
    You could also have a look at this thread. There are links to English sites.
    Did you consider to use SetupDiGetDeviceRegistryProperty/
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured