• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash
2
3typeset -i I ITERATIONS PHASE LOC COUNT MAXCOUNT
4
5ME=`basename $0`
6
7if [ "$#" -ne 3 ]
8then
9  echo "$ME: Usage: $ME <iterations> <maxcount> <filesystem_image>" >&2
10  exit 1;
11fi
12
13ITERATIONS="$1"
14MAXCOUNT="$2"
15ORIG_FS_IMAGE="$3"
16FIXED_FS_IMAGE="/tmp/fixedfsimage.$$"
17NEW_FS_IMAGE="/tmp/newfsimage.$$"
18
19if [ ! -f "$ORIG_FS_IMAGE" ]
20then
21  echo "$ME: Filesystem image $NEW_FS_IMAGE does not exist" >&2
22  exit 1
23fi
24
25trap "rm -f $NEW_FS_IMAGE $FIXED_FS_IMAGE" 0 1 2 3 15
26
27rm -f "$NEW_FS_IMAGE" "$FIXED_FS_IMAGE"
28
29# Create the fixed image to compare against
30cp "$ORIG_FS_IMAGE" "$FIXED_FS_IMAGE"
31ext4fixup "$FIXED_FS_IMAGE"
32
33if [ "$?" -ne 0 ]
34then
35  echo "$ME: ext4fixup failed!\n"
36  exit 1
37fi
38
39I=0
40while [ "$I" -lt "$ITERATIONS" ]
41do
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++
70done
71
72