home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / pm-utils / sleep.d / 95hdparm-apm < prev    next >
Encoding:
Text File  |  2009-04-07  |  1.2 KB  |  51 lines

  1. #! /bin/sh
  2. #
  3. # This script adjusts hard drive APM settings using hdparm. The hardware
  4. # defaults (usually hdparm -B 128) cause excessive head load/unload cycles
  5. # on many modern hard drives. We therefore set hdparm -B 254 while on AC
  6. # power. On battery we set hdparm -B 128, because the head parking is
  7. # very useful for shock protection.
  8. #
  9. # Refactored from acpi-support's 90-hdparm.sh for pm-utils
  10.  
  11. resume_hdparm_apm()
  12. {
  13.     if [ -e /usr/sbin/laptop_mode ] ; then 
  14.         LMT_CONTROL_HD_POWERMGMT=$(. /etc/laptop-mode/laptop-mode.conf && echo "$CONTROL_HD_POWERMGMT")
  15.         if [ "$LMT_CONTROL_HD_POWERMGMT" != 0 ] \
  16.            && [ -e /var/run/laptop-mode-tools/enabled ]
  17.         then
  18.             # Laptop mode controls hdparm -B settings, we don't.
  19.             return
  20.         fi
  21.     fi
  22.  
  23.     # Determine the APM policy based on the AC state
  24.     level=254
  25.  
  26.     if [ "$(get_power_status)" = battery ]
  27.     then
  28.         level=128
  29.     fi
  30.  
  31.     for dev in /dev/sd? /dev/hd? ; do
  32.         if [ -b $dev ] ; then
  33.             # Check for APM support; discard errors since not all
  34.             # drives support HDIO_GET_IDENTITY (-i).
  35.             if hdparm -i $dev 2> /dev/null | grep -q 'AdvancedPM=yes'
  36.             then
  37.                 hdparm -B $level $dev
  38.             fi
  39.         fi
  40.     done
  41. }
  42.  
  43. case "$1" in
  44.     thaw|resume)
  45.         resume_hdparm_apm
  46.         ;;
  47.     *)
  48.         exit 254
  49.         ;;
  50. esac
  51.