overlay: run unionmount testsuite test cases
[xfstests-dev.git] / tests / ext4 / 011
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 011
6 #
7 # Create and populate an ext4 filesystem, corrupt the MMP block, then
8 # see how the kernel and e2fsck deal with it.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     #rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/attr
29
30 # real QA test starts here
31 _supported_fs ext4
32 _supported_os Linux
33
34 _require_scratch
35 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
36 _require_attrs
37
38 rm -f $seqres.full
39 TESTDIR="${SCRATCH_MNT}/scratchdir"
40 TESTFILE="${TESTDIR}/testfile"
41
42 echo "+ create scratch fs"
43 _scratch_mkfs_ext4 -O mmp -E mmp_update_interval=2 > /dev/null 2>&1
44
45 echo "+ mount fs image"
46 _scratch_mount
47 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
48
49 echo "+ make some files"
50 echo moo > "${SCRATCH_MNT}/file0"
51 umount "${SCRATCH_MNT}"
52
53 echo "+ check fs"
54 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
55
56 echo "+ corrupt image"
57 blk="$(dumpe2fs "${SCRATCH_DEV}" 2> /dev/null | grep 'MMP block number' | sed -e 's/^MMP block number: *\([0-9]*\)$/\1/g')"
58 $XFS_IO_PROG -f -c "pwrite -S 0x62 $((blk * blksz + 16)) 8" "${SCRATCH_DEV}" >> $seqres.full
59
60 echo "+ mount image"
61 _try_scratch_mount 2> /dev/null && _fail "mount should fail due to bad MMP"
62
63 echo "+ repair fs"
64 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
65
66 echo "+ mount image (2)"
67 _try_scratch_mount || _fail "mount should not fail; MMP has been fixed"
68
69 echo "+ check fs (2)"
70 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
71
72 status=0
73 exit