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.
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
35 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
39 TESTDIR="${SCRATCH_MNT}/scratchdir"
40 TESTFILE="${TESTDIR}/testfile"
42 echo "+ create scratch fs"
43 _scratch_mkfs_ext4 > /dev/null 2>&1
44 dumpe2fs -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
46 echo "+ mount fs image"
49 echo "+ make some files"
51 for x in `seq 1 128`; do
52 touch "${SCRATCH_MNT}/junk.${x}"
53 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
54 if [ "$x" -gt 64 ] && [ "$((inode % 64))" -eq 0 ]; then
55 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
59 for x in `seq 2 64`; do
60 echo moo >> "${TESTFILE}.${x}"
62 umount "${SCRATCH_MNT}"
65 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
67 echo "+ corrupt image"
68 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
69 debugfs -w -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "group descriptor fuzz failed"
73 _try_scratch_mount 2> /dev/null && _fail "mount should not succeed"
76 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
77 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
79 echo "+ mount image (2)"
82 umount "${SCRATCH_MNT}"
85 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"