misc/libphysfs/archiver_iso9660.c
author Wuzzy <Wuzzy2@mail.ru>
Tue, 13 Mar 2018 00:50:58 +0100
branchqt5transition
changeset 13181 34cf782e061c
parent 12218 bb5522e88ab2
permissions -rw-r--r--
Also update default binds for SDL2 keypad names
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     1
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     2
 * ISO9660 support routines for PhysicsFS.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     3
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     4
 * Please see the file LICENSE.txt in the source's root directory.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     5
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     6
 *  This file written by Christoph Nelles.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     7
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     8
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
     9
/* !!! FIXME: this file needs Ryanification. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    10
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    11
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    12
 * Handles CD-ROM disk images (and raw CD-ROM devices).
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    13
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    14
 * Not supported:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    15
 * - RockRidge
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    16
 * - Non 2048 Sectors
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    17
 * - UDF
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    18
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    19
 * Deviations from the standard
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    20
 * - Ignores mandatory sort order
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    21
 * - Allows various invalid file names
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    22
 *
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    23
 * Problems
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    24
 * - Ambiguities in the standard
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    25
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    26
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    27
#define __PHYSICSFS_INTERNAL__
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    28
#include "physfs_internal.h"
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    29
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    30
#if PHYSFS_SUPPORTS_ISO9660
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    31
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    32
#include <time.h>
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    33
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    34
/* cache files smaller than this completely in memory */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    35
#define ISO9660_FULLCACHEMAXSIZE 2048
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    36
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    37
/* !!! FIXME: this is going to cause trouble. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    38
#pragma pack(push)  /* push current alignment to stack */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    39
#pragma pack(1)     /* set alignment to 1 byte boundary */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    40
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    41
/* This is the format as defined by the standard
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    42
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    43
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    44
    PHYSFS_uint32 lsb;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    45
    PHYSFS_uint32 msb;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    46
} ISOBB32bit; // 32byte Both Byte type, means the value first in LSB then in MSB
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    47
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    48
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    49
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    50
    PHYSFS_uint16 lsb;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    51
    PHYSFS_uint16 msb;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    52
} ISOBB16bit; // 16byte Both Byte type, means the value first in LSB then in MSB
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    53
*/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    54
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    55
/* define better ones to simplify coding (less if's) */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    56
#if PHYSFS_BYTEORDER == PHYSFS_LIL_ENDIAN
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    57
#define ISOBB32bit(name) PHYSFS_uint32 name; PHYSFS_uint32 __dummy_##name;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    58
#define ISOBB16bit(name) PHYSFS_uint16 name; PHYSFS_uint16 __dummy_##name;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    59
#else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    60
#define ISOBB32bit(name) PHYSFS_uint32 __dummy_##name; PHYSFS_uint32 name;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    61
#define ISOBB16bit(name) PHYSFS_uint16 __dummy_##name; PHYSFS_uint16 name;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    62
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    63
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    64
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    65
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    66
    char year[4];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    67
    char month[2];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    68
    char day[2];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    69
    char hour[2];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    70
    char minute[2];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    71
    char second[2];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    72
    char centisec[2];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    73
    PHYSFS_sint8 offset; /* in 15min from GMT */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    74
} ISO9660VolumeTimestamp;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    75
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    76
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    77
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    78
    PHYSFS_uint8 year;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    79
    PHYSFS_uint8 month;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    80
    PHYSFS_uint8 day;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    81
    PHYSFS_uint8 hour;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    82
    PHYSFS_uint8 minute;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    83
    PHYSFS_uint8 second;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    84
    PHYSFS_sint8 offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    85
} ISO9660FileTimestamp;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    86
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    87
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    88
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    89
  unsigned existence:1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    90
  unsigned directory:1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    91
  unsigned associated_file:1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    92
  unsigned record:1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    93
  unsigned protection:1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    94
  unsigned reserved:2;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    95
  unsigned multiextent:1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    96
} ISO9660FileFlags;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    97
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    98
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
    99
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   100
    PHYSFS_uint8 length;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   101
    PHYSFS_uint8 attribute_length;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   102
    ISOBB32bit(extent_location)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   103
    ISOBB32bit(data_length)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   104
    ISO9660FileTimestamp timestamp;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   105
    ISO9660FileFlags file_flags;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   106
    PHYSFS_uint8 file_unit_size;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   107
    PHYSFS_uint8 gap_size;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   108
    ISOBB16bit(vol_seq_no)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   109
    PHYSFS_uint8 len_fi;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   110
    char unused;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   111
} ISO9660RootDirectoryRecord;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   112
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   113
/* this structure is combined for all Volume descriptor types */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   114
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   115
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   116
    PHYSFS_uint8 type;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   117
    char identifier[5];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   118
    PHYSFS_uint8 version;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   119
    PHYSFS_uint8 flags;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   120
    char system_identifier[32];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   121
    char volume_identifier[32];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   122
    char unused2[8];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   123
    ISOBB32bit(space_size)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   124
    PHYSFS_uint8 escape_sequences[32];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   125
    ISOBB16bit(vol_set_size)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   126
    ISOBB16bit(vol_seq_no)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   127
    ISOBB16bit(block_size)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   128
    ISOBB32bit(path_table_size)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   129
/*    PHYSFS_uint32 path_table_start_lsb; // why didn't they use both byte type?
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   130
    PHYSFS_uint32 opt_path_table_start_lsb;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   131
    PHYSFS_uint32 path_table_start_msb;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   132
    PHYSFS_uint32 opt_path_table_start_msb;*/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   133
#if PHYSFS_BYTEORDER == PHYSFS_LIL_ENDIAN
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   134
    PHYSFS_uint32 path_table_start;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   135
    PHYSFS_uint32 opt_path_table_start;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   136
    PHYSFS_uint32 unused6;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   137
    PHYSFS_uint32 unused7;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   138
#else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   139
    PHYSFS_uint32 unused6;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   140
    PHYSFS_uint32 unused7;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   141
    PHYSFS_uint32 path_table_start;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   142
    PHYSFS_uint32 opt_path_table_start;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   143
#endif
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   144
    ISO9660RootDirectoryRecord rootdirectory;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   145
    char set_identifier[128];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   146
    char publisher_identifier[128];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   147
    char preparer_identifer[128];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   148
    char application_identifier[128];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   149
    char copyright_file_identifier[37];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   150
    char abstract_file_identifier[37];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   151
    char bibliographic_file_identifier[37];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   152
    ISO9660VolumeTimestamp creation_timestamp;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   153
    ISO9660VolumeTimestamp modification_timestamp;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   154
    ISO9660VolumeTimestamp expiration_timestamp;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   155
    ISO9660VolumeTimestamp effective_timestamp;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   156
    PHYSFS_uint8 file_structure_version;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   157
    char unused4;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   158
    char application_use[512];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   159
    char unused5[653];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   160
} ISO9660VolumeDescriptor;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   161
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   162
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   163
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   164
    PHYSFS_uint8 recordlen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   165
    PHYSFS_uint8 extattributelen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   166
    ISOBB32bit(extentpos)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   167
    ISOBB32bit(datalen)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   168
    ISO9660FileTimestamp recordtime;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   169
    ISO9660FileFlags flags;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   170
    PHYSFS_uint8 file_unit_size;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   171
    PHYSFS_uint8 interleave_gap;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   172
    ISOBB16bit(volseqno)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   173
    PHYSFS_uint8 filenamelen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   174
    char filename[222]; /* This is not exact, but makes reading easier */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   175
} ISO9660FileDescriptor;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   176
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   177
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   178
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   179
    ISOBB16bit(owner)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   180
    ISOBB16bit(group)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   181
    PHYSFS_uint16 flags; /* not implemented*/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   182
    ISO9660VolumeTimestamp create_time; /* yes, not file timestamp */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   183
    ISO9660VolumeTimestamp mod_time;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   184
    ISO9660VolumeTimestamp expire_time;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   185
    ISO9660VolumeTimestamp effective_time;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   186
    PHYSFS_uint8 record_format;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   187
    PHYSFS_uint8 record_attributes;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   188
    ISOBB16bit(record_len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   189
    char system_identifier[32];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   190
    char system_use[64];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   191
    PHYSFS_uint8 version;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   192
    ISOBB16bit(escape_len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   193
    char reserved[64];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   194
    /** further fields not implemented */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   195
} ISO9660ExtAttributeRec;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   196
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   197
#pragma pack(pop)   /* restore original alignment from stack */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   198
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   199
typedef struct
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   200
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   201
    PHYSFS_Io *io;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   202
    PHYSFS_uint32 rootdirstart;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   203
    PHYSFS_uint32 rootdirsize;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   204
    PHYSFS_uint64 currpos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   205
    int isjoliet;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   206
    char *path;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   207
    void *mutex;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   208
} ISO9660Handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   209
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   210
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   211
typedef struct __ISO9660FileHandle
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   212
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   213
    PHYSFS_sint64 filesize;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   214
    PHYSFS_uint64 currpos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   215
    PHYSFS_uint64 startblock;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   216
    ISO9660Handle *isohandle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   217
    PHYSFS_uint32 (*read) (struct __ISO9660FileHandle *filehandle, void *buffer,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   218
            PHYSFS_uint64 len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   219
    int (*seek)(struct __ISO9660FileHandle *filehandle,  PHYSFS_sint64 offset);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   220
    void (*close)(struct __ISO9660FileHandle *filehandle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   221
    /* !!! FIXME: anonymouse union is going to cause problems. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   222
    union
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   223
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   224
        /* !!! FIXME: just use a memory PHYSFS_Io here, unify all this code. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   225
        char *cacheddata; /* data of file when cached */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   226
        PHYSFS_Io *io; /* handle to separate opened file */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   227
    };
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   228
} ISO9660FileHandle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   229
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   230
/*******************************************************************************
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   231
 * Time conversion functions
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   232
 ******************************************************************************/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   233
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   234
static PHYSFS_sint64 iso_mktime(ISO9660FileTimestamp *timestamp)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   235
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   236
    struct tm tm;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   237
    tm.tm_year = timestamp->year;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   238
    tm.tm_mon = timestamp->month - 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   239
    tm.tm_mday = timestamp->day;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   240
    tm.tm_hour = timestamp->hour;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   241
    tm.tm_min = timestamp->minute;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   242
    tm.tm_sec = timestamp->second;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   243
    /* Ignore GMT offset for now... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   244
    return mktime(&tm);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   245
} /* iso_mktime */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   246
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   247
static int iso_atoi2(char *text)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   248
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   249
    return ((text[0] - 40) * 10) + (text[1] - 40);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   250
} /* iso_atoi2 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   251
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   252
static int iso_atoi4(char *text)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   253
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   254
    return ((text[0] - 40) * 1000) + ((text[1] - 40) * 100) +
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   255
           ((text[2] - 40) * 10) + (text[3] - 40);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   256
} /* iso_atoi4 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   257
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   258
static PHYSFS_sint64 iso_volume_mktime(ISO9660VolumeTimestamp *timestamp)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   259
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   260
    struct tm tm;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   261
    tm.tm_year = iso_atoi4(timestamp->year);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   262
    tm.tm_mon = iso_atoi2(timestamp->month) - 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   263
    tm.tm_mday = iso_atoi2(timestamp->day);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   264
    tm.tm_hour = iso_atoi2(timestamp->hour);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   265
    tm.tm_min = iso_atoi2(timestamp->minute);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   266
    tm.tm_sec = iso_atoi2(timestamp->second);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   267
    /* this allows values outside the range of a unix timestamp... sanitize them */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   268
    PHYSFS_sint64 value = mktime(&tm);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   269
    return value == -1 ? 0 : value;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   270
} /* iso_volume_mktime */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   271
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   272
/*******************************************************************************
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   273
 * Filename extraction
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   274
 ******************************************************************************/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   275
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   276
static int iso_extractfilenameISO(ISO9660FileDescriptor *descriptor,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   277
        char *filename, int *version)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   278
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   279
    *filename = '\0';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   280
    if (descriptor->flags.directory)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   281
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   282
        strncpy(filename, descriptor->filename, descriptor->filenamelen);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   283
        filename[descriptor->filenamelen] = '\0';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   284
        *version = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   285
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   286
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   287
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   288
        /* find last SEPARATOR2 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   289
        int pos = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   290
        int lastfound = -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   291
        for(;pos < descriptor->filenamelen; pos++)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   292
            if (descriptor->filename[pos] == ';')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   293
                lastfound = pos;
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   294
        BAIL_IF_MACRO(lastfound < 1, PHYSFS_ERR_NOT_FOUND /* !!! FIXME: PHYSFS_ERR_BAD_FILENAME */, -1);
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   295
        BAIL_IF_MACRO(lastfound == (descriptor->filenamelen -1), PHYSFS_ERR_NOT_FOUND /* !!! PHYSFS_ERR_BAD_FILENAME */, -1);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   296
        strncpy(filename, descriptor->filename, lastfound);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   297
        if (filename[lastfound - 1] == '.')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   298
            filename[lastfound - 1] = '\0'; /* consume trailing ., as done in all implementations */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   299
        else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   300
            filename[lastfound] = '\0';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   301
        *version = atoi(descriptor->filename + lastfound);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   302
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   303
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   304
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   305
} /* iso_extractfilenameISO */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   306
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   307
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   308
static int iso_extractfilenameUCS2(ISO9660FileDescriptor *descriptor,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   309
        char *filename, int *version)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   310
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   311
    PHYSFS_uint16 tmp[128];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   312
    PHYSFS_uint16 *src;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   313
    int len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   314
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   315
    *filename = '\0';
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   316
    *version = 1; /* Joliet does not have versions.. at least not on my images */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   317
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   318
    src = (PHYSFS_uint16*) descriptor->filename;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   319
    len = descriptor->filenamelen / 2;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   320
    tmp[len] = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   321
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   322
    while(len--)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   323
        tmp[len] = PHYSFS_swapUBE16(src[len]);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   324
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   325
    PHYSFS_utf8FromUcs2(tmp, filename, 255);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   326
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   327
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   328
} /* iso_extractfilenameUCS2 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   329
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   330
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   331
static int iso_extractfilename(ISO9660Handle *handle,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   332
        ISO9660FileDescriptor *descriptor, char *filename,int *version)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   333
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   334
    if (handle->isjoliet)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   335
        return iso_extractfilenameUCS2(descriptor, filename, version);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   336
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   337
        return iso_extractfilenameISO(descriptor, filename, version);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   338
} /* iso_extractfilename */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   339
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   340
/*******************************************************************************
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   341
 * Basic image read functions
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   342
 ******************************************************************************/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   343
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   344
static int iso_readimage(ISO9660Handle *handle, PHYSFS_uint64 where,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   345
                         void *buffer, PHYSFS_uint64 len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   346
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   347
    BAIL_IF_MACRO(!__PHYSFS_platformGrabMutex(handle->mutex), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   348
    int rc = -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   349
    if (where != handle->currpos)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   350
        GOTO_IF_MACRO(!handle->io->seek(handle->io,where), ERRPASS, unlockme);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   351
    rc = handle->io->read(handle->io, buffer, len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   352
    if (rc == -1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   353
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   354
        handle->currpos = (PHYSFS_uint64) -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   355
        goto unlockme;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   356
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   357
    handle->currpos += rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   358
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   359
    unlockme:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   360
    __PHYSFS_platformReleaseMutex(handle->mutex);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   361
    return rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   362
} /* iso_readimage */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   363
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   364
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   365
static PHYSFS_sint64 iso_readfiledescriptor(ISO9660Handle *handle,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   366
                                            PHYSFS_uint64 where,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   367
                                            ISO9660FileDescriptor *descriptor)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   368
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   369
    PHYSFS_sint64 rc = iso_readimage(handle, where, descriptor,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   370
                                     sizeof (descriptor->recordlen));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   371
    BAIL_IF_MACRO(rc == -1, ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   372
    BAIL_IF_MACRO(rc != 1, PHYSFS_ERR_CORRUPT, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   373
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   374
    if (descriptor->recordlen == 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   375
        return 0; /* fill bytes at the end of a sector */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   376
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   377
    rc = iso_readimage(handle, where + 1, &descriptor->extattributelen,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   378
            descriptor->recordlen - sizeof(descriptor->recordlen));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   379
    BAIL_IF_MACRO(rc == -1, ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   380
    BAIL_IF_MACRO(rc != 1, PHYSFS_ERR_CORRUPT, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   381
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   382
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   383
} /* iso_readfiledescriptor */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   384
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   385
static void iso_extractsubpath(char *path, char **subpath)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   386
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   387
    *subpath = strchr(path,'/');
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   388
    if (*subpath != 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   389
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   390
        **subpath = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   391
        *subpath +=1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   392
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   393
} /* iso_extractsubpath */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   394
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   395
/*
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   396
 * Don't use path tables, they are not necessarily faster, but more complicated
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   397
 * to implement as they store only directories and not files, so searching for
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   398
 * a file needs to branch to the directory extent sooner or later.
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   399
 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   400
static int iso_find_dir_entry(ISO9660Handle *handle,const char *path,
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   401
                              ISO9660FileDescriptor *descriptor)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   402
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   403
    char *subpath = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   404
    PHYSFS_uint64 readpos, end_of_dir;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   405
    char filename[255];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   406
    char pathcopy[256];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   407
    char *mypath;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   408
    int version = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   409
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   410
    strcpy(pathcopy, path);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   411
    mypath = pathcopy;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   412
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   413
    readpos = handle->rootdirstart;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   414
    end_of_dir = handle->rootdirstart + handle->rootdirsize;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   415
    iso_extractsubpath(mypath, &subpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   416
    while (1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   417
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   418
        BAIL_IF_MACRO(iso_readfiledescriptor(handle, readpos, descriptor), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   419
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   420
        /* recordlen = 0 -> no more entries or fill entry */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   421
        if (!descriptor->recordlen)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   422
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   423
            /* if we are in the last sector of the directory & it's 0 -> end */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   424
            if ((end_of_dir - 2048) <= (readpos -1))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   425
                break; /* finished */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   426
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   427
            /* else skip to the next sector & continue; */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   428
            readpos = (((readpos - 1) / 2048) + 1) * 2048;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   429
            continue;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   430
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   431
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   432
        readpos += descriptor->recordlen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   433
        if (descriptor->filenamelen == 1 && (descriptor->filename[0] == 0
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   434
                || descriptor->filename[0] == 1))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   435
            continue; /* special ones, ignore */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   436
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   437
        BAIL_IF_MACRO(
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   438
            iso_extractfilename(handle, descriptor, filename, &version),
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   439
            ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   440
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   441
        if (strcmp(filename, mypath) == 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   442
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   443
            if ( (subpath == 0) || (subpath[0] == 0) )
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   444
                return 0;  /* no subpaths left and we found the entry */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   445
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   446
            if (descriptor->flags.directory)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   447
            {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   448
                /* shorten the path to the subpath */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   449
                mypath = subpath;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   450
                iso_extractsubpath(mypath, &subpath);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   451
                /* gosub to the new directory extent */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   452
                readpos = descriptor->extentpos * 2048;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   453
                end_of_dir = readpos + descriptor->datalen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   454
            } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   455
            else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   456
            {
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   457
                /* !!! FIXME: set PHYSFS_ERR_NOT_FOUND? */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   458
                /* we're at a file but have a remaining subpath -> no match */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   459
                return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   460
            } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   461
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   462
    } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   463
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   464
    /* !!! FIXME: set PHYSFS_ERR_NOT_FOUND? */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   465
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   466
} /* iso_find_dir_entry */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   467
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   468
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   469
static int iso_read_ext_attributes(ISO9660Handle *handle, int block,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   470
                                   ISO9660ExtAttributeRec *attributes)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   471
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   472
    return iso_readimage(handle, block * 2048, attributes,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   473
                         sizeof(ISO9660ExtAttributeRec));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   474
} /* iso_read_ext_attributes */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   475
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   476
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   477
static int ISO9660_flush(PHYSFS_Io *io) { return 1;  /* no write support. */ }
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   478
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   479
static PHYSFS_Io *ISO9660_duplicate(PHYSFS_Io *_io)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   480
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   481
    BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL);  /* !!! FIXME: write me. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   482
} /* ISO9660_duplicate */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   483
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   484
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   485
static void ISO9660_destroy(PHYSFS_Io *io)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   486
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   487
    ISO9660FileHandle *fhandle = (ISO9660FileHandle*) io->opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   488
    fhandle->close(fhandle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   489
    allocator.Free(io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   490
} /* ISO9660_destroy */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   491
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   492
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   493
static PHYSFS_sint64 ISO9660_read(PHYSFS_Io *io, void *buf, PHYSFS_uint64 len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   494
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   495
    ISO9660FileHandle *fhandle = (ISO9660FileHandle*) io->opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   496
    return fhandle->read(fhandle, buf, len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   497
} /* ISO9660_read */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   498
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   499
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   500
static PHYSFS_sint64 ISO9660_write(PHYSFS_Io *io, const void *b, PHYSFS_uint64 l)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   501
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   502
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   503
} /* ISO9660_write */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   504
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   505
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   506
static PHYSFS_sint64 ISO9660_tell(PHYSFS_Io *io)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   507
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   508
    return ((ISO9660FileHandle*) io->opaque)->currpos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   509
} /* ISO9660_tell */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   510
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   511
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   512
static int ISO9660_seek(PHYSFS_Io *io, PHYSFS_uint64 offset)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   513
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   514
    ISO9660FileHandle *fhandle = (ISO9660FileHandle*) io->opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   515
    return fhandle->seek(fhandle, offset);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   516
} /* ISO9660_seek */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   517
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   518
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   519
static PHYSFS_sint64 ISO9660_length(PHYSFS_Io *io)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   520
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   521
    return ((ISO9660FileHandle*) io->opaque)->filesize;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   522
} /* ISO9660_length */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   523
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   524
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   525
static const PHYSFS_Io ISO9660_Io =
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   526
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   527
    CURRENT_PHYSFS_IO_API_VERSION, NULL,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   528
    ISO9660_read,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   529
    ISO9660_write,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   530
    ISO9660_seek,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   531
    ISO9660_tell,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   532
    ISO9660_length,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   533
    ISO9660_duplicate,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   534
    ISO9660_flush,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   535
    ISO9660_destroy
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   536
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   537
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   538
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   539
/*******************************************************************************
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   540
 * Archive management functions
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   541
 ******************************************************************************/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   542
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   543
static void *ISO9660_openArchive(PHYSFS_Io *io, const char *filename, int forWriting)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   544
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   545
    char magicnumber[6];
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   546
    ISO9660Handle *handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   547
    int founddescriptor = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   548
    int foundjoliet = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   549
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   550
    assert(io != NULL);  /* shouldn't ever happen. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   551
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   552
    BAIL_IF_MACRO(forWriting, PHYSFS_ERR_READ_ONLY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   553
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   554
    /* Skip system area to magic number in Volume descriptor */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   555
    BAIL_IF_MACRO(!io->seek(io, 32769), ERRPASS, NULL);
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   556
    BAIL_IF_MACRO(io->read(io, magicnumber, 5) != 5, ERRPASS, NULL);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   557
    if (memcmp(magicnumber, "CD001", 6) != 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   558
        BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   559
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   560
    handle = allocator.Malloc(sizeof(ISO9660Handle));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   561
    GOTO_IF_MACRO(!handle, PHYSFS_ERR_OUT_OF_MEMORY, errorcleanup);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   562
    handle->path = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   563
    handle->mutex= 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   564
    handle->io = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   565
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   566
    handle->path = allocator.Malloc(strlen(filename) + 1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   567
    GOTO_IF_MACRO(!handle->path, PHYSFS_ERR_OUT_OF_MEMORY, errorcleanup);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   568
    strcpy(handle->path, filename);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   569
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   570
    handle->mutex = __PHYSFS_platformCreateMutex();
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   571
    GOTO_IF_MACRO(!handle->mutex, ERRPASS, errorcleanup);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   572
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   573
    handle->io = io;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   574
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   575
    /* seek Primary Volume Descriptor */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   576
    GOTO_IF_MACRO(!io->seek(io, 32768), PHYSFS_ERR_IO, errorcleanup);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   577
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   578
    while (1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   579
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   580
        ISO9660VolumeDescriptor descriptor;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   581
        GOTO_IF_MACRO(io->read(io, &descriptor, sizeof(ISO9660VolumeDescriptor)) != sizeof(ISO9660VolumeDescriptor), PHYSFS_ERR_IO, errorcleanup);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   582
        GOTO_IF_MACRO(strncmp(descriptor.identifier, "CD001", 5) != 0, PHYSFS_ERR_UNSUPPORTED, errorcleanup);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   583
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   584
        if (descriptor.type == 255)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   585
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   586
            /* type 255 terminates the volume descriptor list */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   587
            if (founddescriptor)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   588
                return handle; /* ok, we've found one volume descriptor */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   589
            else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   590
                GOTO_MACRO(PHYSFS_ERR_CORRUPT, errorcleanup);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   591
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   592
        if (descriptor.type == 1 && !founddescriptor)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   593
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   594
            handle->currpos = io->tell(io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   595
            handle->rootdirstart =
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   596
                    descriptor.rootdirectory.extent_location * 2048;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   597
            handle->rootdirsize =
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   598
                    descriptor.rootdirectory.data_length;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   599
            handle->isjoliet = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   600
            founddescriptor = 1; /* continue search for joliet */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   601
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   602
        if (descriptor.type == 2 && !foundjoliet)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   603
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   604
            /* check if is joliet */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   605
            PHYSFS_uint8 *s = descriptor.escape_sequences;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   606
            int joliet = !(descriptor.flags & 1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   607
                    && (s[0] == 0x25)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   608
                    && (s[1] == 0x2F)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   609
                    && ((s[2] == 0x40) || (s[2] == 0x43) || (s[2] == 0x45));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   610
            if (!joliet)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   611
                continue;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   612
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   613
            handle->currpos = io->tell(io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   614
            handle->rootdirstart =
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   615
                    descriptor.rootdirectory.extent_location * 2048;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   616
            handle->rootdirsize =
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   617
                    descriptor.rootdirectory.data_length;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   618
            handle->isjoliet = 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   619
            founddescriptor = 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   620
            foundjoliet = 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   621
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   622
    } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   623
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   624
    GOTO_MACRO(PHYSFS_ERR_CORRUPT, errorcleanup);  /* not found. */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   625
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   626
errorcleanup:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   627
    if (handle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   628
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   629
        if (handle->path)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   630
            allocator.Free(handle->path);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   631
        if (handle->mutex)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   632
            __PHYSFS_platformDestroyMutex(handle->mutex);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   633
        allocator.Free(handle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   634
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   635
    return NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   636
} /* ISO9660_openArchive */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   637
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   638
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   639
static void ISO9660_closeArchive(void *opaque)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   640
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   641
    ISO9660Handle *handle = (ISO9660Handle*) opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   642
    handle->io->destroy(handle->io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   643
    __PHYSFS_platformDestroyMutex(handle->mutex);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   644
    allocator.Free(handle->path);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   645
    allocator.Free(handle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   646
} /* ISO9660_closeArchive */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   647
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   648
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   649
/*******************************************************************************
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   650
 * Read functions
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   651
 ******************************************************************************/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   652
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   653
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   654
static PHYSFS_uint32 iso_file_read_mem(ISO9660FileHandle *filehandle,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   655
                                       void *buffer, PHYSFS_uint64 len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   656
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   657
    /* check remaining bytes & max obj which can be fetched */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   658
    const PHYSFS_sint64 bytesleft = filehandle->filesize - filehandle->currpos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   659
    if (bytesleft < len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   660
        len = bytesleft;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   661
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   662
    if (len == 0)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   663
        return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   664
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   665
    memcpy(buffer, filehandle->cacheddata + filehandle->currpos, (size_t) len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   666
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   667
    filehandle->currpos += len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   668
    return (PHYSFS_uint32) len;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   669
} /* iso_file_read_mem */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   670
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   671
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   672
static int iso_file_seek_mem(ISO9660FileHandle *fhandle, PHYSFS_sint64 offset)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   673
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   674
    BAIL_IF_MACRO(offset < 0, PHYSFS_ERR_INVALID_ARGUMENT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   675
    BAIL_IF_MACRO(offset >= fhandle->filesize, PHYSFS_ERR_PAST_EOF, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   676
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   677
    fhandle->currpos = offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   678
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   679
} /* iso_file_seek_mem */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   680
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   681
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   682
static void iso_file_close_mem(ISO9660FileHandle *fhandle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   683
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   684
    allocator.Free(fhandle->cacheddata);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   685
    allocator.Free(fhandle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   686
} /* iso_file_close_mem */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   687
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   688
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   689
static PHYSFS_uint32 iso_file_read_foreign(ISO9660FileHandle *filehandle,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   690
                                           void *buffer, PHYSFS_uint64 len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   691
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   692
    /* check remaining bytes & max obj which can be fetched */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   693
    const PHYSFS_sint64 bytesleft = filehandle->filesize - filehandle->currpos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   694
    if (bytesleft < len)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   695
        len = bytesleft;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   696
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   697
    const PHYSFS_sint64 rc = filehandle->io->read(filehandle->io, buffer, len);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   698
    BAIL_IF_MACRO(rc == -1, ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   699
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   700
    filehandle->currpos += rc; /* i trust my internal book keeping */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   701
    BAIL_IF_MACRO(rc < len, PHYSFS_ERR_CORRUPT, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   702
    return rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   703
} /* iso_file_read_foreign */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   704
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   705
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   706
static int iso_file_seek_foreign(ISO9660FileHandle *fhandle,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   707
                                 PHYSFS_sint64 offset)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   708
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   709
    BAIL_IF_MACRO(offset < 0, PHYSFS_ERR_INVALID_ARGUMENT, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   710
    BAIL_IF_MACRO(offset >= fhandle->filesize, PHYSFS_ERR_PAST_EOF, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   711
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   712
    PHYSFS_sint64 pos = fhandle->startblock * 2048 + offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   713
    BAIL_IF_MACRO(!fhandle->io->seek(fhandle->io, pos), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   714
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   715
    fhandle->currpos = offset;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   716
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   717
} /* iso_file_seek_foreign */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   718
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   719
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   720
static void iso_file_close_foreign(ISO9660FileHandle *fhandle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   721
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   722
    fhandle->io->destroy(fhandle->io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   723
    allocator.Free(fhandle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   724
} /* iso_file_close_foreign */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   725
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   726
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   727
static int iso_file_open_mem(ISO9660Handle *handle, ISO9660FileHandle *fhandle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   728
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   729
    fhandle->cacheddata = allocator.Malloc(fhandle->filesize);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   730
    BAIL_IF_MACRO(!fhandle->cacheddata, PHYSFS_ERR_OUT_OF_MEMORY, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   731
    int rc = iso_readimage(handle, fhandle->startblock * 2048,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   732
                           fhandle->cacheddata, fhandle->filesize);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   733
    GOTO_IF_MACRO(rc < 0, ERRPASS, freemem);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   734
    GOTO_IF_MACRO(rc == 0, PHYSFS_ERR_CORRUPT, freemem);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   735
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   736
    fhandle->read = iso_file_read_mem;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   737
    fhandle->seek = iso_file_seek_mem;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   738
    fhandle->close = iso_file_close_mem;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   739
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   740
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   741
freemem:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   742
    allocator.Free(fhandle->cacheddata);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   743
    return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   744
} /* iso_file_open_mem */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   745
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   746
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   747
static int iso_file_open_foreign(ISO9660Handle *handle,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   748
                                 ISO9660FileHandle *fhandle)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   749
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   750
    int rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   751
    fhandle->io = __PHYSFS_createNativeIo(handle->path, 'r');
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   752
    BAIL_IF_MACRO(!fhandle->io, ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   753
    rc = fhandle->io->seek(fhandle->io, fhandle->startblock * 2048);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   754
    GOTO_IF_MACRO(!rc, ERRPASS, closefile);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   755
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   756
    fhandle->read = iso_file_read_foreign;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   757
    fhandle->seek = iso_file_seek_foreign;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   758
    fhandle->close = iso_file_close_foreign;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   759
    return 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   760
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   761
closefile:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   762
    fhandle->io->destroy(fhandle->io);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   763
    return -1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   764
} /* iso_file_open_foreign */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   765
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   766
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   767
static PHYSFS_Io *ISO9660_openRead(void *opaque, const char *filename)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   768
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   769
    PHYSFS_Io *retval = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   770
    ISO9660Handle *handle = (ISO9660Handle*) opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   771
    ISO9660FileHandle *fhandle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   772
    ISO9660FileDescriptor descriptor;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   773
    int rc;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   774
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   775
    fhandle = allocator.Malloc(sizeof(ISO9660FileHandle));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   776
    BAIL_IF_MACRO(fhandle == 0, PHYSFS_ERR_OUT_OF_MEMORY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   777
    fhandle->cacheddata = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   778
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   779
    retval = allocator.Malloc(sizeof(PHYSFS_Io));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   780
    GOTO_IF_MACRO(retval == 0, PHYSFS_ERR_OUT_OF_MEMORY, errorhandling);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   781
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   782
    /* find file descriptor */
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   783
    rc = iso_find_dir_entry(handle, filename, &descriptor);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   784
    GOTO_IF_MACRO(rc, ERRPASS, errorhandling);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   785
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   786
    fhandle->startblock = descriptor.extentpos + descriptor.extattributelen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   787
    fhandle->filesize = descriptor.datalen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   788
    fhandle->currpos = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   789
    fhandle->isohandle = handle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   790
    fhandle->cacheddata = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   791
    fhandle->io = NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   792
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   793
    if (descriptor.datalen <= ISO9660_FULLCACHEMAXSIZE)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   794
        rc = iso_file_open_mem(handle, fhandle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   795
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   796
        rc = iso_file_open_foreign(handle, fhandle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   797
    GOTO_IF_MACRO(rc, ERRPASS, errorhandling);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   798
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   799
    memcpy(retval, &ISO9660_Io, sizeof (PHYSFS_Io));
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   800
    retval->opaque = fhandle;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   801
    return retval;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   802
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   803
errorhandling:
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   804
    if (retval) allocator.Free(retval);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   805
    if (fhandle) allocator.Free(fhandle);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   806
    return NULL;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   807
} /* ISO9660_openRead */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   808
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   809
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   810
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   811
/*******************************************************************************
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   812
 * Information gathering functions
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   813
 ******************************************************************************/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   814
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   815
static void ISO9660_enumerateFiles(void *opaque, const char *dname,
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   816
                                   PHYSFS_EnumFilesCallback cb,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   817
                                   const char *origdir, void *callbackdata)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   818
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   819
    ISO9660Handle *handle = (ISO9660Handle*) opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   820
    ISO9660FileDescriptor descriptor;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   821
    PHYSFS_uint64 readpos;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   822
    PHYSFS_uint64 end_of_dir;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   823
    char filename[130]; /* ISO allows 31, Joliet 128 -> 128 + 2 eol bytes */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   824
    int version = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   825
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   826
    if (*dname == '\0')
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   827
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   828
        readpos = handle->rootdirstart;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   829
        end_of_dir = readpos + handle->rootdirsize;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   830
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   831
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   832
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   833
        printf("pfad %s\n",dname);
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   834
        BAIL_IF_MACRO(iso_find_dir_entry(handle,dname, &descriptor), ERRPASS,);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   835
        BAIL_IF_MACRO(!descriptor.flags.directory, ERRPASS,);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   836
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   837
        readpos = descriptor.extentpos * 2048;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   838
        end_of_dir = readpos + descriptor.datalen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   839
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   840
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   841
    while (1)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   842
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   843
        BAIL_IF_MACRO(iso_readfiledescriptor(handle, readpos, &descriptor), ERRPASS, );
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   844
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   845
        /* recordlen = 0 -> no more entries or fill entry */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   846
        if (!descriptor.recordlen)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   847
        {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   848
            /* if we are in the last sector of the directory & it's 0 -> end */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   849
            if ((end_of_dir - 2048) <= (readpos -1))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   850
                break;  /* finished */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   851
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   852
            /* else skip to the next sector & continue; */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   853
            readpos = (((readpos - 1) / 2048) + 1) * 2048;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   854
            continue;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   855
        } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   856
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   857
        readpos +=  descriptor.recordlen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   858
        if (descriptor.filenamelen == 1 && (descriptor.filename[0] == 0
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   859
                || descriptor.filename[0] == 1))
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   860
            continue; /* special ones, ignore */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   861
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   862
        strncpy(filename,descriptor.filename,descriptor.filenamelen);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   863
        iso_extractfilename(handle, &descriptor, filename, &version);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   864
        cb(callbackdata, origdir,filename);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   865
    } /* while */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   866
} /* ISO9660_enumerateFiles */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   867
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   868
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   869
static int ISO9660_stat(void *opaque, const char *name, PHYSFS_Stat *stat)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   870
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   871
    ISO9660Handle *handle = (ISO9660Handle*) opaque;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   872
    ISO9660FileDescriptor descriptor;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   873
    ISO9660ExtAttributeRec extattr;
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   874
    BAIL_IF_MACRO(iso_find_dir_entry(handle, name, &descriptor), ERRPASS, -1);
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   875
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   876
    stat->readonly = 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   877
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   878
    /* try to get extended info */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   879
    if (descriptor.extattributelen)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   880
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   881
        BAIL_IF_MACRO(iso_read_ext_attributes(handle,
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   882
                descriptor.extentpos, &extattr), ERRPASS, -1);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   883
        stat->createtime = iso_volume_mktime(&extattr.create_time);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   884
        stat->modtime = iso_volume_mktime(&extattr.mod_time);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   885
        stat->accesstime = iso_volume_mktime(&extattr.mod_time);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   886
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   887
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   888
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   889
        stat->createtime = iso_mktime(&descriptor.recordtime);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   890
        stat->modtime = iso_mktime(&descriptor.recordtime);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   891
        stat->accesstime = iso_mktime(&descriptor.recordtime);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   892
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   893
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   894
    if (descriptor.flags.directory)
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   895
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   896
        stat->filesize = 0;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   897
        stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   898
    } /* if */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   899
    else
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   900
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   901
        stat->filesize = descriptor.datalen;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   902
        stat->filetype = PHYSFS_FILETYPE_REGULAR;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   903
    } /* else */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   904
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   905
    return 1;
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   906
} /* ISO9660_stat */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   907
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   908
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   909
/*******************************************************************************
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   910
 * Not supported functions
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   911
 ******************************************************************************/
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   912
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   913
static PHYSFS_Io *ISO9660_openWrite(void *opaque, const char *name)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   914
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   915
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   916
} /* ISO9660_openWrite */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   917
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   918
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   919
static PHYSFS_Io *ISO9660_openAppend(void *opaque, const char *name)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   920
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   921
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, NULL);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   922
} /* ISO9660_openAppend */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   923
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   924
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   925
static int ISO9660_remove(void *opaque, const char *name)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   926
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   927
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   928
} /* ISO9660_remove */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   929
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   930
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   931
static int ISO9660_mkdir(void *opaque, const char *name)
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   932
{
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   933
    BAIL_MACRO(PHYSFS_ERR_READ_ONLY, 0);
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   934
} /* ISO9660_mkdir */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   935
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   936
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   937
const PHYSFS_Archiver __PHYSFS_Archiver_ISO9660 =
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   938
{
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   939
    CURRENT_PHYSFS_ARCHIVER_API_VERSION,
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   940
    {
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   941
        "ISO",
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   942
        "ISO9660 image file",
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   943
        "Christoph Nelles <evilazrael@evilazrael.de>",
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   944
        "https://www.evilazrael.de/",
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   945
        0,  /* supportsSymlinks */
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   946
    },
12218
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   947
    ISO9660_openArchive,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   948
    ISO9660_enumerateFiles,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   949
    ISO9660_openRead,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   950
    ISO9660_openWrite,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   951
    ISO9660_openAppend,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   952
    ISO9660_remove,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   953
    ISO9660_mkdir,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   954
    ISO9660_stat,
bb5522e88ab2 bulk copy of latest physfs to our misc/libphysfs since this seems to fix an off-by-1 error reliably hit in readln read of 1 byte probably introduced in the addition of the buffered read. Whether this is excessive or whether libphysfs should even be maintained by us is another matter. But at least we shouldn't crash
nemo
parents: 8524
diff changeset
   955
    ISO9660_closeArchive
7768
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   956
};
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   957
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   958
#endif  /* defined PHYSFS_SUPPORTS_ISO9660 */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   959
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   960
/* end of archiver_iso9660.c ... */
13e2037ebc79 Try using PhysicsFS.
unc0rr
parents:
diff changeset
   961