diff options
author | Kay Sievers <kay@vrfy.org> | 2015-03-12 00:50:35 +0100 |
---|---|---|
committer | Kay Sievers <kay@vrfy.org> | 2015-03-12 00:50:35 +0100 |
commit | 2bcd919c681c952eb867ef1bdb458f1bc49c2d55 (patch) | |
tree | b9230d9c37325f62e8af8012b1ecb87f8b0b2635 | |
parent | 2fb51f9139ddeaa876337d2305f0bb482f58f1d0 (diff) |
efi: rename config option to "editor" and read a boolean
-rw-r--r-- | src/efi/gummiboot.c | 22 | ||||
-rw-r--r-- | src/efi/util.c | 20 | ||||
-rw-r--r-- | src/efi/util.h | 6 |
3 files changed, 37 insertions, 11 deletions
diff --git a/src/efi/gummiboot.c b/src/efi/gummiboot.c index 0297236..be5765c 100644 --- a/src/efi/gummiboot.c +++ b/src/efi/gummiboot.c @@ -84,7 +84,7 @@ typedef struct { CHAR16 *entry_oneshot; CHAR16 *options_edit; CHAR16 *entries_auto; - BOOLEAN disable_edit; + BOOLEAN no_editor; } Config; static VOID cursor_left(UINTN *cursor, UINTN *first) @@ -431,7 +431,7 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag Print(L"console size: %d x %d\n", x, y); if (efivar_get_raw(&global_guid, L"SecureBoot", &b, &size) == EFI_SUCCESS) { - Print(L"SecureBoot: %s\n", *b > 0 ? L"enabled" : L"disabled"); + Print(L"SecureBoot: %s\n", yes_no(*b > 0)); FreePool(b); } @@ -459,7 +459,7 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag config->background->Red, config->background->Green, config->background->Blue); - Print(L"editing %s\n", config->disable_edit ? L"disabled" : L"enabled"); + Print(L"editor: %s\n", yes_no(!config->no_editor)); Print(L"\n"); Print(L"config entry count: %d\n", config->entry_count); @@ -531,7 +531,7 @@ static VOID print_status(Config *config, EFI_FILE *root_dir, CHAR16 *loaded_imag Print(L"options '%s'\n", entry->options); if (entry->splash) Print(L"splash '%s'\n", entry->splash); - Print(L"auto-select %s\n", entry->no_autoselect ? L"no" : L"yes"); + Print(L"auto-select %s\n", yes_no(!entry->no_autoselect)); if (entry->call) Print(L"internal call yes\n"); @@ -848,7 +848,7 @@ static BOOLEAN menu_run(Config *config, ConfigEntry **chosen_entry, EFI_FILE *ro case KEYPRESS(0, 0, 'e'): /* only the options of configured entries can be edited */ - if (config->disable_edit || config->entries[idx_highlight]->type == LOADER_UNDEFINED) + if (config->no_editor || config->entries[idx_highlight]->type == LOADER_UNDEFINED) break; uefi_call_wrapper(ST->ConOut->SetAttribute, 2, ST->ConOut, EFI_LIGHTGRAY|EFI_BACKGROUND_BLACK); uefi_call_wrapper(ST->ConOut->SetCursorPosition, 3, ST->ConOut, 0, y_max-1); @@ -1116,12 +1116,12 @@ static VOID config_defaults_load_from_file(Config *config, CHAR8 *content) { continue; } - if (strcmpa((CHAR8 *)"editing", key) == 0) { - if (strcmpa((CHAR8 *)"enable", value) == 0 || strcmpa((CHAR8 *)"enabled", value) == 0) - config->disable_edit = FALSE; - else if (strcmpa((CHAR8 *)"disable", value) == 0 || strcmpa((CHAR8 *)"disabled", value) == 0) - config->disable_edit = TRUE; - continue; + if (strcmpa((CHAR8 *)"editor", key) == 0) { + BOOLEAN on; + + if (EFI_ERROR(parse_boolean(value, &on))) + continue; + config->no_editor = !on; } } } diff --git a/src/efi/util.c b/src/efi/util.c index 5678b50..ba5ed7d 100644 --- a/src/efi/util.c +++ b/src/efi/util.c @@ -69,6 +69,26 @@ UINT64 time_usec(VOID) { return 1000 * 1000 * ticks / freq; } +EFI_STATUS parse_boolean(CHAR8 *v, BOOLEAN *b) { + if (strcmpa(v, (CHAR8 *)"1") == 0 || + strcmpa(v, (CHAR8 *)"yes") == 0 || + strcmpa(v, (CHAR8 *)"y") == 0 || + strcmpa(v, (CHAR8 *)"true") == 0) { + *b = TRUE; + return EFI_SUCCESS; + } + + if (strcmpa(v, (CHAR8 *)"0") == 0 || + strcmpa(v, (CHAR8 *)"no") == 0 || + strcmpa(v, (CHAR8 *)"n") == 0 || + strcmpa(v, (CHAR8 *)"false") == 0) { + *b = FALSE; + return EFI_SUCCESS; + } + + return EFI_INVALID_PARAMETER; +} + EFI_STATUS efivar_set_raw(const EFI_GUID *vendor, CHAR16 *name, CHAR8 *buf, UINTN size, BOOLEAN persistent) { UINT32 flags; diff --git a/src/efi/util.h b/src/efi/util.h index 91757c4..b86102e 100644 --- a/src/efi/util.h +++ b/src/efi/util.h @@ -23,6 +23,12 @@ #define ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0])) +static inline const CHAR16 *yes_no(BOOLEAN b) { + return b ? L"yes" : L"no"; +} + +EFI_STATUS parse_boolean(CHAR8 *v, BOOLEAN *b); + UINT64 ticks_read(void); UINT64 ticks_freq(void); UINT64 time_usec(void); |