[JFFS2] Use f->target instead of 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.

Signed-off-by: Artem B. Bityutskiy <dedekind@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
Artem B. Bityutskiy 2005-07-17 12:13:51 +01:00 committed by Thomas Gleixner
parent 730554d946
commit 2b79adcca1
5 changed files with 44 additions and 47 deletions

View File

@ -7,7 +7,7 @@
* *
* For licensing information, see the file 'LICENCE' in this directory. * For licensing information, see the file 'LICENCE' in this directory.
* *
* $Id: dir.c,v 1.86 2005/07/06 12:13:09 dwmw2 Exp $ * $Id: dir.c,v 1.87 2005/07/17 11:13:46 dedekind Exp $
* *
*/ */
@ -344,9 +344,9 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
return PTR_ERR(fn); return PTR_ERR(fn);
} }
/* We use f->dents field to store the target path. */ /* We use f->target field to store the target path. */
f->dents = kmalloc(targetlen + 1, GFP_KERNEL); f->target = kmalloc(targetlen + 1, GFP_KERNEL);
if (!f->dents) { if (!f->target) {
printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1); printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1);
up(&f->sem); up(&f->sem);
jffs2_complete_reservation(c); jffs2_complete_reservation(c);
@ -354,8 +354,8 @@ static int jffs2_symlink (struct inode *dir_i, struct dentry *dentry, const char
return -ENOMEM; return -ENOMEM;
} }
memcpy(f->dents, target, targetlen + 1); memcpy(f->target, target, targetlen + 1);
D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->dents)); 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 /* No data here. Only a metadata node, which will be
obsoleted by the first data write obsoleted by the first data write

View File

@ -7,7 +7,7 @@
* *
* For licensing information, see the file 'LICENCE' in this directory. * For licensing information, see the file 'LICENCE' in this directory.
* *
* $Id: os-linux.h,v 1.58 2005/07/12 02:34:35 tpoynor Exp $ * $Id: os-linux.h,v 1.59 2005/07/17 11:13:46 dedekind Exp $
* *
*/ */
@ -57,6 +57,7 @@ static inline void jffs2_init_inode_info(struct jffs2_inode_info *f)
f->fragtree = RB_ROOT; f->fragtree = RB_ROOT;
f->metadata = NULL; f->metadata = NULL;
f->dents = NULL; f->dents = NULL;
f->target = NULL;
f->flags = 0; f->flags = 0;
f->usercompr = 0; f->usercompr = 0;
} }

View File

@ -7,7 +7,7 @@
* *
* For licensing information, see the file 'LICENCE' in this directory. * For licensing information, see the file 'LICENCE' in this directory.
* *
* $Id: readinode.c,v 1.126 2005/07/17 06:56:21 dedekind Exp $ * $Id: readinode.c,v 1.127 2005/07/17 11:13:46 dedekind Exp $
* *
*/ */
@ -547,11 +547,10 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
if (f->inocache->state != INO_STATE_CHECKING) { if (f->inocache->state != INO_STATE_CHECKING) {
/* Symlink's inode data is the target path. Read it and /* Symlink's inode data is the target path. Read it and
* keep in RAM to facilitate quick follow symlink operation. * keep in RAM to facilitate quick follow symlink
* We use f->dents field to store the target path, which * operation. */
* is somewhat ugly. */ f->target = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL);
f->dents = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL); if (!f->target) {
if (!f->dents) {
printk(KERN_WARNING "Can't allocate %d bytes of memory " printk(KERN_WARNING "Can't allocate %d bytes of memory "
"for the symlink target path cache\n", "for the symlink target path cache\n",
je32_to_cpu(latest_node->csize)); je32_to_cpu(latest_node->csize));
@ -561,21 +560,21 @@ static int jffs2_do_read_inode_internal(struct jffs2_sb_info *c,
} }
ret = jffs2_flash_read(c, ref_offset(fn->raw) + sizeof(*latest_node), 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 (ret || retlen != je32_to_cpu(latest_node->csize)) {
if (retlen != je32_to_cpu(latest_node->csize)) if (retlen != je32_to_cpu(latest_node->csize))
ret = -EIO; ret = -EIO;
kfree(f->dents); kfree(f->target);
f->dents = NULL; f->target = NULL;
up(&f->sem); up(&f->sem);
jffs2_do_clear_inode(c, f); jffs2_do_clear_inode(c, f);
return -ret; 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", D1(printk(KERN_DEBUG "jffs2_do_read_inode(): symlink's target '%s' cached\n",
(char *)f->dents)); f->target));
} }
/* fall through... */ /* fall through... */
@ -638,20 +637,16 @@ void jffs2_do_clear_inode(struct jffs2_sb_info *c, struct jffs2_inode_info *f)
jffs2_kill_fragtree(&f->fragtree, deleted?c:NULL); jffs2_kill_fragtree(&f->fragtree, deleted?c:NULL);
/* For symlink inodes we us f->dents to store the target path name */ if (f->target) {
if (S_ISLNK(OFNI_EDONI_2SFFJ(f)->i_mode)) { kfree(f->target);
if (f->dents) { f->target = NULL;
kfree(f->dents); }
f->dents = NULL;
} fds = f->dents;
} else { while(fds) {
fds = f->dents; fd = fds;
fds = fd->next;
while(fds) { jffs2_free_full_dirent(fd);
fd = fds;
fds = fd->next;
jffs2_free_full_dirent(fd);
}
} }
if (f->inocache && f->inocache->state != INO_STATE_CHECKING) { if (f->inocache && f->inocache->state != INO_STATE_CHECKING) {

View File

@ -7,7 +7,7 @@
* *
* For licensing information, see the file 'LICENCE' in this directory. * For licensing information, see the file 'LICENCE' in this directory.
* *
* $Id: symlink.c,v 1.16 2005/03/01 10:50:48 dedekind Exp $ * $Id: symlink.c,v 1.18 2005/11/06 11:03:27 gleixner Exp $
* *
*/ */
@ -30,35 +30,33 @@ struct inode_operations jffs2_symlink_inode_operations =
static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd) static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
{ {
struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode); struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
char *p = (char *)f->dents; char *p = (char *)f->target;
/* /*
* We don't acquire the f->sem mutex here since the only data we * 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 * use is f->target.
* symlink's target path.
* *
* 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. * to point to the target path.
* 2. Nobody uses f->dents (if the inode is symlink's inode). The * 2. Nobody uses f->target (if the inode is symlink's inode). The
* exception is inode freeing function which frees f->dents. But * exception is inode freeing function which frees f->target. But
* it can't be called while we are here and before VFS has * 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. * nd_set_link() call.
*/ */
if (!p) { if (!p) {
printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n"); printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n");
p = ERR_PTR(-EIO); p = ERR_PTR(-EIO);
} else {
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, p); nd_set_link(nd, p);
/* /*
* We unlock the f->sem mutex but VFS will use the f->dents string. This is safe * 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->dents to be changed is iput() operation. * since the only way that may cause f->target to be changed is iput() operation.
* But VFS will not use f->dents after iput() has been called. * But VFS will not use f->target after iput() has been called.
*/ */
return NULL; return NULL;
} }

View File

@ -1,4 +1,4 @@
/* $Id: jffs2_fs_i.h,v 1.17 2004/11/11 23:51:27 dwmw2 Exp $ */ /* $Id: jffs2_fs_i.h,v 1.18 2005/07/17 11:13:48 dedekind Exp $ */
#ifndef _JFFS2_FS_I #ifndef _JFFS2_FS_I
#define _JFFS2_FS_I #define _JFFS2_FS_I
@ -32,6 +32,9 @@ struct jffs2_inode_info {
/* Directory entries */ /* Directory entries */
struct jffs2_full_dirent *dents; struct jffs2_full_dirent *dents;
/* The target path if this is the inode of a symlink */
unsigned char *target;
/* Some stuff we just have to keep in-core at all times, for each inode. */ /* Some stuff we just have to keep in-core at all times, for each inode. */
struct jffs2_inode_cache *inocache; struct jffs2_inode_cache *inocache;