From patchwork Tue Dec 8 14:34:18 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Fran=C3=A7ois_Revol?= X-Patchwork-Id: 40637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id A4A98B7088 for ; Wed, 9 Dec 2009 01:38:43 +1100 (EST) Received: from localhost ([127.0.0.1]:50948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NI1D3-0002UN-U8 for incoming@patchwork.ozlabs.org; Tue, 08 Dec 2009 09:38:37 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NI198-0002Sh-HT for qemu-devel@nongnu.org; Tue, 08 Dec 2009 09:34:34 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NI192-0002Oq-TA for qemu-devel@nongnu.org; Tue, 08 Dec 2009 09:34:33 -0500 Received: from [199.232.76.173] (port=38974 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NI192-0002Of-30 for qemu-devel@nongnu.org; Tue, 08 Dec 2009 09:34:28 -0500 Received: from smtp2-g21.free.fr ([212.27.42.2]:50590) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NI191-0006ki-Ev for qemu-devel@nongnu.org; Tue, 08 Dec 2009 09:34:28 -0500 Received: from smtp2-g21.free.fr (localhost [127.0.0.1]) by smtp2-g21.free.fr (Postfix) with ESMTP id DB05C4B01DB for ; Tue, 8 Dec 2009 15:34:22 +0100 (CET) Received: from laptop (vaf26-2-82-244-111-82.fbx.proxad.net [82.244.111.82]) by smtp2-g21.free.fr (Postfix) with ESMTP id E24B84B019B for ; Tue, 8 Dec 2009 15:34:19 +0100 (CET) To: qemu-devel@nongnu.org X-Mailer: BeMail - Mail Daemon Replacement 3.0.0 Final From: "=?utf-8?q?Fran=C3=A7ois?= Revol" Date: Tue, 08 Dec 2009 15:34:18 +0100 CET Message-Id: <630568266-BeMail@laptop> Mime-Version: 1.0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [Qemu-devel] [PATCH] block/vdi: allow disk sizes not multiple of block size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org The disk image I created from my old laptop disk with VBoxManage internalcommand converthd obviously was not a multiple of 1MB as when created from scratch. This fixes QEMU refusing it. We still require the size to be a multiple of sector size though. It then boots correctly. Signed-off-by: Allow opening VDI images with size not multiple of 1MB (as when converted from a raw disk). Signed-off-by: François Revol diff --git a/block/vdi.c b/block/vdi.c index 45aa81c..c91961a 100644 --- a/block/vdi.c +++ b/block/vdi.c @@ -411,14 +411,17 @@ static int vdi_open(BlockDriverState *bs, const char *filename, int flags) /* We only support data blocks which start on a sector boundary. */ logout("unsupported data offset 0x%x B\n", header.offset_data); goto fail; + } else if (header.disk_size % SECTOR_SIZE != 0) { + logout("unsupported disk size %" PRIu64 " B\n", header.disk_size); + goto fail; } else if (header.sector_size != SECTOR_SIZE) { logout("unsupported sector size %u B\n", header.sector_size); goto fail; } else if (header.block_size != 1 * MiB) { logout("unsupported block size %u B\n", header.block_size); goto fail; - } else if (header.disk_size != - (uint64_t)header.blocks_in_image * header.block_size) { + } else if ((header.disk_size + header.block_size - 1) / header.block_size != + (uint64_t)header.blocks_in_image) { logout("unexpected block number %u B\n", header.blocks_in_image); goto fail; } else if (!uuid_is_null(header.uuid_link)) {