3 # scsi-devfs.sh: udev external PROGRAM script
5 # Copyright 2004 Richard Gooch <rgooch@atnf.csiro.au>
6 # Copyright 2004 Fujitsu Ltd.
7 # Distributed under the GNU Copyleft version 2.0.
9 # return devfs-names for scsi-devices
10 # Usage in udev.rules:
11 # BUS="scsi", KERNEL="sd*", PROGRAM="/etc/udev/scripts/scsi-devfs.sh sd %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
12 # BUS="scsi", KERNEL="sr*", PROGRAM="/etc/udev/scripts/scsi-devfs.sh sr %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
13 # BUS="scsi", KERNEL="st*", PROGRAM="/etc/udev/scripts/scsi-devfs.sh st %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
14 # BUS="scsi", KERNEL="sg*", PROGRAM="/etc/udev/scripts/scsi-devfs.sh sg %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
16 # Find out where sysfs is mounted. Exit if not available
17 sysfs=`grep -F sysfs /proc/mounts | awk '{print $2}'`
18 if [ "$sysfs" = "" ]; then
19 echo "sysfs is required"
22 cd $sysfs/bus/scsi/devices
26 # Extract partition component
27 if [ "$3" = "" ]; then
52 # Extract SCSI logical address components
53 scsi_host=`echo $2 | cut -f 1 -d:`
54 scsi_bus=`echo $2 | cut -f 2 -d:`
55 scsi_target=`echo $2 | cut -f 3 -d:`
56 scsi_lun=`echo $2 | cut -f 4 -d:`
58 # Generate long and short common name parts
59 l_com="bus$scsi_bus/target$scsi_target/lun$scsi_lun/$lpart"
60 s_com="b${scsi_bus}t${scsi_target}u${scsi_lun}$spart"
62 # Generate long and short logical names
63 l_log="scsi/host$scsi_host/$l_com"
64 s_log="$1/c${scsi_host}${s_com}"
66 readlink $2 | grep -F -q pci
67 if [ "$?" != "0" ]; then
68 # Not a PCI controller, show logical locations only
74 tmp=`readlink $2 | sed -e 's@/host.*/.*@@'`
75 pci_addr=`basename "$tmp"`
76 pci_domain=`echo $pci_addr | cut -f 1 -d:`
77 pci_bus=`echo $pci_addr | cut -f 2 -d:`
78 pci_slot=`echo $pci_addr | tr . : | cut -f 3 -d:`
79 pci_function=`echo $pci_addr | cut -f 2 -d.`
81 # Generate long and short physical names
82 l_pci="domain$pci_domain/bus$pci_bus/slot$pci_slot/function$pci_function"
83 l_phy="bus/pci/$l_pci/scsi/$l_com"
84 s_phy="$1/pci/$pci_addr/$s_com"
86 echo $l_phy $s_phy $l_log $s_log