]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libfdisk: move fdisk_field_...() functions to field.c
authorKarel Zak <kzak@redhat.com>
Thu, 12 May 2016 10:21:59 +0000 (12:21 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 12 May 2016 10:21:59 +0000 (12:21 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
libfdisk/src/Makemodule.am
libfdisk/src/field.c [new file with mode: 0644]
libfdisk/src/label.c
libfdisk/src/libfdisk.h.in

index d7e7f16d8360b3db0bc23e1d944c447ebbdf6f8f..e24ae56206723b55549cfa4e3e1f1ee78f66bd03 100644 (file)
@@ -9,6 +9,7 @@ libfdisk_la_SOURCES = \
        \
        libfdisk/src/fdiskP.h \
        libfdisk/src/init.c \
+       libfdisk/src/field.c \
        libfdisk/src/test.c \
        libfdisk/src/ask.c \
        libfdisk/src/alignment.c \
diff --git a/libfdisk/src/field.c b/libfdisk/src/field.c
new file mode 100644 (file)
index 0000000..b9c5930
--- /dev/null
@@ -0,0 +1,88 @@
+
+#include "fdiskP.h"
+
+/**
+ * SECTION: field
+ * @title: Field
+ * @short_description: description of the partition fields
+ *
+ * The fdisk fields are static user-freindly descriptions of the partition. The
+ * fields are used to avoid label specific stuff in the functions that list disk
+ * partitions (e.g. fdisk -l). The field Id is the same as Id for fdisk_partition_to_string().
+ *
+ * <informalexample>
+ *   <programlisting>
+ * int *ids;
+ * size_t nids;
+ * struct fdisk_partition *pa = NULL;
+ * struct fdisk_label *lb = fdisk_get_label(cxt, NULL);
+ *
+ * fdisk_label_get_fields_ids(lb, cxt, &ids, &nids);
+ *
+ * fdisk_get_partition(cxt, 0, &pa);
+ *
+ * for (i = 0; i < nids; i++) {
+ *     const struct fdisk_field *field = fdisk_label_get_field(lb, ids[i]);
+ *
+ *     int id = fdisk_field_get_id(fl);
+ *     const char *name = fdisk_field_get_name(fl);
+ *     char *data;
+ *
+ *     fdisk_partition_to_string(pa, id, &data);
+ *     printf("%s: %s\n", name, data);
+ *     free(data);
+ * }
+ * free(ids);
+ *    </programlisting>
+ * </informalexample>
+ *
+ * This example lists all information about the first partition. It will work
+ * for MBR as well as for GPT because fields are not hardcoded in the execmple.
+ *
+ * See also fdisk_label_get_field_by_name(), fdisk_label_get_fields_ids_all()
+ * and fdisk_label_get_fields_ids().
+ */
+
+/**
+ * fdisk_field_get_id:
+ * @field: field instance
+ *
+ * Returns: field Id (FDISK_FIELD_*)
+ */
+int fdisk_field_get_id(const struct fdisk_field *field)
+{
+       return field ? field->id : -EINVAL;
+}
+
+/**
+ * fdisk_field_get_name:
+ * @field: field instance
+ *
+ * Returns: field name
+ */
+const char *fdisk_field_get_name(const struct fdisk_field *field)
+{
+       return field ? field->name : NULL;
+}
+
+/**
+ * fdisk_field_get_width:
+ * @field: field instance
+ *
+ * Returns: libsmartcols compatible width.
+ */
+double fdisk_field_get_width(const struct fdisk_field *field)
+{
+       return field ? field->width : -EINVAL;
+}
+
+/**
+ * fdisk_field_is_number:
+ * @field: field instance
+ *
+ * Returns: 1 if field represent number
+ */
+int fdisk_field_is_number(const struct fdisk_field *field)
+{
+       return field->flags ? field->flags & FDISK_FIELDFL_NUMBER : 0;
+}
index ee5ee3e4ac60ace4e20279f8934e23e7f63f65e2..3410ed9ba1f276dc7c7fa4094798e04ff3e7b229 100644 (file)
@@ -243,52 +243,6 @@ const struct fdisk_field *fdisk_label_get_field_by_name(
        return NULL;
 }
 
-
-/**
- * fdisk_field_get_id:
- * @field: field instance
- *
- * Returns: field Id (FDISK_FIELD_*)
- */
-int fdisk_field_get_id(const struct fdisk_field *field)
-{
-       return field ? field->id : -EINVAL;
-}
-
-/**
- * fdisk_field_get_name:
- * @field: field instance
- *
- * Returns: field name
- */
-const char *fdisk_field_get_name(const struct fdisk_field *field)
-{
-       return field ? field->name : NULL;
-}
-
-/**
- * fdisk_field_get_width:
- * @field: field instance
- *
- * Returns: libsmartcols compatible width.
- */
-double fdisk_field_get_width(const struct fdisk_field *field)
-{
-       return field ? field->width : -EINVAL;
-}
-
-/**
- * fdisk_field_is_number:
- * @field: field instance
- *
- * Returns: 1 if field represent number
- */
-int fdisk_field_is_number(const struct fdisk_field *field)
-{
-       return field->flags ? field->flags & FDISK_FIELDFL_NUMBER : 0;
-}
-
-
 /**
  * fdisk_write_disklabel:
  * @cxt: fdisk context
index 6bd3a1e56991b1c71a4052285d8edcc52cfc8bf1..2e1a9b5ee0e791539fa96309428b76a07185683c 100644 (file)
@@ -254,6 +254,14 @@ unsigned int fdisk_parttype_get_code(const struct fdisk_parttype *t);
 const char *fdisk_parttype_get_name(const struct fdisk_parttype *t);
 int fdisk_parttype_is_unknown(const struct fdisk_parttype *t);
 
+
+/* field.c */
+extern int fdisk_field_get_id(const struct fdisk_field *field);
+extern const char *fdisk_field_get_name(const struct fdisk_field *field);
+extern double fdisk_field_get_width(const struct fdisk_field *field);
+extern int fdisk_field_is_number(const struct fdisk_field *field);
+
+
 /* label.c */
 
 /**
@@ -348,12 +356,6 @@ extern const struct fdisk_field *fdisk_label_get_field_by_name(
                        const struct fdisk_label *lb,
                        const char *name);
 
-extern int fdisk_field_get_id(const struct fdisk_field *field);
-extern const char *fdisk_field_get_name(const struct fdisk_field *field);
-extern double fdisk_field_get_width(const struct fdisk_field *field);
-extern int fdisk_field_is_number(const struct fdisk_field *field);
-
-
 extern void fdisk_label_set_changed(struct fdisk_label *lb, int changed);
 extern int fdisk_label_is_changed(const struct fdisk_label *lb);