From: Andrey Borzenkov <arvidjaar@gmail.com>
To: grub-devel@gnu.org
Cc: mchang@suse.com, mjg@redhat.com
Subject: [PATCH] Fix prefix autodetection when booting from EFI CD-ROM
Date: Thu, 31 Jan 2013 16:24:00 +0400 [thread overview]
Message-ID: <1359635040-23786-1-git-send-email-arvidjaar@gmail.com> (raw)
Fix autodetection of $prefix when booted from EFI CD-ROM.
Based on patch from Matthew Garrett, modified to not overwrite
memory returned by device path protocol handler and rebased to
current trunk.
Additionally fixes potential memory leak - dup_dp was not deallocated
if device path was not found.
Signed-off-by: Andrey Borzenkov <arvidjaar@gmail.com>
---
grub-core/disk/efi/efidisk.c | 121 +++++++++++++++++++++++-------------------
1 file changed, 66 insertions(+), 55 deletions(-)
diff --git a/grub-core/disk/efi/efidisk.c b/grub-core/disk/efi/efidisk.c
index 98cd226..15c8109 100644
--- a/grub-core/disk/efi/efidisk.c
+++ b/grub-core/disk/efi/efidisk.c
@@ -775,67 +775,78 @@ grub_efidisk_get_device_name (grub_efi_handle_t *handle)
if (! ldp)
return 0;
- if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE
- && (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp)
- == GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE))
+ if (GRUB_EFI_DEVICE_PATH_TYPE (ldp) == GRUB_EFI_MEDIA_DEVICE_PATH_TYPE)
{
- struct grub_efidisk_get_device_name_ctx ctx;
- char *dev_name;
- grub_efi_device_path_t *dup_dp, *dup_ldp;
- grub_disk_t parent = 0;
-
- /* It is necessary to duplicate the device path so that GRUB
- can overwrite it. */
- dup_dp = duplicate_device_path (dp);
- if (! dup_dp)
- return 0;
-
- dup_ldp = find_last_device_path (dup_dp);
- dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
- dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
- dup_ldp->length[0] = sizeof (*dup_ldp);
- dup_ldp->length[1] = 0;
+ int is_cdrom = 0;
- if (!get_diskname_from_path (dup_dp, device_name))
- return 0;
- parent = grub_disk_open (device_name);
- grub_free (dup_dp);
-
- if (! parent)
- return 0;
-
- /* Find a partition which matches the hard drive device path. */
- ctx.partition_name = NULL;
- grub_memcpy (&ctx.hd, ldp, sizeof (ctx.hd));
- if (ctx.hd.partition_start == 0
- && ctx.hd.partition_size == grub_disk_get_size (parent))
- {
- dev_name = grub_strdup (parent->name);
- }
- else
+ switch (GRUB_EFI_DEVICE_PATH_SUBTYPE (ldp))
{
- grub_partition_iterate (parent, grub_efidisk_get_device_name_iter,
- &ctx);
-
- if (! ctx.partition_name)
+ case GRUB_EFI_CDROM_DEVICE_PATH_SUBTYPE:
+ is_cdrom = 1;
+ /* Intentionally fall through */
+ case GRUB_EFI_HARD_DRIVE_DEVICE_PATH_SUBTYPE:
{
+ struct grub_efidisk_get_device_name_ctx ctx;
+ char *dev_name;
+ grub_efi_device_path_t *dup_dp, *dup_ldp;
+ grub_disk_t parent = 0;
+
+ /* It is necessary to duplicate the device path so that GRUB
+ can overwrite it. */
+ dup_dp = duplicate_device_path (dp);
+ if (! dup_dp)
+ return 0;
+
+ dup_ldp = find_last_device_path (dup_dp);
+ dup_ldp->type = GRUB_EFI_END_DEVICE_PATH_TYPE;
+ dup_ldp->subtype = GRUB_EFI_END_ENTIRE_DEVICE_PATH_SUBTYPE;
+ dup_ldp->length[0] = sizeof (*dup_ldp);
+ dup_ldp->length[1] = 0;
+
+ if (!get_diskname_from_path (dup_dp, device_name))
+ {
+ grub_free (dup_dp);
+ return 0;
+ }
+ grub_free (dup_dp);
+ if (is_cdrom)
+ return grub_strdup (device_name);
+
+ parent = grub_disk_open (device_name);
+ if (! parent)
+ return 0;
+
+ /* Find a partition which matches the hard drive device path. */
+ ctx.partition_name = NULL;
+ grub_memcpy (&ctx.hd, ldp, sizeof (ctx.hd));
+ if (ctx.hd.partition_start == 0
+ && ctx.hd.partition_size == grub_disk_get_size (parent))
+ {
+ dev_name = grub_strdup (parent->name);
+ }
+ else
+ {
+ grub_partition_iterate (parent, grub_efidisk_get_device_name_iter,
+ &ctx);
+
+ if (! ctx.partition_name)
+ {
+ grub_disk_close (parent);
+ return 0;
+ }
+
+ dev_name = grub_xasprintf ("%s,%s", parent->name,
+ ctx.partition_name);
+ grub_free (ctx.partition_name);
+ }
grub_disk_close (parent);
- return 0;
- }
- dev_name = grub_xasprintf ("%s,%s", parent->name,
- ctx.partition_name);
- grub_free (ctx.partition_name);
+ return dev_name;
+ }
}
- grub_disk_close (parent);
-
- return dev_name;
- }
- else
- {
- /* This should be an entire disk. */
- if (!get_diskname_from_path (dp, device_name))
- return 0;
- return grub_strdup (device_name);
}
+ /* This may be guessed device - floppy, cdrom or entire disk. */
+ if (!get_diskname_from_path (dp, device_name))
+ return 0;
+ return grub_strdup (device_name);
}
--
tg: (4b9ea2e..) u/efi-cdrom-prefix (depends on: master)
next reply other threads:[~2013-01-31 12:24 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-31 12:24 Andrey Borzenkov [this message]
2013-02-03 20:13 ` [PATCH] Fix prefix autodetection when booting from EFI CD-ROM Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-05 13:12 ` Vladimir 'φ-coder/phcoder' Serbinenko
2013-04-05 15:28 ` Andrey Borzenkov
2013-10-14 15:07 ` Vladimir 'φ-coder/phcoder' Serbinenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359635040-23786-1-git-send-email-arvidjaar@gmail.com \
--to=arvidjaar@gmail.com \
--cc=grub-devel@gnu.org \
--cc=mchang@suse.com \
--cc=mjg@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).