[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / fs / cramfs / uncompress.c
blob5034365b06a862ac84470d560fc1684253d598ea
1 /*
2 * uncompress.c
4 * (C) Copyright 1999 Linus Torvalds
6 * cramfs interfaces to the uncompression library. There's really just
7 * three entrypoints:
9 * - cramfs_uncompress_init() - called to initialize the thing.
10 * - cramfs_uncompress_exit() - tell me when you're done
11 * - cramfs_uncompress_block() - uncompress a block.
13 * NOTE NOTE NOTE! The uncompression is entirely single-threaded. We
14 * only have one stream, and we'll initialize it only once even if it
15 * then is used by multiple filesystems.
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/vmalloc.h>
21 #include <linux/zlib.h>
23 static z_stream stream;
24 static int initialized;
26 /* Returns length of decompressed data. */
27 int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen)
29 int err;
31 stream.next_in = src;
32 stream.avail_in = srclen;
34 stream.next_out = dst;
35 stream.avail_out = dstlen;
37 err = zlib_inflateReset(&stream);
38 if (err != Z_OK) {
39 printk("zlib_inflateReset error %d\n", err);
40 zlib_inflateEnd(&stream);
41 zlib_inflateInit(&stream);
44 err = zlib_inflate(&stream, Z_FINISH);
45 if (err != Z_STREAM_END)
46 goto err;
47 return stream.total_out;
49 err:
50 printk("Error %d while decompressing!\n", err);
51 printk("%p(%d)->%p(%d)\n", src, srclen, dst, dstlen);
52 return 0;
55 int cramfs_uncompress_init(void)
57 if (!initialized++) {
58 stream.workspace = vmalloc(zlib_inflate_workspacesize());
59 if ( !stream.workspace ) {
60 initialized = 0;
61 return -ENOMEM;
63 stream.next_in = NULL;
64 stream.avail_in = 0;
65 zlib_inflateInit(&stream);
67 return 0;
70 int cramfs_uncompress_exit(void)
72 if (!--initialized) {
73 zlib_inflateEnd(&stream);
74 vfree(stream.workspace);
76 return 0;