From f7606d2d9f8f7fc28b6b5e6cb295d4104b3df69b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 11 Jan 2018 14:23:57 +0100 Subject: [PATCH] libfdisk: (sun) fix n-1 bug and whole-disk * set whole_disk variable if SUN_TAG_WHOLEDISK specified * fix N-1 bug in add new partition according to template (script) Addresses: https://github.com/karelzak/util-linux/issues/555 Signed-off-by: Karel Zak --- libfdisk/src/sun.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libfdisk/src/sun.c b/libfdisk/src/sun.c index 0be4d8df68..a247dbcf57 100644 --- a/libfdisk/src/sun.c +++ b/libfdisk/src/sun.c @@ -522,6 +522,9 @@ static int sun_add_partition( fetch_sun(cxt, starts, lens, &start, &stop); + if (pa && pa->type && pa->type->code == SUN_TAG_WHOLEDISK) + whole_disk = 1; + if (stop <= start) { if (n == 2) whole_disk = 1; @@ -629,8 +632,9 @@ static int sun_add_partition( /* last */ if (pa && pa->end_follow_default) last = whole_disk || (n == 2 && !first) ? stop2 : stop; + else if (pa && fdisk_partition_has_size(pa)) { - last = first + pa->size - 1ULL; + last = first + pa->size; if (!whole_disk && last > stop) return -ERANGE; -- 2.47.2