2 # Ensure that mv, cp -a and cp --preserve=xattr(all) options do work
3 # as expected on file systems without their support and do show correct
4 # diagnostics when required
6 # Copyright (C) 2009-2018 Free Software Foundation, Inc.
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <https://www.gnu.org/licenses/>.
21 .
"${srcdir=.}/tests/init.sh"; path_prepend_ .
/src
27 cleanup_
() { cd /; umount
"$cwd/noxattr"; umount
"$cwd/xattr"; }
31 # Mount an ext2 loopback file system at $WHERE with $OPTS
38 dd if=/dev
/zero of
="$fs" bs
=8192 count
=200 > /dev
/null
2>&1 \
40 mkdir
"$where" || skip
=1
41 mkfs
-t ext2
-F "$fs" ||
42 skip_
"failed to create ext2 file system"
43 mount
-oloop,$opts "$fs" "$where" || skip
=1
44 echo test > "$where"/f || skip
=1
45 test -s "$where"/f || skip
=1
48 skip_
"insufficient mount/ext2 support"
51 make_fs noxattr nouser_xattr
52 make_fs xattr user_xattr
54 # testing xattr name-value pair
57 xattr_pair
="$xattr_name=\"$xattr_value\""
59 echo test > xattr
/a || framework_failure_
60 getfattr
-d xattr
/a
>out_a || skip_
"failed to get xattr of file"
61 grep -F "$xattr_pair" out_a
>/dev
/null
&& framework_failure_
62 setfattr
-n "$xattr_name" -v "$xattr_value" xattr
/a
>out_a \
63 || skip_
"failed to set xattr of file"
64 getfattr
-d xattr
/a
>out_a || skip_
"failed to get xattr of file"
65 grep -F "$xattr_pair" out_a
>/dev
/null \
66 || skip_
"failed to set xattr of file"
69 # This should pass without diagnostics
70 cp -a xattr
/a noxattr
/ 2>err || fail
=1
71 test -s noxattr
/a || fail
=1 # destination file must not be empty
72 compare
/dev
/null err || fail
=1
76 # This should pass without diagnostics (new file)
77 cp --preserve=all xattr
/a noxattr
/ 2>err || fail
=1
78 test -s noxattr
/a || fail
=1 # destination file must not be empty
79 compare
/dev
/null err || fail
=1
81 # This should pass without diagnostics (existing file)
82 cp --preserve=all xattr
/a noxattr
/ 2>err || fail
=1
83 test -s noxattr
/a || fail
=1 # destination file must not be empty
84 compare
/dev
/null err || fail
=1
88 # This should fail with corresponding diagnostics
89 cp -a --preserve=xattr xattr
/a noxattr
/ 2>err
&& fail
=1
90 if grep '^#define USE_XATTR 1' $CONFIG_HEADER > /dev
/null
; then
92 cp: setting attributes
for 'noxattr/a': Operation not supported
96 cp: cannot preserve extended attributes
, cp is built without xattr support
100 compare exp err || fail
=1
104 # This should pass without diagnostics
105 mv xattr
/a noxattr
/ 2>err || fail
=1
106 test -s noxattr
/a || fail
=1 # destination file must not be empty
107 compare
/dev
/null err || fail
=1
109 # This should pass and copy xattrs of the symlink
110 # since the xattrs used here are not in the 'user.' namespace.
111 # Up to and including coreutils-8.22 xattrs of symlinks
112 # were not copied across file systems.
113 ln -s 'foo' xattr
/symlink || framework_failure_
114 # Note 'user.' namespace is only supported on regular files/dirs
115 # so use the 'trusted.' namespace here
116 txattr
='trusted.overlay.whiteout'
117 if setfattr
-hn "$txattr" -v y xattr
/symlink
; then
118 # Note only root can read the 'trusted.' namespace
119 if getfattr
-h -m- -d xattr
/symlink |
grep -F "$txattr"; then
120 mv xattr
/symlink noxattr
/ 2>err || fail
=1
121 if grep '^#define USE_XATTR 1' $CONFIG_HEADER > /dev
/null
; then
122 getfattr
-h -m- -d noxattr
/symlink |
grep -F "$txattr" || fail
=1
124 compare
/dev
/null err || fail
=1
126 echo "failed to get '$txattr' xattr. skipping symlink check" >&2
129 echo "failed to set '$txattr' xattr. skipping symlink check" >&2