hdparm 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. set -e
  3. [ -n "$DEVNAME" ] || exit 1
  4. . /lib/hdparm/hdparm-functions
  5. if [ -e /proc/cmdline ]; then #linux only - future proofing against BSD and Hurd :)
  6. if grep -wq nohdparm /proc/cmdline ; then
  7. exit 0
  8. fi
  9. fi
  10. raidstat=OK
  11. if [ -e /proc/mdstat ]; then
  12. if egrep -iq "resync|repair|recover|check" /proc/mdstat; then
  13. raidstat=RESYNC
  14. fi
  15. elif [ -e /proc/rd/status ]; then
  16. raidstat=`cat /proc/rd/status`
  17. fi
  18. if ! [ "$raidstat" = 'OK' ]; then
  19. exit 1
  20. fi
  21. die() { echo "$*" 1>&2 ; exit 1; }
  22. OPTIONS=$(hdparm_options $DEVNAME) || die "hdparm_options failed with: $OPTIONS"
  23. apmopts=''
  24. if [ -n "$OPTIONS" ]; then
  25. for opt in $OPTIONS; do
  26. case $opt in
  27. (*'-B'*|*'-S'*|*'force_spindown_time'*)
  28. apmopts='true'
  29. ;;
  30. esac
  31. done
  32. if [ "$apmopts" = true ]; then
  33. /usr/lib/pm-utils/power.d/95hdparm-apm resume
  34. fi
  35. # strip -S (spindown) and -B (apm), force_spindown_time and -q
  36. # apm options are handled by /usr/lib/pm-utils/power.d/95hdparm-apm
  37. OPTIONS=$(echo $OPTIONS | perl -pe 's/((-S|-B|force_spindown_time)[\d]{1,3})|(-q\s?)//g')
  38. if [ -n "$OPTIONS" ]; then
  39. /sbin/hdparm -q $OPTIONS $DEVNAME 2>/dev/null
  40. fi
  41. fi
  42. exit 0