2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an ext4 filesystem, corrupt root directory, then
8 # see how 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 128`; do
50 touch "${SCRATCH_MNT}/junk.${x}"
51 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
52 if [ "$x" -gt 64 ] && [ "$((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 umount "${SCRATCH_MNT}"
63 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
65 echo "+ corrupt image"
66 debugfs -w -R "zap -f / 0" "${SCRATCH_DEV}" >> $seqres.full 2>&1
73 for x in `seq 1 64`; do
74 #test -e "${TESTFILE}.${x}" || continue
75 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
76 test $? -ne 0 && broken=1
77 echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
78 test $? -ne 0 && broken=1
80 echo "broken: ${broken}"
81 umount "${SCRATCH_MNT}"
84 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1 && _fail "e2fsck should not succeed"
86 echo "+ mount image (2)"
90 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
92 echo "+ modify files (2)"
94 for x in `seq 1 64`; do
95 test -e "${TESTFILE}.${x}" || continue
96 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
97 test $? -ne 0 && broken=1
98 echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
99 test $? -ne 0 && broken=1
101 echo "broken: ${broken}"
102 umount "${SCRATCH_MNT}"
104 echo "+ check fs (2)"
105 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"