xfs: force file creation to the data device for certain layout tests
[xfstests-dev.git] / tests / xfs / 001
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 SGI.  All Rights Reserved.
4 #
5 # FS QA Test No. 001
6 #
7 # Test the xfs_db write of the XFS BMBT entries. For each XFS BMBT field,
8 # write the value 0, each bit and finally the entry beyond the maximum legal
9 # value. Also makes sure a core write and hex input still work.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22     cd /
23     rm -f $tmp.*
24 }
25
26 _do_bit_test()
27 {
28         field="$1"
29         bits="$2"
30
31         echo "testing $field with $bits bits"
32         _scratch_xfs_db -x -c "inode $FILE_INO" -c "write $field 0"
33         num=1
34         for n in `seq 0 1 $bits`; do
35                 _scratch_xfs_db -x -c "inode $FILE_INO" \
36                           -c "write $field $num"
37                 let num=$num*2
38         done
39         echo
40 }
41
42 # get standard environment, filters and checks
43 . ./common/rc
44 . ./common/filter
45
46 # real QA test starts here
47
48 # Modify as appropriate.
49 _supported_fs xfs
50 _require_scratch_nocheck
51
52 _scratch_mkfs >/dev/null 2>&1
53 _scratch_mount
54
55 # create the test file
56 echo "make a file with data so it has an extent" > $SCRATCH_MNT/file
57
58 # find the inode for the test file
59 FILE_INO=`ls -i $SCRATCH_MNT |awk '{print $1}'`
60
61 _scratch_unmount
62
63 # test bit length constants
64 BMBT_EXNTFLAG_BITLEN=1
65 BMBT_STARTOFF_BITLEN=54
66 BMBT_STARTBLOCK_BITLEN=52
67 BMBT_BLOCKCOUNT_BITLEN=21
68
69 prefix=$(_scratch_get_bmx_prefix $FILE_INO)
70 test -n "$prefix" || _fail "could not find bmx prefix from inode $FILE_INO"
71
72 filter_output() {
73         sed -e "s/${prefix}/u.bmx/g"
74 }
75
76 # test setting the BMBT entries from 0 to past the valid number.
77 _do_bit_test "${prefix}[0].extentflag" $BMBT_EXNTFLAG_BITLEN | filter_output
78 _do_bit_test "${prefix}[0].startoff" $BMBT_STARTOFF_BITLEN | filter_output
79 _do_bit_test "${prefix}[0].startblock" $BMBT_STARTBLOCK_BITLEN | filter_output
80 _do_bit_test "${prefix}[0].blockcount" $BMBT_BLOCKCOUNT_BITLEN | filter_output
81 # test setting the 32 bit generation number
82 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen 0x5a"
83 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen 0xa5"
84 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen 0"
85 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen #5a5a"
86 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen #a5a5"
87 status=0
88 exit