Table

Table — container for fdisk partitions

Functions

Types and Values

struct fdisk_table

Description

The fdisk_table is simple container for fdisk_partitions. The table is no directly connected to label data (partition table), and table changes don't affect in-memory or on-disk data.

Functions

fdisk_get_freespaces ()

int
fdisk_get_freespaces (struct fdisk_context *cxt,
                      struct fdisk_table **tb);

This function adds freespace (described by fdisk_partition) to table , it allocates a new table if the table points to NULL.

Note that free space smaller than grain (see fdisk_get_grain_size()) is ignored.

Parameters

cxt

fdisk context

 

tb

returns table

 

Returns

0 on success, otherwise, a corresponding error.


fdisk_get_partitions ()

int
fdisk_get_partitions (struct fdisk_context *cxt,
                      struct fdisk_table **tb);

This function adds partitions from disklabel to table , it allocates a new table if if table points to NULL.

Parameters

cxt

fdisk context

 

tb

returns table

 

Returns

0 on success, otherwise, a corresponding error.


fdisk_apply_table ()

int
fdisk_apply_table (struct fdisk_context *cxt,
                   struct fdisk_table *tb);

Add partitions from table tb to the in-memory disk label. See fdisk_add_partition(), fdisk_delete_all_partitions(). The partitions that does not define start (or does not follow the default start) are ignored.

Parameters

cxt

context

 

tb

table

 

Returns

0 on success, <0 on error.


fdisk_new_table ()

struct fdisk_table *
fdisk_new_table (void);

The table is a container for struct fdisk_partition entries. The container does not have any real connection with label (partition table) and with real on-disk data.

Returns

newly allocated table struct.


fdisk_ref_table ()

void
fdisk_ref_table (struct fdisk_table *tb);

Increments reference counter.

Parameters

tb

table pointer

 

fdisk_reset_table ()

int
fdisk_reset_table (struct fdisk_table *tb);

Removes all entries (partitions) from the table. The partitions with zero reference count will be deallocated. This function does not modify partition table.

Parameters

tb

tab pointer

 

Returns

0 on success or negative number in case of error.


fdisk_table_add_partition ()

int
fdisk_table_add_partition (struct fdisk_table *tb,
                           struct fdisk_partition *pa);

Adds a new entry to table and increment pa reference counter. Don't forget to use fdisk_unref_partition() after fdisk_table_add_partition() if you want to keep the pa referenced by the table only.

Parameters

tb

tab pointer

 

pa

new entry

 

Returns

0 on success or negative number in case of error.


fdisk_table_get_nents ()

size_t
fdisk_table_get_nents (struct fdisk_table *tb);

Parameters

tb

pointer to tab

 

Returns

number of entries in table.


fdisk_table_get_partition ()

struct fdisk_partition *
fdisk_table_get_partition (struct fdisk_table *tb,
                           size_t n);

Parameters

tb

tab pointer

 

n

number of entry in table

 

Returns

n-th entry from table or NULL


fdisk_table_get_partition_by_partno ()

struct fdisk_partition *
fdisk_table_get_partition_by_partno (struct fdisk_table *tb,
                                     size_t partno);

Parameters

tb

tab pointer

 

partno

partition number

 

Returns

partition with partno or NULL.


fdisk_table_is_empty ()

int
fdisk_table_is_empty (struct fdisk_table *tb);

Parameters

tb

pointer to tab

 

Returns

1 if the table is without filesystems, or 0.


fdisk_table_next_partition ()

int
fdisk_table_next_partition (struct fdisk_table *tb,
                            struct fdisk_iter *itr,
                            struct fdisk_partition **pa);

Parameters

tb

tab pointer

 

itr

iterator

 

pa

returns the next tab entry

 

Returns

0 on success, negative number in case of error or 1 at the end of list.

Example:

1
2
3
while(fdisk_table_next_partition(tb, itr, &pa) == 0) {
...
}

fdisk_table_remove_partition ()

int
fdisk_table_remove_partition (struct fdisk_table *tb,
                              struct fdisk_partition *pa);

Removes the pa from the table and de-increment reference counter of the pa . The partition with zero reference counter will be deallocated. Don't forget to use fdisk_ref_partition() before call fdisk_table_remove_partition() if you want to use pa later.

Parameters

tb

tab pointer

 

pa

new entry

 

Returns

0 on success or negative number in case of error.


fdisk_table_sort_partitions ()

int
fdisk_table_sort_partitions (struct fdisk_table *tb,
                             int (*cmp) (struct fdisk_partition *, struct fdisk_partition *));

Sort partition in the table.

Parameters

tb

table

 

cmp

compare function

 

Returns

0 on success, <0 on error.


fdisk_table_wrong_order ()

int
fdisk_table_wrong_order (struct fdisk_table *tb);

Parameters

tb

table

 

Returns

1 of the table is not in disk order


fdisk_unref_table ()

void
fdisk_unref_table (struct fdisk_table *tb);

Descrements reference counter, on zero the tb is automatically deallocated.

Parameters

tb

table pointer

 

Types and Values

struct fdisk_table

struct fdisk_table;

Container for fdisk_partition objects