]> git.sesse.net Git - bcachefs-tools-debian/blob - include/linux/zutil.h
New setattr command
[bcachefs-tools-debian] / 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 <stdlib.h>
17 #include <string.h>
18 #include <linux/zlib.h>
19 #include <linux/string.h>
20 #include <linux/kernel.h>
21
22 typedef unsigned char  uch;
23 typedef unsigned short ush;
24 typedef unsigned long  ulg;
25
26         /* common constants */
27
28 #define STORED_BLOCK 0
29 #define STATIC_TREES 1
30 #define DYN_TREES    2
31 /* The three kinds of block type */
32
33 #define MIN_MATCH  3
34 #define MAX_MATCH  258
35 /* The minimum and maximum match lengths */
36
37 #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
38
39         /* target dependencies */
40
41         /* Common defaults */
42
43 #ifndef OS_CODE
44 #  define OS_CODE  0x03  /* assume Unix */
45 #endif
46
47          /* functions */
48
49 typedef uLong (*check_func) (uLong check, const Byte *buf,
50                                        uInt len);
51
52
53                         /* checksum functions */
54
55 #define BASE 65521L /* largest prime smaller than 65536 */
56 #define NMAX 5552
57 /* NMAX is the largest n such that 255n(n+1)/2 + (n+1)(BASE-1) <= 2^32-1 */
58
59 #define DO1(buf,i)  {s1 += buf[i]; s2 += s1;}
60 #define DO2(buf,i)  DO1(buf,i); DO1(buf,i+1);
61 #define DO4(buf,i)  DO2(buf,i); DO2(buf,i+2);
62 #define DO8(buf,i)  DO4(buf,i); DO4(buf,i+4);
63 #define DO16(buf)   DO8(buf,0); DO8(buf,8);
64
65 /* ========================================================================= */
66 /*
67      Update a running Adler-32 checksum with the bytes buf[0..len-1] and
68    return the updated checksum. If buf is NULL, this function returns
69    the required initial value for the checksum.
70    An Adler-32 checksum is almost as reliable as a CRC32 but can be computed
71    much faster. Usage example:
72
73      uLong adler = zlib_adler32(0L, NULL, 0);
74
75      while (read_buffer(buffer, length) != EOF) {
76        adler = zlib_adler32(adler, buffer, length);
77      }
78      if (adler != original_adler) error();
79 */
80 static inline uLong zlib_adler32(uLong adler,
81                                  const Byte *buf,
82                                  uInt len)
83 {
84     unsigned long s1 = adler & 0xffff;
85     unsigned long s2 = (adler >> 16) & 0xffff;
86     int k;
87
88     if (buf == NULL) return 1L;
89
90     while (len > 0) {
91         k = len < NMAX ? len : NMAX;
92         len -= k;
93         while (k >= 16) {
94             DO16(buf);
95             buf += 16;
96             k -= 16;
97         }
98         if (k != 0) do {
99             s1 += *buf++;
100             s2 += s1;
101         } while (--k);
102         s1 %= BASE;
103         s2 %= BASE;
104     }
105     return (s2 << 16) | s1;
106 }
107
108 #endif /* _Z_UTIL_H */