qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 3/3] block: vpc: handle fixed size images in probe f


From: Levente Kurusa
Subject: [Qemu-devel] [PATCH 3/3] block: vpc: handle fixed size images in probe function
Date: Fri, 1 Aug 2014 15:40:01 +0200

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 <address@hidden>
Signed-off-by: Levente Kurusa <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]