[U-Boot] [PATCH 1/2] lib_generic: gunzip: New function zunzip

Separate gunzip in
gunzip: Find the end of the header and call zunzip. zunzip: Inflate gunzip block without header.
Signed-off-by: Ricardo Ribalda Delgado ricardo.ribalda@uam.es --- lib_generic/gunzip.c | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/lib_generic/gunzip.c b/lib_generic/gunzip.c index 01a4031..d59a448 100644 --- a/lib_generic/gunzip.c +++ b/lib_generic/gunzip.c @@ -39,6 +39,8 @@ int gunzip(void *, int, unsigned char *, unsigned long *); void *zalloc(void *, unsigned, unsigned); void zfree(void *, void *, unsigned); +int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, + int stoponerr, int offset);
void *zalloc(void *x, unsigned items, unsigned size) { @@ -59,8 +61,7 @@ void zfree(void *x, void *addr, unsigned nb)
int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) { - z_stream s; - int r, i, flags; + int i, flags;
/* skip header */ i = 10; @@ -84,6 +85,18 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) return (-1); }
+ return zunzip(dst, dstlen, src, lenp, 1, i); +} + +/* + * Uncompress blocks compressed with zlib without headers + */ +int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, + int stoponerr, int offset) +{ + z_stream s; + int r; + s.zalloc = zalloc; s.zfree = zfree; #if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) @@ -95,14 +108,14 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) r = inflateInit2(&s, -MAX_WBITS); if (r != Z_OK) { printf ("Error: inflateInit2() returned %d\n", r); - return (-1); + return -1; } - s.next_in = src + i; - s.avail_in = *lenp - i; + s.next_in = src + offset; + s.avail_in = *lenp - offset; s.next_out = dst; s.avail_out = dstlen; r = inflate(&s, Z_FINISH); - if (r != Z_STREAM_END) { + if ((r != Z_STREAM_END) && (stoponerr==1)) { printf ("Error: inflate() returned %d\n", r); inflateEnd(&s); return (-1); @@ -110,5 +123,5 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) *lenp = s.next_out - (unsigned char *) dst; inflateEnd(&s);
- return (0); + return 0; }

Blocks compressed with zlib dont have the full gzip header.
Without this patch, block compressed with zlib cannot be readed!
Signed-off-by: Ricardo Ribalda Delgado ricardo.ribalda@uam.es --- v3: Create generic function zunzip v2: remove unused parts.
fs/ubifs/ubifs.c | 7 +++++-- fs/ubifs/ubifs.h | 2 -- 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/fs/ubifs/ubifs.c b/fs/ubifs/ubifs.c index 427d84a..739fb04 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! @@ -33,15 +34,17 @@ DECLARE_GLOBAL_DATA_PTR;
/* compress.c */
+int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp, + int stoponerr, int offset); /* - * We need a wrapper for gunzip() because the parameters are + * We need a wrapper for zunzip() because the parameters are * incompatible with the lzo decompressor. */ 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 zunzip(out, *out_len, (unsigned char *)in, &len, 0, 0); }
/* Fake description object for the "none" compressor */ diff --git a/fs/ubifs/ubifs.h b/fs/ubifs/ubifs.h index 91351de..a68e4c1 100644 --- a/fs/ubifs/ubifs.h +++ b/fs/ubifs/ubifs.h @@ -2172,6 +2172,4 @@ 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); - #endif /* !__UBIFS_H__ */

Dear Ricardo Ribalda Delgado,
In message 1240823996-10418-1-git-send-email-ricardo.ribalda@uam.es you wrote:
Separate gunzip in
gunzip: Find the end of the header and call zunzip. zunzip: Inflate gunzip block without header.
What is the needed for? Maybe you should provide a use case so we can see why this change makes sense.
Signed-off-by: Ricardo Ribalda Delgado ricardo.ribalda@uam.es
lib_generic/gunzip.c | 27 ++++++++++++++++++++------- 1 files changed, 20 insertions(+), 7 deletions(-)
diff --git a/lib_generic/gunzip.c b/lib_generic/gunzip.c index 01a4031..d59a448 100644 --- a/lib_generic/gunzip.c +++ b/lib_generic/gunzip.c @@ -39,6 +39,8 @@ int gunzip(void *, int, unsigned char *, unsigned long *); void *zalloc(void *, unsigned, unsigned); void zfree(void *, void *, unsigned); +int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
int stoponerr, int offset);
void *zalloc(void *x, unsigned items, unsigned size) { @@ -59,8 +61,7 @@ void zfree(void *x, void *addr, unsigned nb)
int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) {
- z_stream s;
- int r, i, flags;
int i, flags;
/* skip header */ i = 10;
@@ -84,6 +85,18 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) return (-1); }
- return zunzip(dst, dstlen, src, lenp, 1, i);
+}
+/*
- Uncompress blocks compressed with zlib without headers
- */
+int zunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp,
int stoponerr, int offset)
+{
- z_stream s;
- int r;
- s.zalloc = zalloc; s.zfree = zfree;
#if defined(CONFIG_HW_WATCHDOG) || defined(CONFIG_WATCHDOG) @@ -95,14 +108,14 @@ int gunzip(void *dst, int dstlen, unsigned char *src, unsigned long *lenp) r = inflateInit2(&s, -MAX_WBITS); if (r != Z_OK) { printf ("Error: inflateInit2() returned %d\n", r);
return (-1);
}return -1;
- s.next_in = src + i;
- s.avail_in = *lenp - i;
- s.next_in = src + offset;
- s.avail_in = *lenp - offset; s.next_out = dst; s.avail_out = dstlen; r = inflate(&s, Z_FINISH);
- if (r != Z_STREAM_END) {
- if ((r != Z_STREAM_END) && (stoponerr==1)) {
Seems this is an unrelated change. Maybe this should be split out into a separate patch?
Please comment what it means.
Best regards,
Wolfgang Denk

Hello Wolfgang
UBI fs blocks can be compresed in lzo, zlib or no-compression. The current implementation of u-boot supported all the compressions but there was a bug in the implementation of zlib. UBIFS's Zlib blocks do not have header but they were compressed using gunzip, a function used to decompress gunzip files/sectors with a header. This patch creates a functions that is able of decompress such a blocks.
Please comment what it means.
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de To the systems programmer, users and applications serve only to provide a test load.

Dear Ricardo Ribalda Delgado,
In message aa76a2be0904270234y4635b4dbj7de80cac751a2725@mail.gmail.com you wrote:
UBI fs blocks can be compresed in lzo, zlib or no-compression. The current implementation of u-boot supported all the compressions but there was a bug in the implementation of zlib. UBIFS's Zlib blocks do not have header but they were compressed using gunzip, a function used to decompress gunzip files/sectors with a header. This patch creates a functions that is able of decompress such a blocks.
Then please write this in the commit message of the patch.
Best regards,
Wolfgang Denk

Hello
Then please write this in the commit message of the patch.
It is already written in the ubifs patch (#2) Shall I also add this to this patch (#1), that only touches the gunzip file?
Regards
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de Niklaus Wirth has lamented that, whereas Europeans pronounce his name correctly (Ni-klows Virt), Americans invariably mangle it into (Nick- les Worth). Which is to say that Europeans call him by name, but Americans call him by value.

Dear Ricardo Ribalda Delgado,
In message aa76a2be0904270317h531e626bn4be3423963aa755@mail.gmail.com you wrote:
Then please write this in the commit message of the patch.
It is already written in the ubifs patch (#2) Shall I also add this to this patch (#1), that only touches the gunzip file?
How should anybody know why the gunzip file gets changed if there is no explanation given at all in the commit message?
How should he know that some other patch might be related when all he has is the commit logs?
Please add an explanation to the patch that says what the patch is changing, and why.
Please re-read http://www.denx.de/wiki/U-Boot/Patches
It says:
In the message body, include a description of your changes.
* For bug fixes: a description of the bug and how your patch fixes this bug. Please try to include a way of demonstrating that the patch actually fixes something. * For new features: a description of the feature and your implementation.
Best regards,
Wolfgang Denk

Dear Ricardo,
In message aa76a2be0904270234y4635b4dbj7de80cac751a2725@mail.gmail.com you wrote:
UBI fs blocks can be compresed in lzo, zlib or no-compression. The current implementation of u-boot supported all the compressions but there was a bug in the implementation of zlib. UBIFS's Zlib blocks do not have header but they were compressed using gunzip, a function used to decompress gunzip files/sectors with a header. This patch creates a functions that is able of decompress such a blocks.
BTW: what is patch 2/2 of this series? According to the References: header it's "[PATCH 2/2] ubifs: BUG: Blocks commpressed with zlib".
But then, what is the second patch for the "[PATCH 1/2] ubifs: BUG realpath string must be ended with NULL" posting?
In other words, we have 2 x [PATCH 1/2] but only one [PATCH 2/2] - or am I missing something?
Best regards,
Wolfgang Denk

Sorry for the mess.
There were 2 patch
1/2 ->: BUG realpath string must be ended with NULL" posting?
2/2 ->ubifs: BUG: Blocks commpressed with zlib"
Since 1/2 has been applied. And 2/2 needed to be separated in two patches
1/2 -> lib_generic: gunzip: New function zunzip 2/2 -> ubifs: BUG: Blocks commpressed with zlib
1/2 Creates a new zunzip function and 2/2 calls it.
On Mon, Apr 27, 2009 at 12:26, Wolfgang Denk wd@denx.de wrote:
Dear Ricardo,
In message aa76a2be0904270234y4635b4dbj7de80cac751a2725@mail.gmail.com you wrote:
UBI fs blocks can be compresed in lzo, zlib or no-compression. The current implementation of u-boot supported all the compressions but there was a bug in the implementation of zlib. UBIFS's Zlib blocks do not have header but they were compressed using gunzip, a function used to decompress gunzip files/sectors with a header. This patch creates a functions that is able of decompress such a blocks.
BTW: what is patch 2/2 of this series? According to the References: header it's "[PATCH 2/2] ubifs: BUG: Blocks commpressed with zlib".
But then, what is the second patch for the "[PATCH 1/2] ubifs: BUG realpath string must be ended with NULL" posting?
In other words, we have 2 x [PATCH 1/2] but only one [PATCH 2/2] - or am I missing something?
Best regards,
Wolfgang Denk
-- DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd@denx.de What kind of love is that? Not to be loved; never to have shown love. -- Commissioner Nancy Hedford, "Metamorphosis", stardate 3219.8

Dear Ricardo Ribalda Delgado,
In message aa76a2be0904270333j75bc9489p74071622499db34d@mail.gmail.com you wrote:
Sorry for the mess.
There were 2 patch
1/2 ->: BUG realpath string must be ended with NULL" posting?
2/2 ->ubifs: BUG: Blocks commpressed with zlib"
Since 1/2 has been applied. And 2/2 needed to be separated in two patches
The "realpath string must be ended with NULL" has been applied? This is news to me.
I don't have it in my trees.
Please explain what you mean?
1/2 -> lib_generic: gunzip: New function zunzip 2/2 -> ubifs: BUG: Blocks commpressed with zlib
In such a situation it would have been much better if you has reposted a new patch series consisting of 3 parts (1/3, 2/3 and 3/3).
On Mon, Apr 27, 2009 at 12:26, Wolfgang Denk wd@denx.de wrote:
Dear Ricardo,
In message aa76a2be0904270234y4635b4dbj7de80cac751a2725@mail.gmail.com =
you wrote:
...
PLEASE STOP TOP POSTING and FULL QUOTING.
PLEASE STOP TOP POSTING and FULL QUOTING.
PLEASE STOP TOP POSTING and FULL QUOTING.
PLEASE STOP TOP POSTING and FULL QUOTING.
PLEASE STOP TOP POSTING and FULL QUOTING.
Best regards,
Wolfgang Denk

Hi Wolfgang
In such a situation it would have been much better if you has reposted a new patch series consisting of 3 parts (1/3, 2/3 and 3/3).
Just sent a new patch series consisting 3 parts.
Sorry for the top posting...

On Monday 27 April 2009, Ricardo Ribalda Delgado wrote:
There were 2 patch
1/2 ->: BUG realpath string must be ended with NULL" posting?
2/2 ->ubifs: BUG: Blocks commpressed with zlib"
Since 1/2 has been applied. And 2/2 needed to be separated in two patches
Just to clarify: Patch 1/2 hasn't been applied yet. I "only" acked it. Wolfgang needs to apply it when he finds time.
Best regards, Stefan
===================================================================== DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-0 Fax: +49-8142-66989-80 Email: office@denx.de =====================================================================
participants (3)
-
Ricardo Ribalda Delgado
-
Stefan Roese
-
Wolfgang Denk