zoukankan      html  css  js  c++  java
  • 能够区分光驱的类型么?比如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;
    
    }
  • 相关阅读:
    每天一个topic----route 设置
    每周一个topic IGMP -- 2013.08.13
    HTTP API 加签名规则
    gitbook 编辑手册
    phpMyAdmin 配置文档
    扒房源线索消息推送设计
    jetty 必知必会
    回溯法解决八皇后问题
    求m行n列个方格的正方形总数
    IOC和AOP的简单实现
  • 原文地址:https://www.cnblogs.com/shangdawei/p/3163963.html
Copyright © 2011-2022 走看看