我的目标是在具有 raid 配置的系统中检测固态驱动器。使用 smartmontools 的以下命令,我观察到位 434 (217) 显示 SSD 的值 1: smartctl -i -r ataioctl,2 /dev/csmi0,0
尝试读取相同的 512 字节数据我尝试通过以下 2 种方式发送 IDENTIFY DEVICE 命令:
方法 1 失败,DeviceIoControl() 将 GetLastError() 设置为 87 (ERROR_INVALID_PARAMETER),你能帮我理解什么可能是错误的,我是否在正确的轨道上?
方法 2 有 info->IoctlHeader.ReturnCode = 3 这意味着 CSMI_SAS_STATUS_INVALID_PARAMETER。(提供的 CSMI 缓冲区太小)
///////// 方法一 /////////
handle = CreateFile(L"\\\\.\\PhysicalDrive0",
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
NULL,
NULL);
if (handle == INVALID_HANDLE_VALUE)
{
printf("Unable to open handle to device , Error %u\n", GetLastError());
return 1;
}
//Allocate memory for ATA_PASS_THROUGH_EX and clear the contents
pATAData = (PATA_PASS_THROUGH_EX) VirtualAlloc(NULL, dataSize, MEM_COMMIT, PAGE_READWRITE);
ZeroMemory(pATAData,dataSize);
//Fill in the IDENTIFY DEVICE query data
pATAData->Length = sizeof(ATA_PASS_THROUGH_EX);
pATAData->DataBufferOffset = sizeof(ATA_PASS_THROUGH_EX);
pATAData->DataTransferLength = 512;
pATAData->AtaFlags = ATA_FLAGS_DATA_IN;
pATAData->TimeOutValue = 10; //Seconds
pATAData->CurrentTaskFile[6] = 0xEC; /* send the command*/
status = DeviceIoControl( handle,
IOCTL_ATA_PASS_THROUGH,
pATAData,
dataSize, /* input buffer and size */
pATAData,
dataSize, /* output buffer and size */
&bytescopied, /* bytes copied to output buffer*/
NULL ); /* no overlapping */
//////// 方法二 //////////
BYTE portNumber = 0;
_stprintf_s(DeviceName, (sizeof(char)*128),_T("\\\\.\\Scsi%u:"),portNumber);
// get a handle to the miniport driver
handle = CreateFile(DeviceName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
NULL,
NULL);
if (handle == INVALID_HANDLE_VALUE)
{
printf("Unable to open handle to device , Error %u\n", GetLastError());
return;
}
CSMI_SAS_STP_PASSTHRU_BUFFER* info = (CSMI_SAS_STP_PASSTHRU_BUFFER *) calloc(1, sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER));
info->IoctlHeader.HeaderLength = sizeof(IOCTL_HEADER);
info->IoctlHeader.Timeout = CSMI_SAS_TIMEOUT;
info->IoctlHeader.ControlCode = CC_CSMI_SAS_STP_PASSTHRU;
info->IoctlHeader.Length = sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER) - sizeof(IOCTL_HEADER);
info->IoctlHeader.ReturnCode = 0;
memcpy(&info->IoctlHeader.Signature, CSMI_SAS_SIGNATURE, sizeof(CSMI_SAS_SIGNATURE));
bSuccess = DeviceIoControl(handle, IOCTL_SCSI_MINIPORT, info, sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER),
info, sizeof(CSMI_SAS_STP_PASSTHRU_BUFFER),
&bytesReturned, NULL);