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;
vhd_batmap_t batmap;
struct list_head next;
+
+ vhd_devops_t *devops;
};
static inline int
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;
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;
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;
}
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;
}
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;
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)
{