~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/openbios/fs/iso9660/iso9660_readdir.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *
 
3
 * (c) 2005-2009 Laurent Vivier <Laurent@vivier.eu>
 
4
 *
 
5
 * This file has been copied from EMILE, http://emile.sf.net
 
6
 *
 
7
 */
 
8
 
 
9
#include "libiso9660.h"
 
10
#include "libopenbios/bindings.h"
 
11
#include "libc/diskio.h"
 
12
 
 
13
#define offsetof(t,m)   ((long)&(((t *)0)->m))
 
14
 
 
15
static void read_extent(iso9660_DIR *dir)
 
16
{
 
17
        seek_io(dir->volume->fd, dir->extent * ISOFS_BLOCK_SIZE);
 
18
        read_io(dir->volume->fd, dir->buffer, ISOFS_BLOCK_SIZE);
 
19
 
 
20
        dir->len -= ISOFS_BLOCK_SIZE;
 
21
        dir->extent ++;
 
22
        dir->index = 0;
 
23
}
 
24
 
 
25
struct iso_directory_record *iso9660_readdir(iso9660_DIR *dir)
 
26
{
 
27
        struct iso_directory_record *idr;
 
28
 
 
29
        if (dir->index >
 
30
            ISOFS_BLOCK_SIZE - offsetof(struct iso_directory_record, name[0]))
 
31
        {
 
32
                if (dir->len <= 0)
 
33
                        return NULL;
 
34
 
 
35
                read_extent(dir);
 
36
        }
 
37
 
 
38
        idr = (struct iso_directory_record *) &dir->buffer[dir->index];
 
39
        if (idr->length[0] == 0)  {
 
40
                if (dir->len <= 0)
 
41
                        return NULL;
 
42
 
 
43
                read_extent(dir);
 
44
                idr = (struct iso_directory_record *) &dir->buffer[dir->index];
 
45
        }
 
46
 
 
47
        dir->index += dir->buffer[dir->index];
 
48
 
 
49
        return idr;
 
50
}