mtd/fs/jffs2 wbuf.c,1.49,1.50

David Woodhouse dwmw2 at infradead.org
Mon Oct 6 08:50:34 EDT 2003


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

Modified Files:
	wbuf.c 
Log Message:
Fix memcpy in case of wbuf-refill from _buf_ not wbuf

Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.49
retrieving revision 1.50
diff -u -r1.49 -r1.50
--- wbuf.c	4 Oct 2003 08:33:07 -0000	1.49
+++ wbuf.c	6 Oct 2003 12:50:31 -0000	1.50
@@ -176,10 +176,12 @@
 	jeb->dirty_size += jeb->wasted_size;
        	jeb->wasted_size = 0;
 
-	/* Find the first node to be recovered */
+	/* Find the first node to be recovered, by skipping over every
+	   node which ends before the wbuf starts, or which is obsolete. */
 	first_raw = &jeb->first_node;
-	while (*first_raw && !ref_obsolete(*first_raw) &&
-	       (ref_offset(*first_raw) + (*first_raw)->totlen) < c->wbuf_ofs) {
+	while (*first_raw && 
+	       (ref_obsolete(*first_raw) ||
+		(ref_offset(*first_raw) + (*first_raw)->totlen) < c->wbuf_ofs)) {
 		D1(printk(KERN_DEBUG "Skipping node at 0x%08x(%d)-0x%08x which is either before 0x%08x or obsolete\n",
 			  ref_offset(*first_raw), ref_flags(*first_raw),
 			  (ref_offset(*first_raw) + (*first_raw)->totlen),
@@ -305,17 +307,24 @@
 		}
 		printk(KERN_NOTICE "Recovery of wbuf succeeded to %08x\n", ofs);
 
-		c->wbuf_len = (end - start) - retlen;
-		c->wbuf_ofs = ofs + retlen;
-		memcpy(c->wbuf, buf + retlen, c->wbuf_len);
+		c->wbuf_len = (end - start) - towrite;
+		c->wbuf_ofs = ofs + towrite;
+		memcpy(c->wbuf, buf + towrite, c->wbuf_len);
 		/* Don't muck about with c->wbuf_inodes. False positives are harmless. */
 
+		kfree(buf);
 	} else {
-		/* OK, now we're left with the dregs in the wbuf */
-		memmove(c->wbuf, c->wbuf + (start - c->wbuf_ofs), end - start);
+		/* OK, now we're left with the dregs in whichever buffer we're using */
+		if (buf) {
+			memcpy(c->wbuf, buf, end-start);
+			kfree(buf);
+		} else {
+			memmove(c->wbuf, c->wbuf + (start - c->wbuf_ofs), end - start);
+		}
 		c->wbuf_ofs = ofs;
 		c->wbuf_len = end - start;
 	}
+
 	/* Now sort out the jffs2_raw_node_refs, moving them from the old to the next block */
 	new_jeb = &c->blocks[ofs / c->sector_size];
 




More information about the linux-mtd-cvs mailing list