blob: 98489349b7121d2d919897135579a5209259f2c7 (
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
|
get_rundir() {
local rundir
rundir="`mount | grep '/run ' | awk '{print $3}'`"
echo ${rundir:-"/var/run"}
}
loopbackeddev() {
local action file size ctlfile
action="$1"
file="$2"
size="$3"
ctlfile=$HA_RSCTMP/`echo $file | tr / _`
case "$action" in
start|setup|make)
if [ ! -f "$ctlfile" ]; then
if [ -z "$size" ]; then
echo "usage: $0 action file size" >&2
exit 1
fi
loopdev=`losetup -f`
if ! dd if=/dev/zero of=$file bs=1 count=0 seek=$size 2>/dev/null; then
echo "$0: dd failed" >&2
exit 1
fi
if ! losetup $loopdev $file; then
echo "$0: losetup failed" >&2
exit 1
fi
echo $loopdev | tee $ctlfile
else
cat $ctlfile
fi
;;
stop|undo|unmake)
if [ -f "$ctlfile" ]; then
losetup -d `cat $ctlfile`
rm -f $file $ctlfile
fi
;;
esac
}
|