diff options
author | Jim Meyering <meyering@redhat.com> | 2010-10-11 10:39:50 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2011-01-30 20:44:11 +0100 |
commit | 0b9f65dc017fa66a47c19f63f49bd013fac0d29c (patch) | |
tree | 1320b3aa20c541aa0484eb9b0b266d1e4b0736af | |
parent | 2db1433eabc847d9ad43e059764222e9b33233aa (diff) | |
download | coreutils-0b9f65dc017fa66a47c19f63f49bd013fac0d29c.tar.xz |
fiemap copy: don't let write failure go unreported; adjust style, etc.
* src/copy.c (write_zeros): Add comments.
(extent_copy): Move decls of "ok" and "i" down to scope where used.
Adjust comments.
Rename local: s/holes_len/hole_size/
Print a diagnostic upon failure to write zeros.
-rw-r--r-- | src/copy.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/copy.c b/src/copy.c index 2c3eabdda..902c6bbea 100644 --- a/src/copy.c +++ b/src/copy.c @@ -153,12 +153,17 @@ clone_file (int dest_fd, int src_fd) #endif } +/* Write N_BYTES zero bytes to file descriptor FD. Return true if successful. + Upon write failure, set errno and return false. */ static bool write_zeros (int fd, uint64_t n_bytes) { static char *zeros; static size_t nz = IO_BUFSIZE; + /* Attempt to use a relatively large calloc'd source buffer for + efficiency, but if that allocation fails, resort to a smaller + statically allocated one. */ if (zeros == NULL) { static char fallback[1024]; @@ -198,14 +203,12 @@ extent_copy (int src_fd, int dest_fd, size_t buf_size, off_t last_ext_logical = 0; uint64_t last_ext_len = 0; uint64_t last_read_size = 0; - unsigned int i; - bool ok = true; open_extent_scan (src_fd, &scan); do { - ok = get_extents_info (&scan); + bool ok = get_extents_info (&scan); if (! ok) { if (scan.hit_last_extent) @@ -218,10 +221,12 @@ extent_copy (int src_fd, int dest_fd, size_t buf_size, return false; } - error (0, errno, _("failed to get extents info %s"), quote (src_name)); + error (0, errno, _("%s: failed to get extents info"), + quote (src_name)); return false; } + unsigned int i; for (i = 0; i < scan.ei_count; i++) { off_t ext_logical = scan.ext_info[i].ext_logical; @@ -243,13 +248,18 @@ extent_copy (int src_fd, int dest_fd, size_t buf_size, } else { - /* If not making a sparse file, write zeros to the destination - file if there is a hole between the last and current extent. */ + /* We're not inducing holes; write zeros to the destination file + if there is a hole between the last and current extent. */ if (last_ext_logical + last_ext_len < ext_logical) { - uint64_t holes_len = ext_logical - last_ext_logical - last_ext_len; - if (! write_zeros (dest_fd, holes_len)) - return false; + uint64_t hole_size = (ext_logical + - last_ext_logical + - last_ext_len); + if (! write_zeros (dest_fd, hole_size)) + { + error (0, errno, _("%s: write failed"), quote (dst_name)); + return false; + } } } |