mtd/fs/jffs2 erase.c,1.53,1.54 gc.c,1.114,1.115 nodelist.c,1.80,1.81 nodelist.h,1.104,1.105 nodemgmt.c,1.102,1.103 scan.c,1.104,1.105 wbuf.c,1.53,1.54 write.c,1.75,1.76

David Woodhouse dwmw2 at infradead.org
Thu Oct 16 05:17:20 EDT 2003


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

Modified Files:
	erase.c gc.c nodelist.c nodelist.h nodemgmt.c scan.c wbuf.c 
	write.c 
Log Message:
Accessor function for ref->totlen and rename it

Index: erase.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/erase.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- erase.c	8 Oct 2003 17:22:54 -0000	1.53
+++ erase.c	16 Oct 2003 09:17:17 -0000	1.54
@@ -387,12 +387,12 @@
 		marker_ref->next_in_ino = NULL;
 		marker_ref->next_phys = NULL;
 		marker_ref->flash_offset = jeb->offset | REF_NORMAL;
-		marker_ref->totlen = PAD(je32_to_cpu(marker.totlen));
+		marker_ref->__totlen = PAD(je32_to_cpu(marker.totlen));
 			
 		jeb->first_node = jeb->last_node = marker_ref;
 			
-		jeb->free_size = c->sector_size - marker_ref->totlen;
-		jeb->used_size = marker_ref->totlen;
+		jeb->free_size = c->sector_size - ref_totlen(marker_ref);
+		jeb->used_size = ref_totlen(marker_ref);
 		jeb->dirty_size = 0;
 		jeb->wasted_size = 0;
 	}

Index: gc.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/gc.c,v
retrieving revision 1.114
retrieving revision 1.115
diff -u -r1.114 -r1.115
--- gc.c	9 Oct 2003 13:53:35 -0000	1.114
+++ gc.c	16 Oct 2003 09:17:17 -0000	1.115
@@ -500,22 +500,22 @@
 	/* Ask for a small amount of space (or the totlen if smaller) because we
 	   don't want to force wastage of the end of a block if splitting would
 	   work. */
-	ret = jffs2_reserve_space_gc(c, min_t(uint32_t, sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN, raw->totlen),
+	ret = jffs2_reserve_space_gc(c, min_t(uint32_t, sizeof(struct jffs2_raw_inode) + JFFS2_MIN_DATA_LEN, ref_totlen(raw)),
 				     &phys_ofs, &alloclen);
 	if (ret)
 		return ret;
 
-	if (alloclen < raw->totlen) {
+	if (alloclen < ref_totlen(raw)) {
 		/* Doesn't fit untouched. We'll go the old route and split it */
 		return -EBADFD;
 	}
 
-	node = kmalloc(raw->totlen, GFP_KERNEL);
+	node = kmalloc(ref_totlen(raw), GFP_KERNEL);
 	if (!node)
                return -ENOMEM;
 
-	ret = jffs2_flash_read(c, ref_offset(raw), raw->totlen, &retlen, (char *)node);
-	if (!ret && retlen != raw->totlen)
+	ret = jffs2_flash_read(c, ref_offset(raw), ref_totlen(raw), &retlen, (char *)node);
+	if (!ret && retlen != ref_totlen(raw))
 		ret = -EIO;
 	if (ret)
 		goto out_node;
@@ -578,14 +578,14 @@
 	/* OK, all the CRCs are good; this node can just be copied as-is. */
  retry:
 	nraw->flash_offset = phys_ofs;
-	nraw->totlen = raw->totlen;
+	nraw->__totlen = ref_totlen(raw);
 	nraw->next_phys = NULL;
 
-	ret = jffs2_flash_write(c, phys_ofs, raw->totlen, &retlen, (char *)node);
+	ret = jffs2_flash_write(c, phys_ofs, ref_totlen(raw), &retlen, (char *)node);
 
-	if (ret || (retlen != raw->totlen)) {
+	if (ret || (retlen != ref_totlen(raw))) {
 		printk(KERN_NOTICE "Write of %d bytes at 0x%08x failed. returned %d, retlen %zd\n",
-                       raw->totlen, phys_ofs, ret, retlen);
+                       ref_totlen(raw), phys_ofs, ret, retlen);
 		if (retlen) {
                         /* Doesn't belong to any inode */
 			nraw->next_in_ino = NULL;
@@ -609,7 +609,7 @@
 			ACCT_SANITY_CHECK(c,jeb);
 			D1(ACCT_PARANOIA_CHECK(jeb));
 
-			ret = jffs2_reserve_space_gc(c, raw->totlen, &phys_ofs, &dummy);
+			ret = jffs2_reserve_space_gc(c, ref_totlen(raw), &phys_ofs, &dummy);
 
 			if (!ret) {
 				D1(printk(KERN_DEBUG "Allocated space at 0x%08x to retry failed write.\n", phys_ofs));

Index: nodelist.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodelist.c,v
retrieving revision 1.80
retrieving revision 1.81
diff -u -r1.80 -r1.81
--- nodelist.c	4 Oct 2003 08:33:06 -0000	1.80
+++ nodelist.c	16 Oct 2003 09:17:17 -0000	1.81
@@ -133,7 +133,7 @@
 		cond_resched();
 
 		/* FIXME: point() */
-		err = jffs2_flash_read(c, (ref_offset(ref)), min_t(uint32_t, ref->totlen, sizeof(node)), &retlen, (void *)&node);
+		err = jffs2_flash_read(c, (ref_offset(ref)), min_t(uint32_t, ref_totlen(ref), sizeof(node)), &retlen, (void *)&node);
 		if (err) {
 			printk(KERN_WARNING "error %d reading node at 0x%08x in get_inode_nodes()\n", err, ref_offset(ref));
 			goto free_out;
@@ -141,7 +141,7 @@
 			
 
 			/* Check we've managed to read at least the common node header */
-		if (retlen < min_t(uint32_t, ref->totlen, sizeof(node.u))) {
+		if (retlen < min_t(uint32_t, ref_totlen(ref), sizeof(node.u))) {
 			printk(KERN_WARNING "short read in get_inode_nodes()\n");
 			err = -EIO;
 			goto free_out;
@@ -321,10 +321,10 @@
 				/* Mark the node as having been checked and fix the accounting accordingly */
 				spin_lock(&c->erase_completion_lock);
 				jeb = &c->blocks[ref->flash_offset / c->sector_size];
-				jeb->used_size += ref->totlen;
-				jeb->unchecked_size -= ref->totlen;
-				c->used_size += ref->totlen;
-				c->unchecked_size -= ref->totlen;
+				jeb->used_size += ref_totlen(ref);
+				jeb->unchecked_size -= ref_totlen(ref);
+				c->used_size += ref_totlen(ref);
+				c->unchecked_size -= ref_totlen(ref);
 
 				/* If node covers at least a whole page, or if it starts at the 
 				   beginning of a page and runs to the end of the file, or if 
@@ -384,10 +384,10 @@
 				/* Mark the node as having been checked and fix the accounting accordingly */
 				spin_lock(&c->erase_completion_lock);
 				jeb = &c->blocks[ref->flash_offset / c->sector_size];
-				jeb->used_size += ref->totlen;
-				jeb->unchecked_size -= ref->totlen;
-				c->used_size += ref->totlen;
-				c->unchecked_size -= ref->totlen;
+				jeb->used_size += ref_totlen(ref);
+				jeb->unchecked_size -= ref_totlen(ref);
+				c->used_size += ref_totlen(ref);
+				c->unchecked_size -= ref_totlen(ref);
 
 				mark_ref_normal(ref);
 				spin_unlock(&c->erase_completion_lock);

Index: nodelist.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodelist.h,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- nodelist.h	8 Oct 2003 11:45:11 -0000	1.104
+++ nodelist.h	16 Oct 2003 09:17:17 -0000	1.105
@@ -59,13 +59,12 @@
 		word so you know when you've got there :) */
 	struct jffs2_raw_node_ref *next_phys;
 	uint32_t flash_offset;
-	uint32_t totlen;
-	
+	uint32_t __totlen; /* This may die; use ref_totlen() below */
+};
+
         /* flash_offset & 3 always has to be zero, because nodes are
 	   always aligned at 4 bytes. So we have a couple of extra bits
-	   to play with. So we set the least significant bit to 1 to
-	   signify that the node is obsoleted by later nodes.
-	*/
+	   to play with, which indicate the node's status; see below: */ 
 #define REF_UNCHECKED	0	/* We haven't yet checked the CRC or built its inode */
 #define REF_OBSOLETE	1	/* Obsolete, can be completely ignored */
 #define REF_PRISTINE	2	/* Completely clean. GC without looking */
@@ -74,7 +73,6 @@
 #define ref_offset(ref)		((ref)->flash_offset & ~3)
 #define ref_obsolete(ref)	(((ref)->flash_offset & 3) == REF_OBSOLETE)
 #define mark_ref_normal(ref)    do { (ref)->flash_offset = ref_offset(ref) | REF_NORMAL; } while(0)
-};
 
 /* 
    Used for keeping track of deletion nodes &c, which can only be marked
@@ -246,9 +244,9 @@
 				BUG(); \
 			} \
 			if (ref_flags(ref2) == REF_UNCHECKED) \
-				my_unchecked_size += ref2->totlen; \
+				my_unchecked_size += ref_totlen(ref2); \
 			else if (!ref_obsolete(ref2)) \
-				my_used_size += ref2->totlen; \
+				my_used_size += ref_totlen(ref2); \
 			if (unlikely((!ref2->next_phys) != (ref2 == jeb->last_node))) { \
 				printk("ref for node at %p (phys %08x) has next_phys->%p (%08x), last_node->%p (phys %08x)\n", \
 				       ref2, ref_offset(ref2), ref2->next_phys, ref_offset(ref2->next_phys), \
@@ -267,6 +265,51 @@
 			BUG(); \
 		} \
 	} while(0)
+
+#if 0 /* This doesn't actually work yet */
+/* Calculate totlen from surrounding nodes or eraseblock */
+static inline uint32_t __ref_totlen(struct jffs2_sb_info *c,
+				    struct jffs2_eraseblock *jeb,
+				    struct jffs2_raw_node_ref *ref)
+{
+	uint32_t ref_end;
+	
+	if (ref->next_phys)
+		ref_end = ref_offset(ref->next_phys);
+	else {
+		/* Last node in block. Use free_space */
+		BUG_ON(ref != jeb->last_node);
+		ref_end = jeb->offset + c->sector_size - jeb->free_size;
+	}
+	return ref_end - ref_offset(ref);
+}
+/* ...and for a while we'll have this as a sanity check... */
+static inline uint32_t ref_totlen(struct jffs2_sb_info *c,
+				   struct jffs2_eraseblock *jeb,
+				   struct jffs2_raw_node_ref *ref)
+{
+	uint32_t ret;
+
+	if (jeb != &c->blocks[ref->flash_offset / c->sector_size]) {
+		printk(KERN_CRIT "ref_totlen called with wrong block -- at 0x%08x instead of 0x08x; ref %08x\n",
+		       jeb->offset, c->blocks[ref->flash_offset / c->sector_size].offset, ref_offset(ref));
+		BUG();
+	}
+	ret = __ref_totlen(c, jeb, ref);
+	if (ret != ref->__totlen) {
+		printk(KERN_CRIT "Totlen for ref at %p (0x%08x-0x%08x) miscalculated as 0x%x instead of %x\n",
+		       ref, ref_offset(ref), ref_offset(ref)+ref->__totlen,
+		       ret, ref->__totlen);
+		paranoia_failed_dump(jeb);
+		BUG();
+	}
+#else
+static inline uint32_t ref_totlen(struct jffs2_raw_node_ref *ref)
+{
+#endif
+	return ref->__totlen;
+}
+
 
 #define ALLOC_NORMAL	0	/* Normal allocation */
 #define ALLOC_DELETION	1	/* Deletion node. Best to allow it */

Index: nodemgmt.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/nodemgmt.c,v
retrieving revision 1.102
retrieving revision 1.103
diff -u -r1.102 -r1.103
--- nodemgmt.c	8 Oct 2003 17:21:19 -0000	1.102
+++ nodemgmt.c	16 Oct 2003 09:17:17 -0000	1.103
@@ -321,9 +321,11 @@
 int jffs2_add_physical_node_ref(struct jffs2_sb_info *c, struct jffs2_raw_node_ref *new)
 {
 	struct jffs2_eraseblock *jeb;
-	uint32_t len = new->totlen;
+	uint32_t len;
 
 	jeb = &c->blocks[new->flash_offset / c->sector_size];
+	len = ref_totlen(new);
+
 	D1(printk(KERN_DEBUG "jffs2_add_physical_node_ref(): Node at 0x%x(%d), size 0x%x\n", ref_offset(new), ref_flags(new), len));
 #if 1
 	if (jeb != c->nextblock || (ref_offset(new)) != jeb->offset + (c->sector_size - jeb->free_size)) {
@@ -420,31 +422,31 @@
 	spin_lock(&c->erase_completion_lock);
 
 	if (ref_flags(ref) == REF_UNCHECKED) {
-		D1(if (unlikely(jeb->unchecked_size < ref->totlen)) {
+		D1(if (unlikely(jeb->unchecked_size < ref_totlen(ref))) {
 			printk(KERN_NOTICE "raw unchecked node of size 0x%08x freed from erase block %d at 0x%08x, but unchecked_size was already 0x%08x\n",
-			       ref->totlen, blocknr, ref->flash_offset, jeb->used_size);
+			       ref_totlen(ref), blocknr, ref->flash_offset, jeb->used_size);
 			BUG();
 		})
-		D1(printk(KERN_DEBUG "Obsoleting previously unchecked node at 0x%08x of len %x: ", ref_offset(ref), ref->totlen));
-		jeb->unchecked_size -= ref->totlen;
-		c->unchecked_size -= ref->totlen;
+		D1(printk(KERN_DEBUG "Obsoleting previously unchecked node at 0x%08x of len %x: ", ref_offset(ref), ref_totlen(ref)));
+		jeb->unchecked_size -= ref_totlen(ref);
+		c->unchecked_size -= ref_totlen(ref);
 	} else {
-		D1(if (unlikely(jeb->used_size < ref->totlen)) {
+		D1(if (unlikely(jeb->used_size < ref_totlen(ref))) {
 			printk(KERN_NOTICE "raw node of size 0x%08x freed from erase block %d at 0x%08x, but used_size was already 0x%08x\n",
-			       ref->totlen, blocknr, ref->flash_offset, jeb->used_size);
+			       ref_totlen(ref), blocknr, ref->flash_offset, jeb->used_size);
 			BUG();
 		})
-		D1(printk(KERN_DEBUG "Obsoleting node at 0x%08x of len %x: ", ref_offset(ref), ref->totlen));
-		jeb->used_size -= ref->totlen;
-		c->used_size -= ref->totlen;
+		D1(printk(KERN_DEBUG "Obsoleting node at 0x%08x of len %x: ", ref_offset(ref), ref_totlen(ref)));
+		jeb->used_size -= ref_totlen(ref);
+		c->used_size -= ref_totlen(ref);
 	}
 
 	// Take care, that wasted size is taken into concern
-	if ((jeb->dirty_size || ISDIRTY(jeb->wasted_size + ref->totlen)) && jeb != c->nextblock) {
+	if ((jeb->dirty_size || ISDIRTY(jeb->wasted_size + ref_totlen(ref))) && jeb != c->nextblock) {
 		D1(printk("Dirtying\n"));
-		addedsize = ref->totlen;
-		jeb->dirty_size += ref->totlen;
-		c->dirty_size += ref->totlen;
+		addedsize = ref_totlen(ref);
+		jeb->dirty_size += ref_totlen(ref);
+		c->dirty_size += ref_totlen(ref);
 
 		/* Convert wasted space to dirty, if not a bad block */
 		if (jeb->wasted_size) {
@@ -465,8 +467,8 @@
 	} else {
 		D1(printk("Wasting\n"));
 		addedsize = 0;
-		jeb->wasted_size += ref->totlen;
-		c->wasted_size += ref->totlen;	
+		jeb->wasted_size += ref_totlen(ref);
+		c->wasted_size += ref_totlen(ref);	
 	}
 	ref->flash_offset = ref_offset(ref) | REF_OBSOLETE;
 	
@@ -572,8 +574,8 @@
 		printk(KERN_WARNING "Short read from obsoleted node at 0x%08x: %zd\n", ref_offset(ref), retlen);
 		return;
 	}
-	if (PAD(je32_to_cpu(n.totlen)) != PAD(ref->totlen)) {
-		printk(KERN_WARNING "Node totlen on flash (0x%08x) != totlen in node ref (0x%08x)\n", je32_to_cpu(n.totlen), ref->totlen);
+	if (PAD(je32_to_cpu(n.totlen)) != PAD(ref_totlen(ref))) {
+		printk(KERN_WARNING "Node totlen on flash (0x%08x) != totlen in node ref (0x%08x)\n", je32_to_cpu(n.totlen), ref_totlen(ref));
 		return;
 	}
 	if (!(je16_to_cpu(n.nodetype) & JFFS2_NODE_ACCURATE)) {

Index: scan.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/scan.c,v
retrieving revision 1.104
retrieving revision 1.105
diff -u -r1.104 -r1.105
--- scan.c	11 Oct 2003 14:52:48 -0000	1.104
+++ scan.c	16 Oct 2003 09:17:17 -0000	1.105
@@ -554,7 +554,7 @@
 				marker_ref->next_in_ino = NULL;
 				marker_ref->next_phys = NULL;
 				marker_ref->flash_offset = ofs | REF_NORMAL;
-				marker_ref->totlen = c->cleanmarker_size;
+				marker_ref->__totlen = c->cleanmarker_size;
 				jeb->first_node = jeb->last_node = marker_ref;
 			     
 				USED_SPACE(PAD(c->cleanmarker_size));
@@ -698,7 +698,7 @@
 	/* Wheee. It worked */
 
 	raw->flash_offset = ofs | REF_UNCHECKED;
-	raw->totlen = PAD(je32_to_cpu(ri->totlen));
+	raw->__totlen = PAD(je32_to_cpu(ri->totlen));
 	raw->next_phys = NULL;
 	raw->next_in_ino = ic->nodes;
 
@@ -775,7 +775,7 @@
 		return -ENOMEM;
 	}
 	
-	raw->totlen = PAD(je32_to_cpu(rd->totlen));
+	raw->__totlen = PAD(je32_to_cpu(rd->totlen));
 	raw->flash_offset = ofs | REF_PRISTINE;
 	raw->next_phys = NULL;
 	raw->next_in_ino = ic->nodes;

Index: wbuf.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/wbuf.c,v
retrieving revision 1.53
retrieving revision 1.54
diff -u -r1.53 -r1.54
--- wbuf.c	11 Oct 2003 11:46:09 -0000	1.53
+++ wbuf.c	16 Oct 2003 09:17:17 -0000	1.54
@@ -179,10 +179,10 @@
 	first_raw = &jeb->first_node;
 	while (*first_raw && 
 	       (ref_obsolete(*first_raw) ||
-		(ref_offset(*first_raw) + (*first_raw)->totlen) < c->wbuf_ofs)) {
+		(ref_offset(*first_raw)+ref_totlen(*first_raw)) < 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),
+			  (ref_offset(*first_raw) + ref_totlen(*first_raw)),
 			  c->wbuf_ofs));
 		first_raw = &(*first_raw)->next_phys;
 	}
@@ -195,13 +195,13 @@
 	}
 
 	start = ref_offset(*first_raw);
-	end = ref_offset(*first_raw) + (*first_raw)->totlen;
+	end = ref_offset(*first_raw) + ref_totlen(*first_raw);
 
 	/* Find the last node to be recovered */
 	raw = first_raw;
 	while ((*raw)) {
 		if (!ref_obsolete(*raw))
-			end = ref_offset(*raw) + (*raw)->totlen;
+			end = ref_offset(*raw) + ref_totlen(*raw);
 
 		raw = &(*raw)->next_phys;
 	}
@@ -295,7 +295,7 @@
 					return;
 
 				raw2->flash_offset = ofs | REF_OBSOLETE;
-				raw2->totlen = (*first_raw)->totlen;
+				raw2->__totlen = ref_totlen(*first_raw);
 				raw2->next_phys = NULL;
 				raw2->next_in_ino = NULL;
 
@@ -337,23 +337,23 @@
 	raw = first_raw;
 	while (*raw) {
 		D1(printk(KERN_DEBUG "Refiling block of %08x at %08x(%d) to %08x\n",
-			  (*raw)->totlen, ref_offset(*raw), ref_flags(*raw), ofs));
+			  ref_totlen(*raw), ref_offset(*raw), ref_flags(*raw), ofs));
 
 		if (ref_obsolete(*raw)) {
 			/* Shouldn't really happen much */
-			new_jeb->dirty_size += (*raw)->totlen;
-			new_jeb->free_size -= (*raw)->totlen;
-			c->dirty_size += (*raw)->totlen;
+			new_jeb->dirty_size += ref_totlen(*raw);
+			new_jeb->free_size -= ref_totlen(*raw);
+			c->dirty_size += ref_totlen(*raw);
 		} else {
-			new_jeb->used_size += (*raw)->totlen;
-			new_jeb->free_size -= (*raw)->totlen;
-			jeb->dirty_size += (*raw)->totlen;
-			jeb->used_size  -= (*raw)->totlen;
-			c->dirty_size += (*raw)->totlen;
+			new_jeb->used_size += ref_totlen(*raw);
+			new_jeb->free_size -= ref_totlen(*raw);
+			jeb->dirty_size += ref_totlen(*raw);
+			jeb->used_size  -= ref_totlen(*raw);
+			c->dirty_size += ref_totlen(*raw);
 		}
-		c->free_size -= (*raw)->totlen;
+		c->free_size -= ref_totlen(*raw);
 		(*raw)->flash_offset = ofs | ref_flags(*raw);
-		ofs += (*raw)->totlen;
+		ofs += ref_totlen(*raw);
 		new_jeb->last_node = *raw;
 
 		raw = &(*raw)->next_phys;

Index: write.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/write.c,v
retrieving revision 1.75
retrieving revision 1.76
diff -u -r1.75 -r1.76
--- write.c	8 Oct 2003 11:45:11 -0000	1.75
+++ write.c	16 Oct 2003 09:17:17 -0000	1.76
@@ -133,7 +133,7 @@
 	fn->raw = raw;
 
 	raw->flash_offset = flash_ofs;
-	raw->totlen = PAD(sizeof(*ri)+datalen);
+	raw->__totlen = PAD(sizeof(*ri)+datalen);
 	raw->next_phys = NULL;
 
 	ret = jffs2_flash_writev(c, vecs, cnt, flash_ofs, &retlen,
@@ -275,7 +275,7 @@
 	fd->raw = raw;
 
 	raw->flash_offset = flash_ofs;
-	raw->totlen = PAD(sizeof(*rd)+namelen);
+	raw->__totlen = PAD(sizeof(*rd)+namelen);
 	raw->next_phys = NULL;
 
 	ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen,




More information about the linux-mtd-cvs mailing list