From 3fda6384eb74aaa5aafa34960b6bcbb168f74627 Mon Sep 17 00:00:00 2001 From: Vreixo Formoso Lopes Date: Wed, 12 Sep 2007 15:46:41 +0000 Subject: [PATCH] Added implementation of a data source for reading from drives. --- libisoburn/data_source.c | 86 ++++++++++++++++++++++++++++++++++++++++ libisoburn/isoburn.h | 9 +++++ 2 files changed, 95 insertions(+) create mode 100644 libisoburn/data_source.c diff --git a/libisoburn/data_source.c b/libisoburn/data_source.c new file mode 100644 index 00000000..7b9560dd --- /dev/null +++ b/libisoburn/data_source.c @@ -0,0 +1,86 @@ +/* + data source for libisoburn. + + Copyright 2007 Vreixo Formoso Lopes +*/ + +#include +#include + +#include "isoburn.h" +#include "../libisofs/libisofs.h" +#include "../libburn/libburn.h" + +struct disc_data_src { + struct burn_drive *d; + int nblocks; +}; + +static int +ds_read_block(struct data_source *src, int lba, unsigned char *buffer) +{ + int ret; + struct disc_data_src *data; + off_t count; + + assert(src && buffer); + + data = (struct disc_data_src*)src->data; + + /* if (lba >= data->nblocks) + * return BLOCK_OUT_OF_FILE; + */ + + ret = burn_read_data(data->d, (off_t) lba * (off_t) 2048, buffer, 2048, &count, 0); + if (ret <= 0 ) + return -1; //error + + return 0; +} + +static int +ds_get_size(struct data_source *src) +{ + struct disc_data_src *data; + + assert(src); + + data = (struct disc_data_src*)src->data; + return data->nblocks; +} + +static void +ds_free_data(struct data_source *src) +{ + free(src->data); +} + +static struct data_source * +isoburn_data_source_new(struct burn_drive *d) +{ + struct disc_data_src *data; + struct data_source *ret; + + assert(d); + + data = malloc(sizeof(struct disc_data_src)); + if (!data) + return NULL; + data->d = d; + + //TODO should be filled with the size of disc (or track?) + data->nblocks = 0; + + ret = malloc(sizeof(struct data_source)); + if (!ret) { + free(data); + return NULL; + } + ret->refcount = 1; + ret->read_block = ds_read_block; + ret->get_size = ds_get_size; + ret->free_data = ds_free_data; + ret->data = data; + return ret; +} + diff --git a/libisoburn/isoburn.h b/libisoburn/isoburn.h index 15df05ff..ebb78c03 100644 --- a/libisoburn/isoburn.h +++ b/libisoburn/isoburn.h @@ -123,6 +123,15 @@ int isoburn_find_emulator(struct isoburn **pt, */ int isoburn_set_start_byte(struct isoburn *o, off_t value, int flag); +/** Get a data source suitable for read from a drive using burn_read_data() + function. + @param d drive to read from. Must be grabbed. + @return the data source, NULL on error. Must be freed with libisofs + data_source_free() function. Note that that doesn't release the + drive. +*/ +static struct data_source * +isoburn_data_source_new(struct burn_drive *d); #endif /* Isoburn_includeD */