diff options
author | Karel Zak | 2017-08-22 14:48:14 +0200 |
---|---|---|
committer | Karel Zak | 2017-08-22 14:48:14 +0200 |
commit | 694a407de9ff9ce92f8a620d7161734d207a9f00 (patch) | |
tree | 99305831cab47dbb1bb924e0f4785ca9772dc68b /libfdisk/src | |
parent | docs: add CAP_SYS_ADMIN to TODO (diff) | |
download | kernel-qcow2-util-linux-694a407de9ff9ce92f8a620d7161734d207a9f00.tar.gz kernel-qcow2-util-linux-694a407de9ff9ce92f8a620d7161734d207a9f00.tar.xz kernel-qcow2-util-linux-694a407de9ff9ce92f8a620d7161734d207a9f00.zip |
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 <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src')
-rw-r--r-- | libfdisk/src/gpt.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index 4904b4dea..73590156e 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) @@ -2332,8 +2334,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; |