From: Sascha Hauer <s.hauer@pengutronix.de>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
Cc: barebox@lists.infradead.org
Subject: Re: [PATCH v2] partitions: dos: improve guess of disk size
Date: Fri, 8 Nov 2013 15:27:29 +0100 [thread overview]
Message-ID: <20131108142729.GV24559@pengutronix.de> (raw)
In-Reply-To: <1383905581-28470-1-git-send-email-u.kleine-koenig@pengutronix.de>
On Fri, Nov 08, 2013 at 11:13:01AM +0100, Uwe Kleine-König wrote:
> The code used to ineffectively take the end of the last partition as guess
> for the disk size. Better use the end of the partition that has its end
> rearmost.
>
> Also return an unsigned type instead of int as the result is always
> non-negative.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Applied, thanks
Sascha
> ---
> common/partitions/dos.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/common/partitions/dos.c b/common/partitions/dos.c
> index 9afd122..64314a8 100644
> --- a/common/partitions/dos.c
> +++ b/common/partitions/dos.c
> @@ -27,19 +27,23 @@
> * @param table partition table
> * @return sector count
> */
> -static int disk_guess_size(struct device_d *dev, struct partition_entry *table)
> +static uint64_t disk_guess_size(struct device_d *dev,
> + struct partition_entry *table)
> {
> uint64_t size = 0;
> int i;
>
> for (i = 0; i < 4; i++) {
> - if (table[i].partition_start != 0) {
> - size += get_unaligned_le32(&table[i].partition_start) - size;
> - size += get_unaligned_le32(&table[i].partition_size);
> + if (get_unaligned_le32(&table[i].partition_start) != 0) {
> + uint64_t part_end = get_unaligned_le32(&table[i].partition_start) +
> + get_unaligned_le32(&table[i].partition_size);
> +
> + if (size < part_end)
> + size = part_end;
> }
> }
>
> - return (int)size;
> + return size;
> }
>
> static void *read_mbr(struct block_device *blk)
> --
> 1.8.4.rc3
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
prev parent reply other threads:[~2013-11-08 14:27 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-08 0:16 [PATCH] " Uwe Kleine-König
2013-11-08 0:50 ` Uwe Kleine-König
2013-11-08 4:36 ` Alexander Aring
2013-11-08 10:13 ` [PATCH v2] " Uwe Kleine-König
2013-11-08 14:27 ` Sascha Hauer [this message]
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=20131108142729.GV24559@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=u.kleine-koenig@pengutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox