1125388Sdes#!/bin/sh
2125388Sdes#
3125388Sdes# $FreeBSD$
4125388Sdes#
5125388Sdes
6125388Sdes# PROVIDE: disks
7125498Sdes# REQUIRE: initrandom
8136224Smtm# KEYWORD: nojail
9125388Sdes
10125388Sdes. /etc/rc.subr
11125388Sdes
12148765Spjdname="encswap"
13148765Spjdstart_cmd="encswap_attach"
14148765Spjdstop_cmd="encswap_detach"
15125388Sdes
16148765Spjdencswap_attach()
17125388Sdes{
18125388Sdes	while read device mountpoint type options rest ; do
19133987Sthomas		case ":${device}:${type}:${options}" in
20133987Sthomas		:#*)
21133987Sthomas			continue
22133987Sthomas			;;
23125388Sdes		*.bde:swap:sw)
24148765Spjd			passphrase=`dd if=/dev/random count=1 2>/dev/null | md5 -q`
25148765Spjd			device="${device%.bde}"
26148765Spjd			gbde init "${device}" -P "${passphrase}" || return 1
27148765Spjd			gbde attach "${device}" -p "${passphrase}" || return 1
28125388Sdes			;;
29148765Spjd		*.eli:swap:sw)
30148765Spjd			device="${device%.eli}"
31148765Spjd			geli onetime ${geli_swap_flags} "${device}" || return 1
32125388Sdes			;;
33125388Sdes		esac
34133987Sthomas	done < /etc/fstab
35125388Sdes}
36125388Sdes
37148765Spjdencswap_detach()
38125388Sdes{
39125388Sdes	while read device mountpoint type options rest ; do
40133987Sthomas		case ":${device}:${type}:${options}" in
41133987Sthomas		:#*)
42133987Sthomas			continue
43133987Sthomas			;;
44125388Sdes		*.bde:swap:sw)
45148765Spjd			device="${device%.bde}"
46148765Spjd			gbde detach "${device}"
47125388Sdes			;;
48148765Spjd		*.eli:swap:sw)
49148765Spjd			# Nothing here, because geli swap devices should be
50148765Spjd			# created with the auto-detach-on-last-close option.
51125388Sdes			;;
52125388Sdes		esac
53133987Sthomas	done < /etc/fstab
54125388Sdes}
55125388Sdes
56125388Sdesload_rc_config $name
57125388Sdesrun_rc_command "$1"
58