From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:40154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOVoj-0008Ro-WE for qemu-devel@nongnu.org; Mon, 23 May 2011 10:09:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOVoi-0002z7-P1 for qemu-devel@nongnu.org; Mon, 23 May 2011 10:09:09 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55214) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOVoi-0002z0-GK for qemu-devel@nongnu.org; Mon, 23 May 2011 10:09:08 -0400 Message-ID: <4DDA6B2A.6000900@redhat.com> Date: Mon, 23 May 2011 16:11:54 +0200 From: Kevin Wolf MIME-Version: 1.0 References: <4DDA5442.30801@amd.com> In-Reply-To: <4DDA5442.30801@amd.com> Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit Subject: Re: [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: Christoph Egger Cc: "qemu-devel@nongnu.org" Am 23.05.2011 14:34, schrieb Christoph Egger: > > if given a block device, use the character device instead. > > From: Manuel Bouyer > Signed-off-by: Christoph Egger A useful commit message would explain why you're doing that. > > 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); Not sure if fprintf is a good idea here, but ok. > + > + 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)); The patch is corrupted by this line wrap. Please remove the fprintf, the callers are responsible for sending an error message to the right destination. > + return -errno; > + } > + > + if (S_ISBLK(sb.st_mode)) > + filename = raw_get_rawdevice(filename); The qemu coding style requires braces. Also, I agree with Christoph that the lstat/S_ISBLK should be moved into the NetBSD specific code. Kevin