From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDD4v-0003sV-0B for qemu-devel@nongnu.org; Fri, 01 Aug 2014 09:41:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XDD4l-0007mm-RI for qemu-devel@nongnu.org; Fri, 01 Aug 2014 09:41:00 -0400 Received: from mail-wg0-x234.google.com ([2a00:1450:400c:c00::234]:65181) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XDD4k-0007m4-Uw for qemu-devel@nongnu.org; Fri, 01 Aug 2014 09:40:51 -0400 Received: by mail-wg0-f52.google.com with SMTP id a1so4322676wgh.35 for ; Fri, 01 Aug 2014 06:40:50 -0700 (PDT) Sender: Levente Kurusa From: Levente Kurusa Date: Fri, 1 Aug 2014 15:40:01 +0200 Message-Id: <1406900401-19550-4-git-send-email-lkurusa@redhat.com> In-Reply-To: <1406900401-19550-1-git-send-email-lkurusa@redhat.com> References: <1406900401-19550-1-git-send-email-lkurusa@redhat.com> Subject: [Qemu-devel] [PATCH 3/3] block: vpc: handle fixed size images in probe function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Kevin Wolf , Stefan Hajnoczi Cc: Andrew Jones , Stefan Weil , Levente Kurusa , Fam Zheng , QEMU Developers Fixed size images do not have a header, only dynamic images have that. This type uses a footer, which is the same structure in the last 512 bytes of the image. We need to parse that too to be able to recognize fixed length images, so check there as well. Reviewed-by: Andrew Jones Signed-off-by: Levente Kurusa --- block/vpc.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/block/vpc.c b/block/vpc.c index a6a7213..b12354a 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -164,8 +164,27 @@ static int vpc_check_signature(const void *buf) static int vpc_probe(BlockDriverState *bs, const uint8_t *buf, int buf_size, const char *filename) { - if (buf_size >= 8 && vpc_check_signature(buf)) - return 100; + char sig[8]; + + if (buf_size < 8) { + return 0; + } + + if (vpc_check_signature(buf)) { + return 100; + } + + /* + * Don't give up just yet, since the spec say that only dynamic + * images have a header (which in fact is a copy of the footer). + * Check the signature in the footer as well in order to handle + * fixed size images. + */ + buf_size = bdrv_pread(bs, bdrv_getlength(bs) - HEADER_SIZE, sig, 8); + if (buf_size >= 8 && vpc_check_signature(sig)) { + return 100; + } + return 0; } -- 1.9.3