mtd/fs/jffs2 read.c,1.27,1.28

David Woodhouse dwmw2 at infradead.org
Fri Nov 8 12:19:02 EST 2002


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

Modified Files:
	read.c 
Log Message:
Fix long-standing hole thinko

Index: read.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/read.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- read.c	6 Sep 2002 14:12:44 -0000	1.27
+++ read.c	8 Nov 2002 17:18:59 -0000	1.28
@@ -192,20 +192,27 @@
 			continue;
 		} else {
 			uint32_t readlen;
-			readlen = min(frag->size, end - offset);
-			D1(printk(KERN_DEBUG "Reading %d-%d from node at 0x%x\n", frag->ofs, frag->ofs+readlen, ref_offset(frag->node->raw)));
-			ret = jffs2_read_dnode(c, frag->node, buf, frag->ofs - frag->node->ofs, readlen);
+			uint32_t fragofs; /* offset within the frag to start reading */
+			
+			fragofs = offset - frag->ofs;
+			readlen = min(frag->size - fragofs, end - offset);
+			D1(printk(KERN_DEBUG "Reading %d-%d from node at 0x%x\n", frag->ofs+fragofs, frag->ofs+fragofs+readlen, 
+				  ref_offset(frag->node->raw)));
+			ret = jffs2_read_dnode(c, frag->node, buf, fragofs + frag->ofs - frag->node->ofs, readlen);
 			D2(printk(KERN_DEBUG "node read done\n"));
 			if (ret) {
 				D1(printk(KERN_DEBUG"jffs2_read_inode_range error %d\n",ret));
-				memset(buf, 0, frag->size);
+				memset(buf, 0, readlen);
 				return ret;
 			}
+			buf += readlen;
+			offset += readlen;
+			frag = frag_next(frag);
+			D2(printk(KERN_DEBUG "node read was OK. Looping\n"));
+			continue;
 		}
-		buf += frag->size;
-		offset += frag->size;
-		frag = frag_next(frag);
-		D2(printk(KERN_DEBUG "node read was OK. Looping\n"));
+		printk(KERN_CRIT "dwmw2 is stupid. Reason #5325\n");
+		BUG();
 	}
 	return 0;
 }





More information about the linux-mtd-cvs mailing list