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