]> granicus.if.org Git - zziplib/blob - zzip/format.h
This commit was generated by cvs2svn to compensate for changes in r97, which
[zziplib] / zzip / format.h
1 /*
2  * Author: 
3  *      Guido Draheim <guidod@gmx.de>
4  *
5  *      Copyright (c) 2000,2001,2002,2003 Guido Draheim
6  *          All rights reserved
7  *          use under the restrictions of the
8  *          Lesser GNU General Public License
9  *          or alternatively the restrictions 
10  *          of the Mozilla Public License 1.1
11  *
12  *  The information was taken from appnote-981119-iz.zip
13  *  at http://www.freesoftware.com/pub/infozip/doc/
14  *  which in turn is based on PKWARE's appnote.txt
15  */
16 #ifndef _ZZIP_FORMAT_H /* zzipformat.h */
17 #define _ZZIP_FORMAT_H
18  
19 #include <zzip/lib.h>
20 /* we have ICO C 9X types defined */
21
22 /* 
23  * Overall zipfile format 
24  *  [local file header + file data + data descriptr] ... [central directory] [EOD record] 
25  */
26  
27 # ifdef _MSC_VER
28 # pragma pack(push, 1)
29 # endif
30
31 struct zzip_version 
32
33     char   version[1]; 
34     char   ostype[1]; 
35 } __attribute__((packed));
36
37 struct zzip_dostime 
38
39     char   time[2]; 
40     char   date[2]; 
41 } __attribute__((packed)); 
42
43 #define ZZIP_CHECKMAGIC(__p,__A,__B,__C,__D) \
44     ( (((char*)(__p))[0]==(__A)) && \
45       (((char*)(__p))[1]==(__B)) && \
46       (((char*)(__p))[2]==(__C)) && \
47       (((char*)(__p))[3]==(__D)) )
48
49 /* A. Local file header */
50 struct zzip_file_header
51 {
52 #   define ZZIP_FILE_HEADER_MAGIC 0x04034b50
53 #   define ZZIP_FILE_HEADER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\3','\4')
54     char   z_magic[4]; /* local file header signature (0x04034b50) */
55     struct zzip_version z_extract; /* version needed to extract */
56     char   z_flags[2]; /* general purpose bit flag */
57     char   z_compr[2]; /* compression method */
58     struct zzip_dostime z_dostime; /* last mod file time (dos format) */
59     char   z_crc32[4]; /* crc-32 */
60     char   z_csize[4]; /* compressed size */
61     char   z_usize[4]; /* uncompressed size */
62     char   z_namlen[2]; /* filename length (null if stdin) */
63     char   z_extras[2]; /* extra field length */
64     /* followed by filename (of variable size) */
65     /* followed by extra field (of variable size) */
66 } __attribute__((packed));
67
68 /* B. data descriptor 
69  * the data descriptor exists only if bit 3 of z_flags is set. It is byte aligned
70  * and immediately follows the last byte of compressed data. It is only used if
71  * the output media of the compressor was not seekable, eg. standard output.
72  */
73 struct zzip_file_trailer
74 {
75 #   define ZZIP_FILE_TRAILER_MAGIC 0x08074B50
76 #   define ZZIP_FILE_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\7','\8')
77     uint32_t z_magic; /* data descriptor signature (0x08074b50) */
78     uint32_t z_crc32; /* crc-32 */
79     uint32_t z_csize; /* compressed size */
80     uint32_t z_usize; /* uncompressed size */
81 } __attribute__((packed));
82
83 /* C. central directory structure:
84     [file header] . . . end of central dir record  
85 */
86
87 /* directory file header 
88  * - a single entry including filename, extras and comment may not exceed 64k.
89  */
90
91 struct zzip_root_dirent
92 {
93 #   define ZZIP_ROOT_DIRENT_MAGIC 0x02014b50
94 #   define ZZIP_ROOT_DIRENT_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\1','\2')
95     char  z_magic[4];  /* central file header signature (0x02014b50) */
96     struct zzip_version z_encoder;  /* version made by */
97     struct zzip_version z_extract;  /* version need to extract */
98     char  z_flags[2];  /* general purpose bit flag */
99     char  z_compr[2];  /* compression method */
100     struct zzip_dostime z_dostime;  /* last mod file time&date (dos format) */
101     char  z_crc32[4];  /* crc-32 */
102     char  z_csize[4];  /* compressed size */
103     char  z_usize[4];  /* uncompressed size */
104     char  z_namlen[2]; /* filename length (null if stdin) */
105     char  z_extras[2];  /* extra field length */
106     char  z_comment[2]; /* file comment length */
107     char  z_diskstart[2]; /* disk number of start (if spanning zip over multiple disks) */
108     char  z_filetype[2];  /* internal file attributes, bit0 = ascii */
109     char  z_filemode[4];  /* extrnal file attributes, eg. msdos attrib byte */
110     char  z_off[4];    /* relative offset of local file header, seekval if singledisk */
111     /* followed by filename (of variable size) */
112     /* followed by extra field (of variable size) */
113     /* followed by file comment (of variable size) */
114 } __attribute__((packed)); 
115
116 /* end of central dir record */
117 struct zzip_disk_trailer
118 {
119 #   define ZZIP_DISK_TRAILER_MAGIC 0x06054b50
120 #   define ZZIP_DISK_TRAILER_CHECKMAGIC(__p) ZZIP_CHECKMAGIC(__p,'P','K','\5','\6')
121     char  z_magic[4]; /* end of central dir signature (0x06054b50) */
122     char  z_disk[2];  /* number of this disk */
123     char  z_finaldisk[2]; /* number of the disk with the start of the central dir */
124     char  z_entries[2]; /* total number of entries in the central dir on this disk */
125     char  z_finalentries[2]; /* total number of entries in the central dir */
126     char  z_rootsize[4]; /* size of the central directory */
127     char  z_rootseek[4]; /* offset of start of central directory with respect to *
128                           * the starting disk number */
129     char  z_comment[2];  /* zipfile comment length */
130     /* followed by zipfile comment (of variable size) */
131 } __attribute__((packed));
132
133 /* z_flags */
134 #define ZZIP_IS_ENCRYPTED(p)    ((*(unsigned char*)p)&1)
135 #define ZZIP_IS_COMPRLEVEL(p)  (((*(unsigned char*)p)>>1)&3)
136 #define ZZIP_IS_STREAMED(p)    (((*(unsigned char*)p)>>3)&1)
137
138 /* z_compr */
139 #define ZZIP_IS_STORED          0
140 #define ZZIP_IS_SHRUNK          1
141 #define ZZIP_IS_REDUCEDx1       2
142 #define ZZIP_IS_REDUCEDx2       3
143 #define ZZIP_IS_REDUCEDx3       4
144 #define ZZIP_IS_REDUCEDx4       5
145 #define ZZIP_IS_IMPLODED        6
146 #define ZZIP_IS_TOKENIZED       7
147 #define ZZIP_IS_DEFLATED        8
148 #define ZZIP_IS_DEFLATED_BETTER 9
149 #define ZZIP_IS_IMPLODED_BETTER 10
150
151 # ifdef _MSC_VER
152 # pragma pack(pop)
153 # endif
154
155 #endif /* _ZZIPFORMAT_H */
156
157
158
159