nfs: new subdir Documentation/filesystems/nfs
[safe/jmp/linux-2.6] / lib / decompress_inflate.c
index 163e66a..fc686c7 100644 (file)
 #include "zlib_inflate/inflate.h"
 
 #include "zlib_inflate/infutil.h"
+#include <linux/slab.h>
 
 #endif /* STATIC */
 
 #include <linux/decompress/mm.h>
 
-#define INBUF_LEN (16*1024)
+#define GZIP_IOBUF_SIZE (16*1024)
+
+static int nofill(void *buffer, unsigned int len)
+{
+       return -1;
+}
 
 /* Included from initramfs et al code */
 STATIC int INIT gunzip(unsigned char *buf, int len,
@@ -41,7 +47,7 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
        set_error_fn(error_fn);
        rc = -1;
        if (flush) {
-               out_len = 0x8100; /* 32 K */
+               out_len = 0x8000; /* 32 K */
                out_buf = malloc(out_len);
        } else {
                out_len = 0x7fffffff; /* no limit */
@@ -54,7 +60,7 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
        if (buf)
                zbuf = buf;
        else {
-               zbuf = malloc(INBUF_LEN);
+               zbuf = malloc(GZIP_IOBUF_SIZE);
                len = 0;
        }
        if (!zbuf) {
@@ -75,8 +81,11 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
                goto gunzip_nomem4;
        }
 
+       if (!fill)
+               fill = nofill;
+
        if (len == 0)
-               len = fill(zbuf, INBUF_LEN);
+               len = fill(zbuf, GZIP_IOBUF_SIZE);
 
        /* verify the gzip header */
        if (len < 10 ||
@@ -97,7 +106,7 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
                        strm->next_in++;
                strm->next_in++;
        }
-       strm->avail_in = len - 10;
+       strm->avail_in = len - (strm->next_in - zbuf);
 
        strm->next_out = out_buf;
        strm->avail_out = out_len;
@@ -112,7 +121,7 @@ STATIC int INIT gunzip(unsigned char *buf, int len,
        while (rc == Z_OK) {
                if (strm->avail_in == 0) {
                        /* TODO: handle case where both pos and fill are set */
-                       len = fill(zbuf, INBUF_LEN);
+                       len = fill(zbuf, GZIP_IOBUF_SIZE);
                        if (len < 0) {
                                rc = -1;
                                error("read error");