qemu-devel
[Top][All Lists]
Advanced

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

[RFC PATCH] block/vpc: Support probing of fixed-size VHD images


From: Thomas Huth
Subject: [RFC PATCH] block/vpc: Support probing of fixed-size VHD images
Date: Mon, 29 Mar 2021 09:25:59 +0200

Fixed-size VHD images don't have a header, only a footer. To be able
to still detect them right, support probing via the file name, too.

Without this change, images get detected as raw:

$ qemu-img create -f vpc -o subformat=fixed test.vhd 2G
Formatting 'test.vhd', fmt=vpc size=2147483648 subformat=fixed
$ qemu-img info test.vhd
image: test.vhd
file format: raw
virtual size: 2 GiB (2147992064 bytes)
disk size: 8 KiB

With this change:

$ qemu-img info test.vhd
image: test.vhd
file format: vpc
virtual size: 2 GiB (2147991552 bytes)
disk size: 8 KiB

Resolves: https://bugs.launchpad.net/qemu/+bug/1819182
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 I've marked the subject with RFC since I'm not quite sure whether this
 is really a good idea... please let me know what you think about it...

 block/vpc.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/block/vpc.c b/block/vpc.c
index 17a705b482..be561e4b39 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -191,8 +191,18 @@ static uint32_t vpc_checksum(void *p, size_t size)
 
 static int vpc_probe(const uint8_t *buf, int buf_size, const char *filename)
 {
-    if (buf_size >= 8 && !strncmp((char *)buf, "conectix", 8))
+    if (buf_size >= 8 && !strncmp((char *)buf, "conectix", 8)) {
         return 100;
+    }
+
+    /* It could be a fixed-size image without header -> check extension, too */
+    if (filename) {
+        int len = strlen(filename);
+        if (len > 4 && !strcasecmp(&filename[len - 4], ".vhd")) {
+            return 10;
+        }
+    }
+
     return 0;
 }
 
-- 
2.27.0




reply via email to

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