[PATCH] partitions: dos: improve guess of disk size

Uwe Kleine-König u.kleine-koenig at pengutronix.de
Thu Nov 7 19:50:37 EST 2013


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 at 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/  |



More information about the barebox mailing list