/* virt-efivars editor. * Copyright (C) 2015 Red Hat Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include #include #include #include #include #include #define GUID_FORMAT "%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x" static void list_variables (void) { efi_guid_t *guid = NULL; char *name = NULL; int r; while ((r = efi_get_next_variable_name (&guid, &name)) > 0) printf (GUID_FORMAT "-%s\n", guid->a, guid->b, guid->c, bswap_16 (guid->d), guid->e[0], guid->e[1], guid->e[2], guid->e[3], guid->e[4], guid->e[5], name); if (r < 0) { perror ("efi_get_next_variable_name"); exit (EXIT_FAILURE); } } static void add_variable (void) { uint8_t data[] = "rwmjtestdata"; if (efi_set_variable (efi_guid_redhat, "RWMJTest", data, sizeof data, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE) < 0) { perror ("efi_set_variable"); exit (EXIT_FAILURE); } } int main (int argc, char *argv[]) { printf ("*** editor running ***\n"); if (!efi_variables_supported ()) { fprintf (stderr, "UEFI variables are not supported!\n"); exit (EXIT_FAILURE); } list_variables (); add_variable (); printf ("*** editor finished ***\n"); exit (EXIT_SUCCESS); }