libfdisk: use context geometry in SGI and SUN

* don't call HDIO_GETGEO ioctls in the drivers
 * use context geometry (so user can overwrite it by -C/H/S options)
 * use default geometry is ioctl does not return anything

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2013-09-25 15:34:34 +02:00
parent 15c755975b
commit e5b5a349cd
2 changed files with 30 additions and 47 deletions

View File

@ -952,41 +952,32 @@ static int sgi_create_disklabel(struct fdisk_context *cxt)
{ {
struct fdisk_sgi_label *sgi; struct fdisk_sgi_label *sgi;
struct sgi_disklabel *sgilabel; struct sgi_disklabel *sgilabel;
struct hd_geometry geometry;
sector_t llsectors;
int res; /* the result from the ioctl */
int sec_fac; /* the sector factor */
assert(cxt); assert(cxt);
assert(cxt->label); assert(cxt->label);
assert(fdisk_is_disklabel(cxt, SGI)); assert(fdisk_is_disklabel(cxt, SGI));
sec_fac = cxt->sector_size / 512; /* determine the sector factor */
res = blkdev_get_sectors(cxt->dev_fd, &llsectors);
#ifdef HDIO_GETGEO #ifdef HDIO_GETGEO
/* TODO: it seems unnecessary, geometry is already set in the context */ if (cxt->geom.heads && cxt->geom.sectors) {
if (ioctl(cxt->dev_fd, HDIO_GETGEO, &geometry) < 0) { sector_t llsectors;
fdisk_warn(cxt, _("HDIO_GETGEO ioctl failed on %s"), cxt->dev_path);
return -1; if (blkdev_get_sectors(cxt->dev_fd, &llsectors) == 0) {
} /* the get device size ioctl was successful */
cxt->geom.heads = geometry.heads; sector_t llcyls;
cxt->geom.sectors = geometry.sectors; int sec_fac = cxt->sector_size / 512;
if (res == 0) {
/* the get device size ioctl was successful */ llcyls = llsectors / (cxt->geom.heads * cxt->geom.sectors * sec_fac);
sector_t llcyls; cxt->geom.cylinders = llcyls;
llcyls = llsectors / (cxt->geom.heads * cxt->geom.sectors * sec_fac); if (cxt->geom.cylinders != llcyls) /* truncated? */
cxt->geom.cylinders = llcyls; cxt->geom.cylinders = ~0;
if (cxt->geom.cylinders != llcyls) /* truncated? */ } else {
cxt->geom.cylinders = ~0; /* otherwise print error and use truncated version */
} else { fdisk_warnx(cxt,
/* otherwise print error and use truncated version */ _("Warning: BLKGETSIZE ioctl failed on %s. "
cxt->geom.cylinders = geometry.cylinders; "Using geometry cylinder value of %llu."
fdisk_warnx(cxt, "This value may be truncated for devices"
_("Warning: BLKGETSIZE ioctl failed on %s. " " > 33.8 GB."), cxt->dev_path, cxt->geom.cylinders);
"Using geometry cylinder value of %llu." }
"This value may be truncated for devices"
" > 33.8 GB."), cxt->dev_path, cxt->geom.cylinders);
} }
#endif #endif
fdisk_zeroize_firstsector(cxt); fdisk_zeroize_firstsector(cxt);
@ -1007,14 +998,14 @@ static int sgi_create_disklabel(struct fdisk_context *cxt)
sgilabel->devparam.gap1 = (0); sgilabel->devparam.gap1 = (0);
sgilabel->devparam.gap2 = (0); sgilabel->devparam.gap2 = (0);
sgilabel->devparam.sparecyl = (0); sgilabel->devparam.sparecyl = (0);
sgilabel->devparam.pcylcount = cpu_to_be16(geometry.cylinders); sgilabel->devparam.pcylcount = cpu_to_be16(cxt->geom.cylinders);
sgilabel->devparam.head_vol0 = cpu_to_be16(0); sgilabel->devparam.head_vol0 = cpu_to_be16(0);
sgilabel->devparam.ntrks = cpu_to_be16(geometry.heads); sgilabel->devparam.ntrks = cpu_to_be16(cxt->geom.heads);
/* tracks/cylinder (heads) */ /* tracks/cylinder (heads) */
sgilabel->devparam.cmd_tag_queue_depth = (0); sgilabel->devparam.cmd_tag_queue_depth = (0);
sgilabel->devparam.unused0 = (0); sgilabel->devparam.unused0 = (0);
sgilabel->devparam.unused1 = cpu_to_be16(0); sgilabel->devparam.unused1 = cpu_to_be16(0);
sgilabel->devparam.nsect = cpu_to_be16(geometry.sectors); sgilabel->devparam.nsect = cpu_to_be16(cxt->geom.sectors);
/* sectors/track */ /* sectors/track */
sgilabel->devparam.bytes = cpu_to_be16(cxt->sector_size); sgilabel->devparam.bytes = cpu_to_be16(cxt->sector_size);
sgilabel->devparam.ilfact = cpu_to_be16(1); sgilabel->devparam.ilfact = cpu_to_be16(1);

View File

@ -190,11 +190,7 @@ static void ask_geom(struct fdisk_context *cxt)
static int sun_create_disklabel(struct fdisk_context *cxt) static int sun_create_disklabel(struct fdisk_context *cxt)
{ {
struct hd_geometry geometry; unsigned int ndiv;
sector_t llsectors, llcyls;
unsigned int ndiv, sec_fac;
int res;
struct fdisk_sun_label *sun; /* libfdisk sun handler */ struct fdisk_sun_label *sun; /* libfdisk sun handler */
struct sun_disklabel *sunlabel; /* on disk data */ struct sun_disklabel *sunlabel; /* on disk data */
@ -216,23 +212,19 @@ static int sun_create_disklabel(struct fdisk_context *cxt)
sunlabel->vtoc.sanity = cpu_to_be32(SUN_VTOC_SANITY); sunlabel->vtoc.sanity = cpu_to_be32(SUN_VTOC_SANITY);
sunlabel->vtoc.nparts = cpu_to_be16(SUN_MAXPARTITIONS); sunlabel->vtoc.nparts = cpu_to_be16(SUN_MAXPARTITIONS);
res = blkdev_get_sectors(cxt->dev_fd, &llsectors);
sec_fac = cxt->sector_size / 512;
#ifdef HDIO_GETGEO #ifdef HDIO_GETGEO
if (ioctl(cxt->dev_fd, HDIO_GETGEO, &geometry) == 0 if (cxt->geom.heads && cxt->geom.sectors) {
&& geometry.heads sector_t llsectors;
&& geometry.sectors) {
if (blkdev_get_sectors(cxt->dev_fd, &llsectors) == 0) {
int sec_fac = cxt->sector_size / 512;
sector_t llcyls;
cxt->geom.heads = geometry.heads;
cxt->geom.sectors = geometry.sectors;
if (res == 0) {
llcyls = llsectors / (cxt->geom.heads * cxt->geom.sectors * sec_fac); llcyls = llsectors / (cxt->geom.heads * cxt->geom.sectors * sec_fac);
cxt->geom.cylinders = llcyls; cxt->geom.cylinders = llcyls;
if (cxt->geom.cylinders != llcyls) if (cxt->geom.cylinders != llcyls)
cxt->geom.cylinders = ~0; cxt->geom.cylinders = ~0;
} else { } else {
cxt->geom.cylinders = geometry.cylinders;
fdisk_warnx(cxt, fdisk_warnx(cxt,
_("BLKGETSIZE ioctl failed on %s. " _("BLKGETSIZE ioctl failed on %s. "
"Using geometry cylinder value of %llu. " "Using geometry cylinder value of %llu. "