diff options
-rw-r--r-- | libfdisk/src/dos.c | 3 | ||||
-rw-r--r-- | libfdisk/src/gpt.c | 13 | ||||
-rw-r--r-- | libfdisk/src/label.c | 2 |
3 files changed, 13 insertions, 5 deletions
diff --git a/libfdisk/src/dos.c b/libfdisk/src/dos.c index 90e5af09a..b337c0bec 100644 --- a/libfdisk/src/dos.c +++ b/libfdisk/src/dos.c @@ -2140,7 +2140,7 @@ static int dos_reorder(struct fdisk_context *cxt) 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) { @@ -2168,7 +2168,6 @@ static int dos_reorder(struct fdisk_context *cxt) if (i) fix_chain_of_logicals(cxt); - fdisk_info(cxt, _("Done.")); return 0; } diff --git a/libfdisk/src/gpt.c b/libfdisk/src/gpt.c index b5bbbf705..98da5aac9 100644 --- a/libfdisk/src/gpt.c +++ b/libfdisk/src/gpt.c @@ -2661,7 +2661,7 @@ static int gpt_entry_cmp_start(const void *a, const void *b) 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); @@ -2670,6 +2670,16 @@ static int gpt_reorder(struct fdisk_context *cxt) 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); @@ -2677,7 +2687,6 @@ static int gpt_reorder(struct fdisk_context *cxt) gpt_recompute_crc(gpt->bheader, gpt->ents); fdisk_label_set_changed(cxt->label, 1); - fdisk_info(cxt, _("Done.")); return 0; } diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 30d0e526f..bcb02ba3a 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -585,7 +585,7 @@ int fdisk_toggle_partition_flag(struct fdisk_context *cxt, * * 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) { |