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 group descriptor, 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
36 dumpe2fs -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
38 echo "+ mount fs image"
41 echo "+ make some files"
43 for x in `seq 1 128`; do
44 touch "${SCRATCH_MNT}/junk.${x}"
45 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
46 if [ "$x" -gt 64 ] && [ "$((inode % 64))" -eq 0 ]; then
47 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
51 for x in `seq 2 64`; do
52 echo moo >> "${TESTFILE}.${x}"
54 umount "${SCRATCH_MNT}"
57 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
59 echo "+ corrupt image"
60 dumpe2fs -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($4) != -1) {print $4}}' | sed -e 's/-.*$//g' | awk '{if (int($1) > 0) {print $1}}' | while read blk; do
61 debugfs -w -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "group descriptor fuzz failed"
65 _try_scratch_mount 2> /dev/null && _fail "mount should not succeed"
68 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
69 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
71 echo "+ mount image (2)"
74 umount "${SCRATCH_MNT}"
77 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"