Skip to contentSkip to conversation

sanity check, to prevent overlapping partitions from being partly reported as free

PATCH Applied [email protected] 2 participants 2 messages Feb 13, 2019 – Feb 18, 2019 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sanity check, to prevent overlapping partitions from being partly reported as free

Hi,

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

---
 libfdisk/src/table.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
libfdisk/src/table.c +6 -2
index 4881db68e..3d32695f4 100644
@@ -582,7 +582,7 @@ int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb)
 {
 	int rc = 0;
 	size_t nparts = 0;
-	fdisk_sector_t last, grain;
+	fdisk_sector_t last, grain, pa_end;
 	struct fdisk_table *parts = NULL;
 	struct fdisk_partition *pa;
 	struct fdisk_iter itr;
@@ -632,7 +632,11 @@ 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)) {
+			pa_end = fdisk_partition_get_end(pa);
+			if(pa_end > last)
+				last = pa_end;
+		}
 		nparts++;
 	}
 
Signature · 1 line
2.12.3
maintainer Applied
#1 lore raw
Quoted 2 lines · On Wed, Feb 13, 2019 at 02:49:10PM +0000, [email protected] wrote:
 libfdisk/src/table.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Applied, thanks.

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com