Top |
The fdisk_partition provides label independent abstraction. The partitions are not directly connected with partition table (label) data. Any change to fdisk_partition does not affects in-memory or on-disk label data.
The fdisk_partition is possible to use as a template for
fdisk_add_partition()
or fdisk_set_partition()
operations.
int fdisk_add_partition (struct fdisk_context *cxt
,struct fdisk_partition *pa
,size_t *partno
);
If pa
is not specified or any pa
item is missiong the libfdisk will ask by
fdisk_ask_ API.
Adds a new partition to disklabel.
int
fdisk_delete_all_partitions (struct fdisk_context *cxt
);
Delete all used partitions from disklabel.
int fdisk_delete_partition (struct fdisk_context *cxt
,size_t partno
);
Deletes a partno
partition from disklabel.
int fdisk_get_partition (struct fdisk_context *cxt
,size_t partno
,struct fdisk_partition **pa
);
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.
int fdisk_is_partition_used (struct fdisk_context *cxt
,size_t n
);
This is faster than fdisk_get_partition()
+ fdisk_partition_is_used()
.
int fdisk_set_partition (struct fdisk_context *cxt
,size_t partno
,struct fdisk_partition *pa
);
Modifies disklabel according to setting with in pa
.
int fdisk_partition_cmp_partno (struct fdisk_partition *a
,struct fdisk_partition *b
);
Compares partitions according to partition number See fdisk_table_sort_partitions()
.
Return: 0 if the same, <0 if b
greater, >0 if a
greater.
int fdisk_partition_cmp_start (struct fdisk_partition *a
,struct fdisk_partition *b
);
Compares partitions according to start offset, See fdisk_table_sort_partitions()
.
Return: 0 if the same, <0 if b
greater, >0 if a
greater.
int fdisk_partition_end_follow_default (struct fdisk_partition *pa
,int enable
);
When pa
used as a template for fdisk_add_partition()
when force label
driver to use all the possible space for the new partition.
fdisk_sector_t
fdisk_partition_get_end (struct fdisk_partition *pa
);
This function may returns absolute non-sense, always check
fdisk_partition_has_end()
.
Note that partition end is defined by fdisk_partition_set_start()
and
fdisk_partition_set_size()
.
int fdisk_partition_get_parent (struct fdisk_partition *pa
,size_t *parent
);
size_t
fdisk_partition_get_partno (struct fdisk_partition *pa
);
The zero is also valid partition number. The function may return random
value when partno is undefined (for example after fdisk_partition_unset_partno()
).
Always use fdisk_partition_has_partno()
to be sure that you work with valid
numbers.
uint64_t
fdisk_partition_get_size (struct fdisk_partition *pa
);
The zero is also valid size. The function may return random undefined
value when size is undefined (for example after fdisk_partition_unset_size()
).
Always use fdisk_partition_has_size()
to be sure that you work with valid
numbers.
uint64_t
fdisk_partition_get_start (struct fdisk_partition *pa
);
The zero is also valid offset. The function may return random undefined
value when start offset is undefined (for example after
fdisk_partition_unset_start()
). Always use fdisk_partition_has_start()
to be
sure that you work with valid numbers.
struct fdisk_parttype *
fdisk_partition_get_type (struct fdisk_partition *pa
);
int fdisk_partition_next_partno (struct fdisk_partition *pa
,struct fdisk_context *cxt
,size_t *n
);
If partno-follow-default (see fdisk_partition_partno_follow_default()
)
enabled then returns next expected partno, otherwise use Ask API to ask user
for the next partno.
int fdisk_partition_partno_follow_default (struct fdisk_partition *pa
,int enable
);
When pa
used as a template for fdisk_add_partition()
when force label driver
to add a new partition to the default (next) position.
int fdisk_partition_set_attrs (struct fdisk_partition *pa
,const char *attrs
);
Sets attrs
to pa
.
Return: 0 on success, <0 on error.
int fdisk_partition_set_name (struct fdisk_partition *pa
,const char *name
);
int fdisk_partition_set_partno (struct fdisk_partition *pa
,size_t num
);
Note that zero is valid partno too. Use fdisk_partition_unset_partno()
to
undefine the partno.
int fdisk_partition_set_size (struct fdisk_partition *pa
,uint64_t sz
);
Note that zero is valid size too. Use fdisk_partition_unset_size()
to
undefine the size.
int fdisk_partition_set_start (struct fdisk_partition *pa
,uint64_t off
);
Note that zero is valid offset too. Use fdisk_partition_unset_start()
to
undefine the offset.
int fdisk_partition_set_type (struct fdisk_partition *pa
,struct fdisk_parttype *type
);
Sets parititon type.
int fdisk_partition_set_uuid (struct fdisk_partition *pa
,const char *uuid
);
int fdisk_partition_size_explicit (struct fdisk_partition *pa
,int enable
);
By default libfdisk aligns the size when add the new partition (by
fdisk_add_partition()
). If you want to disable this functionality use
enable
= 1.
int fdisk_partition_start_follow_default (struct fdisk_partition *pa
,int enable
);
When pa
used as a template for fdisk_add_partition()
when force label driver
to use the first possible space for the new partition.
int
fdisk_partition_start_is_default (struct fdisk_partition *pa
);
int fdisk_partition_to_string (struct fdisk_partition *pa
,struct fdisk_context *cxt
,int id
,char **data
);
Returns info about partition converted to printable string.
For example
1 2 3 4 5 6 7 |
struct fdisk_parition *pa; fdisk_get_partition(cxt, 0, &pa); fdisk_partition_to_string(pa, FDISK_FIELD_UUID, &data); printf("first partition uuid: %s\n", data); free(data); fdisk_unref_partition(pa); |
returns UUID for the first partition.
int
fdisk_partition_unset_partno (struct fdisk_partition *pa
);
Sets the partno as undefined. See fdisk_partition_has_partno()
.
int
fdisk_partition_unset_size (struct fdisk_partition *pa
);
Sets the size as undefined. See fdisk_partition_has_size()
.
int
fdisk_partition_unset_start (struct fdisk_partition *pa
);
Sets the size as undefined. See fdisk_partition_has_start()
.
void
fdisk_ref_partition (struct fdisk_partition *pa
);
Incremparts reference counter.
void
fdisk_reset_partition (struct fdisk_partition *pa
);
Resets partition content.