From mboxrd@z Thu Jan 1 00:00:00 1970 From: Roger Pau Monne Subject: [PATCH 2/2] qemu-xen-trad/block: get right partition size Date: Wed, 30 May 2012 14:45:22 +0100 Message-ID: <1338385522-21949-3-git-send-email-roger.pau@citrix.com> References: <1338385522-21949-1-git-send-email-roger.pau@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1338385522-21949-1-git-send-email-roger.pau@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xen.org Cc: Kevin Wolf , Christoph Egger , Roger Pau Monne List-Id: xen-devel@lists.xenproject.org use the correct way to get the size of a disk device or partition This this a backport of d1f6fd8d1400ab356aee776b1ecc3ed1e89dbeaa. From: Adam Hamsik Signed-off-by: Christoph Egger Signed-off-by: Kevin Wolf Signed-off-by: Roger Pau Monne --- block-raw-posix.c | 33 ++++++++++++++++++++++++++++++++- 1 files changed, 32 insertions(+), 1 deletions(-) diff --git a/block-raw-posix.c b/block-raw-posix.c index e7d7457..795cd5b 100644 --- a/block-raw-posix.c +++ b/block-raw-posix.c @@ -60,6 +60,12 @@ #include #include #endif +#ifdef __NetBSD__ +#include +#include +#include +#include +#endif #ifdef __OpenBSD__ #include @@ -811,7 +817,32 @@ static int64_t raw_getlength(BlockDriverState *bs) } else return st.st_size; } -#else /* !__OpenBSD__ */ +#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; +} +#else /* !__OpenBSD__ && !__NetBSD__ */ static int64_t raw_getlength(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; -- 1.7.7.5 (Apple Git-26)