blob: 6e5ad049b13c003d9a5cec8b1f4b3091c87d1614 (
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
|
#! /bin/bash
# SPDX-License-Identifier: GPL-2.0
# Copyright (c) 2000-2002 Silicon Graphics, Inc. All Rights Reserved.
#
# FS QA Test No. 062
#
# Exercises the getfattr/setfattr tools
# Derived from tests originally written by Andreas Gruenbacher for ext2
#
. ./common/preamble
_begin_fstest attr udf auto quick
# Import common functions.
. ./common/filter
. ./common/attr
# Override the default cleanup function.
_cleanup()
{
cd /
echo; echo "*** unmount"
_scratch_unmount 2>/dev/null
rm -f $tmp.*
}
getfattr()
{
_getfattr --absolute-names -dh $@ 2>&1 | _filter_scratch
}
setfattr()
{
$SETFATTR_PROG $@ 2>&1 | _filter_scratch
}
_create_test_bed()
{
echo "*** create test bed"
touch $SCRATCH_MNT/reg
mkdir -p $SCRATCH_MNT/dir
ln -s $SCRATCH_MNT/dir $SCRATCH_MNT/lnk
mkdir $SCRATCH_MNT/dev
mknod $SCRATCH_MNT/dev/b b 0 0
mknod $SCRATCH_MNT/dev/c c 1 3
mknod $SCRATCH_MNT/dev/p p
# sanity check
find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch | grep -v "lost+found"
}
# real QA test starts here
_supported_fs generic
_require_scratch
_require_attrs
_require_symlinks
_require_mknod
rm -f $tmp.backup1 $tmp.backup2 $seqres.full
# real QA test starts here
_scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
_scratch_mount
_create_test_bed
# In kernels before 3.0, getxattr() fails with EPERM for an attribute which
# cannot exist. Later kernels fail with ENODATA. Accept both results.
invalid_attribute_filter() {
sed -e "s:\(No such attribute\|Operation not permitted\):No such attribute or operation not permitted:"
}
if [ "$USE_ATTR_SECURE" = yes ]; then
ATTR_MODES="user security trusted"
ATTR_FILTER="^(user|security|trusted)"
else
ATTR_MODES="user trusted"
ATTR_FILTER="^(user|trusted)"
fi
_require_attrs $ATTR_MODES
for nsp in $ATTR_MODES; do
for inode in reg dir lnk dev/b dev/c dev/p; do
echo; echo "=== TYPE $inode; NAMESPACE $nsp"; echo
echo "*** set/get one initially empty attribute"
setfattr -h -n $nsp.name $SCRATCH_MNT/$inode
getfattr -m $nsp $SCRATCH_MNT/$inode
echo "*** overwrite empty, set several new attributes"
setfattr -h -n $nsp.name -v 0xbabe $SCRATCH_MNT/$inode
setfattr -h -n $nsp.name2 -v 0xdeadbeef $SCRATCH_MNT/$inode
setfattr -h -n $nsp.name3 -v 0xdeface $SCRATCH_MNT/$inode
echo "*** fetch several attribute names and values (hex)"
getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
echo "*** fetch several attribute names and values (base64)"
getfattr -m $nsp -e base64 $SCRATCH_MNT/$inode
echo "*** shrink value of an existing attribute"
setfattr -h -n $nsp.name2 -v 0xdeaf $SCRATCH_MNT/$inode
getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
echo "*** grow value of existing attribute"
setfattr -h -n $nsp.name2 -v 0xdecade $SCRATCH_MNT/$inode
getfattr -m $nsp -e hex $SCRATCH_MNT/$inode
echo "*** set an empty value for second attribute"
setfattr -h -n $nsp.name2 $SCRATCH_MNT/$inode
getfattr -m $nsp -n $nsp.name2 $SCRATCH_MNT/$inode 2>&1 | invalid_attribute_filter
echo "*** overwrite empty value"
setfattr -h -n $nsp.name2 -v 0xcafe $SCRATCH_MNT/$inode
getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode 2>&1 | invalid_attribute_filter
echo "*** remove attribute"
setfattr -h -x $nsp.name2 $SCRATCH_MNT/$inode
getfattr -m $nsp -e hex -n $nsp.name2 $SCRATCH_MNT/$inode 2>&1 | invalid_attribute_filter
echo "*** final list (strings, type=$inode, nsp=$nsp)"
getfattr -m $ATTR_FILTER -e hex $SCRATCH_MNT/$inode
done
done
#
# Test the directory descent code
#
echo; echo
_extend_test_bed()
{
echo "*** extend test bed"
# must set some descents' attributes to be useful
mkdir -p $SCRATCH_MNT/here/up/ascend
mkdir -p $SCRATCH_MNT/descend/down/here
find $SCRATCH_MNT/descend | xargs setfattr -n user.x -v yz
find $SCRATCH_MNT/descend | xargs setfattr -n user.1 -v 23
find $SCRATCH_MNT/here | xargs setfattr -n trusted.a -v bc
find $SCRATCH_MNT/here | xargs setfattr -n trusted.9 -v 87
# whack a symlink in the middle, just to be difficult
ln -s $SCRATCH_MNT/here/up $SCRATCH_MNT/descend/and
# dump out our new starting point
find $SCRATCH_MNT | LC_COLLATE=POSIX sort | _filter_scratch | grep -v "lost+found"
}
_extend_test_bed
echo
echo "*** directory descent with us following symlinks"
getfattr -h -L -R -m "$ATTR_FILTER" -e hex $SCRATCH_MNT | _sort_getfattr_output
echo
echo "*** directory descent without following symlinks"
getfattr -h -P -R -m "$ATTR_FILTER" -e hex $SCRATCH_MNT | _sort_getfattr_output
#
# Test the backup/restore code
#
echo; echo
_backup()
{
# Note: we don't filter scratch here since we need to restore too. But
# we *do* sort the output by path, since it otherwise would depend on
# readdir order, which on some filesystems may change after re-creating
# the files.
_getfattr --absolute-names -dh -R -m $ATTR_FILTER $SCRATCH_MNT | _sort_getfattr_output >$1
echo BACKUP $1 >>$seqres.full
cat $1 >> $seqres.full
[ ! -s $1 ] && echo "warning: $1 (backup file) is empty"
}
echo "*** backup everything"
_backup $tmp.backup1
echo "*** clear out the scratch device"
rm -rf $(find $SCRATCH_MNT/* | grep -v "lost+found")
echo "AFTER REMOVE" >>$seqres.full
getfattr -L -R -m '.' $SCRATCH_MNT >>$seqres.full
echo "*** reset test bed with no extended attributes"
_create_test_bed
_extend_test_bed
echo "*** restore everything"
setfattr -h --restore=$tmp.backup1
_backup $tmp.backup2
echo "AFTER RESTORE" >>$seqres.full
getfattr -L -R -m '.' $SCRATCH_MNT >>$seqres.full
echo "*** compare before and after backups"
diff $tmp.backup1 $tmp.backup2
if [ $? -ne 0 ]; then
echo "urk, failed - creating $seq.backup1 and $seq.backup2"
cp $tmp.backup1 $seq.backup1 && cp $tmp.backup2 $seq.backup2
status=1
exit
fi
# success, all done
status=0
exit
|