grub2/0172-grub-core-disk-efi-efidisk.c-Transform-iterate_child.patch
2013-05-02 16:54:52 -04:00

120 lines
3.3 KiB
Diff

From d81bf19e26c7af47e38206a7cbd825f559ac7457 Mon Sep 17 00:00:00 2001
From: Vladimir 'phcoder' Serbinenko <phcoder@gmail.com>
Date: Fri, 1 Mar 2013 10:37:11 +0100
Subject: [PATCH 172/364] * grub-core/disk/efi/efidisk.c: Transform
iterate_child_devices into a FOR_CHILDREN macro.
---
ChangeLog | 5 ++++
grub-core/disk/efi/efidisk.c | 55 +++++++++++++++++---------------------------
2 files changed, 26 insertions(+), 34 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 986871c..ccd6c0a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
2013-03-01 Vladimir Serbinenko <phcoder@gmail.com>
+ * grub-core/disk/efi/efidisk.c: Transform iterate_child_devices into
+ a FOR_CHILDREN macro.
+
+2013-03-01 Vladimir Serbinenko <phcoder@gmail.com>
+
* grub-core/kern/main.c (grub_set_prefix_and_root): Strip trailing
platform from firmware path.
diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c
index 19c5923..c883b2c 100644
--- a/grub-core/disk/efi/efidisk.c
+++ b/grub-core/disk/efi/efidisk.c
@@ -175,39 +175,29 @@ find_parent_device (struct grub_efidisk_data *devices,
}
static int
-iterate_child_devices (struct grub_efidisk_data *devices,
- struct grub_efidisk_data *d,
- int (*hook) (struct grub_efidisk_data *child))
+is_child (struct grub_efidisk_data *child,
+ struct grub_efidisk_data *parent)
{
- struct grub_efidisk_data *p;
-
- for (p = devices; p; p = p->next)
- {
- grub_efi_device_path_t *dp, *ldp;
-
- dp = duplicate_device_path (p->device_path);
- if (! dp)
- return 0;
-
- ldp = find_last_device_path (dp);
- ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
- ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
- ldp->length[0] = sizeof (*ldp);
- ldp->length[1] = 0;
+ grub_efi_device_path_t *dp, *ldp;
+ int ret;
- if (grub_efi_compare_device_paths (dp, d->device_path) == 0)
- if (hook (p))
- {
- grub_free (dp);
- return 1;
- }
+ dp = duplicate_device_path (child->device_path);
+ if (! dp)
+ return 0;
- grub_free (dp);
- }
+ ldp = find_last_device_path (dp);
+ ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
+ ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ ldp->length[0] = sizeof (*ldp);
+ ldp->length[1] = 0;
- return 0;
+ ret = (grub_efi_compare_device_paths (dp, parent->device_path) == 0);
+ grub_free (dp);
+ return ret;
}
+#define FOR_CHILDREN(p, dev) for (p = dev; p; p = p->next) if (is_child (p, d))
+
/* Add a device into a list of devices in an ascending order. */
static void
add_device (struct grub_efidisk_data **devices, struct grub_efidisk_data *d)
@@ -655,9 +645,10 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
{
struct grub_efidisk_data *devices;
grub_efi_handle_t handle = 0;
- auto int find_partition (struct grub_efidisk_data *c);
+ struct grub_efidisk_data *c;
- int find_partition (struct grub_efidisk_data *c)
+ devices = make_devices ();
+ FOR_CHILDREN (c, devices)
{
grub_efi_hard_drive_device_path_t hd;
@@ -673,14 +664,10 @@ grub_efidisk_get_device_handle (grub_disk_t disk)
== hd.partition_size))
{
handle = c->handle;
- return 1;
+ break;
}
-
- return 0;
}
- devices = make_devices ();
- iterate_child_devices (devices, d, find_partition);
free_devices (devices);
if (handle != 0)
--
1.8.1.4