if (partition_unused(&e[i]) ||
partition_unused(&e[j]))
continue;
- if (partition_overlap(&e[i], &e[j]))
- /* two overlaping partitions is enough! */
+ if (partition_overlap(&e[i], &e[j])) {
+ DBG(LABEL, dbgprint("GPT partitions overlap detected [%u vs. %u]", i, j));
return i + 1;
+ }
}
return 0;
goto err0;
/* check that disk is big enough to handle the backup header */
- if (gpt->pheader->alternative_lba > cxt->total_sectors)
+ if (le64_to_cpu(gpt->pheader->alternative_lba) > cxt->total_sectors)
goto err0;
/* check that the backup header is properly placed */
- if (gpt->pheader->alternative_lba < cxt->total_sectors - 1)
+ if (le64_to_cpu(gpt->pheader->alternative_lba) < cxt->total_sectors - 1)
/* TODO: correct this (with user authorization) and write */
goto err0;
*/
if (gpt_write_partitions(cxt, gpt->bheader, gpt->ents) != 0)
goto err1;
- if (gpt_write_header(cxt, gpt->bheader, gpt->pheader->alternative_lba) != 0)
+ if (gpt_write_header(cxt, gpt->bheader,
+ le64_to_cpu(gpt->pheader->alternative_lba)) != 0)
goto err1;
if (gpt_write_partitions(cxt, gpt->pheader, gpt->ents) != 0)
goto err1;
if (gpt_write_pmbr(cxt) != 0)
goto err1;
+ DBG(LABEL, dbgprint("GPT write success"));
return 0;
err0:
+ DBG(LABEL, dbgprint("GPT write failed: incorrect input"));
+ errno = EINVAL;
return -EINVAL;
err1:
+ DBG(LABEL, dbgprint("GPT write failed: %m"));
return -errno;
}
fdisk_warnx(cxt, _("MyLBA mismatch with real position at backup header."));
}
- if (gpt->pheader->alternative_lba >= cxt->total_sectors) {
+ if (le64_to_cpu(gpt->pheader->alternative_lba) >= cxt->total_sectors) {
nerror++;
fdisk_warnx(cxt, _("Disk is to small to hold all data."));
}
* if the GPT is the primary table, check the alternateLBA
* to see if it is a valid GPT
*/
- if (gpt->bheader && (gpt->pheader->my_lba != gpt->bheader->alternative_lba)) {
+ if (gpt->bheader && (le64_to_cpu(gpt->pheader->my_lba) !=
+ le64_to_cpu(gpt->bheader->alternative_lba))) {
nerror++;
fdisk_warnx(cxt, _("Primary and backup header mismatch."));
}