mtd/fs/jffs2 dir.c, 1.86, 1.87 os-linux.h, 1.58, 1.59 readinode.c, 1.126, 1.127 symlink-v24.c, 1.17, 1.18 symlink.c, 1.16, 1.17

Artem Bityuckiy dedekind at infradead.org
Sun Jul 17 07:13:50 EDT 2005


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

Modified Files:
	dir.c os-linux.h readinode.c symlink-v24.c symlink.c 
Log Message:
[JFFS2] Don't use f->dents for symlink target

JFFS2 uses f->dents to store the pointer to the symlink target string (in case
the inode is symlink). This is somewhat ugly to use the same field for
different reasons. Introduce distinct field f->target for this purpose.
Note, f->fragtree, f->dents, f->target may probably be put in a union.


Index: dir.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/dir.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -r1.86 -r1.87
--- dir.c	6 Jul 2005 12:13:09 -0000	1.86
+++ dir.c	17 Jul 2005 11:13:46 -0000	1.87
@@ -344,9 +344,9 @@
 		return PTR_ERR(fn);
 	}
 
-	/* We use f->dents field to store the target path. */
-	f->dents = kmalloc(targetlen + 1, GFP_KERNEL);
-	if (!f->dents) {
+	/* We use f->target field to store the target path. */
+	f->target = kmalloc(targetlen + 1, GFP_KERNEL);
+	if (!f->target) {
 		printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1);
 		up(&f->sem);
 		jffs2_complete_reservation(c);
@@ -354,8 +354,8 @@
 		return -ENOMEM;
 	}
 
-	memcpy(f->dents, target, targetlen + 1);
-	D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->dents));
+	memcpy(f->target, target, targetlen + 1);
+	D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->target));
 
 	/* No data here. Only a metadata node, which will be 
 	   obsoleted by the first data write

Index: os-linux.h
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/os-linux.h,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -r1.58 -r1.59
--- os-linux.h	12 Jul 2005 02:34:35 -0000	1.58
+++ os-linux.h	17 Jul 2005 11:13:46 -0000	1.59
@@ -57,6 +57,7 @@
 	f->fragtree = RB_ROOT;
 	f->metadata = NULL;
 	f->dents = NULL;
+	f->target = NULL;
 	f->flags = 0;
 	f->usercompr = 0;
 }

Index: readinode.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/readinode.c,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -r1.126 -r1.127
--- readinode.c	17 Jul 2005 06:56:21 -0000	1.126
+++ readinode.c	17 Jul 2005 11:13:46 -0000	1.127
@@ -547,11 +547,10 @@
 
 		if (f->inocache->state != INO_STATE_CHECKING) {
 			/* Symlink's inode data is the target path. Read it and
-			 * keep in RAM to facilitate quick follow symlink operation.
-			 * We use f->dents field to store the target path, which
-			 * is somewhat ugly. */
-			f->dents = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL);
-			if (!f->dents) {
+			 * keep in RAM to facilitate quick follow symlink
+			 * operation. */
+			f->target = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL);
+			if (!f->target) {
 				printk(KERN_WARNING "Can't allocate %d bytes of memory "
 						"for the symlink target path cache\n",
 						je32_to_cpu(latest_node->csize));
@@ -561,21 +560,21 @@
 			}
 			
 			ret = jffs2_flash_read(c, ref_offset(fn->raw) + sizeof(*latest_node),
-						je32_to_cpu(latest_node->csize), &retlen, (char *)f->dents);
+						je32_to_cpu(latest_node->csize), &retlen, (char *)f->target);
 			
 			if (ret  || retlen != je32_to_cpu(latest_node->csize)) {
 				if (retlen != je32_to_cpu(latest_node->csize))
 					ret = -EIO;
-				kfree(f->dents);
-				f->dents = NULL;
+				kfree(f->target);
+				f->target = NULL;
 				up(&f->sem);
 				jffs2_do_clear_inode(c, f);
 				return -ret;
 			}
 
-			((char *)f->dents)[je32_to_cpu(latest_node->csize)] = '\0';
+			f->target[je32_to_cpu(latest_node->csize)] = '\0';
 			D1(printk(KERN_DEBUG "jffs2_do_read_inode(): symlink's target '%s' cached\n",
-						(char *)f->dents));
+						f->target));
 		}
 		
 		/* fall through... */
@@ -638,20 +637,16 @@
 
 	jffs2_kill_fragtree(&f->fragtree, deleted?c:NULL);
 
-	/* For symlink inodes we us f->dents to store the target path name */
-	if (S_ISLNK(OFNI_EDONI_2SFFJ(f)->i_mode)) {
-		if (f->dents) {
-			kfree(f->dents);
-			f->dents = NULL;
-		}
-	} else {
-		fds = f->dents;
-
-		while(fds) {
-			fd = fds;
-			fds = fd->next;
-			jffs2_free_full_dirent(fd);
-		}
+	if (f->target) {
+		kfree(f->target);
+		f->target = NULL;
+	}
+	
+	fds = f->dents;
+	while(fds) {
+		fd = fds;
+		fds = fd->next;
+		jffs2_free_full_dirent(fd);
 	}
 
 	if (f->inocache && f->inocache->state != INO_STATE_CHECKING) {

Index: symlink-v24.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/symlink-v24.c,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- symlink-v24.c	4 Mar 2005 13:12:25 -0000	1.17
+++ symlink-v24.c	17 Jul 2005 11:13:47 -0000	1.18
@@ -31,22 +31,22 @@
 {
 	struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
 
-	if (!f->dents) {
+	if (!f->target) {
 		printk(KERN_ERR "jffs2_readlink(): can't find symlink taerget\n");
 		return -EIO;
 	}
 
-	return vfs_readlink(dentry, buffer, buflen, (char *)f->dents);
+	return vfs_readlink(dentry, buffer, buflen, (char *)f->target);
 }
 
 int jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
 {
 	struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
 
-	if (!f->dents) {
+	if (!f->target) {
 		printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n");
 		return -EIO;
 	}
 	
-	return vfs_follow_link(nd, (char *)f->dents);
+	return vfs_follow_link(nd, (char *)f->target);
 }

Index: symlink.c
===================================================================
RCS file: /home/cvs/mtd/fs/jffs2/symlink.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -r1.16 -r1.17
--- symlink.c	1 Mar 2005 10:50:48 -0000	1.16
+++ symlink.c	17 Jul 2005 11:13:47 -0000	1.17
@@ -33,30 +33,29 @@
 	
 	/*
 	 * We don't acquire the f->sem mutex here since the only data we
-	 * use is f->dents which in case of the symlink inode points to the
-	 * symlink's target path.
+	 * use is f->target.
 	 *
-	 * 1. If we are here the inode has already built and f->dents has
+	 * 1. If we are here the inode has already built and f->target has
 	 * to point to the target path.
-	 * 2. Nobody uses f->dents (if the inode is symlink's inode). The
-	 * exception is inode freeing function which frees f->dents. But
+	 * 2. Nobody uses f->target (if the inode is symlink's inode). The
+	 * exception is inode freeing function which frees f->target. But
 	 * it can't be called while we are here and before VFS has
-	 * stopped using our f->dents string which we provide by means of
+	 * stopped using our f->target string which we provide by means of
 	 * nd_set_link() call.
 	 */
 	
-	if (!f->dents) {
+	if (!f->target) {
 		printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n");
 		return -EIO;
 	}
-	D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->dents));
+	D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->target));
 
-	nd_set_link(nd, (char *)f->dents);
+	nd_set_link(nd, (char *)f->target);
 	
 	/*
-	 * We unlock the f->sem mutex but VFS will use the f->dents string. This is safe
-	 * since the only way that may cause f->dents to be changed is iput() operation.
-	 * But VFS will not use f->dents after iput() has been called.
+	 * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe
+	 * since the only way that may cause f->target to be changed is iput() operation.
+	 * But VFS will not use f->target after iput() has been called.
 	 */
 	return 0;
 }





More information about the linux-mtd-cvs mailing list