diff options
author | Karel Zak | 2014-10-03 12:12:23 +0200 |
---|---|---|
committer | Karel Zak | 2014-10-07 14:55:32 +0200 |
commit | eac3aac95bfcaee3cc4cbc784a7b8b73e37fcd9c (patch) | |
tree | 65a1530c8f79c443c95a3757f35dd77adec4e853 /libfdisk/src/label.c | |
parent | libfdisk: (gpt) remove 'Cylinders' (diff) | |
download | kernel-qcow2-util-linux-eac3aac95bfcaee3cc4cbc784a7b8b73e37fcd9c.tar.gz kernel-qcow2-util-linux-eac3aac95bfcaee3cc4cbc784a7b8b73e37fcd9c.tar.xz kernel-qcow2-util-linux-eac3aac95bfcaee3cc4cbc784a7b8b73e37fcd9c.zip |
libfdisk: add fdisk_label_get_field_by_name() and const for labels
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/label.c')
-rw-r--r-- | libfdisk/src/label.c | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index 071657c57..a3a4e8812 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -65,7 +65,7 @@ int fdisk_probe_labels(struct fdisk_context *cxt) * * Returns: label name */ -const char *fdisk_label_get_name(struct fdisk_label *lb) +const char *fdisk_label_get_name(const struct fdisk_label *lb) { return lb ? lb->name : NULL; } @@ -76,7 +76,7 @@ const char *fdisk_label_get_name(struct fdisk_label *lb) * * Returns: FDISK_DISKLABEL_*. */ -int fdisk_label_get_type(struct fdisk_label *lb) +int fdisk_label_get_type(const struct fdisk_label *lb) { return lb->id; } @@ -87,7 +87,7 @@ int fdisk_label_get_type(struct fdisk_label *lb) * * Returns: 1 if label requires CHS geometry */ -int fdisk_label_require_geometry(struct fdisk_label *lb) +int fdisk_label_require_geometry(const struct fdisk_label *lb) { assert(lb); @@ -109,7 +109,7 @@ int fdisk_label_require_geometry(struct fdisk_label *lb) * Returns 0 on success, otherwise, a corresponding error. */ int fdisk_label_get_fields_ids( - struct fdisk_label *lb, + const struct fdisk_label *lb, struct fdisk_context *cxt, int **ids, size_t *nids) { @@ -162,7 +162,7 @@ int fdisk_label_get_fields_ids( * * Returns: pointer to static instance of the field. */ -const struct fdisk_field *fdisk_label_get_field(struct fdisk_label *lb, int id) +const struct fdisk_field *fdisk_label_get_field(const struct fdisk_label *lb, int id) { size_t i; @@ -178,6 +178,31 @@ const struct fdisk_field *fdisk_label_get_field(struct fdisk_label *lb, int id) } /** + * fdisk_label_get_field_by_name + * @lb: label + * @name: field name + * + * Returns: pointer to static instance of the field. + */ +const struct fdisk_field *fdisk_label_get_field_by_name( + const struct fdisk_label *lb, + const char *name) +{ + size_t i; + + assert(lb); + assert(name); + + for (i = 0; i < lb->nfields; i++) { + if (lb->fields[i].name && strcasecmp(lb->fields[i].name, name) == 0) + return &lb->fields[i]; + } + + return NULL; +} + + +/** * fdisk_field_get_id: * @field: field instance * @@ -495,7 +520,7 @@ void fdisk_label_set_changed(struct fdisk_label *lb, int changed) * * Returns: 1 if in-memory data has been changed. */ -int fdisk_label_is_changed(struct fdisk_label *lb) +int fdisk_label_is_changed(const struct fdisk_label *lb) { assert(lb); return lb ? lb->changed : 0; @@ -524,7 +549,7 @@ void fdisk_label_set_disabled(struct fdisk_label *lb, int disabled) * * Returns: 1 if label driver disabled. */ -int fdisk_label_is_disabled(struct fdisk_label *lb) +int fdisk_label_is_disabled(const struct fdisk_label *lb) { assert(lb); return lb ? lb->disabled : 0; |