xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 085
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. 085
6 #
7 # Create and populate an XFS filesystem, corrupt a superblock, then see how
8 # the kernel and xfs_repair 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 . ./common/populate
24
25 # real QA test starts here
26 _supported_fs xfs
27
28 _require_scratch
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
30 _require_attrs
31 _require_populate_commands
32 _require_xfs_db_blocktrash_z_command
33
34 TESTDIR="${SCRATCH_MNT}/scratchdir"
35 TESTFILE="${TESTDIR}/testfile"
36
37 echo "+ create scratch fs"
38 _scratch_mkfs_xfs > /dev/null
39
40 echo "+ mount fs image"
41 _scratch_mount
42 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
43
44 echo "+ make some files"
45 mkdir -p "${TESTDIR}"
46 for x in `seq 1 1024`; do
47         touch "${SCRATCH_MNT}/junk.${x}"
48         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
49         if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
50                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
51                 break
52         fi
53 done
54 for x in `seq 2 64`; do
55         touch "${TESTFILE}.${x}"
56 done
57 inode="$(stat -c '%i' "${TESTFILE}.1")"
58 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
59 umount "${SCRATCH_MNT}"
60
61 echo "+ check fs"
62 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
63
64 echo "+ corrupt image"
65 $XFS_IO_PROG -f -c "pwrite -S 0x62 32 4" "${SCRATCH_DEV}" >> $seqres.full
66
67 echo "+ mount image"
68 _try_scratch_mount 2>/dev/null && _fail "mount should not succeed"
69
70 echo "+ repair fs"
71 _repair_scratch_fs >> $seqres.full 2>&1
72
73 echo "+ mount image (2)"
74 _scratch_mount
75
76 echo "+ chattr -R -i"
77 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
78
79 echo "+ modify files (2)"
80 broken=0
81 for x in `seq 1 64`; do
82         test -e "${TESTFILE}.${x}" || continue
83         echo moo | dd oflag=append conv=notrunc of="${TESTFILE}.${x}" 2>/dev/null
84         test $? -ne 0 && broken=1
85 done
86 echo "broken: ${broken}"
87 umount "${SCRATCH_MNT}"
88
89 echo "+ check fs (2)"
90 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
91
92 status=0
93 exit