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