jdk/src/java.base/share/native/libzip/zip_util.h
author chegar
Wed, 03 Dec 2014 14:22:58 +0000
changeset 27565 729f9700483a
parent 27084 d7fbf9a294af
child 29389 348a32f79d79
permissions -rw-r--r--
8049367: Modular Run-Time Images Reviewed-by: chegar, dfuchs, ihse, joehw, mullan, psandoz, wetmore Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, bradford.wetmore@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, james.laskey@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com, sundararajan.athijegannathan@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 18223
diff changeset
     2
 * Copyright (c) 1995, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5148
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * Prototypes for zip file support
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#ifndef _ZIP_H_
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
#define _ZIP_H_
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * Header signatures
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#define LOCSIG 0x04034b50L          /* "PK\003\004" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#define EXTSIG 0x08074b50L          /* "PK\007\008" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#define CENSIG 0x02014b50L          /* "PK\001\002" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#define ENDSIG 0x06054b50L          /* "PK\005\006" */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    41
#define ZIP64_ENDSIG 0x06064b50L    /* "PK\006\006" */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    42
#define ZIP64_LOCSIG 0x07064b50L    /* "PK\006\007" */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    43
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Header sizes including signatures
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    47
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
#define LOCHDR 30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
#define EXTHDR 16
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
#define CENHDR 46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
#define ENDHDR 22
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    53
#define ZIP64_ENDHDR 56       // ZIP64 end header size
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    54
#define ZIP64_LOCHDR 20       // ZIP64 end loc header size
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    55
#define ZIP64_EXTHDR 24       // EXT header size
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    56
#define ZIP64_EXTID   1       // Extra field Zip64 header ID
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    57
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    58
#define ZIP64_MAGICVAL 0xffffffffLL
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    59
#define ZIP64_MAGICCOUNT 0xffff
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    60
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    61
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Header field access macros
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
#define CH(b, n) (((unsigned char *)(b))[n])
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
#define SH(b, n) (CH(b, n) | (CH(b, n+1) << 8))
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    67
#define LG(b, n) ((SH(b, n) | (SH(b, n+2) << 16)) &0xffffffffUL)
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
    68
#define LL(b, n) (((jlong)LG(b, n)) | (((jlong)LG(b, n+4)) << 32))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
#define GETSIG(b) LG(b, 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * Macros for getting local file (LOC) header fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
#define LOCVER(b) SH(b, 4)          /* version needed to extract */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
#define LOCFLG(b) SH(b, 6)          /* general purpose bit flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
#define LOCHOW(b) SH(b, 8)          /* compression method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
#define LOCTIM(b) LG(b, 10)         /* modification time */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
#define LOCCRC(b) LG(b, 14)         /* crc of uncompressed data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
#define LOCSIZ(b) LG(b, 18)         /* compressed data size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
#define LOCLEN(b) LG(b, 22)         /* uncompressed data size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
#define LOCNAM(b) SH(b, 26)         /* filename length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
#define LOCEXT(b) SH(b, 28)         /* extra field length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Macros for getting extra local (EXT) header fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
#define EXTCRC(b) LG(b, 4)          /* crc of uncompressed data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
#define EXTSIZ(b) LG(b, 8)          /* compressed size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
#define EXTLEN(b) LG(b, 12)         /* uncompressed size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * Macros for getting central directory header (CEN) fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
#define CENVEM(b) SH(b, 4)          /* version made by */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
#define CENVER(b) SH(b, 6)          /* version needed to extract */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
#define CENFLG(b) SH(b, 8)          /* general purpose bit flags */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
#define CENHOW(b) SH(b, 10)         /* compression method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
#define CENTIM(b) LG(b, 12)         /* modification time */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
#define CENCRC(b) LG(b, 16)         /* crc of uncompressed data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
#define CENSIZ(b) LG(b, 20)         /* compressed size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
#define CENLEN(b) LG(b, 24)         /* uncompressed size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
#define CENNAM(b) SH(b, 28)         /* length of filename */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
#define CENEXT(b) SH(b, 30)         /* length of extra field */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
#define CENCOM(b) SH(b, 32)         /* file comment length */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
#define CENDSK(b) SH(b, 34)         /* disk number start */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
#define CENATT(b) SH(b, 36)         /* internal file attributes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
#define CENATX(b) LG(b, 38)         /* external file attributes */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
#define CENOFF(b) LG(b, 42)         /* offset of local header */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * Macros for getting end of central directory header (END) fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
#define ENDSUB(b) SH(b, 8)          /* number of entries on this disk */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
#define ENDTOT(b) SH(b, 10)         /* total number of entries */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
#define ENDSIZ(b) LG(b, 12)         /* central directory size */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
#define ENDOFF(b) LG(b, 16)         /* central directory offset */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
#define ENDCOM(b) SH(b, 20)         /* size of zip file comment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
/*
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   120
 * Macros for getting Zip64 end of central directory header fields
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   121
 */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   122
#define ZIP64_ENDLEN(b) LL(b, 4)      /* size of zip64 end of central dir */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   123
#define ZIP64_ENDVEM(b) SH(b, 12)     /* version made by */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   124
#define ZIP64_ENDVER(b) SH(b, 14)     /* version needed to extract */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   125
#define ZIP64_ENDNMD(b) LG(b, 16)     /* number of this disk */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   126
#define ZIP64_ENDDSK(b) LG(b, 20)     /* disk number of start */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   127
#define ZIP64_ENDTOD(b) LL(b, 24)     /* total number of entries on this disk */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   128
#define ZIP64_ENDTOT(b) LL(b, 32)     /* total number of entries */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   129
#define ZIP64_ENDSIZ(b) LL(b, 40)     /* central directory size in bytes */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   130
#define ZIP64_ENDOFF(b) LL(b, 48)     /* offset of first CEN header */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   131
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   132
/*
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   133
 * Macros for getting Zip64 end of central directory locator fields
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   134
 */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   135
#define ZIP64_LOCDSK(b) LG(b, 4)      /* disk number start */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   136
#define ZIP64_LOCOFF(b) LL(b, 8)      /* offset of zip64 end */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   137
#define ZIP64_LOCTOT(b) LG(b, 16)     /* total number of disks */
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   138
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   139
/*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * Supported compression methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
#define STORED      0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
#define DEFLATED    8
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * Support for reading ZIP/JAR files. Some things worth noting:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * - Zip file entries larger than 2**32 bytes are not supported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * - jzentry time and crc fields are signed even though they really
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *   represent unsigned quantities.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * - If csize is zero then the entry is uncompressed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * - If extra != 0 then the first two bytes are the length of the extra
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *   data in intel byte order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * - If pos <= 0 then it is the position of entry LOC header.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *   If pos > 0 then it is the position of entry data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *   pos should not be accessed directly, but only by ZIP_GetEntryDataOffset.
27084
d7fbf9a294af 8048025: Ensure cache consistency
sherman
parents: 25859
diff changeset
   157
 * - entry name may include embedded null character, use nlen for length
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
typedef struct jzentry {  /* Zip file entry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    char *name;           /* entry name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    jlong time;           /* modification time */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    jlong size;           /* size of uncompressed data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    jlong csize;          /* size of compressed data (zero if uncompressed) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    jint crc;             /* crc of uncompressed data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    char *comment;        /* optional zip file comment */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    jbyte *extra;         /* optional extra data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    jlong pos;            /* position of LOC header or entry data */
2592
ef26f663a2ba 4244499: ZipEntry() does not convert filenames from Unicode to platform
sherman
parents: 2438
diff changeset
   169
    jint flag;            /* general purpose flag */
27084
d7fbf9a294af 8048025: Ensure cache consistency
sherman
parents: 25859
diff changeset
   170
    jint nlen;            /* length of the entry name */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
} jzentry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * In-memory hash table cell.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * In a typical system we have a *lot* of these, as we have one for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * every entry in every active JAR.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * Note that in order to save space we don't keep the name in memory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * but merely remember a 32 bit hash.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
typedef struct jzcell {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    unsigned int hash;    /* 32 bit hashcode on name */
15256
9639ef45ef3e 8005466: JAR file entry hash table uses too much memory (zlib_util.c)
sherman
parents: 7668
diff changeset
   182
    unsigned int next;    /* hash chain: index into jzfile->entries */
2438
21c111b51aa8 4681995: Add support for large (> 4GB) zip/jar files
sherman
parents: 2163
diff changeset
   183
    jlong cenpos;         /* Offset of central directory file header */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
} jzcell;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
typedef struct cencache {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    char *data;           /* A cached page of CEN headers */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    jlong pos;            /* file offset of data */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
} cencache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
 * Use ZFILE to represent access to a file in a platform-indepenent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
 * fashion.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
#ifdef WIN32
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
#define ZFILE jlong
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
#else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
#define ZFILE int
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
#endif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
 * Descriptor for a ZIP file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
typedef struct jzfile {   /* Zip file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    char *name;           /* zip file name */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    jint refs;            /* number of active references */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    jlong len;            /* length (in bytes) of zip file */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
#ifdef USE_MMAP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    unsigned char *maddr; /* beginning address of the CEN & ENDHDR */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    jlong mlen;           /* length (in bytes) mmaped */
2074
346a841b2dcc 6599383: Unable to open zip files more than 2GB in size
kevinw
parents: 2
diff changeset
   211
    jlong offset;         /* offset of the mmapped region from the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                             start of the file. */
5148
2bf5469864ea 6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents: 3078
diff changeset
   213
    jboolean usemmap;     /* if mmap is used. */
2bf5469864ea 6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents: 3078
diff changeset
   214
#endif
18223
35a5c2462991 8008593: Better URLClassLoader resource management
chegar
parents: 15256
diff changeset
   215
    jboolean locsig;      /* if zip file starts with LOCSIG */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    cencache cencache;    /* CEN header cache */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    ZFILE zfd;            /* open file descriptor */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    void *lock;           /* read lock */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    char *comment;        /* zip file comment */
3078
c491f0d2a8aa 6707281: Adler32.update() JavaDoc is wrong
sherman
parents: 2592
diff changeset
   220
    jint clen;            /* length of the zip file comment */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    char *msg;            /* zip error message */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    jzcell *entries;      /* array of hash cells */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    jint total;           /* total number of entries */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    jint *table;          /* Hash chain heads: indexes into entries */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    jint tablelen;        /* number of hash heads */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    struct jzfile *next;  /* next zip file in search list */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    jzentry *cache;       /* we cache the most recently freed jzentry */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /* Information on metadata names in META-INF directory */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    char **metanames;     /* array of meta names (may have null names) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    jint metacurrent;     /* the next empty slot in metanames array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    jint metacount;       /* number of slots in metanames array */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    jlong lastModified;   /* last modified time */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    jlong locpos;         /* position of first LOC header (usually 0) */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
} jzfile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
 * Index representing end of hash chain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
#define ZIP_ENDCHAIN ((jint)-1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
jzentry * JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
ZIP_FindEntry(jzfile *zip, char *name, jint *sizeP, jint *nameLenP);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
jboolean JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
ZIP_ReadEntry(jzfile *zip, jzentry *entry, unsigned char *buf, char *entrynm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
jzentry * JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
ZIP_GetNextEntry(jzfile *zip, jint n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
jzfile * JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
ZIP_Open(const char *name, char **pmsg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
jzfile *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
ZIP_Open_Generic(const char *name, char **pmsg, int mode, jlong lastModified);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
jzfile *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
ZIP_Get_From_Cache(const char *name, char **pmsg, jlong lastModified);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
jzfile *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
ZIP_Put_In_Cache(const char *name, ZFILE zfd, char **pmsg, jlong lastModified);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
5148
2bf5469864ea 6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents: 3078
diff changeset
   262
jzfile *
2bf5469864ea 6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents: 3078
diff changeset
   263
ZIP_Put_In_Cache0(const char *name, ZFILE zfd, char **pmsg, jlong lastModified, jboolean usemmap);
2bf5469864ea 6929479: Add a system property sun.zip.disableMemoryMapping to disable mmap use in ZipFile
sherman
parents: 3078
diff changeset
   264
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
ZIP_Close(jzfile *zip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
jzentry * ZIP_GetEntry(jzfile *zip, char *name, jint ulen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
void ZIP_Lock(jzfile *zip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
void ZIP_Unlock(jzfile *zip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
jint ZIP_Read(jzfile *zip, jzentry *entry, jlong pos, void *buf, jint len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
void ZIP_FreeEntry(jzfile *zip, jzentry *ze);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
jlong ZIP_GetEntryDataOffset(jzfile *zip, jzentry *entry);
27084
d7fbf9a294af 8048025: Ensure cache consistency
sherman
parents: 25859
diff changeset
   274
jzentry * ZIP_GetEntry2(jzfile *zip, char *name, jint ulen, jboolean addSlash);
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27084
diff changeset
   275
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27084
diff changeset
   276
jboolean JNICALL
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27084
diff changeset
   277
ZIP_InflateFully(void *inBuf, jlong inLen, void *outBuf, jlong outLen, char **pmsg);
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 27084
diff changeset
   278
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
#endif /* !_ZIP_H_ */