From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:40347) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOSez-0002Ur-4d for qemu-devel@nongnu.org; Mon, 23 May 2011 06:46:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOSey-0000Dz-9c for qemu-devel@nongnu.org; Mon, 23 May 2011 06:46:53 -0400 Received: from tx2ehsobe001.messaging.microsoft.com ([65.55.88.11]:40639 helo=TX2EHSOBE002.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOSey-0000Du-4K for qemu-devel@nongnu.org; Mon, 23 May 2011 06:46:52 -0400 Received: from mail119-tx2 (localhost.localdomain [127.0.0.1]) by mail119-tx2-R.bigfish.com (Postfix) with ESMTP id B44131980A9C for ; Mon, 23 May 2011 10:16:45 +0000 (UTC) Received: from TX2EHSMHS004.bigfish.com (unknown [10.9.14.251]) by mail119-tx2.bigfish.com (Postfix) with ESMTP id 6C1B050050 for ; Mon, 23 May 2011 10:16:45 +0000 (UTC) Received: from sausexedgep02.amd.com (sausexedgep02-ext.amd.com [163.181.249.73]) (using TLSv1 with cipher AES128-SHA (128/128 bits)) (No client certificate requested) by ausb3twp02.amd.com (Axway MailGate 3.8.1) with ESMTP id 2F4D4C83DD for ; Mon, 23 May 2011 05:16:41 -0500 (CDT) Message-ID: <4DDA3153.4070003@amd.com> Date: Mon, 23 May 2011 12:05:07 +0200 From: Christoph Egger MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------050807040304050607040302" Subject: [Qemu-devel] [PATCH] block/raw-posix: get right partition size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --------------050807040304050607040302 Content-Type: text/plain; charset="ISO-8859-15"; format=flowed Content-Transfer-Encoding: 7bit This does 2 things: - use the correct way to get the size of a disk device or partition (from haad@NetBSD.org) - if given a block device, use the character device instead. (from bouyer@NetBSD.org) From: Adam Hamsik From: Manuel Bouyer Signed-off-by: Christoph Egger -- ---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 --------------050807040304050607040302 Content-Type: text/plain; name="qemu_block_raw_posix.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="qemu_block_raw_posix.diff" Content-Description: qemu_block_raw_posix.diff diff --git a/block/raw-posix.c b/block/raw-posix.c index 6b72470..7cf6461 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -64,6 +64,13 @@ #include #endif +#ifdef __NetBSD__ +#include +#include +#include +#include +#endif + #ifdef __DragonFly__ #include #include @@ -141,7 +148,32 @@ static int raw_open_common(BlockDriverState *bs, const char *filename, { 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_ISLNK(sb.st_mode)) { + fprintf(stderr, "%s: symbolic link not supported\n", filename); + return -EINVAL; + } +#if defined(__NetBSD__) + if (S_ISBLK(sb.st_mode)) { + 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); + } +#endif s->open_flags = open_flags | O_BINARY; s->open_flags &= ~O_ACCMODE; if (bdrv_flags & BDRV_O_RDWR) { @@ -603,7 +635,7 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset) return 0; } -#ifdef __OpenBSD__ +#if defined(__OpenBSD__) || defined(__NetBSD__) static int64_t raw_getlength(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; @@ -613,12 +645,22 @@ static int64_t raw_getlength(BlockDriverState *bs) if (fstat(fd, &st)) return -1; if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { - struct disklabel dl; +#if defined(__NetBSD__) + struct dkwedge_info dkw; - if (ioctl(fd, DIOCGDINFO, &dl)) - return -1; - return (uint64_t)dl.d_secsize * - dl.d_partitions[DISKPART(st.st_rdev)].p_size; + if (ioctl(fd, DIOCGWEDGEINFO, &dkw) != -1) { + return dkw.dkw_size * 512; + } else { +#endif + struct disklabel dl; + + if (ioctl(fd, DIOCGDINFO, &dl)) + return -1; + return (uint64_t)dl.d_secsize * + dl.d_partitions[DISKPART(st.st_rdev)].p_size; +#if defined(__NetBSD__) + } +#endif } else return st.st_size; } --------------050807040304050607040302--