USB Memory Stick.

I am new to DDK WDM Concept.

There are SCSI commands available. When i try that command listed below different behavior output i am getting.
CHANGE ALIASES, FORMAT UNIT, INQUIRY, LOG SELECT, LOG SENSE, MODE SELECT (6),
MODE SELECT (10), MODE SENSE (6) , MODE SENSE (10), PRE-FETCH (10), PRE-FETCH (16) , READ (6) , READ (10), READ BUFFER , READ CAPACITY (10) , READ DEFECT DATA (10), READ LONG (10) , RELEASE (6), REQUEST SENSE , REZERO UNIT , SEEK , SEND DIAGNOSTICS, START STOP UNIT , SYNCHRONIZE CACHE (10), TEST UNIT READY,
VERIFY (10) , WRITE (6) , WRITE (10) , WRITE AND VERIFY (10), WRITE BUFFER , WRITE LONG (10) , WRITE SAME (10) ,
My Code for Read buffer.

BOOL ReadDataBuffer(HANDLE hDevice)
{
printf("*********BOOL ReadDataBuffer(HANDLE hDevice)*********\n");
BOOL status =0;
ULONG length = 0;
ULONG returned = 0;
ULONG alignmentMask = 0;
PUCHAR dataBuffer = NULL;
PUCHAR pUnAlignedBuffer = NULL;
SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER sptdwb;

ZeroMemory(&sptdwb, sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER));
dataBuffer = AllocateAlignedBuffer(SECTOR_SIZE, 0/*alignmentMask*/, &pUnAlignedBuffer);
ZeroMemory(dataBuffer,SECTOR_SIZE);

sptdwb.sptd.Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
sptdwb.sptd.PathId = 0;
sptdwb.sptd.TargetId = 1;
sptdwb.sptd.Lun = 0;
sptdwb.sptd.CdbLength = CDB10GENERIC_LENGTH;
sptdwb.sptd.DataIn = SCSI_IOCTL_DATA_IN;
sptdwb.sptd.SenseInfoLength = SPT_SENSE_LENGTH;
sptdwb.sptd.DataTransferLength = SECTOR_SIZE;
sptdwb.sptd.TimeOutValue = 2;
sptdwb.sptd.DataBuffer = dataBuffer;
sptdwb.sptd.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER,ucSenseBuf);
sptdwb.sptd.Cdb[0] = SCSIOP_READ_DATA_BUFF;
sptdwb.sptd.Cdb[1] = 2; // Data mode
sptdwb.sptd.Cdb[7] = (UCHAR)(SECTOR_SIZE >> 8); // Parameter List length
sptdwb.sptd.Cdb[8] = 0;
length = sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER);
status = DeviceIoControl(hDevice,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
&sptdwb,
length,
&sptdwb,
length,
&returned,
FALSE);

PrintStatusResults(status,returned, (PSCSI_PASS_THROUGH_WITH_BUFFERS)&sptdwb,length);

if ((sptdwb.sptd.ScsiStatus == 0) && (status != 0))
{
PrintDataBuffer(dataBuffer,sptdwb.sptd.DataTransferLength);
}
return status;
}
int _tmain(int argc, _TCHAR* argv)
{
HANDLE hDevice;
BOOL status = 0;
ULONG alignmentMask = 0;
DWORD errorCode =0;

CString strDev;
strDev.Format(L"\\.\g:");
hDevice = CreateFile(strDev,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, NULL);
if(hDevice == INVALID_HANDLE_VALUE)
{
printf("Error accessing rom drive - creating handle (%d)\n", GetLastError());
}
status = ReadDataBuffer(hDevice);
if (!status )
{
PrintError(GetLastError());
return 1;
}
}

The PROBLEM IS:-

  1. DeviceIOControl return 1
    but sptdwb.sptd.ScsiStatus is 0x02.
    Scsi status: 02h
    Sense Info -- Sense info buffer data details.

F0 01 05 00 00 00 00 0A 00 AA 55 61 20 00 01 00 01 00

sptdwb.sptd.DataTransferLength also become zero after exection of DeviceIOControl API.
*******************************
Same for READ10 and WRITE10 commands

For READ10:- But If i ignore the error and check the READ10 Buffer data. The data is come from Memory stick. Even data is matching.
For WRITE10:- When the DeviceIOControl execute it tries the CDROME device (note:- not writing Memory stick)