home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / linuxconsole0.4.lcm / etc / hotplug / scsi.agent < prev    next >
Encoding:
Text File  |  2004-03-26  |  2.3 KB  |  116 lines

  1. #!/bin/bash
  2. #
  3. # nplanel@mandrakesoft.com
  4. #
  5. # SCSI-specific hotplug policy agent.
  6. #
  7. # This should handle 2.4.* SCSI hotplugging. (usefull with usb-storage)
  8. #
  9. # Kernel SCSI params are:
  10. #   ACTION=%s [add or remove]
  11. #   SCSI_HOST=%u
  12. #   SCSI_BUS=%u
  13. #   SCSI_TARGET=%u
  14. #   SCSI_LUN=%u
  15. #   SCSI_VENDOR=%s
  16. #   SCSI_MODEL=%s
  17. #   SCSI_REV=%s
  18. #   SCSI_TYPE=%d          [0 for direct access device, 1 for ...]
  19. #   SCSI_REMOVABLE=%d     [1 for removable, 0 for not removable]
  20. #   SCSI_EMULATED=%d      [1 implies native to another stack (emulated)]
  21. #   SCSI_ACCESS_COUNT     [number of sd, sr and sg open() active on this device]
  22. #   SCSI_WRITEABLE=%d
  23. #   SCSI_LOCKABLE=%d
  24. #   SCSI_EVENT_ATTACHED=%lu
  25. #   [ SCSI_EVENT_DETACHED=%lu when ACTION=remove  ]
  26.  
  27. cd /etc/hotplug
  28. . hotplug.functions
  29.  
  30. TYPE_DISK=0
  31. TYPE_TAPE=1          
  32. TYPE_PRINTER=2       
  33. TYPE_PROCESSOR=3      #/* HP scanners use this */
  34. TYPE_WORM=4           #/* Treated as ROM by our system */
  35. TYPE_ROM=5            
  36. TYPE_SCANNER=6        
  37. TYPE_MOD=7            #/* Magneto-optical disk - treated as TYPE_DISK */
  38.  
  39. load_module () {
  40.     MODULE=$1
  41.     if ! $(grep -q "^$MODULE " /proc/modules); then
  42.     debug_mesg "loading ... $MODULE"
  43.     if $MODPROBE -n $MODULE >/dev/null 2>&1 &&
  44.         ! $MODPROBE $MODULE >/dev/null 2>&1 ; then
  45.         mesg "... can't load module $MODULE"
  46.     fi    
  47.     else
  48.     debug_mesg "$MODULE allready loaded"
  49.     fi
  50. }
  51.  
  52. load_disk_modules () {
  53.     load_module sd_mod
  54. }
  55.  
  56. load_cdrom_modules () {
  57.     load_module sr_mod
  58. }
  59.  
  60. load_tape_modules () {
  61.     load_module st
  62. }
  63.  
  64. load_generic_modules () {
  65.     load_module sg
  66. }
  67.  
  68. #
  69. # What to do with this SCSI hotplug event?
  70. #
  71.  
  72. case $ACTION in
  73.    
  74.     add)
  75.     case $SCSI_TYPE in
  76. # Disk   
  77.         $TYPE_MOD)       #/* Magneto-optical disk - treated as TYPE_DISK */
  78.         load_disk_modules
  79.         ;;
  80.         $TYPE_DISK)
  81.         load_disk_modules
  82.         ;;
  83. # Tape
  84.         $TYPE_TAPE)
  85.         load_tape_modules
  86.         ;;
  87. # CDROM
  88.         $TYPE_WORM)      #/* Treated as ROM by our system */
  89.         load_cdrom_modules
  90.         ;;
  91.         $TYPE_ROM)            
  92.         load_cdrom_modules
  93.         ;;
  94. # Generic
  95.         $TYPE_PRINTER)       
  96.         load_generic_modules
  97.         ;;
  98.         $TYPE_PROCESSOR) #/* HP scanners use this */
  99.         load_generic_modules
  100.         ;;
  101.         $TYPE_SCANNER)      
  102.         load_generic_modules
  103.         ;;
  104.         *)
  105.         debug_mesg "Unknown type: $SCSI_TYPE"
  106.         ;;
  107.     esac
  108.     exit 0
  109.     ;;
  110.     *)
  111.     debug_mesg SCSI $ACTION event not supported
  112.     exit 1
  113.     ;;
  114. esac
  115.  
  116.