From 2dc69ead56b7ecd60eb513ab5b6c9978e06070ef Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 23 Feb 2016 15:48:41 +0100 Subject: [PATCH 32/47] vma: better driver guessing for bdrv_open Only use 'raw' when the file actually ends with .raw and no protocol has been specified. With protocol pass the BDRV_O_PROTOCOL flag to tell bdrv_fill_options() to take it into account. --- vma.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/vma.c b/vma.c index 08e4725..8a27704 100644 --- a/vma.c +++ b/vma.c @@ -293,7 +293,20 @@ static int extract_content(int argc, char **argv) } BlockDriverState *bs = bdrv_new(); - if (errp || bdrv_open(&bs, devfn, NULL, NULL, flags, &errp)) { + + size_t devlen = strlen(devfn); + bool protocol = path_has_protocol(devfn); + QDict *options = NULL; + if (devlen > 4 && strcmp(devfn+devlen-4, ".raw") == 0 && !protocol) { + /* explicit raw format */ + options = qdict_new(); + qdict_put(options, "driver", qstring_from_str("raw")); + } else if (protocol) { + /* tell bdrv_open to honor the protocol */ + flags |= BDRV_O_PROTOCOL; + } + + if (errp || bdrv_open(&bs, devfn, NULL, options, flags, &errp)) { g_error("can't open file %s - %s", devfn, error_get_pretty(errp)); } -- 2.1.4