static int notsane_gpt(const struct part_iter *iter) { const struct disk_gpt_part_entry *gp; gp = (const struct disk_gpt_part_entry *) (iter->data + iter->index0 * iter->sub.gpt.pe_size); if (guid_is0(&gp->type)) return 0; if (gp->lba_first < iter->sub.gpt.ufirst || gp->lba_last > iter->sub.gpt.ulast) { error("Insane GPT partition.\n"); return -1; } return 0; }
static int notsane_gpt(const struct part_iter *iter) { const struct disk_gpt_part_entry *gp; gp = (const struct disk_gpt_part_entry *) (iter->data + iter->index0 * iter->gpt.pe_size); if (guid_is0(&gp->type)) return 0; if (iter->flags & PIF_RELAX) return 0; if (gp->lba_first < iter->gpt.ufirst || gp->lba_last > iter->gpt.ulast) { error("LBA sectors of GPT partition are beyond the range allowed in GPT header."); return -1; } return 0; }
static struct part_iter *pi_gpt_next(struct part_iter *iter) { const struct disk_gpt_part_entry *gpt_part = NULL; if (iter->status) goto bail; while (++iter->index0 < iter->sub.gpt.pe_count) { gpt_part = (const struct disk_gpt_part_entry *) (iter->data + iter->index0 * iter->sub.gpt.pe_size); if (notsane_gpt(iter)) { iter->status = PI_INSANE; goto bail; } if (!guid_is0(&gpt_part->type) || iter->stepall) break; } /* no more partitions ? */ if (iter->index0 == iter->sub.gpt.pe_count) { iter->status = PI_DONE; goto bail; } /* gpt_part is guaranteed to be valid here */ iter->index = iter->index0 + 1; iter->rawindex = iter->index0 + 1; iter->start_lba = gpt_part->lba_first; iter->length = gpt_part->lba_last - gpt_part->lba_first + 1; iter->record = (char *)gpt_part; memcpy(&iter->sub.gpt.part_guid, &gpt_part->uid, sizeof(struct guid)); gpt_conv_label(iter); #ifdef DEBUG disk_gpt_part_dump(gpt_part); #endif return iter; bail: return NULL; }