Avoid consuming lots of space and time if the first partition is not near the start of the disk (Debian bug #619458, Ubuntu bug #691569).

This commit is contained in:
Colin Watson 2011-03-25 17:22:12 +00:00
parent 7bdeb3987a
commit 58ed62d221
5 changed files with 27 additions and 7 deletions

View file

@ -125,6 +125,7 @@ gpt_partition_map_iterate (grub_disk_t disk,
#ifdef GRUB_UTIL
static grub_err_t
gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
unsigned int max_nsectors,
grub_embed_type_t embed_type,
grub_disk_addr_t **sectors)
{
@ -174,6 +175,8 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
" embedding won't be possible!");
*nsectors = len;
if (*nsectors > max_nsectors)
*nsectors = max_nsectors;
*sectors = grub_malloc (*nsectors * sizeof (**sectors));
if (!*sectors)
return grub_errno;

View file

@ -185,6 +185,7 @@ grub_partition_msdos_iterate (grub_disk_t disk,
#ifdef GRUB_UTIL
static grub_err_t
pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
unsigned int max_nsectors,
grub_embed_type_t embed_type,
grub_disk_addr_t **sectors)
{
@ -275,10 +276,13 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
{
unsigned i, j;
char *embed_signature_check;
unsigned int orig_nsectors;
unsigned int orig_nsectors, avail_nsectors;
orig_nsectors = *nsectors;
*nsectors = end - 2;
avail_nsectors = *nsectors;
if (*nsectors > max_nsectors)
*nsectors = max_nsectors;
*sectors = grub_malloc (*nsectors * sizeof (**sectors));
if (!*sectors)
return grub_errno;
@ -307,11 +311,20 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
"future. Please ask its authors not to store data "
"in the boot track",
(*sectors)[i], embed_signatures[j].name);
(*nsectors)--;
avail_nsectors--;
if (avail_nsectors < *nsectors)
*nsectors = avail_nsectors;
/* Avoid this sector. */
for (j = i; j < *nsectors; j++)
(*sectors)[j]++;
/* Have we run out of space? */
if (avail_nsectors < orig_nsectors)
break;
/* Make sure to check the next sector. */
i--;
}
grub_free (embed_signature_check);