#include "fdiskP.h"
+/**
+ * SECTION: alignment
+ * @title: Align LBA
+ * @short_description: function to align partitions and work with disk topology and geometry.
+ */
+
/*
* Alignment according to logical granulity (usually 1MiB)
*/
#include "fdiskP.h"
+
+/**
+ * SECTION: context
+ * @title: libfdisk handler
+ * @short_description: stores infor about device, labels etc.
+ *
+ * Partitioning data:
+ *
+ * on-disk data
+ * The libfdisk reads PT when you assign device to the context, the
+ * function fdisk_write_disklabel() modify on-disk data.
+ *
+ * in-memory data
+ * All data are label specific, but usually stored in the first sector
+ * which is cached in memory and shared between all label drivers (see
+ * labelsection for more details). All label operations are based on
+ * in-memory data.
+ *
+ * struct fdisk_partition
+ * The struct provides abstraction to present partitions to users (for
+ * example to generate human readable info about PT) and it's also unified
+ * way how to define partition template that can be used by label driver to
+ * create a new partition. It's necessary to understand the struct
+ * fdisk_partition is always completely independent object and any change to
+ * the object has no effect to in-memory (or on-disk) label data.
+ */
+
/**
* fdisk_new_context:
*
* @cxt: context
* @name: label name (e.g. "gpt")
*
- * Forces libfdisk to use the label driver.
+ * Forces libfdisk to use the label driver. It's usually bad idea to use this
+ * function, it's better to use fdisk_create_disklabel().
+ *
*
* Returns: 0 on succes, <0 in case of error.
*/
* @cxt: fdisk context
* @l: disklabel type
*
+ * See also fdisk_is_label() macro in libfdisk.h.
+ *
* Returns: return 1 if there is @l disklabel on the device.
*/
int fdisk_is_labeltype(struct fdisk_context *cxt, enum fdisk_labeltype l)
* @fname: path to the device to be handled
* @readonly: how to open the device
*
- * Open the device, discovery topology, geometry, and detect disklabel.
+ * Open the device, discovery topology, geometry, detect disklabel and
+ * switch the current label driver to reflect the probing result.
*
* Returns: 0 on success, < 0 on error.
*/
return -errno;
}
+/**
+ * fdisk_deassign_device:
+ * @cxt: context
+ * @nosync: disable fsync()
+ *
+ * Close device and call fsync()
+ */
int fdisk_deassign_device(struct fdisk_context *cxt, int nosync)
{
assert(cxt);
return 0;
}
+/**
+ * fdisk_is_readonly:
+ * @cxt: context
+ *
+ * Returns: 1 if device open readonly
+ */
int fdisk_is_readonly(struct fdisk_context *cxt)
{
assert(cxt);
#include "fdiskP.h"
-/*
- * Don't use this function derectly
+/**
+ * SECTION: label
+ * @title: Label specific driver
+ * @short_description: label (PT) specific data and functions
+ *
+ * The fdisk_new_context() initializes all label drivers, and allocate
+ * per-label specific data struct. This concept allows to store label specific
+ * settings to the label driver independently on the currently active label
+ * driver.
+ *
+ * Anyway, all label drives share in-memory first sector. The function
+ * fdisk_create_disklabel() overwrites the sector. But it's possible that
+ * label driver also uses another buffers, for example GPT uses more than only
+ * the first sector.
+ *
+ * All label operations are in-memory only, except fdisk_write_disklabel().
+ *
+ * All functions that use "struct fdisk_context" rather than "struct
+ * fdisk_label" use the currently active label driver.
*/
int fdisk_probe_labels(struct fdisk_context *cxt)
{
return 0;
}
+/**
+ * fdisk_label_get_field:
+ * @lb: label
+ * @id: FDISK_FIELD_*
+ *
+ * The field struct describes data stored in struct fdisk_partition. The info
+ * about data is usable for example to generate human readable output (e.g.
+ * fdisk 'p'rint command). See fdisk_partition_to_stirng() and fdisk code.
+ *
+ * Returns: pointer to static instance of the field.
+ */
const struct fdisk_field *fdisk_label_get_field(struct fdisk_label *lb, int id)
{
size_t i;
return NULL;
}
+/**
+ * fdisk_field_get_id:
+ * @field: field instance
+ *
+ * Returns: field Id (FDISK_FIELD_*)
+ */
int fdisk_field_get_id(const struct fdisk_field *field)
{
return field ? field->id : -EINVAL;
}
+/**
+ * fdisk_field_get_name:
+ * @field: field instance
+ *
+ * Returns: field name
+ */
const char *fdisk_field_get_name(const struct fdisk_field *field)
{
return field ? field->name : NULL;
}
+/**
+ * fdisk_field_get_width:
+ * @field: field instance
+ *
+ * Returns: libsmartcols compatible width.
+ */
double fdisk_field_get_width(const struct fdisk_field *field)
{
return field ? field->width : -EINVAL;
}
+/**
+ * fdisk_field_is_number:
+ * @field: field instance
+ *
+ * Returns: 1 if field represent number
+ */
int fdisk_field_is_number(const struct fdisk_field *field)
{
return field->flags ? field->flags & FDISK_FIELDFL_NUMBER : 0;
* fdisk_write_disklabel:
* @cxt: fdisk context
*
- * Write in-memory changes to disk
+ * Write in-memory changes to disk. Be careful!
*
* Returns 0 on success, otherwise, a corresponding error.
*/
* @cxt: fdisk context
* @name: label name
*
- * Creates a new disk label of type @name. If @name is NULL, then it
- * will create a default system label type, either SUN or DOS.
+ * Creates a new disk label of type @name. If @name is NULL, then it will
+ * create a default system label type, either SUN or DOS. The function
+ * automaticaly switches the current label driver to @name. The function
+ * fdisk_get_label() returns the current label driver.
+ *
+ * The function modifies in-memory data only.
*
* Returns 0 on success, otherwise, a corresponding error.
*/
/**
* fdisk_get_disklabel_id:
* @cxt: fdisk context
- * @id: returns pointer to allocated string
+ * @id: returns pointer to allocated string (MBR Id or GPT dirk UUID)
*
* Returns 0 on success, otherwise, a corresponding error.
*/
lb->op->deinit(lb);
}
+/**
+ * fdisk_label_set_changed:
+ * @lb: label
+ * @changed: 0/1
+ *
+ * Marks in-memory data as changed, to force fdisk_write_disklabel() to write
+ * to device. This should be unnecessar by default, the library keeps track
+ * about changes.
+ */
void fdisk_label_set_changed(struct fdisk_label *lb, int changed)
{
assert(lb);
lb->changed = changed ? 1 : 0;
}
+/**
+ * fdisk_label_is_changed:
+ * @lb: label
+ *
+ * Returns: 1 if in-memory data has been changed.
+ */
int fdisk_label_is_changed(struct fdisk_label *lb)
{
assert(lb);
return lb ? lb->changed : 0;
}
+/**
+ * fdisk_label_set_disabled:
+ * @lb: label
+ *
+ * Mark label as disabled, then libfdisk is going to ignore the label when
+ * probe device for labels.
+ */
void fdisk_label_set_disabled(struct fdisk_label *lb, int disabled)
{
assert(lb);
lb->disabled = disabled ? 1 : 0;
}
+/**
+ * fdisk_label_is_disabled:
+ * @lb: label
+ *
+ * Returns: 1 if label driver disabled.
+ */
int fdisk_label_is_disabled(struct fdisk_label *lb)
{
assert(lb);
#include "fdiskP.h"
+/**
+ * fdisk_new_partition:
+ *
+ * Returns: new instance.
+ */
struct fdisk_partition *fdisk_new_partition(void)
{
struct fdisk_partition *pa = calloc(1, sizeof(*pa));
return pa;
}
+/**
+ * fdisk_reset_partition:
+ * @pa: partition
+ *
+ * Resets partition content.
+ */
void fdisk_reset_partition(struct fdisk_partition *pa)
{
int ref;
INIT_LIST_HEAD(&pa->parts);
}
+/**
+ * fdisk_ref_partition:
+ * @tb: partition pointer
+ *
+ * Incremparts reference counter.
+ */
void fdisk_ref_partition(struct fdisk_partition *pa)
{
if (pa)
pa->refcount++;
}
+/**
+ * fdisk_unref_partition:
+ * @tb: partition pointer
+ *
+ * De-incremparts reference counter, on zero the @tb is automatically
+ * deallocated.
+ */
void fdisk_unref_partition(struct fdisk_partition *pa)
{
if (!pa)
return 0;
}
+/**
+ * fdisk_partition_set_start:
+ * @pa: partition
+ * @off: offset in sectors
+ *
+ * Returns: 0 on success, <0 on error.
+ */
int fdisk_partition_set_start(struct fdisk_partition *pa, uint64_t off)
{
if (!pa)
return 0;
}
+/**
+ * fdisk_partition_get_start:
+ * @pa: partition
+ *
+ * Returns: start offset in sectors
+ */
uint64_t fdisk_partition_get_start(struct fdisk_partition *pa)
{
return pa ? pa->start : 0;
}
+/**
+ * fdisk_partition_cmp_start:
+ * @a: partition
+ * @b: partition
+ * See fdisk_sort_table().
+ */
int fdisk_partition_cmp_start(struct fdisk_partition *a,
struct fdisk_partition *b)
{
return a->start - b->start;
}
+/**
+ * fdisk_partition_set_end:
+ * @pa: partition
+ * @off: offset in sectors
+ *
+ * Sets end offset, and zeroize size.
+ *
+ * The usual way is to address end of the partition by fdisk_partition_set_size().
+ *
+ * Returns: 0 on success, <0 on error.
+ */
int fdisk_partition_set_end(struct fdisk_partition *pa, uint64_t off)
{
if (!pa)
return 0;
}
+/**
+ * fdisk_partition_get_start:
+ * @pa: partition
+ *
+ * Returns: start offset in sectors
+ */
uint64_t fdisk_partition_get_end(struct fdisk_partition *pa)
{
return pa ? pa->end : 0;
}
-
+/**
+ * fdisk_partition_set_size
+ * @pa: partition
+ * @size: in bytes
+ *
+ * Sets size, zeroize end offset. See also fdisk_partition_set_end().
+ *
+ * Returns: 0 on success, <0 on error.
+ */
int fdisk_partition_set_size(struct fdisk_partition *pa, uint64_t size)
{
if (!pa)
return 0;
}
+/**
+ * fdisk_partition_get_start:
+ * @pa: partition
+ *
+ * Returns: size in sectors
+ */
uint64_t fdisk_partition_get_size(struct fdisk_partition *pa)
{
return pa ? pa->size : 0;
}
+/**
+ * fdisk_partition_set_partno
+ * @pa: partition
+ * @n: partitiion number
+ *
+ * When @pa used as a tempalate for fdisk_add_partition() when infor label driver
+ * about wanted partition position.
+ *
+ * Returns: 0 on success, <0 on error.
+ */
int fdisk_partition_set_partno(struct fdisk_partition *pa, size_t n)
{
if (!pa)
return 0;
}
+/**
+ * fdisk_partition_partno_follow_default
+ * @pa: partition
+ * @enable: 0|1
+ *
+ * When @pa used as a tempalate for fdisk_add_partition() when force label driver
+ * to add a new partition to the default (next) position.
+ *
+ * Returns: 0 on success, <0 on error.
+ */
int fdisk_partition_partno_follow_default(struct fdisk_partition *pa, int enable)
{
if (!pa)
return 0;
}
+/**
+ * fdisk_partition_start_follow_default
+ * @pa: partition
+ * @enable: 0|1
+ *
+ * When @pa used as a tempalate for fdisk_add_partition() when force label driver
+ * to use the first possible space for the new partition.
+ *
+ * Returns: 0 on success, <0 on error.
+ */
int fdisk_partition_start_follow_default(struct fdisk_partition *pa, int enable)
{
if (!pa)
return 0;
}
+/**
+ * fdisk_partition_start_follow_default
+ * @pa: partition
+ * @enable: 0|1
+ *
+ * When @pa used as a tempalate for fdisk_add_partition() when force label driver
+ * to use all the possible space for the new partition.
+ *
+ * Returns: 0 on success, <0 on error.
+ */
int fdisk_partition_end_follow_default(struct fdisk_partition *pa, int enable)
{
if (!pa)
* @tb: table pointer
*
* De-incremparts reference counter, on zero the @tb is automatically
- * deallocated by fdisk_free_table().
+ * deallocated.
*/
void fdisk_unref_table(struct fdisk_table *tb)
{
return cmp(pa, pb);
}
+/**
+ * fdisk_table_sort_partitions:
+ * @tb: table
+ * @cmp: compare function
+ *
+ * Sort partition in the table.
+ */
int fdisk_table_sort_partitions(struct fdisk_table *tb,
int (*cmp)(struct fdisk_partition *,
struct fdisk_partition *))
* 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_topology_get_grain()) is
- * ignored.
+ * Note that free space smaller than grain (see fdisk_get_grain()) is ignored.
* Returns 0 on success, otherwise, a corresponding error.
*/