misc: move exit status into trap handler
[xfstests-dev.git] / tests / ext4 / 010
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. 010
6 #
7 # Create and populate an ext4 filesystem, corrupt an inode 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_scratch
34 _require_dumpe2fs
35 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
36 _require_attrs
37 _require_command "$RESIZE2FS_PROG" resize2fs
38
39 rm -f $seqres.full
40 TESTDIR="${SCRATCH_MNT}/scratchdir"
41 TESTFILE="${TESTDIR}/testfile"
42
43 echo "+ create scratch fs"
44 _scratch_mkfs_ext4 > /dev/null 2>&1
45 $DUMPE2FS_PROG -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
46 $RESIZE2FS_PROG -M "${SCRATCH_DEV}" >> $seqres.full 2>&1
47 nr_groups="$($DUMPE2FS_PROG -g "${SCRATCH_DEV}" 2> /dev/null | tail -n 1 | cut -d : -f 1)"
48
49 echo "+ mount fs image"
50 _scratch_mount
51
52 echo "+ make some files"
53 # abuse orlov allocator in the hopes that each bg ends up with some inodes
54 for i in `seq 1 $((nr_groups * 8))`; do
55         mkdir -p "${SCRATCH_MNT}/d_${i}"
56 done
57 umount "${SCRATCH_MNT}"
58
59 echo "+ check fs"
60 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
61
62 echo "+ corrupt image"
63 $DUMPE2FS_PROG -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($6) > 0) {print $6}}' | while read blk; do
64         debugfs -w -n -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "inode bitmap fuzz failed"
65 done
66
67 echo "+ mount image"
68 _scratch_mount
69
70 echo "+ modify files"
71 touch "${SCRATCH_MNT}/file0" > /dev/null 2>&1 && _fail "touch should fail"
72 umount "${SCRATCH_MNT}"
73
74 echo "+ repair fs"
75 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
76
77 echo "+ mount image (2)"
78 _scratch_mount
79
80 echo "+ modify files (2)"
81 touch "${SCRATCH_MNT}/file1"
82 umount "${SCRATCH_MNT}"
83
84 echo "+ check fs (2)"
85 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
86
87 status=0
88 exit