Disk Drive Dangers - SMART and WMI
Written by Mike James   
Wednesday, 08 August 2012
Article Index
Disk Drive Dangers - SMART and WMI
A practical project
Get Smart
Decoding WMI data

Get Smart

Now that we have the basics of WMI in .NET worked out it's time to get back to SMART. Some information presented by WMI is provided by SMART and this is fairly easy to get at.

For example, if you simply want to discover what SMART thinks of each drive you can make use of the WMI Win32_DiskDrive object and its Status property. This gives an overall disk status based on SMART and other considerations. The possible values are:

  • OK
  • Error
  • Degraded
  • Unknown
  • PredFail
  • Starting
  • Stopping
  • Service
  • Stressed
  • NonRecover
  • No Contact
  • Lost Comm

Pred Fail, i.e. Predicted Failure result, is the one that we are most interested in using as a way of avoiding trouble before it happens.

Start a new project, or use the previous project and place a button labelled “Get Drive Status” on the form along with a RichTextBox.

To read the Status property and present it enter the following into the button’s click event handler :

private void button1_Click(object sender,
EventArgs e)
{
ManagementObjectSearcher WMISearch =
new ManagementObjectSearcher(
"Select * from Win32_DiskDrive");
ManagementObjectCollection Drives =
WMISearch.Get();
richTextBox1.Text =
"Drive\t\t\tStatus\n";
foreach ( ManagementObject Drive
in Drives )
{
richTextBox1.Text = richTextBox1.Text +
Drive.Properties["DeviceId"].
Value.ToString()+"\t";
richTextBox1.Text = richTextBox1.Text +
Drive.Properties["Status"].
Value.ToString()+"\n";
}
}

The “\t”s are tab formatting characters and the “\n” is a newline.

status

 

If you want to go beyond this simple go/no-go test then there are a number of problems.

There are (at least) four WMI objects that provide access to SMART but lack of documentation makes them difficult to use. The only information available can be found in an archived paper on the Micorosft site which describes four objects:

MSStorageDriver_FailurePredictStatus
MSStorageDriver_FailurePredictData
MSStorageDriver_FailurePredictEvent
MSStorageDriver_FailurePredictFunction

The first provides information on the state of the drive similar to the state property already described. The second provides the SMART data that this decision was based on but the format used varies according to the make of the drive and no information is given how to decipher it. The third implements events based on the SMART status and the fourth provides methods that can be used to configure a SMART drive and initiate a test.

There is also another object:

MSStorageDriver_ATAPISmartData

but there seems to be even less documentation for this and it is only available in Vista and later. It seems to return the same information as

MSStorageDriver_FailurePredictData

To get at the SMART data we need to use MSStorageDriver_FailurePredictData. This is stored in \root\wmi rather than the default \root\cimv2 and means we need to set the scope:

WMISearch.Scope=new 
ManagementScope(@"\root\wmi" );

You can also specify a machine and user if you want to collect data on a remote machine. The WQL query is:

WMISearch.Query=new ObjectQuery(
"Select * from
MSStorageDriver_FailurePredictData");
ManagementObjectCollection
FailDataSet = WMISearch.Get();

The FailDataSet contains a block of SMART data for each drive in the system that supports it. Each of the FailData objects in the collection has a VendorSpecific property which returns a byte array full of SMART data.

The big problem is in figuring out what it all means as it really is “vendor specific”. The data is organized into 12 byte blocks of attribute data. The first byte of the array gives the number of attribute blocks. Each attribute block has the format:

Item    Data
0 and 1 Unknown usually zero
2 Attribute
3 Status
4 Unknown usually zero
5 Value
6 Worst
7,8 Raw Value
9,10,11 Unknown usually zero

The attribute codes are also not standardized but there are a core set that you can rely on:

Code  Attribute
1       Raw Read Error Rate
2 Throughput Performance
3 Spin Up Time
4 Start/Stop Count
5 Reallocated Sector Count
6 Read Channel Margin
7 Seek Error Rate
8 Seek Time Performance
9 Power On Hours Count
10 Spin Retry Count
11 Calibration Retry Count
12 Power Cycle Count
192 Power-off Retract Count
193 Load Cycle Count
194 Temperature
196 Reallocation Event Count
197 Current Pending Sector Count
198 Off-line Scan Uncorrectable Sector Count
199 Ultra DMA CRC Error Count
201 Soft Read Error Rate
220 Disk Shift

Not all drives support all attributes and you can be certain that some will report attributes not in this list. A more complete list can be found on Wikipedia: SMART. Notice also that code 194 gives the temperature of the drive.

<ASIN:1555582664>



Last Updated ( Wednesday, 08 August 2012 )