cp: fix copying a sparse file to a pipe
authorJim Meyering <meyering@redhat.com>
Mon, 31 Jan 2011 17:25:58 +0000 (18:25 +0100)
committerJim Meyering <meyering@redhat.com>
Mon, 31 Jan 2011 17:26:06 +0000 (18:26 +0100)
commitcc0645fc643d3ea5a06f12f5fad784a2b8097888
tree003a918196b8804d758cdc3d10c8504785ef8885
parent96a93f9480e0a420c21db7b58662a6e3ddf16124
cp: fix copying a sparse file to a pipe

The recent FIEMAP-related changes made it so the unusual case of
copying a sparse file to a non-regular destination (e.g., a pipe)
would erroneously write one byte too many to that destination.
That happened because extent_copy assumed that it could use lseek
to obtain the number of bytes written to the output file descriptor.
That was valid only for regular files.
* src/copy.c (sparse_copy): Add a parameter, to be used by extent_copy,
but not by reg_copy.  Adjust callers.
(extent_copy): Maintain new local, dest_pos, using new arg, n_read.
Don't call lseek on dest_fd; use new var, dest_pos, instead.
(copy_reg): Add unused arg.
src/copy.c