From: Darrick J. Wong <djwong@xxxxxxxxxx> Detect short writes to the end of the destination device and report them. Signed-off-by: Darrick J. Wong <djwong@xxxxxxxxxx> --- copy/xfs_copy.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 79f65946..d9a14a95 100644 --- a/copy/xfs_copy.c +++ b/copy/xfs_copy.c @@ -889,18 +889,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); + } } }