]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add fdisk_table_get_partition_by_partno()
authorKarel Zak <kzak@redhat.com>
Tue, 21 Apr 2015 12:35:18 +0000 (14:35 +0200)
committerKarel Zak <kzak@redhat.com>
Wed, 29 Apr 2015 10:41:44 +0000 (12:41 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/docs/libfdisk-sections.txt
libfdisk/src/libfdisk.h.in
libfdisk/src/libfdisk.sym
libfdisk/src/table.c

index 2d5cd92fb76d2ae58c993b674b067d51d00b280b..4eee46f356a98c30c806e46253c3e67cf6355095 100644 (file)
@@ -265,6 +265,7 @@ fdisk_reset_table
 fdisk_table_add_partition
 fdisk_table_get_nents
 fdisk_table_get_partition
+fdisk_table_get_partition_by_partno
 fdisk_table_is_empty
 fdisk_table_next_partition
 fdisk_table_remove_partition
index 78c0728116a0967c85209a35810be9f5c0dbf2b4..2b8c0538d667c7e32579ca3d939eebc5d3c93f09 100644 (file)
@@ -361,7 +361,6 @@ int fdisk_partition_cmp_partno(struct fdisk_partition *a,
                                       struct fdisk_partition *b);
 int fdisk_partition_partno_follow_default(struct fdisk_partition *pa, int enable);
 
-
 extern int fdisk_partition_set_type(struct fdisk_partition *pa, struct fdisk_parttype *type);
 extern struct fdisk_parttype *fdisk_partition_get_type(struct fdisk_partition *pa);
 extern int fdisk_partition_set_name(struct fdisk_partition *pa, const char *name);
@@ -415,6 +414,10 @@ extern int fdisk_table_next_partition(
 extern struct fdisk_partition *fdisk_table_get_partition(
                        struct fdisk_table *tb,
                        size_t n);
+extern struct fdisk_partition *fdisk_table_get_partition_by_partno(
+                       struct fdisk_table *tb,
+                       size_t partno);
+
 extern int fdisk_apply_table(struct fdisk_context *cxt, struct fdisk_table *tb);
 
 /* alignment.c */
index 9f720ffcab9c8e5a13e17497b1a955a196faa603..52cdc1427ca6df1cbde91d7caf3d4762be2ad2ed 100644 (file)
@@ -243,4 +243,5 @@ local:
 FDISK_2.27 {
        fdisk_enable_bootbits_protection;
        fdisk_has_protected_bootbits;
+       fdisk_table_get_partition_by_partno;
 } FDISK_2.26;
index ae6e7daab7ebbfb0e3a61884c813d16d9263fa77..ea47951c14bd18274e25966c5a55cf0f33ce9df7 100644 (file)
@@ -158,6 +158,13 @@ int fdisk_table_next_partition(
        return rc;
 }
 
+/**
+ * fdisk_table_get_partition:
+ * @tb: tab pointer
+ * @n: number of entry in table
+ *
+ * Returns: n-th entry from table or NULL
+ */
 struct fdisk_partition *fdisk_table_get_partition(
                        struct fdisk_table *tb,
                        size_t n)
@@ -179,6 +186,33 @@ struct fdisk_partition *fdisk_table_get_partition(
        return NULL;
 }
 
+/**
+ * fdisk_table_get_partition_by_partno:
+ * @tb: tab pointer
+ * @partno: partition number
+ *
+ * Returns: partition with @partno or NULL.
+ */
+struct fdisk_partition *fdisk_table_get_partition_by_partno(
+                       struct fdisk_table *tb,
+                       size_t partno)
+{
+       struct fdisk_partition *pa = NULL;
+       struct fdisk_iter itr;
+
+       if (!tb)
+               return NULL;
+
+       fdisk_reset_iter(&itr, FDISK_ITER_FORWARD);
+
+       while (fdisk_table_next_partition(tb, &itr, &pa) == 0) {
+               if (pa->partno == partno)
+                       return pa;
+       }
+
+       return NULL;
+}
+
 /**
  * fdisk_table_add_partition
  * @tb: tab pointer