From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:54063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOUYJ-00047x-CA for qemu-devel@nongnu.org; Mon, 23 May 2011 08:48:08 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOUYI-0004Ho-7r for qemu-devel@nongnu.org; Mon, 23 May 2011 08:48:07 -0400 Received: from tx2ehsobe001.messaging.microsoft.com ([65.55.88.11]:57003 helo=TX2EHSOBE002.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOUYI-0004Hj-2A for qemu-devel@nongnu.org; Mon, 23 May 2011 08:48:06 -0400 Received: from mail161-tx2 (localhost.localdomain [127.0.0.1]) by mail161-tx2-R.bigfish.com (Postfix) with ESMTP id 1A9DA14C0BBB for ; Mon, 23 May 2011 12:48:04 +0000 (UTC) Received: from TX2EHSMHS017.bigfish.com (unknown [10.9.14.243]) by mail161-tx2.bigfish.com (Postfix) with ESMTP id 5B045AF00BB for ; Mon, 23 May 2011 12:45:58 +0000 (UTC) Received: from sausexedgep01.amd.com (sausexedgep01-ext.amd.com [163.181.249.72]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp01.amd.com (Axway MailGate 3.8.1) with ESMTP id 2DC221028410 for ; Mon, 23 May 2011 07:45:50 -0500 (CDT) Message-ID: <4DDA5442.30801@amd.com> Date: Mon, 23 May 2011 14:34:10 +0200 From: Christoph Egger MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-15"; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH] block/raw-posix: use a character device if a block device is given List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "qemu-devel@nongnu.org" if given a block device, use the character device instead. From: Manuel Bouyer Signed-off-by: Christoph Egger diff --git a/block/raw-posix.c b/block/raw-posix.c index 6b72470..d05f373 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -136,11 +143,45 @@ static int64_t raw_getlength(BlockDriverState *bs); static int cdrom_reopen(BlockDriverState *bs); #endif +#if defined(__NetBSD__) +static const char *raw_get_rawdevice(const char *filename) +{ + static char namebuf[PATH_MAX]; + const char *dp = strrchr(filename, '/'); + + if (dp == NULL) { + snprintf(namebuf, PATH_MAX, "r%s", filename); + } else { + snprintf(namebuf, PATH_MAX, "%.*s/r%s", + (int)(dp - filename), filename, dp + 1); + } + fprintf(stderr, "%s is a block device", filename); + filename = namebuf; + fprintf(stderr, ", using %s\n", filename); + + return filename; +} +#else +static const char *raw_get_rawdevice(const char *filename) +{ + return filename; +} +#endif + static int raw_open_common(BlockDriverState *bs, const char *filename, int bdrv_flags, int open_flags) { BDRVRawState *s = bs->opaque; int fd, ret; + struct stat sb; + + if (lstat(filename, &sb) < 0) { + fprintf(stderr, "%s: stat failed: %s\n", filename, strerror(errno)); + return -errno; + } + + if (S_ISBLK(sb.st_mode)) + filename = raw_get_rawdevice(filename); s->open_flags = open_flags | O_BINARY; s->open_flags &= ~O_ACCMODE; -- ---to satisfy European Law for business letters: Advanced Micro Devices GmbH Einsteinring 24, 85689 Dornach b. Muenchen Geschaeftsfuehrer: Alberto Bozzo, Andrew Bowd Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632