EMILE/libiso9660/iso9660_read.c

72 lines
1.3 KiB
C
Raw Normal View History

2005-11-12 19:12:13 +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;
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;
int offset_extent;
int offset_index;
2005-11-12 19:12:13 +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
if (file->current != offset_extent)
2005-11-14 07:35:45 +00:00
{
if ( (offset_index == 0) &&
(count >= ISO9660_EXTENT_SIZE) )
{
/* direct i/o */
2005-11-14 07:35:45 +00:00
int extents_nb;
2005-11-14 07:35:45 +00:00
extents_nb = count / ISO9660_EXTENT_SIZE;
2005-11-14 07:35:45 +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);
file->offset += part;
count -= part;
read += part;
2005-11-14 07:35:45 +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
}
part = ISO9660_EXTENT_SIZE - offset_index;
if (count < part)
2005-11-12 19:12:13 +00:00
part = count;
memcpy(buf + read, file->buffer + offset_index, part);
2005-11-12 19:12:13 +00:00
file->offset += part;
2005-11-12 19:12:13 +00:00
count -= part;
read += part;
}
return read;
}