Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Rotation Speed of Disk Sample Code

Im not really good at VC++ but does anyone have a sample code to get the rotation speed of disk in a computer. I have been working on detecting SSD drives and one solution from researching all day was to get the rotation speed and since SSD have 0 rpm this might be the only way to detect SSD drive.

like image 900
patlimosnero Avatar asked Apr 28 '11 06:04

patlimosnero


2 Answers

You are likely better off looking for the TRIM command.

BOOL IsDriveSSD(){

    DWORD dwBytesReturned;

    HANDLE volhand = INVALID_HANDLE_VALUE;
    try{
        volhand = CreateFile("\\\\.\\PHYSICALDRIVE0", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL);
    }
    catch(...){
        volhand = INVALID_HANDLE_VALUE;
    }

    if (volhand == INVALID_HANDLE_VALUE) return FALSE;


    // Test 1: See if we have a TRIM command, if so, we're SSD.
    STORAGE_PROPERTY_QUERY spq;
    DEVICE_TRIM_DESCRIPTOR dtr;
    memset(&dtr,0,sizeof(DEVICE_TRIM_DESCRIPTOR));
    memset(&spq,0,sizeof(STORAGE_PROPERTY_QUERY));
    spq.PropertyId=StorageDeviceTrimProperty;
    spq.QueryType=PropertyStandardQuery;

    BOOL ret = DeviceIoControl(volhand, IOCTL_STORAGE_QUERY_PROPERTY,
        &spq,sizeof(spq),
        &dtr,sizeof(dtr),
        &dwBytesReturned,FALSE);

    if(ret){
        ret = dtr.TrimEnabled;
    }

    CloseHandle(volhand);

    return ret;
}
like image 20
Woody14619 Avatar answered Oct 01 '22 19:10

Woody14619


From google wmi ssd detect

There is an NV cache manager interface used for ReadyDrive which is new to Vista. I think it is testing NV_FEATURE_PARAMETER's NVReadSpeed and NVWrtSpeed values.

Windows 7 detects SSDs by using ATA8-ACS identify word 217: Nominal media rotation rate, with value 0001h as Non-rotating media like solid state devices. But not all SSDs adhere to the ATA8-ACS1 spec section 7.16.7.77, some may need firmware updates.

If you want to lean more about sending ATA commands in Windows, I suggest you to dig aound the Storage Platform ATA forum. This forum is being archived so act quickly.


Also very enlightening:

http://blogs.msdn.com/b/e7/archive/2009/05/05/support-and-q-a-for-solid-state-drives-and.aspx

Will disk defragmentation be disabled by default on SSDs?

Yes. The automatic scheduling of defragmentation will exclude partitions on devices that declare themselves as SSDs. Additionally, if the system disk has random read performance characteristics above the threshold of 8 MB/sec, then it too will be excluded. The threshold was determined by internal analysis.

like image 126
sehe Avatar answered Oct 01 '22 21:10

sehe