generic/520: Remove sync in clean_dir
[xfstests-dev.git] / tests / generic / 424
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat, Inc.  All Rights Reserved.
4 #
5 # FS QA Test 424
6 #
7 # Test the statx stx_attribute flags that can be set with chattr
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
16 trap "_cleanup; exit \$status" 0 1 2 3 15
17
18 _cleanup()
19 {
20         cd /
21         rm -f $tmp.*
22         $CHATTR_PROG -a -i $testfile
23         rm -f $testfile
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29
30 # remove previous $seqres.full before test
31 rm -f $seqres.full
32
33 # real QA test starts here
34
35 # Modify as appropriate.
36 _supported_fs generic
37 _supported_os Linux
38 _require_test
39 _require_test_program stat_test
40 _require_statx
41 _require_command "$CHATTR_PROG" chattr
42
43 function check_stat () {
44         $here/src/stat_test $* || echo stat_test failed
45 }
46
47 testfile=$TEST_DIR/$seq-file
48 touch $testfile
49
50 # Work out what chattrs are supported on the fs under test
51 a_supported=""
52 c_supported=""
53 d_supported=""
54 i_supported=""
55 a_list="0"
56 c_list="0"
57 d_list="0"
58 i_list="0"
59
60 if $CHATTR_PROG +a $testfile >&/dev/null; then
61     a_supported=1
62     a_list="+a -a"
63 fi
64
65 if $CHATTR_PROG +c $testfile >&/dev/null; then
66     c_supported=1
67     c_list="+c -c"
68 fi
69
70 if $CHATTR_PROG +d $testfile >&/dev/null; then
71     d_supported=1
72     d_list="+d -d"
73 fi
74
75 if $CHATTR_PROG +i $testfile >&/dev/null; then
76     i_supported=1
77     i_list="+i -i"
78 fi
79
80 echo "a=$a_supported d=$d_supported c=$c_supported i=$i_supported" >>$seqres.full
81
82 if [ "$a_supported$c_supported$d_supported$i_supported" = "" ]; then
83         _notrun "file system doesn't support any of $CHATTR_PROG +a/+c/+d/+i"
84 fi
85
86 $CHATTR_PROG -a -c -d -i $testfile
87
88 ###############################################################################
89 #
90 # Now do the actual test.  We can turn on and off append (a), compressed (c),
91 # immutable (i) and no-dump (d) and theoretically see the output in the
92 # attribute flags.  The following associations can be seen:
93 #
94 #       chattr flag     stx_attributes flag
95 #       +a              STATX_ATTR_APPEND
96 #       +c              STATX_ATTR_COMPRESSED
97 #       +d              STATX_ATTR_NODUMP
98 #       +i              STATX_ATTR_IMMUTABLE
99 #
100 # Note, however, that if the filesystem doesn't paste this information into
101 # stx_attributes, there's no way to tell the difference between cleared and
102 # unset.
103 #
104 ###############################################################################
105 function try () {
106         echo Trying "$*" >>$seqres.full
107         $CHATTR_PROG ${a_supported:+$1} \
108                ${c_supported:+$2} \
109                ${d_supported:+$3} \
110                ${i_supported:+$4} \
111                $testfile
112         check_stat $testfile \
113                ${a_supported:+attr=${1/a/append}} \
114                ${c_supported:+attr=${2/c/compressed}} \
115                ${d_supported:+attr=${3/d/nodump}} \
116                ${i_supported:+attr=${4/i/immutable}} \
117                stx_type=file \
118                stx_size=0 \
119                stx_rdev_major=0 \
120                stx_rdev_minor=0 \
121                stx_nlink=1
122 }
123
124 for a in $a_list; do
125         for c in $c_list; do
126                 for d in $d_list; do
127                         for i in $i_list; do
128                                 try $a $c $d $i
129                         done
130                 done
131         done
132 done
133
134 # For tradition's sake
135 echo "Silence is golden"
136
137 # Done.  We leave the success determination to the output comparator.
138 status=0
139 exit