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 #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Koen De Wit <koen.de.wit <at> oracle.com>
To: bug-coreutils <at> gnu.org
Subject: Erroneous sparse copy command results in empty file
Date: Fri, 14 Jun 2013 13:35:59 +0200
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:

# 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 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.