From f2e6cd4dbcaa57b592f6a6478fbec50e15b781fa Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 13 Oct 2026 22:26:08 +0200 Subject: [PATCH] repart: copy --copy-from= partitions at their offset With --copy-from=, we seek the source image to each partition before copying its blocks. All partitions that are copied from the same image share one file offset. Let's pass the partition offset to copy_bytes_full() instead, so we don't have to move the file offset. --- src/repart/repart.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/repart/repart.c b/src/repart/repart.c index e91e6253ffd..257e6b7222b 100644 --- a/src/repart/repart.c +++ b/src/repart/repart.c @@ -6642,14 +6642,10 @@ static int context_copy_blocks(Context *context) { if (p->copy_blocks_offset == UINT64_MAX) log_info("Copying in '%s' (%s) on block level into future partition %" PRIu64 ".", p->copy_blocks_path, FORMAT_BYTES(p->copy_blocks_size), p->partno); - else { + else log_info("Copying in '%s' @ %" PRIu64 " (%s) on block level into future partition %" PRIu64 ".", p->copy_blocks_path, p->copy_blocks_offset, FORMAT_BYTES(p->copy_blocks_size), p->partno); - if (lseek(p->copy_blocks_fd, p->copy_blocks_offset, SEEK_SET) < 0) - return log_error_errno(errno, "Failed to seek to copy blocks offset in %s: %m", p->copy_blocks_path); - } - /* We call copy_bytes_full() instead of copy_file_range() directly, because copy_file_range() * needs to be called with a size limit to allow for progress updates. But we don't want that * for cloning, we want one big massive reflink if possible, and unfortunately we can't know @@ -6658,7 +6654,7 @@ static int context_copy_blocks(Context *context) { * clone, and then falls back to copying in chunks. */ r = copy_bytes_full( p->copy_blocks_fd, - /* foffset= */ NULL, + /* foffset= */ p->copy_blocks_offset == UINT64_MAX ? NULL : &(uint64_t) { p->copy_blocks_offset }, partition_target_fd(t), /* toffset= */ NULL, p->copy_blocks_size,