Skip to contentSkip to conversation

Remove JFFS2 dependency on internal Zlib header

PATCH In review Daniel Hazelton 2 participants 4 messages Jun 2, 2007 – Jun 3, 2007 Journalling flash file system V2 (JFFS2)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Remove JFFS2 dependency on internal Zlib header

History:
During the discussion over the speed and stability of the proposed inclusion
of a stripped-down, minimized version of the LZO compression algorithm it was noted that the way that patch handled separation of compression and decompression could be used for zlib as well. Then it was noted that moving the private zlib header 'zutil.h' to a combined zlib directory would break JFFS2, which used it. On examining JFFS2 it became clear that the only thing JFFS2 used the header for was a single constant. Since his code was involved, Mark Adler was contacted and he stated that that constant - PRESET_DICT - was part of the zlib standard and defined in RFC 1950. So, to remove the dependency the simplest recourse is to replace PRESET_DICT with the 'magic number' it represents.

DRH

fs/jffs2/compr_zlib.c +1 -2
index 2b87fcc..9f1b935 100644
@@ -16,7 +16,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/zlib.h>
-#include <linux/zutil.h>
 #include "nodelist.h"
 #include "compr.h"
 
@@ -154,7 +153,7 @@ static int jffs2_zlib_decompress(unsigned char *data_in,
 
        /* If it's deflate, and it's got no preset dictionary, then
           we can tell zlib to skip the adler32 check. */
-       if (srclen > 2 && !(data_in[1] & PRESET_DICT) &&
+       if (srclen > 2 && !(data_in[1] & 0x20) &&
            ((data_in[0] & 0x0f) == Z_DEFLATED) &&
            !(((data_in[0]<<8) + data_in[1]) % 31)) {
fs/jffs2/compr_zlib.c +1 -2
index 2b87fcc..9f1b935 100644
@@ -16,7 +16,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/zlib.h>
-#include <linux/zutil.h>
 #include "nodelist.h"
 #include "compr.h"
 
@@ -154,7 +153,7 @@ static int jffs2_zlib_decompress(unsigned char *data_in,
 
 	/* If it's deflate, and it's got no preset dictionary, then
 	   we can tell zlib to skip the adler32 check. */
-	if (srclen > 2 && !(data_in[1] & PRESET_DICT) &&
+	if (srclen > 2 && !(data_in[1] & 0x20) &&
 	    ((data_in[0] & 0x0f) == Z_DEFLATED) &&
 	    !(((data_in[0]<<8) + data_in[1]) % 31)) {
 
#1 lore raw
Quoted 18 lines · Daniel Hazelton

DRH

fs/jffs2/compr_zlib.c +0 -1
index 2b87fcc..9f1b935 100644
@@ -16,7 +16,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/zlib.h>
-#include <linux/zutil.h>
 #include "nodelist.h"
 #include "compr.h"
 

fs/jffs2/compr_zlib.c static int jffs2_zlib_decompress(unsigned char *data_in, · line 159

Quoted 8 lines
fs/jffs2/compr_zlib.c +1 -1
@@ -154,7 +153,7 @@ static int jffs2_zlib_decompress(unsigned char *data_in,
 
        /* If it's deflate, and it's got no preset dictionary, then
           we can tell zlib to skip the adler32 check. */
-       if (srclen > 2 && !(data_in[1] & PRESET_DICT) &&
+       if (srclen > 2 && !(data_in[1] & 0x20) &&
            ((data_in[0] & 0x0f) == Z_DEFLATED) &&
            !(((data_in[0]<<8) + data_in[1]) % 31)) {
 

Why not

#define PRESET_DICT 0x20

instead of obfuscating the code with a magic number ? (Or name it differently if it clashes with something else...)

Cheers,

Prakash

#2 lore raw
Quoted 31 lines · On Saturday 02 June 2007 20:21:13 Prakash Punnoor wrote:
Quoted 17 lines · Daniel Hazelton

DRH

fs/jffs2/compr_zlib.c +0 -1
index 2b87fcc..9f1b935 100644
@@ -16,7 +16,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/zlib.h>
-#include <linux/zutil.h>
 #include "nodelist.h"
 #include "compr.h"
 

fs/jffs2/compr_zlib.c static int jffs2_zlib_decompress(unsigned char · line 159

Quoted 8 lines
fs/jffs2/compr_zlib.c +1 -1
@@ -154,7 +153,7 @@ static int jffs2_zlib_decompress(unsigned char
 *data_in,
 
        /* If it's deflate, and it's got no preset dictionary, then
           we can tell zlib to skip the adler32 check. */
-       if (srclen > 2 && !(data_in[1] & PRESET_DICT) &&
+       if (srclen > 2 && !(data_in[1] & 0x20) &&
            ((data_in[0] & 0x0f) == Z_DEFLATED) &&
            !(((data_in[0]<<8) + data_in[1]) % 31)) {

Why not

#define PRESET_DICT 0x20

Quoted 7 lines

instead of obfuscating the code with a magic number ? (Or name it differently if it clashes with something else...)

Cheers,

Prakash

Not a problem. This patch was just a result of a quick s/PRESET_DICT/0x20/p - I'll change the patch so there is a localized PRESET_DICT macro.

I've attached an updated patch that does just that.

(Mark Adler suggested a second, more involved patch that would put the burdon of all the checking that JFFS2 is doing where it belongs, and already is done actually, zlib's inflate() )

DRH

fs/jffs2/compr_zlib.c +7 -1
index 2b87fcc..f4519db 100644
@@ -16,7 +16,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/zlib.h>
-#include <linux/zutil.h>
 #include "nodelist.h"
 #include "compr.h"
 
@@ -29,6 +28,13 @@
        */
 #define STREAM_END_SPACE 12
 
+/*
+ * PRESET_DICT is set in the internal (aka: private) zlib header zutil.h
+ * the value - 0x20 - is defined in RFC 1950, so making a duplicate
+ * definition here to remove this code's dependency on that file is safe.
+ */
+#define PRESET_DICT 0x20
+
 static DEFINE_MUTEX(deflate_mutex);
 static DEFINE_MUTEX(inflate_mutex);
 static z_stream inf_strm, def_strm;
fs/jffs2/compr_zlib.c +7 -1
index 2b87fcc..f4519db 100644
@@ -16,7 +16,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/zlib.h>
-#include <linux/zutil.h>
 #include "nodelist.h"
 #include "compr.h"
 
@@ -29,6 +28,13 @@
 	*/
 #define STREAM_END_SPACE 12
 
+/*
+ * PRESET_DICT is set in the internal (aka: private) zlib header zutil.h
+ * the value - 0x20 - is defined in RFC 1950, so making a duplicate
+ * definition here to remove this code's dependency on that file is safe.
+ */
+#define PRESET_DICT 0x20
+
 static DEFINE_MUTEX(deflate_mutex);
 static DEFINE_MUTEX(inflate_mutex);
 static z_stream inf_strm, def_strm;
#3 lore raw

PATCH 1/1 Remove JFFS2 dependency on internal Zlib header (take 2)

In reply to Prakash Punnoor

No code besides zlib itself should depend on linux/zutil.h - the only item JFFS2 uses from that header is a constant that is defined in RFC 1950 and should never change. This patch mirrors the #define in zutil.h and removes the #include.

DRH

fs/jffs2/compr_zlib.c +7 -1
index 2b87fcc..f4519db 100644
@@ -16,7 +16,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/zlib.h>
-#include <linux/zutil.h>
 #include "nodelist.h"
 #include "compr.h"
 
@@ -29,6 +28,13 @@
        */
 #define STREAM_END_SPACE 12
 
+/*
+ * PRESET_DICT is set in the internal (aka: private) zlib header zutil.h
+ * the value - 0x20 - is defined in RFC 1950, so making a duplicate
+ * definition here to remove this code's dependency on that file is safe.
+ */
+#define PRESET_DICT 0x20
+
 static DEFINE_MUTEX(deflate_mutex);
 static DEFINE_MUTEX(inflate_mutex);
 static z_stream inf_strm, def_strm;
fs/jffs2/compr_zlib.c +7 -1
index 2b87fcc..f4519db 100644
@@ -16,7 +16,6 @@
 #include <linux/kernel.h>
 #include <linux/slab.h>
 #include <linux/zlib.h>
-#include <linux/zutil.h>
 #include "nodelist.h"
 #include "compr.h"
 
@@ -29,6 +28,13 @@
 	*/
 #define STREAM_END_SPACE 12
 
+/*
+ * PRESET_DICT is set in the internal (aka: private) zlib header zutil.h
+ * the value - 0x20 - is defined in RFC 1950, so making a duplicate
+ * definition here to remove this code's dependency on that file is safe.
+ */
+#define PRESET_DICT 0x20
+
 static DEFINE_MUTEX(deflate_mutex);
 static DEFINE_MUTEX(inflate_mutex);
 static z_stream inf_strm, def_strm;