| From Aaditya.Kumar@ap.sony.com Fri Nov 23 03:47:49 2012 |
| From: Aaditya Kumar <aaditya.kumar@ap.sony.com> |
| Date: Fri, 23 Nov 2012 17:12:07 +0530 |
| Subject: [PATCH v2 RESEND 11/15] AXFS: axfs_uncompress.c |
| To: Greg KH <gregkh@linuxfoundation.org> |
| Cc: "ltsi-dev@lists.linuxfoundation.org" <ltsi-dev@lists.linuxfoundation.org>, tim.bird@am.sony.com, frank.rowand@am.sony.com, takuzo.ohara@ap.sony.com, amit.agarwal@ap.sony.com, kan.iibuchi@jp.sony.com, aaditya.kumar.30@gmail.com |
| Message-ID: <50AF610F.3000208@ap.sony.com> |
| |
| |
| From: Jared Hulbert <jaredeh@gmail.com> |
| |
| AXFS interfaces to the uncompression library |
| |
| Signed-off-by: Jared Hulbert <jaredeh@gmail.com> |
| Signed-off-by: Aaditya Kumar <aaditya.kumar@ap.sony.com> |
| --- |
| fs/axfs/axfs_uncompress.c | 90 ++++++++++++++++++++++++++++++++++++++++++++++ |
| 1 file changed, 90 insertions(+) |
| create mode 100644 fs/axfs/axfs_uncompress.c |
| |
| --- /dev/null |
| +++ b/fs/axfs/axfs_uncompress.c |
| @@ -0,0 +1,90 @@ |
| +/* |
| + * Advanced XIP File System for Linux - AXFS |
| + * Readonly, compressed, and XIP filesystem for Linux systems big and small |
| + * |
| + * Modified in 2006 by Eric Anderson |
| + * from the cramfs sources fs/cramfs/uncompress.c |
| + * |
| + * (C) Copyright 1999 Linus Torvalds |
| + * |
| + * axfs_uncompress.c - |
| + * axfs interfaces to the uncompression library. There's really just |
| + * three entrypoints: |
| + * |
| + * - axfs_uncompress_init() - called to initialize the thing. |
| + * - axfs_uncompress_exit() - tell me when you're done |
| + * - axfs_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. |
| + * |
| + */ |
| + |
| +#include <linux/errno.h> |
| +#include <linux/vmalloc.h> |
| +#include <linux/zlib.h> |
| +#include <linux/init.h> |
| +#include <linux/mutex.h> |
| + |
| +static z_stream stream; |
| +static DEFINE_MUTEX(axfs_uncmp_mutex); |
| + |
| +int axfs_uncompress_block(void *dst, int dstlen, void *src, int srclen) |
| +{ |
| + int err; |
| + int out; |
| + |
| + mutex_lock(&axfs_uncmp_mutex); |
| + |
| + stream.next_in = src; |
| + stream.avail_in = srclen; |
| + |
| + stream.next_out = dst; |
| + stream.avail_out = dstlen; |
| + |
| + err = zlib_inflateReset(&stream); |
| + if (err != Z_OK) { |
| + printk(KERN_ERR "axfs: zlib_inflateReset error %d\n", err); |
| + zlib_inflateEnd(&stream); |
| + zlib_inflateInit(&stream); |
| + } |
| + |
| + err = zlib_inflate(&stream, Z_FINISH); |
| + if (err != Z_STREAM_END) |
| + goto err; |
| + |
| + out = stream.total_out; |
| + |
| + mutex_unlock(&axfs_uncmp_mutex); |
| + |
| + return out; |
| + |
| +err: |
| + |
| + mutex_unlock(&axfs_uncmp_mutex); |
| + |
| + printk(KERN_ERR "axfs: error %d while decompressing!\n", err); |
| + printk(KERN_ERR "%p(%d)->%p(%d)\n", src, srclen, dst, dstlen); |
| + return 0; |
| +} |
| + |
| +int __init axfs_uncompress_init(void) |
| +{ |
| + |
| + stream.workspace = vmalloc(zlib_inflate_workspacesize()); |
| + if (!stream.workspace) |
| + return -ENOMEM; |
| + stream.next_in = NULL; |
| + stream.avail_in = 0; |
| + zlib_inflateInit(&stream); |
| + |
| + return 0; |
| +} |
| + |
| +int axfs_uncompress_exit(void) |
| +{ |
| + zlib_inflateEnd(&stream); |
| + vfree(stream.workspace); |
| + return 0; |
| +} |