generic: test for creating duplicate filenames in encrypted dir
[xfstests-dev.git] / tests / ext4 / 013
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. 013
6 #
7 # Create and populate an ext4 filesystem, corrupt an inode, then see how
8 # 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 1024`; do
50         touch "${SCRATCH_MNT}/junk.${x}"
51         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
52         if [ "$x" -gt 512 ] && [ "$((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 inode="$(stat -c '%i' "${TESTFILE}.1")"
61 umount "${SCRATCH_MNT}"
62
63 echo "+ check fs"
64 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
65
66 echo "+ corrupt image"
67 blk="$(debugfs -R "imap <$inode>" "${SCRATCH_DEV}" 2> /dev/null | grep located | sed -e 's/^.*block \([0-9]*\),.*$/\1/g')"
68 debugfs -w -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "inode fuzz failed"
69
70 echo "+ mount image"
71 _scratch_mount
72
73 echo "+ modify files"
74 broken=0
75 for x in `seq 1 64`; do
76         #test -e "${TESTFILE}.${x}" || continue
77         stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
78         test $? -ne 0 && broken=1
79         echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
80         test $? -ne 0 && broken=1
81 done
82 echo "broken: ${broken}"
83 umount "${SCRATCH_MNT}"
84
85 echo "+ repair fs"
86 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
87
88 echo "+ mount image (2)"
89 _scratch_mount
90
91 echo "+ chattr -R -i"
92 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
93
94 echo "+ modify files (2)"
95 broken=0
96 for x in `seq 1 64`; do
97         test -e "${TESTFILE}.${x}" || continue
98         stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
99         test $? -ne 0 && broken=1
100         echo moo | dd oflag=append of="${TESTFILE}.${x}" 2>/dev/null
101         test $? -ne 0 && broken=1
102 done
103 echo "broken: ${broken}"
104 umount "${SCRATCH_MNT}"
105
106 echo "+ check fs (2)"
107 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
108
109 status=0
110 exit