2004-03-23 09:43:07 +03:00
#! /bin/sh
#
# scsi-devfs.sh: udev external PROGRAM script
#
# Copyright 2004 Richard Gooch <rgooch@atnf.csiro.au>
# Copyright 2004 Fujitsu Ltd.
# Distributed under the GNU Copyleft version 2.0.
#
# return devfs-names for scsi-devices
# Usage in udev.rules:
# BUS="scsi", KERNEL="sd*", PROGRAM="/etc/udev/scsi-devfs.sh sd %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
# BUS="scsi", KERNEL="sr*", PROGRAM="/etc/udev/scsi-devfs.sh sr %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
# BUS="scsi", KERNEL="st*", PROGRAM="/etc/udev/scsi-devfs.sh st %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
# BUS="scsi", KERNEL="sg*", PROGRAM="/etc/udev/scsi-devfs.sh sg %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
# Find out where sysfs is mounted. Exit if not available
[PATCH] Minor POSIX-fixes for udev
The attached patch contains a few patches against udev, to remove
use of various XSI:isms and bash:isms, and to change two scripts form
/bin/bash to /bin/sh. None of the bash-scripts in test/ uses any
bash-specific functions as far as I know, but I didn't touch them since
they aren't used runtime.
Rationale:
* Both of the /bin/bash-scripts are totally free from bashisms, hence they
don't need to be /bin/bash; using /bin/sh instead helps (mainly)
embedded-people
* local and source are bash:isms (well, they exist in several other
shells as well, but they aren't part of POSIX or any of its extensions)
* -a in tests is an XSI-extension, not part of strict POSIX, and is
easily replaced by &&
| http://www.opengroup.org/onlinepubs/009695399/utilities/test.html
* Use of fgrep is deprecated in POSIX in favour of grep -F (though fgrep
will remain in use for a long time...)
| http://www.opengroup.org/onlinepubs/009695399/utilities/grep.html
The fgrep-change isn't really necessary, since fgrep can always be
implemented as a shell-script, but the rest of the changes would really
be appreciated.
2004-08-11 12:03:03 +04:00
sysfs = ` grep -F sysfs /proc/mounts | awk '{print $2}' `
2004-03-23 09:43:07 +03:00
if [ " $sysfs " = "" ] ; then
echo "sysfs is required"
exit 1
fi
cd $sysfs /bus/scsi/devices
case " $1 " in
sd)
# Extract partition component
if [ " $3 " = "" ] ; then
lpart = "disc"
spart = ""
else
lpart = " part $3 "
spart = " p $3 "
fi
; ;
sr)
lpart = "cdrom"
spart = ""
; ;
st)
# Not supported yet
exit 1
; ;
sg)
lpart = "generic"
spart = ""
; ;
*)
exit 1
; ;
esac
# Extract SCSI logical address components
scsi_host = ` echo $2 | cut -f 1 -d:`
scsi_bus = ` echo $2 | cut -f 2 -d:`
scsi_target = ` echo $2 | cut -f 3 -d:`
scsi_lun = ` echo $2 | cut -f 4 -d:`
# Generate long and short common name parts
l_com = " bus $scsi_bus /target $scsi_target /lun $scsi_lun / $lpart "
s_com = " b ${ scsi_bus } t ${ scsi_target } u ${ scsi_lun } $spart "
# Generate long and short logical names
l_log = " scsi/host $scsi_host / $l_com "
s_log = " $1 /c ${ scsi_host } ${ s_com } "
[PATCH] Minor POSIX-fixes for udev
The attached patch contains a few patches against udev, to remove
use of various XSI:isms and bash:isms, and to change two scripts form
/bin/bash to /bin/sh. None of the bash-scripts in test/ uses any
bash-specific functions as far as I know, but I didn't touch them since
they aren't used runtime.
Rationale:
* Both of the /bin/bash-scripts are totally free from bashisms, hence they
don't need to be /bin/bash; using /bin/sh instead helps (mainly)
embedded-people
* local and source are bash:isms (well, they exist in several other
shells as well, but they aren't part of POSIX or any of its extensions)
* -a in tests is an XSI-extension, not part of strict POSIX, and is
easily replaced by &&
| http://www.opengroup.org/onlinepubs/009695399/utilities/test.html
* Use of fgrep is deprecated in POSIX in favour of grep -F (though fgrep
will remain in use for a long time...)
| http://www.opengroup.org/onlinepubs/009695399/utilities/grep.html
The fgrep-change isn't really necessary, since fgrep can always be
implemented as a shell-script, but the rest of the changes would really
be appreciated.
2004-08-11 12:03:03 +04:00
readlink $2 | grep -F -q pci
2004-03-23 09:43:07 +03:00
if [ " $? " != "0" ] ; then
# Not a PCI controller, show logical locations only
echo $l_log $s_log
exit 0
fi
# Extract PCI address
tmp = ` readlink $2 | sed -e 's@/host.*/.*@@' `
pci_addr = ` basename " $tmp " `
pci_domain = ` echo $pci_addr | cut -f 1 -d:`
pci_bus = ` echo $pci_addr | cut -f 2 -d:`
pci_slot = ` echo $pci_addr | tr . : | cut -f 3 -d:`
pci_function = ` echo $pci_addr | cut -f 2 -d.`
# Generate long and short physical names
l_pci = " domain $pci_domain /bus $pci_bus /slot $pci_slot /function $pci_function "
l_phy = " bus/pci/ $l_pci /scsi/ $l_com "
s_phy = " $1 /pci/ $pci_addr / $s_com "
echo $l_phy $s_phy $l_log $s_log