[U-Boot] [PATCH 2/2] ubifs: BUG: Blocks commpressed with zlib

Ricardo Ribalda Delgado ricardo.ribalda at uam.es
Fri Apr 24 17:23:12 CEST 2009


Blocks compressed with zlib dont have the full gzip header.

This patch adds a new function to properly handle blocks compressed
with zlib.

Without this patch, block compressed with zlib cannot be readed!

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda at uam.es>
---
v3: return is not a function. prototypes in header
v2: remove unused parts..

 fs/ubifs/ubifs.c |   32 +++++++++++++++++++++++++++++++-
 fs/ubifs/ubifs.h |    5 +++--
 2 files changed, 34 insertions(+), 3 deletions(-)

diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c
index 3c8b5da..d80774c 100644
--- a/fs/ubifs/ubifs.c
+++ b/fs/ubifs/ubifs.c
@@ -24,6 +24,7 @@
  */
 
 #include "ubifs.h"
+#include <u-boot/zlib.h>
 
 #if !defined(CONFIG_SYS_64BIT_VSPRINTF)
 #warning Please define CONFIG_SYS_64BIT_VSPRINTF for correct output!
@@ -41,7 +42,7 @@ static int gzip_decompress(const unsigned char *in, size_t in_len,
 			   unsigned char *out, size_t *out_len)
 {
 	unsigned long len = in_len;
-	return gunzip(out, *out_len, (unsigned char *)in, &len);
+	return ubi_gunzip(out, *out_len, (unsigned char *)in, &len);
 }
 
 /* Fake description object for the "none" compressor */
@@ -686,3 +687,32 @@ out:
 	ubi_close_volume(c->ubi);
 	return err;
 }
+
+int ubi_gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp)
+{
+	z_stream s;
+	int r, flags;
+
+	s.zalloc = zalloc;
+	s.zfree = zfree;
+#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG)
+	s.outcb = (cb_func)WATCHDOG_RESET;
+#else
+	s.outcb = Z_NULL;
+#endif	/* CONFIG_HW_WATCHDOG */
+
+	r = inflateInit2(&s, -MAX_WBITS);
+	if (r != Z_OK) {
+		printf ("Error: inflateInit2() returned %d\n", r);
+		return -1;
+	}
+	s.next_in = src;
+	s.avail_in = *lenp;
+	s.next_out = dst;
+	s.avail_out = dstlen;
+	r = inflate(&s, Z_FINISH);
+	*lenp = s.next_out - (unsigned char *) dst;
+	inflateEnd(&s);
+
+	return 0;
+}
diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h
index 91351de..2e1680b 100644
--- a/fs/ubifs/ubifs.h
+++ b/fs/ubifs/ubifs.h
@@ -2172,6 +2172,7 @@ int ubifs_decompress(const void *buf, int len, void *out, int *out_len,
 /* todo: Move these to a common U-Boot header */
 int lzo1x_decompress_safe(const unsigned char *in, size_t in_len,
 			  unsigned char *out, size_t *out_len);
-int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
-
+int ubi_gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp);
+void *zalloc(void *, unsigned, unsigned);
+void zfree(void *, void *, unsigned);
 #endif /* !__UBIFS_H__ */
-- 
1.6.2.4



More information about the U-Boot mailing list