⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 smart.pas

📁 检测CPU信息和硬盘温度,以及硬盘使用时间和IP地址的小软件。
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit smart;

interface

uses
  windows;
// Miscellaneous
const
  MAX_IDE_DRIVES             = 4; // Max number of drives assuming primary/secondary, master/slave topology
  READ_ATTRIBUTE_BUFFER_SIZE = 512;
  IDENTIFY_BUFFER_SIZE	     = 512;
  READ_THRESHOLD_BUFFER_SIZE = 512;

//
// IOCTL commands
//
const
  DFP_GET_VERSION	 = $00074080;
  DFP_SEND_DRIVE_COMMAND = $0007c084;
  DFP_RECEIVE_DRIVE_DATA = $0007c088;

//---------------------------------------------------------------------
// GETVERSIONOUTPARAMS contains the data returned from the
// Get Driver Version function.
//---------------------------------------------------------------------
type
  GETVERSIONOUTPARAMS = packed record
    bVersion:  Byte;  // Binary driver version.
    bRevision: Byte;  // Binary driver revision.
    bReserved: Byte;  // Not used.
    bIDEDeviceMap: BYTE;  // Bit map of IDE devices.
    fCapabilities: DWORD; // Bit mask of driver capabilities.
    dwReserved: array [0..3] of DWORD; // For future use.
  end; {GETVERSIONOUTPARAMS}
  PGETVERSIONOUTPARAMS = ^GETVERSIONOUTPARAMS;

//
// Bits returned in the fCapabilities member of GETVERSIONOUTPARAMS
//
const
  CAP_IDE_ID_FUNCTION            = 1; // ATA ID command supported
  CAP_IDE_ATAPI_ID               = 2; // ATAPI ID command supported
  CAP_IDE_EXECUTE_SMART_FUNCTION = 4; // SMART commannds supported

//---------------------------------------------------------------------
// IDE registers
//---------------------------------------------------------------------
type
  IDEREGS = packed record
    bFeaturesReg: Byte;     // Used for specifying SMART "commands".
    bSectorCountReg: Byte;  // IDE sector count register
    bSectorNumberReg: Byte; // IDE sector number register
    bCylLowReg: Byte;       // IDE low order cylinder value
    bCylHighReg: Byte;      // IDE high order cylinder value
    bDriveHeadReg: Byte;    // IDE drive/head register
    bCommandReg: Byte;      // Actual IDE command.
    bReserved: Byte;        // reserved for future use.  Must be zero.
  end; {IDEREGS}
  PIDEREGS = ^IDEREGS;

//---------------------------------------------------------------------
// SENDCMDINPARAMS contains the input parameters for the
// Send Command to Drive function.
//---------------------------------------------------------------------
type
  SENDCMDINPARAMS = packed record
    cBufferSize:  DWORD;   // Buffer size in bytes
    irDriveRegs:  IDEREGS; // Structure with drive register values.
    bDriveNumber: Byte;    // Physical drive number to send
                           // command to (0,1,2,3).
    bReserved:  array [0..2] of Byte;  // Reserved for future expansion.
    dwReserved: array [0..3] of DWORD; // For future use.
    bBuffer:    array [0..0] of Byte;  // Input buffer.
  end; {SENDCMDINPARAMS}
  PSENDCMDINPARAMS = ^SENDCMDINPARAMS;

//
// Valid values for the bCommandReg member of IDEREGS.
//
const
  IDE_ATAPI_ID                = $A1; // Returns ID sector for ATAPI.
  IDE_ID_FUNCTION             = $EC; // Returns ID sector for ATA.
  IDE_EXECUTE_SMART_FUNCTION  = $B0; // Performs SMART cmd.
											// Requires valid bFeaturesReg,
											// bCylLowReg, and bCylHighReg
//
// Cylinder register values required when issuing SMART command
//
const
  SMART_CYL_LOW = $4F;
  SMART_CYL_HI  = $C2;

//---------------------------------------------------------------------
// Status returned from driver
//---------------------------------------------------------------------
type
  DRIVERSTATUS = packed record
    bDriverError: Byte; // Error code from driver,
		        // or 0 if no error.
    bIDEStatus: Byte;   // Contents of IDE Error register.
		        // Only valid when bDriverError
		        // is SMART_IDE_ERROR.
    bReserved: array [0..1] of Byte; // Reserved for future expansion.
    dwReserved: array [0..1] of DWORD; // Reserved for future expansion.
  end; {DRIVERSTATUS}
  PDRIVERSTATUS = ^DRIVERSTATUS;

//
// bDriverError values
//
const
  SMART_NO_ERROR         =  0; // No error
  SMART_IDE_ERROR        =  1; // Error from IDE controller
  SMART_INVALID_FLAG     =  2; // Invalid command flag
  SMART_INVALID_COMMAND  =  3; // Invalid command byte
  SMART_INVALID_BUFFER   =  4; // Bad buffer (null, invalid addr..)
  SMART_INVALID_DRIVE    =  5; // Drive number not valid
  SMART_INVALID_IOCTL    =  6; // Invalid IOCTL
  SMART_ERROR_NO_MEM     =  7; // Could not lock user's buffer
  SMART_INVALID_REGISTER =  8; // Some IDE Register not valid
  SMART_NOT_SUPPORTED    =  9; // Invalid cmd flag set
  SMART_NO_IDE_DEVICE    = 10; // Cmd issued to device not present
                               // although drive number is valid
// 11-255 reserved

//---------------------------------------------------------------------
// Structure returned by SMART IOCTL for several commands
//---------------------------------------------------------------------
type
  SENDCMDOUTPARAMS = packed record
    cBufferSize:  DWORD;          // Size of bBuffer in bytes
    DriverStatus: DRIVERSTATUS;   // Driver status structure.
    bBuffer: array [0..0] of Byte; // Buffer of arbitrary length in which to
                                   //  store the data read from the drive.
  end; {SENDCMDOUTPARAMS}
  PSENDCMDOUTPARAMS = ^SENDCMDOUTPARAMS;

//---------------------------------------------------------------------
// Feature register defines for SMART "sub commands"
//---------------------------------------------------------------------
const
  SMART_READ_ATTRIBUTE_VALUES             = $D0; // ATA4: Renamed
                                                 // SMART READ DATA
  SMART_READ_ATTRIBUTE_THRESHOLDS         = $D1; // Obsoleted in ATA4!
  SMART_ENABLE_DISABLE_ATTRIBUTE_AUTOSAVE = $D2;
  SMART_SAVE_ATTRIBUTE_VALUES             = $D3;
  SMART_EXECUTE_OFFLINE_IMMEDIATE         = $D4; // ATA4
                                                 // Vendor specific commands:
  SMART_ENABLE_SMART_OPERATIONS           = $D8;
  SMART_DISABLE_SMART_OPERATIONS          = $D9;
  SMART_RETURN_SMART_STATUS               = $DA;

//---------------------------------------------------------------------
// The following structure defines the structure of a Drive Attribute
//---------------------------------------------------------------------
type
  DRIVEATTRIBUTE = packed record
    bAttrID:      Byte; // Identifies which attribute
    wStatusFlags: Word;	// see bit definitions below
    bAttrValue:   Byte; // Current normalized value
    bWorstValue:  Byte; // How bad has it ever been?
    bRawValue: array [0..5] of Byte; // Un-normalized value
    bReserved:    Byte; // ...
  end; {DRIVEATTRIBUTE}
  PDRIVEATTRIBUTE = ^DRIVEATTRIBUTE;

//---------------------------------------------------------------------
// The following structure defines the structure of a Warranty Threshold
// Obsoleted in ATA4!
//---------------------------------------------------------------------
type
  ATTRTHRESHOLD = packed record
    bAttrID: Byte;            // Identifies which attribute
    bWarrantyThreshold: Byte; // Triggering value
    bReserved: array [0..9] of Byte; // ...
  end; {ATTRTHRESHOLD}
  PATTRTHRESHOLD = ^ATTRTHRESHOLD;

//---------------------------------------------------------------------
// The following struct defines the interesting part of the IDENTIFY
// buffer:
//---------------------------------------------------------------------
type
  USHORT = Word;
  
  IDSECTOR = packed record
    wGenConfig: USHORT;
    wNumCyls:   USHORT;
    wReserved:  USHORT;
    wNumHeads:  USHORT;
    wBytesPerTrack:   USHORT;
    wBytesPerSector:  USHORT;
    wSectorsPerTrack: USHORT;
    wVendorUnique: array [0..2] of USHORT;
    sSerialNumber: array [0..19] of Char;
//    sSerialNumber: string [20];
    wBufferType:   USHORT;
    wBufferSize:   USHORT;
    wECCSize:      USHORT;
    sFirmwareRev:  array [0..7] of CHAR;
//    sFirmwareRev:  string [8];
    sModelNumber:  array [0..39] of CHAR;
//    sModelNumber:  string [40];

    wMoreVendorUnique: USHORT;
    wDoubleWordIO: USHORT;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -