Top |
The library distinguish between three types of partitioning objects.
on-disk label 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 label 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
used (with fdisk_table) in fdisk scripts
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
Don't forget to inform kernel about changes by fdisk_reread_partition_table()
or more smart fdisk_reread_changes()
.
int fdisk_assign_device (struct fdisk_context *cxt
,const char *fname
,int readonly
);
Open the device, discovery topology, geometry, detect disklabel, check for collisions and switch the current label driver to reflect the probing result.
If in standard mode (!= non-listonly mode) then also detects for collisions.
The result is accessible by fdisk_get_collision()
and
fdisk_is_ptcollision()
. The collision (e.g. old obsolete PT) may be removed
by fdisk_enable_wipe()
. Note that new PT and old PT may be on different
locations.
Note that this function resets all generic setting in context.
If the cxt
is nested context (necessary for example to edit BSD or PMBR)
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_assign_device_by_fd (struct fdisk_context *cxt
,int fd
,const char *fname
,int readonly
);
Like fdisk_assign_device()
, but caller is responsible to open and close the
device. The library only fsync()
the device on fdisk_deassign_device()
.
The device has to be open O_RDWR on readonly
=0.
cxt |
context |
|
fd |
device file descriptor |
|
fname |
path to the device (used for dialogs, debugging, partition names, ...) |
|
readonly |
how to use the device |
Since: 2.35
int fdisk_deassign_device (struct fdisk_context *cxt
,int nosync
);
Call fsync()
, close()
and than sync()
, but for read-only handler close the
device only. If the cxt
is nested context then the request is redirected to
the parent.
int
fdisk_reassign_device (struct fdisk_context *cxt
);
This function is "hard reset" of the context and it does not write anything to the device. All in-memory changes associated with the context will be lost. It's recommended to use this function after some fatal problem when the context (and label specific driver) is in an undefined state.
int
fdisk_device_is_used (struct fdisk_context *cxt
);
The function returns always 0 if the device has not been opened by
fdisk_assign_device()
or if open read-only.
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 can be used 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()
.
int fdisk_disable_dialogs (struct fdisk_context *cxt
,int disable
);
The library uses dialog driven partitioning by default.
Since: 2.31
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.
int fdisk_get_disklabel_item (struct fdisk_context *cxt
,int id
,struct fdisk_labelitem *item
);
Note that id
is always in range 0..N. It's fine to use the function in loop
until it returns error or 2, the result in item
should be ignored when
function returns 1. Don't forget to use fdisk_reset_labelitem()
or fdisk_unref_labelitem()
.
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.
int
fdisk_is_ptcollision (struct fdisk_context *cxt
);
The collision detected by libblkid (usually another partition table). Note
that libfdisk does not support all partitions tables, so fdisk_has_label()
may return false, but fdisk_is_ptcollision()
may return true.
Since: 2.30
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.
int fdisk_reread_changes (struct fdisk_context *cxt
,struct fdisk_table *org
);
Like fdisk_reread_partition_table()
but don't forces kernel re-read all
partition table. The BLKPG_* ioctls are used for individual partitions. The
advantage is that unmodified partitions maybe mounted.
The function behaves like fdisk_reread_partition_table()
on systems where
are no available BLKPG_* ioctls.
int
fdisk_reread_partition_table (struct fdisk_context *cxt
);
Force *kernel* to re-read partition table on block devices.
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.
Note that this function changes only runtime information. It does not update any range in on-disk partition table. For example GPT Header contains First and Last usable LBA fields. These fields are not updated by this function. Be careful.
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.