diff options
author | Karel Zak | 2014-10-15 14:10:25 +0200 |
---|---|---|
committer | Karel Zak | 2014-10-15 14:10:25 +0200 |
commit | dfc6db2a3558d2a2cedbeb381e2cc8feda41a214 (patch) | |
tree | 2d21b109a09da5aac2ec36a7ef4ccb6433203b86 /libfdisk/src/partition.c | |
parent | libfdisk: cleanup partno API (diff) | |
download | kernel-qcow2-util-linux-dfc6db2a3558d2a2cedbeb381e2cc8feda41a214.tar.gz kernel-qcow2-util-linux-dfc6db2a3558d2a2cedbeb381e2cc8feda41a214.tar.xz kernel-qcow2-util-linux-dfc6db2a3558d2a2cedbeb381e2cc8feda41a214.zip |
libfdisk: cleanup parttype API
* add reference counting
* add functions to set allocated types
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libfdisk/src/partition.c')
-rw-r--r-- | libfdisk/src/partition.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/libfdisk/src/partition.c b/libfdisk/src/partition.c index d63dae03e..ee33d7bdf 100644 --- a/libfdisk/src/partition.c +++ b/libfdisk/src/partition.c @@ -48,7 +48,7 @@ void fdisk_reset_partition(struct fdisk_partition *pa) DBG(PART, ul_debugobj(pa, "reset")); ref = pa->refcount; - fdisk_free_parttype(pa->type); + fdisk_unref_parttype(pa->type); free(pa->name); free(pa->uuid); free(pa->attrs); @@ -383,17 +383,35 @@ int fdisk_partition_partno_follow_default(struct fdisk_partition *pa, int enable return 0; } +/** + * fdisk_partition_set_type: + * @pa: partition + * @type: partition type + * + * Sets parition type. + * + * Returns: 0 on success, <0 on error. + */ int fdisk_partition_set_type(struct fdisk_partition *pa, - const struct fdisk_parttype *type) + struct fdisk_parttype *type) { if (!pa) return -EINVAL; - fdisk_free_parttype(pa->type); - pa->type = fdisk_copy_parttype(type); + + fdisk_ref_parttype(type); + fdisk_unref_parttype(pa->type); + pa->type = type; + return 0; } -const struct fdisk_parttype *fdisk_partition_get_type(struct fdisk_partition *pa) +/** + * fdisk_partition_get_type: + * @pa: partition + * + * Returns: pointer to partition type. + */ +struct fdisk_parttype *fdisk_partition_get_type(struct fdisk_partition *pa) { return pa ? pa->type : NULL; } |