From patchwork Mon May 23 12:31:17 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Egger X-Patchwork-Id: 96941 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6EC43B6F91 for ; Mon, 23 May 2011 23:13:29 +1000 (EST) Received: from localhost ([::1]:46111 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOUwo-0004x2-M7 for incoming@patchwork.ozlabs.org; Mon, 23 May 2011 09:13:26 -0400 Received: from eggs.gnu.org ([140.186.70.92]:51890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOUwb-0004lC-AW for qemu-devel@nongnu.org; Mon, 23 May 2011 09:13:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QOUwZ-0000cT-3B for qemu-devel@nongnu.org; Mon, 23 May 2011 09:13:13 -0400 Received: from am1ehsobe005.messaging.microsoft.com ([213.199.154.208]:44102 helo=AM1EHSOBE005.bigfish.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QOUwY-0000c5-SU for qemu-devel@nongnu.org; Mon, 23 May 2011 09:13:11 -0400 Received: from mail35-am1-R.bigfish.com (10.3.201.253) by AM1EHSOBE005.bigfish.com (10.3.204.25) with Microsoft SMTP Server id 14.1.225.22; Mon, 23 May 2011 12:43:02 +0000 Received: from mail35-am1 (localhost.localdomain [127.0.0.1]) by mail35-am1-R.bigfish.com (Postfix) with ESMTP id 5737AA786E9 for ; Mon, 23 May 2011 12:43:02 +0000 (UTC) X-SpamScore: 1 X-BigFish: VPS1(zzzz1202hzz8275bh8275dhz32i668h839h62h) X-Forefront-Antispam-Report: CIP:163.181.249.109; KIP:(null); UIP:(null); IPVD:NLI; H:ausb3twp02.amd.com; RD:none; EFVD:NLI Received: from mail35-am1 (localhost.localdomain [127.0.0.1]) by mail35-am1 (MessageSwitch) id 130615458264194_22291; Mon, 23 May 2011 12:43:02 +0000 (UTC) Received: from AM1EHSMHS012.bigfish.com (unknown [10.3.201.250]) by mail35-am1.bigfish.com (Postfix) with ESMTP id 0BEC41A6004B for ; Mon, 23 May 2011 12:43:02 +0000 (UTC) Received: from ausb3twp02.amd.com (163.181.249.109) by AM1EHSMHS012.bigfish.com (10.3.207.112) with Microsoft SMTP Server id 14.1.225.22; Mon, 23 May 2011 12:43:01 +0000 X-WSS-ID: 0LLNFBM-02-0JX-02 X-M-MSG: 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 ausb3twp02.amd.com (Axway MailGate 3.8.1) with ESMTP id 2FD03C83D6 for ; Mon, 23 May 2011 07:42:57 -0500 (CDT) Received: from sausexhtp02.amd.com (163.181.3.152) by sausexedgep01.amd.com (163.181.36.54) with Microsoft SMTP Server (TLS) id 8.3.106.1; Mon, 23 May 2011 07:43:04 -0500 Received: from storexhtp01.amd.com (172.24.4.3) by sausexhtp02.amd.com (163.181.3.152) with Microsoft SMTP Server (TLS) id 8.3.83.0; Mon, 23 May 2011 07:42:59 -0500 Received: from rhodium.osrc.amd.com (165.204.15.173) by storexhtp01.amd.com (172.24.4.3) with Microsoft SMTP Server id 8.3.83.0; Mon, 23 May 2011 08:42:57 -0400 Message-ID: <4DDA5395.6070007@amd.com> Date: Mon, 23 May 2011 14:31:17 +0200 From: Christoph Egger User-Agent: Mozilla/5.0 (X11; U; NetBSD amd64; en-US; rv:1.9.2.13) Gecko/20110202 Lightning/1.0b3pre Thunderbird/3.1.7 MIME-Version: 1.0 To: "qemu-devel@nongnu.org" X-OriginatorOrg: amd.com X-detected-operating-system: by eggs.gnu.org: Windows 2000 SP2+, XP SP1+ (seldom 98) X-Received-From: 213.199.154.208 Subject: [Qemu-devel] [PATCH] block/raw-posix: get right partition size X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org use the correct way to get the size of a disk device or partition From: Adam Hamsik 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 @@ -64,6 +64,13 @@ #include #endif +#ifdef __NetBSD__ +#include +#include +#include +#include +#endif + #ifdef __DragonFly__ #include #include @@ -622,6 +663,31 @@ static int64_t raw_getlength(BlockDriverState *bs) } else return st.st_size; } +#elif defined(__NetBSD__) +static int64_t raw_getlength(BlockDriverState *bs) +{ + BDRVRawState *s = bs->opaque; + int fd = s->fd; + struct stat st; + + if (fstat(fd, &st)) + return -1; + if (S_ISCHR(st.st_mode) || S_ISBLK(st.st_mode)) { + struct dkwedge_info dkw; + + if (ioctl(fd, DIOCGWEDGEINFO, &dkw) != -1) { + return dkw.dkw_size * 512; + } else { + 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; + } + } else + return st.st_size; +} #elif defined(__sun__) static int64_t raw_getlength(BlockDriverState *bs) {