发送IDENTIFY DEVICE COMMAND - ATA PASS通过raid - SSD

时间:2012-06-18 10:06:38

标签: windows raid deviceiocontrol ata

我的目标是在具有raid配置的系统中检测固态硬盘。使用smartmontools的以下命令,我观察到位434(217)显示SSD的值为1:smartctl -i -r ataioctl,2 / dev / csmi0,0

尝试读取相同的512字节数据我试图通过以下两种方式发送IDENTIFY DEVICE命令:

方法1失败,DeviceIoControl()将GetLastError()设置为87(ERROR_INVALID_PARAMETER),你能帮我理解可能出错的地方吗?我是否在正确的轨道上?

方法2有info-> IoctlHeader.ReturnCode = 3,这意味着CSMI_SAS_STATUS_INVALID_PARAMETER。(提供的CSMI缓冲区太小)

/////////方法1 /////////

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 */

////////方法2 //////////

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);

0 个答案:

没有答案