From patchwork Wed Oct 31 02:59:32 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Arnold X-Patchwork-Id: 195718 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 A5A962C0098 for ; Wed, 31 Oct 2012 13:59:47 +1100 (EST) Received: from localhost ([::1]:54282 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTOWv-0006OO-TF for incoming@patchwork.ozlabs.org; Tue, 30 Oct 2012 22:59:45 -0400 Received: from eggs.gnu.org ([208.118.235.92]:37591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTOWp-0006O6-5G for qemu-devel@nongnu.org; Tue, 30 Oct 2012 22:59:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TTOWo-0003Ag-7u for qemu-devel@nongnu.org; Tue, 30 Oct 2012 22:59:39 -0400 Received: from novprvoes0310.provo.novell.com ([137.65.248.74]:38901) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TTOWo-00038b-0g for qemu-devel@nongnu.org; Tue, 30 Oct 2012 22:59:38 -0400 Received: from INET-PRV-MTA by novprvoes0310.provo.novell.com with Novell_GroupWise; Tue, 30 Oct 2012 20:59:34 -0600 Message-Id: <50903FB402000091000826B3@novprvoes0310.provo.novell.com> X-Mailer: Novell GroupWise Internet Agent 12.0.1 Date: Tue, 30 Oct 2012 20:59:32 -0600 From: "Charles Arnold" To: Mime-Version: 1.0 Content-Disposition: inline X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) X-Received-From: 137.65.248.74 Cc: Kevin Wolf Subject: [Qemu-devel] [PATCH] block: vpc support for ~2 TB disks 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 The VHD specification allows for up to a 2 TB disk size. The current implementation in qemu emulates EIDE and ATA-2 hardware which only allows for up to 127 GB. This disk size limitation can be overridden by allowing up to 255 heads instead of the normal 4 bit limitation of 16. Doing so allows disk images to be created of up to nearly 2 TB. This change does not violate the VHD format specification nor does it change how smaller disks (ie, <=127GB) are defined. Signed-off-by: Charles Arnold diff --git a/block/vpc.c b/block/vpc.c index b6bf52f..0c2eaf8 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -198,7 +198,8 @@ static int vpc_open(BlockDriverState *bs, int flags) bs->total_sectors = (int64_t) be16_to_cpu(footer->cyls) * footer->heads * footer->secs_per_cyl; - if (bs->total_sectors >= 65535 * 16 * 255) { + /* Allow a maximum disk size of approximately 2 TB */ + if (bs->total_sectors >= 65535LL * 255 * 255) { err = -EFBIG; goto fail; } @@ -524,19 +525,27 @@ static coroutine_fn int vpc_co_write(BlockDriverState *bs, int64_t sector_num, * Note that the geometry doesn't always exactly match total_sectors but * may round it down. * - * Returns 0 on success, -EFBIG if the size is larger than 127 GB + * Returns 0 on success, -EFBIG if the size is larger than ~2 TB. Override + * the hardware EIDE and ATA-2 limit of 16 heads (max disk size of 127 GB) + * and instead allow up to 255 heads. */ static int calculate_geometry(int64_t total_sectors, uint16_t* cyls, uint8_t* heads, uint8_t* secs_per_cyl) { uint32_t cyls_times_heads; - if (total_sectors > 65535 * 16 * 255) + /* Allow a maximum disk size of approximately 2 TB */ + if (total_sectors > 65535LL * 255 * 255) { return -EFBIG; + } if (total_sectors > 65535 * 16 * 63) { *secs_per_cyl = 255; - *heads = 16; + if (total_sectors > 65535 * 16 * 255) { + *heads = 255; + } else { + *heads = 16; + } cyls_times_heads = total_sectors / *secs_per_cyl; } else { *secs_per_cyl = 17;