[nvmewin] DeviceIOControl Error
Sean Chen
beanhay at gmail.com
Mon Jun 9 05:56:40 PDT 2014
Hi All
I study PT_IOCTL.doc to implement NVMe command for windows. But
DeviceIControl return "The request could not be performed because of an I/O
device error." The following is my code:
// ================ Get Device ================
char driveName[256];
Select_choice = ComboBox->GetCurSel();
sprintf(driveName, "\\\\.\\scsi%d:", Select_choice);
DeviceHandle = CreateFile(driveName,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL,
NULL);
if (DeviceHandle == INVALID_HANDLE_VALUE) {
MessageBox("Cannot open device.", "Device Error", MB_OK|MB_ICONERROR);
return FALSE;
}
// ================ NVME Test ================
int ByteSizeTX = 256;
BOOL status = 0;
DWORD count = 0;
DWORD InputBufLen = 0;
DWORD OutputBufLen = 0;
PNVME_PASS_THROUGH_IOCTL pInBuffer = NULL;
PNVME_PASS_THROUGH_IOCTL pOutBuffer = NULL;
// From Device to Host
// Allocate input buffer to accommodate size of NVME_PASS_THRUGH_IOCTL only
InputBufLen = sizeof(NVME_PASS_THROUGH_IOCTL);
pInBuffer = (PNVME_PASS_THROUGH_IOCTL) malloc(InputBufLen);
// Allocate output buffer to accommodate size of NVME_PASS_THRUGH_IOCTL and
data
OutputBufLen = sizeof(NVME_PASS_THROUGH_IOCTL) + ByteSizeTX;
pOutBuffer = (PNVME_PASS_THROUGH_IOCTL) malloc(OutputBufLen);
// Confirm we have buffers allocated successfully
if (pInBuffer == NULL || pOutBuffer == NULL)
return;
// Zero out the buffers
memset(pInBuffer, 0, InputBufLen);
memset(pOutBuffer, 0, OutputBufLen);
// Populate SRB_IO_CONTROL fields in input buffer
pInBuffer->SrbIoCtrl.ControlCode = NVME_PASS_THROUGH_SRB_IO_CODE;
pInBuffer->SrbIoCtrl.HeaderLength = sizeof(SRB_IO_CONTROL);
memcpy((UCHAR*)(&pInBuffer->SrbIoCtrl.Signature[0]), NVME_SIG_STR,
NVME_SIG_STR_LEN);
pInBuffer->SrbIoCtrl.Timeout = 40;
pInBuffer->SrbIoCtrl.Length = InputBufLen - sizeof(SRB_IO_CONTROL);
pInBuffer->DataBufferLen = ByteSizeTX;
pInBuffer->ReturnBufferLen = OutputBufLen;
//pInBuffer->Direction = NVME_FROM_DEV_TO_HOST;
// Fill in pInBuffer->NVMeCmd here
pInBuffer->NVMeCmd[0] = 0x0A; // OpCode
pInBuffer->NVMeCmd[1] = 0x01; // Namespace ID
pInBuffer->NVMeCmd[10] = 0x01;
// Fill pInBuffer->DataBuffer here when transferring data to device
status = DeviceIoControl(
DeviceHandle, // Handle to \\.\scsi device via
CreateFile
IOCTL_SCSI_MINIPORT, // IO control function to a
miniport driver
pInBuffer, // Input buffer with data sent to
driver
InputBufLen, // Length of data sent to driver
(in bytes)
pOutBuffer, // Output buffer with data
received from driver
OutputBufLen, // Length of data received from
driver
&count, // Bytes placed in DataBuffer
NULL); // NULL = no overlap
free(pInBuffer);
free(pOutBuffer);
// ====================================================
May I have anything wrong?
Thanks for your help.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openfabrics.org/pipermail/nvmewin/attachments/20140609/e8b04256/attachment.html>
More information about the nvmewin
mailing list