Changeset View
Changeset View
Standalone View
Standalone View
head/usr.sbin/efibootmgr/efibootmgr.c
/*- | /*- | ||||
* Copyright (c) 2017 Netflix, Inc. | * Copyright (c) 2017-2018 Netflix, Inc. | ||||
* All rights reserved. | * All rights reserved. | ||||
* | * | ||||
* Redistribution and use in source and binary forms, with or without | * Redistribution and use in source and binary forms, with or without | ||||
* modification, are permitted provided that the following conditions | * modification, are permitted provided that the following conditions | ||||
* are met: | * are met: | ||||
* 1. Redistributions of source code must retain the above copyright | * 1. Redistributions of source code must retain the above copyright | ||||
* notice, this list of conditions and the following disclaimer | * notice, this list of conditions and the following disclaimer | ||||
* in this position and unchanged. | * in this position and unchanged. | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | typedef struct _bmgr_opts { | ||||
bool set_bootnext; | bool set_bootnext; | ||||
bool set_inactive; | bool set_inactive; | ||||
bool set_timeout; | bool set_timeout; | ||||
int timeout; | int timeout; | ||||
bool verbose; | bool verbose; | ||||
} bmgr_opts_t; | } bmgr_opts_t; | ||||
static struct option lopts[] = { | static struct option lopts[] = { | ||||
{"activate", required_argument, NULL, 'a'}, | {"activate", no_argument, NULL, 'a'}, | ||||
{"bootnext", required_argument, NULL, 'n'}, /* set bootnext */ | {"bootnext", no_argument, NULL, 'n'}, /* set bootnext */ | ||||
{"bootnum", required_argument, NULL, 'b'}, | {"bootnum", required_argument, NULL, 'b'}, | ||||
{"bootorder", required_argument, NULL, 'o'}, /* set order */ | {"bootorder", required_argument, NULL, 'o'}, /* set order */ | ||||
{"copy", required_argument, NULL, 'C'}, /* Copy boot method */ | {"copy", required_argument, NULL, 'C'}, /* Copy boot method */ | ||||
{"create", no_argument, NULL, 'c'}, | {"create", no_argument, NULL, 'c'}, | ||||
{"deactivate", required_argument, NULL, 'A'}, | {"deactivate", no_argument, NULL, 'A'}, | ||||
{"del-timout", no_argument, NULL, 'T'}, | {"del-timout", no_argument, NULL, 'T'}, | ||||
{"delete", required_argument, NULL, 'B'}, | {"delete", no_argument, NULL, 'B'}, | ||||
{"delete-bootnext", required_argument, NULL, 'N'}, | {"delete-bootnext", no_argument, NULL, 'N'}, | ||||
{"dry-run", no_argument, NULL, 'D'}, | {"dry-run", no_argument, NULL, 'D'}, | ||||
{"env", required_argument, NULL, 'e'}, | {"env", required_argument, NULL, 'e'}, | ||||
{"help", no_argument, NULL, 'h'}, | {"help", no_argument, NULL, 'h'}, | ||||
{"kernel", required_argument, NULL, 'k'}, | {"kernel", required_argument, NULL, 'k'}, | ||||
{"label", required_argument, NULL, 'L'}, | {"label", required_argument, NULL, 'L'}, | ||||
{"loader", required_argument, NULL, 'l'}, | {"loader", required_argument, NULL, 'l'}, | ||||
{"once", no_argument, NULL, 'O'}, | {"once", no_argument, NULL, 'O'}, | ||||
{"set-timeout", required_argument, NULL, 't'}, | {"set-timeout", required_argument, NULL, 't'}, | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
return efi_set_variable(EFI_GLOBAL_GUID, name, data, size, | return efi_set_variable(EFI_GLOBAL_GUID, name, data, size, | ||||
COMMON_ATTRS); | COMMON_ATTRS); | ||||
} | } | ||||
#define USAGE \ | #define USAGE \ | ||||
" [-aAnNB Bootvar] [-t timeout] [-T] [-o bootorder] [-O] [--verbose] [--help] \n\ | " [-aAnB -b bootnum] [-N] [-t timeout] [-T] [-o bootorder] [-O] [--verbose] [--help]\n\ | ||||
[-c -l loader [-k kernel ] [-L label] [--dry-run] [-b Bootvar]]" | [-c -l loader [-k kernel] [-L label] [--dry-run] [-b bootnum]]" | ||||
#define CREATE_USAGE \ | #define CREATE_USAGE \ | ||||
" efibootmgr -c -l loader [-k kernel] [-L label] [--dry-run]" | " efibootmgr -c -l loader [-k kernel] [-L label] [--dry-run] [-b bootnum] [-a]" | ||||
#define ORDER_USAGE \ | #define ORDER_USAGE \ | ||||
" efibootmgr -o bootvarnum1,bootvarnum2,..." | " efibootmgr -o bootvarnum1,bootvarnum2,..." | ||||
#define TIMEOUT_USAGE \ | #define TIMEOUT_USAGE \ | ||||
" efibootmgr -t seconds" | " efibootmgr -t seconds" | ||||
#define DELETE_USAGE \ | #define DELETE_USAGE \ | ||||
" efibootmgr -B bootvarnum" | " efibootmgr -B -b bootnum" | ||||
#define ACTIVE_USAGE \ | #define ACTIVE_USAGE \ | ||||
" efibootmgr [-a | -A] bootvarnum" | " efibootmgr [-a | -A] -b bootnum" | ||||
#define BOOTNEXT_USAGE \ | #define BOOTNEXT_USAGE \ | ||||
" efibootmgr [-n | -N] bootvarnum" | " efibootmgr [-n | -N] -b bootnum" | ||||
static void | static void | ||||
parse_args(int argc, char *argv[]) | parse_args(int argc, char *argv[]) | ||||
{ | { | ||||
int ch; | int ch; | ||||
while ((ch = getopt_long(argc, argv, "A:a:B:b:C:cDe:hk:L:l:Nn:Oo:Tt:v", | while ((ch = getopt_long(argc, argv, "AaBb:C:cDe:hk:L:l:NnOo:Tt:v", | ||||
lopts, NULL)) != -1) { | lopts, NULL)) != -1) { | ||||
switch (ch) { | switch (ch) { | ||||
case 'A': | case 'A': | ||||
opts.set_inactive = true; | opts.set_inactive = true; | ||||
opts.bootnum = strtoul(optarg, NULL, 16); | |||||
break; | break; | ||||
case 'a': | case 'a': | ||||
opts.set_active = true; | opts.set_active = true; | ||||
opts.bootnum = strtoul(optarg, NULL, 16); | |||||
break; | break; | ||||
case 'b': | case 'b': | ||||
opts.has_bootnum = true; | opts.has_bootnum = true; | ||||
opts.bootnum = strtoul(optarg, NULL, 16); | opts.bootnum = strtoul(optarg, NULL, 16); | ||||
break; | break; | ||||
case 'B': | case 'B': | ||||
opts.delete = true; | opts.delete = true; | ||||
opts.bootnum = strtoul(optarg, NULL, 16); | |||||
break; | break; | ||||
case 'C': | case 'C': | ||||
opts.copy = true; | opts.copy = true; | ||||
opts.cp_src = strtoul(optarg, NULL, 16); | opts.cp_src = strtoul(optarg, NULL, 16); | ||||
case 'c': | case 'c': | ||||
opts.create = true; | opts.create = true; | ||||
break; | break; | ||||
case 'D': /* should be remove dups XXX */ | case 'D': /* should be remove dups XXX */ | ||||
Show All 20 Lines | case 'l': | ||||
opts.loader = strdup(optarg); | opts.loader = strdup(optarg); | ||||
opts.loader = mangle_loader(opts.loader); | opts.loader = mangle_loader(opts.loader); | ||||
break; | break; | ||||
case 'N': | case 'N': | ||||
opts.delete_bootnext = true; | opts.delete_bootnext = true; | ||||
break; | break; | ||||
case 'n': | case 'n': | ||||
opts.set_bootnext = true; | opts.set_bootnext = true; | ||||
opts.bootnum = strtoul(optarg, NULL, 16); | |||||
break; | break; | ||||
case 'O': | case 'O': | ||||
opts.once = true; | opts.once = true; | ||||
break; | break; | ||||
case 'o': | case 'o': | ||||
free(opts.order); | free(opts.order); | ||||
opts.order = strdup(optarg); | opts.order = strdup(optarg); | ||||
break; | break; | ||||
Show All 12 Lines | parse_args(int argc, char *argv[]) | ||||
if (opts.create) { | if (opts.create) { | ||||
if (!opts.loader) | if (!opts.loader) | ||||
errx(1, "%s",CREATE_USAGE); | errx(1, "%s",CREATE_USAGE); | ||||
return; | return; | ||||
} | } | ||||
if (opts.order && !(opts.order)) | if (opts.order && !(opts.order)) | ||||
errx(1, "%s", ORDER_USAGE); | errx(1, "%s", ORDER_USAGE); | ||||
if ((opts.set_inactive || opts.set_active) && !opts.has_bootnum) | |||||
errx(1, "%s", ACTIVE_USAGE); | |||||
if (opts.delete && !opts.has_bootnum) | |||||
errx(1, "%s", DELETE_USAGE); | |||||
if (opts.set_bootnext && !opts.has_bootnum) | |||||
errx(1, "%s", BOOTNEXT_USAGE); | |||||
} | } | ||||
static void | static void | ||||
read_vars(void) | read_vars(void) | ||||
{ | { | ||||
efi_guid_t *guid; | efi_guid_t *guid; | ||||
▲ Show 20 Lines • Show All 653 Lines • Show Last 20 Lines |