mtd/fs/jffs2 compr_zlib.c,1.20,1.21

David Woodhouse dwmw2 at infradead.org
Fri Jan 10 06:42:38 EST 2003


Update of /home/cvs/mtd/fs/jffs2
In directory phoenix.infradead.org:/tmp/cvs-serv8237

Modified Files:
	compr_zlib.c 
Log Message:
Fix failure due to returning Z_STREAM_END on success instead of zero.
Also clean up the adler32-skip bits, so we fall back to a normal zlib 
invocation if we don't grok the incoming stream fully -- in case zlib 
_does_ manage to understand it.


Index: compr_zlib.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/compr_zlib.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- compr_zlib.c	10 Jan 2003 08:44:48 -0000	1.20
+++ compr_zlib.c	10 Jan 2003 11:42:35 -0000	1.21
@@ -112,16 +112,19 @@
 		goto out;
 	}
 
-	D1(printk(KERN_DEBUG "zlib compressed %ld bytes into %ld\n",
-		  def_strm.total_in, def_strm.total_out));
-
 	if (def_strm.total_out >= def_strm.total_in) {
+		D1(printk(KERN_DEBUG "zlib compressed %ld bytes into %ld; failing\n",
+			  def_strm.total_in, def_strm.total_out));
 		ret = -1;
 		goto out;
 	}
 
+	D1(printk(KERN_DEBUG "zlib compressed %ld bytes into %ld\n",
+		  def_strm.total_in, def_strm.total_out));
+
 	*dstlen = def_strm.total_out;
 	*sourcelen = def_strm.total_in;
+	ret = 0;
  out:
 	up(&deflate_sem);
 	return ret;
@@ -131,32 +134,39 @@
 		      uint32_t srclen, uint32_t destlen)
 {
 	int ret;
+	int wbits = MAX_WBITS;
 
 	down(&inflate_sem);
 
-	if (Z_OK != zlib_inflateInit2(&inf_strm, -MAX_WBITS)) {
-		printk(KERN_WARNING "inflateInit failed\n");
-		up(&inflate_sem);
-		return;
-	}
-	/* skip header and checksum test */
-	if( (data_in[0] & 0x0f) != Z_DEFLATED){
-		printk("unknown compression method\n");
-		up(&inflate_sem);
-		return;
-	}
-	if(data_in[1] & PRESET_DICT){
-		printk("dictionary not preset\n");
-		up(&inflate_sem);
-		return;
-	}
-	inf_strm.next_in = data_in + 2;
-	inf_strm.avail_in = srclen - 2;
+	inf_strm.next_in = data_in;
+	inf_strm.avail_in = srclen;
 	inf_strm.total_in = 0;
 	
 	inf_strm.next_out = cpage_out;
 	inf_strm.avail_out = destlen;
 	inf_strm.total_out = 0;
+
+	/* 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) &&
+	    ((data_in[0] & 0x0f) == Z_DEFLATED) &&
+	    !(((data_in[0]<<8) + data_in[1]) % 31)) {
+
+		D2(printk(KERN_DEBUG "inflate skipping adler32\n"));
+		wbits = -((data_in[0] >> 4) + 8);
+		inf_strm.next_in += 2;
+		inf_strm.avail_in -= 2;
+	} else {
+		/* Let this remain D1 for now -- it should never happen */
+		D1(printk(KERN_DEBUG "inflate not skipping adler32\n"));
+	}
+
+
+	if (Z_OK != zlib_inflateInit2(&inf_strm, wbits)) {
+		printk(KERN_WARNING "inflateInit failed\n");
+		up(&inflate_sem);
+		return;
+	}
 
 	while((ret = zlib_inflate(&inf_strm, Z_FINISH)) == Z_OK)
 		;





More information about the linux-mtd-cvs mailing list