|
你下SCSI指令是会有BUFFER, DATA放在BUFFER内.
请参考.
#include "ntddscsi.h"
#include "Winioctl.h"
UCHAR szBuffer[512*0x80]; //64k/////////////////////// DATA BUFFER
SCSI_PASS_THROUGH_WITH_BUFFERS sptwb;
bool CSCSICommand::SCSI_READ_10(DWORD ucAddress, WORD wBlock, UINT uiBlockSize )
{
PreCMD();
sptwb.Spt.DataIn = SCSI_IOCTL_DATA_IN;
sptwb.Spt.DataTransferLength = wBlock * uiBlockSize;
sptwb.Spt.Cdb[0] = 0x28;
sptwb.Spt.Cdb[1] = 0x00;
sptwb.Spt.Cdb[2] = (ucAddress & 0xFF000000) >> 24;
sptwb.Spt.Cdb[3] = (ucAddress & 0x00FF0000) >> 16;
sptwb.Spt.Cdb[4] = (ucAddress & 0x0000FF00) >> 8;
sptwb.Spt.Cdb[5] = (ucAddress & 0x000000FF) >> 0;
sptwb.Spt.Cdb[6] = 0x00;
sptwb.Spt.Cdb[7] = (wBlock & 0xFF00) >> 8;
sptwb.Spt.Cdb[8] = (wBlock & 0x00FF) >> 0;
sptwb.Spt.Cdb[9] = 0x00;
sptwb.Spt.Cdb[10] = 0x00;
sptwb.Spt.Cdb[11] = 0x00;
return SedCMD();
}
void CSCSICommand::PreCMD(void)
{
ZeroMemory(&sptwb, sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS));
sptwb.Spt.Length = sizeof(SCSI_PASS_THROUGH);
sptwb.Spt.PathId = 0;
sptwb.Spt.TargetId = 1;
sptwb.Spt.Lun = 0;
sptwb.Spt.CdbLength = 12;
sptwb.Spt.SenseInfoLength = sizeof(sptwb.SenseBuf);
sptwb.Spt.TimeOutValue = TIME_OUT;
sptwb.Spt.DataBufferOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS,DataBuf);
sptwb.Spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS,SenseBuf);
}
bool CSCSICommand::SedCMD(void)
{
ULONG returned;
ULONG length = sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS);
if (sptwb.Spt.DataIn == SCSI_IOCTL_DATA_IN)
ZeroMemory(szBuffer, sptwb.Spt.DataTransferLength);
if (sptwb.Spt.DataIn == SCSI_IOCTL_DATA_OUT)
memcpy(&sptwb.DataBuf[0],&szBuffer[0],sptwb.Spt.DataTransferLength);
//QueryPerformanceCounter(&Lstart_time1);
BOOL status = DeviceIoControl(hDevice,
IOCTL_SCSI_PASS_THROUGH,
&sptwb,
length,
&sptwb,
length,
&returned,
FALSE);
//QueryPerformanceCounter(&Lend_time1);
//Ldiff_time1.QuadPart = (Lend_time1.QuadPart - Lstart_time1.QuadPart);
if ((! status) || (sptwb.Spt.ScsiStatus))
{
memcpy(ucSenseKey, sptwb.SenseBuf,sizeof(sptwb.SenseBuf));
return false;
}
else
{
if (sptwb.Spt.DataIn == SCSI_IOCTL_DATA_IN)
memcpy(&szBuffer[0],&sptwb.DataBuf[0],sptwb.Spt.DataTransferLength);
return true;
}
}
|
|