开发者

Sending a specific SCSI command to a SCSI device in Windows

开发者 https://www.devze.com 2023-01-08 07:16 出处:网络
Does windows have specific interface by which I can send a specific scsi command such Inquiry to scsi device ? I searched the net, found passing reference to SCSI Pass Through interface. But Its very

Does windows have specific interface by which I can send a specific scsi command such Inquiry to scsi device ? I searched the net, found passing reference to SCSI Pass Through interface. But Its very Vague.

Is there any documentation for that API on how to use it?开发者_开发知识库?


#include <iostream>
#include <windows.h>
#include <winioctl.h>
#define ULONG_PTR ULONG
#include <ntddscsi.h> //from SDK
#include <spti.h>      //from DDK 
using namespace std;

int demo()
{
    HANDLE hDisk;
    SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER sptdwb; 
    ULONG length = 0;
    DWORD bytesReturn;
    BYTE bufDataRead[64*1024+10];
    int iRet;        

    hDisk = CreateFile(path,GENERIC_READ | GENERIC_WRITE,     
            FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,OPEN_EXISTING,0,NULL                                 
            );
    if (hDisk ==INVALID_HANDLE_VALUE)  {              
          return 0;
    }
    ZeroMemory(&sptdwb, sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER));
    sptdwb.sptd.Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
    sptdwb.sptd.PathId = 0;
    sptdwb.sptd.TargetId = 1;
    sptdwb.sptd.Lun = 0;
    sptdwb.sptd.CdbLength = 6;
    sptdwb.sptd.DataIn = SCSI_IOCTL_DATA_IN;
    sptdwb.sptd.SenseInfoLength = 24;
    sptdwb.sptd.DataTransferLength = 8; 
    sptdwb.sptd.TimeOutValue = 2;
    sptdwb.sptd.DataBuffer = bufDataRead; 
    sptdwb.sptd.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER,ucSenseBuf);       
    sptdwb.sptd.Cdb[0] = 0x12;
    sptdwb.sptd.Cdb[1] = 0x00;
    sptdwb.sptd.Cdb[2] = 0x00;
    sptdwb.sptd.Cdb[3] = 0x00;
    sptdwb.sptd.Cdb[4] = 0xFF;
    sptdwb.sptd.Cdb[5] = 0x00;

    length = sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER);
    iRet = DeviceIoControl(hDisk,
            IOCTL_SCSI_PASS_THROUGH_DIRECT,
            &sptdwb,
            length,
            &sptdwb,
            length,
            &bytesReturn,
            NULL);
    if (0 == iRet)  {
        printf("inquiry fail");
        return 0;
    } else {
    //Check returned data in sptdwb.sptd.DataBuffer.
    }       
    return 0;

}


SCSI covers a vast amount of ground. Are you talking to a CD/DVD/Disk/Tape/Scanner or what.

For CD/DVD the best (and only) free reference for setup/read/write commands are to be found here: http://www.t10.org/drafts.htm

Re SPTI, there is some very basic documentation in the old 'Programmers guide to SCSI'. There is an article on an ASPI -> SPTI converter that can be found on the DDJ web site.

Bear in mind that SPTI is simply an API, it imposes nor knows anything about SCSI message content or format.

  • Brian Sawert, Addison Wesley 1998.


You can send SCSI commands to the SCSI Port driver by sending it an IRP_MJ_SCSI IRP, see http://msdn.microsoft.com/en-us/library/ff565387(VS.85).aspx. However, you will have to construct the SCSI CBD yourself, and I have yet to find a document which describes it.


Anymore, the SCSI commands are broken down into a number of specs. The INQUIRY command is in the SPC spec, while device type specific commands are broken down into several specs (i.e. block, ses, ...).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号