2005-11-12 19:12:13 +00:00
|
|
|
/*
|
|
|
|
*
|
2006-09-15 14:55:39 +00:00
|
|
|
* (c) 2005 Laurent Vivier <Laurent@lvivier.info>
|
2005-11-12 19:12:13 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "libiso9660.h"
|
|
|
|
|
|
|
|
ssize_t iso9660_read(iso9660_FILE *file, void *buf, size_t count)
|
|
|
|
{
|
|
|
|
size_t read = 0;
|
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
if ( count > (file->size - file->offset) )
|
|
|
|
count = file->size - file->offset;
|
|
|
|
|
2005-11-12 19:12:13 +00:00
|
|
|
while (count > 0)
|
|
|
|
{
|
|
|
|
size_t part;
|
2005-11-14 19:30:39 +00:00
|
|
|
int offset_extent;
|
|
|
|
int offset_index;
|
2005-11-12 19:12:13 +00:00
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
offset_extent = file->base +
|
|
|
|
(file->offset / ISO9660_EXTENT_SIZE);
|
|
|
|
offset_index = file->offset % ISO9660_EXTENT_SIZE;
|
2005-11-14 07:35:45 +00:00
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
if (file->current != offset_extent)
|
2005-11-14 07:35:45 +00:00
|
|
|
{
|
2005-11-14 19:30:39 +00:00
|
|
|
if ( (offset_index == 0) &&
|
|
|
|
(count >= ISO9660_EXTENT_SIZE) )
|
|
|
|
{
|
|
|
|
/* direct i/o */
|
2005-11-14 07:35:45 +00:00
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
int extents_nb;
|
2005-11-14 07:35:45 +00:00
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
extents_nb = count / ISO9660_EXTENT_SIZE;
|
2005-11-14 07:35:45 +00:00
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
part = extents_nb * ISO9660_EXTENT_SIZE;
|
2005-11-14 07:35:45 +00:00
|
|
|
|
2005-11-21 22:07:17 +00:00
|
|
|
file->volume->device->read_sector(file->volume->device->data,
|
|
|
|
offset_extent,
|
|
|
|
buf + read, part);
|
2005-11-14 19:30:39 +00:00
|
|
|
file->offset += part;
|
|
|
|
count -= part;
|
|
|
|
read += part;
|
2005-11-14 07:35:45 +00:00
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
file->current = offset_extent;
|
2005-11-21 22:07:17 +00:00
|
|
|
file->volume->device->read_sector(file->volume->device->data,
|
|
|
|
offset_extent,
|
|
|
|
file->buffer,
|
|
|
|
ISO9660_EXTENT_SIZE);
|
2005-11-12 19:12:13 +00:00
|
|
|
}
|
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
part = ISO9660_EXTENT_SIZE - offset_index;
|
|
|
|
if (count < part)
|
2005-11-12 19:12:13 +00:00
|
|
|
part = count;
|
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
memcpy(buf + read, file->buffer + offset_index, part);
|
2005-11-12 19:12:13 +00:00
|
|
|
|
2005-11-14 19:30:39 +00:00
|
|
|
file->offset += part;
|
2005-11-12 19:12:13 +00:00
|
|
|
count -= part;
|
|
|
|
read += part;
|
|
|
|
}
|
|
|
|
|
|
|
|
return read;
|
|
|
|
}
|