Avoid end partition overlap when resizing extended partition (#678831)

When resizing an extended partition, a problem can occur with MiB
alignment wherein the requested end sector could be less than the end
sector of the last logical partition.  This would be an invalid
geometry because all the logical partitions must be wholly contained
within the extended partition.

Check for this situation and if found then set requested end for
the extended partition to the end of the last logical partition.

Closes Bug #678831 - Partition End Overlap when Resizing Extended
                     Partition
This commit is contained in:
Curtis Gedak 2012-06-30 10:35:08 -06:00
parent 367945bbb2
commit 6a6607e1c6
1 changed files with 20 additions and 0 deletions

View File

@ -566,6 +566,26 @@ bool GParted_Core::snap_to_mebibyte( const Device & device, Partition & partitio
}
}
//If this is an extended partition then check to see if the end of the
// extended partition encompasses the end of the last logical partition.
if ( partition .type == TYPE_EXTENDED )
{
//If there is logical partition that has an end sector beyond the
// end of the extended partition, then set the extended partition
// end sector to be the same as the end of the logical partition.
for ( unsigned int t = 0; t < partition .logicals .size(); t++ )
{
if ( ( partition .logicals[ t ] .type == TYPE_LOGICAL )
&& ( ( partition .logicals[ t ] .sector_end )
> ( partition .sector_end )
)
)
{
partition .sector_end = partition .logicals[ t ] .sector_end ;
}
}
}
//If this is a GPT partition table and the partition ends less than 34 sectors
// from the end of the device, then reserve at least a mebibyte for the
// backup partition table