]> git.ipfire.org Git - thirdparty/systemd.git/blob - extras/scsi-devfs.sh
[PATCH] volume_id fix
[thirdparty/systemd.git] / extras / scsi-devfs.sh
1 #! /bin/sh
2 #
3 # scsi-devfs.sh: udev external PROGRAM script
4 #
5 # Copyright 2004 Richard Gooch <rgooch@atnf.csiro.au>
6 # Copyright 2004 Fujitsu Ltd.
7 # Distributed under the GNU Copyleft version 2.0.
8 #
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}"
15
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"
20 exit 1
21 fi
22 cd $sysfs/bus/scsi/devices
23
24 case "$1" in
25 sd)
26 # Extract partition component
27 if [ "$3" = "" ]; then
28 lpart="disc"
29 spart=""
30 else
31 lpart="part$3"
32 spart="p$3"
33 fi
34 ;;
35 sr)
36 lpart="cdrom"
37 spart=""
38 ;;
39 st)
40 # Not supported yet
41 exit 1
42 ;;
43 sg)
44 lpart="generic"
45 spart=""
46 ;;
47 *)
48 exit 1
49 ;;
50 esac
51
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:`
57
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"
61
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}"
65
66 readlink $2 | grep -F -q pci
67 if [ "$?" != "0" ]; then
68 # Not a PCI controller, show logical locations only
69 echo $l_log $s_log
70 exit 0
71 fi
72
73 # Extract PCI address
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.`
80
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"
85
86 echo $l_phy $s_phy $l_log $s_log
87
88