home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / etc / init.d / hdparm < prev    next >
Encoding:
Text File  |  2005-04-21  |  5.0 KB  |  278 lines

  1. #!/bin/sh
  2.  
  3. set -e
  4.  
  5. . /lib/lsb/init-functions
  6. . /etc/default/rcS
  7.  
  8. #In certian cases you may wish to run this script twice.  Once at S07
  9. #and once later in the boot process. If you do this call /etc/init.d/hdparm
  10. #again from rcS.d with a name such as S27hdparm.second.
  11. #
  12. #See /usr/share/doc/hdparm/README.Debian for more details.
  13.  
  14. case "$0" in
  15.   *hdparm)
  16.     FIRST=yes
  17.     ;;
  18.   *)
  19.     FIRST=no
  20.     ;;
  21. esac
  22.  
  23. MYNAME="$0"
  24.  
  25. report()
  26. {
  27.   echo "${MYNAME}: $*"
  28. }
  29.  
  30. report_error()
  31. {
  32.   echo "${MYNAME}: Error: $*" >&2
  33. }
  34.  
  35. report_error_and_exit()
  36. {
  37.   report_error "$*.  Exiting."
  38.   exit 1
  39. }
  40.  
  41. case $1 in
  42.   start|restart|reload|force-reload)
  43.     ;;
  44.   stop) 
  45.     exit 0
  46.     ;;
  47.   *)
  48.     log_success_msg "Usage: $0 {stop|start|restart|reload|force-reload}"
  49.     exit 1
  50.     ;;
  51. esac
  52.  
  53. if grep -w -q "nohdparm" /proc/cmdline ; then
  54.   log_success_msg "Skipping setup of disc parameters as specified..."
  55.   exit 0
  56. fi
  57.  
  58. raidstat=OK
  59. if [ -e /proc/mdstat ]; then
  60.   if grep -iq resync /proc/mdstat; then
  61.     raidstat=RESYNC
  62.   fi
  63. elif [ -e /proc/rd/status ]; then
  64.   raidstat=`cat /proc/rd/status`
  65. fi
  66.  
  67. if ! [ "$raidstat" = 'OK' ]; then
  68.   log_warning_msg "RAID status not OK.  Exiting."
  69.   exit 0
  70. fi
  71.  
  72. log_begin_msg "Setting disc parameters..."
  73.  
  74. DISC=
  75. DEFAULT=
  76. OPTIONS=
  77. DEF_QUIET=
  78. OPT_QUIET=
  79.  
  80. #  set_option() adds $1 to the $OPTIONS list if in a disk stanza
  81. #             and adds $1 to the $DEFAULT list if not in a disk stanza
  82. #
  83. #  the block beginning:
  84. #        if test x${i%${i#??}} != x${1%${1#??}}; then
  85. #  checks to see if $1 is already in the list and
  86. #    if so removes the first instance
  87.  
  88. set_option() 
  89. {
  90.   if test -n "$DISC"; then
  91.     NEW_OPT=
  92.     for i in $OPTIONS; do
  93.       if test x${i%${i#??}} != x${1%${1#??}}; then
  94.         NEW_OPT="$NEW_OPT $i"
  95.       else
  96.         NEW_OPT=${NEW_OPT%-q}
  97.       fi
  98.     done
  99.     OPTIONS="$NEW_OPT $OPT_QUIET $1"
  100.   else
  101.     NEW_DEF=
  102.     for i in $DEFAULT; do
  103.       if test x${i%${i#??}} != x${1%${1#??}}; then
  104.         NEW_DEF="$NEW_DEF $i"
  105.       else
  106.         NEW_DEF=${NEW_DEF%-q}
  107.       fi
  108.     done
  109.     DEFAULT="$NEW_DEF $DEF_QUIET $1"
  110.   fi
  111. }
  112.  
  113. eval_value() 
  114. {
  115.   case $1 in
  116.     off|0) 
  117.       set_option "$2"0
  118.        ;;
  119.     on|1) 
  120.       set_option "$2"1
  121.       ;;
  122.     *) 
  123.       return 1
  124.       ;;
  125.   esac
  126. }
  127.  
  128. # Get blocks as far as the drive's write cache.
  129. /bin/sync
  130.  
  131. # Set options for a group of disks in /etc/default/hdparm
  132. [ -e /etc/default/hdparm ] && . /etc/default/hdparm
  133.  
  134. if [ -n "$harddisks" -a -n "$hdparm_opts" ]; then
  135.   for drive in $harddisks; do 
  136.     /sbin/hdparm -q -f $drive
  137.     hdparm -q $hdparm_opts -q $drive
  138.     [ "$VERBOSE" != no ] && log_success_msg "Found enabled disk: $drive"
  139.   done
  140. fi
  141.  
  142. egrep -v '^[[:space:]]*(#|$)' /etc/hdparm.conf | while read KEY SEP VALUE; do
  143.  if [ "$NEXT_LINE" != 'go' ]; then
  144.   case $SEP in
  145.     '{')
  146.        case $KEY in
  147.          command_line)
  148.            NEXT_LINE=go
  149.            unset DISC
  150.            unset OPTIONS
  151.            unset OPT_QUIET
  152.            ;;
  153.          *)
  154.            DISC=$KEY
  155.            OPTIONS=$DEFAULT
  156.            OPT_QUIET=$DEF_QUIET
  157.            WAS_RUN=0
  158.            ;;
  159.        esac
  160.        ;;
  161.     =)
  162.        case $KEY in
  163.          read_ahead_sect) 
  164.        set_option -a$VALUE
  165.        ;;
  166.      lookahead) 
  167.        eval_value $VALUE -A
  168.        ;;
  169.      bus) 
  170.        eval_value $VALUE -b
  171.        ;;
  172.      apm) 
  173.        set_option -B$VALUE
  174.        ;;
  175.      io32_support) 
  176.        set_option -c$VALUE
  177.        ;;
  178.      dma) 
  179.        eval_value $VALUE -d
  180.        ;;
  181.      defect_mana) 
  182.        eval_value $VALUE -D
  183.        ;;
  184.      cd_speed) 
  185.        set_option -E$VALUE
  186.        ;;
  187.      mult_sect_io) 
  188.        set_option -m$VALUE
  189.        ;;
  190.      prefetch_sect) 
  191.        set_option -P$VALUE
  192.        ;;
  193.      read_only) 
  194.        eval_value $VALUE -r
  195.        ;;
  196.      spindown_time) 
  197.        set_option -S$VALUE
  198.        ;;
  199.      interrupt_unmask) 
  200.        eval_value $VALUE -u
  201.        ;;
  202.      write_cache) 
  203.        eval_value $VALUE -W
  204.        ;;
  205.      transfer_mode) 
  206.        set_option -X$VALUE
  207.        ;;
  208.      acoustic_management)
  209.        set_option -M$VALUE
  210.        ;;
  211.          keep_settings_over_reset)
  212.            eval_value $VALUE -k
  213.           ;;
  214.          keep_features_over_reset)
  215.            eval_value $VALUE -K
  216.           ;;
  217.          chipset_pio_mode)
  218.            set_option -p$VALUE
  219.           ;;
  220.      *)
  221.        log_failure_msg "Unknown option $KEY!"
  222.        exit 1
  223.        ;;
  224.        esac
  225.     ;;
  226.     "")
  227.        case $KEY in
  228.          })
  229.        if [ -z "$DISC" ]; then
  230.              if [ "$WAS_RUN" != 1 ]; then
  231.            log_failure_msg "No disk enabled. Exiting..."
  232.            exit 1
  233.              fi
  234.        fi
  235.        if [ -n "$OPTIONS" ]; then
  236.          # Flush the drive's internal write cache to the disk.
  237.          /sbin/hdparm -q -f $DISC
  238.  
  239.          /sbin/hdparm $OPTIONS $DISC
  240.          [ "$VERBOSE" != no ] && log_success_msg "Found enabled disk: $DISC"
  241.        fi       
  242.            ;;
  243.          quiet)
  244.        if [ -n "$DISC" ]; then
  245.          OPT_QUIET=-q
  246.        else
  247.          DEF_QUIET=-q
  248.        fi
  249.            ;;
  250.          standby) 
  251.            set_option -y
  252.        ;;
  253.          sleep) 
  254.            set_option -Y
  255.        ;;
  256.          disable_seagate) 
  257.            set_option -Z
  258.        ;;
  259.          *)
  260.        log_failure_msg "Unknown option $KEY!"
  261.        exit 1
  262.        ;;
  263.        esac
  264.        ;;
  265.    *)
  266.      log_failure_msg "Unknown separator $SEP!"
  267.      exit 1
  268.      ;;
  269.   esac
  270. else
  271.   $KEY $SEP $VALUE
  272.   NEXT_LINE=no-go
  273.   WAS_RUN=1
  274. fi
  275. done
  276.  
  277. log_end_msg 0
  278.