#include #include #include #include #include #include #include #include #include #include #define EFI_PAGE_SHIFT 12 #define EFI_PAGE_SIZE (1 << EFI_PAGE_SHIFT) #define EFI_VARNAME_MAXLENGTH EFI_PAGE_SIZE int main(void) { int efifd; struct efi_var_ioc ev; char buf[MB_LEN_MAX]; mbstate_t ps; size_t i, n; if (setlocale(LC_CTYPE, "C.UTF-8") == NULL) err(1, "setlocale(LC_CTYPE, \"C.UTF-8\")"); efifd = open("/dev/efi", O_RDWR); if (efifd == -1) err(1, "open"); memset(&ev, 0, sizeof(ev)); ev.name = ecalloc(EFI_VARNAME_MAXLENGTH, sizeof(*ev.name)); ev.namesize = EFI_VARNAME_MAXLENGTH; if (ioctl(efifd, EFIIOC_VAR_NEXT, &ev) == -1) err(1, "ioctl(EFIIOC_VAR_NEXT)"); memset(&ps, 0, sizeof(ps)); for (i = 0; i < ev.namesize; i++) { if (ev.name[i] == U'\0') break; n = c16rtomb(buf, ev.name[i], &ps); if (n == (size_t)-1) err(1, "c16rtomb"); if (fwrite(buf, n, 1, stdout) != 1) err(1, "fwrite"); } printf("\n"); fflush(stdout); return ferror(stdout); }