From 16445670518ee8a668b9d87712cd987c58c2796a Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Fri, 3 Mar 2017 20:23:10 +0000 Subject: [PATCH] Implement --guid/-g to print the known GUIDs as human readable. The list of known GUIDs can be found with --list-guids. Sponsored by: Netflix --- usr.sbin/efivar/efivar.8 | 6 ++++++ usr.sbin/efivar/efivar.c | 24 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/usr.sbin/efivar/efivar.8 b/usr.sbin/efivar/efivar.8 index dccdea66ccee..965527e634e7 100644 --- a/usr.sbin/efivar/efivar.8 +++ b/usr.sbin/efivar/efivar.8 @@ -41,6 +41,7 @@ .Op Fl -binary .Op Fl -delete .Op Fl -fromfile Ar file +.Op Fl -guid .Op Fl -hex .Op Fl -list-guids .Op Fl -list @@ -116,6 +117,10 @@ flags. No .Ar value may be specified. +.It Fl g Fl -guid +flag is specified, guids are converted to names if they are known (and +show up in +.Fl -list-guids ). .It Fl H Fl -hex List variable data as a hex dump. .It Fl L Fl -list-guids @@ -151,6 +156,7 @@ Set the specified to .Ar value . This is not yet implemented. +If the .Sh COMPATIBILITY The .Nm diff --git a/usr.sbin/efivar/efivar.c b/usr.sbin/efivar/efivar.c index 36f9edd91c74..12ed5dc7b174 100644 --- a/usr.sbin/efivar/efivar.c +++ b/usr.sbin/efivar/efivar.c @@ -46,6 +46,7 @@ static struct option longopts[] = { { "binary", no_argument, NULL, 'b' }, { "delete", no_argument, NULL, 'D' }, { "fromfile", required_argument, NULL, 'f' }, + { "guid", no_argument, NULL, 'g' }, { "hex", no_argument, NULL, 'H' }, { "list-guids", no_argument, NULL, 'L' }, { "list", no_argument, NULL, 'l' }, @@ -59,7 +60,7 @@ static struct option longopts[] = { }; -static int aflag, Aflag, bflag, dflag, Dflag, Hflag, Nflag, +static int aflag, Aflag, bflag, dflag, Dflag, gflag, Hflag, Nflag, lflag, Lflag, Rflag, wflag, pflag; static char *varname; static u_long attrib = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; @@ -195,6 +196,20 @@ bindump(uint8_t *data, size_t datalen) write(1, data, datalen); } +static void +pretty_guid(efi_guid_t *guid, char **gname) +{ + char *pretty = NULL; + + if (gflag) + efi_guid_to_name(guid, &pretty); + + if (pretty == NULL) + efi_guid_to_str(guid, gname); + else + *gname = pretty; +} + static void print_var(efi_guid_t *guid, char *name) { @@ -204,7 +219,7 @@ print_var(efi_guid_t *guid, char *name) char *gname; int rv; - efi_guid_to_str(guid, &gname); + pretty_guid(guid, &gname); if (pflag) { rv = efi_get_variable(*guid, name, &data, &datalen, &att); @@ -267,7 +282,7 @@ parse_args(int argc, char **argv) { int ch, i; - while ((ch = getopt_long(argc, argv, "aAbdDf:HlLNn:pRt:w", + while ((ch = getopt_long(argc, argv, "aAbdDf:gHlLNn:pRt:w", longopts, NULL)) != -1) { switch (ch) { case 'a': @@ -285,6 +300,9 @@ parse_args(int argc, char **argv) case 'D': Dflag++; break; + case 'g': + gflag++; + break; case 'H': Hflag++; break;