2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an ext4 filesystem, corrupt a htree block, 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
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"
47 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
49 echo "+ make some files"
50 mkdir -p "${SCRATCH_MNT}/test/"
51 for x in `seq 1 $((blksz * 4 / 256))`; do
52 fname="$(printf "%.255s\n" "$(perl -e "print \"${x}_\" x 500;")")"
53 touch "${SCRATCH_MNT}/test/${fname}"
55 umount "${SCRATCH_MNT}"
58 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
60 echo "+ corrupt image"
61 debugfs -w -R "zap -f /test 0" "${SCRATCH_DEV}" 2> /dev/null
67 mkdir -p "${SCRATCH_MNT}/test/newdir" 2> /dev/null && _fail "htree should be corrupt"
68 umount "${SCRATCH_MNT}"
71 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
73 echo "+ mount image (2)"
76 echo "+ modify dirs (2)"
77 mkdir -p "${SCRATCH_MNT}/test/newdir" || _fail "htree should not be corrupt"
78 umount "${SCRATCH_MNT}"
81 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"