From: Einar Lueck <elelu...@de.ibm.com> This patch uses ioctl HDIO_GETGEO to guess geometry of a disk in case nothing is specified explicitly.
Signed-off-by: Einar Lueck <elelu...@de.ibm.com> Signed-off-by: Christian Borntraeger <borntrae...@de.ibm.com> --- block.c | 12 ++++++++++++ 1 files changed, 12 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index fe74ddd..8af4d19 100644 --- a/block.c +++ b/block.c @@ -32,6 +32,10 @@ #include "qmp-commands.h" #include "qemu-timer.h" +#ifdef __linux__ +#include <linux/hdreg.h> +#endif + #ifdef CONFIG_BSD #include <sys/types.h> #include <sys/stat.h> @@ -2054,6 +2058,7 @@ void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *pse int translation, lba_detected = 0; int cylinders, heads, secs; uint64_t nb_sectors; + struct hd_geometry geo; /* if a geometry hint is available, use it */ bdrv_get_geometry(bs, &nb_sectors); @@ -2063,6 +2068,13 @@ void bdrv_guess_geometry(BlockDriverState *bs, int *pcyls, int *pheads, int *pse *pcyls = cylinders; *pheads = heads; *psecs = secs; +#ifdef __linux__ + } else if (bdrv_ioctl(bs, HDIO_GETGEO, &geo) == 0) { + *pcyls = geo.cylinders; + *pheads = geo.heads; + *psecs = geo.sectors; + bdrv_set_geometry_hint(bs, *pcyls, *pheads, *psecs); +#endif } else { if (guess_disk_lchs(bs, &cylinders, &heads, &secs) == 0) { if (heads > 16) { -- 1.7.0.1