diff options
author | Darrick J. Wong <djwong@kernel.org> | 2023-12-20 08:53:43 -0800 |
---|---|---|
committer | Darrick J. Wong <djwong@kernel.org> | 2023-12-21 18:29:14 -0800 |
commit | 603850fe94cdb6a586eb75cb33bcb9e24e204b18 (patch) | |
tree | 616cb3bbfe10df50dc9c5912b9d49122cf4cbdcf | |
parent | b9166aea5eb825bdb603f21d9eb43c7bfe846ca2 (diff) | |
download | xfsprogs-dev-603850fe94cdb6a586eb75cb33bcb9e24e204b18.tar.gz |
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 <djwong@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
-rw-r--r-- | copy/xfs_copy.c | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/copy/xfs_copy.c b/copy/xfs_copy.c index 6e692e4f72..2cfb7519e2 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); + } } } |