]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add fdisk_table_get_partition()
authorKarel Zak <kzak@redhat.com>
Wed, 22 Jan 2014 10:52:50 +0000 (11:52 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 11 Mar 2014 10:35:13 +0000 (11:35 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/libfdisk.h
libfdisk/src/table.c

index f3cc0d390154b3e41f4e2b4c1a2f0589fc179ac3..8a9cc926ec5ebc6c9d23380c9db6dbc2c62b506b 100644 (file)
@@ -228,6 +228,11 @@ extern int fdisk_table_next_partition(
                        struct fdisk_table *tb,
                        struct fdisk_iter *itr,
                        struct fdisk_partition **pa);
+
+extern struct fdisk_partition *fdisk_table_get_partition(
+                       struct fdisk_table *tb,
+                       size_t n);
+
 /* alignment.c */
 extern int fdisk_reset_alignment(struct fdisk_context *cxt);
 extern int fdisk_reset_device_properties(struct fdisk_context *cxt);
index 9a19dd39f64f8561270a25dfa869ecb769eefb07..5d3a02c679ab7cbcb8bd4ad78fba97c41052a462 100644 (file)
@@ -148,6 +148,27 @@ int fdisk_table_next_partition(
        return rc;
 }
 
+struct fdisk_partition *fdisk_table_get_partition(
+                       struct fdisk_table *tb,
+                       size_t n)
+{
+       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 (n == 0)
+                       return pa;
+               n--;
+       }
+
+       return NULL;
+}
+
 /**
  * fdisk_table_add_partition
  * @tb: tab pointer