3 CRYPTSETUP="../src/cryptsetup"
5 DEV_STACKED="luks0xbabe"
11 udevadm settle >/dev/null 2>&1
12 if [ -d "$MNT_DIR" ] ; then
13 umount -f $MNT_DIR 2>/dev/null
14 rmdir $MNT_DIR 2>/dev/null
16 [ -b /dev/mapper/$DEV_STACKED ] && dmsetup remove $DEV_STACKED >/dev/null 2>&1
17 rmmod scsi_debug 2>/dev/null
23 if [ -n "$1" ] ; then echo "FAIL $1" ; else echo "FAIL" ; fi
30 echo "TEST SKIPPED: $1"
36 modprobe scsi_debug $@
37 if [ $? -ne 0 ] ; then
38 echo "This kernel seems to not support proper scsi_debug module, test skipped."
43 DEV=$(grep -l -e scsi_debug /sys/block/*/device/model | cut -f4 -d /)
45 if [ ! -e /sys/block/$DEV/alignment_offset ] ; then
46 echo "This kernel seems to not support topology info, test skipped."
52 [ -b $DEV ] || fail "Cannot find $DEV."
55 format() # key_bits expected [forced]
58 echo -n "Formatting using topology info ($1 bits key)..."
59 echo $PWD1 | $CRYPTSETUP luksFormat $DEV -q -i1 -c aes-cbc-essiv:sha256 -s $1
61 echo -n "Formatting using forced sector alignment $3 ($1 bits key)..."
62 echo $PWD1 | $CRYPTSETUP luksFormat $DEV -q -i1 -s $1 -c aes-cbc-essiv:sha256 --align-payload=$2
65 ALIGN=$($CRYPTSETUP luksDump $DEV |grep "Payload offset" | sed -e s/.*\\t//)
66 #echo "ALIGN = $ALIGN"
68 [ -z "$ALIGN" ] && fail
69 [ $ALIGN -ne $2 ] && fail "Expected alignment differs: expected $2 != detected $ALIGN"
71 # test some operation, just in case
72 echo -e "$PWD1\n$PWD2" | $CRYPTSETUP luksAddKey $DEV -i1 --key-slot 1
73 [ $? -ne 0 ] && fail "Keyslot add failed."
75 $CRYPTSETUP -q luksKillSlot $DEV 1
76 [ $? -ne 0 ] && fail "Keyslot removal failed."
83 $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
88 if [ $3 -eq 0 ] ; then
89 echo -n "Formatting using topology info ($1 bits key) [slot 0"
90 echo $PWD1 | $CRYPTSETUP luksFormat $DEV -q -i1 -c null -s $1
92 echo -n "Formatting using forced sector alignment $3 ($1 bits key) [slot 0"
93 echo $PWD1 | $CRYPTSETUP luksFormat $DEV -q -i1 -c null -s $1 --align-payload=$3
96 POFF=$(get_offsets "Payload offset")
97 [ -z "$POFF" ] && fail
98 [ $POFF != $2 ] && fail "Expected data offset differs: expected $2 != detected $POFF"
100 for j in 1 2 3 4 5 6 7 ; do
101 echo -e "$PWD1\n$PWD2$j" | $CRYPTSETUP luksAddKey $DEV -q -i1 --key-slot $j -c null $PARAMS
106 KOFF=$(get_offsets "Key material offset")
107 [ -z "$KOFF" ] && fail
108 [ $KOFF != $4 ] && fail "Expected keyslots offsets differ: expected $4 != detected $KOFF"
114 if [ $(id -u) != 0 ]; then
115 echo "WARNING: You must be root to run this test, test skipped."
119 modprobe --dry-run scsi_debug || exit 0
122 echo "# Create desktop-class 4K drive"
123 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=0)"
124 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 num_tgts=1
133 echo "# Create desktop-class 4K drive w/ 63-sector DOS partition compensation"
134 echo "# (logical_block_size=512, physical_block_size=4096, alignment_offset=3584)"
135 add_device dev_size_mb=16 sector_size=512 physblk_exp=3 lowest_aligned=7 num_tgts=1
142 echo "# Create enterprise-class 4K drive"
143 echo "# (logical_block_size=4096, physical_block_size=4096, alignment_offset=0)"
144 add_device dev_size_mb=16 sector_size=4096 num_tgts=1
151 echo "# Create classic 512B drive and stack dm-linear"
152 echo "# (logical_block_size=512, physical_block_size=512, alignment_offset=0)"
153 add_device dev_size_mb=16 sector_size=512 num_tgts=1
155 DEV=/dev/mapper/$DEV_STACKED
156 dmsetup create $DEV_STACKED --table "0 32768 linear $DEV2 0"
164 echo "# Offset check: 512B sector drive"
165 add_device dev_size_mb=16 sector_size=512 num_tgts=1
166 # |k| expO reqO expected slot offsets
167 format_null 64 2048 0 8:72:136:200:264:328:392:456
170 format_null 64 640 128
171 format_null 64 2048 2048
172 format_null 128 2048 0 8:136:264:392:520:648:776:904
173 format_null 128 1032 1
174 format_null 128 1032 8
175 format_null 128 1152 128
176 format_null 128 2048 2048
177 format_null 256 4096 0 8:264:520:776:1032:1288:1544:1800
178 format_null 256 2056 1
179 format_null 256 2056 8
180 format_null 256 2176 128
181 format_null 256 4096 2048
182 format_null 512 4096 0 8:512:1016:1520:2024:2528:3032:3536
183 format_null 512 4040 1
184 format_null 512 4040 8
185 format_null 512 4096 128
186 format_null 512 4096 2048
189 echo "# Offset check: 4096B sector drive"
190 add_device dev_size_mb=16 sector_size=4096 num_tgts=1
191 format_null 64 2048 0 8:72:136:200:264:328:392:456
194 format_null 64 640 128
195 format_null 64 2048 2048
196 format_null 128 2048 0 8:136:264:392:520:648:776:904
197 format_null 128 1032 1
198 format_null 128 1032 8
199 format_null 128 1152 128
200 format_null 128 2048 2048
201 format_null 256 4096 0 8:264:520:776:1032:1288:1544:1800
202 format_null 256 2056 1
203 format_null 256 2056 8
204 format_null 256 2176 128
205 format_null 256 4096 2048
206 format_null 512 4096 0 8:512:1016:1520:2024:2528:3032:3536
207 format_null 512 4040 1
208 format_null 512 4040 8
209 format_null 512 4096 128
210 format_null 512 4096 2048
213 echo "# Create enterprise-class 4K drive with fs and LUKS images."
214 # loop device here presents 512 block but images have 4k block
215 # cryptsetup should properly use 4k block on direct-io
216 add_device dev_size_mb=16 sector_size=4096 physblk_exp=0 num_tgts=1
217 for file in $(ls img_fs_*.img.bz2) ; do
218 echo "Format using fs image $file."
219 bzip2 -d -c $file | dd of=$DEV bs=1M 2>/dev/null || fail "bad image"
220 [ ! -d $MNT_DIR ] && mkdir $MNT_DIR
221 mount $DEV $MNT_DIR || skip "Mounting image is not available."
222 echo $PWD1 | $CRYPTSETUP luksFormat -i 1 $MNT_DIR/luks.img || fail
223 echo $PWD2 | $CRYPTSETUP luksFormat -i 1 $MNT_DIR/luks.img --header $MNT_DIR/luks_header.img || fail