Received: from [140.186.70.92] (port=43098 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PNePW-0006Oe-JC for qemu-devel@nongnu.org; Tue, 30 Nov 2010 23:35:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PNRue-0004z4-IB for qemu-devel@nongnu.org; Tue, 30 Nov 2010 10:14:38 -0500 Received: from mtagate4.uk.ibm.com ([194.196.100.164]:42999) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PNRue-0004vb-9T for qemu-devel@nongnu.org; Tue, 30 Nov 2010 10:14:36 -0500 Received: from d06nrmr1507.portsmouth.uk.ibm.com (d06nrmr1507.portsmouth.uk.ibm.com [9.149.38.233]) by mtagate4.uk.ibm.com (8.13.1/8.13.1) with ESMTP id oAUFEY4s030873 for ; Tue, 30 Nov 2010 15:14:34 GMT Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by d06nrmr1507.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id oAUFEcSo2871486 for ; Tue, 30 Nov 2010 15:14:38 GMT Received: from d06av12.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id oAUFEXab013945 for ; Tue, 30 Nov 2010 08:14:34 -0700 From: Stefan Hajnoczi Date: Tue, 30 Nov 2010 15:14:15 +0000 Message-Id: <1291130056-32441-3-git-send-email-stefanha@linux.vnet.ibm.com> In-Reply-To: <1291130056-32441-1-git-send-email-stefanha@linux.vnet.ibm.com> References: <1291130056-32441-1-git-send-email-stefanha@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 2/3] block: Introduce path_has_protocol() function List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Anthony Liguori , 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 --- block.c | 24 ++++++++++++++++-------- 1 files changed, 16 insertions(+), 8 deletions(-) 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 ":" */ +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; -- 1.7.2.3