Top |
The library distinguish between three types of partitioning objects.
on-disk data
disk label specific
probed and read by disklabel drivers when assign device to the context or when switch to another disk label type
only fdisk_write_disklabel()
modify on-disk data
in-memory data
generic data and disklabel specific data stored in struct fdisk_label
all partitioning operations are based on in-memory data only
struct fdisk_partition
provides abstraction to present partitions to users
fdisk_partition is possible to gather to fdisk_table container
used as unified template for new partitions
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
int fdisk_assign_device (struct fdisk_context *cxt
,const char *fname
,int readonly
);
Open the device, discovery topology, geometry, detect disklabel and switch the current label driver to reflect the probing result.
Note that this function resets all generic setting in context. If the cxt
is nested context then the device is assigned to the parental context and
necessary properties are copied to the cxt
. The change is propagated in
child->parent direction only. It's impossible to use a different device for
primary and nested contexts.
int fdisk_deassign_device (struct fdisk_context *cxt
,int nosync
);
Close device and call fsync()
. If the cxt
is nested context than the
request is redirected to the parent.
int fdisk_enable_bootbits_protection (struct fdisk_context *cxt
,int enable
);
The library zeroizes all the first sector when create a new disk label by default. This function allows to control this behavior. For now it's supported for MBR and GPT.
int fdisk_enable_details (struct fdisk_context *cxt
,int enable
);
Enables or disables "details" display mode. This function has effect to
fdisk_partition_to_string()
function.
int fdisk_enable_listonly (struct fdisk_context *cxt
,int enable
);
Just list partition only, don't care about another details, mistakes, ...
int fdisk_enable_wipe (struct fdisk_context *cxt
,int enable
);
The library removes all PT/filesystem/RAID signatures before it writes partition table. The probing area where it looks for signatures is from the begin of the disk. The device is wiped by libblkid.
See also fdisk_wipe_partition()
.
unsigned long
fdisk_get_alignment_offset (struct fdisk_context *cxt
);
The alignment offset is offset between logical and physical sectors. For backward compatibility the first logical sector on 4K disks does no have to start on the same place like physical sectors.
fdisk_sector_t
fdisk_get_last_lba (struct fdisk_context *cxt
);
Note that the device has to be already assigned.
unsigned long
fdisk_get_optimal_iosize (struct fdisk_context *cxt
);
The optimal I/O is optional and does not have to be provided by device, anyway libfdisk never returns zero. If the optimal I/O size is not provided then libfdisk returns minimal I/O size or sector size.
int
fdisk_get_size_unit (struct fdisk_context *cxt
);
Gets unit for SIZE output field (see fdisk_partition_to_string()
).
unsigned int
fdisk_get_units_per_sector (struct fdisk_context *cxt
);
This is necessary only for brain dead situations when we use "cylinders";
int
fdisk_has_wipe (struct fdisk_context *cxt
);
Returns the current wipe setting. See fdisk_enable_wipe()
.
int fdisk_is_labeltype (struct fdisk_context *cxt
,enum fdisk_labeltype id
);
See also fdisk_is_label()
macro in libfdisk.h.
struct fdisk_context * fdisk_new_nested_context (struct fdisk_context *parent
,const char *name
);
Create a new nested fdisk context for nested disk labels (e.g. BSD or PMBR). The function also probes for the nested label on the device if device is already assigned to parent.
The new context is initialized according to parent
and both context shares
some settings and file descriptor to the device. The child propagate some
changes (like fdisk_assign_device()
) to parent, but it does not work
vice-versa. The behavior is undefined if you assign another device to
parent.
void
fdisk_ref_context (struct fdisk_context *cxt
);
Increments reference counter.
fdisk_sector_t fdisk_set_first_lba (struct fdisk_context *cxt
,fdisk_sector_t lba
);
It's strongly recommended to use the default library setting. The first LBA
is always reset by fdisk_assign_device()
, fdisk_override_geometry()
and fdisk_reset_alignment()
. This is very low level function and library
does not check if your setting makes any sense.
This function is necessary only when you want to work with very unusual partition tables like GPT protective MBR or hybrid partition tables on bootable media where the first partition may start on very crazy offsets.
fdisk_sector_t fdisk_set_last_lba (struct fdisk_context *cxt
,fdisk_sector_t lba
);
It's strongly recommended to use the default library setting. The last LBA
is always reset by fdisk_assign_device()
, fdisk_override_geometry()
and
fdisk_reset_alignment()
.
The default is number of sectors on the device, but maybe modified by the current disklabel driver (for example GPT uses the end of disk for backup header, so last_lba is smaller than total number of sectors).
int fdisk_set_size_unit (struct fdisk_context *cxt
,int unit
);
Sets unit for SIZE output field (see fdisk_partition_to_string()
).
int fdisk_set_unit (struct fdisk_context *cxt
,const char *str
);
This is pure shit, unfortunately for example Sun addresses begin of the partition by cylinders...
void
fdisk_unref_context (struct fdisk_context *cxt
);
Deallocates context struct.