mirror of the now-defunct rocklinux.org
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

100 lines
2.6 KiB

  1. #!/bin/bash
  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="/lib/udev/scsi-devfs.sh sd %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
  12. # BUS="scsi", KERNEL="sr*", PROGRAM="/lib/udev/scsi-devfs.sh sr %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
  13. # BUS="scsi", KERNEL="st*", PROGRAM="/lib/udev/scsi-devfs.sh st %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
  14. # BUS="scsi", KERNEL="sg*", PROGRAM="/lib/udev/scsi-devfs.sh sg %b %n", NAME="%c{1}", SYMLINK="%c{2} %k %c{3} %c{4}"
  15. # Find out where sysfs is mounted. Exit if not available
  16. sysfs=`grep -F sysfs /proc/mounts | awk '{print $2}'`
  17. if [ "$sysfs" = "" ]; then
  18. echo "sysfs is required"
  19. exit 1
  20. fi
  21. cd $sysfs/bus/scsi/devices
  22. case "$1" in
  23. sd)
  24. # Extract partition component
  25. if [ "$3" = "" ]; then
  26. lpart="disc"
  27. spart=""
  28. else
  29. lpart="part$3"
  30. spart="p$3"
  31. fi
  32. ;;
  33. sr)
  34. lpart="cdrom"
  35. spart=""
  36. ;;
  37. st)
  38. # Not supported yet
  39. exit 1
  40. ;;
  41. sg)
  42. lpart="generic"
  43. spart=""
  44. ;;
  45. *)
  46. exit 1
  47. ;;
  48. esac
  49. # Extract SCSI logical address components
  50. scsi_host=`echo $2 | cut -f 1 -d:`
  51. scsi_bus=`echo $2 | cut -f 2 -d:`
  52. scsi_target=`echo $2 | cut -f 3 -d:`
  53. scsi_lun=`echo $2 | cut -f 4 -d:`
  54. # Generate long and short common name parts
  55. l_com="bus$scsi_bus/target$scsi_target/lun$scsi_lun/$lpart"
  56. s_com="b${scsi_bus}t${scsi_target}u${scsi_lun}$spart"
  57. # Generate long and short logical names
  58. l_log="scsi/host$scsi_host/$l_com"
  59. s_log="$1/c${scsi_host}${s_com}"
  60. readlink $2 | grep -F -q pci
  61. if [ "$?" != "0" ]; then
  62. # Not a PCI controller, show logical locations only
  63. echo $l_log $s_log
  64. exit 0
  65. fi
  66. # Extract PCI address
  67. tmp=`readlink $2 | sed -e 's@/host.*/.*@@'`
  68. pci_addr=`basename "$tmp"`
  69. pci_domain=`echo $pci_addr | cut -f 1 -d:`
  70. pci_bus=`echo $pci_addr | cut -f 2 -d:`
  71. pci_slot=`echo $pci_addr | tr . : | cut -f 3 -d:`
  72. pci_function=`echo $pci_addr | cut -f 2 -d.`
  73. # Generate long and short physical names
  74. l_pci="domain$pci_domain/bus$pci_bus/slot$pci_slot/function$pci_function"
  75. l_phy="bus/pci/$l_pci/scsi/$l_com"
  76. s_phy="$1/pci/$pci_addr/$s_com"
  77. if [ -d /dev/discs ] ; then
  78. for x in /dev/discs/disc* ; do
  79. if readlink $x/disc | grep -q "$l_pci" ; then
  80. x=`echo $x | cut -f3 -dc` # gives the number in disc0
  81. break
  82. fi
  83. unset x
  84. done
  85. fi
  86. if [ -z "${x}" -a -d /dev/discs ] ; then
  87. x="`ls /dev/discs/ | grep -c .`"
  88. fi
  89. echo $l_log $s_log discs/disc${x}/${lpart}