$OpenBSD: patch-block-raw-posix_c,v 1.1 2008/04/28 22:52:38 todd Exp $ --- block-raw-posix.c.orig Sun Jan 6 14:38:42 2008 +++ block-raw-posix.c Tue Apr 1 22:38:47 2008 @@ -28,7 +28,9 @@ #endif #include "block_int.h" #include +#ifndef CONFIG_NO_AIO #include +#endif #ifdef CONFIG_COCOA #include @@ -55,6 +57,11 @@ #ifdef __FreeBSD__ #include #endif +#ifdef __OpenBSD__ +#include +#include +#include +#endif //#define DEBUG_FLOPPY @@ -231,6 +238,7 @@ label__raw_write__success: } /***********************************************************/ +#ifndef CONFIG_NO_AIO /* Unix AIO using POSIX AIO */ typedef struct RawAIOCB { @@ -456,6 +464,37 @@ static void raw_aio_cancel(BlockDriverAIOCB *blockacb) } } +# else /* !CONFIG_NO_AIO */ + +void qemu_aio_init(void) +{ +} + +void qemu_aio_poll(void) +{ +} + +void qemu_aio_flush(void) +{ +} + +void qemu_aio_wait_start(void) +{ +} + +void qemu_aio_wait(void) +{ +#ifndef QEMU_IMG + qemu_bh_poll(); +#endif +} + +void qemu_aio_wait_end(void) +{ +} + +#endif /* !CONFIG_NO_AIO */ + static void raw_close(BlockDriverState *bs) { BDRVRawState *s = bs->opaque; @@ -475,8 +514,25 @@ static int raw_truncate(BlockDriverState *bs, int64_t return 0; } +#ifdef __OpenBSD__ 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 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; int fd = s->fd; int64_t size; @@ -521,6 +577,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) @@ -555,11 +612,12 @@ BlockDriver bdrv_raw = { raw_close, raw_create, raw_flush, - +#ifndef CONFIG_NO_AIO .bdrv_aio_read = raw_aio_read, .bdrv_aio_write = raw_aio_write, .bdrv_aio_cancel = raw_aio_cancel, .aiocb_size = sizeof(RawAIOCB), +#endif .protocol_name = "file", .bdrv_pread = raw_pread, .bdrv_pwrite = raw_pwrite, @@ -907,11 +965,12 @@ BlockDriver bdrv_host_device = { raw_close, NULL, raw_flush, - +#ifndef CONFIG_NO_AIO .bdrv_aio_read = raw_aio_read, .bdrv_aio_write = raw_aio_write, .bdrv_aio_cancel = raw_aio_cancel, .aiocb_size = sizeof(RawAIOCB), +#endif .bdrv_pread = raw_pread, .bdrv_pwrite = raw_pwrite, .bdrv_getlength = raw_getlength,