generic: test for non-zero used blocks while writing into a file
[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, which is fixed by commit 1b9598c8fb99 ("xfs: fix
9 # reporting supported extra file attributes for statx()")
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
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 -f $tmp.* $testfile
22 }
23
24 # get standard environment, filters and checks
25 . ./common/rc
26
27 # real QA test starts here
28 _supported_fs generic
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