diff --git a/commands/search.c b/commands/search.c index 01e83739b..c3626d352 100644 --- a/commands/search.c +++ b/commands/search.c @@ -30,7 +30,8 @@ #include void -FUNC_NAME (const char *key, const char *var, int no_floppy) +FUNC_NAME (const char *key, const char *var, int no_floppy, + const char **hints, unsigned nhints) { int count = 0; char *buf = NULL; @@ -118,22 +119,32 @@ FUNC_NAME (const char *key, const char *var, int no_floppy) return (found && var); } + auto void try (void); + void try (void) + { + unsigned i; + for (i = 0; i < nhints; i++) + if (iterate_device (hints[i])) + return; + grub_device_iterate (iterate_device); + } + /* First try without autoloading if we're setting variable. */ if (var) { saved_autoload = grub_fs_autoload_hook; grub_fs_autoload_hook = 0; - grub_device_iterate (iterate_device); + try (); /* Restore autoload hook. */ grub_fs_autoload_hook = saved_autoload; /* Retry with autoload if nothing found. */ if (grub_errno == GRUB_ERR_NONE && count == 0) - grub_device_iterate (iterate_device); + try (); } else - grub_device_iterate (iterate_device); + try (); grub_free (buf); @@ -148,7 +159,8 @@ grub_cmd_do_search (grub_command_t cmd __attribute__ ((unused)), int argc, if (argc == 0) return grub_error (GRUB_ERR_BAD_ARGUMENT, "no argument specified"); - FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0); + FUNC_NAME (args[0], argc == 1 ? 0 : args[1], 0, (const char **) (args + 2), + argc > 2 ? argc - 2 : 0); return grub_errno; } @@ -165,7 +177,7 @@ GRUB_MOD_INIT(search_fs_label) { cmd = grub_register_command (COMMAND_NAME, grub_cmd_do_search, - "NAME [VARIABLE]", + "NAME [VARIABLE] [HINTS]", "Search devices by " SEARCH_TARGET "." " If VARIABLE is specified, " "the first device found is set to a variable."); diff --git a/commands/search_wrap.c b/commands/search_wrap.c index 2891d85d7..eb9279e87 100644 --- a/commands/search_wrap.c +++ b/commands/search_wrap.c @@ -62,11 +62,14 @@ grub_cmd_search (grub_extcmd_t cmd, int argc, char **args) var = state[SEARCH_SET].arg ? state[SEARCH_SET].arg : "root"; if (state[SEARCH_LABEL].set) - grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set); + grub_search_label (args[0], var, state[SEARCH_NO_FLOPPY].set, + (const char **) (args + 1), argc - 1); else if (state[SEARCH_FS_UUID].set) - grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set); + grub_search_fs_uuid (args[0], var, state[SEARCH_NO_FLOPPY].set, + (const char **) (args + 1), argc - 1); else if (state[SEARCH_FILE].set) - grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set); + grub_search_fs_file (args[0], var, state[SEARCH_NO_FLOPPY].set, + (const char **) (args + 1), argc - 1); else return grub_error (GRUB_ERR_INVALID_COMMAND, "unspecified search type"); @@ -80,7 +83,7 @@ GRUB_MOD_INIT(search) cmd = grub_register_extcmd ("search", grub_cmd_search, GRUB_COMMAND_FLAG_BOTH, - N_("search [-f|-l|-u|-s|-n] NAME"), + N_("[-f|-l|-u|-s|-n] NAME [HINTS]"), N_("Search devices by file, filesystem label" " or filesystem UUID." " If --set is specified, the first device found is" diff --git a/include/grub/search.h b/include/grub/search.h index e8f9db285..3c56f0305 100644 --- a/include/grub/search.h +++ b/include/grub/search.h @@ -19,8 +19,11 @@ #ifndef GRUB_SEARCH_HEADER #define GRUB_SEARCH_HEADER 1 -void grub_search_fs_file (const char *key, const char *var, int no_floppy); -void grub_search_fs_uuid (const char *key, const char *var, int no_floppy); -void grub_search_label (const char *key, const char *var, int no_floppy); +void grub_search_fs_file (const char *key, const char *var, int no_floppy, + const char **hints, unsigned nhints); +void grub_search_fs_uuid (const char *key, const char *var, int no_floppy, + const char **hints, unsigned nhints); +void grub_search_label (const char *key, const char *var, int no_floppy, + const char **hints, unsigned nhints); #endif