Support topology information for data alignment (LUKS).
[platform/upstream/cryptsetup.git] / tests / align_test
1 #!/bin/bash
2
3 CRYPTSETUP="../src/cryptsetup"
4 DEV=""
5
6 add_device() {
7         modprobe scsi_debug $@
8         DEV=/dev/$(grep scsi_debug /sys/block/*/device/model | cut -f4 -d /)
9         sleep 2
10         [ -b $DEV ] || exit 100
11 }
12
13 cleanup() {
14         udevadm settle
15         rmmod scsi_debug 2>/dev/null
16         sleep 2
17 }
18
19 format() # key_bits expected [forced]
20 {
21         if [ -z "$3" ] ; then
22                 echo -n "Formatting using topology info ($1 bits key)...."
23                 echo xxx| $CRYPTSETUP luksFormat $DEV -q -s $1
24         else
25                 echo -n "Formatting using forced offset $3 ($1 bits key)..."
26                 echo xxx| $CRYPTSETUP luksFormat $DEV -q -s $1 --align-payload=$2
27         fi
28
29         ALIGN=$($CRYPTSETUP luksDump $DEV |grep "Payload offset" | sed -e s/.*\\t//)
30         #echo "ALIGN = $ALIGN"
31
32         if [ $ALIGN -ne $2 ] ; then
33                 echo "FAIL"
34                 echo "Expected alignment differs: expected $2 != detected $ALIGN"
35                 exit 100
36         fi
37         echo "PASSED"
38 }
39
40 modprobe --dry-run scsi_debug || exit 0
41 cleanup
42
43 echo "# Create desktop-class 4K drive"
44 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=0)"
45 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 num_tgts=1
46 format 256 2112
47 format 128 1088
48 format 256 8192 8192
49 format 128 8192 8192
50 cleanup
51
52 echo "# Create desktop-class 4K drive w/ 63-sector DOS partition compensation"
53 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=3584)"
54 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 lowest_aligned=7 num_tgts=1
55 format 256 2119
56 format 128 1095
57 cleanup
58
59 echo "# Create enterprise-class 4K drive"
60 echo "# (logical_block_size=4096, physical_block_size=4096, alignment_offset=0)"
61 add_device dev_size_mb=16 sector_size=4096 num_tgts=1
62 format 256 2560
63 format 128 1536 
64 cleanup
65
66 echo "# Create classic 512b drive and stack dm-linear"
67 echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0)"
68 add_device dev_size_mb=16 sector_size=512 num_tgts=1
69 DEV2=$DEV
70 DEV=/dev/mapper/luks0xbabe
71 dmsetup create luks0xbabe --table "0 32768 linear $DEV2 0"
72 format 256 2112
73 format 128 1088
74 format 128 8192 8192
75 dmsetup remove luks0xbabe
76 cleanup