Fix/finish modularization
[mapsector.git] / lib / 50_map_crtypt.sh
1 detect_crypt()
2 {
3     which cryptsetup >/dev/null 2>&1 && [ -n "`dmcryptmap $device`" ]
4 }
5
6 describe_crypt()
7 {
8     echo "    cryptsetup (luks and dmcrypt)"
9 }
10
11 do_crypt()
12 {
13     # Step 2: Find the crypted volume defined for this partition
14
15     local offset
16     local devnums
17     local cryptdev
18     local cryptsector
19     local type
20
21     echo "# $device: cryptsetup detected" 1>&2
22
23     offset="`cryptsetup luksDump $device 2>/dev/null | awk '/^Payload offset/{print $3}'`"
24
25     if [ -z "$offset" ]; then
26         # Plain dmcrypt
27         offset=0
28         type=dmcrypt
29     else
30         type=luks
31     fi
32
33     cryptdev="`dmcryptmap $device`"
34
35     if [ -z "$cryptdev" ]; then
36         echo "! Failed to find decrypted mapper device for $device"
37         exit 1;
38     fi
39
40     cryptsector="`dc -e "$sector $offset - p"`" #`"
41
42     echo "offset $offset"
43     echo "device $cryptdev crypt"
44     echo "type $type"
45     echo "sector $cryptsector"
46     
47     device="$cryptdev"
48     sector="$cryptsector"
49
50     return 1
51 }
52
53 register_mapper "crypt"