fstests: move test group info to test files
[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 . ./common/preamble
11 _begin_fstest fuzzers
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16     cd /
17     #rm -f $tmp.*
18 }
19
20 # Import common functions.
21 . ./common/filter
22 . ./common/attr
23
24 # real QA test starts here
25 _supported_fs ext4
26
27 _require_scratch
28 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
29 _require_attrs
30
31 TESTDIR="${SCRATCH_MNT}/scratchdir"
32 TESTFILE="${TESTDIR}/testfile"
33
34 echo "+ create scratch fs"
35 _scratch_mkfs_ext4 > /dev/null 2>&1
36
37 echo "+ mount fs image"
38 _scratch_mount
39
40 echo "+ make some files"
41 mkdir -p "${TESTDIR}"
42 for x in `seq 1 128`; do
43         touch "${SCRATCH_MNT}/junk.${x}"
44         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
45         if [ "$x" -gt 64 ] && [ "$((inode % 64))" -eq 0 ]; then
46                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
47                 break
48         fi
49 done
50 for x in `seq 2 64`; do
51         touch "${TESTFILE}.${x}"
52 done
53 umount "${SCRATCH_MNT}"
54
55 echo "+ check fs"
56 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
57
58 echo "+ corrupt image"
59 debugfs -w -R "zap -f / 0" "${SCRATCH_DEV}" >> $seqres.full 2>&1
60
61 echo "+ mount image"
62 _scratch_mount
63
64 echo "+ modify files"
65 broken=0
66 for x in `seq 1 64`; do
67         #test -e "${TESTFILE}.${x}" || continue
68         stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
69         test $? -ne 0 && broken=1
70         echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
71         test $? -ne 0 && broken=1
72 done
73 echo "broken: ${broken}"
74 umount "${SCRATCH_MNT}"
75
76 echo "+ repair fs"
77 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1 && _fail "e2fsck should not succeed"
78
79 echo "+ mount image (2)"
80 _scratch_mount
81
82 echo "+ chattr -R -i"
83 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
84
85 echo "+ modify files (2)"
86 broken=0
87 for x in `seq 1 64`; do
88         test -e "${TESTFILE}.${x}" || continue
89         stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
90         test $? -ne 0 && broken=1
91         echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
92         test $? -ne 0 && broken=1
93 done
94 echo "broken: ${broken}"
95 umount "${SCRATCH_MNT}"
96
97 echo "+ check fs (2)"
98 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
99
100 status=0
101 exit