summaryrefslogtreecommitdiff
path: root/tests/generic/424
blob: 0ed0e4aaa2d5daac0da7e9c9cf109c59a6e7a98d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2017 Red Hat, Inc.  All Rights Reserved.
#
# FS QA Test 424
#
# Test the statx stx_attribute flags that can be set with chattr
#
. ./common/preamble
_begin_fstest auto quick

# Override the default cleanup function.
_cleanup()
{
	cd /
	rm -f $tmp.*
	$CHATTR_PROG -a -i $testfile
	rm -f $testfile
}

# Import common functions.
. ./common/filter

# real QA test starts here

# Modify as appropriate.
_supported_fs generic
_require_test
_require_test_program stat_test
_require_statx
_require_command "$CHATTR_PROG" chattr

function check_stat () {
	$here/src/stat_test $* || echo stat_test failed
}

testfile=$TEST_DIR/$seq-file
touch $testfile

# Work out what chattrs are supported on the fs under test
a_supported=""
c_supported=""
d_supported=""
i_supported=""
a_list="0"
c_list="0"
d_list="0"
i_list="0"

if $CHATTR_PROG +a $testfile >&/dev/null; then
    a_supported=1
    a_list="+a -a"
fi

if $CHATTR_PROG +c $testfile >&/dev/null; then
    c_supported=1
    c_list="+c -c"
fi

if $CHATTR_PROG +d $testfile >&/dev/null; then
    d_supported=1
    d_list="+d -d"
fi

if $CHATTR_PROG +i $testfile >&/dev/null; then
    i_supported=1
    i_list="+i -i"
fi

echo "a=$a_supported d=$d_supported c=$c_supported i=$i_supported" >>$seqres.full

if [ "$a_supported$c_supported$d_supported$i_supported" = "" ]; then
	_notrun "file system doesn't support any of $CHATTR_PROG +a/+c/+d/+i"
fi

$CHATTR_PROG -a -c -d -i $testfile

###############################################################################
#
# Now do the actual test.  We can turn on and off append (a), compressed (c),
# immutable (i) and no-dump (d) and theoretically see the output in the
# attribute flags.  The following associations can be seen:
#
#	chattr flag	stx_attributes flag
#	+a		STATX_ATTR_APPEND
#	+c		STATX_ATTR_COMPRESSED
#	+d		STATX_ATTR_NODUMP
#	+i		STATX_ATTR_IMMUTABLE
#
# Note, however, that if the filesystem doesn't paste this information into
# stx_attributes, there's no way to tell the difference between cleared and
# unset.
#
###############################################################################
function try () {
	echo Trying "$*" >>$seqres.full
	$CHATTR_PROG ${a_supported:+$1} \
	       ${c_supported:+$2} \
	       ${d_supported:+$3} \
	       ${i_supported:+$4} \
	       $testfile
	check_stat $testfile \
	       ${a_supported:+attr=${1/a/append}} \
	       ${c_supported:+attr=${2/c/compressed}} \
	       ${d_supported:+attr=${3/d/nodump}} \
	       ${i_supported:+attr=${4/i/immutable}} \
	       stx_type=file \
	       stx_size=0 \
	       stx_rdev_major=0 \
	       stx_rdev_minor=0 \
	       stx_nlink=1
}

for a in $a_list; do
	for c in $c_list; do
		for d in $d_list; do
			for i in $i_list; do
				try $a $c $d $i
			done
		done
	done
done

# For tradition's sake
echo "Silence is golden"

# Done.  We leave the success determination to the output comparator.
status=0
exit