diff mbox

[2/3] block: Introduce path_has_protocol() function

Message ID 1291130056-32441-3-git-send-email-stefanha@linux.vnet.ibm.com
State New
Headers show

Commit Message

Stefan Hajnoczi Nov. 30, 2010, 3:14 p.m. UTC
The bdrv_find_protocol() function returns NULL if an unknown protocol
name is given.  It returns the "file" protocol when the filename
contains no protocol at all.  This makes it difficult to distinguish
between paths which contain a protocol and those which do not.

Factor out a helper function that tests whether or not a filename has a
protocol.  The next patch makes use of this function.

Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
---
 block.c |   24 ++++++++++++++++--------
 1 files changed, 16 insertions(+), 8 deletions(-)

Comments

Kevin Wolf Dec. 9, 2010, 10:59 a.m. UTC | #1
Am 30.11.2010 16:14, schrieb Stefan Hajnoczi:
> The bdrv_find_protocol() function returns NULL if an unknown protocol
> name is given.  It returns the "file" protocol when the filename
> contains no protocol at all.  This makes it difficult to distinguish
> between paths which contain a protocol and those which do not.
> 
> Factor out a helper function that tests whether or not a filename has a
> protocol.  The next patch makes use of this function.
> 
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>

This breaks the mingw32 build:

/home/kwolf/tmp/win32/qemu/block.c: In function 'path_has_protocol':
/home/kwolf/tmp/win32/qemu/block.c:78: warning: implicit declaration of
function 'is_windows_drive_prefix'
/home/kwolf/tmp/win32/qemu/block.c:78: warning: nested extern
declaration of 'is_windows_drive_prefix'
/home/kwolf/tmp/win32/qemu/block.c: At top level:
/home/kwolf/tmp/win32/qemu/block.c:261: error: static declaration of
'is_windows_drive_prefix' follows non-static declaration
/home/kwolf/tmp/win32/qemu/block.c:78: note: previous implicit
declaration of 'is_windows_drive_prefix' was here

Kevin
diff mbox

Patch

diff --git a/block.c b/block.c
index e7a986c..59b69e4 100644
--- a/block.c
+++ b/block.c
@@ -70,6 +70,19 @@  static BlockDriverState *bs_snapshots;
 /* If non-zero, use only whitelisted block drivers */
 static int use_bdrv_whitelist;
 
+/* check if the path starts with "<protocol>:" */
+static int path_has_protocol(const char *path)
+{
+#ifdef _WIN32
+    if (is_windows_drive(path) ||
+        is_windows_drive_prefix(path)) {
+        return 0;
+    }
+#endif
+
+    return strchr(path, ':') != NULL;
+}
+
 int path_is_absolute(const char *path)
 {
     const char *p;
@@ -307,16 +320,11 @@  BlockDriver *bdrv_find_protocol(const char *filename)
         return drv1;
     }
 
-#ifdef _WIN32
-     if (is_windows_drive(filename) ||
-         is_windows_drive_prefix(filename))
-         return bdrv_find_format("file");
-#endif
-
-    p = strchr(filename, ':');
-    if (!p) {
+    if (!path_has_protocol(filename)) {
         return bdrv_find_format("file");
     }
+    p = strchr(filename, ':');
+    assert(p != NULL);
     len = p - filename;
     if (len > sizeof(protocol) - 1)
         len = sizeof(protocol) - 1;