2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an ext4 filesystem, corrupt the MMP block, 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 -O mmp -E mmp_update_interval=2 > /dev/null 2>&1
37 echo "+ mount fs image"
39 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
41 echo "+ make some files"
42 echo moo > "${SCRATCH_MNT}/file0"
43 umount "${SCRATCH_MNT}"
46 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
48 echo "+ corrupt image"
49 blk="$(dumpe2fs "${SCRATCH_DEV}" 2> /dev/null | grep 'MMP block number' | sed -e 's/^MMP block number: *\([0-9]*\)$/\1/g')"
50 $XFS_IO_PROG -f -c "pwrite -S 0x62 $((blk * blksz + 16)) 8" "${SCRATCH_DEV}" >> $seqres.full
53 _try_scratch_mount 2> /dev/null && _fail "mount should fail due to bad MMP"
56 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
58 echo "+ mount image (2)"
59 _try_scratch_mount || _fail "mount should not fail; MMP has been fixed"
62 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"