Fix definition of grub_efi_hard_drive_device_path. Take care that

existing code would work even if by some reason bogus definition is
	used by EFI implementations.
This commit is contained in:
Vladimir Serbinenko 2013-12-14 22:04:02 +01:00
parent f2c6ff15e5
commit 6dc3337774
4 changed files with 24 additions and 18 deletions

View File

@ -1,3 +1,9 @@
2013-12-14 Vladimir Serbinenko <phcoder@gmail.com>
Fix definition of grub_efi_hard_drive_device_path. Take care that
existing code would work even if by some reason bogus definition is
used by EFI implementations.
2013-12-14 Vladimir Serbinenko <phcoder@gmail.com> 2013-12-14 Vladimir Serbinenko <phcoder@gmail.com>
* grub-core/osdep/windows/hostdisk.c: Fix cygwin compilation. * grub-core/osdep/windows/hostdisk.c: Fix cygwin compilation.

View File

@ -666,20 +666,20 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
devices = make_devices (); devices = make_devices ();
FOR_CHILDREN (c, devices) FOR_CHILDREN (c, devices)
{ {
grub_efi_hard_drive_device_path_t hd; grub_efi_hard_drive_device_path_t *hd;
grub_memcpy (&hd, c->last_device_path, sizeof (hd)); hd = (grub_efi_hard_drive_device_path_t *) c->last_device_path;
if ((GRUB_EFI_DEVICE_PATH_TYPE (c->last_device_path) if ((GRUB_EFI_DEVICE_PATH_TYPE (c->last_device_path)
== GRUB_EFI_MEDIA_DEVICE_PATH_TYPE) == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE)
&& (GRUB_EFI_DEVICE_PATH_SUBTYPE (c->last_device_path) && (GRUB_EFI_DEVICE_PATH_SUBTYPE (c->last_device_path)
== GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE) == GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE)
&& (grub_partition_get_start (disk->partition) && (grub_partition_get_start (disk->partition)
== (hd.partition_start << (disk->log_sector_size == (hd->partition_start << (disk->log_sector_size
- GRUB_DISK_SECTOR_BITS))) - GRUB_DISK_SECTOR_BITS)))
&& (grub_partition_get_len (disk->partition) && (grub_partition_get_len (disk->partition)
== (hd.partition_size << (disk->log_sector_size == (hd->partition_size << (disk->log_sector_size
- GRUB_DISK_SECTOR_BITS)))) - GRUB_DISK_SECTOR_BITS))))
{ {
handle = c->handle; handle = c->handle;
break; break;
@ -745,7 +745,7 @@ get_diskname_from_path (const grub_efi_device_path_t *path,
struct grub_efidisk_get_device_name_ctx struct grub_efidisk_get_device_name_ctx
{ {
char *partition_name; char *partition_name;
grub_efi_hard_drive_device_path_t hd; grub_efi_hard_drive_device_path_t *hd;
}; };
/* Helper for grub_efidisk_get_device_name. /* Helper for grub_efidisk_get_device_name.
@ -757,11 +757,11 @@ grub_efidisk_get_device_name_iter (grub_disk_t disk,
struct grub_efidisk_get_device_name_ctx *ctx = data; struct grub_efidisk_get_device_name_ctx *ctx = data;
if (grub_partition_get_start (part) if (grub_partition_get_start (part)
== (ctx->hd.partition_start << (disk->log_sector_size == (ctx->hd->partition_start << (disk->log_sector_size
- GRUB_DISK_SECTOR_BITS)) - GRUB_DISK_SECTOR_BITS))
&& grub_partition_get_len (part) && grub_partition_get_len (part)
== (ctx->hd.partition_size << (disk->log_sector_size == (ctx->hd->partition_size << (disk->log_sector_size
- GRUB_DISK_SECTOR_BITS))) - GRUB_DISK_SECTOR_BITS)))
{ {
ctx->partition_name = grub_partition_get_name (part); ctx->partition_name = grub_partition_get_name (part);
return 1; return 1;
@ -831,10 +831,10 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
/* Find a partition which matches the hard drive device path. */ /* Find a partition which matches the hard drive device path. */
ctx.partition_name = NULL; ctx.partition_name = NULL;
grub_memcpy (&ctx.hd, ldp, sizeof (ctx.hd)); ctx.hd = (grub_efi_hard_drive_device_path_t *) ldp;
if (ctx.hd.partition_start == 0 if (ctx.hd->partition_start == 0
&& (ctx.hd.partition_size << (parent->log_sector_size && (ctx.hd->partition_size << (parent->log_sector_size
- GRUB_DISK_SECTOR_BITS)) - GRUB_DISK_SECTOR_BITS))
== grub_disk_get_size (parent)) == grub_disk_get_size (parent))
{ {
dev_name = grub_strdup (parent->name); dev_name = grub_strdup (parent->name);

View File

@ -704,7 +704,7 @@ grub_efi_print_device_path (grub_efi_device_path_t *dp)
(unsigned) hd->partition_signature[5], (unsigned) hd->partition_signature[5],
(unsigned) hd->partition_signature[6], (unsigned) hd->partition_signature[6],
(unsigned) hd->partition_signature[7], (unsigned) hd->partition_signature[7],
(unsigned) hd->mbr_type, (unsigned) hd->partmap_type,
(unsigned) hd->signature_type); (unsigned) hd->signature_type);
} }
break; break;

View File

@ -827,8 +827,8 @@ struct grub_efi_hard_drive_device_path
grub_efi_uint32_t partition_number; grub_efi_uint32_t partition_number;
grub_efi_lba_t partition_start; grub_efi_lba_t partition_start;
grub_efi_lba_t partition_size; grub_efi_lba_t partition_size;
grub_efi_uint8_t partition_signature[8]; grub_efi_uint8_t partition_signature[16];
grub_efi_uint8_t mbr_type; grub_efi_uint8_t partmap_type;
grub_efi_uint8_t signature_type; grub_efi_uint8_t signature_type;
} __attribute__ ((packed)); } __attribute__ ((packed));
typedef struct grub_efi_hard_drive_device_path grub_efi_hard_drive_device_path_t; typedef struct grub_efi_hard_drive_device_path grub_efi_hard_drive_device_path_t;