gpt: add search by disk uuid command
This commit is contained in:
parent
a8c24e86d0
commit
53a4e99990
9 changed files with 103 additions and 2 deletions
|
@ -30,7 +30,8 @@
|
|||
#include <grub/i18n.h>
|
||||
#include <grub/disk.h>
|
||||
#include <grub/partition.h>
|
||||
#if defined(DO_SEARCH_PART_UUID) || defined(DO_SEARCH_PART_LABEL)
|
||||
#if defined(DO_SEARCH_PART_UUID) || defined(DO_SEARCH_PART_LABEL) || \
|
||||
defined(DO_SEARCH_DISK_UUID)
|
||||
#include <grub/gpt_partition.h>
|
||||
#endif
|
||||
|
||||
|
@ -69,7 +70,7 @@ iterate_device (const char *name, void *data)
|
|||
name[0] == 'f' && name[1] == 'd' && name[2] >= '0' && name[2] <= '9')
|
||||
return 0;
|
||||
|
||||
#ifdef DO_SEARCH_FS_UUID
|
||||
#if defined(DO_SEARCH_FS_UUID) || defined(DO_SEARCH_DISK_UUID)
|
||||
#define compare_fn grub_strcasecmp
|
||||
#else
|
||||
#define compare_fn grub_strcmp
|
||||
|
@ -128,6 +129,25 @@ iterate_device (const char *name, void *data)
|
|||
grub_free (quid);
|
||||
}
|
||||
|
||||
grub_device_close (dev);
|
||||
}
|
||||
}
|
||||
#elif defined(DO_SEARCH_DISK_UUID)
|
||||
{
|
||||
grub_device_t dev;
|
||||
char *quid;
|
||||
|
||||
dev = grub_device_open (name);
|
||||
if (dev)
|
||||
{
|
||||
if (grub_gpt_disk_uuid (dev, &quid) == GRUB_ERR_NONE)
|
||||
{
|
||||
if (grub_strcmp (quid, ctx->key) == 0)
|
||||
found = 1;
|
||||
|
||||
grub_free (quid);
|
||||
}
|
||||
|
||||
grub_device_close (dev);
|
||||
}
|
||||
}
|
||||
|
@ -360,6 +380,8 @@ GRUB_MOD_INIT(search_part_uuid)
|
|||
GRUB_MOD_INIT(search_part_label)
|
||||
#elif defined (DO_SEARCH_FS_UUID)
|
||||
GRUB_MOD_INIT(search_fs_uuid)
|
||||
#elif defined (DO_SEARCH_DISK_UUID)
|
||||
GRUB_MOD_INIT(search_disk_uuid)
|
||||
#else
|
||||
GRUB_MOD_INIT(search_label)
|
||||
#endif
|
||||
|
@ -378,6 +400,8 @@ GRUB_MOD_FINI(search_part_uuid)
|
|||
GRUB_MOD_FINI(search_part_label)
|
||||
#elif defined (DO_SEARCH_FS_UUID)
|
||||
GRUB_MOD_FINI(search_fs_uuid)
|
||||
#elif defined (DO_SEARCH_DISK_UUID)
|
||||
GRUB_MOD_FINI(search_disk_uuid)
|
||||
#else
|
||||
GRUB_MOD_FINI(search_label)
|
||||
#endif
|
||||
|
|
5
grub-core/commands/search_disk_uuid.c
Normal file
5
grub-core/commands/search_disk_uuid.c
Normal file
|
@ -0,0 +1,5 @@
|
|||
#define DO_SEARCH_DISK_UUID 1
|
||||
#define FUNC_NAME grub_search_disk_uuid
|
||||
#define COMMAND_NAME "search.disk_uuid"
|
||||
#define HELP_MESSAGE N_("Search devices by disk UUID. If VARIABLE is specified, the first device found is set to a variable.")
|
||||
#include "search.c"
|
|
@ -40,6 +40,8 @@ static const struct grub_arg_option options[] =
|
|||
0, 0},
|
||||
{"part-uuid", 'U', 0, N_("Search devices by a partition UUID."),
|
||||
0, 0},
|
||||
{"disk-uuid", 'U', 0, N_("Search devices by a disk UUID."),
|
||||
0, 0},
|
||||
{"set", 's', GRUB_ARG_OPTION_OPTIONAL,
|
||||
N_("Set a variable to the first device found."), N_("VARNAME"),
|
||||
ARG_TYPE_STRING},
|
||||
|
@ -77,6 +79,7 @@ enum options
|
|||
SEARCH_FS_UUID,
|
||||
SEARCH_PART_LABEL,
|
||||
SEARCH_PART_UUID,
|
||||
SEARCH_DISK_UUID,
|
||||
SEARCH_SET,
|
||||
SEARCH_NO_FLOPPY,
|
||||
SEARCH_HINT,
|
||||
|
@ -198,6 +201,9 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args)
|
|||
else if (state[SEARCH_PART_UUID].set)
|
||||
grub_search_part_uuid (id, var, state[SEARCH_NO_FLOPPY].set,
|
||||
hints, nhints);
|
||||
else if (state[SEARCH_DISK_UUID].set)
|
||||
grub_search_disk_uuid (id, var, state[SEARCH_NO_FLOPPY].set,
|
||||
hints, nhints);
|
||||
else if (state[SEARCH_FILE].set)
|
||||
grub_search_fs_file (id, var, state[SEARCH_NO_FLOPPY].set,
|
||||
hints, nhints);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue