ppc64: Don't set Kp bit on SLB
[openbios/afaerber.git] / fs / iso9660 / iso9660_read.c
blob22cc463f04a8744ea0c5d87832d39d4be7d0093f
1 /*
3 * (c) 2005-2009 Laurent Vivier <Laurent@vivier.eu>
5 * This file has been copied from EMILE, http://emile.sf.net
7 */
9 #include "libiso9660.h"
10 #include "libopenbios/bindings.h"
11 #include "libc/diskio.h"
13 size_t iso9660_read(iso9660_FILE *_file, char *buf, size_t count)
15 iso9660_FILE *file = (iso9660_FILE*)_file;
16 size_t read = 0;
18 if ( count > (file->size - file->offset) )
19 count = file->size - file->offset;
21 while (count > 0)
23 size_t part;
24 int offset_extent;
25 int offset_index;
27 offset_extent = file->base +
28 (file->offset / ISOFS_BLOCK_SIZE);
29 offset_index = file->offset % ISOFS_BLOCK_SIZE;
31 if (file->current != offset_extent)
33 if ( (offset_index == 0) &&
34 (count >= ISOFS_BLOCK_SIZE) )
36 /* direct i/o */
38 int extents_nb;
40 extents_nb = count / ISOFS_BLOCK_SIZE;
42 part = extents_nb * ISOFS_BLOCK_SIZE;
44 seek_io(file->volume->fd,
45 offset_extent * ISOFS_BLOCK_SIZE);
46 read_io(file->volume->fd, buf + read, part);
48 file->offset += part;
49 count -= part;
50 read += part;
52 continue;
55 file->current = offset_extent;
56 seek_io(file->volume->fd,
57 offset_extent * ISOFS_BLOCK_SIZE);
58 read_io(file->volume->fd, file->buffer,
59 ISOFS_BLOCK_SIZE);
62 part = ISOFS_BLOCK_SIZE - offset_index;
63 if (count < part)
64 part = count;
66 memcpy(buf + read, file->buffer + offset_index, part);
68 file->offset += part;
69 count -= part;
70 read += part;
73 return read;