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 extent tree block, then
8 # see how the kernel and e2fsck deal with it.
11 _begin_fstest fuzzers punch
13 # Override the default cleanup function.
20 # Import common functions.
24 # real QA test starts here
27 _require_xfs_io_command "falloc"
28 _require_xfs_io_command "fpunch"
30 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
33 TESTDIR="${SCRATCH_MNT}/scratchdir"
34 TESTFILE="${TESTDIR}/testfile"
36 echo "+ create scratch fs"
37 _scratch_mkfs_ext4 > /dev/null 2>&1
39 echo "+ mount fs image"
41 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
42 freeblks="$((3 * blksz / 12))"
44 echo "+ make some files"
45 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
46 seq 1 2 ${freeblks} | while read lblk; do
47 $XFS_IO_PROG -f -c "fpunch $((lblk * blksz)) ${blksz}" "${SCRATCH_MNT}/bigfile" >> $seqres.full
49 umount "${SCRATCH_MNT}"
52 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
54 echo "+ corrupt image"
55 debugfs "${SCRATCH_DEV}" -R 'ex /bigfile' 2> /dev/null | grep '^ 0' | awk '{print $8}' | while read blk; do
56 $XFS_IO_PROG -f -c "pwrite -S 0x62 $((blk * blksz + 8)) 8" "${SCRATCH_DEV}" >> $seqres.full
63 echo moo >> "${SCRATCH_MNT}/bigfile" 2> /dev/null && _fail "extent tree should be corrupt"
64 umount "${SCRATCH_MNT}"
67 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
69 echo "+ mount image (2)"
72 echo "+ modify files (2)"
73 $XFS_IO_PROG -f -c "pwrite ${blksz} ${blksz}" "${SCRATCH_MNT}/bigfile" >> $seqres.full
74 umount "${SCRATCH_MNT}"
77 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"