-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathflashrd.sub
109 lines (92 loc) · 1.42 KB
/
flashrd.sub
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
###
#
# fallback harness
c() {
[ -z "$1" ] && exit 1
lvl="$1"
shift
[ -z "$*" ] && exit 1
if ! eval $*; then
echo % $* failure
if echo "$*" | grep last.output >/dev/null 2>&1; then
echo % See $TMPDIR/last.output for further diagnostics
fi
case $lvl {
4)
4; 3; 2; 1; 0;
;;
3)
3; 2; 1; 0;
;;
2)
2; 1; 0;
;;
1)
1; 0;
;;
0)
0;
;;
}
fi
}
###
#
# Wait up to 30 seconds for the kernel to catch up,
# otherwise give up umount with fallback harness
umountwait() {
y=1
while ! umount $2 2>/dev/null; do
echo -n "...$y"
sleep 1
let y=y+1
if [ "$y" -gt 30 ]; then
c $1 umount $2
fi
done
}
###
#
# Test Argument
t2() {
if [ -z "$1" ]; then
echo "t2: argument missing"
exit 1
fi
}
###
#
# Sectors to MBytes
sectors2mbytes() {
echo $(((($1 / 1024) * bytessec) / 1024))
}
###
#
# MBytes to sectors
mbytes2sectors() {
echo $(((($1 * 1024) / bytessec) * 1024))
}
###
#
# Find a free vnd
getavailvnd() {
set -A vndevices `vnconfig -l | grep -i 'not in use' | sed 's/\(vnd[[:digit:]]\).*/\1/'`
if [ ${#vndevices[@]} -lt "$1" ]; then
echo "Not enough vnd device(s) available (${#vndevices[@]} < $1)"
exit 1
fi
}
###
#
# Return a directory tree size in blocks
getsize() {
if [ -z "$1" ]; then
echo "getsize: argument missing"
fi
if [ ! -d "$1" ]; then
echo "getsize: the argument must be a directory"
fi
unset BLOCKSIZE
set -- $(du -s $1)
echo $1
}