From: Darrick J. Wong Date: Wed, 20 Dec 2023 16:53:43 +0000 (-0800) Subject: xfs_copy: distinguish short writes to EOD from runtime errors X-Git-Tag: v6.6.0~6^2~2 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fxfsprogs-dev.git;a=commitdiff_plain;h=603850fe94cdb6a586eb75cb33bcb9e24e204b18 xfs_copy: distinguish short writes to EOD from runtime errors Detect short writes to the end of the destination device and report them. Signed-off-by: Darrick J. Wong Reviewed-by: Christoph Hellwig --- diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 6e692e4f7..2cfb7519e 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -884,18 +884,28 @@ main(int argc, char **argv) } else { char *lb[XFS_MAX_SECTORSIZE] = { NULL }; off64_t off; + ssize_t len; /* ensure device files are sufficiently large */ off = mp->m_sb.sb_dblocks * source_blocksize; off -= sizeof(lb); - if (pwrite(target[i].fd, lb, sizeof(lb), off) < 0) { + len = pwrite(target[i].fd, lb, XFS_MAX_SECTORSIZE, off); + if (len < 0) { do_log(_("%s: failed to write last block\n"), progname); do_log(_("\tIs target \"%s\" too small?\n"), target[i].name); die_perror(); } + if (len != XFS_MAX_SECTORSIZE) { + do_log( + _("%s: short write to last block: %zd bytes, %zu expected\n"), + progname, len, XFS_MAX_SECTORSIZE); + do_log(_("\tIs target \"%s\" too small?\n"), + target[i].name); + exit(1); + } } }