Click here to Skip to main content
16,012,843 members
Articles / Programming Languages / C++
Article

Hard drive information using S.M.A.R.T.

Rate me:
Please Sign up or sign in to vote.
4.33/5 (31 votes)
25 May 2007 349K   18.2K   70   100
Retrieving Hard drive information using S.M.A.R.T.

Sample Image - SMARTIMAGE.jpg

Introduction

This is very simple program which communicates with the Hard drive to get the information using S.M.A.R.T. available within the hard drive.

The core part is to prepare the command structure and pass it to the device driver which communicates with the hard drive. It uses the DeviceIoControl function. For eg: bRet=DeviceIoControl(hDevice,SMART_SEND_DRIVE_COMMAND,&stCIP,sizeof(stCIP),&stCOP,sizeof(stCOP),&dwRet,NULL);

Don't forget to include the "DDKInclude" folder in the workspace to your VC's include folder before compiling. This sample is only intended for beginners. Most of the information for S.M.A.R.T. is available in the net.

Also the information for each id is stored in an .ini file. You can see that in the Debug / Release folder.

Double click on any of the item in the list box to get more information about it. For e.g., xx sector count

Please contact me for any doubts and i will be happy to answer to your questions

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
I am from the beautiful sea side town called Kochi ( cochin), Kerala, South India.

Comments and Discussions

 
GeneralZip is Corrupt Pin
girish_ksharma22-May-07 21:09
girish_ksharma22-May-07 21:09 
QuestionRe: Zip is Corrupt Pin
Saneesh23-May-07 4:33
Saneesh23-May-07 4:33 
GeneralThreshold values always are zero Pin
GipsySh26-Apr-07 22:09
GipsySh26-Apr-07 22:09 
GeneralRe: Threshold values always are zero Pin
Saneesh27-Apr-07 4:30
Saneesh27-Apr-07 4:30 
GeneralRe: Threshold values always are zero Pin
GipsySh27-Apr-07 11:56
GipsySh27-Apr-07 11:56 
GeneralRe: Threshold values always are zero Pin
Saneesh28-Apr-07 19:25
Saneesh28-Apr-07 19:25 
GeneralRe: Threshold values always are zero Pin
GipsySh21-May-07 4:11
GipsySh21-May-07 4:11 
GeneralRe: Threshold values always are zero Pin
Nathan Lewis15-Jun-07 7:44
Nathan Lewis15-Jun-07 7:44 
Looking at Section 2.6 of the SFF 8035i Revision 2 SMART Specification, titled "SMART Read Attribute Thresholds", the buffer beginning at OutParams.stCOP.bBuffer contains a 512 byte structure. This structure contains, among other things, a collection of smaller structures which include the threshold data. These structures are easily coded as something like this:
<br />
   // Maximum allowed number of SMART Attributes / Thresholds<br />
   //<br />
   #define SMART_MAX_ATTRIBUTES     30<br />
   #define SMART_MAX_THRESHOLDS     30<br />
<br />
#pragma pack( push, 1 )// Structures must be aligned on a single-byte boundary!<br />
   typedef struct<br />
   {<br />
      BYTE ucId;<br />
      BYTE ucValue;<br />
      BYTE ucReserved[10];<br />
<br />
   } SMART_THRESHOLD_INFO, *LPSMART_THRESHOLD_INFO;<br />
<br />
   typedef struct<br />
   {<br />
      WORD wRevision;<br />
      SMART_THRESHOLD_INFO arThresholds[ SMART_MAX_THRESHOLDS ];<br />
      BYTE ucReserved[18];<br />
      BYTE ucVendorSpecific[131];<br />
      BYTE ucChecksum;<br />
<br />
   } SMART_THRESHOLDS, *LPSMART_THRESHOLDS;<br />
#pragma pack( pop )<br />

With these structures in hand, we can modify the "Read Thresholds" code to be a bit easier to follow...
<br />
   // Get a pointer to the return buffer...<br />
   LPSMART_THRESHOLDS pThresholds = (LPSMART_THRESHOLDS)OutParams.stCOP.bBuffer;<br />
<br />
   // Cycle through all the SMART_THRESHOLD_INFO structures inside<br />
   // the larger SMART_THRESHOLDS structure...<br />
   //<br />
   for( ucT1 = 0; ucT1 < SMART_MAX_THRESHOLDS; ucT1++ )<br />
   {<br />
      // Get a reference to the current SMART_THRESHOLD_INFO structure<br />
      SMART_THRESHOLD_INFO& info = pThresholds->arThresholds[ ucT1 ];<br />
<br />
      // Skip empty values<br />
      if( info.ucId != 0 )<br />
      {<br />
         // Look up the value associated with this threshold data based<br />
         // on the ucId field, and update the threshold info if found...<br />
         //<br />
         pSmartValues = GetSMARTValue( ucDriveIndex, info.ucId );<br />
<br />
         if( pSmartValues )<br />
            pSmartValues->m_dwThreshold = info.ucValue;<br />
      }<br />
   }<br />

This same approach could, of course, be applied to the code which reads the attributes in as well. I'll leave that as an exercise for the reader... Wink | ;)


Hope this helps!

- NL


*Real* programmers use "copy con:progname.exe"!

QuestionHow about 2 HDD's using RAID? Pin
Ingenious00127-Mar-07 5:30
Ingenious00127-Mar-07 5:30 
AnswerRe: How about 2 HDD's using RAID? Pin
Saneesh27-Mar-07 12:26
Saneesh27-Mar-07 12:26 
GeneralRe: How about 2 HDD's using RAID? Pin
Ingenious0012-Apr-07 9:35
Ingenious0012-Apr-07 9:35 
QuestionAnyone have success detecting on Vista Pin
DCB_526-Jan-07 9:22
DCB_526-Jan-07 9:22 
AnswerRe: Anyone have success detecting on Vista Pin
Saneesh26-Feb-07 9:47
Saneesh26-Feb-07 9:47 
Generalcannot open include file: 'devioctl.h' Pin
hdpc19-Dec-06 12:10
hdpc19-Dec-06 12:10 
GeneralRe: cannot open include file: 'devioctl.h' Pin
Saneesh20-Dec-06 10:45
Saneesh20-Dec-06 10:45 
GeneralRe: cannot open include file: 'devioctl.h' Pin
hdpc22-Dec-06 6:22
hdpc22-Dec-06 6:22 
Generalratings Pin
renato tome10-Dec-06 16:04
renato tome10-Dec-06 16:04 
GeneralRe: ratings Pin
Saneesh14-Dec-06 10:36
Saneesh14-Dec-06 10:36 
GeneralStrange temperature values Pin
krepak7-Dec-06 0:06
krepak7-Dec-06 0:06 
AnswerRe: Strange temperature values Pin
Saneesh7-Dec-06 4:50
Saneesh7-Dec-06 4:50 
GeneralRe: Strange temperature values Pin
krepak7-Dec-06 11:14
krepak7-Dec-06 11:14 
GeneralRe: Strange temperature values Pin
Saneesh22-Jun-07 5:18
Saneesh22-Jun-07 5:18 
General5 votes for this article. Popularity: -33.9. Rating: -48.5 out of 5 Pin
Kochise6-Dec-06 21:30
Kochise6-Dec-06 21:30 
GeneralRe: 5 votes for this article. Popularity: -33.9. Rating: -48.5 out of 5 Pin
sps-itsec467-Dec-06 3:59
sps-itsec467-Dec-06 3:59 
GeneralRe: 5 votes for this article. Popularity: -33.9. Rating: -48.5 out of 5 Pin
Saneesh7-Dec-06 4:47
Saneesh7-Dec-06 4:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.