3 CRYPTSETUP="../src/cryptsetup"
5 DEV_STACKED="luks0xbabe"
10 udevadm settle >/dev/null 2>&1
11 [ -b /dev/mapper/$DEV_STACKED ] && dmsetup remove $DEV_STACKED >/dev/null 2>&1
12 rmmod scsi_debug 2>/dev/null
19 [ -n "$1" ] && echo "$1"
25 modprobe scsi_debug $@
26 if [ $? -ne 0 ] ; then
27 echo "This kernel seems to not support proper scsi_debug module, test skipped."
32 DEV=$(grep scsi_debug /sys/block/*/device/model | cut -f4 -d /)
34 if [ ! -e /sys/block/$DEV/alignment_offset ] ; then
35 echo "This kernel seems to not support topology info, test skipped."
41 [ -b $DEV ] || fail "Cannot find $DEV."
44 format() # key_bits expected [forced]
47 echo -n "Formatting using topology info ($1 bits key)..."
48 echo $PWD1 | $CRYPTSETUP luksFormat $DEV -q -i1 -c aes-cbc-essiv:sha256 -s $1
50 echo -n "Formatting using forced sector alignment $3 ($1 bits key)..."
51 echo $PWD1 | $CRYPTSETUP luksFormat $DEV -q -i1 -s $1 -c aes-cbc-essiv:sha256 --align-payload=$2
54 ALIGN=$($CRYPTSETUP luksDump $DEV |grep "Payload offset" | sed -e s/.*\\t//)
55 #echo "ALIGN = $ALIGN"
57 [ -z "$ALIGN" ] && fail
58 [ $ALIGN -ne $2 ] && fail "Expected alignment differs: expected $2 != detected $ALIGN"
60 # test some operation, just in case
61 echo -e "$PWD1\n$PWD2" | $CRYPTSETUP luksAddKey $DEV -i1 --key-slot 1
62 [ $? -ne 0 ] && fail "Keyslot add failed."
64 $CRYPTSETUP -q luksKillSlot $DEV 1
65 [ $? -ne 0 ] && fail "Keyslot removal failed."
72 $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
77 if [ $3 -eq 0 ] ; then
78 echo -n "Formatting using topology info ($1 bits key) [slot 0"
79 echo $PWD1 | $CRYPTSETUP luksFormat $DEV -q -i1 -c null -s $1
81 echo -n "Formatting using forced sector alignment $3 ($1 bits key) [slot 0"
82 echo $PWD1 | $CRYPTSETUP luksFormat $DEV -q -i1 -c null -s $1 --align-payload=$3
85 POFF=$(get_offsets "Payload offset")
86 [ -z "$POFF" ] && fail
87 [ $POFF != $2 ] && fail "Expected data offset differs: expected $2 != detected $POFF"
89 for j in 1 2 3 4 5 6 7 ; do
90 echo -e "$PWD1\n$PWD2$j" | $CRYPTSETUP luksAddKey $DEV -q -i1 --key-slot $j -c null $PARAMS
95 KOFF=$(get_offsets "Key material offset")
96 [ -z "$KOFF" ] && fail
97 [ $KOFF != $4 ] && fail "Expected keyslots offsets differ: expected $4 != detected $KOFF"
103 if [ $(id -u) != 0 ]; then
104 echo "WARNING: You must be root to run this test, test skipped."
108 modprobe --dry-run scsi_debug || exit 0
111 echo "# Create desktop-class 4K drive"
112 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=0)"
113 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 num_tgts=1
122 echo "# Create desktop-class 4K drive w/ 63-sector DOS partition compensation"
123 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=3584)"
124 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 lowest_aligned=7 num_tgts=1
131 echo "# Create enterprise-class 4K drive"
132 echo "# (logical_block_size=4096, physical_block_size=4096, alignment_offset=0)"
133 add_device dev_size_mb=16 sector_size=4096 num_tgts=1
140 echo "# Create classic 512B drive and stack dm-linear"
141 echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0)"
142 add_device dev_size_mb=16 sector_size=512 num_tgts=1
144 DEV=/dev/mapper/$DEV_STACKED
145 dmsetup create $DEV_STACKED --table "0 32768 linear $DEV2 0"
153 echo "# Offset check: 512B sector drive"
154 add_device dev_size_mb=16 sector_size=512 num_tgts=1
155 # |k| expO reqO expected slot offsets
156 format_null 64 2048 0 8:72:136:200:264:328:392:456
159 format_null 64 640 128
160 format_null 64 2048 2048
161 format_null 128 2048 0 8:136:264:392:520:648:776:904
162 format_null 128 1032 1
163 format_null 128 1032 8
164 format_null 128 1152 128
165 format_null 128 2048 2048
166 format_null 256 4096 0 8:264:520:776:1032:1288:1544:1800
167 format_null 256 2056 1
168 format_null 256 2056 8
169 format_null 256 2176 128
170 format_null 256 4096 2048
171 format_null 512 4096 0 8:512:1016:1520:2024:2528:3032:3536
172 format_null 512 4040 1
173 format_null 512 4040 8
174 format_null 512 4096 128
175 format_null 512 4096 2048
178 echo "# Offset check: 4096B sector drive"
179 add_device dev_size_mb=16 sector_size=4096 num_tgts=1
180 format_null 64 2048 0 8:72:136:200:264:328:392:456
183 format_null 64 640 128
184 format_null 64 2048 2048
185 format_null 128 2048 0 8:136:264:392:520:648:776:904
186 format_null 128 1032 1
187 format_null 128 1032 8
188 format_null 128 1152 128
189 format_null 128 2048 2048
190 format_null 256 4096 0 8:264:520:776:1032:1288:1544:1800
191 format_null 256 2056 1
192 format_null 256 2056 8
193 format_null 256 2176 128
194 format_null 256 4096 2048
195 format_null 512 4096 0 8:512:1016:1520:2024:2528:3032:3536
196 format_null 512 4040 1
197 format_null 512 4040 8
198 format_null 512 4096 128
199 format_null 512 4096 2048