]> xenbits.xensource.com Git - people/dstodden/blktap.git/commitdiff
add optional devops vector to libvhd
authorJake Wires <Jake.Wires@citrix.com>
Fri, 11 Jun 2010 20:37:07 +0000 (13:37 -0700)
committerDaniel Stodden <daniel.stodden@citrix.com>
Tue, 30 Aug 2011 12:47:59 +0000 (13:47 +0100)
include/libvhd.h
vhd/lib/libvhd.c

index 5f4c767e800aabe4ba722809771780fc5a6f7827..8f9daf4d952606a6877e25a287abd6749b8b5fd5 100644 (file)
@@ -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
index 4150bf5f5f8d124f6d0d742af0a73fbe34097a23..dc565504917daf435b12bc20a88f70643ea19877 100644 (file)
@@ -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)
 {