[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/3] geometry detection: use HDIO_GETGEO
From: |
Christian Borntraeger |
Subject: |
[Qemu-devel] [PATCH 2/3] geometry detection: use HDIO_GETGEO |
Date: |
Thu, 26 Apr 2012 15:49:24 +0200 |
From: Einar Lueck <address@hidden>
This patch uses ioctl HDIO_GETGEO to guess geometry of a disk in
case nothing is specified explicitly.
Signed-off-by: Einar Lueck <address@hidden>
Signed-off-by: Christian Borntraeger <address@hidden>
---
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