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

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