Help Please!!!!! I am lost in the structures........
I am trying to get the Power On Hours of a Hard Disk into nVal as shown below. The Attributes are returned sucessfully, but I am lost tring to get the Power On Hours into nVal. Power On Hours is the ninth attribute, I think. You can check out the following URL to see SMART. See code below. What am I doing wrong? If I get this working I can also get the temperature.
SNMP_ERRSTAT DCdsContentServerTemperatures::OnGet_CdsContentServerHDTemp(tUint32 transactionId, tASN_INT& nVal)
{
HANDLE hSMARTIOCTL = 0;
DWORD cbBytesReturned;
GETVERSIONOUTPARAMS VersionParams;
SENDCMDINPARAMS scip;
SENDCMDOUTPARAMS OutCmd;
BYTE bDfpDriveMap = 0;
BYTE bSuccess = 1;
BYTE bIDCmd = 236; // IDE IDENTIFY cmd
int i =1;
PDRIVEATTRIBUTE pDA;
// Try to get a handle to SMART IOCTL, report failure and exit if
// can't.
if ((hSMARTIOCTL = CreateFile("\\\\.\\PhysicalDrive0",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,
OPEN_EXISTING,0,NULL)) == INVALID_HANDLE_VALUE)
{
nVal = 0; //No Success -- Invalid Handle
}
if (hSMARTIOCTL != INVALID_HANDLE_VALUE) //Success -- Valid Handle
{
// Success -- Setup for Read Attributes Command
memset(AttrOutCmd, 0, sizeof(AttrOutCmd));
if ( !(bSuccess = DoReadAttributesCmd(hSMARTIOCTL,
&scip,
(PSENDCMDOUTPARAMS)&AttrOutCmd,
1))) // Drive Number (Physical Drive 0 is Drive 1)
{
nVal = 0; //Can't Read Attributes
}
else
{ // Read Successful -- Get HD Temperature -- This is where I need help!!
nVal = *((PSENDCMDOUTPARAMS)AttrOutCmd[10])->bBuffer;
} // End if Do Read Attributes
// Close SMART.
if (hSMARTIOCTL)
CloseHandle(hSMARTIOCTL);
} // End if Success -- Valid Handle
return eSNMP_ERRSTAT_NO_ERROR;
}
/****************************************************************************
*
* DoReadAttributesCmd
*
* FUNCTION: Send a SMART_READ_ATTRIBUTE_VALUES command to the drive
* bDriveNum = 0-3
*
****************************************************************************/
BOOL DoReadAttributesCmd(HANDLE hSMARTIOCTL, PSENDCMDINPARAMS pSCIP, PSENDCMDOUTPARAMS pSCOP, BYTE bDriveNum)
{
DWORD cbBytesReturned;
//
// Set up data structures for Read Attributes SMART Command.
//
pSCIP->cBufferSize = READ_ATTRIBUTE_BUFFER_SIZE;
pSCIP->irDriveRegs.bFeaturesReg = SMART_READ_ATTRIBUTE_VALUES;
pSCIP->irDriveRegs.bSectorCountReg = 1;
pSCIP->irDriveRegs.bSectorNumberReg = 1;
pSCIP->irDriveRegs.bCylLowReg = SMART_CYL_LOW;
pSCIP->irDriveRegs.bCylHighReg = SMART_CYL_HI;
//
// Compute the drive number.
//
//pSCIP->irDriveRegs.bDriveHeadReg = 0xA0 | ((bDriveNum & 1) << 4);
pSCIP->irDriveRegs.bCommandReg = IDE_EXECUTE_SMART_FUNCTION;
pSCIP->bDriveNumber = 1;
return ( DeviceIoControl(hSMARTIOCTL, DFP_RECEIVE_DRIVE_DATA,
(LPVOID)pSCIP, sizeof(SENDCMDINPARAMS) - 1,
(LPVOID)pSCOP, sizeof(SENDCMDOUTPARAMS) + READ_ATTRIBUTE_BUFFER_SIZE - 1,
&cbBytesReturned, NULL) );
}
I am trying to get the Power On Hours of a Hard Disk into nVal as shown below. The Attributes are returned sucessfully, but I am lost tring to get the Power On Hours into nVal. Power On Hours is the ninth attribute, I think. You can check out the following URL to see SMART. See code below. What am I doing wrong? If I get this working I can also get the temperature.
SNMP_ERRSTAT DCdsContentServerTemperatures::OnGet_CdsContentServerHDTemp(tUint32 transactionId, tASN_INT& nVal)
{
HANDLE hSMARTIOCTL = 0;
DWORD cbBytesReturned;
GETVERSIONOUTPARAMS VersionParams;
SENDCMDINPARAMS scip;
SENDCMDOUTPARAMS OutCmd;
BYTE bDfpDriveMap = 0;
BYTE bSuccess = 1;
BYTE bIDCmd = 236; // IDE IDENTIFY cmd
int i =1;
PDRIVEATTRIBUTE pDA;
// Try to get a handle to SMART IOCTL, report failure and exit if
// can't.
if ((hSMARTIOCTL = CreateFile("\\\\.\\PhysicalDrive0",GENERIC_READ | GENERIC_WRITE,FILE_SHARE_READ|FILE_SHARE_WRITE,NULL,
OPEN_EXISTING,0,NULL)) == INVALID_HANDLE_VALUE)
{
nVal = 0; //No Success -- Invalid Handle
}
if (hSMARTIOCTL != INVALID_HANDLE_VALUE) //Success -- Valid Handle
{
// Success -- Setup for Read Attributes Command
memset(AttrOutCmd, 0, sizeof(AttrOutCmd));
if ( !(bSuccess = DoReadAttributesCmd(hSMARTIOCTL,
&scip,
(PSENDCMDOUTPARAMS)&AttrOutCmd,
1))) // Drive Number (Physical Drive 0 is Drive 1)
{
nVal = 0; //Can't Read Attributes
}
else
{ // Read Successful -- Get HD Temperature -- This is where I need help!!
nVal = *((PSENDCMDOUTPARAMS)AttrOutCmd[10])->bBuffer;
} // End if Do Read Attributes
// Close SMART.
if (hSMARTIOCTL)
CloseHandle(hSMARTIOCTL);
} // End if Success -- Valid Handle
return eSNMP_ERRSTAT_NO_ERROR;
}
/****************************************************************************
*
* DoReadAttributesCmd
*
* FUNCTION: Send a SMART_READ_ATTRIBUTE_VALUES command to the drive
* bDriveNum = 0-3
*
****************************************************************************/
BOOL DoReadAttributesCmd(HANDLE hSMARTIOCTL, PSENDCMDINPARAMS pSCIP, PSENDCMDOUTPARAMS pSCOP, BYTE bDriveNum)
{
DWORD cbBytesReturned;
//
// Set up data structures for Read Attributes SMART Command.
//
pSCIP->cBufferSize = READ_ATTRIBUTE_BUFFER_SIZE;
pSCIP->irDriveRegs.bFeaturesReg = SMART_READ_ATTRIBUTE_VALUES;
pSCIP->irDriveRegs.bSectorCountReg = 1;
pSCIP->irDriveRegs.bSectorNumberReg = 1;
pSCIP->irDriveRegs.bCylLowReg = SMART_CYL_LOW;
pSCIP->irDriveRegs.bCylHighReg = SMART_CYL_HI;
//
// Compute the drive number.
//
//pSCIP->irDriveRegs.bDriveHeadReg = 0xA0 | ((bDriveNum & 1) << 4);
pSCIP->irDriveRegs.bCommandReg = IDE_EXECUTE_SMART_FUNCTION;
pSCIP->bDriveNumber = 1;
return ( DeviceIoControl(hSMARTIOCTL, DFP_RECEIVE_DRIVE_DATA,
(LPVOID)pSCIP, sizeof(SENDCMDINPARAMS) - 1,
(LPVOID)pSCOP, sizeof(SENDCMDOUTPARAMS) + READ_ATTRIBUTE_BUFFER_SIZE - 1,
&cbBytesReturned, NULL) );
}