check: use generated group files
[xfstests-dev.git] / tests / ext4 / 015
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. 015
6 #
7 # Create and populate an ext4 filesystem, corrupt an extent tree block, then
8 # see how the kernel and e2fsck deal with it.
9 #
10 . ./common/preamble
11 _begin_fstest fuzzers punch
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_xfs_io_command "falloc"
28 _require_xfs_io_command "fpunch"
29 _require_scratch
30 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
31 _require_attrs
32
33 TESTDIR="${SCRATCH_MNT}/scratchdir"
34 TESTFILE="${TESTDIR}/testfile"
35
36 echo "+ create scratch fs"
37 _scratch_mkfs_ext4 > /dev/null 2>&1
38
39 echo "+ mount fs image"
40 _scratch_mount
41 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
42 freeblks="$((3 * blksz / 12))"
43
44 echo "+ make some files"
45 $XFS_IO_PROG -f -c "falloc 0 $((blksz * freeblks))" "${SCRATCH_MNT}/bigfile" >> $seqres.full
46 seq 1 2 ${freeblks} | while read lblk; do
47         $XFS_IO_PROG -f -c "fpunch $((lblk * blksz)) ${blksz}" "${SCRATCH_MNT}/bigfile" >> $seqres.full
48 done
49 umount "${SCRATCH_MNT}"
50
51 echo "+ check fs"
52 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
53
54 echo "+ corrupt image"
55 debugfs "${SCRATCH_DEV}" -R 'ex /bigfile' 2> /dev/null | grep '^ 0' | awk '{print $8}' | while read blk; do
56         $XFS_IO_PROG -f -c "pwrite -S 0x62 $((blk * blksz + 8)) 8" "${SCRATCH_DEV}" >> $seqres.full
57 done
58
59 echo "+ mount image"
60 _scratch_mount
61
62 echo "+ modify files"
63 echo moo >> "${SCRATCH_MNT}/bigfile" 2> /dev/null && _fail "extent tree should be corrupt"
64 umount "${SCRATCH_MNT}"
65
66 echo "+ repair fs"
67 e2fsck -fy "${SCRATCH_DEV}" >> $seqres.full 2>&1
68
69 echo "+ mount image (2)"
70 _scratch_mount
71
72 echo "+ modify files (2)"
73 $XFS_IO_PROG -f -c "pwrite ${blksz} ${blksz}" "${SCRATCH_MNT}/bigfile" >> $seqres.full
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