1test_description="e2undo and mke2fs with offset option" 2OUT="$test_name.log" 3TDB_FILE="$TMPFILE.e2undo" 4 5E2UNDO_FEATURE_COMPAT_OFFSET=1 6 7trap "rm -f $TDB_FILE" EXIT INT QUIT 8 9test_e2undo_mke2fs_off() { 10 OFF=$1 11 12 rm -f "$TDB_FILE" 13 echo "testing e2undo and mke2fs with the -E offset=$OFF option" >> "$OUT" 14 # prepare $TMPFILE 15 yes a | $DD of="$TMPFILE" bs="$OFF" count=1 iflag=fullblock \ 16 > /dev/null 2>>"$OUT" 17 yes b | $DD bs=1k count=1024 iflag=fullblock >> "$TMPFILE" 2>>"$OUT" 18 yes c | $DD bs=1k count=3 iflag=fullblock >> "$TMPFILE" 2>>"$OUT" 19 20 crc_exp=`$CRCSUM "$TMPFILE"` 21 $MKE2FS -F -z "$TDB_FILE" -b 1024 -E offset="$OFF" "$TMPFILE" 1024 \ 22 >> "$OUT" 2>&1 23 24 # supplement test with offset specific data 25 supplement_test_$OFF 26 27 # dump undo header (just to ease debugging in case of a failure) 28 echo "undo header:" >> "$OUT" 29 $E2UNDO -h "$TDB_FILE" "$TMPFILE" >> "$OUT" 2>&1 30 31 # offset is stored in the undo header 32 $E2UNDO "$TDB_FILE" "$TMPFILE" >> "$OUT" 2>&1 33 crc_act=`$CRCSUM "$TMPFILE"` 34 35 # also test the key extension code path: the key for the fs block 960 36 # (tdb block 30) is extended by the fs block 992 (tdb block 31) 37 # => we have exactly 3 key blocks instead of 4 38 num_keys_exp=3 39 num_keys_act=`$E2UNDO -h "$TDB_FILE" "$TMPFILE" | grep "^nr keys:" \ 40 | cut -f2` 41 42 offset_exp=$OFF 43 offset_act=`$E2UNDO -h "$TDB_FILE" "$TMPFILE" | grep "^fs offset:" \ 44 | cut -f2` 45 compat_exp=$E2UNDO_FEATURE_COMPAT_OFFSET 46 compat_act=`$E2UNDO -h "$TDB_FILE" "$TMPFILE" | grep "^compat:" | cut -f3` 47 48 if [ "$crc_exp" != "$crc_act" -o \ 49 "$num_keys_exp" != "$num_keys_act" -o \ 50 "$offset_exp" != "$offset_act" -o \ 51 $(($compat_act & $E2UNDO_FEATURE_COMPAT_OFFSET)) -ne $compat_exp ] 52 then 53 echo "mke2fs called with offset: $OFF" >> "$test_name.failed" 54 echo "crc_exp: $crc_exp" >> "$test_name.failed" 55 echo "crc_act: $crc_act" >> "$test_name.failed" 56 echo "num_keys_exp: $num_keys_exp" >> "$test_name.failed" 57 echo "num_keys_act: $num_keys_act" >> "$test_name.failed" 58 echo "offset_exp: $offset_exp" >> "$test_name.failed" 59 echo "offset_act: $offset_act" >> "$test_name.failed" 60 echo "compat_exp: $compat_exp" >> "$test_name.failed" 61 echo "compat_act: $compat_act" >> "$test_name.failed" 62 echo >> "$test_name.failed" 63 fi 64} 65 66supplement_test_2048() { 67 # modify the two subsequent 1k blocks (1026 and 1027) after the fs end: 68 # e2undo will overwrite these modified blocks with the old 69 # data again (this might be considered as a bug (for now, 70 # this testcase just documents this behavior)) 71 SEEK_BLOCKS=$(((2048 + 1024 * 1024) / 1024)) 72 yes d | $DD of="$TMPFILE" bs=1k count=2 seek="$SEEK_BLOCKS" \ 73 iflag=fullblock > /dev/null 2>>"$OUT" 74} 75 76supplement_test_96255() { 77 # nothing to supplement 78 : 79} 80 81# test even offset < tdb_data_size 82# with an offset of 2048 the old code wrote an incorrect undo file, 83# for example, the computations for fs block 0 were wrong: 84# * backing_blk_num was set to ULLONG_MAX - 1 instead of 0 85# * data was read from the beginning of the file instead of offset 2048 86# * data_ptr was set to read_ptr - 2048 87# for details, see the old undo_write_tdb code in undo_io.c 88test_e2undo_mke2fs_off 2048 89 90# test odd offset > tdb_data_size: 32768 * 3 - 2 * 1024 - 1 91# a somewhat arbitrary value, for example, during the backup of 92# fs block 0 such an offset resulted in: 93# * the largest "in fs block offset" (96255 % 1024 == 1023) 94# * a wrong value for data_size (actual bytes read: 31745) 95# * an invalid address for data_ptr 96# for details, see the old undo_write_tdb code in undo_io.c 97test_e2undo_mke2fs_off 96255 98 99if [ -e "$test_name.failed" ]; then 100 echo "$test_name: $test_description: failed" 101else 102 echo "$test_name: $test_description: ok" 103 touch "$test_name.ok" 104fi 105