From: Jim Meyering Date: Sat, 6 Mar 2004 17:40:56 +0000 (+0000) Subject: cp --sparse=always sparse-image-file.img /dev/hda1 could X-Git-Tag: v5.2.1~47 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0ede5ec7f9de3cf6d79c80184420feadddea9b4b;p=thirdparty%2Fcoreutils.git cp --sparse=always sparse-image-file.img /dev/hda1 could produce an invalid copy on the destination device. (copy_reg): Even with --sparse=always, try to make `holes' only if the destination is a regular file. Reported by Szakacsits Szabolcs. --- diff --git a/src/copy.c b/src/copy.c index b38b535ae8..8685234e5e 100644 --- a/src/copy.c +++ b/src/copy.c @@ -214,7 +214,7 @@ copy_reg (const char *src_path, const char *dst_path, int return_val = 0; off_t n_read_total = 0; int last_write_made_hole = 0; - int make_holes = (x->sparse_mode == SPARSE_ALWAYS); + int make_holes = 0; source_desc = open (src_path, O_RDONLY); if (source_desc < 0) @@ -286,6 +286,11 @@ copy_reg (const char *src_path, const char *dst_path, buf_size = ST_BLKSIZE (sb); + /* Even with --sparse=always, try to create holes only + if the destination is a regular file. */ + if (x->sparse_mode == SPARSE_ALWAYS && S_ISREG (sb.st_mode)) + make_holes = 1; + #if HAVE_STRUCT_STAT_ST_BLOCKS if (x->sparse_mode == SPARSE_AUTO && S_ISREG (sb.st_mode)) {