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.
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"
39 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
41 echo "+ make some files"
42 mkdir -p "${SCRATCH_MNT}/test/"
43 for x in `seq 1 $((blksz * 4 / 256))`; do
44 fname="$(printf "%.255s\n" "$(perl -e "print \"${x}_\" x 500;")")"
45 touch "${SCRATCH_MNT}/test/${fname}"
47 umount "${SCRATCH_MNT}"
50 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
52 echo "+ corrupt image"
53 debugfs -w -R "zap -f /test 0" "${SCRATCH_DEV}" 2> /dev/null
59 mkdir -p "${SCRATCH_MNT}/test/newdir" 2> /dev/null && _fail "htree should be corrupt"
60 umount "${SCRATCH_MNT}"
63 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
65 echo "+ mount image (2)"
68 echo "+ modify dirs (2)"
69 mkdir -p "${SCRATCH_MNT}/test/newdir" || _fail "htree should not be corrupt"
70 umount "${SCRATCH_MNT}"
73 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"