mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-04-10 06:03:31 +02:00
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.
This commit is contained in:
28
src/copy.c
28
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user