From: Jake Wires Date: Fri, 11 Jun 2010 20:37:07 +0000 (-0700) Subject: add optional devops vector to libvhd X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=eb450f0a61cdf4f18cbe01fc8e44aadb03edef9f;p=people%2Fdstodden%2Fblktap.git add optional devops vector to libvhd --- diff --git a/include/libvhd.h b/include/libvhd.h index 5f4c767..8f9daf4 100644 --- a/include/libvhd.h +++ b/include/libvhd.h @@ -116,9 +116,19 @@ typedef struct vhd_bat vhd_bat_t; typedef struct vhd_batmap vhd_batmap_t; typedef struct dd_batmap_hdr vhd_batmap_header_t; typedef struct prt_loc vhd_parent_locator_t; +typedef struct vhd_devops vhd_devops_t; typedef struct vhd_context vhd_context_t; typedef uint32_t vhd_flag_creat_t; +struct vhd_devops { + off64_t (*position) (vhd_context_t *); + int (*seek) (vhd_context_t *, off64_t, int); + int (*read) (vhd_context_t *, void *, size_t); + int (*write) (vhd_context_t *, void *, size_t); + int (*pread) (vhd_context_t *, void *, size_t, off64_t); + int (*pwrite) (vhd_context_t *, void *, size_t, off64_t); +}; + struct vhd_bat { uint32_t spb; uint32_t entries; @@ -145,6 +155,8 @@ struct vhd_context { vhd_batmap_t batmap; struct list_head next; + + vhd_devops_t *devops; }; static inline int diff --git a/vhd/lib/libvhd.c b/vhd/lib/libvhd.c index 4150bf5..dc56550 100644 --- a/vhd/lib/libvhd.c +++ b/vhd/lib/libvhd.c @@ -2339,8 +2339,8 @@ vhd_atomic_io(ssize_t (*f) (int, void *, size_t), int fd, void *_s, size_t n) return res; } -int -vhd_seek(vhd_context_t *ctx, off64_t offset, int whence) +static int +__vhd_seek(vhd_context_t *ctx, off64_t offset, int whence) { off64_t off; @@ -2354,14 +2354,14 @@ vhd_seek(vhd_context_t *ctx, off64_t offset, int whence) return 0; } -off64_t -vhd_position(vhd_context_t *ctx) +static off64_t +__vhd_position(vhd_context_t *ctx) { return lseek64(ctx->fd, 0, SEEK_CUR); } -int -vhd_read(vhd_context_t *ctx, void *buf, size_t size) +static int +__vhd_read(vhd_context_t *ctx, void *buf, size_t size) { size_t ret; @@ -2377,8 +2377,8 @@ vhd_read(vhd_context_t *ctx, void *buf, size_t size) return (errno ? -errno : -EIO); } -int -vhd_write(vhd_context_t *ctx, void *buf, size_t size) +static int +__vhd_write(vhd_context_t *ctx, void *buf, size_t size) { size_t ret; @@ -2395,7 +2395,7 @@ vhd_write(vhd_context_t *ctx, void *buf, size_t size) } static int -vhd_pread(vhd_context_t *ctx, void *buf, size_t size, off64_t offset) +__vhd_pread(vhd_context_t *ctx, void *buf, size_t size, off64_t offset) { ssize_t ret; @@ -2412,7 +2412,7 @@ vhd_pread(vhd_context_t *ctx, void *buf, size_t size, off64_t offset) } static int -vhd_pwrite(vhd_context_t *ctx, void *buf, size_t size, off64_t offset) +__vhd_pwrite(vhd_context_t *ctx, void *buf, size_t size, off64_t offset) { ssize_t ret; @@ -2428,6 +2428,54 @@ vhd_pwrite(vhd_context_t *ctx, void *buf, size_t size, off64_t offset) return (errno ? -errno : -EIO); } +int +vhd_seek(vhd_context_t *ctx, off64_t offset, int whence) +{ + if (ctx->devops && ctx->devops->seek) + return ctx->devops->seek(ctx, offset, whence); + return __vhd_seek(ctx, offset, whence); +} + +off64_t +vhd_position(vhd_context_t *ctx) +{ + if (ctx->devops && ctx->devops->position) + return ctx->devops->position(ctx); + return __vhd_position(ctx); +} + +int +vhd_read(vhd_context_t *ctx, void *buf, size_t size) +{ + if (ctx->devops && ctx->devops->read) + return ctx->devops->read(ctx, buf, size); + return __vhd_read(ctx, buf, size); +} + +int +vhd_write(vhd_context_t *ctx, void *buf, size_t size) +{ + if (ctx->devops && ctx->devops->write) + return ctx->devops->write(ctx, buf, size); + return __vhd_write(ctx, buf, size); +} + +static int +vhd_pread(vhd_context_t *ctx, void *buf, size_t size, off64_t offset) +{ + if (ctx->devops && ctx->devops->pread) + return ctx->devops->pread(ctx, buf, size, offset); + return __vhd_pread(ctx, buf, size, offset); +} + +static int +vhd_pwrite(vhd_context_t *ctx, void *buf, size_t size, off64_t offset) +{ + if (ctx->devops && ctx->devops->pwrite) + return ctx->devops->pwrite(ctx, buf, size, offset); + return __vhd_pwrite(ctx, buf, size, offset); +} + int vhd_offset(vhd_context_t *ctx, uint32_t sector, uint32_t *offset) {