Subject: bug#17108: [PATCH] libparted: Check AlternateLBA against LBA-1

From: "Brian C. Lane" <[email-masked]>
Date: Mon, 7 Apr 2014 17:38:12 -0700

On Thu, Mar 27, 2014 at 08:05:14PM -0400, Phillip Susi wrote:
> t0210-gpt-resized-partition-entry-array failed because gpt-header-munge
> did not relocate the LastUsableLBA to agree with the smaller table size.
> This caused parted to complain that the backup was not at the end of the
> disk ( as indicated by LastUsableLBA ), when in fact, it was.  Accept
> the current AlternateLBA if it is *either* in the right place relative
> to LastUsableLBA, or the last sector of the disk.
> ---
>  libparted/labels/gpt.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
> index 42b0360..971c1c0 100644
> --- a/libparted/labels/gpt.c
> +++ b/libparted/labels/gpt.c
> @@ -991,7 +991,8 @@ gpt_read (PedDisk *disk)
>                         disk->dev->sector_size);
>  
>        gpt_disk_data->AlternateLBA = PED_LE64_TO_CPU (primary_gpt->AlternateLBA);
> -      if (PED_LE64_TO_CPU (primary_gpt->AlternateLBA) != gpt_disk_end)
> +      if (gpt_disk_data->AlternateLBA != gpt_disk_end &&
> +	  gpt_disk_data->AlternateLBA != disk->dev->length - 1)
>          {
>            if (ped_exception_throw
>                    (PED_EXCEPTION_ERROR,
> -- 
> 1.8.3.2
> 

That can't work either:

1 - you dropped PED_LE64_TO_CPU
2 - if the PE count doesn't match the amount of space between the start
and the backup.
3 - when we fix the backup we *must* write it to length-1, not to the
possibly incorrect gpt_disk_end.

I think we're better off dropping one or the other of these prompts.
I've accepted the inevitability of leaving the header in place and using
it as is, I'm fine with those bits of the patches.

The check for extra space will catch a out of position backup, there's
no need to have two different ways to check. Either the backup is at
length-1 or there is extra space.

I'll revisit your comments about last_usable_min_default tomorrow.

-- 
Brian C. Lane | Anaconda Team | IRC: bcl #anaconda | Port Orchard, WA (PST8PDT)