--- block-raw.c.orig 2010-07-20 00:42:03.000000000 +0200 +++ block-raw.c 2010-07-20 00:52:19.000000000 +0200 @@ -63,6 +63,12 @@ #include #include #endif +#if defined(__NetBSD__) +#include +#include +#include +#include +#endif //#define DEBUG_FLOPPY @@ -549,7 +555,28 @@ static int64_t raw_getlength(BlockDrive }else return st.st_size; } -#else /* !__OpenBSD__ */ +#elif defined(__NetBSD__) +static int64_t raw_getlength(BlockDriverState *bs) +{ + int fd = ((BDRVRawState*)bs->opaque)->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;