diff options
author | fishsoupisgood <github@madingley.org> | 2019-04-29 01:17:54 +0100 |
---|---|---|
committer | fishsoupisgood <github@madingley.org> | 2019-05-27 03:43:43 +0100 |
commit | 3f2546b2ef55b661fd8dd69682b38992225e86f6 (patch) | |
tree | 65ca85f13617aee1dce474596800950f266a456c /roms/openbios/fs/iso9660/iso9660_readdir.c | |
download | qemu-master.tar.gz qemu-master.tar.bz2 qemu-master.zip |
Diffstat (limited to 'roms/openbios/fs/iso9660/iso9660_readdir.c')
-rw-r--r-- | roms/openbios/fs/iso9660/iso9660_readdir.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/roms/openbios/fs/iso9660/iso9660_readdir.c b/roms/openbios/fs/iso9660/iso9660_readdir.c new file mode 100644 index 00000000..003ffb20 --- /dev/null +++ b/roms/openbios/fs/iso9660/iso9660_readdir.c @@ -0,0 +1,50 @@ +/* + * + * (c) 2005-2009 Laurent Vivier <Laurent@vivier.eu> + * + * This file has been copied from EMILE, http://emile.sf.net + * + */ + +#include "libiso9660.h" +#include "libopenbios/bindings.h" +#include "libc/diskio.h" + +#define offsetof(t,m) ((long)&(((t *)0)->m)) + +static void read_extent(iso9660_DIR *dir) +{ + seek_io(dir->volume->fd, dir->extent * ISOFS_BLOCK_SIZE); + read_io(dir->volume->fd, dir->buffer, ISOFS_BLOCK_SIZE); + + dir->len -= ISOFS_BLOCK_SIZE; + dir->extent ++; + dir->index = 0; +} + +struct iso_directory_record *iso9660_readdir(iso9660_DIR *dir) +{ + struct iso_directory_record *idr; + + if (dir->index > + ISOFS_BLOCK_SIZE - offsetof(struct iso_directory_record, name[0])) + { + if (dir->len <= 0) + return NULL; + + read_extent(dir); + } + + idr = (struct iso_directory_record *) &dir->buffer[dir->index]; + if (idr->length[0] == 0) { + if (dir->len <= 0) + return NULL; + + read_extent(dir); + idr = (struct iso_directory_record *) &dir->buffer[dir->index]; + } + + dir->index += dir->buffer[dir->index]; + + return idr; +} |