GNU bug report logs - #14618
cp: erroneous sparse copy command results in empty file

Previous Next

Package: coreutils;

Reported by: Koen De Wit <koen.de.wit <at> oracle.com>

Date: Fri, 14 Jun 2013 16:00:03 UTC

Severity: normal

Done: Assaf Gordon <assafgordon <at> gmail.com>

Bug is archived. No further changes may be made.

Full log


Message #8 received at 14618 <at> debbugs.gnu.org (full text, mbox):

From: Pádraig Brady <P <at> draigBrady.com>
To: Koen De Wit <koen.de.wit <at> oracle.com>
Cc: 14618 <at> debbugs.gnu.org
Subject: Re: bug#14618: Erroneous sparse copy command results in empty file
Date: Fri, 14 Jun 2013 21:03:52 +0100
On 06/14/2013 12:35 PM, Koen De Wit wrote:
> When trying to create a sparse copy of a file on a different filesystem you get an "Invalid cross-device link" error, as expected. However, an empty file is created instead of the sparse copy:

As a side note, sparse copying is a separate thing to reflinking.

> # mkfs.btrfs -f /dev/sde1
> # mkfs.btrfs -f /dev/sde2
> # mount /dev/sde1 /mnt/part1
> # mount /dev/sde2 /mnt/part2
> # echo "abc" > /mnt/part1/testfile
> # ./cp --reflink /mnt/part1/testfile /mnt/part2/testcopy
> ./cp: failed to clone ‘/mnt/part2/testcopy’ from ‘/mnt/part1/testfile’: Invalid cross-device link
> # ls -la /mnt/part1/testfile
> -rw-r--r--. 1 root root 4 Jun 14 14:49 /mnt/part1/testfile
> # ls -la /mnt/part2/testcopy
> -rw-r--r--. 1 root root 0 Jun 14 14:49 /mnt/part2/testcopy
> 
> The same occurs when trying to create a sparse copy on a filesystem that does not support sparse copies:
> 
> # mkfs.ext3 /dev/sde1
> # mount /dev/sde1 /mnt/part1
> # echo "abc" > /mnt/part1/testfile
> # ./cp --reflink /mnt/part1/testfile /mnt/part1/testcopy
> ./cp: failed to clone ‘/mnt/part1/testcopy’ from ‘/mnt/part1/testfile’: Inappropriate ioctl for device
> # ls -la /mnt/part1
> (...)
> -rw-r--r--. 1 root root 0 Jun 14 14:58 testcopy
> -rw-r--r--. 1 root root 4 Jun 14 14:58 testfile
> 
> If creating a sparse copy fails, no file should be created.
> 
> ln treats this error in the right way:
> 
> # ln /mnt/part1/testfile /mnt/part2/testlink
> ln: creating hard link `/mnt/part2/testlink' => `/mnt/part1/testfile': Invalid cross-device link
> # ls -la /mnt/part2/testlink
> ls: cannot access /mnt/part2/testlink: No such file or directory
> 
> Tested with coreutils today's git HEAD and kernel 3.9.5.

This was discussed previously:
http://lists.gnu.org/archive/html/coreutils/2013-03/msg00056.html
Summary of that is that it may be best handled outside of cp.

cheers,
Pádraig.




This bug report was last modified 6 years and 221 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.