summaryrefslogtreecommitdiffstats
path: root/etc/rc.d/encswap
blob: 622199869d1c87fd6e722b0496f5e35323bc5eea (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
#!/bin/sh
#
# $FreeBSD$
#

# PROVIDE: disks
# REQUIRE: initrandom
# KEYWORD: nojail

. /etc/rc.subr

name="encswap"
start_cmd="encswap_attach"
stop_cmd="encswap_detach"

encswap_attach()
{
	while read device mountpoint type options rest ; do
		case ":${device}:${type}:${options}" in
		:#*)
			continue
			;;
		*.bde:swap:sw)
			passphrase=`dd if=/dev/random count=1 2>/dev/null | md5 -q`
			device="${device%.bde}"
			gbde init "${device}" -P "${passphrase}" || return 1
			gbde attach "${device}" -p "${passphrase}" || return 1
			;;
		*.eli:swap:sw)
			device="${device%.eli}"
			geli onetime ${geli_swap_flags} "${device}" || return 1
			;;
		esac
	done < /etc/fstab
}

encswap_detach()
{
	while read device mountpoint type options rest ; do
		case ":${device}:${type}:${options}" in
		:#*)
			continue
			;;
		*.bde:swap:sw)
			device="${device%.bde}"
			gbde detach "${device}"
			;;
		*.eli:swap:sw)
			# Nothing here, because geli swap devices should be
			# created with the auto-detach-on-last-close option.
			;;
		esac
	done < /etc/fstab
}

load_rc_config $name
run_rc_command "$1"
OpenPOWER on IntegriCloud