From patchwork Mon Jan 11 13:06:54 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 42618 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 B3801B6EDF for ; Tue, 12 Jan 2010 00:22:19 +1100 (EST) Received: from localhost ([127.0.0.1]:41640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUK0I-0008Mn-87 for incoming@patchwork.ozlabs.org; Mon, 11 Jan 2010 08:08:18 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NUJz9-0008MX-SQ for qemu-devel@nongnu.org; Mon, 11 Jan 2010 08:07:08 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NUJz5-0008LQ-0Y for qemu-devel@nongnu.org; Mon, 11 Jan 2010 08:07:06 -0500 Received: from [199.232.76.173] (port=39270 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUJz4-0008LE-L2 for qemu-devel@nongnu.org; Mon, 11 Jan 2010 08:07:02 -0500 Received: from verein.lst.de ([213.95.11.210]:36780) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1NUJz3-0001DI-Va for qemu-devel@nongnu.org; Mon, 11 Jan 2010 08:07:02 -0500 Received: from verein.lst.de (localhost [127.0.0.1]) by verein.lst.de (8.12.3/8.12.3/Debian-7.1) with ESMTP id o0BD6sWY024767 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Mon, 11 Jan 2010 14:06:54 +0100 Received: (from hch@localhost) by verein.lst.de (8.12.3/8.12.3/Debian-7.2) id o0BD6sCL024766 for qemu-devel@nongnu.org; Mon, 11 Jan 2010 14:06:54 +0100 Date: Mon, 11 Jan 2010 14:06:54 +0100 From: Christoph Hellwig To: qemu-devel@nongnu.org Message-ID: <20100111130654.GA24241@lst.de> Mime-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.3.28i X-Spam-Score: 0 () X-Scanned-By: MIMEDefang 2.39 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Subject: [Qemu-devel] [PATCH] dmg: fix ->open failure 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 Currently the dmg image format driver simply opens the images as raw if any kind of failure happens. This is contrarty to the behaviour of all other image formats which just return an error and let the block core deal with it. Signed-off-by: Christoph Hellwig Acked-by: Kevin Wolf Index: qemu/block/dmg.c =================================================================== --- qemu.orig/block/dmg.c 2010-01-11 14:00:25.945021645 +0100 +++ qemu/block/dmg.c 2010-01-11 14:03:03.006036707 +0100 @@ -90,24 +90,21 @@ static int dmg_open(BlockDriverState *bs /* read offset of info blocks */ if(lseek(s->fd,-0x1d8,SEEK_END)<0) { -dmg_close: - close(s->fd); - /* open raw instead */ - bs->drv=bdrv_find_format("raw"); - return bs->drv->bdrv_open(bs, filename, flags); + goto fail; } + info_begin=read_off(s->fd); if(info_begin==0) - goto dmg_close; + goto fail; if(lseek(s->fd,info_begin,SEEK_SET)<0) - goto dmg_close; + goto fail; if(read_uint32(s->fd)!=0x100) - goto dmg_close; + goto fail; if((count = read_uint32(s->fd))==0) - goto dmg_close; + goto fail; info_end = info_begin+count; if(lseek(s->fd,0xf8,SEEK_CUR)<0) - goto dmg_close; + goto fail; /* read offsets */ last_in_offset = last_out_offset = 0; @@ -116,14 +113,14 @@ dmg_close: count = read_uint32(s->fd); if(count==0) - goto dmg_close; + goto fail; type = read_uint32(s->fd); if(type!=0x6d697368 || count<244) lseek(s->fd,count-4,SEEK_CUR); else { int new_size, chunk_count; if(lseek(s->fd,200,SEEK_CUR)<0) - goto dmg_close; + goto fail; chunk_count = (count-204)/40; new_size = sizeof(uint64_t) * (s->n_chunks + chunk_count); s->types = qemu_realloc(s->types, new_size/2); @@ -142,7 +139,7 @@ dmg_close: chunk_count--; i--; if(lseek(s->fd,36,SEEK_CUR)<0) - goto dmg_close; + goto fail; continue; } read_uint32(s->fd); @@ -163,11 +160,14 @@ dmg_close: s->compressed_chunk = qemu_malloc(max_compressed_size+1); s->uncompressed_chunk = qemu_malloc(512*max_sectors_per_chunk); if(inflateInit(&s->zstream) != Z_OK) - goto dmg_close; + goto fail; s->current_chunk = s->n_chunks; return 0; +fail: + close(s->fd); + return -1; } static inline int is_sector_in_chunk(BDRVDMGState* s,