]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
cp: read sparse files more efficiently with non regular destination
authorPádraig Brady <P@draigBrady.com>
Mon, 6 Oct 2014 10:02:34 +0000 (11:02 +0100)
committerPádraig Brady <P@draigBrady.com>
Wed, 15 Oct 2014 01:19:48 +0000 (02:19 +0100)
* src.copy.c (copy_reg): Use fiemap to read sparse files, even
if the output is not to a regular file.
* NEWS: Mention the improvement.

NEWS
src/copy.c

diff --git a/NEWS b/NEWS
index e7aef7725dd7900f6e015214f8c9aa8547e80100..52332bd117a9ef14d80e727d8f315f4fe14d9ebe 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -36,6 +36,9 @@ GNU coreutils NEWS                                    -*- outline -*-
   cp,install,mv will convert smaller runs of NULs in the input to holes,
   and cp --sparse=always avoids speculative preallocation on XFS for example.
 
+  cp will read sparse files more efficiently when the destination is a
+  non regular file.  For example when copying a disk image to a device node.
+
   mv will try a reflink before falling back to a standard copy, which is
   more efficient when moving files across BTRFS subvolume boundaries.
 
index 85a4c59659414bdaa9d4adb5fe4565c076240d4b..b8e12c2bdf11f9a37a52a45d68b4b19bba3887d0 100644 (file)
@@ -1214,7 +1214,7 @@ copy_reg (char const *src_name, char const *dst_name,
 
       /* Deal with sparse files.  */
       bool make_holes = false;
-      bool sparse_src = false;
+      bool sparse_src = is_probably_sparse (&src_open_sb);
 
       if (S_ISREG (sb.st_mode))
         {
@@ -1227,7 +1227,6 @@ copy_reg (char const *src_name, char const *dst_name,
              blocks.  If the file has fewer blocks than would normally be
              needed for a file of its size, then at least one of the blocks in
              the file is a hole.  */
-          sparse_src = is_probably_sparse (&src_open_sb);
           if (x->sparse_mode == SPARSE_AUTO && sparse_src)
             make_holes = true;
         }
@@ -1270,7 +1269,7 @@ copy_reg (char const *src_name, char const *dst_name,
              any extents to read more efficiently.  */
           if (extent_copy (source_desc, dest_desc, buf, buf_size, hole_size,
                            src_open_sb.st_size,
-                           S_ISREG (sb.st_mode) ? x->sparse_mode : SPARSE_NEVER,
+                           make_holes ? x->sparse_mode : SPARSE_NEVER,
                            src_name, dst_name, &normal_copy_required))
             goto preserve_metadata;