Added implementation of a data source for reading from drives.
This commit is contained in:
parent
b51c3b8212
commit
110f22932d
86
libisoburn/trunk/libisoburn/data_source.c
Normal file
86
libisoburn/trunk/libisoburn/data_source.c
Normal file
@ -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;
|
||||
}
|
||||
|
@ -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…
Reference in New Issue
Block a user