您可以發送0xEC
ATA命令到HDD並檢索IDENTIFY_DEVICE_DATA
結構,其中包含有關您的HDD的信息。 它要求irb.h
庫包含WDK(Windows驅動程序工具包)。
BOOL getAtaCompliance() {
DWORD dwBytes;
BOOL bResult;
CONST UINT bufferSize = 512;
CONST BYTE identifyDataCommandId = 0xEC;
UCHAR identifyDataBuffer[bufferSize
+ sizeof(ATA_PASS_THROUGH_EX)] = { 0 };
ATA_PASS_THROUGH_EX & PTE = *(ATA_PASS_THROUGH_EX *) identifyDataBuffer;
PTE.Length = sizeof(PTE);
PTE.TimeOutValue = 10;
PTE.DataTransferLength = 512;
PTE.DataBufferOffset = sizeof(ATA_PASS_THROUGH_EX);
IDEREGS * ideRegs = (IDEREGS *) PTE.CurrentTaskFile;
ideRegs->bCommandReg = identifyDataCommandId;
ideRegs->bSectorCountReg = 1;
PTE.AtaFlags = ATA_FLAGS_DATA_IN | ATA_FLAGS_DRDY_REQUIRED;
bResult = DeviceIoControl(hDevice, IOCTL_ATA_PASS_THROUGH, &PTE,
sizeof(identifyDataBuffer), &PTE,
sizeof(identifyDataBuffer), &dwBytes, 0);
if (bResult == FALSE) {
std::cout << "Oops, something went wrong, error code: "
<< GetLastError() << std::endl;
return bResult;
}
WORD *data = (WORD *)(identifyDataBuffer + sizeof(ATA_PASS_THROUGH_EX));
int16_t ataSupportBits = data[80];
return bResult;
}
ataSupportBits將包含關於支持的ATA標準的16位。 From Information technology - AT Attachment 8 - ATA/ATAPI Command Set (ATA8-ACS)