mtd/fs/jffs2/ecos/src dir-ecos.c,1.10,1.11 fs-ecos.c,1.41,1.42

lunn at infradead.org lunn at infradead.org
Tue Feb 8 14:36:30 EST 2005


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

Modified Files:
	dir-ecos.c fs-ecos.c 
Log Message:
Bug fixes in the eCos parts. Mostly wrong signs on error codes,
iput missing etc.


Index: dir-ecos.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/ecos/src/dir-ecos.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- dir-ecos.c	26 Nov 2003 15:55:35 -0000	1.10
+++ dir-ecos.c	8 Feb 2005 19:36:27 -0000	1.11
@@ -48,9 +48,9 @@
 	up(&dir_f->sem);
 	if (ino) {
 		inode = jffs2_iget(dir_i->i_sb, ino);
-		if (!inode) {
+		if (IS_ERR(inode)) {
 			printk("jffs2_iget() failed for ino #%u\n", ino);
-			return (ERR_PTR(-EIO));
+			return inode;
 		}
 	}
 

Index: fs-ecos.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/ecos/src/fs-ecos.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- fs-ecos.c	22 Jan 2005 16:01:12 -0000	1.41
+++ fs-ecos.c	8 Feb 2005 19:36:27 -0000	1.42
@@ -709,7 +709,7 @@
 			if (err != 0) {
                                 //Possible orphaned inode on the flash - but will be gc'd
                           	jffs2_iput(ds.dir);
-                                return err;
+                                return -err;
 			}
 
 			err = ENOERR;
@@ -825,9 +825,10 @@
 	} else {
 		// If there we no error, something already exists with that
 		// name, so we cannot create another one.
-		jffs2_iput(ds.node);
-		if (err == ENOERR)
-			err = EEXIST;
+               if (err == ENOERR) {
+            		jffs2_iput(ds.node);
+                        err = EEXIST;
+               }
 	}
 	jffs2_iput(ds.dir);
 	return err;
@@ -946,7 +947,6 @@
 		    ds2.dir->i_ctime = ds2.dir->i_mtime = cyg_timestamp();
  out:
 	jffs2_iput(ds1.dir);
-	jffs2_iput(ds1.node);
 	if (S_ISDIR(ds1.node->i_mode)) {
 		/* Renamed a directory to elsewhere... so fix up its
 		   i_parent pointer and the i_counts of its old and
@@ -957,10 +957,11 @@
 	} else {
 		jffs2_iput(ds2.dir); /* ... doing this */
 	}
+	jffs2_iput(ds1.node);
 	if (ds2.node)
 		jffs2_iput(ds2.node);
  
-	return -err;
+	return err;
 }
 
 // -------------------------------------------------------------------------
@@ -1095,9 +1096,11 @@
 			return err;
 
 		// check it is a directory
-		if (!S_ISDIR(ds.node->i_mode))
+		if (!S_ISDIR(ds.node->i_mode)) {
+                        jffs2_iput(ds.node);
 			return ENOTDIR;
-
+                }
+                
 		// Pass it out
 		*dir_out = (cyg_dir) ds.node;
 	} else {
@@ -1363,7 +1366,7 @@
 		int err;
 
 		D2(printf("jffs2_fo_write page_start_pos %d\n", pos));
-		D2(printf("jffs2_fo_write transfer size %d\n", l));
+		D2(printf("jffs2_fo_write transfer size %d\n", len));
 
 		err = jffs2_write_inode_range(c, f, &ri, buf,
 					      pos, len, &writtenlen);
@@ -1421,8 +1424,6 @@
 		return EINVAL;
 	}
 
-        // Check that pos is still within current file size, or at the
-        // very end.
         if (pos < 0 )
                 return EINVAL;
 
@@ -1752,13 +1753,14 @@
 	// Not cached, so malloc it
 	inode = new_inode(sb);
 	if (inode == NULL)
-		return 0;
+		return ERR_PTR(-ENOMEM);
 
 	inode->i_ino = ino;
 
 	err = jffs2_read_inode(inode);
 	if (err) {
 		printf("jffs2_read_inode() failed\n");
+                inode->i_nlink = 0; // free _this_ bad inode right now
 		jffs2_iput(inode);
 		inode = NULL;
 		return ERR_PTR(err);
@@ -1869,8 +1871,17 @@
 	ri->mode =  cpu_to_jemode(mode);
 	ret = jffs2_do_new_inode (c, f, mode, ri);
 	if (ret) {
-		jffs2_iput(inode);
-		return ERR_PTR(ret);
+                // forceful evict: f->sem is locked already, and the
+                // inode is bad.
+                if (inode->i_cache_prev)
+                       inode->i_cache_prev->i_cache_next = inode->i_cache_next;
+                if (inode->i_cache_next)
+                       inode->i_cache_next->i_cache_prev = inode->i_cache_prev; 
+                up(&(f->sem));
+                jffs2_clear_inode(inode);
+                memset(inode, 0x6a, sizeof(*inode));
+                free(inode);
+                return ERR_PTR(ret);
 	}
 	inode->i_nlink = 1;
 	inode->i_ino = je32_to_cpu(ri->ino);





More information about the linux-mtd-cvs mailing list