2013年4月1日星期一

General SCSI addressing


scsibus/target/lun



LUN是英文 Logical unit number的缩写,即逻辑单元号

16位宽的SCSI总线,其寻址范围只有16个,即只能挂载16个外围设备,每个设备称为一个target


Linux has a four level hierarchical addressing scheme for SCSI devices:
  • SCSI adapter number [host]
  • channel number [bus]
  • id number [target]
  • lun [lun]



在SCSI术语里,HBA称为“initiator“,占用一个SCSI id号(绝大部分是7,如果不是,改为7)

scsi设备地址映射
SCSI adapter number [host]
host说的是适配卡在计算机内部IO总线的位置(比如PCI,PCMCIA,ISA等),适配器也称为HBA,其编号由内核以0开始的升序分配。
host id,也就是scsi适配器的id,可以认为就是scsi适配器的序号。顺序一般情况下和通过lspci列出来scsi适配器的顺序是一致的

channel number [bus]
一个HBA可能控制一个或者多个SCSI总线
channel id,对应不同的scsi总线类型。一个scsi适配器可以支持多种不同的总线类型,连接不同的scsi设备

id number [target]
每一个SCSI总线可以有多个SCSI设备连接在上面。

lun [lun]
每一个SCSI设备本身(绝大部分情况下说的是虚拟存储,比如RAID)能够包含多个LUN


Ntddscsi.h
IOCTL_SCSI_GET_ADDRESS
Returns the address information, such as the target ID (TID) and the logical unit number (LUN) of a particular SCSI target

typedef struct _SCSI_ADDRESS {
  ULONG Length;      结构体的大小
  UCHAR PortNumber;  Contains the number of the SCSI adapter
  UCHAR PathId;      Contains the number of the bus.
  UCHAR TargetId;
  UCHAR Lun;
} SCSI_ADDRESS, *PSCSI_ADDRESS;
#define MAX_SCG  64 /* Max # of SCSI controllers */
#define MAX_TGT  16 /* Max # of SCSI Targets */
#define MAX_LUN  8 /* Max # of SCSI LUNs  */
typedef struct {
 BYTE ha;   /* SCSI Bus #   */
 BYTE tgt;   /* SCSI Target #  */
 BYTE lun;   /* SCSI Lun #   */
 BYTE PortNumber;  /* SCSI Card # (\\.\SCSI%d) */
 BYTE PathId;   /* SCSI Bus/Channel # on card n */
 BYTE driveLetter;  /* Win32 drive letter (e.g. c:) */
 BOOL bUsed;   /* Win32 drive letter is used */
 HANDLE hDevice;  /* Win32 handle for ioctl() */
 BYTE inqData[NTSCSI_HA_INQUIRY_SIZE];
} DRIVE;

  BOOL rt = DeviceIoControl(
   device, IOCTL_SCSI_GET_ADDRESS,
   NULL, 0, &s_add, sizeof(s_add),
   &rtBytes, NULL);
it does not work for USB CD-RW
I don't know how to 
map 
USB/Firewire CD-RW drive's driver letter (e.g. E:) to 
SCSI bus/target/lun 
because USB/Firewire CD-RW has nothing to do with SCSI.


support USB/FIREWIRE devices where this call is not supported assign drive letter as device ID


HANDLE device = CreateFile(L"\\\\.\\c:", 0, FILE_SHARE_READ | FILE_SHARE_WRITE,
                      0, OPEN_EXISTING, 0, NULL);
The "\\.\" prefix will access the Win32 device namespace instead of the Win32 file namespace.  例如:
\\.\COM56   \\.\SCSI1


 * Universal function to get a file handle to the CD device.  Since
 * NT 4.0 wants just the GENERIC_READ flag, and Win2K wants both
 * GENERIC_READ and GENERIC_WRITE (why a read-only CD device needs
 * GENERIC_WRITE access is beyond me...), the easist workaround is to just
 * try them both.


--------------------------------------------------------------------------
SCSI总线-任何实现了ANSI的SCSI标准的并行(多信号)I/O总线。wide SCSI总线可以连接16个发起者和目标。narrow SCSI总线可以连接8个发起者和目标。

没有评论:

发表评论