bug#80060: mv: move files across bind mounts using the rename syscall

Bernhard Voelker <[email protected]> Tue, 27 Jan 2026 23:03:12 +0100
Newsgroups gmane.comp.gnu.core-utils.bugs
Message-ID <[email protected]>
On 12/23/25 20:09, Paul Eggert wrote:
> On 2025-12-23 04:27, Pádraig Brady wrote:
>> I don't think it's appropriate for mv to do this expensive/error prone
>> path manipulation for each file being copied across devices.
>> IMHO this is more appropriate for the kernel,
>> which has a more holistic view of the mount space.
> 
> Plus, it's not like mv is the only app with this efficiency issue. Why
> should all those apps be modified to work around the inefficiency when
> the kernel can do the job right once and for all?

yes, that's definitely kernel business.
Even if it's a bind mount and therefore part of the same file system,
it could e.g. be read-only on VFS level:

   $ date > /root/file

   $ mount --bind -r /root /mnt

   $ ls -li /root/file /mnt/file
   525930 -rw-r--r-- 1 root root 29 Jan 27 22:50 /mnt/file
   525930 -rw-r--r-- 1 root root 29 Jan 27 22:50 /root/file

   $ mv /mnt/file /root/file2
   mv: cannot remove '/mnt/file': Read-only file system

   $ mv /root/file /mnt/file2
   mv: inter-device move failed: '/root/file' to '/mnt/file2'; unable to remove target: Read-only file system


   $ mv /mnt/file /mnt/file2
   mv: cannot move '/mnt/file' to '/mnt/file2': Read-only file system

   $ mv -v /root/file /root/file2
   renamed '/root/file' -> '/root/file2'

Have a nice day,
Berny