summaryrefslogtreecommitdiffstats
path: root/libfdisk
diff options
context:
space:
mode:
authorKarel Zak2014-04-16 12:51:08 +0200
committerKarel Zak2014-04-16 12:51:08 +0200
commit8b60872ec01c185b003826adabe3aa4f52c44ad0 (patch)
tree5dd953e4d49d19f91fbd77425b0921ec3714ecd4 /libfdisk
parentlibsmartcols: don't colorize tree ascii art (diff)
downloadkernel-qcow2-util-linux-8b60872ec01c185b003826adabe3aa4f52c44ad0.tar.gz
kernel-qcow2-util-linux-8b60872ec01c185b003826adabe3aa4f52c44ad0.tar.xz
kernel-qcow2-util-linux-8b60872ec01c185b003826adabe3aa4f52c44ad0.zip
libfdisk: add generic function to check partitions order
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk')
-rw-r--r--libfdisk/src/libfdisk.h1
-rw-r--r--libfdisk/src/table.c23
2 files changed, 24 insertions, 0 deletions
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