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>
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
)
32 stream
.avail_in
= srclen
;
34 stream
.next_out
= dst
;
35 stream
.avail_out
= dstlen
;
37 err
= zlib_inflateReset(&stream
);
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
)
47 return stream
.total_out
;
50 printk("Error %d while decompressing!\n", err
);
51 printk("%p(%d)->%p(%d)\n", src
, srclen
, dst
, dstlen
);
55 int cramfs_uncompress_init(void)
58 stream
.workspace
= vmalloc(zlib_inflate_workspacesize());
59 if ( !stream
.workspace
) {
63 stream
.next_in
= NULL
;
65 zlib_inflateInit(&stream
);
70 int cramfs_uncompress_exit(void)
73 zlib_inflateEnd(&stream
);
74 vfree(stream
.workspace
);