libfdisk: add info about display units to context
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
parent
b3d212f83f
commit
cb7ce873a5
|
@ -201,3 +201,58 @@ int fdisk_context_set_ask(struct fdisk_context *cxt,
|
|||
cxt->ask_data = data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @str: "cylinder" or "sector".
|
||||
*
|
||||
* This is pure shit, unfortunately for example Sun addresses begin of the
|
||||
* partition by cylinders...
|
||||
*/
|
||||
int fdisk_context_set_unit(struct fdisk_context *cxt, const char *str)
|
||||
{
|
||||
assert(cxt);
|
||||
|
||||
cxt->display_in_cyl_units = 0;
|
||||
|
||||
if (!str)
|
||||
return 0;
|
||||
|
||||
if (strcmp(str, "cylinder") == 0 || strcmp(str, "cylinders") == 0)
|
||||
cxt->display_in_cyl_units = 1;
|
||||
|
||||
else if (strcmp(str, "sector") == 0 || strcmp(str, "sectors") == 0)
|
||||
cxt->display_in_cyl_units = 0;
|
||||
|
||||
DBG(CONTEXT, dbgprint("display unit: %s", fdisk_context_get_unit(cxt, 0)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *fdisk_context_get_unit(struct fdisk_context *cxt, int n)
|
||||
{
|
||||
assert(cxt);
|
||||
|
||||
if (fdisk_context_use_cylinders(cxt))
|
||||
return P_("cylinder", "cylinders", n);
|
||||
return P_("sector", "sectors", n);
|
||||
}
|
||||
|
||||
/* Returns 1 if user wants to display in cylinders. */
|
||||
int fdisk_context_use_cylinders(struct fdisk_context *cxt)
|
||||
{
|
||||
assert(cxt);
|
||||
return cxt->display_in_cyl_units == 1;
|
||||
}
|
||||
|
||||
/* Returns number of "units" per sector, default is 1 if display unit is sector.
|
||||
*/
|
||||
unsigned int fdisk_context_get_units_per_sector(struct fdisk_context *cxt)
|
||||
{
|
||||
assert(cxt);
|
||||
|
||||
if (fdisk_context_use_cylinders(cxt)) {
|
||||
assert(cxt->geom.heads);
|
||||
return cxt->geom.heads * cxt->geom.sectors;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
|
@ -254,6 +254,8 @@ struct fdisk_context {
|
|||
unsigned long sector_size; /* logical size */
|
||||
unsigned long alignment_offset;
|
||||
|
||||
int display_in_cyl_units; /* for obscure labels */
|
||||
|
||||
/* alignment */
|
||||
unsigned long grain; /* alignment unit */
|
||||
sector_t first_lba; /* recommended begin of the first partition */
|
||||
|
|
|
@ -82,6 +82,11 @@ extern struct fdisk_label *fdisk_context_get_label(struct fdisk_context *cxt,
|
|||
extern int fdisk_context_switch_label(struct fdisk_context *cxt,
|
||||
const char *name);
|
||||
|
||||
extern int fdisk_context_set_unit(struct fdisk_context *cxt, const char *str);
|
||||
extern const char *fdisk_context_get_unit(struct fdisk_context *cxt, int n);
|
||||
extern int fdisk_context_use_cylinders(struct fdisk_context *cxt);
|
||||
extern unsigned int fdisk_context_get_units_per_sector(struct fdisk_context *cxt);
|
||||
|
||||
/* parttype.c */
|
||||
extern struct fdisk_parttype *fdisk_get_parttype_from_code(struct fdisk_context *cxt,
|
||||
unsigned int code);
|
||||
|
|
Loading…
Reference in New Issue