summaryrefslogtreecommitdiff
path: root/tests/cp/cp-mv-enotsup-xattr
blob: 620560b264079efd4d12a9d53290fc1dc6f322e6 (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
#!/bin/sh
# Ensure that mv, cp -a and cp --preserve=xattr(all) options do work
# as expected on file system without their support and do show correct
# diagnostics when required

# Copyright (C) 2009 Free Software Foundation, Inc.

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

if test "$VERBOSE" = yes; then
  set -x
  cp --version
  mv --version
fi

. $srcdir/test-lib.sh
require_root_

cwd=`pwd`
cleanup_() { cd /; umount "$cwd/mnt"; }

skip=0
# Create a file system without user xattr support, then mount it.
dd if=/dev/zero of=blob bs=8192 count=200 > /dev/null 2>&1 \
                                             || skip=1
mkdir mnt                                    || skip=1
mkfs -t ext2 -F blob ||
  skip_test_ "failed to create ext2 file system"

mount -oloop,nouser_xattr blob mnt           || skip=1
echo test > mnt/f                            || skip=1
test -s mnt/f                                || skip=1

test $skip = 1 \
    && skip_test_ "insufficient mount/ext2 support"

# testing xattr name-value pair
xattr_name="user.foo"
xattr_value="bar"
xattr_pair="$xattr_name=\"$xattr_value\""

echo test > a || framework_failure
getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
grep -F "$xattr_pair" out_a >/dev/null && framework_failure
setfattr -n "$xattr_name" -v "$xattr_value" a >out_a \
  || skip_test_ "failed to set xattr of file"
getfattr -d a >out_a || skip_test_ "failed to get xattr of file"
grep -F "$xattr_pair" out_a >/dev/null \
  || skip_test_ "failed to set xattr of file"


# This should pass without diagnostics
cp -a a mnt/ 2>err  || fail=1
test -s mnt/a       || fail=1  # destination file must not be empty
test -s err         && fail=1  # there must be no stderr output

rm -f err mnt/a

# This should pass without diagnostics
cp --preserve=all a mnt/ 2>err  || fail=1
test -s mnt/a       || fail=1  # destination file must not be empty
test -s err         && fail=1  # there must be no stderr output

rm -f err mnt/a

# This should fail with coresponding diagnostics
cp -a --preserve=xattr a mnt/ 2>err  && fail=1
cat <<\EOF > exp || fail=1
cp: setting attributes for `mnt/a': Operation not supported
EOF

compare err exp     || fail=1

rm -f err mnt/a

# This should pass without diagnostics
mv a mnt/ 2>err     || fail=1
test -s mnt/a       || fail=1  # destination file must not be empty
test -s err         && fail=1  # there must be no stderr output

Exit $fail