| Index: fs/partitions/efi.c
|
| diff --git a/fs/partitions/efi.c b/fs/partitions/efi.c
|
| index 49cfd5f5423894df4c2f52ac48bac1f82a9b43a3..e9e4923707ede7161de16ab502179a8889ce5515 100644
|
| --- a/fs/partitions/efi.c
|
| +++ b/fs/partitions/efi.c
|
| @@ -637,3 +637,62 @@ efi_partition(struct parsed_partitions *state, struct block_device *bdev)
|
| printk("\n");
|
| return 1;
|
| }
|
| +
|
| +/**
|
| + * efi_find_partition(efi_guid_t *guid, struct block_device *bdev)
|
| + * @guid
|
| + * @bdev
|
| + *
|
| + * Returns:
|
| + * -1 if an error occurred
|
| + * 0 if there was no match (or not GPT)
|
| + * >=1 is the index of the partition found.
|
| + *
|
| + */
|
| +int efi_find_partition(efi_guid_t *guid, struct block_device *bdev) {
|
| + gpt_header *gpt = NULL;
|
| + gpt_entry *ptes = NULL;
|
| + u32 i;
|
| + struct parsed_partitions *state;
|
| + int part = 0;
|
| +
|
| + if (!bdev || !guid)
|
| + return -1;
|
| +
|
| + state = kzalloc(sizeof(struct parsed_partitions), GFP_KERNEL);
|
| + if (!state)
|
| + return -1;
|
| +
|
| + state->limit = disk_max_parts(bdev->bd_disk);
|
| + pr_debug(KERN_WARNING "efi_find_partition looking for gpt\n");
|
| +
|
| + if (!find_valid_gpt(bdev, &gpt, &ptes) || !gpt || !ptes) {
|
| + pr_debug(KERN_WARNING "efi_find_partition no GPT\n");
|
| + kfree(gpt);
|
| + kfree(ptes);
|
| + kfree(state);
|
| + return 0;
|
| + }
|
| +
|
| + pr_debug("GUID Partition Table is valid! Yea!\n");
|
| +
|
| + pr_debug(KERN_WARNING "efi_find_partition: 0 -> %d (limit:%d)\n",
|
| + le32_to_cpu(gpt->num_partition_entries),
|
| + state->limit);
|
| + for (i = 0; i < le32_to_cpu(gpt->num_partition_entries) &&
|
| + i < state->limit-1; i++) {
|
| + if (!is_pte_valid(&ptes[i], last_lba(bdev)))
|
| + continue;
|
| +
|
| + /* Bails on first hit so duped "unique" GUIDs will be FCFS. */
|
| + if (!efi_guidcmp(ptes[i].unique_partition_guid,
|
| + *guid)) {
|
| + part = i + 1;
|
| + break;
|
| + }
|
| + }
|
| + kfree(ptes);
|
| + kfree(gpt);
|
| + kfree(state);
|
| + return part;
|
| +}
|
|
|