• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/sh
2
3# old distros are missing "truncate", emulate it with "dd"
4truncate()
5{
6	[ "$1" = "-s" ] && size=$2 && shift 2
7
8	dd if=/dev/zero of=$1 bs=1 count=0 seek=$size >> $LOG 2>&1
9}
10
11resize_test () {
12DBG_FLAGS=63
13
14echo $test_description starting > $LOG
15rm -f $TMPFILE
16touch $TMPFILE
17
18# Verify that the $TMP filesystem handles $SIZE_2 sparse files.
19# If that fails, try the local filesystem instead.
20if truncate -s $SIZE_2 $TMPFILE 2> /dev/null; then
21	echo "using $TMPFILE" >> $LOG
22else
23	rm $TMPFILE
24	export TMPFILE=$(mktemp ./$test_name.tmp.XXXXXX)
25	touch $TMPFILE
26	echo "using $TMPFILE" >> $LOG
27	if ! truncate -s $SIZE_2 $TMPFILE >> $LOG 2>&1; then
28		rm $TMPFILE
29		return 111
30	fi
31fi
32> $TMPFILE
33
34echo $MKE2FS $FEATURES -qF $TMPFILE $SIZE_1 >> $LOG
35$MKE2FS $FEATURES -qF $TMPFILE $SIZE_1 >> $LOG
36
37OUT_TMP=$(mktemp ${TMPDIR:-/tmp}/csum-tmp.XXXXXX)
38
39date > $OUT_TMP
40cat $E2FSCK >> $OUT_TMP
41echo $CRCSUM $OUT_TMP >> $LOG 2>&1
42CSUM_1=$($CRCSUM $OUT_TMP)
43echo Checksum is $CSUM_1 >> $LOG
44
45echo Setting up file system >> $LOG
46$DEBUGFS -w $TMPFILE  >> $LOG 2>&1 << EOF
47mkdir test
48cd test
49write $OUT_TMP e2fsck
50ls /test
51stat /test/e2fsck
52quit
53EOF
54echo " " >> $LOG
55
56rm -f $OUT_TMP
57
58echo $FSCK -fy $TMPFILE >> $LOG 2>&1
59$FSCK -fy $TMPFILE >> $LOG 2>&1
60
61echo $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS $TMPFILE $SIZE_2 >> $LOG 2>&1
62if ! $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS $TMPFILE $SIZE_2 >> $LOG 2>&1
63then
64	return 1
65fi
66
67echo $FSCK -fy $TMPFILE >> $LOG 2>&1
68if ! $FSCK -fy $TMPFILE >> $LOG 2>&1
69then
70	$DUMPE2FS $TMPFILE >> $LOG
71	return 1
72fi
73
74echo $DEBUGFS -R "dump /test/e2fsck $OUT_TMP" $TMPFILE >> $LOG 2>&1
75$DEBUGFS -R "dump /test/e2fsck $OUT_TMP" $TMPFILE >> $LOG 2>&1
76
77echo $CRCSUM $OUT_TMP >> $LOG 2>&1
78CSUM_2=$($CRCSUM $OUT_TMP)
79echo Checksum is $CSUM_2 >> $LOG
80
81if test "$CSUM_1" != "$CSUM_2"
82then
83	return 1
84fi
85
86# Uncomment to grab extra debugging image
87#
88#mv $TMPFILE /tmp/foo.img
89#return 0
90
91echo $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS -M $TMPFILE $SIZE_2 >> $LOG 2>&1
92if ! $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS -M $TMPFILE $SIZE_2 >> $LOG 2>&1
93then
94	return 1
95fi
96
97echo $FSCK -fy $TMPFILE >> $LOG 2>&1
98if ! $FSCK -fy $TMPFILE >> $LOG 2>&1
99then
100	$DUMPE2FS $TMPFILE >> $LOG
101	return 1
102fi
103
104echo $DEBUGFS -R "dump /test/e2fsck $OUT_TMP" $TMPFILE >> $LOG 2>&1
105$DEBUGFS -R "dump /test/e2fsck $OUT_TMP" $TMPFILE >> $LOG 2>&1
106
107echo $CRCSUM $OUT_TMP >> $LOG 2>&1
108CSUM_2=$($CRCSUM $OUT_TMP)
109echo Checksum is $CSUM_2 >> $LOG
110
111if test "$CSUM_1" != "$CSUM_2"
112then
113	return 1
114fi
115
116echo $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS -M $TMPFILE $SIZE_2 >> $LOG 2>&1
117if ! $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS -M $TMPFILE $SIZE_2 >> $LOG 2>&1
118then
119	return 1
120fi
121
122echo $FSCK -fy $TMPFILE >> $LOG 2>&1
123if ! $FSCK -fy $TMPFILE >> $LOG 2>&1
124then
125	$DUMPE2FS $TMPFILE >> $LOG
126	return 1
127fi
128
129echo $DEBUGFS -R "dump /test/e2fsck $OUT_TMP" $TMPFILE >> $LOG 2>&1
130$DEBUGFS -R "dump /test/e2fsck $OUT_TMP" $TMPFILE >> $LOG 2>&1
131
132echo $CRCSUM $OUT_TMP >> $LOG 2>&1
133CSUM_2=$($CRCSUM $OUT_TMP)
134echo Checksum is $CSUM_2 >> $LOG
135
136if test "$CSUM_1" != "$CSUM_2"
137then
138	return 1
139fi
140
141echo $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS -M $TMPFILE $SIZE_2 >> $LOG 2>&1
142if ! $RESIZE2FS $RESIZE2FS_OPTS -d $DBG_FLAGS -M $TMPFILE $SIZE_2 >> $LOG 2>&1
143then
144	return 1
145fi
146
147echo $FSCK -fy $TMPFILE >> $LOG 2>&1
148if ! $FSCK -fy $TMPFILE >> $LOG 2>&1
149then
150	$DUMPE2FS $TMPFILE >> $LOG
151	return 1
152fi
153
154echo $DEBUGFS -R "dump /test/e2fsck $OUT_TMP" $TMPFILE >> $LOG 2>&1
155$DEBUGFS -R "dump /test/e2fsck $OUT_TMP" $TMPFILE >> $LOG 2>&1
156
157echo $CRCSUM $OUT_TMP >> $LOG 2>&1
158CSUM_2=$($CRCSUM $OUT_TMP)
159echo Checksum is $CSUM_2 >> $LOG
160
161rm $OUT_TMP
162unset OUT_TMP
163
164rm -f $TMPFILE
165
166if test "$CSUM_1" != "$CSUM_2"
167then
168	return 1
169fi
170
171return 0
172
173}
174