xfs: convert tests to SPDX license tags
[xfstests-dev.git] / tests / xfs / 341
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2016, Oracle and/or its affiliates.  All Rights Reserved.
4 #
5 # FS QA Test No. 341
6 #
7 # Cross-link file block into rtrmapbt and see if repair fixes it.
8 #
9 seq=`basename "$0"`
10 seqres="$RESULT_DIR/$seq"
11 echo "QA output created by $seq"
12
13 here=`pwd`
14 tmp=/tmp/$$
15 status=1    # failure is the default!
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -rf "$tmp".*
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26 . ./common/filter
27
28 # real QA test starts here
29 _supported_os Linux
30 _supported_fs xfs
31 _require_realtime
32 _require_xfs_scratch_rmapbt
33 _require_test_program "punch-alternating"
34 _disable_dmesg_check
35
36 rm -f "$seqres.full"
37
38 echo "Format and mount"
39 _scratch_mkfs | _filter_mkfs 2>$tmp.mkfs >/dev/null
40 . $tmp.mkfs
41 cat $tmp.mkfs > "$seqres.full" 2>&1
42 _scratch_mount
43 blksz="$(_get_block_size $SCRATCH_MNT)"
44
45 # inode core size is at least 176 bytes; btree header is 56 bytes;
46 # rtrmap record is 32 bytes; and rtrmap key/pointer are 56 bytes.
47 i_ptrs=$(( (isize - 176) / 56 ))
48 bt_recs=$(( (blksz - 56) / 32 ))
49
50 blocks=$((i_ptrs * bt_recs + 1))
51 len=$((blocks * rtextsz))
52
53 echo "Create some files"
54 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f1 >> $seqres.full
55 $XFS_IO_PROG -f -R -c "falloc 0 $len" -c "pwrite -S 0x68 -b 1048576 0 $len" $SCRATCH_MNT/f2 >> $seqres.full
56 ./src/punch-alternating $SCRATCH_MNT/f1 >> "$seqres.full"
57 ./src/punch-alternating $SCRATCH_MNT/f2 >> "$seqres.full"
58 echo garbage > $SCRATCH_MNT/f3
59 ino=$(stat -c '%i' $SCRATCH_MNT/f3)
60 _scratch_unmount
61
62 echo "Corrupt fs"
63 fsbno=$(_scratch_xfs_db -c "inode $ino" -c 'bmap' | \
64         sed -e 's/^.*startblock \([0-9]*\) .*$/\1/g')
65
66 _scratch_xfs_db -x -c 'sb 0' -c 'addr rrmapino' \
67         -c "write u3.rtrmapbt.ptrs[1] $fsbno" -c 'p' >> $seqres.full
68 _scratch_mount
69
70 echo "Try to create more files"
71 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f5 >> $seqres.full 2>&1
72 test -e $SCRATCH_MNT/f5 && echo "should not have been able to write f5"
73
74 echo "Repair fs"
75 _scratch_unmount 2>&1 | _filter_scratch
76 _repair_scratch_fs >> $seqres.full 2>&1
77
78 echo "Try to create more files (again)"
79 _scratch_mount
80 $XFS_IO_PROG -f -R -c "pwrite -S 0x68 0 9999" $SCRATCH_MNT/f4 >> $seqres.full
81
82 # success, all done
83 status=0
84 exit