From: Karel Zak Date: Thu, 6 Dec 2012 14:22:43 +0000 (+0100) Subject: libfdisk: cleanup the rest of fdisks/utils.c stuff X-Git-Tag: v2.23-rc1~158 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=171372d37ce16e2a28e106a764a211237fe4df75;p=thirdparty%2Futil-linux.git libfdisk: cleanup the rest of fdisks/utils.c stuff - remove obsolete code - move fdisk_{set,get}_partition_type() to label.c (this is label driver operation) Signed-off-by: Karel Zak --- diff --git a/fdisks/fdisk.h b/fdisks/fdisk.h index ec20837df2..4196d7bda5 100644 --- a/fdisks/fdisk.h +++ b/fdisks/fdisk.h @@ -60,13 +60,6 @@ enum failure { unable_to_write }; -/* - * labels - */ -extern struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum); -extern int fdisk_set_partition_type(struct fdisk_context *cxt, int partnum, - struct fdisk_parttype *t); - /* prototypes for fdisk.c */ extern char *line_ptr; extern int partitions; diff --git a/libfdisk/src/label.c b/libfdisk/src/label.c index fa7218c0f8..5d0eb3ef8a 100644 --- a/libfdisk/src/label.c +++ b/libfdisk/src/label.c @@ -194,3 +194,51 @@ int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name) return cxt->label->create(cxt); } + +/** + * fdisk_get_partition_type: + * @cxt: fdisk context + * @partnum: partition number + * + * Returns partition type or NULL upon failure. + */ +struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum) +{ + if (!cxt || !cxt->label || !cxt->label->part_get_type) + return NULL; + + DBG(LABEL, dbgprint("partition: %d: get type", partnum)); + return cxt->label->part_get_type(cxt, partnum); +} + +/** + * fdisk_set_partition_type: + * @cxt: fdisk context + * @partnum: partition number + * @t: new type + * + * Returns 0 on success, < 0 on error. + */ +int fdisk_set_partition_type(struct fdisk_context *cxt, int partnum, + struct fdisk_parttype *t) +{ + if (!cxt || !cxt->label || !cxt->label->part_set_type) + return -EINVAL; + + DBG(LABEL, dbgprint("partition: %d: set type", partnum)); + return cxt->label->part_set_type(cxt, partnum, t); +} + +/** + * fdisk_get_nparttypes: + * @cxt: fdisk context + * + * Returns: number of partition types supported by the current label + */ +size_t fdisk_get_nparttypes(struct fdisk_context *cxt) +{ + if (!cxt || !cxt->label) + return 0; + + return cxt->label->nparttypes; +} diff --git a/libfdisk/src/libfdisk.h b/libfdisk/src/libfdisk.h index 276f79b83e..d719a5c8d3 100644 --- a/libfdisk/src/libfdisk.h +++ b/libfdisk/src/libfdisk.h @@ -69,10 +69,15 @@ extern int fdisk_dev_is_disklabel(struct fdisk_context *cxt, enum fdisk_labeltyp extern int fdisk_write_disklabel(struct fdisk_context *cxt); extern int fdisk_verify_disklabel(struct fdisk_context *cxt); +extern int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name); extern int fdisk_add_partition(struct fdisk_context *cxt, int partnum, struct fdisk_parttype *t); extern int fdisk_delete_partition(struct fdisk_context *cxt, int partnum); +extern struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum); +extern int fdisk_set_partition_type(struct fdisk_context *cxt, int partnum, + struct fdisk_parttype *t); + /* alignment.c */ extern int fdisk_reset_alignment(struct fdisk_context *cxt); diff --git a/libfdisk/src/parttype.c b/libfdisk/src/parttype.c index 1d9f4e8027..e78b355943 100644 --- a/libfdisk/src/parttype.c +++ b/libfdisk/src/parttype.c @@ -165,50 +165,4 @@ void fdisk_free_parttype(struct fdisk_parttype *t) } } -/** - * fdisk_get_partition_type: - * @cxt: fdisk context - * @partnum: partition number - * - * Returns partition type or NULL upon failure. - */ -struct fdisk_parttype *fdisk_get_partition_type(struct fdisk_context *cxt, int partnum) -{ - if (!cxt || !cxt->label || !cxt->label->part_get_type) - return NULL; - - DBG(LABEL, dbgprint("partition: %d: get type", partnum)); - return cxt->label->part_get_type(cxt, partnum); -} - -/** - * fdisk_set_partition_type: - * @cxt: fdisk context - * @partnum: partition number - * @t: new type - * - * Returns 0 on success, < 0 on error. - */ -int fdisk_set_partition_type(struct fdisk_context *cxt, int partnum, - struct fdisk_parttype *t) -{ - if (!cxt || !cxt->label || !cxt->label->part_set_type) - return -EINVAL; - - DBG(LABEL, dbgprint("partition: %d: set type", partnum)); - return cxt->label->part_set_type(cxt, partnum, t); -} - -/** - * fdisk_get_nparttypes: - * @cxt: fdisk context - * - * Returns: number of partition types supported by the current label - */ -size_t fdisk_get_nparttypes(struct fdisk_context *cxt) -{ - if (!cxt || !cxt->label) - return 0; - return cxt->label->nparttypes; -}