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

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