]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) fix size-1 error
authorKarel Zak <kzak@redhat.com>
Tue, 22 Aug 2017 12:48:14 +0000 (14:48 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 20 Sep 2017 12:20:19 +0000 (14:20 +0200)
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 <kzak@redhat.com>
libfdisk/src/gpt.c

index 9176a6d1011b165ba6fb1ded5b820de941c4b6a7..efb1faf37abb6d8674e1283d50f133ba161c65b3 100644 (file)
@@ -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;