Blame view
fs/cramfs/uncompress.c
1.73 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
/* * uncompress.c * * (C) Copyright 1999 Linus Torvalds * * cramfs interfaces to the uncompression library. There's really just * three entrypoints: * * - cramfs_uncompress_init() - called to initialize the thing. * - cramfs_uncompress_exit() - tell me when you're done * - cramfs_uncompress_block() - uncompress a block. * * NOTE NOTE NOTE! The uncompression is entirely single-threaded. We * only have one stream, and we'll initialize it only once even if it * then is used by multiple filesystems. */ |
4f21e1ea0 fs/cramfs: use pr... |
17 |
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
1da177e4c Linux-2.6.12-rc2 |
18 19 20 21 |
#include <linux/kernel.h> #include <linux/errno.h> #include <linux/vmalloc.h> #include <linux/zlib.h> |
f7f4f4dd6 cramfs: take head... |
22 |
#include "internal.h" |
1da177e4c Linux-2.6.12-rc2 |
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
static z_stream stream; static int initialized; /* Returns length of decompressed data. */ int cramfs_uncompress_block(void *dst, int dstlen, void *src, int srclen) { int err; stream.next_in = src; stream.avail_in = srclen; stream.next_out = dst; stream.avail_out = dstlen; err = zlib_inflateReset(&stream); if (err != Z_OK) { |
f175ff810 fs/cramfs: conver... |
40 41 |
pr_err("zlib_inflateReset error %d ", err); |
1da177e4c Linux-2.6.12-rc2 |
42 43 44 45 46 47 48 49 50 51 |
zlib_inflateEnd(&stream); zlib_inflateInit(&stream); } err = zlib_inflate(&stream, Z_FINISH); if (err != Z_STREAM_END) goto err; return stream.total_out; err: |
f175ff810 fs/cramfs: conver... |
52 53 54 55 |
pr_err("Error %d while decompressing! ", err); pr_err("%p(%d)->%p(%d) ", src, srclen, dst, dstlen); |
98310e581 cramfs: propagate... |
56 |
return -EIO; |
1da177e4c Linux-2.6.12-rc2 |
57 58 59 60 61 62 |
} int cramfs_uncompress_init(void) { if (!initialized++) { stream.workspace = vmalloc(zlib_inflate_workspacesize()); |
31d92e551 fs/cramfs: code c... |
63 |
if (!stream.workspace) { |
1da177e4c Linux-2.6.12-rc2 |
64 65 66 67 68 69 70 71 72 |
initialized = 0; return -ENOMEM; } stream.next_in = NULL; stream.avail_in = 0; zlib_inflateInit(&stream); } return 0; } |
368bdb3d6 [PATCH] cramfs: m... |
73 |
void cramfs_uncompress_exit(void) |
1da177e4c Linux-2.6.12-rc2 |
74 75 76 77 78 |
{ if (!--initialized) { zlib_inflateEnd(&stream); vfree(stream.workspace); } |
1da177e4c Linux-2.6.12-rc2 |
79 |
} |