summaryrefslogtreecommitdiff
blob: 2f6470d6b7bf2e7dc36c27ea259286da4839761e (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
#!/sbin/runscript
# Copyright 1999-2005 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Id$

depend() {
	if [ -x /etc/init.d/root ]; then
		need root
	else
		need checkroot
	fi
	need modules
	before localmount
}

start() {
	local status="0"

	ebegin "Starting crypto loop devices"

	if [ -e /etc/conf.d/crypto-loop ] ; then
		egrep "^loop" /etc/conf.d/crypto-loop | \
		while read loopline ; do
			eval ${loopline}

			local configured=$(awk -v MOUNT="${device}" \
				'($2 == MOUNT) { print "yes" }' /proc/mounts)

			if [ "${configured}" != "yes" ] ; then
				einfo "  Loop ${loop} on device ${device} (cipher ${cipher}, key size ${keysize}): "

				if [ -n "${hash}" ] ; then
					/usr/sbin/hashalot -n ${keysize} ${hash} </dev/tty|\
					/sbin/losetup -p 0 -e ${cipher}-${keysize} ${loop} ${device} ${other}
				else
					/sbin/losetup -e ${cipher}-${keysize} ${loop} ${device} ${other}
				fi

				if [ $? -ne 0 ] ; then
					ewarn "Failure configuring ${loop}.  Skipping."
					status=1
				fi
			else
				ewarn "  Loop ${loop} on device ${device} are already configured"
			fi
		done
	fi
	ewend ${status} "Failed to start some loop devices."

	# We do not fail if some loop devices did not start ...
	return 0
}

stop() {
	local status="0"
	for loop in $(ls /dev/loop[0-9] 2>/dev/null) ; do
		losetup ${loop} > /dev/null 2>&1
		if [ $? -eq 0 ] ; then
			( umount ${loop} || swapoff "${loop}" ) >/dev/null 2>&1
			if ! /sbin/losetup -d ${loop} > /dev/null 2>&1; then
				ewarn "Failure deconfiguring ${loop}."
				status=1
			fi
		fi
	done
	ewend ${status}
}


# vim:ts=4