Top |
fdisk_sector_t | fdisk_align_lba () |
fdisk_sector_t | fdisk_align_lba_in_range () |
int | fdisk_has_user_device_properties () |
int | fdisk_lba_is_phy_aligned () |
int | fdisk_override_geometry () |
int | fdisk_reset_alignment () |
int | fdisk_reset_device_properties () |
int | fdisk_save_user_geometry () |
int | fdisk_save_user_grain () |
int | fdisk_save_user_sector_size () |
#define | FDISK_ALIGN_DOWN |
#define | FDISK_ALIGN_NEAREST |
#define | FDISK_ALIGN_UP |
typedef | fdisk_sector_t |
The libfdisk aligns the end of the partitions to make it possible to align
the next partition to the "grain" (see fdisk_get_grain_size()
). The grain is
usually 1MiB (or more for devices where optimal I/O is greater than 1MiB).
It means that the library does not align strictly to physical sector size (or minimal or optimal I/O), but it uses greater granularity. It makes partition tables more portable. If you copy disk layout from 512-sector to 4K-sector device, all partitions are still aligned to physical sectors.
This unified concept also makes partition tables more user friendly, all tables look same, LBA of the first partition is 2048 sectors everywhere, etc.
It's recommended to not change any alignment or device properties. All is
initialized by default by fdisk_assign_device()
.
Note that terminology used by libfdisk is:
device properties: I/O limits (topology), geometry, sector size, ...
alignment: first, last LBA, grain, ...
The alignment setting may be modified by disk label driver.
fdisk_sector_t fdisk_align_lba (struct fdisk_context *cxt
,fdisk_sector_t lba
,int direction
);
This function aligns lba
to the "grain" (see fdisk_get_grain_size()
). If the
device uses alignment offset then the result is moved according the offset
to be on the physical boundary.
fdisk_sector_t fdisk_align_lba_in_range (struct fdisk_context *cxt
,fdisk_sector_t lba
,fdisk_sector_t start
,fdisk_sector_t stop
);
Align lba
, the result has to be between start
and stop
int
fdisk_has_user_device_properties (struct fdisk_context *cxt
);
int fdisk_lba_is_phy_aligned (struct fdisk_context *cxt
,fdisk_sector_t lba
);
Check if the lba
is aligned to physical sector boundary.
int fdisk_override_geometry (struct fdisk_context *cxt
,unsigned int cylinders
,unsigned int heads
,unsigned int sectors
);
Overrides auto-discovery. The function fdisk_reset_device_properties()
restores the original setting.
The difference between fdisk_override_geometry()
and fdisk_save_user_geometry()
is that saved user geometry is persistent setting and it's applied always
when device is assigned to the context or device properties are reset.
int
fdisk_reset_alignment (struct fdisk_context *cxt
);
Resets alignment setting to the default and label specific values. This function does not change device properties (I/O limits, geometry etc.).
int
fdisk_reset_device_properties (struct fdisk_context *cxt
);
Resets and discovery topology (I/O limits), geometry, re-read the first
rector on the device if necessary and apply user device setting (geometry
and sector size), then initialize alignment according to label driver (see
fdisk_reset_alignment()
).
You don't have to use this function by default, fdisk_assign_device()
is
smart enough to initialize all necessary setting.
int fdisk_save_user_geometry (struct fdisk_context *cxt
,unsigned int cylinders
,unsigned int heads
,unsigned int sectors
);
Save user defined geometry to use it for partitioning.
The user properties are applied by fdisk_assign_device()
or
fdisk_reset_device_properties()
.
int fdisk_save_user_grain (struct fdisk_context *cxt
,unsigned long grain
);
Save user define grain size. The size is used to align partitions.
The default is 1MiB (or optimal I/O size if greater than 1MiB). It's strongly recommended to use the default.
The smallest possible granularity for partitioning is physical sector size
(or minimal I/O size; the bigger number win). If the user's grain
size is
too small then the smallest possible granularity is used. It means
fdisk_save_user_grain(cxt, 512) forces libfdisk to use grain as small as
possible.
The setting is applied by fdisk_assign_device()
or
fdisk_reset_device_properties()
.
int fdisk_save_user_sector_size (struct fdisk_context *cxt
,unsigned int phy
,unsigned int log
);
Save user defined sector sizes to use it for partitioning.
The user properties are applied by fdisk_assign_device()
or
fdisk_reset_device_properties()
.