@@ -209,6 +209,7 @@ int copy_bytes_full(
209
209
r = reflink_range (fdf , foffset , fdt , toffset , max_bytes == UINT64_MAX ? 0 : max_bytes ); /* partial reflink */
210
210
if (r >= 0 ) {
211
211
off_t t ;
212
+ int ret ;
212
213
213
214
/* This worked, yay! Now — to be fully correct — let's adjust the file pointers */
214
215
if (max_bytes == UINT64_MAX ) {
@@ -227,7 +228,14 @@ int copy_bytes_full(
227
228
if (t < 0 )
228
229
return - errno ;
229
230
230
- return 0 ; /* we copied the whole thing, hence hit EOF, return 0 */
231
+ if (FLAGS_SET (copy_flags , COPY_VERIFY_LINKED )) {
232
+ r = fd_verify_linked (fdf );
233
+ if (r < 0 )
234
+ return r ;
235
+ }
236
+
237
+ /* We copied the whole thing, hence hit EOF, return 0. */
238
+ ret = 0 ;
231
239
} else {
232
240
t = lseek (fdf , foffset + max_bytes , SEEK_SET );
233
241
if (t < 0 )
@@ -237,8 +245,18 @@ int copy_bytes_full(
237
245
if (t < 0 )
238
246
return - errno ;
239
247
240
- return 1 ; /* we copied only some number of bytes, which worked, but this means we didn't hit EOF, return 1 */
248
+ /* We copied only some number of bytes, which worked, but
249
+ * this means we didn't hit EOF, return 1. */
250
+ ret = 1 ;
251
+ }
252
+
253
+ if (FLAGS_SET (copy_flags , COPY_VERIFY_LINKED )) {
254
+ r = fd_verify_linked (fdf );
255
+ if (r < 0 )
256
+ return r ;
241
257
}
258
+
259
+ return ret ;
242
260
}
243
261
}
244
262
}
@@ -484,6 +502,12 @@ int copy_bytes_full(
484
502
copied_something = true;
485
503
}
486
504
505
+ if (FLAGS_SET (copy_flags , COPY_VERIFY_LINKED )) {
506
+ r = fd_verify_linked (fdf );
507
+ if (r < 0 )
508
+ return r ;
509
+ }
510
+
487
511
if (copy_flags & COPY_TRUNCATE ) {
488
512
off_t off = lseek (fdt , 0 , SEEK_CUR );
489
513
if (off < 0 )
@@ -799,6 +823,12 @@ static int fd_copy_regular(
799
823
(void ) futimens (fdt , (struct timespec []) { st -> st_atim , st -> st_mtim });
800
824
(void ) copy_xattr (fdf , NULL , fdt , NULL , copy_flags );
801
825
826
+ if (FLAGS_SET (copy_flags , COPY_VERIFY_LINKED )) {
827
+ r = fd_verify_linked (fdf );
828
+ if (r < 0 )
829
+ return r ;
830
+ }
831
+
802
832
if (copy_flags & COPY_FSYNC ) {
803
833
if (fsync (fdt ) < 0 ) {
804
834
r = - errno ;
@@ -1334,6 +1364,12 @@ int copy_file_fd_at_full(
1334
1364
(void ) copy_xattr (fdf , NULL , fdt , NULL , copy_flags );
1335
1365
}
1336
1366
1367
+ if (FLAGS_SET (copy_flags , COPY_VERIFY_LINKED )) {
1368
+ r = fd_verify_linked (fdf );
1369
+ if (r < 0 )
1370
+ return r ;
1371
+ }
1372
+
1337
1373
if (copy_flags & COPY_FSYNC_FULL ) {
1338
1374
r = fsync_full (fdt );
1339
1375
if (r < 0 )
@@ -1404,6 +1440,12 @@ int copy_file_at_full(
1404
1440
(void ) copy_times (fdf , fdt , copy_flags );
1405
1441
(void ) copy_xattr (fdf , NULL , fdt , NULL , copy_flags );
1406
1442
1443
+ if (FLAGS_SET (copy_flags , COPY_VERIFY_LINKED )) {
1444
+ r = fd_verify_linked (fdf );
1445
+ if (r < 0 )
1446
+ goto fail ;
1447
+ }
1448
+
1407
1449
if (chattr_mask != 0 )
1408
1450
(void ) chattr_fd (fdt , chattr_flags , chattr_mask & ~CHATTR_EARLY_FL , NULL );
1409
1451
0 commit comments