GNU bug report logs -
#65599
mv and cp give a pointless warning when moving/copying a directory
Previous Next
Reported by: Bruno Haible <bruno <at> clisp.org>
Date: Tue, 29 Aug 2023 18:21:01 UTC
Severity: normal
Done: Paul Eggert <eggert <at> cs.ucla.edu>
Bug is archived. No further changes may be made.
Full log
View this message in rfc822 format
[Message part 1 (text/plain, inline)]
Your message dated Sat, 2 Sep 2023 13:44:11 -0700
with message-id <ed3656da-48b8-bdd1-40d1-3402d3b064b8 <at> cs.ucla.edu>
and subject line Re: bug#65599: mv and cp give a pointless warning when moving/copying a directory
has caused the debbugs.gnu.org bug report #65599,
regarding mv and cp give a pointless warning when moving/copying a directory
to be marked as done.
(If you believe you have received this mail in error, please contact
help-debbugs <at> gnu.org.)
--
65599: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=65599
GNU Bug Tracking System
Contact help-debbugs <at> gnu.org with problems
[Message part 2 (message/rfc822, inline)]
[Message part 3 (text/plain, inline)]
When I move a directory from an ext4 file system to a CIFS v1 file system,
I get a diagnostic
mv: failed to preserve ownership for '...': Permission denied
although the owner and group of the directory after and before the move
are the same. So, there is actually nothing to warn about.
$ mv --version
mv (GNU coreutils) 9.3.147-d553ab
Copyright (C) 2023 Free Software Foundation, Inc.
...
$ mkdir dir1
$ echo foo > dir1/file1
$ ls -ld dir1
drwxrwxr-x 2 bruno bruno 4096 Aug 26 19:38 dir1
$ strace -o /tmp/mv.log mv dir1 /media/nas/bruno/dir1
mv: failed to preserve ownership for '/media/nas/bruno/dir1': Permission denied
$ echo $?
0
$ ls -ld /media/nas/bruno/dir1
drwxrwxr-x 2 bruno bruno 0 Aug 26 19:38 /media/nas/bruno/dir1
Find attached the strace log file. The essential line is
fchownat(AT_FDCWD, "/media/nas/bruno/dir1", 1000, 1000, AT_SYMLINK_NOFOLLOW) = -1 EACCES (Permission denied)
People say that "chown only works for root anyway" [1], but it's certainly
safer to try the chown nevertheless, because
- the current user might not be root but might have non-standard capabilities.
- the target file system may be reporting failure but may do the requested
action nevertheless,
- the target file system might map uids (think of NFS or CIFS [2]).
However, the diagnostic should be omitted if the 'mv' program can verify
that the uid and gid of the directory on the target file system is the same
as on the source file system.
Likewise for the 'cp' program:
$ cp --version
cp (GNU coreutils) 9.3.147-d553ab
...
Written by Torbjorn Granlund, David MacKenzie, and Jim Meyering.
$ mkdir dir2
$ echo foo > dir2/file2
$ ls -ld dir2
drwxrwxr-x 2 bruno bruno 4096 Aug 29 20:15 dir2
$ strace -o /tmp/cp.log cp dir2 /media/nas/bruno/dir2
$ strace -o /tmp/cp.log cp -a dir2 /media/nas/bruno/dir2
cp: failed to preserve ownership for '/media/nas/bruno/dir2': Permission denied
$ ls -ld /media/nas/bruno/dir2
drwx------ 2 bruno bruno 0 Aug 29 20:15 /media/nas/bruno/dir2
Here, in cp.log, the essential line is:
fchownat(AT_FDCWD, "/media/nas/bruno/dir2", 1000, 1000, AT_SYMLINK_NOFOLLOW) = -1 EACCES (Permission denied)
Bruno
[1] https://lists.gnu.org/archive/html/emacs-devel/2009-10/msg00094.html
[2] https://linux.die.net/man/8/mount.cifs
[mv.log (text/x-log, attachment)]
[cp.log (text/x-log, attachment)]
[Message part 6 (message/rfc822, inline)]
[Message part 7 (text/plain, inline)]
On 2023-09-02 04:18, Bruno Haible wrote:
> chmod fails with EACCES, hence per POSIX
> <https://pubs.opengroup.org/onlinepubs/9699919799/functions/chmod.html>
> it's buggy.
Thanks, I reported the bug with chmod, chown, etc. to the linux-cifs
mailing list, here:
https://lore.kernel.org/linux-cifs/fe8ab586-c697-583b-650d-3adac64df7b2 <at> cs.ucla.edu/T/#u
I did some testing with fsetxattr and found that it has a similar issue
even with ext4; for example, setxattr("/", "a", "b", 1, 0) fails with
EACCES. This is not a POSIX violation, since POSIX lacks setxattr.
However it's bad form. And it means coreutils needs the attached
workaround not just for CIFS, but also for ext4 in some (rare) cases.
I installed the attached workaround on coreutils and am closing the bug
report. Thanks again for mentioning it.
[0001-cp-mv-install-fix-chmod-on-Linux-CIFS.patch (text/x-patch, attachment)]
This bug report was last modified 1 year and 354 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.