能够区分光驱的类型么?比如CDROM、DVD还是CD-RW

http://www.jubao163.com/it/bianchengwendang/2007-06-17/14948.shtml

typedef struct _SCSI_PASS_THROUGH
{
  USHORT Length;
  UCHAR ScsiStatus;
  UCHAR PathId;
  UCHAR TargetId;
  UCHAR Lun;
  UCHAR CdbLength;
  UCHAR SenseInfoLength;
  UCHAR DataIn;
  ULONG DataTransferLength;
  ULONG TimeOutValue;
  ULONG_PTR DataBufferOffset;
  ULONG SenseInfoOffset;
  UCHAR Cdb[ 16 ];
} SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;

typedef struct _SCSI_PASS_THROUGH_WITH_BUFFERS
{
  SCSI_PASS_THROUGH Spt;
  ULONG Filler;
  UCHAR SenseBuf[ 32 ];
  UCHAR DataBuf[ 512 ];
} SCSI_PASS_THROUGH_WITH_BUFFERS, *PSCSI_PASS_THROUGH_WITH_BUFFERS;

// 判断设备是否可写 
// 返回该设备是否可写 
BOOL CanWrite( HANDLE hDevice ) // hDevice(设备句柄)
{
  SCSI_PASS_THROUGH_WITH_BUFFERS sptwb;
  UCHAR CDReader, CDwriter, DVDReader, DVDwriter;
  ULONG returned = 0;

  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 = 6;
  sptwb.Spt.SenseInfoLength = 24;
  sptwb.Spt.DataIn = 1;
  sptwb.Spt.DataTransferLength = 192;
  sptwb.Spt.TimeOutValue = 2;
  sptwb.Spt.DataBufferOffset = offsetof( SCSI_PASS_THROUGH_WITH_BUFFERS,
    DataBuf );
  sptwb.Spt.SenseInfoOffset = offsetof( SCSI_PASS_THROUGH_WITH_BUFFERS,
    SenseBuf );
  sptwb.Spt.Cdb[ 0 ] = 0x1A;
  sptwb.Spt.Cdb[ 1 ] = 0x08;
  sptwb.Spt.Cdb[ 2 ] = 0x2A;
  sptwb.Spt.Cdb[ 4 ] = 192;

  ULONG length = offsetof( SCSI_PASS_THROUGH_WITH_BUFFERS, DataBuf )
    + sptwb.Spt.DataTransferLength;

  BOOL status = DeviceIoControl( hDevice, IOCTL_SCSI_PASS_THROUGH, &sptwb,
    sizeof(SCSI_PASS_THROUGH), &sptwb, length, &returned, FALSE );

  if ( !status )
  {
    return false;
  }

  if ( sptwb.Spt.ScsiStatus )
  {
    return false;
  }
  else
  {
    if ( CDwriter = ( ( sptwb.DataBuf[ 7 ] & 0x01 )
      || ( sptwb.DataBuf[ 7 ] & 0x02 ) ) )
    {
      return true;
    }
    if ( DVDwriter = ( ( sptwb.DataBuf[ 7 ] & 0x10 )
      || ( sptwb.DataBuf[ 7 ] & 0x20 ) ) )
    {
      return true;
    }
  }
  return false;

}

 

你可能感兴趣的:(ROM)