From 2dd66a4c5f888d6c059091969f187f2f0fac35fd Mon Sep 17 00:00:00 2001
From: Vladimir Serbinenko <phcoder@gmail.com>
Date: Wed, 11 Dec 2013 15:54:01 +0100
Subject: [PATCH 1/9] 	* include/grub/efi/api.h (grub_efi_device_path):
 Define length as 	unaligned u16 rather than u8[2].

---
 grub-core/disk/efi/efidisk.c       | 9 +++------
 grub-core/loader/efi/chainloader.c | 7 ++-----
 include/grub/efi/api.h             | 7 +++----
 3 files changed, 8 insertions(+), 15 deletions(-)

Index: grub-2.00/grub-core/disk/efi/efidisk.c
===================================================================
--- grub-2.00.orig/grub-core/disk/efi/efidisk.c
+++ grub-2.00/grub-core/disk/efi/efidisk.c
@@ -157,8 +157,7 @@ find_parent_device (struct grub_efidisk_
   ldp = find_last_device_path (dp);
   ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
   ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
-  ldp->length[0] = sizeof (*ldp);
-  ldp->length[1] = 0;
+  ldp->length = sizeof (*ldp);
 
   for (parent = devices; parent; parent = parent->next)
     {
@@ -192,8 +191,7 @@ iterate_child_devices (struct grub_efidi
       ldp = find_last_device_path (dp);
       ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
       ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
-      ldp->length[0] = sizeof (*ldp);
-      ldp->length[1] = 0;
+      ldp->length = sizeof (*ldp);
 
       if (grub_efi_compare_device_paths (dp, d->device_path) == 0)
 	if (hook (p))
@@ -803,8 +801,7 @@ grub_efidisk_get_device_name (grub_efi_h
       dup_ldp = find_last_device_path (dup_dp);
       dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
       dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
-      dup_ldp->length[0] = sizeof (*dup_ldp);
-      dup_ldp->length[1] = 0;
+      dup_ldp->length = sizeof (*dup_ldp);
 
       if (!get_diskname_from_path (dup_dp, device_name))
 	return 0;
@@ -852,8 +849,7 @@ grub_efidisk_get_device_name (grub_efi_h
       dup_ldp = find_last_device_path (dup_dp);
       dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
       dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
-      dup_ldp->length[0] = 4;
-      dup_ldp->length[1] = 0;
+      dup_ldp->length = 4;
 
       if (!get_diskname_from_path (dup_dp, device_name))
         {
Index: grub-2.00/grub-core/loader/efi/chainloader.c
===================================================================
--- grub-2.00.orig/grub-core/loader/efi/chainloader.c
+++ grub-2.00/grub-core/loader/efi/chainloader.c
@@ -135,9 +135,7 @@ copy_file_path (grub_efi_file_path_devic
     if (*p == '/')
       *p = '\\';
 
-  size = size * sizeof (grub_efi_char16_t) + sizeof (*fp);
-  fp->header.length[0] = (grub_efi_uint8_t) (size & 0xff);
-  fp->header.length[1] = (grub_efi_uint8_t) (size >> 8);
+  fp->header.length = size * sizeof (grub_efi_char16_t) + sizeof (*fp);
 }
 
 static grub_efi_device_path_t *
@@ -197,8 +195,7 @@ make_file_path (grub_efi_device_path_t *
   d = GRUB_EFI_NEXT_DEVICE_PATH (d);
   d->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
   d->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
-  d->length[0] = sizeof (*d);
-  d->length[1] = 0;
+  d->length = sizeof (*d);
 
   return file_path;
 }
Index: grub-2.00/include/grub/efi/api.h
===================================================================
--- grub-2.00.orig/include/grub/efi/api.h
+++ grub-2.00/include/grub/efi/api.h
@@ -402,8 +402,8 @@ struct grub_efi_device_path
 {
   grub_efi_uint8_t type;
   grub_efi_uint8_t subtype;
-  grub_efi_uint8_t length[2];
-};
+  grub_efi_uint16_t length;
+} __attribute__ ((packed));
 typedef struct grub_efi_device_path grub_efi_device_path_t;
 /* XXX EFI does not define EFI_DEVICE_PATH_PROTOCOL but uses it.
    It seems to be identical to EFI_DEVICE_PATH.  */
@@ -411,8 +411,7 @@ typedef struct grub_efi_device_path grub
 
 #define GRUB_EFI_DEVICE_PATH_TYPE(dp)		((dp)->type & 0x7f)
 #define GRUB_EFI_DEVICE_PATH_SUBTYPE(dp)	((dp)->subtype)
-#define GRUB_EFI_DEVICE_PATH_LENGTH(dp)		\
-  ((dp)->length[0] | ((grub_efi_uint16_t) ((dp)->length[1]) << 8))
+#define GRUB_EFI_DEVICE_PATH_LENGTH(dp)		((dp)->length)
 
 /* The End of Device Path nodes.  */
 #define GRUB_EFI_END_DEVICE_PATH_TYPE			(0xff & 0x7f)
