patch-2.4.10 linux/fs/jffs/intrep.c

Next file: linux/fs/jffs/jffs_fm.c
Previous file: linux/fs/jffs/inode-v23.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.9/linux/fs/jffs/intrep.c linux/fs/jffs/intrep.c
@@ -10,8 +10,7 @@
  * the Free Software Foundation; either version 2 of the License, or
  * (at your option) any later version.
  *
- * - Based on Id: intrep.c,v 1.71 2000/10/27 16:51:29 dwmw2 Exp
- * - With the ctype() changes from v1.77.
+ * $Id: intrep.c,v 1.71.2.4 2001/01/08 23:27:02 dwmw2 Exp $
  *
  * Ported to Linux 2.3.x and MTD:
  * Copyright (C) 2000  Alexander Larsson (alex@cendio.se), Cendio Systems AB
@@ -640,10 +639,10 @@
 				   (or from start) 
 				*/
 				if (start < (pos & ~(fmc->sector_size-1))) {
-					D1(printk("Reducing start to 0x%x from 0x%x\n", pos & ~(fmc->sector_size-1), start));
+					D1(printk("Reducing start to 0x%lx from 0x%lx\n", (unsigned long)pos & ~(fmc->sector_size-1), (unsigned long)start));
 					start = pos & ~(fmc->sector_size-1);
 				}
-				D1(printk("Dirty space: 0x%x for 0x%x bytes\n", start, (pos - start)));
+				D1(printk("Dirty space: 0x%lx for 0x%lx bytes\n", (unsigned long)start, (unsigned long)(pos - start)));
 				jffs_fmalloced(fmc, (__u32) start,
 					       (__u32) (pos - start), 0);
 			}
@@ -1003,12 +1002,11 @@
 		f->atime = raw_inode->atime;
 		f->mtime = raw_inode->mtime;
 		f->ctime = raw_inode->ctime;
-		f->deleted = raw_inode->deleted;
 	}
 	else if ((f->highest_version < node->version)
 		 || (node->version == 0)) {
 		/* Insert at the end of the list.  I.e. this node is the
-		   oldest one so far.  */
+		   newest one so far.  */
 		node->version_prev = f->version_tail;
 		node->version_next = 0;
 		f->version_tail->version_next = node;
@@ -1022,7 +1020,6 @@
 		f->atime = raw_inode->atime;
 		f->mtime = raw_inode->mtime;
 		f->ctime = raw_inode->ctime;
-		f->deleted = raw_inode->deleted;
 	}
 	else if (f->version_head->version > node->version) {
 		/* Insert at the bottom of the list.  */
@@ -1033,9 +1030,6 @@
 		if (!f->name) {
 			update_name = 1;
 		}
-		if (raw_inode->deleted) {
-			f->deleted = raw_inode->deleted;
-		}
 	}
 	else {
 		struct jffs_node *n;
@@ -1059,6 +1053,11 @@
 		}
 	}
 
+	/* Deletion is irreversible. If any 'deleted' node is ever
+	   written, the file is deleted */
+	if (raw_inode->deleted)
+		f->deleted = raw_inode->deleted;
+
 	/* Perhaps update the name.  */
 	if (raw_inode->nsize && update_name && name && *name && (name != f->name)) {
 		if (f->name) {
@@ -1083,16 +1082,15 @@
 		if (insert_into_tree) {
 			jffs_insert_file_into_tree(f);
 		}
-		if (f->deleted) {
-			/* Mark all versions of the node as obsolete.  */
-			jffs_possibly_delete_file(f);
-		}
-		else {
-			if (node->data_size || node->removed_size) {
-				jffs_update_file(f, node);
-			}
-			jffs_remove_redundant_nodes(f);
+		/* Once upon a time, we would call jffs_possibly_delete_file()
+		   here. That causes an oops if someone's still got the file
+		   open, so now we only do it in jffs_delete_inode()
+		   -- dwmw2
+		*/
+		if (node->data_size || node->removed_size) {
+			jffs_update_file(f, node);
 		}
+		jffs_remove_redundant_nodes(f);
 
 		jffs_garbage_collect_trigger(c);
 
@@ -1331,7 +1329,7 @@
 	D3(printk("jffs_find_child()\n"));
 
 	for (f = dir->children; f; f = f->sibling_next) {
-		if (f->name
+		if (!f->deleted && f->name
 		    && !strncmp(f->name, name, len)
 		    && f->name[len] == '\0') {
 			break;
@@ -1573,6 +1571,8 @@
 		}
 		pos += total_name_size;
 	}
+	if (raw_inode->deleted)
+		f->deleted = 1;
 
 	/* Step 3: Append the actual data, if any.  */
 	if (raw_inode->dsize) {
@@ -1609,7 +1609,7 @@
 		  "version: %u, node_offset: %u\n",
 		  f->name, node->ino, node->version, node_offset));
 
-	r = min(u32, avail, max_size);
+	r = min_t(u32, avail, max_size);
 	D3(printk(KERN_NOTICE "jffs_get_node_data\n"));
 	flash_safe_read(fmc->mtd, pos, buf, r);
 
@@ -1662,7 +1662,7 @@
 		int r;
 		if (!node->fm) {
 			/* This node does not refer to real data.  */
-			r = min(u32, size - read_data,
+			r = min_t(u32, size - read_data,
 				node->data_size - node_offset);
 			memset(&buf[read_data], 0, r);
 		}
@@ -1904,7 +1904,7 @@
 		else {
 			/* No.  No need to split the node.  Just remove
 			   the end of the node.  */
-			int r = min(u32, n->data_offset + n->data_size
+			int r = min_t(u32, n->data_offset + n->data_size
 				    - offset, remove_size);
 			n->data_size -= r;
 			remove_size -= r;
@@ -2460,7 +2460,7 @@
 		}
 
 		while (size) {
-			__u32 s = min(int, size, PAGE_SIZE);
+			__u32 s = min_t(int, size, PAGE_SIZE);
 			if ((r = jffs_read_data(f, (char *)page,
 						offset, s)) < s) {
 				free_page((unsigned long)page);
@@ -2654,8 +2654,8 @@
 	   what's available */
 	if (size > JFFS_PAD(node->data_size) + total_name_size + 
 	    sizeof(struct jffs_raw_inode) + extra_available) {
-		D1(printk("Reducing size of new node from %d to %ld to avoid "
-		       "catching our tail\n", size, 
+		D1(printk("Reducing size of new node from %d to %d to avoid "
+			  "catching our tail\n", size,
 			  JFFS_PAD(node->data_size) + JFFS_PAD(node->name_size) + 
 			  sizeof(struct jffs_raw_inode) + extra_available));
 		D1(printk("space_needed = %d, extra_available = %d\n", 
@@ -2821,7 +2821,7 @@
 				printk("JFFS: Erase failed! pos = 0x%lx\n",
 				       (long)pos);
 				jffs_hexdump(fmc->mtd, pos,
-					     min(u32, 256, end - pos));
+					     min_t(u32, 256, end - pos));
 				err = -1;
 				break;
 			}

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)