xfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 178
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2007 Silicon Graphics, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 178
6 #
7 # Reproduce PV#:967665
8 # Test if mkfs.xfs wipes old AG headers when using -f option
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 # dd the 1st sector then repair
25 _dd_repair_check()
26 {
27         #dd first sector
28         dd if=/dev/zero of=$1 bs=$2 count=1 2>&1 | _filter_dd
29         #xfs_repair
30         _scratch_xfs_repair 2>&1 | _filter_repair
31         #check repair
32         if _check_scratch_fs; then
33                 echo "repair passed"
34         else
35                 echo "repair failed!"
36         fi
37 }
38
39 # get standard environment, filters and checks
40 . ./common/rc
41 . ./common/filter
42 . ./common/repair
43
44 # real QA test starts here
45
46 # Modify as appropriate.
47 _supported_fs xfs
48 _supported_os Linux
49
50 # From the PV
51 # o Summary of testing:
52 #    1. mkfs.xfs a default filesystem, note agcount value.
53 #    2. dd zero first sector and repair and verify.
54 #    3. mkfs.xfs overriding agcount to a smaller value
55 #             (ie. each AG is bigger)
56 #    4. dd zero first sector, repair and verify.
57 #          -> old mkfs.xfs will cause repair to incorrectly
58 #             fix filesystem, new mkfs.xfs will be fine.
59
60 _require_scratch
61 _scratch_mkfs_xfs | _filter_mkfs 2>$tmp.mkfs \
62         || _fail "mkfs failed!"
63
64 # By executing the followint tmp file, will get on the mkfs options stored in
65 # variables
66 . $tmp.mkfs
67
68 # if the default agcount is too small, bump it up and re-mkfs before testing
69 if [ $agcount -lt 8 ]; then
70         agcount=8
71         _scratch_mkfs_xfs -dagcount=$agcount >/dev/null 2>&1 \
72                 || _notrun "Test requires at least 8 AGs."
73 fi
74
75 _dd_repair_check $SCRATCH_DEV $sectsz
76
77 # smaller AGCOUNT
78 let "agcount=$agcount-2"
79 _scratch_mkfs_xfs -dagcount=$agcount >/dev/null 2>&1 \
80         || _fail "mkfs failed!"
81
82 _dd_repair_check $SCRATCH_DEV $sectsz
83
84 # success, all done
85 status=0
86 exit