]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: add fdisk_label_get_fields_ids_all()
authorKarel Zak <kzak@redhat.com>
Mon, 11 May 2015 10:42:24 +0000 (12:42 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 11 May 2015 10:42:24 +0000 (12:42 +0200)
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>
libfdisk/docs/libfdisk-sections.txt
libfdisk/src/label.c
libfdisk/src/libfdisk.h.in
libfdisk/src/libfdisk.sym

index 02b775ea6bf26b7925dd696ccb521e038c62df77..ea35e2bc590c3b8943abdbbe5c8a319ad5f27678 100644 (file)
@@ -101,6 +101,7 @@ fdisk_is_label
 fdisk_label_get_field
 fdisk_label_get_field_by_name
 fdisk_label_get_fields_ids
+fdisk_label_get_fields_ids_all
 fdisk_label_get_name
 fdisk_label_get_nparttypes
 fdisk_label_get_parttype
index 717a8cd802a2b73ea74d0d01b4df3ea653d27a0b..dd9fef040bb016314d7d69aebf1ce292cb11b7aa 100644 (file)
@@ -156,6 +156,47 @@ int fdisk_label_get_fields_ids(
        return 0;
 }
 
+/**
+ * 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
index a5a46567461de01e6aa905343a28f7141f950497..bfb22a2f7687b91a6b4e1be53c7599db1a608df2 100644 (file)
@@ -308,6 +308,11 @@ extern int fdisk_label_get_fields_ids(
                        struct fdisk_context *cxt,
                        int **ids, size_t *nids);
 
+extern int fdisk_label_get_fields_ids_all(
+                       const struct fdisk_label *lb,
+                       struct fdisk_context *cxt,
+                       int **ids, size_t *nids);
+
 extern const struct fdisk_field *fdisk_label_get_field(const struct fdisk_label *lb, int id);
 extern const struct fdisk_field *fdisk_label_get_field_by_name(
                        const struct fdisk_label *lb,
index 1e6394465d86a74d73b5871510518046dc67c97c..15c268ee30d6733ad579046a0b681fd664947cb0 100644 (file)
@@ -241,12 +241,13 @@ local:
 };
 
 FDISK_2.27 {
-       fdisk_script_set_fgets;
-       fdisk_script_set_userdata;
-       fdisk_script_get_userdata;
        fdisk_enable_bootbits_protection;
-       fdisk_has_protected_bootbits;
-       fdisk_table_get_partition_by_partno;
        fdisk_gpt_get_partition_attrs;
        fdisk_gpt_set_partition_attrs;
+       fdisk_has_protected_bootbits;
+       fdisk_label_get_fields_ids_all;
+       fdisk_script_get_userdata;
+       fdisk_script_set_fgets;
+       fdisk_script_set_userdata;
+       fdisk_table_get_partition_by_partno;
 } FDISK_2.26;