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