summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/table.c
diff options
context:
space:
mode:
authorKarel Zak2014-08-29 11:18:29 +0200
committerKarel Zak2014-08-29 11:18:29 +0200
commit3c0e6b1530a089c592f0149a3e976f0d403eefd7 (patch)
tree712d082ba9fa23c6a01428ef4e32be9af86c551f /libfdisk/src/table.c
parentlibfdisk: improve debug messages (diff)
downloadkernel-qcow2-util-linux-3c0e6b1530a089c592f0149a3e976f0d403eefd7.tar.gz
kernel-qcow2-util-linux-3c0e6b1530a089c592f0149a3e976f0d403eefd7.tar.xz
kernel-qcow2-util-linux-3c0e6b1530a089c592f0149a3e976f0d403eefd7.zip
libfdisk: add fdisk_apply_table() and fdisk_delete_all_partitions()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/table.c')
-rw-r--r--libfdisk/src/table.c36
1 files changed, 34 insertions, 2 deletions
diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c
index 8de8a7542..c6c51c837 100644
--- a/libfdisk/src/table.c
+++ b/libfdisk/src/table.c
@@ -28,8 +28,9 @@ struct fdisk_table *fdisk_new_table(void)
* fdisk_reset_table:
* @tb: tab pointer
*
- * Removes all entries (filesystems) from the table. The filesystems with zero
- * reference count will be deallocated.
+ * Removes all entries (partitions) from the table. The parititons with zero
+ * reference count will be deallocated. This function does not modify partition
+ * table.
*
* Returns: 0 on success or negative number in case of error.
*/
@@ -530,3 +531,34 @@ int fdisk_table_wrong_order(struct fdisk_table *tb)
return 0;
}
+/**
+ * fdisk_apply_table:
+ * @cxt: context
+ * @tb: table
+ *
+ * Add partitions from table @tb to the in-memory disk label. See
+ * fdisk_add_partition(), fdisk_delete_all_partitions().
+ *
+ * Returns: 0 on success, <0 on error.
+ */
+int fdisk_apply_table(struct fdisk_context *cxt, struct fdisk_table *tb)
+{
+ struct fdisk_partition *pa;
+ struct fdisk_iter itr;
+ int rc = 0;
+
+ assert(cxt);
+ assert(tb);
+
+ DBG(TAB, ul_debugobj(tb, "applying to context %p", cxt));
+
+ fdisk_reset_iter(&itr, FDISK_ITER_FORWARD);
+ while (tb && fdisk_table_next_partition(tb, &itr, &pa) == 0) {
+ rc = fdisk_add_partition(cxt, pa);
+ if (rc)
+ break;
+ }
+
+ return rc;
+}
+