diff options
author | Daan De Meyer <daan.j.demeyer@gmail.com> | 2022-11-21 11:23:51 +0100 |
---|---|---|
committer | Daan De Meyer <daan.j.demeyer@gmail.com> | 2022-11-21 11:47:13 +0100 |
commit | 6b1ea55e0b84da0104afe058347b556dcef0e2ba (patch) | |
tree | e5e624fcf01db2718070b387f079dc4dd6fcfe71 /src/partition | |
parent | 488bb758c074314b08293ae1501f6b53352f7d87 (diff) | |
download | systemd-6b1ea55e0b84da0104afe058347b556dcef0e2ba.tar.gz |
repart: Rework PartitionTarget initialization
Diffstat (limited to 'src/partition')
-rw-r--r-- | src/partition/repart.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/partition/repart.c b/src/partition/repart.c index 5bae554258..5beba69f3f 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -3047,9 +3047,13 @@ static int partition_target_prepare( * the result into the image. */ - t = new0(PartitionTarget, 1); + t = new(PartitionTarget, 1); if (!t) return log_oom(); + *t = (PartitionTarget) { + .fd = -1, + .whole_fd = -1, + }; if (S_ISBLK(st.st_mode) || (p->format && !mkfs_supports_root_option(p->format))) { _cleanup_(loop_device_unrefp) LoopDevice *d = NULL; @@ -3061,10 +3065,7 @@ static int partition_target_prepare( if (r < 0) return log_error_errno(r, "Failed to make loopback device of future partition %" PRIu64 ": %m", p->partno); - *t = (PartitionTarget) { - .loop = TAKE_PTR(d), - .fd = -1, - }; + t->loop = TAKE_PTR(d); } else if (need_path) { _cleanup_(unlink_and_freep) char *temp = NULL; _cleanup_close_ int fd = -1; @@ -3086,18 +3087,13 @@ static int partition_target_prepare( return log_error_errno(errno, "Failed to truncate temporary file to %s: %m", FORMAT_BYTES(size)); - *t = (PartitionTarget) { - .fd = TAKE_FD(fd), - .path = TAKE_PTR(temp), - }; + t->fd = TAKE_FD(fd); + t->path = TAKE_PTR(temp); } else { if (lseek(whole_fd, p->offset, SEEK_SET) == (off_t) -1) return log_error_errno(errno, "Failed to seek to partition offset: %m"); - *t = (PartitionTarget) { - .fd = -1, - .whole_fd = whole_fd, - }; + t->whole_fd = whole_fd; } *ret = TAKE_PTR(t); |