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
34 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
38 TESTDIR="${SCRATCH_MNT}/scratchdir"
39 TESTFILE="${TESTDIR}/testfile"
41 echo "+ create scratch fs"
42 _scratch_mkfs_ext4 > /dev/null 2>&1
44 echo "+ mount fs image"
47 echo "+ make some files"
49 for x in `seq 1 1024`; do
50 touch "${SCRATCH_MNT}/junk.${x}"
51 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
52 if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
53 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
57 for x in `seq 2 64`; do
58 touch "${TESTFILE}.${x}"
60 inode="$(stat -c '%i' "${TESTFILE}.1")"
61 umount "${SCRATCH_MNT}"
64 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
66 echo "+ corrupt image"
67 blk="$(debugfs -R "imap <$inode>" "${SCRATCH_DEV}" 2> /dev/null | grep located | sed -e 's/^.*block \([0-9]*\),.*$/\1/g')"
68 debugfs -w -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "inode fuzz failed"
75 for x in `seq 1 64`; do
76 #test -e "${TESTFILE}.${x}" || continue
77 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
78 test $? -ne 0 && broken=1
79 echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
80 test $? -ne 0 && broken=1
82 echo "broken: ${broken}"
83 umount "${SCRATCH_MNT}"
86 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
88 echo "+ mount image (2)"
92 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
94 echo "+ modify files (2)"
96 for x in `seq 1 64`; do
97 test -e "${TESTFILE}.${x}" || continue
98 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
99 test $? -ne 0 && broken=1
100 echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
101 test $? -ne 0 && broken=1
103 echo "broken: ${broken}"
104 umount "${SCRATCH_MNT}"
106 echo "+ check fs (2)"
107 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"