2005-11-23 22:39:03 +00:00
|
|
|
/*
|
|
|
|
*
|
2006-09-15 14:55:39 +00:00
|
|
|
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
2005-11-23 22:39:03 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "libblock.h"
|
2008-04-20 16:16:53 +00:00
|
|
|
#include "block.h"
|
2005-11-23 22:39:03 +00:00
|
|
|
|
|
|
|
#define NB_SECTORS (18*2)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* path is "<first>,<size>"
|
|
|
|
* where <first> is the offset of the first byte to read on the device
|
|
|
|
* and <size> is the number of bytes to read then.
|
|
|
|
*/
|
|
|
|
|
2008-04-20 16:16:53 +00:00
|
|
|
stream_FILE *block_open(stream_VOLUME *volume, char *path)
|
2005-11-23 22:39:03 +00:00
|
|
|
{
|
|
|
|
block_FILE *block;
|
2008-04-20 16:16:53 +00:00
|
|
|
int blocksize = ((device_io_t*)volume)->get_blocksize(((device_io_t*)volume)->data);
|
2005-11-23 22:39:03 +00:00
|
|
|
int first, size;
|
|
|
|
|
|
|
|
first = strtol(path, &path, 0);
|
|
|
|
if ( (*path != ',') && (*path != 0) )
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (*path == ',')
|
|
|
|
{
|
2005-11-26 08:43:04 +00:00
|
|
|
path++;
|
2005-11-23 22:39:03 +00:00
|
|
|
size = strtol(path, &path, 0);
|
|
|
|
if (*path != 0)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
size = -1;
|
|
|
|
|
|
|
|
block = (block_FILE *)malloc(sizeof(block_FILE) +
|
|
|
|
NB_SECTORS * blocksize);
|
|
|
|
if (block == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
block->base = first;
|
|
|
|
block->offset = 0;
|
|
|
|
block->size = size;
|
2008-04-20 16:16:53 +00:00
|
|
|
block->device = (device_io_t*)volume;
|
2005-11-23 22:39:03 +00:00
|
|
|
block->current = -1;
|
2008-02-14 19:46:10 +00:00
|
|
|
block->buffer_size = NB_SECTORS;
|
2005-11-23 22:39:03 +00:00
|
|
|
|
2008-04-20 16:16:53 +00:00
|
|
|
return (stream_FILE*)block;
|
2005-11-23 22:39:03 +00:00
|
|
|
}
|