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
This commit is contained in:
Warner Losh 2017-03-03 20:23:10 +00:00
parent 4a110fbfa7
commit 1644567051
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=314619
2 changed files with 27 additions and 3 deletions

View File

@ -41,6 +41,7 @@
.Op Fl -binary .Op Fl -binary
.Op Fl -delete .Op Fl -delete
.Op Fl -fromfile Ar file .Op Fl -fromfile Ar file
.Op Fl -guid
.Op Fl -hex .Op Fl -hex
.Op Fl -list-guids .Op Fl -list-guids
.Op Fl -list .Op Fl -list
@ -116,6 +117,10 @@ flags.
No No
.Ar value .Ar value
may be specified. 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 .It Fl H Fl -hex
List variable data as a hex dump. List variable data as a hex dump.
.It Fl L Fl -list-guids .It Fl L Fl -list-guids
@ -151,6 +156,7 @@ Set the specified
to to
.Ar value . .Ar value .
This is not yet implemented. This is not yet implemented.
If the
.Sh COMPATIBILITY .Sh COMPATIBILITY
The The
.Nm .Nm

View File

@ -46,6 +46,7 @@ static struct option longopts[] = {
{ "binary", no_argument, NULL, 'b' }, { "binary", no_argument, NULL, 'b' },
{ "delete", no_argument, NULL, 'D' }, { "delete", no_argument, NULL, 'D' },
{ "fromfile", required_argument, NULL, 'f' }, { "fromfile", required_argument, NULL, 'f' },
{ "guid", no_argument, NULL, 'g' },
{ "hex", no_argument, NULL, 'H' }, { "hex", no_argument, NULL, 'H' },
{ "list-guids", no_argument, NULL, 'L' }, { "list-guids", no_argument, NULL, 'L' },
{ "list", 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; lflag, Lflag, Rflag, wflag, pflag;
static char *varname; static char *varname;
static u_long attrib = EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS; 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); 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 static void
print_var(efi_guid_t *guid, char *name) print_var(efi_guid_t *guid, char *name)
{ {
@ -204,7 +219,7 @@ print_var(efi_guid_t *guid, char *name)
char *gname; char *gname;
int rv; int rv;
efi_guid_to_str(guid, &gname); pretty_guid(guid, &gname);
if (pflag) { if (pflag) {
rv = efi_get_variable(*guid, name, &data, &datalen, &att); rv = efi_get_variable(*guid, name, &data, &datalen, &att);
@ -267,7 +282,7 @@ parse_args(int argc, char **argv)
{ {
int ch, i; 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) { longopts, NULL)) != -1) {
switch (ch) { switch (ch) {
case 'a': case 'a':
@ -285,6 +300,9 @@ parse_args(int argc, char **argv)
case 'D': case 'D':
Dflag++; Dflag++;
break; break;
case 'g':
gflag++;
break;
case 'H': case 'H':
Hflag++; Hflag++;
break; break;