From: Karel Zak Date: Tue, 22 Aug 2017 12:48:14 +0000 (+0200) Subject: libfdisk: (gpt) fix size-1 error X-Git-Tag: v2.30.2~12 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=a0dae7cf46810f6d0df7768653ed16ce2b3fbdf3;p=thirdparty%2Futil-linux.git libfdisk: (gpt) fix size-1 error If partition does not require alignment, then don't call LBA align function and don't use size-=1 (fdisk_align_lba_in_range() returns unmodified size and we call size=-1 more than once for the same size). Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index 9176a6d101..efb1faf37a 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -280,6 +280,8 @@ static struct fdisk_parttype gpt_parttypes[] = DEF_GUID("C91818F9-8025-47AF-89D2-F030D7000C2C", N_("Plan 9 partition")) }; +#define alignment_required(_x) ((_x)->grain != (_x)->sector_size) + /* gpt_entry macros */ #define gpt_partition_start(_e) le64_to_cpu((_e)->lba_start) #define gpt_partition_end(_e) le64_to_cpu((_e)->lba_end) @@ -2320,8 +2322,12 @@ static int gpt_add_partition( user_l = user_f + pa->size - 1; DBG(LABEL, ul_debug("size defined: %ju, end: %"PRIu64" (last possible: %"PRIu64")", (uintmax_t)pa->size, user_l, dflt_l)); - if (user_l != dflt_l && !pa->size_explicit + + if (user_l != dflt_l + && !pa->size_explicit + && alignment_required(cxt) && user_l - user_f > (cxt->grain / fdisk_get_sector_size(cxt))) { + user_l = fdisk_align_lba_in_range(cxt, user_l, user_f, dflt_l); if (user_l > user_f) user_l -= 1ULL;