]>
Commit | Line | Data |
---|---|---|
2c75dbed WB |
1 | From 97fe08940a43098fb033950ea8c46716a7476439 Mon Sep 17 00:00:00 2001 |
2 | From: Wolfgang Bumiller <w.bumiller@proxmox.com> | |
3 | Date: Tue, 23 Feb 2016 15:48:41 +0100 | |
4 | Subject: [PATCH] vma: better driver guessing for bdrv_open | |
5 | ||
6 | Only use 'raw' when the file actually ends with .raw and | |
7 | no protocol has been specified. With protocol pass the | |
8 | BDRV_O_PROTOCOL flag to tell bdrv_fill_options() to take it | |
9 | into account. | |
10 | --- | |
11 | vma.c | 15 +++++++++++---- | |
12 | 1 file changed, 11 insertions(+), 4 deletions(-) | |
13 | ||
14 | diff --git a/vma.c b/vma.c | |
15 | index cc48013..1c4103f 100644 | |
16 | --- a/vma.c | |
17 | +++ b/vma.c | |
18 | @@ -301,10 +301,17 @@ static int extract_content(int argc, char **argv) | |
19 | ||
20 | BlockDriverState *bs = bdrv_new(); | |
21 | ||
22 | - const char *tmp = g_strrstr(devfn, "."); | |
23 | - const char *format = (tmp == NULL) ? "raw" : ++tmp; | |
24 | - QDict *options = qdict_new(); | |
25 | - qdict_put(options, "driver", qstring_from_str(format)); | |
26 | + size_t devlen = strlen(devfn); | |
27 | + bool protocol = path_has_protocol(devfn); | |
28 | + QDict *options = NULL; | |
29 | + if (devlen > 4 && strcmp(devfn+devlen-4, ".raw") == 0 && !protocol) { | |
30 | + /* explicit raw format */ | |
31 | + options = qdict_new(); | |
32 | + qdict_put(options, "driver", qstring_from_str("raw")); | |
33 | + } else if (protocol) { | |
34 | + /* tell bdrv_open to honor the protocol */ | |
35 | + flags |= BDRV_O_PROTOCOL; | |
36 | + } | |
37 | ||
38 | if (errp || bdrv_open(&bs, devfn, NULL, options, flags, &errp)) { | |
39 | g_error("can't open file %s - %s", devfn, | |
40 | -- | |
41 | 2.1.4 | |
42 |