summaryrefslogtreecommitdiffstats
path: root/common/partitions
diff options
context:
space:
mode:
authorUwe Kleine-König <u.kleine-koenig@pengutronix.de>2013-11-08 11:13:01 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2013-11-08 15:27:17 +0100
commite55160fe10ffce82df8e39d6dda48ee9512bf066 (patch)
tree00d85a13b1bcad27c7812aee86ec74db46351242 /common/partitions
parent480782a2659bd14f751d893abeed974443c5976c (diff)
downloadbarebox-e55160fe10ffce82df8e39d6dda48ee9512bf066.tar.gz
barebox-e55160fe10ffce82df8e39d6dda48ee9512bf066.tar.xz
partitions: dos: improve guess of disk size
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> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/partitions')
-rw-r--r--common/partitions/dos.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index 31b1ed60d1..2e39e7d816 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)