xref: /openbmc/u-boot/lib/zlib/inflate.h (revision e89516f0)
1*e89516f0SMike Frysinger /* inflate.h -- internal inflate state definition
2*e89516f0SMike Frysinger  * Copyright (C) 1995-2004 Mark Adler
3*e89516f0SMike Frysinger  * For conditions of distribution and use, see copyright notice in zlib.h
4*e89516f0SMike Frysinger  */
5*e89516f0SMike Frysinger 
6*e89516f0SMike Frysinger /* WARNING: this file should *not* be used by applications. It is
7*e89516f0SMike Frysinger    part of the implementation of the compression library and is
8*e89516f0SMike Frysinger    subject to change. Applications should only use zlib.h.
9*e89516f0SMike Frysinger  */
10*e89516f0SMike Frysinger 
11*e89516f0SMike Frysinger /* define NO_GZIP when compiling if you want to disable gzip header and
12*e89516f0SMike Frysinger    trailer decoding by inflate().  NO_GZIP would be used to avoid linking in
13*e89516f0SMike Frysinger    the crc code when it is not needed.  For shared libraries, gzip decoding
14*e89516f0SMike Frysinger    should be left enabled. */
15*e89516f0SMike Frysinger #ifndef NO_GZIP
16*e89516f0SMike Frysinger #  define GUNZIP
17*e89516f0SMike Frysinger #endif
18*e89516f0SMike Frysinger 
19*e89516f0SMike Frysinger /* Possible inflate modes between inflate() calls */
20*e89516f0SMike Frysinger typedef enum {
21*e89516f0SMike Frysinger     HEAD,       /* i: waiting for magic header */
22*e89516f0SMike Frysinger     FLAGS,      /* i: waiting for method and flags (gzip) */
23*e89516f0SMike Frysinger     TIME,       /* i: waiting for modification time (gzip) */
24*e89516f0SMike Frysinger     OS,         /* i: waiting for extra flags and operating system (gzip) */
25*e89516f0SMike Frysinger     EXLEN,      /* i: waiting for extra length (gzip) */
26*e89516f0SMike Frysinger     EXTRA,      /* i: waiting for extra bytes (gzip) */
27*e89516f0SMike Frysinger     NAME,       /* i: waiting for end of file name (gzip) */
28*e89516f0SMike Frysinger     COMMENT,    /* i: waiting for end of comment (gzip) */
29*e89516f0SMike Frysinger     HCRC,       /* i: waiting for header crc (gzip) */
30*e89516f0SMike Frysinger     DICTID,     /* i: waiting for dictionary check value */
31*e89516f0SMike Frysinger     DICT,       /* waiting for inflateSetDictionary() call */
32*e89516f0SMike Frysinger         TYPE,       /* i: waiting for type bits, including last-flag bit */
33*e89516f0SMike Frysinger         TYPEDO,     /* i: same, but skip check to exit inflate on new block */
34*e89516f0SMike Frysinger         STORED,     /* i: waiting for stored size (length and complement) */
35*e89516f0SMike Frysinger         COPY,       /* i/o: waiting for input or output to copy stored block */
36*e89516f0SMike Frysinger         TABLE,      /* i: waiting for dynamic block table lengths */
37*e89516f0SMike Frysinger         LENLENS,    /* i: waiting for code length code lengths */
38*e89516f0SMike Frysinger         CODELENS,   /* i: waiting for length/lit and distance code lengths */
39*e89516f0SMike Frysinger             LEN,        /* i: waiting for length/lit code */
40*e89516f0SMike Frysinger             LENEXT,     /* i: waiting for length extra bits */
41*e89516f0SMike Frysinger             DIST,       /* i: waiting for distance code */
42*e89516f0SMike Frysinger             DISTEXT,    /* i: waiting for distance extra bits */
43*e89516f0SMike Frysinger             MATCH,      /* o: waiting for output space to copy string */
44*e89516f0SMike Frysinger             LIT,        /* o: waiting for output space to write literal */
45*e89516f0SMike Frysinger     CHECK,      /* i: waiting for 32-bit check value */
46*e89516f0SMike Frysinger     LENGTH,     /* i: waiting for 32-bit length (gzip) */
47*e89516f0SMike Frysinger     DONE,       /* finished check, done -- remain here until reset */
48*e89516f0SMike Frysinger     BAD,        /* got a data error -- remain here until reset */
49*e89516f0SMike Frysinger     MEM,        /* got an inflate() memory error -- remain here until reset */
50*e89516f0SMike Frysinger     SYNC        /* looking for synchronization bytes to restart inflate() */
51*e89516f0SMike Frysinger } inflate_mode;
52*e89516f0SMike Frysinger 
53*e89516f0SMike Frysinger /*
54*e89516f0SMike Frysinger     State transitions between above modes -
55*e89516f0SMike Frysinger 
56*e89516f0SMike Frysinger     (most modes can go to the BAD or MEM mode -- not shown for clarity)
57*e89516f0SMike Frysinger 
58*e89516f0SMike Frysinger     Process header:
59*e89516f0SMike Frysinger         HEAD -> (gzip) or (zlib)
60*e89516f0SMike Frysinger         (gzip) -> FLAGS -> TIME -> OS -> EXLEN -> EXTRA -> NAME
61*e89516f0SMike Frysinger         NAME -> COMMENT -> HCRC -> TYPE
62*e89516f0SMike Frysinger         (zlib) -> DICTID or TYPE
63*e89516f0SMike Frysinger         DICTID -> DICT -> TYPE
64*e89516f0SMike Frysinger     Read deflate blocks:
65*e89516f0SMike Frysinger             TYPE -> STORED or TABLE or LEN or CHECK
66*e89516f0SMike Frysinger             STORED -> COPY -> TYPE
67*e89516f0SMike Frysinger             TABLE -> LENLENS -> CODELENS -> LEN
68*e89516f0SMike Frysinger     Read deflate codes:
69*e89516f0SMike Frysinger                 LEN -> LENEXT or LIT or TYPE
70*e89516f0SMike Frysinger                 LENEXT -> DIST -> DISTEXT -> MATCH -> LEN
71*e89516f0SMike Frysinger                 LIT -> LEN
72*e89516f0SMike Frysinger     Process trailer:
73*e89516f0SMike Frysinger         CHECK -> LENGTH -> DONE
74*e89516f0SMike Frysinger  */
75*e89516f0SMike Frysinger 
76*e89516f0SMike Frysinger /* state maintained between inflate() calls.  Approximately 7K bytes. */
77*e89516f0SMike Frysinger struct inflate_state {
78*e89516f0SMike Frysinger     inflate_mode mode;          /* current inflate mode */
79*e89516f0SMike Frysinger     int last;                   /* true if processing last block */
80*e89516f0SMike Frysinger     int wrap;                   /* bit 0 true for zlib, bit 1 true for gzip */
81*e89516f0SMike Frysinger     int havedict;               /* true if dictionary provided */
82*e89516f0SMike Frysinger     int flags;                  /* gzip header method and flags (0 if zlib) */
83*e89516f0SMike Frysinger     unsigned dmax;              /* zlib header max distance (INFLATE_STRICT) */
84*e89516f0SMike Frysinger     unsigned long check;        /* protected copy of check value */
85*e89516f0SMike Frysinger     unsigned long total;        /* protected copy of output count */
86*e89516f0SMike Frysinger     gz_headerp head;            /* where to save gzip header information */
87*e89516f0SMike Frysinger         /* sliding window */
88*e89516f0SMike Frysinger     unsigned wbits;             /* log base 2 of requested window size */
89*e89516f0SMike Frysinger     unsigned wsize;             /* window size or zero if not using window */
90*e89516f0SMike Frysinger     unsigned whave;             /* valid bytes in the window */
91*e89516f0SMike Frysinger     unsigned write;             /* window write index */
92*e89516f0SMike Frysinger     unsigned char FAR *window;  /* allocated sliding window, if needed */
93*e89516f0SMike Frysinger         /* bit accumulator */
94*e89516f0SMike Frysinger     unsigned long hold;         /* input bit accumulator */
95*e89516f0SMike Frysinger     unsigned bits;              /* number of bits in "in" */
96*e89516f0SMike Frysinger         /* for string and stored block copying */
97*e89516f0SMike Frysinger     unsigned length;            /* literal or length of data to copy */
98*e89516f0SMike Frysinger     unsigned offset;            /* distance back to copy string from */
99*e89516f0SMike Frysinger         /* for table and code decoding */
100*e89516f0SMike Frysinger     unsigned extra;             /* extra bits needed */
101*e89516f0SMike Frysinger         /* fixed and dynamic code tables */
102*e89516f0SMike Frysinger     code const FAR *lencode;    /* starting table for length/literal codes */
103*e89516f0SMike Frysinger     code const FAR *distcode;   /* starting table for distance codes */
104*e89516f0SMike Frysinger     unsigned lenbits;           /* index bits for lencode */
105*e89516f0SMike Frysinger     unsigned distbits;          /* index bits for distcode */
106*e89516f0SMike Frysinger         /* dynamic table building */
107*e89516f0SMike Frysinger     unsigned ncode;             /* number of code length code lengths */
108*e89516f0SMike Frysinger     unsigned nlen;              /* number of length code lengths */
109*e89516f0SMike Frysinger     unsigned ndist;             /* number of distance code lengths */
110*e89516f0SMike Frysinger     unsigned have;              /* number of code lengths in lens[] */
111*e89516f0SMike Frysinger     code FAR *next;             /* next available space in codes[] */
112*e89516f0SMike Frysinger     unsigned short lens[320];   /* temporary storage for code lengths */
113*e89516f0SMike Frysinger     unsigned short work[288];   /* work area for code table building */
114*e89516f0SMike Frysinger     code codes[ENOUGH];         /* space for code tables */
115*e89516f0SMike Frysinger };
116