⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 skscsi.pas

📁 用于CD/DVD烧录的Delphi源码,包括source和demo
💻 PAS
📖 第 1 页 / 共 3 页
字号:
{==============================================================================|
| SCSI Header for ASPI, ASAPI and SPTI/IOCTL                                   |
|==============================================================================|
|                                                                              |
| Author: Kalman Speier                                                        |
|   Mail: mail@speier.hu                                                       |
|   Home: www.speier.hu                                                        |
|  Legal: Copyright (c) 2002-2005 Speier Software                              |
|         All Rights Reserved                                                  |
|                                                                              |
|==============================================================================|
|                                                                              |
| Definitions:                                                                 |
|   SCSI = Small Computer System Interface                                     |
|   ASPI = Advanced SCSI Programming Interface (Developed by Adaptec)          |
|  ASAPI = Advanced ASPI Programming Interface (Developed by VOB/Pinnacle)     |
|   SPTI = SCSI Passthrough Interface (MS Replacement of ASPI on NT/2k/XP/2k3) |
|  IOCTL = Device Input/Output Control (WinAPI Command is DeviceIOControl)     |
|                                                                              |
|==============================================================================|
|                                                                              |
| Used Sources and Docs:                                                       |
|  Adaptec Software Developer's Kit (SDK) v2.4                                 |
|  SPC & MMC Drafts from T10.org (www.t10.org)                                 |
|  ASPI & SCSI Programming by Alvise Valsecchi (www.hochfeiler.it/alvise)      |
|                                                                              |
| Thanx to:                                                                    |
|  daNIL for WNASPI32 & SCSIDEFS 'C' Headers Translation (Project Jedi)        |
|  Sergey "KSER" Kabikov for his Delphi ASPI Library                           |
|  Farshid Mossaiby for ASPI Spy                                               |
|  Jay A. Key for AKRip                                                        |
|  Additional programming by Dancemammal                                       |
|==============================================================================}

unit skSCSI;

interface

uses
  Windows,
  SysUtils;

const
  {****************************************************************************}
  {  ASPI COMMAND CONSTANTS                                                    }
  {****************************************************************************}
  SENSE_LEN = 14; // Default sense buffer length
  SRB_DIR_SCSI = $00; // Direction determined by SCSI command
  SRB_DIR_IN = $08; // Transfer from SCSI target to host
  SRB_DIR_OUT = $10; // Transfer from host to SCSI target
  SRB_POSTING = $01; // Enable ASPI posting
  SRB_EVENT_NOTIFY = $40; // Enable ASPI event notification
  SRB_ENABLE_RESIDUAL_COUNT = $04; // Enable residual byte count reporting
  SRB_DATA_SG_LIST = $02; // Data buffer points to scatter-gather list
  WM_ASPIPOST = $4D42; // ASPI Post message
  DTYPE_CDROM = $05; // CD-ROM device type
  DTYPE_UNKNOWN = $1F; // Unknown or no device type

  {****************************************************************************}
  {  ASPI COMMAND DEFINITIONS                                                  }
  {****************************************************************************}
  SC_HA_INQUIRY = $00; // Host adapter inquiry
  SC_GET_DEV_TYPE = $01; // Get device type
  SC_EXEC_SCSI_CMD = $02; // Execute SCSI command
  SC_ABORT_SRB = $03; // Abort an SRB
  SC_RESET_DEV = $04; // SCSI bus device reset
  SC_GET_DISK_INFO = $06; // Get Disk information
  SC_SCSI_INQUIRY = $12; // SCSI inquiry

  {****************************************************************************}
  {  SRB STATUS                                                                }
  {****************************************************************************}
  SS_PENDING = $00; // SRB being processed
  SS_COMP = $01; // SRB completed without error
  SS_ABORTED = $02; // SRB aborted
  SS_ABORT_FAIL = $03; // Unable to abort SRB
  SS_ERR = $04; // SRB completed with error
  SS_INVALID_CMD = $80; // Invalid ASPI command
  SS_INVALID_HA = $81; // Invalid host adapter number
  SS_NO_DEVICE = $82; // SCSI device not installed
  SS_INVALID_SRB = $E0; // Invalid parameter set in SRB
  SS_FAILED_INIT = $E4; // ASPI for windows failed init
  SS_ASPI_IS_BUSY = $E5; // No resources available to execute cmd
  SS_BUFFER_TO_BIG = $E6; // Buffer size to big to handle!
  SS_NO_ADAPTERS = $E8; // No host adapters to manage

  {****************************************************************************}
  {  HOST ADAPTER STATUS                                                       }
  {****************************************************************************}
  HASTAT_OK = $00; // Host adapter did not detect an error
  HASTAT_SEL_TO = $11; // Selection Timeout
  HASTAT_DO_DU = $12; // Data overrun data underrun
  HASTAT_BUS_FREE = $13; // Unexpected bus free
  HASTAT_PHASE_ERR = $14; // Target bus phase sequence failure
  HASTAT_TIMEOUT = $09; // Timed out while SRB was waiting to be processed
  HASTAT_COMMAND_TIMEOUT = $0B;
  // While processing the SRB, the adapter is timed out
  HASTAT_MESSAGE_REJECT = $0D;
  // While processing SRB, the adapter received a MESSAGE REJECT
  HASTAT_BUS_RESET = $0E; // A bus reset was detected
  HASTAT_PARITY_ERROR = $0F; // A parity error was detected
  HASTAT_REQUEST_SENSE_FAILED = $10;
  // The adapter failed in issuing REQUEST SENSE

type
  TCDB = array[0..15] of Byte; // SCSI Command Descriptor Block (Max 16 bytes)

type
  {****************************************************************************}
  {  HOST ADAPTER INQUIRY - SC_HA_INQUIRY                                      }
  {****************************************************************************}
  TSRB_HAInquiry = packed record
    Cmd, // ASPI command code = SC_HA_INQUIRY
    Status, // ASPI command status byte
    HaId, // ASPI host adapter number
    Flags: BYTE; // ASPI request flags
    Hdr_Rsvd: DWORD; // Reserved, MUST = 0
    HA_Count, // Number of host adapters present
    HA_SCSI_ID: BYTE; // SCSI ID of host adapter
    HA_ManagerId, // String describing the manager
    HA_Identifier, // String describing the host adapter
    HA_Unique: array[0..15] of CHAR; // Host Adapter Unique parameters
    HA_Rsvd1: WORD;
  end;
  PSRB_HAInquiry = ^TSRB_HAInquiry;

  {****************************************************************************}
  {  GET DEVICE TYPE - SC_GET_DEV_TYPE                                         }
  {****************************************************************************}
  TSRB_GDEVBlock = packed record
    Cmd, // ASPI command code = SC_GET_DEV_TYPE
    Status, // ASPI command status byte
    HaId, // ASPI host adapter number
    Flags: BYTE; // Reserved
    Hdr_Rsvd: DWORD; // Reserved
    Target, // Target's SCSI ID
    Lun, // Target's LUN number
    DeviceType, // Target's peripheral device type
    Rsvd1: BYTE;
  end;
  PSRB_GDEVBlock = ^TSRB_GDEVBlock;

  {****************************************************************************}
  {  REQUES SENSE DATA FORMAT                                                  }
  {****************************************************************************}
  TSenseArea = packed record
    ErrorCode,
      SegmentNum,
      SenseKey,
      InfoByte0,
      InfoByte1,
      InfoByte2,
      InfoByte3,
      AddSenLen,
      ComSpecInf0,
      ComSpecInf1,
      ComSpecInf2,
      ComSpecInf3,
      AddSenseCode,
      AddSenQual,
      FieldRepUCode,
      SenKeySpec15,
      SenKeySpec16,
      SenKeySpec17: Byte;
    AddSenseBytes: array[18..$20] of Byte;
  end;

  {****************************************************************************}
  {  EXECUTE SCSI COMMAND - SC_EXEC_SCSI_CMD                                   }
  {****************************************************************************}
  TSRB_ExecSCSICmd = packed record
    Cmd, // ASPI command code = SC_EXEC_SCSI_CMD
    Status, // ASPI command status byte
    HaId, // ASPI host adapter number
    Flags: BYTE; // ASPI request flags
    Hdr_Rsvd: DWORD; // Reserved
    Target, // Target's SCSI ID
    Lun: BYTE; // Target's LUN number
    Rsvd1: WORD; // Reserved for Alignment
    BufLen: DWORD; // Data Allocation Length
    BufPointer: PCHAR; // Data Buffer Pointer
    SenseLen, // Sense Allocation Length
    CDBLen, // CDB Length
    HaStat, // Host Adapter Status
    TargStat: BYTE; // Target Status
    PostProc: THANDLE; // Post routine
    Rsvd2: POINTER; // Reserved
    Rsvd3, // Reserved for alignment
    CDBByte: TCDB; // SCSI CDB
    SenseArea: TSenseArea; // Request Sense buffer
  end;
  PSRB_ExecSCSICmd = ^TSRB_ExecSCSICmd;

  {****************************************************************************}
  {  ABORT AN SRB - SC_ABORT_SRB                                               }
  {****************************************************************************}
  TSRB_Abort = packed record
    Cmd, // ASPI command code = SC_EXEC_SCSI_CMD
    Status, // ASPI command status byte
    HaId, // ASPI host adapter number
    Flags: BYTE; // Reserved
    Hdr_Rsvd: DWORD; // Reserved
    ToAbort: POINTER; // Pointer to SRB to abort
  end;

  {****************************************************************************}
  {  BUS DEVICE RESET - SC_RESET_DEV                                           }
  {****************************************************************************}
  TSRB_BusDeviceReset = packed record
    Cmd, // ASPI command code = SC_EXEC_SCSI_CMD
    Status, // ASPI command status byte
    HaId, // ASPI host adapter number
    Flags: BYTE; // Reserved
    Hdr_Rsvd: DWORD; // Reserved
    Target, // Target's SCSI ID
    Lun: BYTE; // Target's LUN number
    Rsvd1: array[0..11] of BYTE; // Reserved for Alignment
    HaStat, // Host Adapter Status
    TargStat: BYTE; // Target Status
    PostProc: THANDLE; // Post routine
    Rsvd2: POINTER; // Reserved
    Rsvd3, // Reserved
    CDBByte: array[0..15] of BYTE; // SCSI CDB
  end;

  {****************************************************************************}
  {  GET DISK INFORMATION - SC_GET_DISK_INFO                                   }
  {****************************************************************************}
  TSRB_GetDiskInfo = packed record
    Cmd, // ASPI command code = SC_EXEC_SCSI_CMD
    Status, // ASPI command status byte
    HaId, // ASPI host adapter number
    Flags: BYTE; // Reserved
    Hdr_Rsvd: DWORD; // Reserved
    Target, // Target's SCSI ID
    Lun, // Target's LUN number
    DriveFlags, // Driver flags
    Int13HDriveInfo, // Host Adapter Status
    Heads, // Preferred number of heads translation
    Sectors: BYTE; // Preferred number of sectors translation
    Rsvd1: array[0..9] of BYTE; // Reserved
  end;
  PSRB_GetDiskInfo = ^TSRB_GetDiskInfo;

const
  {****************************************************************************}
  {  SPTI/IOCTL CONSTANTS                                                      }
  {****************************************************************************}

  (* method codes *)
  METHOD_BUFFERED = 0;
  METHOD_IN_DIRECT = 1;
  METHOD_OUT_DIRECT = 2;
  METHOD_NEITHER = 3;

  (* file access values *)
  FILE_ANY_ACCESS = 0;
  FILE_READ_ACCESS = $0001;
  FILE_WRITE_ACCESS = $0002;
  IOCTL_CDROM_BASE = $00000002;
  IOCTL_SCSI_BASE = $00000004;

  (* constants for DataIn member of SCSI_PASS_THROUGH structures *)
  SCSI_IOCTL_DATA_OUT = 0;
  SCSI_IOCTL_DATA_IN = 1;
  SCSI_IOCTL_DATA_UNSPECIFIED = 2;

  (* standard IOCTL codes *)
  IOCTL_CDROM_READ_TOC = $24000;
  IOCTL_CDROM_GET_LAST_SESSION = $24038;
  IOCTL_SCSI_PASS_THROUGH = $4D004;
  IOCTL_SCSI_MINIPORT = $4D008;
  IOCTL_SCSI_GET_INQUIRY_DATA = $4100C;
  IOCTL_SCSI_GET_CAPABILITIES = $41010;
  IOCTL_SCSI_PASS_THROUGH_DIRECT = $4D014;
  IOCTL_SCSI_GET_ADDRESS = $41018;

type
  {****************************************************************************}
  {  STRUCT DEFINITIONS FOR SPTI                                               }
  {****************************************************************************}
  SCSI_PASS_THROUGH = record
    Length: Word;
    SCSIStatus: Byte;
    PathId: Byte;
    Target: Byte;
    Lun: Byte;
    CDBLength: Byte;
    SenseInfoLength: Byte;
    DataIn: Byte;
    DataTransferLength: ULONG;
    TimeOutValue: ULONG;
    DataBufferOffset: ULONG;
    SenseInfoOffset: ULONG;
    CDB: array[0..16 - 1] of Byte;
  end;
  PSCSI_PASS_THROUGH = ^SCSI_PASS_THROUGH;

  PVOID = Pointer;

  SCSI_PASS_THROUGH_DIRECT = record
    Length: Word;
    SCSIStatus: Byte;
    PathID: Byte;
    Target: Byte;
    Lun: Byte;
    CDBLength: Byte;
    SenseInfoLength: Byte;
    DataIn: Byte;
    DataTransferLength: ULONG;
    TimeOutValue: ULONG;
    DataBuffer: PVOID;
    SenseInfoOffset: ULONG;
    CDB: array[0..16 - 1] of Byte;
  end;
  PSCSI_PASS_THROUGH_DIRECT = ^SCSI_PASS_THROUGH_DIRECT;

  SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER = record
    SPT: SCSI_PASS_THROUGH_DIRECT;
    Filler: ULONG;
    ucSenseBuf: array[0..32 - 1] of Byte;
  end;
  PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER = ^SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;

  TSCSIDRIVE = record
    HA, Target, Lun,
      Letter: Byte;
    Used: Boolean;
    DeviceHandle: THANDLE;
    inqData: array[0..64] of Char;
  end;

  TSCSIDRIVES = record
    numAdapters: Byte;
    Drive: array[0..26] of TSCSIDRIVE;
  end;

  (* SCSI ADDRESS HA/TargetID/Lun *)
  SCSI_ADDRESS = record
    Length: LongInt;
    HA: Byte;
    PathID: Byte;
    Target: Byte;
    Lun: Byte;
  end;
  PSCSI_ADDRESS = ^SCSI_ADDRESS;

type
  {****************************************************************************}
  {  VERSION INFO CLASS                                                        }
  {****************************************************************************}
  TVersionInfo = class

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -