generic: test for creating duplicate filenames in encrypted dir
[xfstests-dev.git] / tests / ext4 / 009
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. 009
6 #
7 # Create and populate an ext4 filesystem, corrupt a block bitmap, 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_xfs_io_command "falloc"
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 > /dev/null 2>&1
44 dumpe2fs -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
45 nr_groups="$(dumpe2fs -g "${SCRATCH_DEV}" 2> /dev/null | tail -n 1 | cut -d : -f 1)"
46
47 echo "+ mount fs image"
48 _scratch_mount
49 # abuse orlov allocator in the hopes that each bg ends up with some inodes
50 for i in `seq 1 $((nr_groups * 8))`; do
51         mkdir -p "${SCRATCH_MNT}/d_${i}"
52 done
53 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
54 freeblks="$(stat -f -c '%a' "${SCRATCH_MNT}")"
55 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile2" >> $seqres.full
56 umount "${SCRATCH_MNT}"
57
58 echo "+ make some files"
59 _scratch_mount
60 rm -rf "${SCRATCH_MNT}/bigfile2"
61 touch "${SCRATCH_MNT}/bigfile"
62 umount "${SCRATCH_MNT}"
63
64 echo "+ check fs"
65 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
66
67 echo "+ corrupt image"
68 dumpe2fs -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($5) > 0) {print $5}}' | while read blk; do
69         debugfs -w -n -R "zap_block -p 0xff ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "block bitmap fuzz failed"
70 done
71
72 echo "+ mount image"
73 _scratch_mount
74
75 echo "+ modify files"
76 b_bytes="$(stat -c '%B' "${SCRATCH_MNT}/bigfile")"
77 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full 2> /dev/null
78 after="$(stat -c '%b' "${SCRATCH_MNT}/bigfile")"
79 echo "$((after * b_bytes))" lt "$((blksz * freeblks / 4))" >> $seqres.full
80 test "$((after * b_bytes))" -lt "$((blksz * freeblks / 4))" || _fail "falloc should fail"
81 umount "${SCRATCH_MNT}"
82
83 echo "+ repair fs"
84 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
85
86 echo "+ mount image (2)"
87 _scratch_mount
88
89 echo "+ modify files (2)"
90 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
91 umount "${SCRATCH_MNT}"
92
93 echo "+ check fs (2)"
94 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
95
96 status=0
97 exit