]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/commitdiff
xfs_copy: distinguish short writes to EOD from runtime errors
authorDarrick J. Wong <djwong@kernel.org>
Wed, 20 Dec 2023 16:53:43 +0000 (08:53 -0800)
committerDarrick J. Wong <djwong@kernel.org>
Fri, 22 Dec 2023 02:29:14 +0000 (18:29 -0800)
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>
copy/xfs_copy.c

index 6e692e4f721dd93040cdc77afc87dbcc17a65a8b..2cfb7519e27e46a7669839de57f33d84ca30bee0 100644 (file)
@@ -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);
+                       }
                }
        }