"Fossies" - the Fresh Open Source Software Archive

Member "dosfstools-4.2/tests/test-fsck" (31 Jan 2021, 2322 Bytes) of package /linux/misc/dosfstools-4.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test-fsck": 4.1_vs_4.2.

    1 #!/bin/sh
    2 # Copyright (C) 2016  Andreas Bombe <aeb@debian.org>
    3 #
    4 # This program is free software: you can redistribute it and/or modify
    5 # it under the terms of the GNU General Public License as published by
    6 # the Free Software Foundation, either version 3 of the License, or
    7 # (at your option) any later version.
    8 #
    9 # This program is distributed in the hope that it will be useful,
   10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   12 # GNU General Public License for more details.
   13 #
   14 # You should have received a copy of the GNU General Public License
   15 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
   16 #
   17 #
   18 # This script expects a testname.fsck file as its sole argument. It must
   19 # be a hex dump that can be converted to a filesystem image with xxd.
   20 # fsck.fat is run on that image to attempt to fix the problem and then
   21 # it is run a second time to determine if the problem has been fixed.
   22 # The test fails if the first run does not detect an error or if the
   23 # second run still detects an error.
   24 
   25 
   26 run_fsck () {
   27     $RUN "../src/fsck.fat" "$@"
   28 }
   29 
   30 
   31 if [ $# -ne 1 ]; then
   32     echo "$0 called with wrong number of arguments"
   33     exit 99
   34 fi
   35 testname=$(basename "$1" .fsck)
   36 
   37 
   38 if [ "$XXD_FOUND" != "yes" ]; then
   39     echo "xxd not available, required by test"
   40     exit 77  # report test skipped
   41 fi
   42 
   43 
   44 if [ -f "$testname.args" ]; then
   45     ARGS=$(cat "$testname.args")
   46 else
   47     ARGS=
   48 fi
   49 
   50 echo "Test $testname"
   51 
   52 # make sure there aren't files remaining from earlier run
   53 rm -f "${testname}.img" "${testname}.refimg"
   54 
   55 xxd -r "${srcdir}/${testname}.fsck" "${testname}.img" || exit 99
   56 
   57 
   58 echo "First fsck run to check and fix error..."
   59 run_fsck -a $ARGS "${testname}.img"
   60 success=$?
   61 if [ $success -eq 0 ]; then
   62     echo "*** Error was not detected by fsck."
   63     success=100
   64 elif [ $success -eq 1 ]; then
   65     echo "Second fsck run to check if error was fixed..."
   66     run_fsck -n "${testname}.img"
   67     success=$?
   68 
   69     if [ $success -ne 0 ]; then
   70         echo "*** Error was not fixed by fsck."
   71     else
   72         echo "Comparing..."
   73         xxd -r "${srcdir}/${testname}.xxd" "${testname}.refimg" || exit 99
   74         cmp "${testname}.img" "${testname}.refimg"
   75         success=$?
   76 
   77         if [ $success -eq 2 ]; then
   78             # cmp reported error
   79             exit 99
   80         fi
   81     fi
   82 fi
   83 
   84 
   85 rm -f "${testname}.img" "${testname}.refimg"
   86 exit $success