xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / ext4 / 008
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 008
6 #
7 # Create and populate an ext4 filesystem, corrupt a group descriptor, then
8 # see how the kernel and e2fsck deal with it.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     #rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/attr
29
30 # real QA test starts here
31 _supported_fs ext4
32
33 _require_scratch
34 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
35 _require_attrs
36
37 rm -f $seqres.full
38 TESTDIR="${SCRATCH_MNT}/scratchdir"
39 TESTFILE="${TESTDIR}/testfile"
40
41 echo "+ create scratch fs"
42 _scratch_mkfs_ext4 > /dev/null 2>&1
43 dumpe2fs -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
44
45 echo "+ mount fs image"
46 _scratch_mount
47
48 echo "+ make some files"
49 mkdir -p "${TESTDIR}"
50 for x in `seq 1 128`; do
51         touch "${SCRATCH_MNT}/junk.${x}"
52         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
53         if [ "$x" -gt 64 ] && [ "$((inode % 64))" -eq 0 ]; then
54                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
55                 break
56         fi
57 done
58 for x in `seq 2 64`; do
59         echo moo >> "${TESTFILE}.${x}"
60 done
61 umount "${SCRATCH_MNT}"
62
63 echo "+ check fs"
64 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
65
66 echo "+ corrupt image"
67 dumpe2fs -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($4) != -1) {print $4}}' | sed -e 's/-.*$//g' | awk '{if (int($1) > 0) {print $1}}' | while read blk; do
68         debugfs -w -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "group descriptor fuzz failed"
69 done
70
71 echo "+ mount image"
72 _try_scratch_mount 2> /dev/null && _fail "mount should not succeed"
73
74 echo "+ repair fs"
75 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
76 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
77
78 echo "+ mount image (2)"
79 _scratch_mount
80
81 umount "${SCRATCH_MNT}"
82
83 echo "+ check fs (2)"
84 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
85
86 status=0
87 exit