4 * Copyright (C) 1999 Linus Torvalds
5 * Copyright (C) 2000-2002 Transmeta Corporation
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License (Version 2) as
9 * published by the Free Software Foundation.
11 * cramfs interfaces to the uncompression library. There's really just
14 * - cramfs_uncompress_init() - called to initialize the thing.
15 * - cramfs_uncompress_exit() - tell me when you're done
16 * - cramfs_uncompress_block() - uncompress a block.
18 * NOTE NOTE NOTE! The uncompression is entirely single-threaded. We
19 * only have one stream, and we'll initialize it only once even if it
20 * then is used by multiple filesystems.
23 #include <linux/kernel.h>
24 #include <linux/errno.h>
25 #include <linux/vmalloc.h>
26 #include <linux/zlib.h>
28 static z_stream stream;
29 static int initialized;
31 /* Returns length of decompressed data. */
32 int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen)
37 stream.avail_in = srclen;
39 stream.next_out = dst;
40 stream.avail_out = dstlen;
42 err = zlib_inflateReset(&stream);
44 printk("zlib_inflateReset error %d\n", err);
45 zlib_inflateEnd(&stream);
46 zlib_inflateInit(&stream);
49 err = zlib_inflate(&stream, Z_FINISH);
50 if (err != Z_STREAM_END)
52 return stream.total_out;
55 printk("Error %d while decompressing!\n", err);
56 printk("%p(%d)->%p(%d)\n", src, srclen, dst, dstlen);
60 int cramfs_uncompress_init(void)
63 stream.workspace = vmalloc(zlib_inflate_workspacesize());
64 if ( !stream.workspace ) {
68 stream.next_in = NULL;
70 zlib_inflateInit(&stream);
75 int cramfs_uncompress_exit(void)
78 zlib_inflateEnd(&stream);
79 vfree(stream.workspace);