From 4068abf47fcb6563cf519d3104c0253438ed6612 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Fri, 29 Nov 2024 11:34:07 +0100 Subject: [PATCH 1/3] image-hd: use partition_end() everywhere Signed-off-by: Michael Olbrich --- image-hd.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/image-hd.c b/image-hd.c index 51d2d4f..423729a 100644 --- a/image-hd.c +++ b/image-hd.c @@ -515,7 +515,7 @@ static int hdimage_insert_gpt(struct image *image, struct list_head *partitions) uuid_parse(part->partition_type_uuid, table[i].type_uuid); uuid_parse(part->partition_uuid, table[i].uuid); table[i].first_lba = htole64(part->offset/512); - table[i].last_lba = htole64((part->offset + part->size)/512 - 1); + table[i].last_lba = htole64((partition_end(part))/512 - 1); table[i].flags = (part->bootable ? GPT_PE_FLAG_BOOTABLE : 0) | (part->read_only ? GPT_PE_FLAG_READ_ONLY : 0) | @@ -540,7 +540,7 @@ static int hdimage_insert_gpt(struct image *image, struct list_head *partitions) if (strstr(part->name, "GPT backup")) continue; - end = part->offset + part->size; + end = partition_end(part); if (end <= smallest_offset && end > first_usable_offset) first_usable_offset = end; } @@ -721,10 +721,10 @@ static int check_overlap(struct image *image, struct partition *p) if (p == q) return 0; /* We must have that p starts beyond where q ends... */ - if (p->offset >= q->offset + q->size) + if (p->offset >= partition_end(q)) continue; /* ...or vice versa. */ - if (q->offset >= p->offset + p->size) + if (q->offset >= partition_end(p)) continue; /* @@ -735,7 +735,7 @@ static int check_overlap(struct image *image, struct partition *p) * specified. */ start = max_ull(p->offset, q->offset); - end = min_ull(p->offset + p->size, q->offset + q->size); + end = min_ull(partition_end(p), q->offset + q->size); if (image_has_hole_covering(q->image, start - q->offset, end - q->offset)) continue; @@ -1181,8 +1181,8 @@ static int hdimage_setup(struct image *image, cfg_t *cfg) part->name, part->size); return -EINVAL; } - if (part->offset + part->size > now) - now = part->offset + part->size; + if (partition_end(part) > now) + now = partition_end(part); if (part->logical) { size_t file_size = part->offset - hd->align + 512; From 60590b3890ee358936343bc6dec07b56194b9d63 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Fri, 29 Nov 2024 11:40:23 +0100 Subject: [PATCH 2/3] image-hd: drop duplicate size check The two checks are identical, so just drop the second one. Signed-off-by: Michael Olbrich --- image-hd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/image-hd.c b/image-hd.c index 423729a..f95059e 100644 --- a/image-hd.c +++ b/image-hd.c @@ -957,11 +957,8 @@ static int setup_part_image(struct image *image, struct partition *part) part->name, part->size, child->file, child->size); return -EINVAL; } - if (part->offset + child->size > hd->file_size) { - size_t file_size = part->offset + child->size; - if (file_size > hd->file_size) - hd->file_size = file_size; - } + if (part->offset + child->size > hd->file_size) + hd->file_size = part->offset + child->size; return 0; } From c44f816c3c89806b38e55140c63d6c9453de0fa3 Mon Sep 17 00:00:00 2001 From: Michael Olbrich Date: Fri, 29 Nov 2024 12:27:13 +0100 Subject: [PATCH 3/3] image-hd: remove space before tab Signed-off-by: Michael Olbrich --- image-hd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/image-hd.c b/image-hd.c index f95059e..5d16667 100644 --- a/image-hd.c +++ b/image-hd.c @@ -100,7 +100,7 @@ struct gpt_partition_entry { } __attribute__((packed)); ct_assert(sizeof(struct gpt_partition_entry) == 128); -#define GPT_ENTRIES 128 +#define GPT_ENTRIES 128 #define GPT_SECTORS (1 + GPT_ENTRIES * sizeof(struct gpt_partition_entry) / 512) #define GPT_REVISION_1_0 0x00010000