mtd/fs/jffs2 compr.c,1.27,1.28 gc.c,1.127,1.128 nodelist.h,1.111,1.112 write.c,1.76,1.77

David Woodhouse dwmw2 at infradead.org
Tue Nov 18 16:14:04 EST 2003


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

Modified Files:
	compr.c gc.c nodelist.h write.c 
Log Message:
Change compress API to make disabling compression less messy

Index: compr.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/compr.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- compr.c	4 Oct 2003 08:33:06 -0000	1.27
+++ compr.c	18 Nov 2003 21:14:01 -0000	1.28
@@ -55,11 +55,17 @@
  * jffs2_compress should compress as much as will fit, and should set 
  * *datalen accordingly to show the amount of data which were compressed.
  */
-unsigned char jffs2_compress(unsigned char *data_in, unsigned char *cpage_out, 
+unsigned char jffs2_compress(unsigned char *data_in, unsigned char **cpage_out, 
 		    uint32_t *datalen, uint32_t *cdatalen)
 {
 	int ret;
 
+	*cpage_out = kmalloc(*cdatalen, GFP_KERNEL);
+	if (!*cpage_out) {
+		printk(KERN_WARNING "No memory for compressor allocation. Compression failed\n");
+		return JFFS2_COMPR_NONE;
+	}
+
 	ret = jffs2_zlib_compress(data_in, cpage_out, datalen, cdatalen);
 	if (!ret) {
 		return JFFS2_COMPR_ZLIB;
@@ -81,18 +87,18 @@
 	if (!ret) {
 		return JFFS2_COMPR_RTIME;
 	}
-#if 0
-	/* We don't need to copy. Let the caller special-case the COMPR_NONE case. */
-	/* If we get here, no compression is going to work */
-	/* But we might want to use the fragmentation part -- Arjan */
-	memcpy(cpage_out,data_in,min(*datalen,*cdatalen));
-	if (*datalen > *cdatalen)
-		*datalen = *cdatalen;
-#endif		
-	return JFFS2_COMPR_NONE; /* We failed to compress */
 
+	kfree(*cpage_out);
+	*cpage_out = data_in;
+	*datalen = *cdatalen;
+	return JFFS2_COMPR_NONE; /* We failed to compress */
 }
 
+void jffs2_free_comprbuf(unsigned char *orig, unsigned char *comprbuf)
+{
+	if (orig != comprbuf)
+		kfree(comprbuf);
+}
 
 int jffs2_decompress(unsigned char comprtype, unsigned char *cdata_in, 
 		     unsigned char *data_out, uint32_t cdatalen, uint32_t datalen)

Index: gc.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/gc.c,v
retrieving revision 1.127
retrieving revision 1.128
diff -u -r1.127 -r1.128
--- gc.c	4 Nov 2003 11:17:05 -0000	1.127
+++ gc.c	18 Nov 2003 21:14:01 -0000	1.128
@@ -1227,7 +1227,6 @@
 		return PTR_ERR(pg);
 	}
 	pg_ptr = (char *)kmap(pg);
-	comprbuf = kmalloc(end - start, GFP_KERNEL);
 
 	offset = start;
 	while(offset < orig_end) {
@@ -1247,14 +1246,8 @@
 
 		writebuf = pg_ptr + (offset & (PAGE_CACHE_SIZE -1));
 
-		if (comprbuf) {
-			comprtype = jffs2_compress(writebuf, comprbuf, &datalen, &cdatalen);
-		}
-		if (comprtype) {
-			writebuf = comprbuf;
-		} else {
-			datalen = cdatalen;
-		}
+		comprtype = jffs2_compress(writebuf, comprbuf, &datalen, &cdatalen);
+
 		ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
 		ri.nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
 		ri.totlen = cpu_to_je32(sizeof(ri) + cdatalen);
@@ -1276,7 +1269,9 @@
 		ri.node_crc = cpu_to_je32(crc32(0, &ri, sizeof(ri)-8));
 		ri.data_crc = cpu_to_je32(crc32(0, writebuf, cdatalen));
 	
-		new_fn = jffs2_write_dnode(c, f, &ri, writebuf, cdatalen, phys_ofs, ALLOC_GC);
+		new_fn = jffs2_write_dnode(c, f, &ri, comprbuf, cdatalen, phys_ofs, ALLOC_GC);
+
+		jffs2_free_comprbuf(comprbuf, writebuf);
 
 		if (IS_ERR(new_fn)) {
 			printk(KERN_WARNING "Error writing new dnode: %ld\n", PTR_ERR(new_fn));
@@ -1291,7 +1286,6 @@
 			f->metadata = NULL;
 		}
 	}
-	if (comprbuf) kfree(comprbuf);
 
 	kunmap(pg);
 	/* XXX: Does the page get freed automatically? */

Index: nodelist.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodelist.h,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -r1.111 -r1.112
--- nodelist.h	3 Nov 2003 17:33:54 -0000	1.111
+++ nodelist.h	18 Nov 2003 21:14:02 -0000	1.112
@@ -440,6 +440,7 @@
 /* compr.c */
 unsigned char jffs2_compress(unsigned char *data_in, unsigned char *cpage_out, 
 			     uint32_t *datalen, uint32_t *cdatalen);
+void jffs2_free_comprbuf(unsigned char *comprbuf, unsigned char *orig);
 int jffs2_decompress(unsigned char comprtype, unsigned char *cdata_in, 
 		     unsigned char *data_out, uint32_t cdatalen, uint32_t datalen);
 

Index: write.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/write.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -r1.76 -r1.77
--- write.c	16 Oct 2003 09:17:17 -0000	1.76
+++ write.c	18 Nov 2003 21:14:02 -0000	1.77
@@ -376,21 +376,7 @@
 		datalen = writelen;
 		cdatalen = min_t(uint32_t, alloclen - sizeof(*ri), writelen);
 
-		comprbuf = kmalloc(cdatalen, GFP_KERNEL);
-		if (comprbuf) {
-			comprtype = jffs2_compress(buf, comprbuf, &datalen, &cdatalen);
-		}
-		if (comprtype == JFFS2_COMPR_NONE) {
-			/* Either compression failed, or the allocation of comprbuf failed */
-			if (comprbuf)
-				kfree(comprbuf);
-			comprbuf = buf;
-			datalen = cdatalen;
-		}
-		/* Now comprbuf points to the data to be written, be it compressed or not.
-		   comprtype holds the compression type, and comprtype == JFFS2_COMPR_NONE means
-		   that the comprbuf doesn't need to be kfree()d. 
-		*/
+		comprtype = jffs2_compress(buf, &comprbuf, &datalen, &cdatalen);
 
 		ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK);
 		ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE);
@@ -409,8 +395,7 @@
 
 		fn = jffs2_write_dnode(c, f, ri, comprbuf, cdatalen, phys_ofs, ALLOC_NORETRY);
 
-		if (comprtype != JFFS2_COMPR_NONE)
-			kfree(comprbuf);
+		jffs2_free_comprbuf(comprbuf, buf);
 
 		if (IS_ERR(fn)) {
 			ret = PTR_ERR(fn);




More information about the linux-mtd-cvs mailing list