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 block bitmap, 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 _require_xfs_io_command "falloc"
36 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
40 TESTDIR="${SCRATCH_MNT}/scratchdir"
41 TESTFILE="${TESTDIR}/testfile"
43 echo "+ create scratch fs"
44 _scratch_mkfs_ext4 > /dev/null 2>&1
45 dumpe2fs -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
46 nr_groups="$(dumpe2fs -g "${SCRATCH_DEV}" 2> /dev/null | tail -n 1 | cut -d : -f 1)"
48 echo "+ mount fs image"
50 # abuse orlov allocator in the hopes that each bg ends up with some inodes
51 for i in `seq 1 $((nr_groups * 8))`; do
52 mkdir -p "${SCRATCH_MNT}/d_${i}"
54 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
55 freeblks="$(stat -f -c '%a' "${SCRATCH_MNT}")"
56 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile2" >> $seqres.full
57 umount "${SCRATCH_MNT}"
59 echo "+ make some files"
61 rm -rf "${SCRATCH_MNT}/bigfile2"
62 touch "${SCRATCH_MNT}/bigfile"
63 umount "${SCRATCH_MNT}"
66 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
68 echo "+ corrupt image"
69 dumpe2fs -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($5) > 0) {print $5}}' | while read blk; do
70 debugfs -w -n -R "zap_block -p 0xff ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "block bitmap fuzz failed"
77 b_bytes="$(stat -c '%B' "${SCRATCH_MNT}/bigfile")"
78 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
79 after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
80 echo "$((after * b_bytes))" lt "$((blksz * freeblks / 4))" >> $seqres.full
81 test "$((after * b_bytes))" -lt "$((blksz * freeblks / 4))" || _fail "falloc should fail"
82 umount "${SCRATCH_MNT}"
85 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
87 echo "+ mount image (2)"
90 echo "+ modify files (2)"
91 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
92 umount "${SCRATCH_MNT}"
95 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"