Merge branch 'master' of /usr/src/ntfs-2.6/
[pandora-kernel.git] / include / linux / zutil.h
1 /* zutil.h -- internal interface and configuration of the compression library
2  * Copyright (C) 1995-1998 Jean-loup Gailly.
3  * For conditions of distribution and use, see copyright notice in zlib.h
4  */
5
6 /* WARNING: this file should *not* be used by applications. It is
7    part of the implementation of the compression library and is
8    subject to change. Applications should only use zlib.h.
9  */
10
11 /* @(#) $Id: zutil.h,v 1.1 2000/01/01 03:32:23 davem Exp $ */
12
13 #ifndef _Z_UTIL_H
14 #define _Z_UTIL_H
15
16 #include <linux/zlib.h>
17 #include <linux/string.h>
18 #include <linux/kernel.h>
19
20 typedef unsigned char  uch;
21 typedef unsigned short ush;
22 typedef unsigned long  ulg;
23
24         /* common constants */
25
26 #ifndef DEF_WBITS
27 #  define DEF_WBITS MAX_WBITS
28 #endif
29 /* default windowBits for decompression. MAX_WBITS is for compression only */
30
31 #if MAX_MEM_LEVEL >= 8
32 #  define DEF_MEM_LEVEL 8
33 #else
34 #  define DEF_MEM_LEVEL  MAX_MEM_LEVEL
35 #endif
36 /* default memLevel */
37
38 #define STORED_BLOCK 0
39 #define STATIC_TREES 1
40 #define DYN_TREES    2
41 /* The three kinds of block type */
42
43 #define MIN_MATCH  3
44 #define MAX_MATCH  258
45 /* The minimum and maximum match lengths */
46
47 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
48
49         /* target dependencies */
50
51         /* Common defaults */
52
53 #ifndef OS_CODE
54 #  define OS_CODE  0x03  /* assume Unix */
55 #endif
56
57          /* functions */
58
59 typedef uLong (*check_func) (uLong check, const Byte *buf,
60                                        uInt len);
61
62
63                         /* checksum functions */
64
65 #define BASE 65521L /* largest prime smaller than 65536 */
66 #define NMAX 5552
67 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
68
69 #define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
70 #define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
71 #define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
72 #define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
73 #define DO16(buf)   DO8(buf,0); DO8(buf,8);
74
75 /* ========================================================================= */
76 /*
77      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
78    return the updated checksum. If buf is NULL, this function returns
79    the required initial value for the checksum.
80    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
81    much faster. Usage example:
82
83      uLong adler = adler32(0L, NULL, 0);
84
85      while (read_buffer(buffer, length) != EOF) {
86        adler = adler32(adler, buffer, length);
87      }
88      if (adler != original_adler) error();
89 */
90 static inline uLong zlib_adler32(uLong adler,
91                                  const Byte *buf,
92                                  uInt len)
93 {
94     unsigned long s1 = adler & 0xffff;
95     unsigned long s2 = (adler >> 16) & 0xffff;
96     int k;
97
98     if (buf == NULL) return 1L;
99
100     while (len > 0) {
101         k = len < NMAX ? len : NMAX;
102         len -= k;
103         while (k >= 16) {
104             DO16(buf);
105             buf += 16;
106             k -= 16;
107         }
108         if (k != 0) do {
109             s1 += *buf++;
110             s2 += s1;
111         } while (--k);
112         s1 %= BASE;
113         s2 %= BASE;
114     }
115     return (s2 << 16) | s1;
116 }
117
118 #endif /* _Z_UTIL_H */