Browse Source

Added implementation of a data source for reading from drives.

master
Vreixo Formoso Lopes 14 years ago
parent
commit
3fda6384eb
  1. 86
      libisoburn/data_source.c
  2. 9
      libisoburn/isoburn.h

86
libisoburn/data_source.c

@ -0,0 +1,86 @@
/*
data source for libisoburn.
Copyright 2007 Vreixo Formoso Lopes <metalpain2002@yahoo.es>
*/
#include <assert.h>
#include <stdlib.h>
#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;
}

9
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 */

Loading…
Cancel
Save