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.
13 # Override the default cleanup function.
20 # Import common functions.
24 # real QA test starts here
28 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
31 TESTDIR="${SCRATCH_MNT}/scratchdir"
32 TESTFILE="${TESTDIR}/testfile"
34 echo "+ create scratch fs"
35 _scratch_mkfs_ext4 > /dev/null 2>&1
37 echo "+ mount fs image"
40 echo "+ make some files"
42 for x in `seq 1 128`; do
43 touch "${SCRATCH_MNT}/junk.${x}"
44 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
45 if [ "$x" -gt 64 ] && [ "$((inode % 64))" -eq 0 ]; then
46 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
50 for x in `seq 2 64`; do
51 touch "${TESTFILE}.${x}"
53 umount "${SCRATCH_MNT}"
56 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
58 echo "+ corrupt image"
59 debugfs -w -R "zap -f / 0" "${SCRATCH_DEV}" >> $seqres.full 2>&1
66 for x in `seq 1 64`; do
67 #test -e "${TESTFILE}.${x}" || continue
68 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
69 test $? -ne 0 && broken=1
70 echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
71 test $? -ne 0 && broken=1
73 echo "broken: ${broken}"
74 umount "${SCRATCH_MNT}"
77 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1 && _fail "e2fsck should not succeed"
79 echo "+ mount image (2)"
83 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
85 echo "+ modify files (2)"
87 for x in `seq 1 64`; do
88 test -e "${TESTFILE}.${x}" || continue
89 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
90 test $? -ne 0 && broken=1
91 echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
92 test $? -ne 0 && broken=1
94 echo "broken: ${broken}"
95 umount "${SCRATCH_MNT}"
98 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"