"Fossies" - the Fresh Open Source Software Archive

Member "hdparm-9.65/debian/20hdparm" (12 Oct 2016, 2265 Bytes) of package /linux/misc/hdparm-9.65.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 #!/bin/sh
    2 
    3 # Copyright (c) 2000-2002 Massachusetts Institute of Technology
    4 #
    5 # This program is free software; you can redistribute it and/or modify
    6 # it under the terms of the GNU General Public License as published by
    7 # the Free Software Foundation; either version 2 of the License, or (at
    8 # your option) any later version.
    9 #
   10 # This program is distributed in the hope that it will be useful, but
   11 # WITHOUT ANY WARRANTY; without even the implied warranty of
   12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   13 # General Public License for more details.
   14 #
   15 # You should have received a copy of the GNU General Public License
   16 # along with this program; if not, write to the Free Software
   17 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
   18 # 02111-1307, USA.
   19 
   20 set -e
   21 
   22 # The APMD_DRIVES setting specifies the drives to be changed.  Set
   23 # this to an empty string to disable any changes.
   24 #APMD_DRIVES=
   25 
   26 # The spindown timeout is set to the value of APMD_SPINDOWN when the
   27 # computer is running on battery power.  When the computer is on AC
   28 # power, the spindown timeout is disabled.  The number specified here
   29 # is encoded in a complicated way.  See the man page for hdparm(8) for
   30 # details.  For small timeouts, numbers between 1 and 240 specify
   31 # multiples of 5 seconds.  So the default value of 18 means 18*5=90
   32 # seconds, or 1.5 minutes.
   33 APMD_SPINDOWN=18
   34 
   35 HDPARM=/sbin/hdparm
   36 [ -x "${HDPARM}" ] || exit 0
   37 
   38 [ -n "${APMD_DRIVES}" ] || exit 0
   39 
   40 for DRIVE in $APMD_DRIVES; do
   41   [ -b "${DRIVE}" ] || exit 0
   42 done
   43 
   44 [ "${APMD_SPINDOWN}" -gt 0 ] || exit 0
   45 
   46 power_conserve ()
   47 {
   48     # Set IDE hard disk spindown time to a short time.
   49     for DRIVE in $APMD_DRIVES; do
   50       "${HDPARM}" -q -S "${APMD_SPINDOWN}" "${DRIVE}" || true
   51     done
   52 }
   53 
   54 power_performance ()
   55 {
   56     # Disable IDE hard disk spindown.
   57     for DRIVE in $APMD_DRIVES; do
   58       "${HDPARM}" -q -S 0 "${DRIVE}" || true
   59     done
   60 }
   61 
   62 choose_power ()
   63 {
   64     if on_ac_power > /dev/null
   65     then
   66     power_performance
   67     else
   68     power_conserve
   69     fi
   70 }
   71 
   72 if [ "${1}" = "start" ]; then
   73     choose_power
   74 elif [ "${1}" = "resume" ] && [ "${2}" != "standby" ]; then
   75     choose_power
   76 elif [ "${1},${2}" = "change,power" ]; then
   77     choose_power
   78 elif [ "${1}" = "stop" ]; then
   79     power_performance
   80 fi
   81 
   82 exit 0