From: Adam Hamsik Date: Thu, 7 Jun 2012 18:36:26 +0000 (+0100) Subject: qemu-xen-trad/block: get right partition size X-Git-Tag: xen-4.2.0-rc1~6 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=cbf0f291d4f1d40c59f56b8bd73292b8ad4f84b5;p=qemu-xen-4.3-testing.git qemu-xen-trad/block: get right partition size 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 Backport-requested-by: Roger Pau Monne Signed-off-by: Roger Pau Monne --- diff --git a/block-raw-posix.c b/block-raw-posix.c index e7d745787..795cd5b78 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;