From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38338) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrACv-0006yN-T0 for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:13 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SrACq-0005n4-HN for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:05 -0400 Received: from mx1.redhat.com ([209.132.183.28]:56406) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SrACq-0005my-9A for qemu-devel@nongnu.org; Tue, 17 Jul 2012 12:01:00 -0400 From: Kevin Wolf Date: Tue, 17 Jul 2012 18:00:07 +0200 Message-Id: <1342540838-9027-11-git-send-email-kwolf@redhat.com> In-Reply-To: <1342540838-9027-1-git-send-email-kwolf@redhat.com> References: <1342540838-9027-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 10/41] hd-geometry: Factor out guess_chs_for_size() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Markus Armbruster Signed-off-by: Markus Armbruster Signed-off-by: Kevin Wolf --- hw/hd-geometry.c | 32 ++++++++++++++++++++------------ 1 files changed, 20 insertions(+), 12 deletions(-) diff --git a/hw/hd-geometry.c b/hw/hd-geometry.c index db47846..1a58894 100644 --- a/hw/hd-geometry.c +++ b/hw/hd-geometry.c @@ -97,14 +97,31 @@ static int guess_disk_lchs(BlockDriverState *bs, return -1; } +static void guess_chs_for_size(BlockDriverState *bs, + int *pcyls, int *pheads, int *psecs) +{ + uint64_t nb_sectors; + int cylinders; + + bdrv_get_geometry(bs, &nb_sectors); + + cylinders = nb_sectors / (16 * 63); + if (cylinders > 16383) { + cylinders = 16383; + } else if (cylinders < 2) { + cylinders = 2; + } + *pcyls = cylinders; + *pheads = 16; + *psecs = 63; +} + void hd_geometry_guess(BlockDriverState *bs, int *pcyls, int *pheads, int *psecs) { int translation, lba_detected = 0; int cylinders, heads, secs; - uint64_t nb_sectors; - bdrv_get_geometry(bs, &nb_sectors); bdrv_get_geometry_hint(bs, &cylinders, &heads, &secs); translation = bdrv_get_translation_hint(bs); @@ -119,16 +136,7 @@ void hd_geometry_guess(BlockDriverState *bs, if (guess_disk_lchs(bs, &cylinders, &heads, &secs) < 0) { /* no LCHS guess: use a standard physical disk geometry */ default_geometry: - cylinders = nb_sectors / (16 * 63); - - if (cylinders > 16383) { - cylinders = 16383; - } else if (cylinders < 2) { - cylinders = 2; - } - *pcyls = cylinders; - *pheads = 16; - *psecs = 63; + guess_chs_for_size(bs, pcyls, pheads, psecs); if ((lba_detected == 1) && (translation == BIOS_ATA_TRANSLATION_AUTO)) { if ((*pcyls * *pheads) <= 131072) { bdrv_set_translation_hint(bs, -- 1.7.6.5