common/rc: add _scratch_{u}mount_idmapped() helpers
[xfstests-dev.git] / tests / ext4 / 017
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. 017
6 #
7 # Create and populate an ext4 filesystem, corrupt a htree 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
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 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
47
48 echo "+ make some files"
49 mkdir -p "${SCRATCH_MNT}/test/"
50 for x in `seq 1 $((blksz * 4 / 256))`; do
51         fname="$(printf "%.255s\n" "$(perl -e "print \"${x}_\" x 500;")")"
52         touch "${SCRATCH_MNT}/test/${fname}"
53 done
54 umount "${SCRATCH_MNT}"
55
56 echo "+ check fs"
57 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
58
59 echo "+ corrupt image"
60 debugfs -w -R "zap -f /test 0" "${SCRATCH_DEV}" 2> /dev/null
61
62 echo "+ mount image"
63 _scratch_mount
64
65 echo "+ modify dirs"
66 mkdir -p "${SCRATCH_MNT}/test/newdir" 2> /dev/null && _fail "htree should be corrupt"
67 umount "${SCRATCH_MNT}"
68
69 echo "+ repair fs"
70 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
71
72 echo "+ mount image (2)"
73 _scratch_mount
74
75 echo "+ modify dirs (2)"
76 mkdir -p "${SCRATCH_MNT}/test/newdir" || _fail "htree should not be corrupt"
77 umount "${SCRATCH_MNT}"
78
79 echo "+ check fs (2)"
80 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
81
82 status=0
83 exit