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