fstests: move test group info to test files
[xfstests-dev.git] / tests / ext4 / 008
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. 008
6 #
7 # Create and populate an ext4 filesystem, corrupt a group descriptor, 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 dumpe2fs -g "${SCRATCH_DEV}" > /dev/null 2>&1 || _notrun "dumpe2fs -g not supported"
37
38 echo "+ mount fs image"
39 _scratch_mount
40
41 echo "+ make some files"
42 mkdir -p "${TESTDIR}"
43 for x in `seq 1 128`; do
44         touch "${SCRATCH_MNT}/junk.${x}"
45         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
46         if [ "$x" -gt 64 ] && [ "$((inode % 64))" -eq 0 ]; then
47                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
48                 break
49         fi
50 done
51 for x in `seq 2 64`; do
52         echo moo >> "${TESTFILE}.${x}"
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 dumpe2fs -g "${SCRATCH_DEV}" 2>/dev/null | awk -F ':' '{if (int($4) != -1) {print $4}}' | sed -e 's/-.*$//g' | awk '{if (int($1) > 0) {print $1}}' | while read blk; do
61         debugfs -w -R "zap_block ${blk}" "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "group descriptor fuzz failed"
62 done
63
64 echo "+ mount image"
65 _try_scratch_mount 2> /dev/null && _fail "mount should not succeed"
66
67 echo "+ repair fs"
68 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
69 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
70
71 echo "+ mount image (2)"
72 _scratch_mount
73
74 umount "${SCRATCH_MNT}"
75
76 echo "+ check fs (2)"
77 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
78
79 status=0
80 exit