From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 7/8] Add deflate_decompress function
Date: Tue, 6 Aug 2013 15:07:07 +0200 [thread overview]
Message-ID: <1375794428-29577-8-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1375794428-29577-1-git-send-email-s.hauer@pengutronix.de>
Needed to implement decompressors for gzip without headers.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/linux/zlib.h | 4 ++++
lib/decompress_inflate.c | 39 +++++++++++++++++++++++++++++++++++++++
2 files changed, 43 insertions(+)
diff --git a/include/linux/zlib.h b/include/linux/zlib.h
index d8bd20c..a3e006b 100644
--- a/include/linux/zlib.h
+++ b/include/linux/zlib.h
@@ -31,6 +31,7 @@
#define _ZLIB_H
#include <linux/zconf.h>
+#include <linux/types.h>
/* zlib deflate based on ZLIB_VERSION "1.1.3" */
/* zlib inflate based on ZLIB_VERSION "1.2.3" */
@@ -708,4 +709,7 @@ extern int zlib_inflateInit2(z_streamp strm, int windowBits);
* return len or negative error code. */
extern int zlib_inflate_blob(void *dst, unsigned dst_sz, const void *src, unsigned src_sz);
+int deflate_decompress(struct z_stream_s *s, const u8 *src, unsigned int slen,
+ u8 *dst, unsigned int *dlen);
+
#endif /* _ZLIB_H */
diff --git a/lib/decompress_inflate.c b/lib/decompress_inflate.c
index 5c1ebb6..d5ea01a 100644
--- a/lib/decompress_inflate.c
+++ b/lib/decompress_inflate.c
@@ -183,4 +183,43 @@ gunzip_nomem1:
return rc; /* returns Z_OK (0) if successful */
}
+int deflate_decompress(struct z_stream_s *stream, const u8 *src, unsigned int slen, u8 *dst,
+ unsigned int *dlen)
+{
+
+ int ret = 0;
+
+ ret = zlib_inflateReset(stream);
+ if (ret != Z_OK) {
+ ret = -EINVAL;
+ goto out;
+ }
+
+ stream->next_in = (u8 *)src;
+ stream->avail_in = slen;
+ stream->next_out = (u8 *)dst;
+ stream->avail_out = *dlen;
+
+ ret = zlib_inflate(stream, Z_SYNC_FLUSH);
+ /*
+ * Work around a bug in zlib, which sometimes wants to taste an extra
+ * byte when being used in the (undocumented) raw deflate mode.
+ * (From USAGI).
+ */
+ if (ret == Z_OK && !stream->avail_in && stream->avail_out) {
+ u8 zerostuff = 0;
+ stream->next_in = &zerostuff;
+ stream->avail_in = 1;
+ ret = zlib_inflate(stream, Z_FINISH);
+ }
+ if (ret != Z_STREAM_END) {
+ ret = -EINVAL;
+ goto out;
+ }
+ ret = 0;
+ *dlen = stream->total_out;
+out:
+ return ret;
+}
+
#define decompress gunzip
--
1.8.4.rc1
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-08-06 13:07 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-06 13:07 [PATCH] UBIFS support Sascha Hauer
2013-08-06 13:07 ` [PATCH 1/8] mtd: ubi: add missing prototype for ubi_volume_notify Sascha Hauer
2013-08-06 13:07 ` [PATCH 2/8] mtd: ubi: add ubi info functions Sascha Hauer
2013-08-06 13:07 ` [PATCH 3/8] filetype: Add ubifs detection Sascha Hauer
2013-08-06 13:07 ` [PATCH 4/8] mtd: ubi: Add support for opening a volume by cdev Sascha Hauer
2013-08-06 13:07 ` [PATCH 5/8] move print_hex_dump function to include/common.h Sascha Hauer
2013-08-06 13:07 ` [PATCH 6/8] extend barebox wrapper header Sascha Hauer
2013-08-06 13:07 ` Sascha Hauer [this message]
2013-08-06 13:07 ` [PATCH 8/8] fs: Add ubifs support Sascha Hauer
2013-08-06 18:16 ` Alexander Aring
2013-08-06 19:50 ` Sascha Hauer
2013-08-06 23:50 ` Alexander Aring
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1375794428-29577-8-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox