diff --git a/src/partition/repart.c b/src/partition/repart.c index 7140f8a7fb2..75a5daf836b 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -192,6 +192,7 @@ struct Partition { char *copy_blocks_path; bool copy_blocks_auto; + const char *copy_blocks_root; int copy_blocks_fd; uint64_t copy_blocks_size; @@ -350,6 +351,7 @@ static void partition_foreignize(Partition *p) { p->copy_blocks_path = mfree(p->copy_blocks_path); p->copy_blocks_fd = safe_close(p->copy_blocks_fd); + p->copy_blocks_root = NULL; p->format = mfree(p->format); p->copy_files = strv_free(p->copy_files); @@ -1336,6 +1338,7 @@ static int config_parse_copy_blocks( if (streq(rvalue, "auto")) { partition->copy_blocks_path = mfree(partition->copy_blocks_path); partition->copy_blocks_auto = true; + partition->copy_blocks_root = arg_root; return 0; } @@ -1352,6 +1355,7 @@ static int config_parse_copy_blocks( free_and_replace(partition->copy_blocks_path, d); partition->copy_blocks_auto = false; + partition->copy_blocks_root = arg_root; return 0; } @@ -4887,7 +4891,6 @@ static int resolve_copy_blocks_auto( static int context_open_copy_block_paths( Context *context, - const char *root, dev_t restrict_devno) { int r; @@ -4909,7 +4912,7 @@ static int context_open_copy_block_paths( if (p->copy_blocks_path) { - source_fd = chase_symlinks_and_open(p->copy_blocks_path, root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NONBLOCK, &opened); + source_fd = chase_symlinks_and_open(p->copy_blocks_path, p->copy_blocks_root, CHASE_PREFIX_ROOT, O_RDONLY|O_CLOEXEC|O_NONBLOCK, &opened); if (source_fd < 0) return log_error_errno(source_fd, "Failed to open '%s': %m", p->copy_blocks_path); @@ -4923,7 +4926,7 @@ static int context_open_copy_block_paths( } else if (p->copy_blocks_auto) { dev_t devno; - r = resolve_copy_blocks_auto(p->type_uuid, root, restrict_devno, &devno, &uuid); + r = resolve_copy_blocks_auto(p->type_uuid, p->copy_blocks_root, restrict_devno, &devno, &uuid); if (r < 0) return r; @@ -5960,7 +5963,6 @@ static int run(int argc, char *argv[]) { /* Open all files to copy blocks from now, since we want to take their size into consideration */ r = context_open_copy_block_paths( context, - arg_root, loop_device ? loop_device->devno : /* if --image= is specified, only allow partitions on the loopback device */ arg_root && !arg_image ? 0 : /* if --root= is specified, don't accept any block device */ (dev_t) -1); /* if neither is specified, make no restrictions */