]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: fix last free sector detection if partition size specified
authorKarel Zak <kzak@redhat.com>
Mon, 10 Aug 2020 09:37:32 +0000 (11:37 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 10 Aug 2020 09:37:32 +0000 (11:37 +0200)
We need to skip useless gaps between partition if the gap is no large
enough for a new partition. Unfortunately, the current code checks
size of the gap, but does not care for location of the gap -- this is
good enough for dialog driven partitioning, but it's pretty bad if
start of the partition is explicitly specified (e.g. sfdisk).

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1860461
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c

index 176969883547abfa10f7ed8e2ce9c14abdcf56fd..890e33a262ff5bc0078b3edab71cf7290b20df17 100644 (file)
@@ -1274,14 +1274,14 @@ static int add_partition(struct fdisk_context *cxt, size_t n,
                        fdisk_sector_t last;
 
                        rc = find_last_free(cxt, is_logical, start, limit, &last);
-
                        if (rc == 0 && last - start + 1 < fdisk_partition_get_size(pa)) {
                                DBG(LABEL, ul_debug("DOS: area <%ju,%ju> too small [wanted=%ju aval=%ju]",
                                                        (uintmax_t) start, (uintmax_t) last,
                                                        fdisk_partition_get_size(pa),
                                                        last - start));
 
-                               if (fdisk_partition_has_start(pa))
+                               if (fdisk_partition_has_start(pa)
+                                   && fdisk_partition_get_start(pa) <= last)
                                        rc = -ENOSPC;
                                else {
                                        start = last + 1;