ext4/046: skip test when ext4 doesn't support bs < ps with dioread_nolock
[xfstests-dev.git] / tests / ext4 / 014
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. 014
6 #
7 # Create and populate an ext4 filesystem, corrupt root directory, 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
33 _require_scratch
34 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
35 _require_attrs
36
37 rm -f $seqres.full
38 TESTDIR="${SCRATCH_MNT}/scratchdir"
39 TESTFILE="${TESTDIR}/testfile"
40
41 echo "+ create scratch fs"
42 _scratch_mkfs_ext4 > /dev/null 2>&1
43
44 echo "+ mount fs image"
45 _scratch_mount
46
47 echo "+ make some files"
48 mkdir -p "${TESTDIR}"
49 for x in `seq 1 128`; do
50         touch "${SCRATCH_MNT}/junk.${x}"
51         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
52         if [ "$x" -gt 64 ] && [ "$((inode % 64))" -eq 0 ]; then
53                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
54                 break
55         fi
56 done
57 for x in `seq 2 64`; do
58         touch "${TESTFILE}.${x}"
59 done
60 umount "${SCRATCH_MNT}"
61
62 echo "+ check fs"
63 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
64
65 echo "+ corrupt image"
66 debugfs -w -R "zap -f / 0" "${SCRATCH_DEV}" >> $seqres.full 2>&1
67
68 echo "+ mount image"
69 _scratch_mount
70
71 echo "+ modify files"
72 broken=0
73 for x in `seq 1 64`; do
74         #test -e "${TESTFILE}.${x}" || continue
75         stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
76         test $? -ne 0 && broken=1
77         echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
78         test $? -ne 0 && broken=1
79 done
80 echo "broken: ${broken}"
81 umount "${SCRATCH_MNT}"
82
83 echo "+ repair fs"
84 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1 && _fail "e2fsck should not succeed"
85
86 echo "+ mount image (2)"
87 _scratch_mount
88
89 echo "+ chattr -R -i"
90 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
91
92 echo "+ modify files (2)"
93 broken=0
94 for x in `seq 1 64`; do
95         test -e "${TESTFILE}.${x}" || continue
96         stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
97         test $? -ne 0 && broken=1
98         echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
99         test $? -ne 0 && broken=1
100 done
101 echo "broken: ${broken}"
102 umount "${SCRATCH_MNT}"
103
104 echo "+ check fs (2)"
105 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
106
107 status=0
108 exit