Improve 'search' grub-shell command with functionality to search for a partition by PARTLABEL string, which is known as GPT partition name on GPT formatted disks.
Signed-off-by: Vitaly Kuzmichev <vitaly.kuzmic...@rtsoft.de> --- grub-core/Makefile.core.def | 5 +++++ grub-core/commands/search.c | 16 ++++++++++++++++ grub-core/commands/search_partlabel.c | 5 +++++ grub-core/commands/search_wrap.c | 8 +++++++- include/grub/search.h | 3 +++ 5 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 grub-core/commands/search_partlabel.c diff --git a/grub-core/Makefile.core.def b/grub-core/Makefile.core.def index 5834e8570..7fbb476c8 100644 --- a/grub-core/Makefile.core.def +++ b/grub-core/Makefile.core.def @@ -1107,6 +1107,11 @@ module = { common = commands/search_label.c; }; +module = { + name = search_part_label; + common = commands/search_partlabel.c; +}; + module = { name = setpci; common = commands/setpci.c; diff --git a/grub-core/commands/search.c b/grub-core/commands/search.c index 96b32baec..7de3aa97a 100644 --- a/grub-core/commands/search.c +++ b/grub-core/commands/search.c @@ -115,6 +115,18 @@ iterate_device (const char *name, void *data) grub_free (part_uuid); grub_device_close (dev); } +#elif defined (DO_SEARCH_PART_LABEL) + { + grub_device_t dev; + char *part_label; + + dev = grub_device_open (name); + part_label = grub_gpt_partition_get_label (dev); + if (part_label && compare_fn (part_label, ctx->key) == 0) + found = 1; + grub_free (part_label); + grub_device_close (dev); + } #elif defined (DO_SEARCH_FILE) { char *buf; @@ -358,6 +370,8 @@ static grub_command_t cmd; GRUB_MOD_INIT(search_fs_file) #elif defined (DO_SEARCH_PART_UUID) GRUB_MOD_INIT(search_part_uuid) +#elif defined (DO_SEARCH_PART_LABEL) +GRUB_MOD_INIT(search_part_label) #elif defined (DO_SEARCH_FS_UUID) GRUB_MOD_INIT(search_fs_uuid) #else @@ -374,6 +388,8 @@ GRUB_MOD_INIT(search_label) GRUB_MOD_FINI(search_fs_file) #elif defined (DO_SEARCH_PART_UUID) GRUB_MOD_FINI(search_part_uuid) +#elif defined (DO_SEARCH_PART_LABEL) +GRUB_MOD_FINI(search_part_label) #elif defined (DO_SEARCH_FS_UUID) GRUB_MOD_FINI(search_fs_uuid) #else diff --git a/grub-core/commands/search_partlabel.c b/grub-core/commands/search_partlabel.c new file mode 100644 index 000000000..bc4f93840 --- /dev/null +++ b/grub-core/commands/search_partlabel.c @@ -0,0 +1,5 @@ +#define DO_SEARCH_PART_LABEL 1 +#define FUNC_NAME grub_search_part_label +#define COMMAND_NAME "search.part_label" +#define HELP_MESSAGE N_("Search devices by GPT partition label (up to 36 characters). If VARIABLE is specified, the first device found is set to a variable.") +#include "search.c" diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c index 8b9a1f018..8478cd363 100644 --- a/grub-core/commands/search_wrap.c +++ b/grub-core/commands/search_wrap.c @@ -34,6 +34,8 @@ static const struct grub_arg_option options[] = {"file", 'f', 0, N_("Search devices by a file."), 0, 0}, {"label", 'l', 0, N_("Search devices by a filesystem label."), 0, 0}, + {"part-label", 0, 0, N_("Search devices by a partition label."), + 0, 0}, {"fs-uuid", 'u', 0, N_("Search devices by a filesystem UUID."), 0, 0}, {"part-uuid", 'p', 0, N_("Search devices by a partition UUID."), @@ -73,6 +75,7 @@ enum options { SEARCH_FILE, SEARCH_LABEL, + SEARCH_PART_LABEL, SEARCH_FS_UUID, SEARCH_PART_UUID, SEARCH_SET, @@ -194,6 +197,8 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) if (state[SEARCH_LABEL].set) grub_search_label (id, var, flags, hints, nhints); + else if (state[SEARCH_PART_LABEL].set) + grub_search_part_label (id, var, flags, hints, nhints); else if (state[SEARCH_FS_UUID].set) grub_search_fs_uuid (id, var, flags, hints, nhints); else if (state[SEARCH_PART_UUID].set) @@ -218,7 +223,8 @@ GRUB_MOD_INIT(search) N_("[-f|-l|-u|-s|-n] [--hint HINT [--hint HINT] ...]" " NAME"), N_("Search devices by file, filesystem label," - " filesystem UUID, GPT partition UUID" + " filesystem UUID, GPT partition label" + " (up to 36 characters long), GPT partition UUID" " or MBR partition signature." " If --set is specified, the first device found is" " set to a variable. If no variable name is" diff --git a/include/grub/search.h b/include/grub/search.h index 43810379f..def10b80f 100644 --- a/include/grub/search.h +++ b/include/grub/search.h @@ -38,5 +38,8 @@ void grub_search_label (const char *key, const char *var, void grub_search_part_uuid (const char *key, const char *var, enum search_flags flags, char **hints, unsigned nhints); +void grub_search_part_label (const char *key, const char *var, + enum search_flags flags, + char **hints, unsigned nhints); #endif -- 2.34.1 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel