[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

jffs_garbage_collect_next() alteration to avoid head meeting tail.



Anyone care to verify this? My brain hurts.


Index: intrep.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs/intrep.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -r1.46 -r1.47
--- intrep.c	2000/08/15 18:10:14	1.46
+++ intrep.c	2000/08/15 19:48:24	1.47
@@ -2454,6 +2454,8 @@
 	int size;
 	int data_size;
 	int total_name_size;
+	__u32 extra_available;
+	__u32 space_needed;
 	__u32 free_chunk_size1 = jffs_free_size1(fmc);
 	D2(__u32 free_chunk_size2 = jffs_free_size2(fmc));
 
@@ -2478,8 +2480,24 @@
 		  "ino: %u, version: %u\n",
 		  (f->name ? f->name : ""), node->ino, node->version));
 
-	/* Compute how much we want to rewrite at the moment.  */
+	/* Calculate the amount of space needed to hold the nodes
+	   which are remaining in the tail */
+	space_needed = fmc->min_free_size - (node->fm->offset % fmc->sector_size);
+	/* From that, calculate how much 'extra' space we can use to
+	   increase the size of the node we're writing from the size
+	   of the node we're obsoleting
+	*/
+	extra_available = fmc->free_size - space_needed;
+
+	/* Compute how many data it's possible to rewrite at the moment.  */
 	data_size = f->size - node->data_offset;
+
+	/* Write out as much as we're allowed */
+	if (data_size > node->data_size + extra_available) {
+		D1(printk("Reducing size of new node to %d from %d to avoid "
+		       "catching our tail\n", node->data_size + extra_available, data_size));
+		data_size = node->data_size + extra_available;
+	}
 	total_name_size = f->nsize + JFFS_GET_PAD_BYTES(f->nsize);
 	size = sizeof(struct jffs_raw_inode) + total_name_size
 	       + data_size + JFFS_GET_PAD_BYTES(data_size);



--
dwmw2