libfdisk: clean up API (alignment.c)
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
6a6321360d
commit
8d605c884a
|
@ -625,9 +625,11 @@ void list_disklabel(struct fdisk_context *cxt)
|
|||
fputc('\n', stdout);
|
||||
|
||||
/* print warnings */
|
||||
while (itr && fdisk_table_next_partition(tb, itr, &pa) == 0)
|
||||
fdisk_warn_alignment(cxt, fdisk_partition_get_start(pa),
|
||||
while (itr && fdisk_table_next_partition(tb, itr, &pa) == 0) {
|
||||
if (!fdisk_lba_is_phy_aligned(cxt, fdisk_partition_get_start(pa)))
|
||||
fdisk_warnx(cxt, _("Partition %zu does not start on physical sector boundary."),
|
||||
fdisk_partition_get_partno(pa) + 1);
|
||||
}
|
||||
|
||||
if (fdisk_table_wrong_order(tb))
|
||||
fdisk_info(cxt, _("Partition table entries are not in disk order."));
|
||||
|
|
|
@ -32,8 +32,13 @@ static int lba_is_phy_aligned(struct fdisk_context *cxt, sector_t lba)
|
|||
return !((granularity + cxt->alignment_offset - offset) & (granularity - 1));
|
||||
}
|
||||
|
||||
/*
|
||||
* Align @lba in @direction FDISK_ALIGN_{UP,DOWN,NEAREST}
|
||||
/**
|
||||
* fdisk_align_lba:
|
||||
* @cxt: context
|
||||
* @lba: address to align
|
||||
* @direction: FDISK_ALIGN_{UP,DOWN,NEAREST}
|
||||
*
|
||||
* Returns: alignment LBA.
|
||||
*/
|
||||
sector_t fdisk_align_lba(struct fdisk_context *cxt, sector_t lba, int direction)
|
||||
{
|
||||
|
@ -81,8 +86,16 @@ sector_t fdisk_align_lba(struct fdisk_context *cxt, sector_t lba, int direction)
|
|||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* fdisk_align_lba_in_range:
|
||||
* @cxt: context
|
||||
* @lba: LBA
|
||||
* @start: range start
|
||||
* @stop: range stop
|
||||
*
|
||||
* Align @lba, the result has to be between @start and @stop
|
||||
*
|
||||
* Returns: aligned LBA
|
||||
*/
|
||||
sector_t fdisk_align_lba_in_range(struct fdisk_context *cxt,
|
||||
sector_t lba, sector_t start, sector_t stop)
|
||||
|
@ -98,15 +111,18 @@ sector_t fdisk_align_lba_in_range(struct fdisk_context *cxt,
|
|||
return lba;
|
||||
}
|
||||
|
||||
/*
|
||||
* Print warning if the partition @lba (start of the @partition) is not
|
||||
* aligned to physical sector boundary.
|
||||
/**
|
||||
* fdisk_lba_is_phy_aligned:
|
||||
* @cxt: context
|
||||
* @lba: LBA to check
|
||||
*
|
||||
* Check if the @lba is aligned.
|
||||
*
|
||||
* Returns: 1 if aligned.
|
||||
*/
|
||||
void fdisk_warn_alignment(struct fdisk_context *cxt, sector_t lba, int partition)
|
||||
int fdisk_lba_is_phy_aligned(struct fdisk_context *cxt, sector_t lba)
|
||||
{
|
||||
if (!lba_is_phy_aligned(cxt, lba))
|
||||
fdisk_warnx(cxt, _("Partition %i does not start on physical sector boundary.\n"),
|
||||
partition + 1);
|
||||
return lba_is_phy_aligned(cxt, lba);
|
||||
}
|
||||
|
||||
static unsigned long get_sector_size(int fd)
|
||||
|
@ -168,6 +184,17 @@ int fdisk_override_geometry(struct fdisk_context *cxt,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* fdisk_save_user_geometry:
|
||||
* @cxt: context
|
||||
* @cylinders: C
|
||||
* @head: H
|
||||
* @sector: S
|
||||
*
|
||||
* Save user defined geometry to use it for partitioning.
|
||||
*
|
||||
* Returns: <0 on error, 0 on success.
|
||||
*/
|
||||
int fdisk_save_user_geometry(struct fdisk_context *cxt,
|
||||
unsigned int cylinders,
|
||||
unsigned int heads,
|
||||
|
@ -191,6 +218,16 @@ int fdisk_save_user_geometry(struct fdisk_context *cxt,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* fdisk_save_user_sector_size:
|
||||
* @cxt: context
|
||||
* @phy: physical sector size
|
||||
* @log: logicla sector size
|
||||
*
|
||||
* Save user defined sector sizes to use it for partitioning.
|
||||
*
|
||||
* Returns: <0 on error, 0 on success.
|
||||
*/
|
||||
int fdisk_save_user_sector_size(struct fdisk_context *cxt,
|
||||
unsigned int phy,
|
||||
unsigned int log)
|
||||
|
@ -206,6 +243,12 @@ int fdisk_save_user_sector_size(struct fdisk_context *cxt,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* fdisk_has_user_device_properties:
|
||||
* @cxt: context
|
||||
*
|
||||
* Returns: 1 if user specified any properties
|
||||
*/
|
||||
int fdisk_has_user_device_properties(struct fdisk_context *cxt)
|
||||
{
|
||||
return (cxt->user_pyh_sector
|
||||
|
@ -391,7 +434,7 @@ static int has_topology(struct fdisk_context *cxt)
|
|||
*
|
||||
* Returns: 0 on error or number of logical sectors.
|
||||
*/
|
||||
sector_t fdisk_topology_get_first_lba(struct fdisk_context *cxt)
|
||||
static sector_t topology_get_first_lba(struct fdisk_context *cxt)
|
||||
{
|
||||
sector_t x = 0, res;
|
||||
|
||||
|
@ -437,7 +480,7 @@ sector_t fdisk_topology_get_first_lba(struct fdisk_context *cxt)
|
|||
*
|
||||
* Returns: 0 on error or number of bytes.
|
||||
*/
|
||||
unsigned long fdisk_topology_get_grain(struct fdisk_context *cxt)
|
||||
static unsigned long topology_get_grain(struct fdisk_context *cxt)
|
||||
{
|
||||
unsigned long res;
|
||||
|
||||
|
@ -478,8 +521,8 @@ int fdisk_reset_alignment(struct fdisk_context *cxt)
|
|||
DBG(CXT, ul_debugobj(cxt, "reseting alignment..."));
|
||||
|
||||
/* default */
|
||||
cxt->grain = fdisk_topology_get_grain(cxt);
|
||||
cxt->first_lba = fdisk_topology_get_first_lba(cxt);
|
||||
cxt->grain = topology_get_grain(cxt);
|
||||
cxt->first_lba = topology_get_first_lba(cxt);
|
||||
cxt->last_lba = cxt->total_sectors - 1;
|
||||
|
||||
/* overwrite default by label stuff */
|
||||
|
@ -506,6 +549,12 @@ sector_t fdisk_cround(struct fdisk_context *cxt, sector_t num)
|
|||
(num / fdisk_get_units_per_sector(cxt)) + 1 : num;
|
||||
}
|
||||
|
||||
/**
|
||||
* fdisk_reread_partition_table:
|
||||
* @cxt: context
|
||||
*
|
||||
* Force *system kernel* to re-read partition table.
|
||||
*/
|
||||
int fdisk_reread_partition_table(struct fdisk_context *cxt)
|
||||
{
|
||||
int i;
|
||||
|
|
|
@ -637,7 +637,7 @@ unsigned long fdisk_get_grain_size(struct fdisk_context *cxt)
|
|||
*
|
||||
* Returns: first possible LBA on disk for data partitions.
|
||||
*/
|
||||
unsigned long fdisk_get_first_lba(struct fdisk_context *cxt)
|
||||
sector_t fdisk_get_first_lba(struct fdisk_context *cxt)
|
||||
{
|
||||
assert(cxt);
|
||||
return cxt->first_lba;
|
||||
|
@ -649,7 +649,7 @@ unsigned long fdisk_get_first_lba(struct fdisk_context *cxt)
|
|||
*
|
||||
* Returns: size of the device in (real) sectors.
|
||||
*/
|
||||
unsigned long fdisk_get_nsectors(struct fdisk_context *cxt)
|
||||
sector_t fdisk_get_nsectors(struct fdisk_context *cxt)
|
||||
{
|
||||
assert(cxt);
|
||||
return cxt->total_sectors;
|
||||
|
|
|
@ -1274,7 +1274,6 @@ static int dos_verify_disklabel(struct fdisk_context *cxt)
|
|||
p = self_partition(cxt, i);
|
||||
if (is_used_partition(p) && !IS_EXTENDED(p->sys_ind)) {
|
||||
check_consistency(cxt, p, i);
|
||||
fdisk_warn_alignment(cxt, get_abs_partition_start(pe), i);
|
||||
if (get_abs_partition_start(pe) < first[i])
|
||||
fdisk_warnx(cxt, _(
|
||||
"Partition %zu: bad start-of-data."),
|
||||
|
|
|
@ -64,9 +64,6 @@ extern int fdisk_run_test(struct fdisk_test *tests, int argc, char *argv[]);
|
|||
#endif
|
||||
|
||||
|
||||
typedef unsigned long long sector_t;
|
||||
|
||||
|
||||
/*
|
||||
* Generic iterator
|
||||
*/
|
||||
|
@ -385,28 +382,9 @@ extern int __fdisk_switch_label(struct fdisk_context *cxt,
|
|||
struct fdisk_label *lb);
|
||||
|
||||
/* alignment.c */
|
||||
extern sector_t fdisk_scround(struct fdisk_context *cxt, sector_t num);
|
||||
extern sector_t fdisk_cround(struct fdisk_context *cxt, sector_t num);
|
||||
|
||||
extern sector_t fdisk_topology_get_first_lba(struct fdisk_context *cxt);
|
||||
extern unsigned long fdisk_topology_get_grain(struct fdisk_context *cxt);
|
||||
|
||||
extern void fdisk_warn_alignment(struct fdisk_context *cxt,
|
||||
sector_t lba, int partition);
|
||||
|
||||
|
||||
#define FDISK_ALIGN_UP 1
|
||||
#define FDISK_ALIGN_DOWN 2
|
||||
#define FDISK_ALIGN_NEAREST 3
|
||||
|
||||
extern sector_t fdisk_align_lba(struct fdisk_context *cxt, sector_t lba, int direction);
|
||||
extern sector_t fdisk_align_lba_in_range(struct fdisk_context *cxt, sector_t lba,
|
||||
sector_t start, sector_t stop);
|
||||
|
||||
|
||||
extern int fdisk_override_geometry(struct fdisk_context *cxt,
|
||||
unsigned int cylinders, unsigned int heads,
|
||||
unsigned int sectors);
|
||||
sector_t fdisk_scround(struct fdisk_context *cxt, sector_t num);
|
||||
sector_t fdisk_cround(struct fdisk_context *cxt, sector_t num);
|
||||
int fdisk_reset_device_properties(struct fdisk_context *cxt);
|
||||
|
||||
extern int fdisk_discover_geometry(struct fdisk_context *cxt);
|
||||
extern int fdisk_discover_topology(struct fdisk_context *cxt);
|
||||
|
|
|
@ -37,6 +37,8 @@ struct fdisk_iter;
|
|||
struct fdisk_table;
|
||||
struct fdisk_field;
|
||||
|
||||
typedef unsigned long long sector_t;
|
||||
|
||||
/*
|
||||
* Supported partition table types (labels)
|
||||
*/
|
||||
|
@ -109,8 +111,8 @@ unsigned long fdisk_get_physector_size(struct fdisk_context *cxt);
|
|||
unsigned long fdisk_get_sector_size(struct fdisk_context *cxt);
|
||||
unsigned long fdisk_get_alignment_offset(struct fdisk_context *cxt);
|
||||
unsigned long fdisk_get_grain_size(struct fdisk_context *cxt);
|
||||
unsigned long fdisk_get_first_lba(struct fdisk_context *cxt);
|
||||
unsigned long fdisk_get_nsectors(struct fdisk_context *cxt);
|
||||
sector_t fdisk_get_first_lba(struct fdisk_context *cxt);
|
||||
sector_t fdisk_get_nsectors(struct fdisk_context *cxt);
|
||||
const char *fdisk_get_devname(struct fdisk_context *cxt);
|
||||
|
||||
/* parttype.c */
|
||||
|
@ -275,21 +277,29 @@ extern struct fdisk_partition *fdisk_table_get_partition(
|
|||
size_t n);
|
||||
|
||||
/* alignment.c */
|
||||
extern int fdisk_reset_alignment(struct fdisk_context *cxt);
|
||||
extern int fdisk_reset_device_properties(struct fdisk_context *cxt);
|
||||
#define FDISK_ALIGN_UP 1
|
||||
#define FDISK_ALIGN_DOWN 2
|
||||
#define FDISK_ALIGN_NEAREST 3
|
||||
|
||||
extern int fdisk_save_user_geometry(struct fdisk_context *cxt,
|
||||
sector_t fdisk_align_lba(struct fdisk_context *cxt, sector_t lba, int direction);
|
||||
sector_t fdisk_align_lba_in_range(struct fdisk_context *cxt,
|
||||
sector_t lba, sector_t start, sector_t stop);
|
||||
int fdisk_lba_is_phy_aligned(struct fdisk_context *cxt, sector_t lba);
|
||||
|
||||
int fdisk_override_geometry(struct fdisk_context *cxt,
|
||||
unsigned int cylinders,
|
||||
unsigned int heads,
|
||||
unsigned int sectors);
|
||||
|
||||
extern int fdisk_save_user_sector_size(struct fdisk_context *cxt,
|
||||
int fdisk_save_user_geometry(struct fdisk_context *cxt,
|
||||
unsigned int cylinders,
|
||||
unsigned int heads,
|
||||
unsigned int sectors);
|
||||
int fdisk_save_user_sector_size(struct fdisk_context *cxt,
|
||||
unsigned int phy,
|
||||
unsigned int log);
|
||||
|
||||
extern int fdisk_has_user_device_properties(struct fdisk_context *cxt);
|
||||
|
||||
extern int fdisk_reread_partition_table(struct fdisk_context *cxt);
|
||||
int fdisk_has_user_device_properties(struct fdisk_context *cxt);
|
||||
int fdisk_reset_alignment(struct fdisk_context *cxt);
|
||||
int fdisk_reread_partition_table(struct fdisk_context *cxt);
|
||||
|
||||
/* iter.c */
|
||||
enum {
|
||||
|
|
Loading…
Reference in New Issue