.版本 2
GetHdSmart ()
返回 (0)
.子程序 GetHdSmart, 逻辑型
.局部变量 hSMARTIOCTL, 整数型
.局部变量 cbBytesReturned, 整数型
.局部变量 VersionParams, GETVERSIONOUTPARAMS
.局部变量 scip, SENDCMDINPARAMS
.局部变量 OutCmd, 整数型
.局部变量 bDfpDriveMap, 字节型
.局部变量 i, 整数型
.局部变量 bIDCmd, 字节型, , , // IDE or ATAPI IDENTIFY cmd
.局部变量 IDSECTOR_tmp, _IDINFO
.局部变量 IdOutCmd_temp, SENDCMDOUTPARAMS
.局部变量 AttrOutCmd_temp, SENDCMDOUTPARAMS
.局部变量 ThreshOutCmd_temp, SENDCMDOUTPARAMS
.局部变量 OutCmd_temp, SENDCMDOUTPARAMS
.局部变量 hInput, 整数型
.局部变量 lpBuff, 字节型, , "20"
.局部变量 lpNumberOfEventsRead, 整数型
.局部变量 ret, 逻辑型
.局部变量 LastMsg, 整数型
GetLastError ()
' pAttrNames = { “No Attribute Here ”, “Raw Read Error Rate ”, “Throughput Performance ”, “Spin Up Time ”, “Start/Stop Count ”, “Reallocated Sector Count”, “Read Channel Margin ”, “Seek Error Rate ”, “Seek Time Performance ”, “Power On Hours Count ”, “Spin Retry Count ”, “Calibration Retry Count ”, “Power Cycle Count ”, “(Unknown attribute) ” }
pAttrNames = { “0___这里没有属性 ”, “1___底层数据读取出错率 ”, “2___硬盘读写数据的吞吐量性能 ”, “3___马达旋转到规定转速所需时间 ”, “4___主轴马达启动/停止次数 ”, “5___重新映射磁盘扇区的数量 ”, “6___读取通道边缘的数据 ”, “7___磁头寻道出错率 ”, “8___磁头寻道时间的平均性能 ”, “9___硬盘加电累计时间 ”, “10__马达重新旋转到规定转速次数 ”, “11__磁盘校准重试次数 ”, “12__硬盘完全启动/停止的次数 ”, “13__程序读取出错率 ”, “184_End to End Error ”, “187_报告的无法校正的错误 ”, “188_命令超时 ”, “189_快速写入 ”, “190_气流温度 ”, “191_震动传感器检测的出错率 ”, “192_硬盘断电回位次数 ”, “193_磁头载入次数 ”, “194_硬盘温度 ”, “195_硬件出错纠正恢复次数 ”, “196_重新映射扇区数据转移的次数 ”, “197_当前不良扇区待映射的数量 ”, “198_脱机无法纠正扇区数量 ”, “199_Ultra DMA 奇偶校验出错次数 ”, “200_磁盘扇区写入出错率 ”, “201_检测磨擦热计数器 ”, “202_增加磨擦热计数器 ”, “203_纠正出错率 ”, “204_程序出错纠正恢复校准 ”, “205_磁盘酷热性能率 ”, “206_磁头定位高度 ”, “207_马达电流过高使磁盘快速旋转 ”, “208_磁盘旋转蜂音 ”, “209_脱机操作的磁盘寻道性能 ”, “211_震动期间写入 ”, “212_冲击期间写入 ”, “220_强烈震动导致磁盘偏移 ”, “221_震动传感器检测的出错率 ”, “222_常规操作所引起磁头载入次数 ”, “223_磁头载入/载出重试次数 ”, “224_摩擦所引起的磁头载入 ”, “225_磁头载入/载出次数 ”, “226_磁头载入时间 ”, “227_磁盘运行旋转瞬间的次数 ”, “228_电源断电磁头紧急缩回次数 ”, “230_正在运行中的 GMR 磁头发抖 ”, “231_硬盘温度 ”, “240_磁头定位时间 ”, “250_读取出错重试率 ”, “254_自由下落保护 ”, “ (未知属性) ” }
hSMARTIOCTL = OpenSMART ()
.如果真 (hSMARTIOCTL ≠ #INVALID_HANDLE_VALUE)
AttrOutCmd = LocalAlloc (64, 17 + 512 - 1)
IdOutCmd = LocalAlloc (64, 17 + 512 - 1)
ThreshOutCmd = LocalAlloc (64, 17 + 512 - 1)
OutCmd = LocalAlloc (64, 17)
' // Get the version, etc of SMART IOCTL
.如果 (DeviceIoControl_GETVERSIONOUTPARAMS (hSMARTIOCTL, #DFP_GET_VERSION, 0, 0, VersionParams, 24, cbBytesReturned, 0) ≠ 0)
标准输出 (, “DFP_GET_VERSION returned:”, #换行符)
标准输出 (, 格式化文本_ (_S (“%8sVersion = %d”), _S (#SPACE_STRING), VersionParams.bVersion), #换行符)
标准输出 (, 格式化文本_ (_S (“%8sRevision = %d”), _S (#SPACE_STRING), VersionParams.bRevision), #换行符)
标准输出 (, 格式化文本_ (_S (“%8sCapabilities = 0x%lx”), _S (#SPACE_STRING), VersionParams.fCapabilities), #换行符)
标准输出 (, 格式化文本_ (_S (“%8sReserved = 0x%x”), _S (#SPACE_STRING), VersionParams.bReserved), #换行符)
标准输出 (, 格式化文本_ (_S (“%8sIDEDeviceMap = 0x%x”), _S (#SPACE_STRING), VersionParams.bIDEDeviceMap), #换行符)
标准输出 (, 格式化文本_ (_S (“%8sBytesReturned = %d”), _S (#SPACE_STRING), cbBytesReturned), #换行符, #换行符)
.否则
标准输出 (, 格式化文本_ (_S (“DFP_GET_VERSION failed. error code : %d ”), GetLastError ()), #换行符)
.如果结束
.变量循环首 (0, #MAX_IDE_DRIVES, 1, i)
' // If there is a IDE device at number "i" issue commands
' // to the device.
.如果真 (位与 (右移 (VersionParams.bIDEDeviceMap, i), 1) ≠ 0)
' // Try to enable SMART so we can tell if a drive supports it.
' // Ignore ATAPI devices.
.如果真 (取反 (位与 (右移 (VersionParams.bIDEDeviceMap, i), 16) ≠ 0))
' memset(&scip, 0, sizeof(scip))
' memset(&OutCmd, 0, sizeof(OutCmd))
.如果 (DoEnableSMART (hSMARTIOCTL, scip, OutCmd, i, cbBytesReturned))
标准输出 (, 格式化文本_ (_S (“SMART Enabled on Drive: %d”), i), #换行符)
' // Mark the drive as SMART enabled
' bDfpDriveMap |= (1 << i)
bDfpDriveMap = 位或 (bDfpDriveMap, 左移 (1, i))
.否则
CopyMemory_Ptr2SENDCMDOUTPARAMS (OutCmd_temp, OutCmd, 17)
标准输出 (, 格式化文本_ (_S (“SMART Enable Command Failed, Drive: %d.”), i), #换行符)
标准输出 (, 格式化文本_ (_S (“ DriverStatus: bDriverError=0x%X, bIDEStatus=0x%X”), OutCmd_temp.DriverStatus.bDriverError, OutCmd_temp.DriverStatus.bIDEStatus), #换行符)
.如果结束
标准输出 (, 格式化文本_ (_S (“%8sBytesReturned: %d”), _S (#SPACE_STRING), cbBytesReturned), #换行符)
.如果真结束
' // Now, get the ID sector for all IDE devices in the system.
' // If the device is ATAPI use the IDE_ATAPI_ID command,
' // otherwise use the IDE_ID_FUNCTION command.
bIDCmd = 选择 (位与 (右移 (VersionParams.bIDEDeviceMap, i), 16) ≠ 0, #IDE_ATAPI_ID, #IDE_ID_FUNCTION)
' memset(&scip, 0, sizeof(scip))
' memset(IdOutCmd, 0, sizeof(IdOutCmd))
.如果 (DoIDENTIFY (hSMARTIOCTL, scip, IdOutCmd, bIDCmd, i, cbBytesReturned))
' DisplayIdInfo((PIDSECTOR) ((PSENDCMDOUTPARAMS)IdOutCmd).bBuffer,scip,bIDCmd,bDfpDriveMap,i)
CopyMemory_Ptr2IDSECTOR (IDSECTOR_tmp, IdOutCmd + 16, 512)
DisplayIdInfo (hSMARTIOCTL, IDSECTOR_tmp, scip, bIDCmd, bDfpDriveMap, i)
.否则
CopyMemory_Ptr2SENDCMDOUTPARAMS (IdOutCmd_temp, IdOutCmd, 17)
标准输出 (, 格式化文本_ (_S (“Identify Command Failed on Drive: %d”), i), #换行符)
标准输出 (, 格式化文本_ (_S (“DriverStatus: bDriverError=0x%X, bIDEStatus=0x%X”), IdOutCmd_temp.DriverStatus.bDriverError, IdOutCmd_temp.DriverStatus.bIDEStatus), #换行符)
.如果结束
标准输出 (, 格式化文本_ (_S (“%8scbBytesReturned: %d”), _S (#SPACE_STRING), cbBytesReturned), #换行符, #换行符)
.如果真结束
.变量循环尾 ()
' // Loop through all possible IDE drives and send commands to the ones that support SMART.
.变量循环首 (0, #MAX_IDE_DRIVES, 1, i)
.如果真 (位与 (右移 (bDfpDriveMap, i), 1) ≠ 0)
' memset(AttrOutCmd, 0, sizeof(AttrOutCmd))
' memset(ThreshOutCmd, 0, sizeof(ThreshOutCmd))
.如果 (取反 (DoReadAttributesCmd (hSMARTIOCTL, scip, AttrOutCmd, i)))
CopyMemory_Ptr2SENDCMDOUTPARAMS (AttrOutCmd_temp, AttrOutCmd, 17)
标准输出 (, 格式化文本_ (_S (“SMART Read Attr Command Failed on Drive: %d.”), i), #换行符)
标准输出 (, 格式化文本_ (_S (“ DriverStatus: bDriverError=0x%X, bIDEStatus=0x%X”), AttrOutCmd_temp.DriverStatus.bDriverError, AttrOutCmd_temp.DriverStatus.bIDEStatus), #换行符)
.否则
' // ReadAttributes worked. Try ReadThresholds.
.如果真 (取反 (DoReadThresholdsCmd (hSMARTIOCTL, scip, ThreshOutCmd, i)))
CopyMemory_Ptr2SENDCMDOUTPARAMS (ThreshOutCmd_temp, ThreshOutCmd, 17)
标准输出 (, 格式化文本_ (_S (“SMART Read Thrsh Command Failed on Drive: %d.”), i), #换行符)
标准输出 (, 格式化文本_ (_S (“ DriverStatus: bDriverError=0x%X, bIDEStatus=0x%X”), ThreshOutCmd_temp.DriverStatus.bDriverError, ThreshOutCmd_temp.DriverStatus.bIDEStatus), #换行符)
.如果真结束
.如果结束
' // The following report will print if ReadAttributes works.
' // If ReadThresholds works, the report will also show values for
' // Threshold values.
DoPrintData (AttrOutCmd, ThreshOutCmd, i)
.如果真结束
.变量循环尾 ()
' // Close SMART.
CloseHandle (hSMARTIOCTL)
LocalFree (AttrOutCmd)
LocalFree (IdOutCmd)
LocalFree (ThreshOutCmd)
LocalFree (OutCmd)
ret = 真
.如果真结束
hInput = GetStdHandle (#STD_INPUT_HANDLE) ' 让易的控制台支持鼠标等
SetConsoleMode (hInput, 位或 (#ENABLE_PROCESSED_INPUT, #ENABLE_LINE_INPUT, #ENABLE_ECHO_INPUT, #ENABLE_WINDOW_INPUT))
标准输出 (, #换行符)
标准输出 (, “Press any key to continue”)
ReadConsoleInput (hInput, lpBuff, 1, lpNumberOfEventsRead)
ReadConsoleInput (hInput, lpBuff, 1, lpNumberOfEventsRead)
.循环判断首 () ' 按任意键继续
延时 (100)
LastMsg = lpBuff [1]
ReadConsoleInput (hInput, lpBuff, 1, lpNumberOfEventsRead)
.循环判断尾 (lpNumberOfEventsRead = 1 且 lpBuff [1] ≠ #KEY_EVENT 或 LastMsg = #MENU_EVENT)
返回 (ret)
.子程序 DoIDENTIFY, 逻辑型
.参数 hSMARTIOCTL, 整数型
.参数 pSCIP, SENDCMDINPARAMS, 参考
.参数 pSCOP, 整数型
.参数 bIDCmd, 字节型
.参数 bDriveNum, 字节型
.参数 lpcbBytesReturned, 整数型, 参考
' /****************************************************************************
' *
' * DoIDENTIFY
' *
' * FUNCTION: Send an IDENTIFY command to the drive
' * bDriveNum = 0-3
' * bIDCmd = IDE_ID_FUNCTION or IDE_ATAPI_ID
' *
' ****************************************************************************/
' BOOL DoIDENTIFY(HANDLE hSMARTIOCTL, PSENDCMDINPARAMS pSCIP,PSENDCMDOUTPARAMS pSCOP, BYTE bIDCmd, BYTE bDriveNum, PDWORD lpcbBytesReturned)
' //
' // Set up data structures for IDENTIFY command.
' //
pSCIP.cBufferSize = #IDENTIFY_BUFFER_SIZE
pSCIP.irDriveRegs.bFeaturesReg = 0
pSCIP.irDriveRegs.bSectorCountReg = 1
pSCIP.irDriveRegs.bSectorNumberReg = 1
pSCIP.irDriveRegs.bCylLowReg = 0
pSCIP.irDriveRegs.bCylHighReg = 0
' //
' // Compute the drive number.
' //
pSCIP.irDriveRegs.bDriveHeadReg = 位或 (160, 左移 (位与 (bDriveNum, 1), 4))
' //
' // The command can either be IDE identify or ATAPI identify.
' //
pSCIP.irDriveRegs.bCommandReg = bIDCmd
pSCIP.bDriveNumber = bDriveNum
pSCIP.cBufferSize = #IDENTIFY_BUFFER_SIZE
返回 (DeviceIoControl_SENDCMDINPARAMS (hSMARTIOCTL, #DFP_RECEIVE_DRIVE_DATA, pSCIP, 32, pSCOP, 528, lpcbBytesReturned, 0) ≠ 0)
.子程序 DisplayIdInfo
.参数 hSMARTIOCTL, 整数型
.参数 pids, _IDINFO
.参数 pSCIP, SENDCMDINPARAMS
.参数 bIDCmd, 字节型
.参数 bDfpDriveMap, 字节型
.参数 bDriveNum, 字节型
.局部变量 szOutBuffer, 文本型
' /****************************************************************************
' *
' * DisplayIdInfo
' *
' * Display the contents of the ID buffer
' *
' ****************************************************************************/
' VOID DisplayIdInfo(PIDSECTOR pids, PSENDCMDINPARAMS pSCIP, BYTE bIDCmd, BYTE bDfpDriveMap, BYTE bDriveNum)
szOutBuffer = 取空白文本 (41)
.如果 (bIDCmd = #IDE_ID_FUNCTION)
标准输出 (, 格式化文本_ (_S (“Drive %d is an IDE Hard drive”), bDriveNum))
szOutBuffer = 选择 (位与 (右移 (bDfpDriveMap, bDriveNum), 1) ≠ 0, “ that supports SMART”, “”)
标准输出 (, 格式化文本_ (_S (“%s”), _S (szOutBuffer)), #换行符)
标准输出 (, 格式化文本_ (_S (“%8s#Cylinders: %d, #Heads: %d, #Sectors per Track: %d”), _S (#SPACE_STRING), pids.wNumCyls, pids.wNumHeads, pids.wSectorsPerTrack), #换行符)
PrintIDERegs (pSCIP)
.否则
标准输出 (, 格式化文本_ (_S (“Drive %d is an ATAPI device.”), bDriveNum), #换行符)
.如果结束
' // Change the WORD array to a BYTE
' // array
ChangeByteOrder (pids.sModelNumber, 40)
' memset(szOutBuffer,0, sizeof(szOutBuffer))
lstrcpyn (szOutBuffer, pids.sModelNumber, 40)
标准输出 (, 格式化文本_ (_S (“%8sModel number: %s”), _S (#SPACE_STRING), _S (szOutBuffer)), #换行符)
' // Change the WORD array to a BYTE
' // array
ChangeByteOrder (pids.sFirmwareRev, 8)
' memset(szOutBuffer,0, sizeof(szOutBuffer))
lstrcpyn (szOutBuffer, pids.sFirmwareRev, 8)
标准输出 (, 格式化文本_ (_S (“%8sFirmware rev: %s”), _S (#SPACE_STRING), _S (szOutBuffer)), #换行符)
' // Change the WORD array to a BYTE
' // array
ChangeByteOrder (pids.sSerialNumber, 20)
' memset(szOutBuffer,0, sizeof(szOutBuffer))
lstrcpyn (szOutBuffer, pids.sSerialNumber, 20)
szOutBuffer = 删首尾空_ (szOutBuffer)
标准输出 (, 格式化文本_ (_S (“%8sSerial number: %s”), _S (#SPACE_STRING), _S (szOutBuffer)), #换行符)
szOutBuffer = 到文本 (DoGETDRIVEGEOMETRY (hSMARTIOCTL)) + “ GB”
标准输出 (, 格式化文本_ (_S (“%8sCapacity: %s”), _S (#SPACE_STRING), _S (szOutBuffer)), #换行符)
.子程序 DoGETDRIVEGEOMETRY, 整数型
.参数 hSMARTIOCTL, 整数型
.局部变量 DG, DISK_GEOMETRY
DeviceIoControl_DISK_GEOMETRY (hSMARTIOCTL, #IOCTL_DISK_GET_DRIVE_GEOMETRY, 0, 0, DG, 24, 0, 0)
返回 (DG.Cylinders × DG.TracksPerCylinder × DG.SectorsPerTrack × DG.BytesPerSector ÷ 1000 ÷ 1000 ÷ 1000)
.子程序 DoEnableSMART, 逻辑型
.参数 hSMARTIOCTL, 整数型
.参数 pSCIP, SENDCMDINPARAMS
.参数 pSCOP, 整数型
.参数 bDriveNum, 字节型
.参数 lpcbBytesReturned, 整数型, 参考
' /****************************************************************************
' *
' * DoEnableSMART
' *
' * FUNCTION: Send a SMART_ENABLE_SMART_OPERATIONS command to the drive
' * bDriveNum = 0-3
' *
' ****************************************************************************/
' BOOL DoEnableSMART(HANDLE hSMARTIOCTL, PSENDCMDINPARAMS pSCIP, PSENDCMDOUTPARAMS pSCOP, BYTE bDriveNum, PDWORD lpcbBytesReturned)
' // Set up data structures for Enable SMART Command.
pSCIP.cBufferSize = 0
pSCIP.irDriveRegs.bFeaturesReg = #SMART_ENABLE_SMART_OPERATIONS
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 = 位或 (160, 左移 (位与 (bDriveNum, 1), 4))
pSCIP.irDriveRegs.bCommandReg = #IDE_EXECUTE_SMART_FUNCTION
pSCIP.bDriveNumber = bDriveNum
返回 (DeviceIoControl_SENDCMDINPARAMS (hSMARTIOCTL, #DFP_SEND_DRIVE_COMMAND, pSCIP, 33 - 1, pSCOP, 17 - 1, lpcbBytesReturned, 0) ≠ 0)
.子程序 DoReadAttributesCmd, 逻辑型
.参数 hSMARTIOCTL, 整数型
.参数 pSCIP, SENDCMDINPARAMS
.参数 pSCOP, 整数型
.参数 bDriveNum, 字节型
.局部变量 cbBytesReturned, 整数型
' /****************************************************************************
' *
' * 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)
' // 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 = 位与 (160, 左移 (位与 (bDriveNum, 1), 4))
pSCIP.irDriveRegs.bCommandReg = #IDE_EXECUTE_SMART_FUNCTION
pSCIP.bDriveNumber = bDriveNum
返回 (DeviceIoControl_SENDCMDINPARAMS (hSMARTIOCTL, #DFP_RECEIVE_DRIVE_DATA, pSCIP, 33 - 1, pSCOP, 17 + #READ_ATTRIBUTE_BUFFER_SIZE - 1, cbBytesReturned, 0) ≠ 0)
.子程序 DoReadThresholdsCmd, 逻辑型, , // FUNCTION: Send a SMART_READ_ATTRIBUTE_THRESHOLDS command to the drive bDriveNum = 0-3
.参数 hSMARTIOCTL, 整数型
.参数 pSCIP, SENDCMDINPARAMS
.参数 pSCOP, 整数型
.参数 bDriveNum, 字节型
.局部变量 cbBytesReturned, 整数型
' // Set up data structures for Read Thresholds SMART Command.
pSCIP.cBufferSize = #READ_THRESHOLD_BUFFER_SIZE
pSCIP.irDriveRegs.bFeaturesReg = #SMART_READ_ATTRIBUTE_THRESHOLDS
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 = 位或 (160, 左移 (位与 (bDriveNum, 1), 4))
pSCIP.irDriveRegs.bCommandReg = #IDE_EXECUTE_SMART_FUNCTION
pSCIP.bDriveNumber = bDriveNum
返回 (DeviceIoControl_SENDCMDINPARAMS (hSMARTIOCTL, #DFP_RECEIVE_DRIVE_DATA, pSCIP, 33 - 1, pSCOP, 17 + #READ_THRESHOLD_BUFFER_SIZE - 1, cbBytesReturned, 0) ≠ 0)
.子程序 DoPrintData, , , //FUNCTION: Display the SMART Attributes and Thresholds
.参数 pAttrBuffer, 整数型
.参数 pThrsBuffer, 整数型
.参数 bDriveNum, 字节型
.局部变量 i, 整数型
.局部变量 pDA, DRIVEATTRIBUTE
.局部变量 pAT, ATTRTHRESHOLD
.局部变量 pDA_Ptr, 整数型
.局部变量 PAT_Ptr, 整数型
' // Print the drive number
标准输出 (, 格式化文本_ (_S (“Data for Drive Number %d”), bDriveNum), #换行符)
' // Print the revisions of the data structures
标准输出 (, “Attribute Structure Revision Threshold Structure Revision”, #换行符)
标准输出 (, 格式化文本_ (_S (“%13s%d%36s%d”), _S (#SPACE_STRING), 指针到字节 (pAttrBuffer + 16), _S (#SPACE_STRING), 指针到字节 (pThrsBuffer + 16)), #换行符, #换行符)
' // Print the header and loop through the structures, printing
' // the structures when the attribute ID is known.
标准输出 (, “ -ID- -属性名- -当前值- -最差- -阈值- -数据-”, #换行符)
pDA_Ptr = pAttrBuffer + 18
PAT_Ptr = pThrsBuffer + 18
.变量循环首 (1, #NUM_ATTRIBUTE_STRUCTS, 1, i)
CopyMemory_Ptr2DRIVEATTRIBUTE (pDA, pDA_Ptr, 12)
CopyMemory_Ptr2ATTRTHRESHOLD (pAT, PAT_Ptr, 12)
.如果真 (pDA.bAttrID ≠ 0)
标准输出 (, 格式化文本_ (_S (“ (%02X) %-31s%3d%7c%3d%6c%3d%6c%d”), pDA.bAttrID, GetAttrName (pDA.bAttrID), pDA.bAttrValue, 32, pDA.bWorstValue, 32, pAT.bWarrantyThreshold, 32, 字节数组到整数 (pDA.bRawValue)), #换行符)
.如果真结束
pDA_Ptr = pDA_Ptr + 12
PAT_Ptr = PAT_Ptr + 12
.变量循环尾 ()
.子程序 GetAttrName, 整数型
.参数 AttrID, 整数型
.局部变量 i, 整数型
.局部变量 sPos, 整数型
.局部变量 sRet, 整数型
sRet = -1
.计次循环首 (取数组成员数 (pAttrNames), i)
sPos = 寻找文本 (pAttrNames [i], “_”, , 假)
.如果真 (AttrID = 到整数 (取文本左边 (pAttrNames [i], sPos - 1)))
' sRet = 取文本右边 (pAttrNames [i], 取文本长度 (pAttrNames [i]) - sPos)
sRet = _S (pAttrNames [i]) + 4
跳出循环 ()
.如果真结束
.计次循环尾 ()
.如果真 (sRet = -1)
sRet = _S (pAttrNames [#MAX_KNOWN_ATTRIBUTES + 0]) + 4
.如果真结束
返回 (sRet)
.子程序 ChangeByteOrder
.参数 szString, 字节型, 数组
.参数 uscStrSize, 短整数型
.局部变量 i, 整数型
.局部变量 temp, 字节型
' VOID ChangeByteOrder(PCHAR szString, USHORT uscStrSize)
.变量循环首 (1, uscStrSize, 2, i)
temp = szString [i]
szString [i] = szString [i + 1]
szString [i + 1] = temp
.变量循环尾 ()
.子程序 PrintIDERegs, , , // Display contents of IDE hardware registers reported by SMART
.参数 pscip, SENDCMDINPARAMS
标准输出 (, 格式化文本_ (_S (“%8sIDE TASK FILE REGISTERS:”), _S (#SPACE_STRING), ), #换行符)
标准输出 (, 格式化文本_ (_S (“%16sbFeaturesReg = 0x%X”), _S (#SPACE_STRING), pscip.irDriveRegs.bFeaturesReg), #换行符)
标准输出 (, 格式化文本_ (_S (“%16sbSectorCountReg = 0x%X”), _S (#SPACE_STRING), pscip.irDriveRegs.bSectorCountReg), #换行符)
标准输出 (, 格式化文本_ (_S (“%16sbSectorNumberReg = 0x%X”), _S (#SPACE_STRING), pscip.irDriveRegs.bSectorNumberReg), #换行符)
标准输出 (, 格式化文本_ (_S (“%16sbCylLowReg = 0x%X”), _S (#SPACE_STRING), pscip.irDriveRegs.bCylLowReg), #换行符)
标准输出 (, 格式化文本_ (_S (“%16sbCylHighReg = 0x%X”), _S (#SPACE_STRING), pscip.irDriveRegs.bCylHighReg), #换行符)
标准输出 (, 格式化文本_ (_S (“%16sbDriveHeadReg = 0x%X”), _S (#SPACE_STRING), pscip.irDriveRegs.bDriveHeadReg), #换行符)
标准输出 (, 格式化文本_ (_S (“%16sStatus = 0x%X”), _S (#SPACE_STRING), pscip.irDriveRegs.bCommandReg), #换行符)
.子程序 OpenSMART, 整数型, , // Open SMART to allow DeviceIoControl communications.
.局部变量 hSMARTIOCTL, 整数型
' // Windows NT, Windows 2000
hSMARTIOCTL = CreateFile (“\\.\PhysicalDrive0”, 位或 (#GENERIC_READ, #GENERIC_WRITE), 位或 (#FILE_SHARE_READ, #FILE_SHARE_WRITE), 0, #OPEN_EXISTING, 0, 0)
' hSMARTIOCTL = CreateFile (“\\.\Scsi0:”, 位或 (#GENERIC_READ, #GENERIC_WRITE), 位或 (#FILE_SHARE_READ, #FILE_SHARE_WRITE), 0, #OPEN_EXISTING, 0, 0)
.如果 (hSMARTIOCTL = #INVALID_HANDLE_VALUE)
标准输出 (, 格式化文本_ (_S (“Unable to open physical drive, error code: 0x%lX”), GetLastError ()), #换行符)
.否则
标准输出 (, “Physical drive opened successfully”, #换行符)
.如果结束
返回 (hSMARTIOCTL)