コード例 #1
0
ファイル: partition.c プロジェクト: balagopalraj/clearlinux
/**
 * fdisk_get_partition:
 * @cxt: context
 * @partno: partition number (0 is the first partition)
 * @pa: returns data about partition
 *
 * Reads disklabel and 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(). If @pa points to
 * NULL then the function allocates a newly allocated fdisk_partition struct,
 * use fdisk_unref_partition() to deallocate.
 *
 * Returns: 0 on success, otherwise, a corresponding error.
 */
int fdisk_get_partition(struct fdisk_context *cxt, size_t partno,
			struct fdisk_partition **pa)
{
	int rc;
	struct fdisk_partition *np = NULL;

	if (!cxt || !cxt->label || !pa)
		return -EINVAL;
	if (!cxt->label->op->get_part)
		return -ENOSYS;
	if (!fdisk_is_partition_used(cxt, partno))
		return -EINVAL;

	if (!*pa) {
		np = *pa = fdisk_new_partition();
		if (!*pa)
			return -ENOMEM;
	} else
		fdisk_reset_partition(*pa);

	(*pa)->partno = partno;
	rc = cxt->label->op->get_part(cxt, partno, *pa);

	if (rc) {
		if (np) {
			fdisk_unref_partition(np);
			*pa = NULL;
		} else
			fdisk_reset_partition(*pa);
	} else
		(*pa)->size_explicit = 1;
	return rc;
}
コード例 #2
0
ファイル: partition.c プロジェクト: balagopalraj/clearlinux
static struct fdisk_partition *__copy_partition(struct fdisk_partition *o)
{
	struct fdisk_partition *n = fdisk_new_partition();

	if (!n)
		return NULL;
	memcpy(n, o, sizeof(*n));
	if (n->type)
		fdisk_ref_parttype(n->type);
	if (o->name)
		n->name = strdup(o->name);
	if (o->uuid)
		n->uuid = strdup(o->uuid);
	if (o->attrs)
		n->attrs = strdup(o->attrs);
	return n;
}
コード例 #3
0
ファイル: label.c プロジェクト: stancheff/util-linux
/**
 * 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,
			     size_t partnum,
			     struct fdisk_parttype *t)
{
	if (!cxt || !cxt->label || !t)
		return -EINVAL;


	if (cxt->label->op->set_part) {
		struct fdisk_partition *pa = fdisk_new_partition();
		int rc;

		if (!pa)
			return -ENOMEM;
		fdisk_partition_set_type(pa, t);

		DBG(CXT, ul_debugobj(cxt, "partition: %zd: set type", partnum));
		rc = cxt->label->op->set_part(cxt, partnum, pa);
		fdisk_unref_partition(pa);
		return rc;
	}

	return -ENOSYS;
}