All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/2] search: fixed bug stopping iteration when --no-floppy is used
@ 2022-02-08  7:39 Renaud Métrich
  2022-02-08  7:39 ` [PATCH v3 2/2] search: new --efidisk-only option on EFI systems Renaud Métrich
  2022-02-24 19:25 ` [PATCH v3 1/2] search: fixed bug stopping iteration when --no-floppy is used Daniel Kiper
  0 siblings, 2 replies; 4+ messages in thread
From: Renaud Métrich @ 2022-02-08  7:39 UTC (permalink / raw)
  To: grub-devel; +Cc: Renaud Métrich

When using --no-floppy and a floppy was encountered, iterate_device()
was returning 1, causing the iteration to stop instead of continuing.

Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
---
 grub-core/commands/search.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c
index ed090b3af..51656e361 100644
--- a/grub-core/commands/search.c
+++ b/grub-core/commands/search.c
@@ -64,7 +64,7 @@ iterate_device (const char *name, void *data)
   /* Skip floppy drives when requested.  */
   if (ctx->no_floppy &&
       name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
-    return 1;
+    return 0;
 
 #ifdef DO_SEARCH_FS_UUID
 #define compare_fn grub_strcasecmp
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v3 2/2] search: new --efidisk-only option on EFI systems
  2022-02-08  7:39 [PATCH v3 1/2] search: fixed bug stopping iteration when --no-floppy is used Renaud Métrich
@ 2022-02-08  7:39 ` Renaud Métrich
  2022-02-24 19:33   ` Daniel Kiper
  2022-02-24 19:25 ` [PATCH v3 1/2] search: fixed bug stopping iteration when --no-floppy is used Daniel Kiper
  1 sibling, 1 reply; 4+ messages in thread
From: Renaud Métrich @ 2022-02-08  7:39 UTC (permalink / raw)
  To: grub-devel; +Cc: Renaud Métrich

When using 'search' on EFI systems, we sometimes want to exclude devices
that are not EFI disks (e.g. md, lvm).
This is typically used when wanting to chainload when having a software
raid (md) for EFI partition:
with no option, 'search --file /EFI/redhat/shimx64.efi' sets root envvar
to 'md/boot_efi' which cannot be used for chainloading since there is no
effective EFI device behind.

This commit also refactors handling of --no-floppy option.

Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
---
 grub-core/commands/search.c      | 27 +++++++++++++++++++++++----
 grub-core/commands/search_wrap.c | 18 ++++++++++++------
 include/grub/search.h            | 15 ++++++++++++---
 3 files changed, 47 insertions(+), 13 deletions(-)

diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c
index 51656e361..57d26ced8 100644
--- a/grub-core/commands/search.c
+++ b/grub-core/commands/search.c
@@ -47,7 +47,7 @@ struct search_ctx
 {
   const char *key;
   const char *var;
-  int no_floppy;
+  enum search_flags flags;
   char **hints;
   unsigned nhints;
   int count;
@@ -62,10 +62,29 @@ iterate_device (const char *name, void *data)
   int found = 0;
 
   /* Skip floppy drives when requested.  */
-  if (ctx->no_floppy &&
+  if (ctx->flags & SEARCH_FLAGS_NO_FLOPPY &&
       name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
     return 0;
 
+  /* Limit to EFI disks when requested.  */
+  if (ctx->flags & SEARCH_FLAGS_EFIDISK_ONLY)
+    {
+      grub_device_t dev;
+      dev = grub_device_open (name);
+      if (! dev)
+	{
+	  grub_errno = GRUB_ERR_NONE;
+	  return 0;
+	}
+      if (! dev->disk || dev->disk->dev->id != GRUB_DISK_DEVICE_EFIDISK_ID)
+	{
+	  grub_device_close (dev);
+	  grub_errno = GRUB_ERR_NONE;
+	  return 0;
+	}
+      grub_device_close (dev);
+    }
+
 #ifdef DO_SEARCH_FS_UUID
 #define compare_fn grub_strcasecmp
 #else
@@ -261,13 +280,13 @@ try (struct search_ctx *ctx)
 }
 
 void
-FUNC_NAME (const char *key, const char *var, int no_floppy,
+FUNC_NAME (const char *key, const char *var, enum search_flags flags,
 	   char **hints, unsigned nhints)
 {
   struct search_ctx ctx = {
     .key = key,
     .var = var,
-    .no_floppy = no_floppy,
+    .flags = flags,
     .hints = hints,
     .nhints = nhints,
     .count = 0,
diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c
index 47fc8eb99..464e6ebb1 100644
--- a/grub-core/commands/search_wrap.c
+++ b/grub-core/commands/search_wrap.c
@@ -40,6 +40,7 @@ static const struct grub_arg_option options[] =
      N_("Set a variable to the first device found."), N_("VARNAME"),
      ARG_TYPE_STRING},
     {"no-floppy",	'n', 0, N_("Do not probe any floppy drive."), 0, 0},
+    {"efidisk-only",	0, 0, N_("Only probe EFI disks."), 0, 0},
     {"hint",	        'h', GRUB_ARG_OPTION_REPEATABLE,
      N_("First try the device HINT. If HINT ends in comma, "
 	"also try subpartitions"), N_("HINT"), ARG_TYPE_STRING},
@@ -73,6 +74,7 @@ enum options
     SEARCH_FS_UUID,
     SEARCH_SET,
     SEARCH_NO_FLOPPY,
+    SEARCH_EFIDISK_ONLY,
     SEARCH_HINT,
     SEARCH_HINT_IEEE1275,
     SEARCH_HINT_BIOS,
@@ -89,6 +91,7 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args)
   const char *id = 0;
   int i = 0, j = 0, nhints = 0;
   char **hints = NULL;
+  enum search_flags flags;
 
   if (state[SEARCH_HINT].set)
     for (i = 0; state[SEARCH_HINT].args[i]; i++)
@@ -180,15 +183,18 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args)
       goto out;
     }
 
+  if (state[SEARCH_NO_FLOPPY].set)
+    flags |= SEARCH_FLAGS_NO_FLOPPY;
+
+  if (state[SEARCH_EFIDISK_ONLY].set)
+    flags |= SEARCH_FLAGS_EFIDISK_ONLY;
+
   if (state[SEARCH_LABEL].set)
-    grub_search_label (id, var, state[SEARCH_NO_FLOPPY].set, 
-		       hints, nhints);
+    grub_search_label (id, var, flags, hints, nhints);
   else if (state[SEARCH_FS_UUID].set)
-    grub_search_fs_uuid (id, var, state[SEARCH_NO_FLOPPY].set,
-			 hints, nhints);
+    grub_search_fs_uuid (id, var, flags, hints, nhints);
   else if (state[SEARCH_FILE].set)
-    grub_search_fs_file (id, var, state[SEARCH_NO_FLOPPY].set, 
-			 hints, nhints);
+    grub_search_fs_file (id, var, flags, hints, nhints);
   else
     grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type");
 
diff --git a/include/grub/search.h b/include/grub/search.h
index d80347df3..4190aeb2c 100644
--- a/include/grub/search.h
+++ b/include/grub/search.h
@@ -19,11 +19,20 @@
 #ifndef GRUB_SEARCH_HEADER
 #define GRUB_SEARCH_HEADER 1
 
-void grub_search_fs_file (const char *key, const char *var, int no_floppy,
+enum search_flags
+  {
+    SEARCH_FLAGS_NO_FLOPPY	= 1,
+    SEARCH_FLAGS_EFIDISK_ONLY	= 2
+  };
+
+void grub_search_fs_file (const char *key, const char *var,
+			  enum search_flags flags,
 			  char **hints, unsigned nhints);
-void grub_search_fs_uuid (const char *key, const char *var, int no_floppy,
+void grub_search_fs_uuid (const char *key, const char *var,
+			  enum search_flags flags,
 			  char **hints, unsigned nhints);
-void grub_search_label (const char *key, const char *var, int no_floppy,
+void grub_search_label (const char *key, const char *var,
+			enum search_flags flags,
 			char **hints, unsigned nhints);
 
 #endif
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 1/2] search: fixed bug stopping iteration when --no-floppy is used
  2022-02-08  7:39 [PATCH v3 1/2] search: fixed bug stopping iteration when --no-floppy is used Renaud Métrich
  2022-02-08  7:39 ` [PATCH v3 2/2] search: new --efidisk-only option on EFI systems Renaud Métrich
@ 2022-02-24 19:25 ` Daniel Kiper
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Kiper @ 2022-02-24 19:25 UTC (permalink / raw)
  To: Renaud Métrich; +Cc: grub-devel

On Tue, Feb 08, 2022 at 08:39:10AM +0100, Renaud Métrich wrote:
> When using --no-floppy and a floppy was encountered, iterate_device()
> was returning 1, causing the iteration to stop instead of continuing.
>
> Signed-off-by: Renaud Métrich <rmetrich@redhat.com>

Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>

Daniel


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v3 2/2] search: new --efidisk-only option on EFI systems
  2022-02-08  7:39 ` [PATCH v3 2/2] search: new --efidisk-only option on EFI systems Renaud Métrich
@ 2022-02-24 19:33   ` Daniel Kiper
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Kiper @ 2022-02-24 19:33 UTC (permalink / raw)
  To: Renaud Métrich; +Cc: grub-devel

On Tue, Feb 08, 2022 at 08:39:11AM +0100, Renaud Métrich wrote:
> When using 'search' on EFI systems, we sometimes want to exclude devices
> that are not EFI disks (e.g. md, lvm).
> This is typically used when wanting to chainload when having a software
> raid (md) for EFI partition:
> with no option, 'search --file /EFI/redhat/shimx64.efi' sets root envvar
> to 'md/boot_efi' which cannot be used for chainloading since there is no
> effective EFI device behind.
>
> This commit also refactors handling of --no-floppy option.

Please split this patch in two then. One for the --no-floppy change and
another one for --efidisk-only addition.

> Signed-off-by: Renaud Métrich <rmetrich@redhat.com>
> ---
>  grub-core/commands/search.c      | 27 +++++++++++++++++++++++----
>  grub-core/commands/search_wrap.c | 18 ++++++++++++------
>  include/grub/search.h            | 15 ++++++++++++---

Please add --efidisk-only option to the GRUB docs.

Daniel


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-02-24 19:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-08  7:39 [PATCH v3 1/2] search: fixed bug stopping iteration when --no-floppy is used Renaud Métrich
2022-02-08  7:39 ` [PATCH v3 2/2] search: new --efidisk-only option on EFI systems Renaud Métrich
2022-02-24 19:33   ` Daniel Kiper
2022-02-24 19:25 ` [PATCH v3 1/2] search: fixed bug stopping iteration when --no-floppy is used Daniel Kiper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.