diff options
-rw-r--r-- | disk-utils/fdisk.c | 6 | ||||
-rw-r--r-- | libfdisk/src/libfdisk.h | 1 | ||||
-rw-r--r-- | libfdisk/src/table.c | 23 |
3 files changed, 30 insertions, 0 deletions
diff --git a/disk-utils/fdisk.c b/disk-utils/fdisk.c index 2283c4142..8762a7ac8 100644 --- a/disk-utils/fdisk.c +++ b/disk-utils/fdisk.c @@ -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); } diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h index d9f33d300..b44451da6 100644 --- a/libfdisk/src/libfdisk.h +++ b/libfdisk/src/libfdisk.h @@ -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 *)); diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c index add6bd983..27365c040 100644 --- a/libfdisk/src/table.c +++ b/libfdisk/src/table.c @@ -526,6 +526,29 @@ done: } /** + * 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 * @cxt: fdisk context |