From a40a8fe1e52a78dc9493cbcecc9a01e72f1a76d8 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 9 Jun 2010 08:15:07 +0200 Subject: [PATCH] copy.c: ensure proper alignment of fiemap buffer * src/copy.c (fiemap_copy): Ensure that our fiemap buffer is large enough and well-aligned. Replace "0LL" with equivalent "0" as 3rd argument to lseek. --- src/copy.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/copy.c b/src/copy.c index 6bb0506..1d32913 100644 --- a/src/copy.c +++ b/src/copy.c @@ -170,11 +170,12 @@ fiemap_copy (int src_fd, int dest_fd, size_t buf_size, char const *dst_name, bool *normal_copy_required) { bool last = false; - char fiemap_buf[4096]; - struct fiemap *fiemap = (struct fiemap *) fiemap_buf; + union { struct fiemap f; char c[4096]; } fiemap_buf; + struct fiemap *fiemap = &fiemap_buf.f; struct fiemap_extent *fm_ext = &fiemap->fm_extents[0]; - uint32_t count = ((sizeof fiemap_buf - sizeof (*fiemap)) - / sizeof (struct fiemap_extent)); + enum { count = (sizeof fiemap_buf - sizeof *fiemap) / sizeof *fm_ext }; + verify (count != 0); + off_t last_ext_logical = 0; uint64_t last_ext_len = 0; uint64_t last_read_size = 0; @@ -184,7 +185,7 @@ fiemap_copy (int src_fd, int dest_fd, size_t buf_size, /* This is required at least to initialize fiemap->fm_start, but also serves (in mid 2010) to appease valgrind, which appears not to know the semantics of the FIEMAP ioctl. */ - memset (fiemap_buf, 0, sizeof fiemap_buf); + memset (&fiemap_buf, 0, sizeof fiemap_buf); do { @@ -219,13 +220,13 @@ fiemap_copy (int src_fd, int dest_fd, size_t buf_size, off_t ext_logical = fm_ext[i].fe_logical; uint64_t ext_len = fm_ext[i].fe_length; - if (lseek (src_fd, ext_logical, SEEK_SET) < 0LL) + if (lseek (src_fd, ext_logical, SEEK_SET) < 0) { error (0, errno, _("cannot lseek %s"), quote (src_name)); return false; } - if (lseek (dest_fd, ext_logical, SEEK_SET) < 0LL) + if (lseek (dest_fd, ext_logical, SEEK_SET) < 0) { error (0, errno, _("cannot lseek %s"), quote (dst_name)); return false; -- 2.7.4