if (!wrong_p_order(cxt, NULL)) {
fdisk_info(cxt, _("Nothing to do. Ordering is correct already."));
- return 0;
+ return 1;
}
while ((i = wrong_p_order(cxt, &k)) != 0 && i < 4) {
if (i)
fix_chain_of_logicals(cxt);
- fdisk_info(cxt, _("Done."));
return 0;
}
static int gpt_reorder(struct fdisk_context *cxt)
{
struct fdisk_gpt_label *gpt;
- size_t nparts;
+ size_t i, nparts, mess;
assert(cxt);
assert(cxt->label);
gpt = self_label(cxt);
nparts = le32_to_cpu(gpt->pheader->npartition_entries);
+ for (i = 0, mess = 0; mess == 0 && i + 1 < nparts; i++)
+ mess = gpt_entry_cmp_start(
+ (const void *) &gpt->ents[i],
+ (const void *) &gpt->ents[i + 1]) > 0;
+
+ if (!mess) {
+ fdisk_info(cxt, _("Nothing to do. Ordering is correct already."));
+ return 1;
+ }
+
qsort(gpt->ents, nparts, sizeof(struct gpt_entry),
gpt_entry_cmp_start);
gpt_recompute_crc(gpt->bheader, gpt->ents);
fdisk_label_set_changed(cxt->label, 1);
- fdisk_info(cxt, _("Done."));
return 0;
}
*
* Sort partitions according to the partition start sector.
*
- * Returns: 0 on success, otherwise, a corresponding error.
+ * Returns: 0 on success, 1 reorder unnecessary, otherwise a corresponding error.
*/
int fdisk_reorder_partitions(struct fdisk_context *cxt)
{