]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: (gpt) reorder only when necessary
authorKarel Zak <kzak@redhat.com>
Wed, 2 Sep 2015 12:43:58 +0000 (14:43 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 2 Sep 2015 12:51:00 +0000 (14:51 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/dos.c
libfdisk/src/gpt.c
libfdisk/src/label.c

index 90e5af09ab55ee1a712d4a3d823ab7ccea9b6638..b337c0bec0d190582c5a491bde00c24407f06e20 100644 (file)
@@ -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;
 }
 
index b5bbbf705c43e7f7ee777457bf25a21b15fbd459..98da5aac9a7b04a11484ec367b940d4a064dae5c 100644 (file)
@@ -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;
 }
 
index 30d0e526f8758edb2f189d87467510d930bbe38d..bcb02ba3abb1664df753fcc33c79b989aed387d0 100644 (file)
@@ -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)
 {