Home | History | Annotate | Download | only in u_offset
      1 test_description="e2undo with the offset option (-o offset)"
      2 OUT="$test_name.log"
      3 TMPFILE2="${TMPFILE}_2"
      4 TDB_FILE="$TMPFILE.e2undo"
      5 
      6 E2UNDO_FEATURE_COMPAT_OFFSET=1
      7 
      8 trap "rm -f $TMPFILE2 $TDB_FILE" EXIT INT QUIT
      9 
     10 read_header_entry() {
     11 	# $2 is just used as a dummy - it is never used by e2undo
     12 	# when dumping the header
     13 	$E2UNDO -h "$1" "$2" | grep "^$3:"
     14 }
     15 
     16 read_header_offset() {
     17 	read_header_entry "$TDB_FILE" "$TMPFILE" "fs offset" | cut -f2
     18 }
     19 
     20 read_header_compat() {
     21 	read_header_entry "$TDB_FILE" "$TMPFILE" "compat" | cut -f3
     22 }
     23 
     24 e2undo_offset_assert() {
     25 	if [ "$crc_exp" != "$crc_act" -o \
     26 		 "$offset_exp" != "$offset_act" -o \
     27 		 $(($compat_act & $E2UNDO_FEATURE_COMPAT_OFFSET)) -ne $compat_exp ]
     28 		then
     29 		echo "$1" >> "$test_name.failed"
     30 		echo "crc_exp: $crc_exp" >> "$test_name.failed"
     31 		echo "crc_act: $crc_act" >> "$test_name.failed"
     32 		echo "offset_exp: $offset_exp" >> "$test_name.failed"
     33 		echo "offset_act: $offset_act" >> "$test_name.failed"
     34 		echo "compat_exp: $compat_exp" >> "$test_name.failed"
     35 		echo "compat_act: $compat_act" >> "$test_name.failed"
     36 	fi
     37 }
     38 
     39 init_fs() {
     40 	echo "#" >> "$OUT"
     41 	echo "# init fs for $1" >> "$OUT"
     42 	echo "#" >> "$OUT"
     43 	rm -f "$TDB_FILE"
     44 	dd if=/dev/zero of="$TMPFILE" bs=1k count=1024 > /dev/null 2>&1
     45 	$MKE2FS -F -z "$TDB_FILE" -b 1024 -E offset=524288 "$TMPFILE" 512 \
     46 		>> "$OUT" 2>&1
     47 }
     48 
     49 #
     50 # test absence of the "-o N" option
     51 #
     52 test_e2undo_offset_no_option() {
     53 	init_fs "test_e2undo_offset_no_option"
     54 
     55 	$E2UNDO "$TDB_FILE" "$TMPFILE" >> "$OUT" 2>&1
     56 
     57 	crc_exp=`dd if=/dev/zero bs=1k count=1024 2>/dev/null | $CRCSUM`
     58 	crc_act=`$CRCSUM "$TMPFILE"`
     59 	offset_exp=524288
     60 	offset_act=`read_header_offset`
     61 	compat_exp=$E2UNDO_FEATURE_COMPAT_OFFSET
     62 	compat_act=`read_header_compat`
     63 	e2undo_offset_assert "test_e2undo_offset_no_option"
     64 }
     65 
     66 #
     67 # test removal of the offset feature in the undo header
     68 #
     69 test_e2undo_offset_no_option_remove_offset_header() {
     70 	init_fs "test_e2undo_offset_no_option_remove_offset_header"
     71 	dd if="$TMPFILE" of="$TMPFILE2" bs=1k count=512 skip=512 \
     72 		> /dev/null 2>&1
     73 	# offset feature will be removed from the undo header
     74 	$TUNE2FS -z "$TDB_FILE" -C 42 "$TMPFILE2" >> "$OUT" 2>&1
     75 
     76 	$E2UNDO "$TDB_FILE" "$TMPFILE2" >> "$OUT" 2>&1
     77 
     78 	crc_exp=`dd if=/dev/zero bs=1k count=512 2>/dev/null | $CRCSUM`
     79 	crc_act=`$CRCSUM "$TMPFILE2"`
     80 	offset_exp=
     81 	offset_act=`read_header_offset`
     82 	compat_exp=0
     83 	compat_act=`read_header_compat`
     84 	e2undo_offset_assert "test_e2undo_offset_no_option_remove_offset_header"
     85 }
     86 
     87 #
     88 # test "-o 4096"
     89 #
     90 test_e2undo_offset_4096() {
     91 	init_fs "test_e2undo_offset_4096"
     92 	dd if=/dev/zero of="$TMPFILE2" bs=1k count=4 > /dev/null 2>&1
     93 	dd if="$TMPFILE" of="$TMPFILE2" bs=1k count=512 skip=512 seek=4 \
     94 		> /dev/null 2>&1
     95 
     96 	$E2UNDO -o 4096 "$TDB_FILE" "$TMPFILE2" >> "$OUT" 2>&1
     97 
     98 	crc_exp=`dd if=/dev/zero bs=1k count=516 2>/dev/null | $CRCSUM`
     99 	crc_act=`$CRCSUM "$TMPFILE2"`
    100 	# the same as in test_e2undo_offset_no_option
    101 	offset_exp=524288
    102 	offset_act=`read_header_offset`
    103 	compat_exp=$E2UNDO_FEATURE_COMPAT_OFFSET
    104 	compat_act=`read_header_compat`
    105 	e2undo_offset_assert "test_e2undo_offset_4096"
    106 }
    107 
    108 #
    109 # test "-o 0"
    110 #
    111 test_e2undo_offset_0() {
    112 	init_fs "test_e2undo_offset_0"
    113 	dd if="$TMPFILE" of="$TMPFILE2" bs=1k count=512 skip=512 \
    114 		> /dev/null 2>&1
    115 
    116 	$E2UNDO -o 0 "$TDB_FILE" "$TMPFILE2" >> "$OUT" 2>&1
    117 
    118 	crc_exp=`dd if=/dev/zero bs=1k count=512 2>/dev/null | $CRCSUM`
    119 	crc_act=`$CRCSUM "$TMPFILE2"`
    120 	# the same as in test_e2undo_offset_no_option
    121 	offset_exp=524288
    122 	offset_act=`read_header_offset`
    123 	compat_exp=$E2UNDO_FEATURE_COMPAT_OFFSET
    124 	compat_act=`read_header_compat`
    125 	e2undo_offset_assert "test_e2undo_offset_0"
    126 }
    127 
    128 test_e2undo_offset_no_option
    129 test_e2undo_offset_no_option_remove_offset_header
    130 test_e2undo_offset_4096
    131 test_e2undo_offset_0
    132 
    133 if [ -e "$test_name.failed" ]; then
    134 	echo "$test_name: $test_description: failed"
    135 else
    136 	echo "$test_name: $test_description: ok"
    137 	touch "$test_name.ok"
    138 fi
    139