3 CRYPTSETUP="../src/cryptsetup"
5 DEV_STACKED="luks0xbabe"
8 udevadm settle >/dev/null 2>&1
9 [ -b /dev/mapper/$DEV_STACKED ] && dmsetup remove $DEV_STACKED >/dev/null 2>&1
10 rmmod scsi_debug 2>/dev/null
17 [ -n "$1" ] && echo "$1"
23 modprobe scsi_debug $@
24 if [ $? -ne 0 ] ; then
25 echo "This kernel seems to not support proper scsi_debug module, test skipped."
30 DEV=$(grep scsi_debug /sys/block/*/device/model | cut -f4 -d /)
32 if [ ! -e /sys/block/$DEV/alignment_offset ] ; then
33 echo "This kernel seems to not support topology info, test skipped."
39 [ -b $DEV ] || fail "Cannot find $DEV."
42 format() # key_bits expected [forced]
45 echo -n "Formatting using topology info ($1 bits key)..."
46 echo xxx| $CRYPTSETUP luksFormat $DEV -q -i1 -c aes-cbc-essiv:sha256 -s $1
48 echo -n "Formatting using forced sector alignment $3 ($1 bits key)..."
49 echo xxx| $CRYPTSETUP luksFormat $DEV -q -i1 -s $1 -c aes-cbc-essiv:sha256 --align-payload=$2
52 ALIGN=$($CRYPTSETUP luksDump $DEV |grep "Payload offset" | sed -e s/.*\\t//)
53 #echo "ALIGN = $ALIGN"
55 [ -z "$ALIGN" ] && fail
56 [ $ALIGN -ne $2 ] && fail "Expected alignment differs: expected $2 != detected $ALIGN"
58 # test some operation, just in case
59 echo -e "xxx\naaa" | $CRYPTSETUP luksAddKey $DEV -i1 --key-slot 1
60 [ $? -ne 0 ] && fail "Keyslot add failed."
62 $CRYPTSETUP -q luksKillSlot $DEV 1
63 [ $? -ne 0 ] && fail "Keyslot removal failed."
70 $CRYPTSETUP luksDump $DEV | grep "$1" | cut -s -d ':' -f 2 | sed -e 's/\s//g' -e :a -e N -e 's/\n/:/g' -e 's/\s//g' -e ta
75 if [ $3 -eq 0 ] ; then
76 echo -n "Formatting using topology info ($1 bits key) [slot 0"
77 echo xxx| $CRYPTSETUP luksFormat $DEV -q -i1 -c null -s $1
79 echo -n "Formatting using forced sector alignment $3 ($1 bits key) [slot 0"
80 echo xxx| $CRYPTSETUP luksFormat $DEV -q -i1 -c null -s $1 --align-payload=$3
83 POFF=$(get_offsets "Payload offset")
84 [ -z "$POFF" ] && fail
85 [ $POFF != $2 ] && fail "Expected data offset differs: expected $2 != detected $POFF"
87 for j in 1 2 3 4 5 6 7 ; do
88 echo -e "xxx\nblah$j" | $CRYPTSETUP luksAddKey $DEV -q -i1 --key-slot $j -c null $PARAMS
93 KOFF=$(get_offsets "Key material offset")
94 [ -z "$KOFF" ] && fail
95 [ $KOFF != $4 ] && fail "Expected keyslots offsets differ: expected $4 != detected $KOFF"
101 if [ $(id -u) != 0 ]; then
102 echo "WARNING: You must be root to run this test, test skipped."
106 modprobe --dry-run scsi_debug || exit 0
109 echo "# Create desktop-class 4K drive"
110 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=0)"
111 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 num_tgts=1
120 echo "# Create desktop-class 4K drive w/ 63-sector DOS partition compensation"
121 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=3584)"
122 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 lowest_aligned=7 num_tgts=1
129 echo "# Create enterprise-class 4K drive"
130 echo "# (logical_block_size=4096, physical_block_size=4096, alignment_offset=0)"
131 add_device dev_size_mb=16 sector_size=4096 num_tgts=1
138 echo "# Create classic 512B drive and stack dm-linear"
139 echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0)"
140 add_device dev_size_mb=16 sector_size=512 num_tgts=1
142 DEV=/dev/mapper/$DEV_STACKED
143 dmsetup create $DEV_STACKED --table "0 32768 linear $DEV2 0"
151 echo "# Offset check: 512B sector drive"
152 add_device dev_size_mb=16 sector_size=512 num_tgts=1
153 # |k| expO reqO expected slot offsets
154 format_null 64 2048 0 8:72:136:200:264:328:392:456
157 format_null 64 640 128
158 format_null 64 2048 2048
159 format_null 128 2048 0 8:136:264:392:520:648:776:904
160 format_null 128 1032 1
161 format_null 128 1032 8
162 format_null 128 1152 128
163 format_null 128 2048 2048
164 format_null 256 4096 0 8:264:520:776:1032:1288:1544:1800
165 format_null 256 2056 1
166 format_null 256 2056 8
167 format_null 256 2176 128
168 format_null 256 4096 2048
169 format_null 512 4096 0 8:512:1016:1520:2024:2528:3032:3536
170 format_null 512 4040 1
171 format_null 512 4040 8
172 format_null 512 4096 128
173 format_null 512 4096 2048
176 echo "# Offset check: 4096B sector drive"
177 add_device dev_size_mb=16 sector_size=4096 num_tgts=1
178 format_null 64 2048 0 8:72:136:200:264:328:392:456
181 format_null 64 640 128
182 format_null 64 2048 2048
183 format_null 128 2048 0 8:136:264:392:520:648:776:904
184 format_null 128 1032 1
185 format_null 128 1032 8
186 format_null 128 1152 128
187 format_null 128 2048 2048
188 format_null 256 4096 0 8:264:520:776:1032:1288:1544:1800
189 format_null 256 2056 1
190 format_null 256 2056 8
191 format_null 256 2176 128
192 format_null 256 4096 2048
193 format_null 512 4096 0 8:512:1016:1520:2024:2528:3032:3536
194 format_null 512 4040 1
195 format_null 512 4040 8
196 format_null 512 4096 128
197 format_null 512 4096 2048