summaryrefslogtreecommitdiffstats
path: root/tests/u_offset/script
blob: c3e03b77f517a28948cee34fb1d16a7a7463be63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
test_description="e2undo with the offset option (-o offset)"
OUT="$test_name.log"
TMPFILE2="${TMPFILE}_2"
TDB_FILE="$TMPFILE.e2undo"

E2UNDO_FEATURE_COMPAT_OFFSET=1

trap "rm -f $TMPFILE2 $TDB_FILE" EXIT INT QUIT

read_header_entry() {
	# $2 is just used as a dummy - it is never used by e2undo
	# when dumping the header
	$E2UNDO -h "$1" "$2" | grep "^$3:"
}

read_header_offset() {
	read_header_entry "$TDB_FILE" "$TMPFILE" "fs offset" | cut -f2
}

read_header_compat() {
	read_header_entry "$TDB_FILE" "$TMPFILE" "compat" | cut -f3
}

e2undo_offset_assert() {
	if [ "$crc_exp" != "$crc_act" -o \
		 "$offset_exp" != "$offset_act" -o \
		 $(($compat_act & $E2UNDO_FEATURE_COMPAT_OFFSET)) -ne $compat_exp ]
		then
		echo "$1" >> "$test_name.failed"
		echo "crc_exp: $crc_exp" >> "$test_name.failed"
		echo "crc_act: $crc_act" >> "$test_name.failed"
		echo "offset_exp: $offset_exp" >> "$test_name.failed"
		echo "offset_act: $offset_act" >> "$test_name.failed"
		echo "compat_exp: $compat_exp" >> "$test_name.failed"
		echo "compat_act: $compat_act" >> "$test_name.failed"
	fi
}

init_fs() {
	echo "#" >> "$OUT"
	echo "# init fs for $1" >> "$OUT"
	echo "#" >> "$OUT"
	rm -f "$TDB_FILE"
	dd if=/dev/zero of="$TMPFILE" bs=1k count=1024 > /dev/null 2>&1
	$MKE2FS -F -z "$TDB_FILE" -b 1024 -E offset=524288 "$TMPFILE" 512 \
		>> "$OUT" 2>&1
}

#
# test absence of the "-o N" option
#
test_e2undo_offset_no_option() {
	init_fs "test_e2undo_offset_no_option"

	$E2UNDO "$TDB_FILE" "$TMPFILE" >> "$OUT" 2>&1

	crc_exp=`dd if=/dev/zero bs=1k count=1024 2>/dev/null | $CRCSUM`
	crc_act=`$CRCSUM "$TMPFILE"`
	offset_exp=524288
	offset_act=`read_header_offset`
	compat_exp=$E2UNDO_FEATURE_COMPAT_OFFSET
	compat_act=`read_header_compat`
	e2undo_offset_assert "test_e2undo_offset_no_option"
}

#
# test removal of the offset feature in the undo header
#
test_e2undo_offset_no_option_remove_offset_header() {
	init_fs "test_e2undo_offset_no_option_remove_offset_header"
	dd if="$TMPFILE" of="$TMPFILE2" bs=1k count=512 skip=512 \
		> /dev/null 2>&1
	# offset feature will be removed from the undo header
	$TUNE2FS -z "$TDB_FILE" -C 42 "$TMPFILE2" >> "$OUT" 2>&1

	$E2UNDO "$TDB_FILE" "$TMPFILE2" >> "$OUT" 2>&1

	crc_exp=`dd if=/dev/zero bs=1k count=512 2>/dev/null | $CRCSUM`
	crc_act=`$CRCSUM "$TMPFILE2"`
	offset_exp=
	offset_act=`read_header_offset`
	compat_exp=0
	compat_act=`read_header_compat`
	e2undo_offset_assert "test_e2undo_offset_no_option_remove_offset_header"
}

#
# test "-o 4096"
#
test_e2undo_offset_4096() {
	init_fs "test_e2undo_offset_4096"
	dd if=/dev/zero of="$TMPFILE2" bs=1k count=4 > /dev/null 2>&1
	dd if="$TMPFILE" of="$TMPFILE2" bs=1k count=512 skip=512 seek=4 \
		> /dev/null 2>&1

	$E2UNDO -o 4096 "$TDB_FILE" "$TMPFILE2" >> "$OUT" 2>&1

	crc_exp=`dd if=/dev/zero bs=1k count=516 2>/dev/null | $CRCSUM`
	crc_act=`$CRCSUM "$TMPFILE2"`
	# the same as in test_e2undo_offset_no_option
	offset_exp=524288
	offset_act=`read_header_offset`
	compat_exp=$E2UNDO_FEATURE_COMPAT_OFFSET
	compat_act=`read_header_compat`
	e2undo_offset_assert "test_e2undo_offset_4096"
}

#
# test "-o 0"
#
test_e2undo_offset_0() {
	init_fs "test_e2undo_offset_0"
	dd if="$TMPFILE" of="$TMPFILE2" bs=1k count=512 skip=512 \
		> /dev/null 2>&1

	$E2UNDO -o 0 "$TDB_FILE" "$TMPFILE2" >> "$OUT" 2>&1

	crc_exp=`dd if=/dev/zero bs=1k count=512 2>/dev/null | $CRCSUM`
	crc_act=`$CRCSUM "$TMPFILE2"`
	# the same as in test_e2undo_offset_no_option
	offset_exp=524288
	offset_act=`read_header_offset`
	compat_exp=$E2UNDO_FEATURE_COMPAT_OFFSET
	compat_act=`read_header_compat`
	e2undo_offset_assert "test_e2undo_offset_0"
}

test_e2undo_offset_no_option
test_e2undo_offset_no_option_remove_offset_header
test_e2undo_offset_4096
test_e2undo_offset_0

if [ -e "$test_name.failed" ]; then
	echo "$test_name: $test_description: failed"
else
	echo "$test_name: $test_description: ok"
	touch "$test_name.ok"
fi