libfdisk: cleanup internal drivers' API

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2014-09-11 11:48:06 +02:00
parent b4df449f53
commit e11c668449
8 changed files with 45 additions and 45 deletions

View File

@ -872,8 +872,8 @@ static const struct fdisk_label_operations bsd_operations =
.list = bsd_list_disklabel,
.write = bsd_write_disklabel,
.create = bsd_create_disklabel,
.part_delete = bsd_delete_part,
.del_part = bsd_delete_part,
.get_part = bsd_get_partition,
.add_part = bsd_add_partition,

View File

@ -2115,8 +2115,8 @@ static const struct fdisk_label_operations dos_operations =
.get_part = dos_get_partition,
.add_part = dos_add_partition,
.del_part = dos_delete_partition,
.part_delete = dos_delete_partition,
.part_set_type = dos_set_parttype,
.part_toggle_flag = dos_toggle_partition_flag,

View File

@ -191,12 +191,18 @@ struct fdisk_label_operations {
/* set disk label ID */
int (*set_id)(struct fdisk_context *cxt);
/* new partition */
int (*add_part)(struct fdisk_context *cxt, struct fdisk_partition *pa, size_t *partno);
/* new partition */
int (*add_part)(struct fdisk_context *cxt, struct fdisk_partition *pa,
size_t *partno);
/* delete partition */
int (*part_delete)(struct fdisk_context *cxt,
size_t partnum);
int (*del_part)(struct fdisk_context *cxt, size_t partnum);
/* fill in partition struct */
int (*get_part)(struct fdisk_context *cxt, size_t n,
struct fdisk_partition *pa);
/*** TODO use set_part() */
/* get partition type */
struct fdisk_parttype *(*part_get_type)(struct fdisk_context *cxt,
size_t partnum);
@ -204,16 +210,11 @@ struct fdisk_label_operations {
int (*part_set_type)(struct fdisk_context *cxt,
size_t partnum,
struct fdisk_parttype *t);
/* return state of the partition */
int (*part_is_used)(struct fdisk_context *cxt, size_t partnum);
/* fill in partition struct */
int (*get_part)(struct fdisk_context *cxt,
size_t n,
struct fdisk_partition *pa);
int (*part_toggle_flag)(struct fdisk_context *cxt, size_t i, unsigned long flag);
/******/
/* refresh alignment setting */
int (*reset_alignment)(struct fdisk_context *cxt);

View File

@ -2409,8 +2409,7 @@ static const struct fdisk_label_operations gpt_operations =
.get_part = gpt_get_partition,
.add_part = gpt_add_partition,
.part_delete = gpt_delete_partition,
.del_part = gpt_delete_partition,
.part_is_used = gpt_part_is_used,
.part_set_type = gpt_set_partition_type,

View File

@ -198,9 +198,9 @@ extern int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id);
extern int fdisk_set_disklabel_id(struct fdisk_context *cxt);
extern int fdisk_get_partition(struct fdisk_context *cxt, size_t partno, struct fdisk_partition **pa);
extern int fdisk_add_partition(struct fdisk_context *cxt, struct fdisk_partition *pa, size_t *partno);
extern int fdisk_delete_partition(struct fdisk_context *cxt, size_t partnum);
extern int fdisk_delete_partition(struct fdisk_context *cxt, size_t partno);
extern int fdisk_delete_all_partitions(struct fdisk_context *cxt);
extern int fdisk_set_partition_type(struct fdisk_context *cxt, size_t partnum,

View File

@ -545,13 +545,14 @@ int fdisk_partition_to_string(struct fdisk_partition *pa,
/**
* fdisk_get_partition:
* @cxt:
* @partno:
* @pa: pointer to partition struct
* @cxt: context
* @partno: partition nuymber
* @pa: returns data about partition
*
* Fills in @pa with data about partition @n. Note that partno may address
* unused partition and then this function does not fill anything to @pa.
* See fdisk_is_partition_used().
* See fdisk_is_partition_used(). If @pa points to NULL then the function
* allocates a newly allocated fdisk_partition struct.
*
* Returns: 0 on success, otherwise, a corresponding error.
*/
@ -588,31 +589,19 @@ int fdisk_get_partition(struct fdisk_context *cxt, size_t partno,
return rc;
}
/*
* This is faster than fdisk_get_partition() + fdisk_partition_is_used()
*/
int fdisk_is_partition_used(struct fdisk_context *cxt, size_t n)
{
if (!cxt || !cxt->label)
return -EINVAL;
if (!cxt->label->op->part_is_used)
return -ENOSYS;
return cxt->label->op->part_is_used(cxt, n);
}
/**
* fdisk_add_partition:
* @cxt: fdisk context
* @pa: template for the partition (or NULL)
* @partno: returns new partition number (optional)
* @partno: NULL or returns new partition number
*
* If @pa is not specified or any @pa item is missiong the libfdisk will ask by
* fdisk_ask_ API.
*
* Creates a new partition.
*
* Returns 0.
* Returns: 0 on success, <0 on error.
*/
int fdisk_add_partition(struct fdisk_context *cxt,
struct fdisk_partition *pa,
@ -652,22 +641,22 @@ int fdisk_add_partition(struct fdisk_context *cxt,
/**
* fdisk_delete_partition:
* @cxt: fdisk context
* @partnum: partition number to delete
* @partno: partition number to delete
*
* Deletes a @partnum partition.
* Deletes a @partno partition.
*
* Returns 0 on success, otherwise, a corresponding error.
* Returns: 0 on success, <0 on error
*/
int fdisk_delete_partition(struct fdisk_context *cxt, size_t partnum)
int fdisk_delete_partition(struct fdisk_context *cxt, size_t partno)
{
if (!cxt || !cxt->label)
return -EINVAL;
if (!cxt->label->op->part_delete)
if (!cxt->label->op->del_part)
return -ENOSYS;
DBG(CXT, ul_debugobj(cxt, "deleting %s partition number %zd",
cxt->label->name, partnum));
return cxt->label->op->part_delete(cxt, partnum);
cxt->label->name, partno));
return cxt->label->op->del_part(cxt, partno);
}
/**
@ -698,3 +687,16 @@ int fdisk_delete_all_partitions(struct fdisk_context *cxt)
return rc;
}
/*
* This is faster than fdisk_get_partition() + fdisk_partition_is_used()
*/
int fdisk_is_partition_used(struct fdisk_context *cxt, size_t n)
{
if (!cxt || !cxt->label)
return -EINVAL;
if (!cxt->label->op->part_is_used)
return -ENOSYS;
return cxt->label->op->part_is_used(cxt, n);
}

View File

@ -1106,10 +1106,9 @@ static const struct fdisk_label_operations sgi_operations =
.get_part = sgi_get_partition,
.add_part = sgi_add_partition,
.del_part = sgi_delete_partition,
.part_delete = sgi_delete_partition,
.part_set_type = sgi_set_parttype,
.part_is_used = sgi_partition_is_used,
.part_toggle_flag = sgi_toggle_partition_flag
};

View File

@ -1020,10 +1020,9 @@ const struct fdisk_label_operations sun_operations =
.get_part = sun_get_partition,
.add_part = sun_add_partition,
.del_part = sun_delete_partition,
.part_delete = sun_delete_partition,
.part_set_type = sun_set_parttype,
.part_is_used = sun_partition_is_used,
.part_toggle_flag = sun_toggle_partition_flag,