aboutsummaryrefslogtreecommitdiff
path: root/block-raw-posix.c
diff options
context:
space:
mode:
authorblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>2008-08-15 18:33:42 +0000
committerblueswir1 <blueswir1@c046a42c-6fe2-441c-8c8c-71466251a162>2008-08-15 18:33:42 +0000
commit128ab2ff50a85969d08d2dec0fd88accdd153bcb (patch)
tree58e3f83a26a0df04bd347789c0163e0ac6c0a5e9 /block-raw-posix.c
parent72c7b06cb7e0cfded2678d531c454fcac16c93c3 (diff)
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
Diffstat (limited to 'block-raw-posix.c')
-rw-r--r--block-raw-posix.c27
1 files changed, 27 insertions, 0 deletions
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 <sys/disk.h>
#endif
+#ifdef __OpenBSD__
+#include <sys/ioctl.h>
+#include <sys/disklabel.h>
+#include <sys/dkio.h>
+#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)