dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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