probedisk 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/sh
  2. #LGPL 2007 Puppy Linux www.puppyos.com
  3. #based on probedisk3 written by Dougal.
  4. #small mods by BK 16 june 2007
  5. # 21 Jun 2007 BK: force /proc update for usb drives.
  6. #v3.93 10 dec 2007 BK: updated for 2.6.24 kernel, no /dev/hd*.
  7. #v3.97 31jan2008 BK: refinement for detecting kernels with /dev/hd* drives.
  8. #v4.01 10may2008 BK: bugfix for detecting if usb drive.
  9. #v4.01 10may2008 BK: new 2nd-param categories. named 'probedisk2'.
  10. #v4.01 21may2008 BK: zip and ls120 now categorized as 'floppy'.
  11. #v4.02 9jun08 BK: correct detection of usb floppy.
  12. #v403 fixed excessive spaces in description field.
  13. #v406 support for old kernel, /proc/ide, /dev/hd*.
  14. #110126 no longer using SATADRIVES variable in PUPSTATE.
  15. #130201 this script no longer named 'probedisk2' (had probedisk symlink to it). now named 'probedisk'.
  16. . /etc/rc.d/PUPSTATE
  17. #110126 ATADRIVES is all ide/pata/sata drives (not usb, not optical).
  18. if [ -f /root/.usb-drive-log-probedisk ];then #force /proc upate mechanism
  19. for ONEUSBDRV in `cat /root/.usb-drive-log-probedisk | tr '\n' ' '`
  20. do
  21. #disktype /dev/$ONEUSBDRV > /dev/null 2>&1
  22. dd if=/dev/$ONEUSBDRV of=/dev/null bs=512 count=1 >/dev/null 2>&1 #v4.01 faster.
  23. done
  24. fi
  25. #mounted drives/partitions...
  26. MNTDDEVS="`mount | cut -f 1 -d ' ' | cut -f 3 -d '/' | grep -E '^hd|^sd|^scd|^sr|^mmc' | tr '\n' ' '`"
  27. #crap, right now, /sys/block does not show my hdb cd/dvd drive, but it is in
  28. #/proc/ide. pathetic kernel! oh well...
  29. if [ ! -e /proc/ide ];then #v3.97
  30. ALLDRVS="`ls -1 /sys/block | grep -E '^scd|^sd|^mmc|^sr' | tr '\n' ' '`"
  31. else
  32. ALLDRVS="`ls -1 /sys/block | grep -E '^scd|^sd|^mmc|^sr' | tr '\n' ' '``ls -1 /proc/ide | grep '^hd' | tr '\n' ' '`"
  33. fi
  34. #note: after further testing, the 2.6.21.5 kernel exhibits inconsistent behaviour for hd devices, best to avoid.
  35. for ONEDRV in $ALLDRVS
  36. do
  37. case $ONEDRV in
  38. hd*) # ide device, look in /proc/ide for info
  39. MEDIA="`cat /proc/ide/$ONEDRV/media`"
  40. [ "$MEDIA" = "disk" ] && MEDIA="drive"
  41. [ "$MEDIA" = "cdrom" ] && MEDIA="optical"
  42. INFO="`cat /proc/ide/$ONEDRV/model`"
  43. ;;
  44. sd*) # scsi devices, look in /sys/block (all appear as Direct-Access)
  45. MEDIA="drive"
  46. VENDOR="`cat /sys/block/$ONEDRV/device/vendor | tr -s ' '`"
  47. MODEL="`cat /sys/block/$ONEDRV/device/model | tr -s ' '`"
  48. INFO="$VENDOR$MODEL"
  49. DRVNAMES="$DRVNAMES `echo -n "$ONEDRV" | cut -b 1-3` "
  50. #log if usb drive (not a ata drive)... v4.01... 110126...
  51. if [ "`echo "$ATADRIVES" | grep "$ONEDRV"`" = "" ];then
  52. MEDIA="usbdrv" #v4.01
  53. echo "$ONEDRV" >> /root/.usb-drive-log-probedisk
  54. sort -u /root/.usb-drive-log-probedisk > /tmp/usb-drive-log-probedisk-tmp
  55. mv -f /tmp/usb-drive-log-probedisk-tmp /root/.usb-drive-log-probedisk
  56. #find out if a usb floppy drive...
  57. if [ -e /sys/block/${ONEDRV}/size ];then
  58. [ "`cat /sys/block/${ONEDRV}/size`" = "2880" ] && MEDIA="floppy"
  59. fi
  60. #if the floppy diskette not inserted, try this fallback test...
  61. #some examples: Vendor: NEC Model: USB UF000x Rev: 1.50, Sony USB Floppy Drive, rev 1.10/5.01,
  62. # MITUMI USB FDD, VenDor: TEAC Model: FD-05PUB, Vendor: COMPAQ Model: USB EXT FLOPPY
  63. if [ -e /sys/block/${ONEDRV}/device/model ];then
  64. [ "`grep -E ' FDD| UF000x|Floppy|USB\-FDU|^FD\-|FLOPPY' /sys/block/${ONEDRV}/device/model`" != "" ] && MEDIA="floppy"
  65. fi
  66. else
  67. #find out if it is a removable internal drive (zip, ls120, etc)...
  68. if [ -e /sys/block/${ONEDRV}/removable ];then
  69. [ "`cat /sys/block/${ONEDRV}/removable`" = "1" ] && MEDIA="floppy"
  70. fi
  71. fi
  72. ;;
  73. scd*|sr*) # scsi cdroms
  74. MEDIA="optical"
  75. VENDOR="`cat /sys/block/$ONEDRV/device/vendor | tr -s ' '`"
  76. MODEL="`cat /sys/block/$ONEDRV/device/model | tr -s ' '`"
  77. INFO="$VENDOR$MODEL"
  78. ;;
  79. mmc*) #/dev/mmcblk0
  80. MEDIA="card"
  81. INFO="MMC/SD: `cat /sys/block/$ONEDRV/device/name`"
  82. ;;
  83. *)
  84. continue
  85. ;;
  86. esac
  87. echo "/dev/$ONEDRV|$MEDIA|$INFO"
  88. done
  89. #find out if a mounted device has been unplugged...
  90. #for hotplug drives, remove it and it will disappear from /sys/block, however
  91. #still shows up in 'mount' if hasn't been unmounted.
  92. for ONEMNTD in $MNTDDEVS
  93. do
  94. case $ONEMNTD in
  95. hd*|sd*|sr*)
  96. MNTDDRVs="`echo -n "$ONEMNTD" | cut -b 1-3` "
  97. ;;
  98. scd*)
  99. MNTDDRVs="`echo -n "$ONEMNTD" | cut -b 1-4` "
  100. ;;
  101. mmc*)
  102. MNTDDRVs="`echo -n "$ONEMNTD" | cut -b 1-7` "
  103. ;;
  104. esac
  105. #prints to system log and to stderr...
  106. [ "`echo "$ALLDRVS" | grep "$MNTDDRVs"`" = "" ] && logger -s "PROBEDISK ERROR: MOUNTED UNPLUGGED $ONEMNTD"
  107. done
  108. ###END###