#------------------------------------------------------------------------------
# /etc/rc.d/rc.hdsleep - change modes for ide-harddisks
#
# Creation:	    24.09.2003 hs
# Last Update:  $Id: rc020.hdsleep 9870 2005-09-30 21:45:19Z lanspezi $
#------------------------------------------------------------------------------

if [ "$OPT_HDSLEEP" = "yes" ]
then
    begin_script HDSLEEP

    # calculate sleeptime-parameter
    if [ "$HDSLEEP_TIMEOUT" -ge 300 ]
    then
        colecho "a timeout above five hours is not supported, changed to five hours" br x br
        sleep 5
        sleep=250
    elif [ "$HDSLEEP_TIMEOUT" -gt 20 ]
    then
        time=`expr $HDSLEEP_TIMEOUT - 1`
        sleep=`expr $time / 30 + 241`
    else
        sleep=`expr $HDSLEEP_TIMEOUT \* 60 / 5`     
    fi

    for device in hda hdb hdc hdd
    do
        devicetyp="`cat /proc/ide/$device/media`"
        if [ "$devicetyp" = "disk" ]
        then
            flashmedia="`hdparm -i /dev/$device | grep nonMagnetic`"
            if [ "$flashmedia" = "" ]
            then
                hdparm -S $sleep /dev/$device
                if [ "$?" != "0" ]
                then
                    colecho "ERROR: Disk $device does not support your HDTUNE-Settings " br x br
                    sleep 10
                fi
            else
                colecho "WARNING: Disk $device is not a harddisk, Operation not supported" br x br
            fi
        elif [ "$devicetyp" = "cdrom" ]
        then
            hdparm -S $sleep /dev/$device
            if [ "$?" != "0" ]
            then
                colecho "ERROR: Disk $device does not support your HDTUNE-Settings " br x br
                sleep 10
            fi
        fi
    done
    end_script
fi



