2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an ext4 filesystem, corrupt an inode, then see how
8 # the kernel and e2fsck deal with it.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
30 # real QA test starts here
35 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
39 TESTDIR="${SCRATCH_MNT}/scratchdir"
40 TESTFILE="${TESTDIR}/testfile"
42 echo "+ create scratch fs"
43 _scratch_mkfs_ext4 > /dev/null 2>&1
45 echo "+ mount fs image"
48 echo "+ make some files"
50 for x in `seq 1 1024`; do
51 touch "${SCRATCH_MNT}/junk.${x}"
52 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
53 if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
54 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
58 for x in `seq 2 64`; do
59 touch "${TESTFILE}.${x}"
61 inode="$(stat -c '%i' "${TESTFILE}.1")"
62 umount "${SCRATCH_MNT}"
65 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
67 echo "+ corrupt image"
68 blk="$(debugfs -R "imap <$inode>" "${SCRATCH_DEV}" 2> /dev/null | grep located | sed -e 's/^.*block \([0-9]*\),.*$/\1/g')"
69 debugfs -w -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "inode fuzz failed"
76 for x in `seq 1 64`; do
77 #test -e "${TESTFILE}.${x}" || continue
78 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
79 test $? -ne 0 && broken=1
80 echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
81 test $? -ne 0 && broken=1
83 echo "broken: ${broken}"
84 umount "${SCRATCH_MNT}"
87 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
89 echo "+ mount image (2)"
93 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
95 echo "+ modify files (2)"
97 for x in `seq 1 64`; do
98 test -e "${TESTFILE}.${x}" || continue
99 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
100 test $? -ne 0 && broken=1
101 echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
102 test $? -ne 0 && broken=1
104 echo "broken: ${broken}"
105 umount "${SCRATCH_MNT}"
107 echo "+ check fs (2)"
108 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"