[parted-devel] [PATCH] libparted: reallocate buf after _disk_analyse_block_size call

Brian C. Lane bcl at redhat.com
Tue Sep 4 23:51:53 UTC 2012


On Tue, Sep 04, 2012 at 04:42:34PM -0700, Brian C. Lane wrote:
> The call to _disk_analyse_block_size may change the
> disk->dev->sector_size, if this happens buf may be too small for
> subsequent reads.
> 
> libparted/labels/mac.c (mac_read): reallocate buf
> ---
>  libparted/labels/mac.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/libparted/labels/mac.c b/libparted/labels/mac.c
> index 1f59a1a..e058124 100644
> --- a/libparted/labels/mac.c
> +++ b/libparted/labels/mac.c
> @@ -759,6 +759,11 @@ mac_read (PedDisk* disk)
>  		mac_disk_data->block_size = raw_disk->block_size;
>  	}
>  
> +	/* re-allocate buf in case _disk_analyse_block_size changed
> +	* the sector_size */
> +	free (buf);
> +	buf = ped_malloc (disk->dev->sector_size);
> +
>  	for (num=1; num==1 || num <= last_part_entry_num; num++) {
>  		void *raw_part = buf;
>  		if (!ped_device_read (disk->dev, raw_part,
> -- 
> 1.7.11.4
> 
> 

I'm looking for comments on this quick test patch. The problem is this:

In Fedora we have a hybrid iso that also contains a couple of EFI boot
partitions in order to make it bootable on EFI systems and on Apple
harware. Parted is sometimes throwing an error when they are written to
a USB stick using dd and then examined with 'parted /dev/sdd p' or
parted -l

I think the right way to fix this is to reallocate the buf with the new
size. The only other alternative I can see is to make
__disk_analyse_block_size always return an error when there is a
mismatch instead of prompting the user.

I'm also not sure how we could write a good test case for this.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 482 bytes
Desc: not available
URL: <http://lists.alioth.debian.org/pipermail/parted-devel/attachments/20120904/28c9a5db/attachment.pgp>


More information about the parted-devel mailing list