]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: sanity check, to prevent overlapping partitions from being partly reported...
authorFabian.Kirsch@dlr.de <Fabian.Kirsch@dlr.de>
Wed, 13 Feb 2019 14:49:10 +0000 (14:49 +0000)
committerKarel Zak <kzak@redhat.com>
Tue, 2 Apr 2019 10:57:51 +0000 (12:57 +0200)
i noticed wrongly reported free space when looking with cfdisk on
an USB drive prepared with the latest alpine *.iso[1].

Feel free to apply below patch, which fixed the issue for me.

Greetings
  Fabian

[1]: http://dl-cdn.alpinelinux.org/alpine/v3.9/releases/x86/alpine-extended-3.9.0-x86.iso

Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/table.c

index 4881db68e2acb759050d142e95d1824c02c826eb..d551c8bd7bf6616dde741423ffa7491f02f7530d 100644 (file)
@@ -575,7 +575,7 @@ done:
  *
  * Note that free space smaller than grain (see fdisk_get_grain_size()) is
  * ignored.
-
+ *
  * Returns: 0 on success, otherwise, a corresponding error.
  */
 int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
@@ -632,7 +632,12 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
                /* add gaps between logical partitions */
                if (fdisk_partition_is_container(pa))
                        rc = check_container_freespace(cxt, parts, *tb, pa);
-               last = fdisk_partition_get_end(pa);
+
+               if (fdisk_partition_has_end(pa)) {
+                       fdisk_sector_t pa_end = fdisk_partition_get_end(pa);
+                       if (pa_end > last)
+                               last = fdisk_partition_get_end(pa);
+               }
                nparts++;
        }