From: Karel Zak Date: Thu, 12 May 2016 10:21:59 +0000 (+0200) Subject: libfdisk: move fdisk_field_...() functions to field.c X-Git-Tag: v2.29-rc1~250 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e4c5250dfbcbba067cea80f3be2a79c7ef3fdc46;p=thirdparty%2Futil-linux.git libfdisk: move fdisk_field_...() functions to field.c Signed-off-by: Karel Zak --- diff --git a/libfdisk/src/Makemodule.am b/libfdisk/src/Makemodule.am index d7e7f16d83..e24ae56206 100644 --- a/libfdisk/src/Makemodule.am +++ b/libfdisk/src/Makemodule.am @@ -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 index 0000000000..b9c5930a7d --- /dev/null +++ b/libfdisk/src/field.c @@ -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(). + * + * + * + * 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); + * + * + * + * 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; +} diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index ee5ee3e4ac..3410ed9ba1 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -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 diff --git a/libfdisk/src/libfdisk.h.in b/libfdisk/src/libfdisk.h.in index 6bd3a1e569..2e1a9b5ee0 100644 --- a/libfdisk/src/libfdisk.h.in +++ b/libfdisk/src/libfdisk.h.in @@ -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);