4ec0ec077373b49c222163fde119bfc56156b6cd
[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 map_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     offset="`cryptsetup luksDump $device 2>/dev/null | awk '/^Payload offset/{print $3}'`"
22
23     if [ -z "$offset" ]; then
24         # Plain dmcrypt
25         offset=0
26         type=dmcrypt
27     else
28         type=luks
29     fi
30
31     cryptdev="`dmcryptmap $device`"
32
33     if [ -z "$cryptdev" ]; then
34         echo "! Failed to find decrypted mapper device for $device"
35         exit 1;
36     fi
37
38     cryptsector="`dc -e "$sector $offset - p"`" #`"
39
40     echo "offset $offset"
41     echo "device $cryptdev crypt"
42     echo "type $type"
43     echo "sector $cryptsector"
44     
45     device="$cryptdev"
46     sector="$cryptsector"
47 }
48
49 register_mapper "crypt"