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 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/vmalloc.h>
21 #include <linux/zlib.h>
22 #include <linux/cramfs_fs.h>
24 static z_stream stream
;
25 static int initialized
;
27 /* Returns length of decompressed data. */
28 int cramfs_uncompress_block(void *dst
, int dstlen
, void *src
, int srclen
)
33 stream
.avail_in
= srclen
;
35 stream
.next_out
= dst
;
36 stream
.avail_out
= dstlen
;
38 err
= zlib_inflateReset(&stream
);
40 printk("zlib_inflateReset error %d\n", err
);
41 zlib_inflateEnd(&stream
);
42 zlib_inflateInit(&stream
);
45 err
= zlib_inflate(&stream
, Z_FINISH
);
46 if (err
!= Z_STREAM_END
)
48 return stream
.total_out
;
51 printk("Error %d while decompressing!\n", err
);
52 printk("%p(%d)->%p(%d)\n", src
, srclen
, dst
, dstlen
);
56 int cramfs_uncompress_init(void)
59 stream
.workspace
= vmalloc(zlib_inflate_workspacesize());
60 if ( !stream
.workspace
) {
64 stream
.next_in
= NULL
;
66 zlib_inflateInit(&stream
);
71 int cramfs_uncompress_exit(void)
74 zlib_inflateEnd(&stream
);
75 vfree(stream
.workspace
);