-
Notifications
You must be signed in to change notification settings - Fork 4
/
disk-functions
88 lines (82 loc) · 1.32 KB
/
disk-functions
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
#
# disk-functions
#
PROFILES='bat adp dyn quiet'
PROFILE_DEFAULT=adp
ata()
{
echo /sys/devices/pci*/*/ata*/host*/target*/*/block/*sd[a-z]
}
usb()
{
local arg dev val
for dev in /sys/devices/pci*/*/usb*/*/*/host*/target*/*/block/*sd[a-z]; do
read val <${dev}/removable
case "${val}" in
(1) echo noop >${dev}/queue/scheduler;;
(0)
for arg in bfq cfq; do
if grep -qws "${arg}" ${dev}/queue/scheduler; then
echo "${arg}" >${dev}/queue/scheduler
break
fi
done
;;
esac
done
}
disk()
{
usb
local dev
for dev in $(ata); do
hdparm -q -S${1:-0} -B${2:-254} /dev/${dev##*/} >${NULL} 2>&1
done
}
start_test()
{
local file=/sys/class/power_supply/AC0/online state
if [ ! -r ${file} ]; then
echo "adp"
return 0
fi
read state <${file}
case "${state}" in
(0) printf "bat";;
(*) printf "adp";;
esac
}
start_post()
{
local arg dev
for dev in $(ata); do
for arg in bfq cfq; do
if grep -qws "${arg}" ${dev}/queue/scheduler; then
echo "${arg}" >${dev}/queue/scheduler
break
fi
done
# NCQ opitmizations
echo 31 >${dev}/queue/nr_requests
echo 2 >${dev}/device/queue_depth
done
}
start_adp()
{
disk
}
start_bat()
{
disk 255 254 254
}
start_dyn()
{
disk 0 254 254
}
start_quiet()
{
disk 255 254 254
}
#
# vim:fenc=utf-8:ft=sh:ci:pi:sts=0:sw=4:ts=4:
#