static int find_slot(sd_id128_t uuid, const char *path, uint16_t *id) { _cleanup_free_ uint16_t *options = NULL; int n, i; n = efi_get_boot_options(&options); if (n < 0) return n; /* find already existing systemd-boot entry */ for (i = 0; i < n; i++) if (same_entry(options[i], uuid, path)) { *id = options[i]; return 1; } /* find free slot in the sorted BootXXXX variable list */ for (i = 0; i < n; i++) if (i != options[i]) { *id = i; return 1; } /* use the next one */ if (i == 0xffff) return -ENOSPC; *id = i; return 0; }
static int status_variables(void) { int n_options, n_order; uint16_t *options = NULL, *order = NULL; int r, i; if (!is_efi_boot()) { fprintf(stderr, "Not booted with EFI, not showing EFI variables.\n"); return 0; } n_options = efi_get_boot_options(&options); if (n_options < 0) { if (n_options == -ENOENT) fprintf(stderr, "Failed to access EFI variables, " "efivarfs needs to be available at /sys/firmware/efi/efivars/.\n"); else fprintf(stderr, "Failed to read EFI boot entries: %s\n", strerror(-n_options)); r = n_options; goto finish; } printf("Boot Loader Entries in EFI Variables:\n"); n_order = efi_get_boot_order(&order); if (n_order == -ENOENT) { n_order = 0; } else if (n_order < 0) { fprintf(stderr, "Failed to read EFI boot order.\n"); r = n_order; goto finish; } /* print entries in BootOrder first */ for (i = 0; i < n_order; i++) print_efi_option(order[i], true); /* print remaining entries */ for (i = 0; i < n_options; i++) { int j; bool found = false; for (j = 0; j < n_order; j++) if (options[i] == order[j]) { found = true; break; } if (found) continue; print_efi_option(options[i], false); } r = 0; finish: free(options); free(order); return r; }
static int status_variables(void) { int n_options, n_order; _cleanup_free_ uint16_t *options = NULL, *order = NULL; int i; if (!is_efi_boot()) { log_notice("Not booted with EFI, not showing EFI variables."); return 0; } n_options = efi_get_boot_options(&options); if (n_options == -ENOENT) return log_error_errno(ENOENT, "Failed to access EFI variables, efivarfs" " needs to be available at /sys/firmware/efi/efivars/."); else if (n_options < 0) return log_error_errno(n_options, "Failed to read EFI boot entries: %m"); n_order = efi_get_boot_order(&order); if (n_order == -ENOENT) n_order = 0; else if (n_order < 0) return log_error_errno(n_order, "Failed to read EFI boot order."); /* print entries in BootOrder first */ printf("Boot Loader Entries in EFI Variables:\n"); for (i = 0; i < n_order; i++) print_efi_option(order[i], true); /* print remaining entries */ for (i = 0; i < n_options; i++) { int j; for (j = 0; j < n_order; j++) if (options[i] == order[j]) goto next; print_efi_option(options[i], false); next: continue; } return 0; }
static int get_boot_entries(struct boot_info *info) { uint16_t *list; int i, n; int err = 0; n = efi_get_boot_options(&list); if (n < 0) return n; for (i = 0; i < n; i++) { struct boot_info_entry *e; e = realloc(info->fw_entries, (info->fw_entries_count+1) * sizeof(struct boot_info_entry)); if (!e) { err = -ENOMEM; break; } info->fw_entries = e; e = &info->fw_entries[info->fw_entries_count]; memzero(e, sizeof(struct boot_info_entry)); e->order = -1; err = efi_get_boot_option(list[i], &e->title, &e->part_uuid, &e->path); if (err < 0) continue; if (isempty(e->title)) { free(e->title); e->title = NULL; } tilt_slashes(e->path); e->id = list[i]; info->fw_entries_count++; } free(list); return err; }
static int find_slot(sd_id128_t uuid, const char *path, uint16_t *id) { uint16_t *options = NULL; int n_options; int i; uint16_t new_id = 0; bool existing = false; n_options = efi_get_boot_options(&options); if (n_options < 0) return n_options; /* find already existing systemd-boot entry */ for (i = 0; i < n_options; i++) if (same_entry(options[i], uuid, path)) { new_id = options[i]; existing = true; goto finish; } /* find free slot in the sorted BootXXXX variable list */ for (i = 0; i < n_options; i++) if (i != options[i]) { new_id = i; goto finish; } /* use the next one */ if (i == 0xffff) return -ENOSPC; new_id = i; finish: *id = new_id; free(options); return existing; }