* [PATCH] partitions: dos: improve guess of disk size
@ 2013-11-08 0:16 Uwe Kleine-König
2013-11-08 0:50 ` Uwe Kleine-König
0 siblings, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2013-11-08 0:16 UTC (permalink / raw)
To: barebox; +Cc: jbe
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>
---
Hello,
note this is only compile tested.
Best regards
Uwe
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..1d8213b 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] partitions: dos: improve guess of disk size
2013-11-08 0:16 [PATCH] partitions: dos: improve guess of disk size 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
0 siblings, 2 replies; 5+ messages in thread
From: Uwe Kleine-König @ 2013-11-08 0:50 UTC (permalink / raw)
To: barebox; +Cc: jbe
On Fri, Nov 08, 2013 at 01:16:31AM +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>
> ---
> Hello,
>
> note this is only compile tested.
... and the introduced warning ignored. I really shouldn't send patches
out that late ...
see below
> --- 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) {
There is an & missing before table.
Best regards
Uwe
> + 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)
--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions | http://www.pengutronix.de/ |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] partitions: dos: improve guess of disk size
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
1 sibling, 0 replies; 5+ messages in thread
From: Alexander Aring @ 2013-11-08 4:36 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox, jbe
On Fri, Nov 08, 2013 at 01:50:37AM +0100, Uwe Kleine-König wrote:
> On Fri, Nov 08, 2013 at 01:16:31AM +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>
> > ---
> > Hello,
> >
> > note this is only compile tested.
> ... and the introduced warning ignored. I really shouldn't send patches
> out that late ...
>
hehe, I know what you mean. :-)
- Alex
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] partitions: dos: improve guess of disk size
2013-11-08 0:50 ` Uwe Kleine-König
2013-11-08 4:36 ` Alexander Aring
@ 2013-11-08 10:13 ` Uwe Kleine-König
2013-11-08 14:27 ` Sascha Hauer
1 sibling, 1 reply; 5+ messages in thread
From: Uwe Kleine-König @ 2013-11-08 10:13 UTC (permalink / raw)
To: barebox
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>
---
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] partitions: dos: improve guess of disk size
2013-11-08 10:13 ` [PATCH v2] " Uwe Kleine-König
@ 2013-11-08 14:27 ` Sascha Hauer
0 siblings, 0 replies; 5+ messages in thread
From: Sascha Hauer @ 2013-11-08 14:27 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-11-08 14:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-08 0:16 [PATCH] partitions: dos: improve guess of disk size 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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox