generic: copy_file_range swapfile test
[xfstests-dev.git] / tests / generic / 532
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0+
3 # Copyright (c) 2019 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 532
6 #
7 # Regression test for a bug where XFS fails to set statx attributes_mask but
8 # sets attribute flags anyway.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13 tmp=/tmp/$$
14 status=1        # failure is the default!
15 trap "_cleanup; exit \$status" 0 1 2 3 15
16
17 _cleanup()
18 {
19         cd /
20         rm -f $tmp.* $testfile
21 }
22
23 # get standard environment, filters and checks
24 . ./common/rc
25
26 # real QA test starts here
27 _supported_fs generic
28 _supported_os Linux
29 _require_test
30
31 get_attributes() {
32         $XFS_IO_PROG -r -c "statx -r" $1 | grep 'stat.attributes =' | cut -d ' ' -f 3
33 }
34
35 get_attributes_mask() {
36         $XFS_IO_PROG -r -c "statx -r" $1 | grep 'stat.attributes_mask =' | cut -d ' ' -f 3
37 }
38
39 check_statx_attributes()
40 {
41         local attrs=$(get_attributes $testfile)
42         local mask=$(get_attributes_mask $testfile)
43
44         echo "MASK:$mask:ATTRS:$attrs:" >> $seqres.full
45
46         test -z "$mask" && _notrun "xfs_io statx command does not support attributes_mask"
47         test $(( attrs & ~(mask) )) -ne 0 && echo "attributes $attrs do not appear in mask $mask"
48 }
49
50 rm -f $seqres.full
51 echo "Silence is golden"
52
53 # Create file, check for incorrect mask
54 testfile=$TEST_DIR/$seq.$$.test
55 touch $testfile
56 check_statx_attributes
57
58 # Do it again, but this time try to turn on one of the attributes.
59 if $CHATTR_PROG +i $testfile > /dev/null 2>&1; then
60         check_statx_attributes
61         $CHATTR_PROG -i $testfile
62 fi
63 if $CHATTR_PROG +a $testfile > /dev/null 2>&1; then
64         check_statx_attributes
65         $CHATTR_PROG -a $testfile
66 fi
67
68 status=0
69 exit