Blame SOURCES/0157-efidisk-move-device-path-helpers-in-core-for-efinet.patch

f731ee
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f731ee
From: Andrei Borzenkov <arvidjaar@gmail.com>
f731ee
Date: Thu, 7 May 2015 20:37:16 +0300
f731ee
Subject: [PATCH] efidisk: move device path helpers in core for efinet
f731ee
f731ee
---
f731ee
 grub-core/disk/efi/efidisk.c | 61 ++++++++------------------------------------
f731ee
 grub-core/kern/efi/efi.c     | 41 +++++++++++++++++++++++++++++
f731ee
 include/grub/efi/efi.h       |  4 +++
f731ee
 3 files changed, 55 insertions(+), 51 deletions(-)
f731ee
f731ee
diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c
f731ee
index 3b12c349923..845c66fa9ab 100644
f731ee
--- a/grub-core/disk/efi/efidisk.c
f731ee
+++ b/grub-core/disk/efi/efidisk.c
f731ee
@@ -43,47 +43,6 @@ static struct grub_efidisk_data *fd_devices;
f731ee
 static struct grub_efidisk_data *hd_devices;
f731ee
 static struct grub_efidisk_data *cd_devices;
f731ee
 
f731ee
-/* Duplicate a device path.  */
f731ee
-static grub_efi_device_path_t *
f731ee
-duplicate_device_path (const grub_efi_device_path_t *dp)
f731ee
-{
f731ee
-  grub_efi_device_path_t *p;
f731ee
-  grub_size_t total_size = 0;
f731ee
-
f731ee
-  for (p = (grub_efi_device_path_t *) dp;
f731ee
-       ;
f731ee
-       p = GRUB_EFI_NEXT_DEVICE_PATH (p))
f731ee
-    {
f731ee
-      total_size += GRUB_EFI_DEVICE_PATH_LENGTH (p);
f731ee
-      if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (p))
f731ee
-	break;
f731ee
-    }
f731ee
-
f731ee
-  p = grub_malloc (total_size);
f731ee
-  if (! p)
f731ee
-    return 0;
f731ee
-
f731ee
-  grub_memcpy (p, dp, total_size);
f731ee
-  return p;
f731ee
-}
f731ee
-
f731ee
-/* Return the device path node right before the end node.  */
f731ee
-static grub_efi_device_path_t *
f731ee
-find_last_device_path (const grub_efi_device_path_t *dp)
f731ee
-{
f731ee
-  grub_efi_device_path_t *next, *p;
f731ee
-
f731ee
-  if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp))
f731ee
-    return 0;
f731ee
-
f731ee
-  for (p = (grub_efi_device_path_t *) dp, next = GRUB_EFI_NEXT_DEVICE_PATH (p);
f731ee
-       ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (next);
f731ee
-       p = next, next = GRUB_EFI_NEXT_DEVICE_PATH (next))
f731ee
-    ;
f731ee
-
f731ee
-  return p;
f731ee
-}
f731ee
-
f731ee
 static struct grub_efidisk_data *
f731ee
 make_devices (void)
f731ee
 {
f731ee
@@ -110,7 +69,7 @@ make_devices (void)
f731ee
       if (! dp)
f731ee
 	continue;
f731ee
 
f731ee
-      ldp = find_last_device_path (dp);
f731ee
+      ldp = grub_efi_find_last_device_path (dp);
f731ee
       if (! ldp)
f731ee
 	/* This is empty. Why?  */
f731ee
 	continue;
f731ee
@@ -150,11 +109,11 @@ find_parent_device (struct grub_efidisk_data *devices,
f731ee
   grub_efi_device_path_t *dp, *ldp;
f731ee
   struct grub_efidisk_data *parent;
f731ee
 
f731ee
-  dp = duplicate_device_path (d->device_path);
f731ee
+  dp = grub_efi_duplicate_device_path (d->device_path);
f731ee
   if (! dp)
f731ee
     return 0;
f731ee
 
f731ee
-  ldp = find_last_device_path (dp);
f731ee
+  ldp = grub_efi_find_last_device_path (dp);
f731ee
   ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
f731ee
   ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
f731ee
   ldp->length = sizeof (*ldp);
f731ee
@@ -180,11 +139,11 @@ is_child (struct grub_efidisk_data *child,
f731ee
   grub_efi_device_path_t *dp, *ldp;
f731ee
   int ret;
f731ee
 
f731ee
-  dp = duplicate_device_path (child->device_path);
f731ee
+  dp = grub_efi_duplicate_device_path (child->device_path);
f731ee
   if (! dp)
f731ee
     return 0;
f731ee
 
f731ee
-  ldp = find_last_device_path (dp);
f731ee
+  ldp = grub_efi_find_last_device_path (dp);
f731ee
   ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
f731ee
   ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
f731ee
   ldp->length = sizeof (*ldp);
f731ee
@@ -207,8 +166,8 @@ add_device (struct grub_efidisk_data **devices, struct grub_efidisk_data *d)
f731ee
     {
f731ee
       int ret;
f731ee
 
f731ee
-      ret = grub_efi_compare_device_paths (find_last_device_path ((*p)->device_path),
f731ee
-					   find_last_device_path (d->device_path));
f731ee
+      ret = grub_efi_compare_device_paths (grub_efi_find_last_device_path ((*p)->device_path),
f731ee
+					   grub_efi_find_last_device_path (d->device_path));
f731ee
       if (ret == 0)
f731ee
 	ret = grub_efi_compare_device_paths ((*p)->device_path,
f731ee
 					     d->device_path);
f731ee
@@ -795,7 +754,7 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
f731ee
   if (! dp)
f731ee
     return 0;
f731ee
 
f731ee
-  ldp = find_last_device_path (dp);
f731ee
+  ldp = grub_efi_find_last_device_path (dp);
f731ee
   if (! ldp)
f731ee
     return 0;
f731ee
 
f731ee
@@ -811,14 +770,14 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
f731ee
 
f731ee
       /* It is necessary to duplicate the device path so that GRUB
f731ee
 	 can overwrite it.  */
f731ee
-      dup_dp = duplicate_device_path (dp);
f731ee
+      dup_dp = grub_efi_duplicate_device_path (dp);
f731ee
       if (! dup_dp)
f731ee
 	return 0;
f731ee
 
f731ee
       while (1)
f731ee
 	{
f731ee
 	  grub_efi_device_path_t *dup_ldp;
f731ee
-	  dup_ldp = find_last_device_path (dup_dp);
f731ee
+	  dup_ldp = grub_efi_find_last_device_path (dup_dp);
f731ee
 	  if (!(GRUB_EFI_DEVICE_PATH_TYPE (dup_ldp) == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
f731ee
 		&& (GRUB_EFI_DEVICE_PATH_SUBTYPE (dup_ldp) == GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE
f731ee
 		    || GRUB_EFI_DEVICE_PATH_SUBTYPE (dup_ldp) == GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE)))
f731ee
diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c
f731ee
index d99a6fbdf0d..c80d85b677e 100644
f731ee
--- a/grub-core/kern/efi/efi.c
f731ee
+++ b/grub-core/kern/efi/efi.c
f731ee
@@ -423,6 +423,47 @@ grub_efi_get_device_path (grub_efi_handle_t handle)
f731ee
 				 GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL);
f731ee
 }
f731ee
 
f731ee
+/* Return the device path node right before the end node.  */
f731ee
+grub_efi_device_path_t *
f731ee
+grub_efi_find_last_device_path (const grub_efi_device_path_t *dp)
f731ee
+{
f731ee
+  grub_efi_device_path_t *next, *p;
f731ee
+
f731ee
+  if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (dp))
f731ee
+    return 0;
f731ee
+
f731ee
+  for (p = (grub_efi_device_path_t *) dp, next = GRUB_EFI_NEXT_DEVICE_PATH (p);
f731ee
+       ! GRUB_EFI_END_ENTIRE_DEVICE_PATH (next);
f731ee
+       p = next, next = GRUB_EFI_NEXT_DEVICE_PATH (next))
f731ee
+    ;
f731ee
+
f731ee
+  return p;
f731ee
+}
f731ee
+
f731ee
+/* Duplicate a device path.  */
f731ee
+grub_efi_device_path_t *
f731ee
+grub_efi_duplicate_device_path (const grub_efi_device_path_t *dp)
f731ee
+{
f731ee
+  grub_efi_device_path_t *p;
f731ee
+  grub_size_t total_size = 0;
f731ee
+
f731ee
+  for (p = (grub_efi_device_path_t *) dp;
f731ee
+       ;
f731ee
+       p = GRUB_EFI_NEXT_DEVICE_PATH (p))
f731ee
+    {
f731ee
+      total_size += GRUB_EFI_DEVICE_PATH_LENGTH (p);
f731ee
+      if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (p))
f731ee
+	break;
f731ee
+    }
f731ee
+
f731ee
+  p = grub_malloc (total_size);
f731ee
+  if (! p)
f731ee
+    return 0;
f731ee
+
f731ee
+  grub_memcpy (p, dp, total_size);
f731ee
+  return p;
f731ee
+}
f731ee
+
f731ee
 static void
f731ee
 dump_vendor_path (const char *type, grub_efi_vendor_device_path_t *vendor)
f731ee
 {
f731ee
diff --git a/include/grub/efi/efi.h b/include/grub/efi/efi.h
f731ee
index a000c383e81..22456327e13 100644
f731ee
--- a/include/grub/efi/efi.h
f731ee
+++ b/include/grub/efi/efi.h
f731ee
@@ -56,6 +56,10 @@ void EXPORT_FUNC(grub_efi_print_device_path) (grub_efi_device_path_t *dp);
f731ee
 char *EXPORT_FUNC(grub_efi_get_filename) (grub_efi_device_path_t *dp);
f731ee
 grub_efi_device_path_t *
f731ee
 EXPORT_FUNC(grub_efi_get_device_path) (grub_efi_handle_t handle);
f731ee
+grub_efi_device_path_t *
f731ee
+EXPORT_FUNC(grub_efi_find_last_device_path) (const grub_efi_device_path_t *dp);
f731ee
+grub_efi_device_path_t *
f731ee
+EXPORT_FUNC(grub_efi_duplicate_device_path) (const grub_efi_device_path_t *dp);
f731ee
 grub_err_t EXPORT_FUNC (grub_efi_finish_boot_services) (grub_efi_uintn_t *outbuf_size, void *outbuf,
f731ee
 							grub_efi_uintn_t *map_key,
f731ee
 							grub_efi_uintn_t *efi_desc_size,