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 | |
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')
-rw-r--r-- | libfdisk/src/label.c | 39 | ||||
-rw-r--r-- | libfdisk/src/libfdisk.h | 32 | ||||
-rw-r--r-- | libfdisk/src/parttype.c | 16 |
3 files changed, 59 insertions, 28 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; diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h index ac0aad263..96c6bfaef 100644 --- a/libfdisk/src/libfdisk.h +++ b/libfdisk/src/libfdisk.h @@ -132,21 +132,21 @@ sector_t fdisk_get_geom_sectors(struct fdisk_context *cxt); sector_t fdisk_get_geom_cylinders(struct fdisk_context *cxt); /* parttype.c */ -const struct fdisk_parttype *fdisk_label_get_parttype(struct fdisk_label *lb, size_t n); -size_t fdisk_label_get_nparttypes(struct fdisk_label *lb); +const struct fdisk_parttype *fdisk_label_get_parttype(const struct fdisk_label *lb, size_t n); +size_t fdisk_label_get_nparttypes(const struct fdisk_label *lb); -int fdisk_label_has_code_parttypes(struct fdisk_label *lb); +int fdisk_label_has_code_parttypes(const struct fdisk_label *lb); struct fdisk_parttype *fdisk_label_get_parttype_from_code( - struct fdisk_label *lb, + const struct fdisk_label *lb, unsigned int code); struct fdisk_parttype *fdisk_label_get_parttype_from_string( - struct fdisk_label *lb, + const struct fdisk_label *lb, const char *str); struct fdisk_parttype *fdisk_new_unknown_parttype(unsigned int code, const char *typestr); struct fdisk_parttype *fdisk_label_parse_parttype( - struct fdisk_label *lb, + const struct fdisk_label *lb, const char *str); struct fdisk_parttype *fdisk_copy_parttype(const struct fdisk_parttype *type); @@ -181,11 +181,13 @@ enum { FDISK_FIELD_NAME, FDISK_FIELD_SADDR, FDISK_FIELD_UUID, + + FDISK_NFIELDS /* must be last */ }; -int fdisk_label_get_type(struct fdisk_label *lb); -const char *fdisk_label_get_name(struct fdisk_label *lb); -int fdisk_label_require_geometry(struct fdisk_label *lb); +int fdisk_label_get_type(const struct fdisk_label *lb); +const char *fdisk_label_get_name(const struct fdisk_label *lb); +int fdisk_label_require_geometry(const struct fdisk_label *lb); extern int fdisk_write_disklabel(struct fdisk_context *cxt); @@ -209,10 +211,14 @@ extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum, extern int fdisk_label_get_fields_ids( - struct fdisk_label *lb, + const struct fdisk_label *lb, struct fdisk_context *cxt, int **ids, size_t *nids); -extern const struct fdisk_field *fdisk_label_get_field(struct fdisk_label *lb, int id); + +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, + const char *name); extern int fdisk_field_get_id(const struct fdisk_field *fl); extern const char *fdisk_field_get_name(const struct fdisk_field *fl); @@ -221,10 +227,10 @@ extern int fdisk_field_is_number(const struct fdisk_field *fl); extern void fdisk_label_set_changed(struct fdisk_label *lb, int changed); -extern int fdisk_label_is_changed(struct fdisk_label *lb); +extern int fdisk_label_is_changed(const struct fdisk_label *lb); extern void fdisk_label_set_disabled(struct fdisk_label *lb, int disabled); -extern int fdisk_label_is_disabled(struct fdisk_label *lb); +extern int fdisk_label_is_disabled(const struct fdisk_label *lb); extern int fdisk_is_partition_used(struct fdisk_context *cxt, size_t n); diff --git a/libfdisk/src/parttype.c b/libfdisk/src/parttype.c index 21baedcd1..8c4ac61ef 100644 --- a/libfdisk/src/parttype.c +++ b/libfdisk/src/parttype.c @@ -12,7 +12,7 @@ * * Returns: number of types supported by label. */ -size_t fdisk_label_get_nparttypes(struct fdisk_label *lb) +size_t fdisk_label_get_nparttypes(const struct fdisk_label *lb) { if (!lb) return 0; @@ -26,7 +26,7 @@ size_t fdisk_label_get_nparttypes(struct fdisk_label *lb) * * Returns: return parttype */ -const struct fdisk_parttype *fdisk_label_get_parttype(struct fdisk_label *lb, size_t n) +const struct fdisk_parttype *fdisk_label_get_parttype(const struct fdisk_label *lb, size_t n) { if (!lb || n >= lb->nparttypes) return NULL; @@ -40,7 +40,7 @@ const struct fdisk_parttype *fdisk_label_get_parttype(struct fdisk_label *lb, si * Returns: 1 if the label uses code as partition type * identifiers (e.g. MBR) or 0. */ -int fdisk_label_has_code_parttypes(struct fdisk_label *lb) +int fdisk_label_has_code_parttypes(const struct fdisk_label *lb) { assert(lb); @@ -60,7 +60,7 @@ int fdisk_label_has_code_parttypes(struct fdisk_label *lb) * Returns: partition type or NULL upon failure or invalid @code. */ struct fdisk_parttype *fdisk_label_get_parttype_from_code( - struct fdisk_label *lb, + const struct fdisk_label *lb, unsigned int code) { size_t i; @@ -87,7 +87,7 @@ struct fdisk_parttype *fdisk_label_get_parttype_from_code( * Returns: partition type or NULL upon failure or invalid @str. */ struct fdisk_parttype *fdisk_label_get_parttype_from_string( - struct fdisk_label *lb, + const struct fdisk_label *lb, const char *str) { size_t i; @@ -172,7 +172,7 @@ struct fdisk_parttype *fdisk_copy_parttype(const struct fdisk_parttype *type) * for all results. */ struct fdisk_parttype *fdisk_label_parse_parttype( - struct fdisk_label *lb, + const struct fdisk_label *lb, const char *str) { struct fdisk_parttype *types, *ret; @@ -184,7 +184,7 @@ struct fdisk_parttype *fdisk_label_parse_parttype( if (!lb->nparttypes) return NULL; - DBG(LABEL, ul_debugobj(lb, "parsing '%s' (%s) partition type", + DBG(LABEL, ul_debugobj((void *) lb, "parsing '%s' (%s) partition type", str, lb->name)); types = lb->parttypes; @@ -195,7 +195,7 @@ struct fdisk_parttype *fdisk_label_parse_parttype( code = strtol(str, &end, 16); if (errno || *end != '\0') { - DBG(LABEL, ul_debugobj(lb, "parsing failed: %m")); + DBG(LABEL, ul_debugobj((void *) lb, "parsing failed: %m")); return NULL; } ret = fdisk_label_get_parttype_from_code(lb, code); |