4 * (C) Copyright 1999 Linus Torvalds
6 * cramfs interfaces to the uncompression library. There's really just
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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
20 #include <linux/kernel.h>
21 #include <linux/errno.h>
22 #include <linux/vmalloc.h>
23 #include <linux/zlib.h>
26 static z_stream stream
;
27 static int initialized
;
29 /* Returns length of decompressed data. */
30 int cramfs_uncompress_block(void *dst
, int dstlen
, void *src
, int srclen
)
35 stream
.avail_in
= srclen
;
37 stream
.next_out
= dst
;
38 stream
.avail_out
= dstlen
;
40 err
= zlib_inflateReset(&stream
);
42 pr_err("zlib_inflateReset error %d\n", err
);
43 zlib_inflateEnd(&stream
);
44 zlib_inflateInit(&stream
);
47 err
= zlib_inflate(&stream
, Z_FINISH
);
48 if (err
!= Z_STREAM_END
)
50 return stream
.total_out
;
53 pr_err("Error %d while decompressing!\n", err
);
54 pr_err("%p(%d)->%p(%d)\n", src
, srclen
, dst
, dstlen
);
58 int cramfs_uncompress_init(void)
61 stream
.workspace
= vmalloc(zlib_inflate_workspacesize());
62 if (!stream
.workspace
) {
66 stream
.next_in
= NULL
;
68 zlib_inflateInit(&stream
);
73 void cramfs_uncompress_exit(void)
76 zlib_inflateEnd(&stream
);
77 vfree(stream
.workspace
);