summaryrefslogtreecommitdiff
blob: e59db8f407ca703ed1a830d88b8e07a5fa6c3985 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/sbin/runscript
# METHOD
# ------
# if /dev/ide exists, find all block devices beneath it named disc, cd, or
# generic.
#
# for the disc and cd ones, if there is a a matching /dev/hdX symlink and
# hdX_args is set in the config file, use hdX_args.  otherwise, if there is a
# matching /dev/discs/discX or /dev/cdroms/cdromX symlink, and discX_args or
# cdromX_args is set in the config file, use discX_args / cdromX_args.  finally,
# if all_args is set in the config file, use that.
#
# for the generic ones, sort them and look for genericX_args in the config file
# or use all_args.
#
# if /dev/ide does not exist, check the /dev/hdX entries, and see which ones
# correspond to real devices by opening them for reading.  then check hdX_args
# and all_args in the config file.
#
# for each device considered, if no args are found in the config file, do not
# run hdparm.

depend() {
    before bootmisc
}

do_hdparm() {
    if [[ ${args:=$all_args} ]]
    then
		orgdevice=`readlink -f $device`
		if [ -b $orgdevice ]; then
	        ebegin "Running hdparm on $device"
		    hdparm $args $device > /dev/null || ewarn "Failed to run hdparm on $device"
		fi
    fi
}

start() {

    ebegin 'Starting hdparm'

    which hdparm &>/dev/null
    eend $? 'hdparm executable not found'

    if [ -e /dev/.devfsd ] || [ -e /dev/.udev ]
    then

		# devfs and udev system
        for device in $(find /dev/ide -name disc)
        do

            args=''

            for alias in /dev/hd?
            do
                if [ $alias -ef $device ]
                then
                    device=$alias
                    eval args=\${`basename $alias`_args}
                    break
                fi
            done

            [ -z "$args" ] && for alias in /dev/discs/*
            do
                if [ $alias/disc -ef $device ]
                then
                    device=$alias/disc
                    eval args=\${`basename $alias`_args}
                    break
                fi
            done

            do_hdparm

        done

        for device in $(find /dev/ide -name cd)
        do

            args=''

            for alias in /dev/hd?
            do
                if [ $alias -ef $device ]
                then
                    device=$alias
                    eval args=\${`basename $alias`_args}
                    break
                fi
            done

			[ -z $args ] && for alias in /dev/cdroms/*
            do
                if [ $alias -ef $device ]
				then
                    device=$alias
                    eval args=\${`basename $alias`_args}
                    break
                fi
            done

            do_hdparm

        done

        let count=0
        # of course, the sort approach would fail here if any of the
        # host/bus/target/lun numbers reached 2 digits..
        for device in $(find /dev/ide -name generic | sort)
        do
            eval args=\${generic${count}_args}
            do_hdparm
            let count=count+1
        done

    else

        # non-devfs system
        for device in /dev/hd?
        do
            # check that the block device really exists
            # by opening it for reading
            if [ -b $device ] && ( : <$device ) 2>/dev/null
            then
                eval args=\${`basename $device`_args}
                do_hdparm
            fi
        done

    fi
}