libfdisk: add fdisk_locate_disklabel()

The function returns offset and size of disklabel elements.

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2013-09-03 17:35:15 +02:00
parent 513d546289
commit c0d20aae6f
3 changed files with 18 additions and 0 deletions

View File

@ -148,6 +148,9 @@ struct fdisk_label_operations {
int (*create)(struct fdisk_context *cxt);
/* list partition table */
int (*list)(struct fdisk_context *cxt);
/* returns offset and size of the 'n' part of the PT */
int (*locate)(struct fdisk_context *cxt, int n, const char **name, off_t *offset, size_t *size);
/* get disk label ID */
int (*get_id)(struct fdisk_context *cxt, char **id);
/* set disk label ID */

View File

@ -245,6 +245,20 @@ int fdisk_create_disklabel(struct fdisk_context *cxt, const char *name)
return cxt->label->op->create(cxt);
}
int fdisk_locate_disklabel(struct fdisk_context *cxt, int n, const char **name,
off_t *offset, size_t *size)
{
if (!cxt || !cxt->label)
return -EINVAL;
if (!cxt->label->op->locate)
return -ENOSYS;
DBG(LABEL, dbgprint("locating %d chunk of %s.", n, cxt->label->name));
return cxt->label->op->locate(cxt, n, name, offset, size);
}
/**
* fdisk_get_disklabel_id:
* @cxt: fdisk context

View File

@ -127,6 +127,7 @@ 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_list_disklabel(struct fdisk_context *cxt);
extern int fdisk_locate_disklabel(struct fdisk_context *cxt, int n, const char **name, off_t *offset, size_t *size);
extern int fdisk_get_disklabel_id(struct fdisk_context *cxt, char **id);
extern int fdisk_set_disklabel_id(struct fdisk_context *cxt);