summaryrefslogtreecommitdiffstats
path: root/libfdisk/src/label.c
diff options
context:
space:
mode:
authorKarel Zak2015-05-11 12:42:24 +0200
committerKarel Zak2015-05-11 12:42:24 +0200
commit31ea7fa6d4f978db37cd0efb08d006ca2f1bec6b (patch)
tree9b62376ba8708cc7324b1f321807a244c9f1f35e /libfdisk/src/label.c
parentfdisk: add the 'i'nfo command (diff)
downloadkernel-qcow2-util-linux-31ea7fa6d4f978db37cd0efb08d006ca2f1bec6b.tar.gz
kernel-qcow2-util-linux-31ea7fa6d4f978db37cd0efb08d006ca2f1bec6b.tar.xz
kernel-qcow2-util-linux-31ea7fa6d4f978db37cd0efb08d006ca2f1bec6b.zip
libfdisk: add fdisk_label_get_fields_ids_all()
The current fdisk_label_get_fields_ids() is too smart as it differentiate between details mode etc. It's useful for default output, but in some cases it's better to provide all output fields. Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/label.c')
-rw-r--r--libfdisk/src/label.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c
index 717a8cd80..dd9fef040 100644
--- a/libfdisk/src/label.c
+++ b/libfdisk/src/label.c
@@ -157,6 +157,47 @@ int fdisk_label_get_fields_ids(
}
/**
+ * fdisk_label_get_fields_ids_all
+ * @lb: label (or NULL for the current label)
+ * @cxt: context
+ * @ids: returns allocated array with FDISK_FIELD_* IDs
+ * @nids: returns number of items in fields
+ *
+ * This function returns all fields for the label.
+ *
+ * Returns: 0 on success, otherwise, a corresponding error.
+ */
+int fdisk_label_get_fields_ids_all(
+ const struct fdisk_label *lb,
+ struct fdisk_context *cxt,
+ int **ids, size_t *nids)
+{
+ size_t i, n;
+ int *c;
+
+ assert(cxt);
+
+ if (!lb)
+ lb = cxt->label;
+ if (!lb)
+ return -EINVAL;
+ if (!lb->fields || !lb->nfields)
+ return -ENOSYS;
+ c = calloc(lb->nfields, sizeof(int));
+ if (!c)
+ return -ENOMEM;
+ for (n = 0, i = 0; i < lb->nfields; i++)
+ c[n++] = lb->fields[i].id;
+ if (ids)
+ *ids = c;
+ else
+ free(c);
+ if (nids)
+ *nids = n;
+ return 0;
+}
+
+/**
* fdisk_label_get_field:
* @lb: label
* @id: FDISK_FIELD_*