libfdisk: cleanup label geometry API

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2014-08-14 00:09:48 +02:00
parent aa36c2cf2c
commit 72d2965c44
5 changed files with 35 additions and 27 deletions

View File

@ -503,6 +503,7 @@ void change_partition_type(struct fdisk_context *cxt)
void list_disk_geometry(struct fdisk_context *cxt)
{
char *id = NULL;
struct fdisk_label *lb = fdisk_get_label(cxt, NULL);
uint64_t bytes = cxt->total_sectors * cxt->sector_size;
char *strsz = size_to_human_string(SIZE_SUFFIX_SPACE
| SIZE_SUFFIX_3LETTER, bytes);
@ -512,7 +513,7 @@ void list_disk_geometry(struct fdisk_context *cxt)
bytes, (uintmax_t) cxt->total_sectors);
free(strsz);
if (fdisk_require_geometry(cxt) || fdisk_use_cylinders(cxt))
if (fdisk_label_require_geometry(lb) || fdisk_use_cylinders(cxt))
fdisk_info(cxt, _("Geometry: %d heads, %llu sectors/track, %llu cylinders"),
cxt->geom.heads, cxt->geom.sectors, cxt->geom.cylinders);

View File

@ -690,4 +690,22 @@ const char *fdisk_get_devname(struct fdisk_context *cxt)
}
int fdisk_missing_geometry(struct fdisk_context *cxt)
{
int rc;
assert(cxt);
if (!cxt || !cxt->label)
return 0;
rc = (fdisk_label_require_geometry(cxt->label) &&
(!cxt->geom.heads || !cxt->geom.sectors
|| !cxt->geom.cylinders));
if (rc && !fdisk_is_listonly(cxt))
fdisk_warnx(cxt, _("Incomplete geometry setting."));
return rc;
}

View File

@ -380,6 +380,7 @@ struct fdisk_context {
/* context.c */
extern int __fdisk_switch_label(struct fdisk_context *cxt,
struct fdisk_label *lb);
extern int fdisk_missing_geometry(struct fdisk_context *cxt);
/* alignment.c */
sector_t fdisk_scround(struct fdisk_context *cxt, sector_t num);

View File

@ -53,6 +53,19 @@ const char *fdisk_label_get_name(struct fdisk_label *lb)
return lb ? lb->name : NULL;
}
/**
* fdisk_label_require_geometry:
* @lb: label
*
* Returns: 1 if label requires CHS geometry
*/
int fdisk_label_require_geometry(struct fdisk_label *lb)
{
assert(lb);
return lb->flags & FDISK_LABEL_FL_REQUIRE_GEOMETRY ? 1 : 0;
}
/**
* fdisk_write_disklabel:
@ -71,29 +84,6 @@ int fdisk_write_disklabel(struct fdisk_context *cxt)
return cxt->label->op->write(cxt);
}
int fdisk_require_geometry(struct fdisk_context *cxt)
{
assert(cxt);
return cxt->label
&& cxt->label->flags & FDISK_LABEL_FL_REQUIRE_GEOMETRY ? 1 : 0;
}
int fdisk_missing_geometry(struct fdisk_context *cxt)
{
int rc;
assert(cxt);
rc = (fdisk_require_geometry(cxt) &&
(!cxt->geom.heads || !cxt->geom.sectors
|| !cxt->geom.cylinders));
if (rc && !fdisk_is_listonly(cxt))
fdisk_warnx(cxt, _("Incomplete geometry setting."));
return rc;
}
/**
* fdisk_get_fields:

View File

@ -160,9 +160,7 @@ enum {
};
const char *fdisk_label_get_name(struct fdisk_label *lb);
extern int fdisk_require_geometry(struct fdisk_context *cxt);
extern int fdisk_missing_geometry(struct fdisk_context *cxt);
int fdisk_label_require_geometry(struct fdisk_label *lb);
extern int fdisk_write_disklabel(struct fdisk_context *cxt);