mtd/fs/jffs2 gc.c,1.111,1.112

David Woodhouse dwmw2 at infradead.org
Wed Oct 8 21:12:56 EDT 2003


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

Modified Files:
	gc.c 
Log Message:
Make it at least slightly saner.


Index: gc.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/gc.c,v
retrieving revision 1.111
retrieving revision 1.112
diff -u -r1.111 -r1.112
--- gc.c	9 Oct 2003 00:35:43 -0000	1.111
+++ gc.c	9 Oct 2003 01:12:53 -0000	1.112
@@ -1063,8 +1063,8 @@
 
 		struct jffs2_node_frag *frag;
 		uint32_t min, max;
-#error this code is untested and may eat your filesystem.
-		min = start & (PAGE_CACHE_SIZE-1);
+#error this code is tested and will eat your filesystem
+		min = start & ~(PAGE_CACHE_SIZE-1);
 		max = min + PAGE_CACHE_SIZE;
 
 		frag = jffs2_lookup_node_frag(&f->fragtree, start);
@@ -1079,14 +1079,14 @@
 			/* If the previous frag doesn't even reach the beginning, there's
 			   excessive fragmentation. Just merge. */
 			if (frag->ofs > min) {
-				D1(printk(KERN_DEBUG "Expanding to cover partial frag (0x%x-0x%x)\n",
+				D1(printk(KERN_DEBUG "Expanding down to cover partial frag (0x%x-0x%x)\n",
 					  frag->ofs, frag->ofs+frag->size));
 				start = frag->ofs;
 				continue;
 			}
 			/* OK. This frag holds the first byte of the page. */
 			if (!frag->node || !frag->node->raw) {
-				D1(printk(KERN_DEBUG "First frag in page is hole (0x%x-0x%x). Not expanding.\n",
+				D1(printk(KERN_DEBUG "First frag in page is hole (0x%x-0x%x). Not expanding down.\n",
 					  frag->ofs, frag->ofs+frag->size));
 				break;
 			} else {
@@ -1101,18 +1101,18 @@
 				jeb = &c->blocks[raw->flash_offset / c->sector_size];
 
 				if (jeb == c->gcblock) {
-					D1(printk(KERN_DEBUG "Expanding to cover frag (0x%x-0x%x) in gcblock at %08x\n",
+					D1(printk(KERN_DEBUG "Expanding down to cover frag (0x%x-0x%x) in gcblock at %08x\n",
 						  frag->ofs, frag->ofs+frag->size, ref_offset(raw)));
 					start = frag->ofs;
 					break;
 				}
 				if (!ISDIRTY(jeb->dirty_size + jeb->wasted_size)) {
-					D1(printk(KERN_DEBUG "Not expanding to cover frag (0x%x-0x%x) in clean block %08x\n",
+					D1(printk(KERN_DEBUG "Not expanding down to cover frag (0x%x-0x%x) in clean block %08x\n",
 						  frag->ofs, frag->ofs+frag->size, jeb->offset));
 					break;
 				}
 
-				D1(printk(KERN_DEBUG "Expanding to cover frag (0x%x-0x%x) in dirty block %08x\n",
+				D1(printk(KERN_DEBUG "Expanding down to cover frag (0x%x-0x%x) in dirty block %08x\n",
 						  frag->ofs, frag->ofs+frag->size, jeb->offset));
 				start = frag->ofs;
 				break;
@@ -1123,20 +1123,21 @@
 
 		/* Find last frag which is actually part of the node we're to GC. */
 		frag = jffs2_lookup_node_frag(&f->fragtree, end-1);
-
-		while((frag = frag_next(frag)) && frag->ofs+frag->size < max) {
+		D1(printk("for expand up, looked up frag at (0x%x-0x%x). Next %p\n", 
+			  frag->ofs, frag->ofs+frag->size, frag_next(frag)));
+		while((frag = frag_next(frag)) && frag->ofs+frag->size <= max) {
 
 			/* If the previous frag doesn't even reach the beginning, there's lots
 			   of fragmentation. Just merge. */
-			if (frag->ofs+frag->size < max-1) {
-				D1(printk(KERN_DEBUG "Expanding to cover partial frag (0x%x-0x%x)\n",
+			if (frag->ofs+frag->size < max) {
+				D1(printk(KERN_DEBUG "Expanding up to cover partial frag (0x%x-0x%x)\n",
 					  frag->ofs, frag->ofs+frag->size));
 				end = frag->ofs + frag->size;
 				continue;
 			}
 
 			if (!frag->node || !frag->node->raw) {
-				D1(printk(KERN_DEBUG "Last frag in page is hole (0x%x-0x%x). Not expanding.\n",
+				D1(printk(KERN_DEBUG "Last frag in page is hole (0x%x-0x%x). Not expanding up.\n",
 					  frag->ofs, frag->ofs+frag->size));
 				break;
 			} else {
@@ -1151,28 +1152,29 @@
 				jeb = &c->blocks[raw->flash_offset / c->sector_size];
 
 				if (jeb == c->gcblock) {
-					D1(printk(KERN_DEBUG "Expanding to cover frag (0x%x-0x%x) in gcblock at %08x\n",
+					D1(printk(KERN_DEBUG "Expanding up to cover frag (0x%x-0x%x) in gcblock at %08x\n",
 						  frag->ofs, frag->ofs+frag->size, ref_offset(raw)));
-					start = frag->ofs;
+					end = frag->ofs + frag->size;
 					break;
 				}
 				if (!ISDIRTY(jeb->dirty_size + jeb->wasted_size)) {
-					D1(printk(KERN_DEBUG "Not expanding to cover frag (0x%x-0x%x) in clean block %08x\n",
+					D1(printk(KERN_DEBUG "Not expanding up to cover frag (0x%x-0x%x) in clean block %08x\n",
 						  frag->ofs, frag->ofs+frag->size, jeb->offset));
 					break;
 				}
 
-				D1(printk(KERN_DEBUG "Expanding to cover frag (0x%x-0x%x) in dirty block %08x\n",
+				D1(printk(KERN_DEBUG "Expanding up to cover frag (0x%x-0x%x) in dirty block %08x\n",
 						  frag->ofs, frag->ofs+frag->size, jeb->offset));
-				start = frag->ofs;
+				end = frag->ofs + frag->size;
 				break;
 			}
 		}
-		BUG_ON(end > JFFS2_F_I_SIZE(f));
-		BUG_ON(end < orig_end);
-
 		D1(printk("Expanded dnode to write from (0x%x-0x%x) to (0x%x-0x%x)\n", 
 			  fn->ofs, orig_end, start, end));
+
+		BUG_ON(end > JFFS2_F_I_SIZE(f));
+		BUG_ON(end < orig_end);
+		BUG_ON(start > fn->ofs);
 	}
 	
 	/* First, use readpage() to read the appropriate page into the page cache */




More information about the linux-mtd-cvs mailing list