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 inode bitmap, 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
29 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
31 _require_command "$RESIZE2FS_PROG" resize2fs
33 TESTDIR="${SCRATCH_MNT}/scratchdir"
34 TESTFILE="${TESTDIR}/testfile"
36 echo "+ create scratch fs"
37 _scratch_mkfs_ext4 > /dev/null 2>&1
38 $DUMPE2FS_PROG -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
39 $RESIZE2FS_PROG -M "${SCRATCH_DEV}" >> $seqres.full 2>&1
40 nr_groups="$($DUMPE2FS_PROG -g "${SCRATCH_DEV}" 2> /dev/null | tail -n 1 | cut -d : -f 1)"
42 echo "+ mount fs image"
45 echo "+ make some files"
46 # abuse orlov allocator in the hopes that each bg ends up with some inodes
47 for i in `seq 1 $((nr_groups * 8))`; do
48 mkdir -p "${SCRATCH_MNT}/d_${i}"
50 umount "${SCRATCH_MNT}"
53 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
55 echo "+ corrupt image"
56 $DUMPE2FS_PROG -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($6) > 0) {print $6}}' | while read blk; do
57 debugfs -w -n -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "inode bitmap fuzz failed"
64 touch "${SCRATCH_MNT}/file0" > /dev/null 2>&1 && _fail "touch should fail"
65 umount "${SCRATCH_MNT}"
68 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
70 echo "+ mount image (2)"
73 echo "+ modify files (2)"
74 touch "${SCRATCH_MNT}/file1"
75 umount "${SCRATCH_MNT}"
78 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"