From 128ab2ff50a85969d08d2dec0fd88accdd153bcb Mon Sep 17 00:00:00 2001 From: blueswir1 Date: Fri, 15 Aug 2008 18:33:42 +0000 Subject: Preliminary OpenBSD host support (based on OpenBSD patches by Todd T. Fries) git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@5012 c046a42c-6fe2-441c-8c8c-71466251a162 --- block-raw-posix.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'block-raw-posix.c') diff --git a/block-raw-posix.c b/block-raw-posix.c index 5c3b0ac2e7..b1fc92181d 100644 --- a/block-raw-posix.c +++ b/block-raw-posix.c @@ -58,6 +58,12 @@ #include #endif +#ifdef __OpenBSD__ +#include +#include +#include +#endif + //#define DEBUG_FLOPPY //#define DEBUG_BLOCK @@ -745,6 +751,26 @@ static int raw_truncate(BlockDriverState *bs, int64_t offset) return 0; } +#ifdef __OpenBSD__ +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 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__ */ static int64_t raw_getlength(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; @@ -791,6 +817,7 @@ static int64_t raw_getlength(BlockDriverState *bs) } return size; } +#endif static int raw_create(const char *filename, int64_t total_size, const char *backing_file, int flags) -- cgit v1.2.1