Fix a double device name

This commit is contained in:
Vladimir 'phcoder' Serbinenko 2010-09-08 20:39:57 +02:00
parent 7b111db538
commit 3fcb410549
3 changed files with 9 additions and 18 deletions

View file

@ -731,7 +731,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
{ {
/* This is a hard disk partition. */ /* This is a hard disk partition. */
grub_disk_t parent = 0; grub_disk_t parent = 0;
char *partition_name = 0; const grub_partition_t tpart = NULL;
char *device_name; char *device_name;
grub_efi_device_path_t *dup_dp, *dup_ldp; grub_efi_device_path_t *dup_dp, *dup_ldp;
grub_efi_hard_drive_device_path_t hd; grub_efi_hard_drive_device_path_t hd;
@ -770,7 +770,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
if (grub_partition_get_start (part) == hd.partition_start if (grub_partition_get_start (part) == hd.partition_start
&& grub_partition_get_len (part) == hd.partition_size) && grub_partition_get_len (part) == hd.partition_size)
{ {
partition_name = grub_partition_get_name (part); tpart = part;
return 1; return 1;
} }
@ -799,13 +799,15 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
grub_memcpy (&hd, ldp, sizeof (hd)); grub_memcpy (&hd, ldp, sizeof (hd));
grub_partition_iterate (parent, find_partition); grub_partition_iterate (parent, find_partition);
if (! partition_name) if (! tpart)
{ {
grub_disk_close (parent); grub_disk_close (parent);
return 0; return 0;
} }
device_name = grub_xasprintf ("%s,%s", parent->name, partition_name); device_name = grub_xasprintf ("%s,%s%d", parent->name,
tpart->partmap->name,
tpart->number + 1);
grub_free (partition_name); grub_free (partition_name);
grub_disk_close (parent); grub_disk_close (parent);

View file

@ -135,28 +135,22 @@ grub_device_iterate (int (*hook) (const char *name))
int iterate_partition (grub_disk_t disk, const grub_partition_t partition) int iterate_partition (grub_disk_t disk, const grub_partition_t partition)
{ {
char *partition_name;
struct part_ent *p; struct part_ent *p;
partition_name = grub_partition_get_name (partition);
if (! partition_name)
return 1;
p = grub_malloc (sizeof (*p)); p = grub_malloc (sizeof (*p));
if (!p) if (!p)
{ {
grub_free (partition_name);
return 1; return 1;
} }
p->name = grub_xasprintf ("%s,%s", disk->name, partition_name); p->name = grub_xasprintf ("%s,%s%d", disk->name, partition->partmap->name,
partition->number + 1);
if (!p->name) if (!p->name)
{ {
grub_free (partition_name);
grub_free (p); grub_free (p);
return 1; return 1;
} }
grub_free (partition_name);
p->next = ents; p->next = ents;
ents = p; ents = p;

View file

@ -100,15 +100,10 @@ static int
iterate_partition (grub_disk_t disk, const grub_partition_t p) iterate_partition (grub_disk_t disk, const grub_partition_t p)
{ {
const char *disk_name = disk->name; const char *disk_name = disk->name;
char *partition_name = grub_partition_get_name (p);
char *name; char *name;
int ret; int ret;
if (! partition_name) name = grub_xasprintf ("%s,%s%d", disk_name, p->partmap->name, p->number + 1);
return 1;
name = grub_xasprintf ("%s,%s", disk_name, partition_name);
grub_free (partition_name);
if (! name) if (! name)
return 1; return 1;