+/*
+ * Search for a specific partition, based on the GPT label.
+ * We return the disk drive number if found, as well as populating the
+ * boot_part pointer with the matching partition, if applicable.
+ * If no matching partition is found, boot_part will be populated with
+ * NULL and we return -1.
+ */
+static int find_by_label(const char *label, struct disk_part_iter **boot_part)
+{
+ int drive;
+ bool is_me;
+
+ for (drive = 0x80; drive <= 0xff; drive++) {
+ if (get_disk_params(drive))
+ continue; /* Drive doesn't exist */
+ /* Check for a GPT disk */
+ boot_part[0] = get_first_partition(NULL);
+ if (!(boot_part[0]->next == next_gpt_part)) {
+ /* Not a GPT disk */
+ while (boot_part[0]) {
+ /* Run through until the end */
+ boot_part[0] = boot_part[0]->next(boot_part[0]);
+ }
+ continue;
+ }
+ /* Check for a matching partition */
+ while (boot_part[0]) {
+ char gpt_label[sizeof(((struct gpt_part *) NULL)->name)];
+ const char *gpt_label_scanner =
+ boot_part[0]->private.gpt.part_label;
+ int j = 0;
+
+ /* Re-write the GPT partition label as ASCII */
+ while (gpt_label_scanner <
+ boot_part[0]->private.gpt.part_label + sizeof(gpt_label)) {
+ if ((gpt_label[j] = *gpt_label_scanner))
+ j++;
+ gpt_label_scanner++;
+ }
+ if ((is_me = !strcmp(label, gpt_label)))
+ break;
+ boot_part[0] = boot_part[0]->next(boot_part[0]);
+ }
+ if (is_me)
+ return drive;
+ }
+
+ return -1;
+}
+