static struct grub_efidisk_data * make_devices (void) { grub_efi_uintn_t num_handles; grub_efi_handle_t *handles; grub_efi_handle_t *handle; struct grub_efidisk_data *devices = 0; /* Find handles which support the disk io interface. */ handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &block_io_guid, 0, &num_handles); if (! handles) return 0; /* Make a linked list of devices. */ for (handle = handles; num_handles--; handle++) { grub_efi_device_path_t *dp; grub_efi_device_path_t *ldp; struct grub_efidisk_data *d; grub_efi_block_io_t *bio; dp = grub_efi_get_device_path (*handle); if (! dp) continue; ldp = find_last_device_path (dp); if (! ldp) /* This is empty. Why? */ continue; bio = grub_efi_open_protocol (*handle, &block_io_guid, GRUB_EFI_OPEN_PROTOCOL_GET_PROTOCOL); if (! bio) /* This should not happen... Why? */ continue; d = grub_malloc (sizeof (*d)); if (! d) { /* Uggh. */ grub_free (handles); return 0; } d->handle = *handle; d->device_path = dp; d->last_device_path = ldp; d->block_io = bio; d->next = devices; devices = d; } grub_free (handles); return devices; }
static grub_efi_boolean_t grub_tpm_handle_find (grub_efi_handle_t *tpm_handle, grub_efi_uint8_t *protocol_version) { grub_efi_handle_t *handles; grub_efi_uintn_t num_handles; if (grub_tpm_handle != NULL) { *tpm_handle = grub_tpm_handle; *protocol_version = grub_tpm_version; return 1; } handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &tpm_guid, NULL, &num_handles); if (handles && num_handles > 0) { grub_tpm_handle = handles[0]; *tpm_handle = handles[0]; grub_tpm_version = 1; *protocol_version = 1; return 1; } handles = grub_efi_locate_handle (GRUB_EFI_BY_PROTOCOL, &tpm2_guid, NULL, &num_handles); if (handles && num_handles > 0) { grub_tpm_handle = handles[0]; *tpm_handle = handles[0]; grub_tpm_version = 2; *protocol_version = 2; return 1; } return 0; }