Home | History | Annotate | Download | only in ext4_utils
      1 #!/bin/bash
      2 
      3 typeset -i I ITERATIONS PHASE LOC COUNT MAXCOUNT
      4 
      5 ME=`basename $0`
      6 
      7 if [ "$#" -ne 3 ]
      8 then
      9   echo "$ME: Usage: $ME <iterations> <maxcount> <filesystem_image>" >&2
     10   exit 1;
     11 fi
     12 
     13 ITERATIONS="$1"
     14 MAXCOUNT="$2"
     15 ORIG_FS_IMAGE="$3"
     16 FIXED_FS_IMAGE="/tmp/fixedfsimage.$$"
     17 NEW_FS_IMAGE="/tmp/newfsimage.$$"
     18 
     19 if [ ! -f "$ORIG_FS_IMAGE" ]
     20 then
     21   echo "$ME: Filesystem image $NEW_FS_IMAGE does not exist" >&2
     22   exit 1
     23 fi
     24 
     25 trap "rm -f $NEW_FS_IMAGE $FIXED_FS_IMAGE" 0 1 2 3 15
     26 
     27 rm -f "$NEW_FS_IMAGE" "$FIXED_FS_IMAGE"
     28 
     29 # Create the fixed image to compare against
     30 cp "$ORIG_FS_IMAGE" "$FIXED_FS_IMAGE"
     31 ext4fixup "$FIXED_FS_IMAGE"
     32 
     33 if [ "$?" -ne 0 ]
     34 then
     35   echo "$ME: ext4fixup failed!\n"
     36   exit 1
     37 fi
     38 
     39 I=0
     40 while [ "$I" -lt "$ITERATIONS" ]
     41 do
     42   # There is also a phase 4, which is writing out the updated superblocks and
     43   # block group descriptors.  Test the with a separate script.
     44   let PHASE="$RANDOM"%3         # 0 to 2
     45   let PHASE++                   # 1 to 3
     46   let LOC="$RANDOM"%2           # 0 to 1
     47   let LOC++                     # 1 to 2
     48   let COUNT="$RANDOM"%"$MAXCOUNT"
     49 
     50   # Make a copy of the original image to fixup
     51   cp "$ORIG_FS_IMAGE" "$NEW_FS_IMAGE"
     52 
     53   # Run the fixup tool, but die partway through to see if we can recover
     54   ext4fixup -d "$PHASE,$LOC,$COUNT" "$NEW_FS_IMAGE" 2>/dev/null
     55  
     56   # run it again without -d to have it finish the job
     57   ext4fixup "$NEW_FS_IMAGE"
     58 
     59   if cmp "$FIXED_FS_IMAGE" "$NEW_FS_IMAGE"
     60   then
     61     :
     62   else
     63     echo "$ME: test failed with parameters $PHASE, $LOC, $COUNT"
     64     exit 1
     65   fi
     66 
     67   rm -f "$NEW_FS_IMAGE"
     68 
     69   let I++
     70 done
     71 
     72