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

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