All of lore.kernel.org
 help / color / mirror / Atom feed
From: <Fabian.Kirsch@dlr.de>
To: <util-linux@vger.kernel.org>
Subject: [PATCH] sanity check, to prevent overlapping partitions from being partly reported as free
Date: Wed, 13 Feb 2019 14:49:10 +0000	[thread overview]
Message-ID: <1550069424.28515.10.camel@dlr.de> (raw)

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(-)

diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c
index 4881db68e..3d32695f4 100644
--- a/libfdisk/src/table.c
+++ b/libfdisk/src/table.c
@@ -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++;
 	}
 
-- 
2.12.3

             reply	other threads:[~2019-02-13 14:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-13 14:49 Fabian.Kirsch [this message]
2019-02-18 12:05 ` [PATCH] sanity check, to prevent overlapping partitions from being partly reported as free Karel Zak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1550069424.28515.10.camel@dlr.de \
    --to=fabian.kirsch@dlr.de \
    --cc=util-linux@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.