From patchwork Fri Jul 6 06:57:49 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Markus Armbruster X-Patchwork-Id: 169384 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 18FFA2C007E for ; Fri, 6 Jul 2012 18:57:06 +1000 (EST) Received: from localhost ([::1]:60310 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn2VP-0004gp-P0 for incoming@patchwork.ozlabs.org; Fri, 06 Jul 2012 02:59:07 -0400 Received: from eggs.gnu.org ([208.118.235.92]:40045) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn2Ue-00037S-6R for qemu-devel@nongnu.org; Fri, 06 Jul 2012 02:58:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Sn2Ub-0003LR-74 for qemu-devel@nongnu.org; Fri, 06 Jul 2012 02:58:19 -0400 Received: from oxygen.pond.sub.org ([78.46.104.156]:50599) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Sn2Ub-0003Kn-12 for qemu-devel@nongnu.org; Fri, 06 Jul 2012 02:58:17 -0400 Received: from blackfin.pond.sub.org (p5B32A0DA.dip.t-dialin.net [91.50.160.218]) by oxygen.pond.sub.org (Postfix) with ESMTPA id 01A4BA5A61; Fri, 6 Jul 2012 08:58:13 +0200 (CEST) Received: by blackfin.pond.sub.org (Postfix, from userid 500) id 14832600A9; Fri, 6 Jul 2012 08:58:11 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Fri, 6 Jul 2012 08:57:49 +0200 Message-Id: <1341557890-17464-12-git-send-email-armbru@redhat.com> X-Mailer: git-send-email 1.7.6.5 In-Reply-To: <1341557890-17464-1-git-send-email-armbru@redhat.com> References: <1341557890-17464-1-git-send-email-armbru@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 78.46.104.156 Cc: kwolf@redhat.com, blauwirbel@gmail.com, stefanha@linux.vnet.ibm.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 11/32] hd-geometry: Factor out guess_chs_for_size() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Markus Armbruster --- 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,