Subject: cp: --sparse=always loses tail-end sparseness Package: coreutils Version: 5.2.1-2 Severity: minor Tags: patch
cp --sparse=always fails to maximize sparseness when a file ends with a partial block cotaining only zeros: $ dd if=/dev/null of=sparse bs=32769 seek=1 count=0 0+0 records in 0+0 records out 0 bytes transferred in 0.001514 seconds (0 bytes/sec) $ ls -ls sparse 0 -rw------- 1 pacman users 32769 Jun 6 13:45 sparse $ cp --sparse=always sparse sparse2 $ ls -ls sparse2 4 -rw------- 1 pacman users 32769 Jun 6 13:46 sparse2 $ This is caused by an unnecessary write() before the ftruncate() which sets the file size. --- src/copy.c.orig 2006-06-06 13:58:23.000000000 -0500 +++ src/copy.c 2006-06-06 14:32:58.000000000 -0500 @@ -363,16 +363,15 @@ } } - /* If the file ends with a `hole', something needs to be written at - the end. Otherwise the kernel would truncate the file at the end - of the last write operation. */ + /* If the file ends with a `hole' and ftruncate is not available, + something needs to be written at the end. Otherwise the kernel would + truncate the file at the end of the last write operation. */ if (last_write_made_hole) { #if HAVE_FTRUNCATE - /* Write a null character and truncate it again. */ - if (full_write (dest_desc, "", 1) != 1 - || ftruncate (dest_desc, n_read_total) < 0) + /* ftruncate sets the file size, so there is no need for a write. */ + if (ftruncate (dest_desc, n_read_total) < 0) #else /* Seek backwards one character and write a null. */ if (lseek (dest_desc, (off_t) -1, SEEK_CUR) < 0L -- System Information: Debian Release: 3.1 Architecture: powerpc (ppc) Kernel: Linux 2.6.16.14 Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968) Versions of packages coreutils depends on: ii libacl1 2.2.23-1 Access control list shared library ii libc6 2.3.2.ds1-22sarge3 GNU C Library: Shared libraries an -- no debconf information -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]