]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add generic function to check partitions order
authorKarel Zak <kzak@redhat.com>
Wed, 16 Apr 2014 10:51:08 +0000 (12:51 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 16 Apr 2014 10:51:08 +0000 (12:51 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
disk-utils/fdisk.c
libfdisk/src/libfdisk.h
libfdisk/src/table.c

index 2283c414276692b9765ad8b198a03b270f101a6a..8762a7ac8bfd3f974ca8e1859a9a91c04d364746 100644 (file)
@@ -589,6 +589,12 @@ void list_disklabel(struct fdisk_context *cxt)
                        free(str);
                }
        }
+
+       if (fdisk_table_wrong_order(tb)) {
+               fputc('\n', stdout);
+               fdisk_info(cxt, _("Partition table entries are not in disk order."));
+       }
+
        fdisk_unref_table(tb);
 }
 
index d9f33d300106c93b04ac66eb77c1cee851665413..b44451da611214e0e6c27be5b9f61c3aeae26d20 100644 (file)
@@ -238,6 +238,7 @@ extern int fdisk_table_remove_partition(struct fdisk_table *tb, struct fdisk_par
 extern int fdisk_get_partitions(struct fdisk_context *cxt, struct fdisk_table **tb);
 extern int fdisk_get_freespaces(struct fdisk_context *cxt, struct fdisk_table **tb);
 
+extern int fdisk_table_wrong_order(struct fdisk_table *tb);
 extern int fdisk_table_sort_partitions(struct fdisk_table *tb,
                        int (*cmp)(struct fdisk_partition *,
                                   struct fdisk_partition *));
index add6bd983d601de0da899840cb27bac0c6246e15..27365c0404243dbd0e6046ae583a86e8cf156917 100644 (file)
@@ -525,6 +525,29 @@ done:
        return rc;
 }
 
+/**
+ * fdisk_table_wrong_order:
+ * @tb: table
+ *
+ * Returns: 1 of the table is not in disk order
+ */
+int fdisk_table_wrong_order(struct fdisk_table *tb)
+{
+       struct fdisk_partition *pa;
+       struct fdisk_iter itr;
+       sector_t last = 0;
+
+       DBG(TAB, ul_debugobj(tb, "wrong older check"));
+
+       fdisk_reset_iter(&itr, FDISK_ITER_FORWARD);
+       while (tb && fdisk_table_next_partition(tb, &itr, &pa) == 0) {
+               if (pa->start < last)
+                       return 1;
+               last = pa->start;
+       }
+       return 0;
+}
+
 /**
  * fdisk_table_to_string
  * @tb: table