Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * JFFS2 -- Journalling Flash File System, Version 2. |
| 3 | * |
| 4 | * Copyright (C) 2001, 2002 Red Hat, Inc. |
| 5 | * |
| 6 | * Created by David Woodhouse <dwmw2@infradead.org> |
| 7 | * |
| 8 | * For licensing information, see the file 'LICENCE' in this directory. |
| 9 | * |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 10 | * $Id: symlink.c,v 1.19 2005/11/07 11:14:42 gleixner Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * |
| 12 | */ |
| 13 | |
| 14 | |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/fs.h> |
| 18 | #include <linux/namei.h> |
| 19 | #include "nodelist.h" |
| 20 | |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 21 | static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | |
| 23 | struct inode_operations jffs2_symlink_inode_operations = |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 24 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | .readlink = generic_readlink, |
| 26 | .follow_link = jffs2_follow_link, |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 27 | .permission = jffs2_permission, |
| 28 | .setattr = jffs2_setattr, |
| 29 | .setxattr = jffs2_setxattr, |
| 30 | .getxattr = jffs2_getxattr, |
| 31 | .listxattr = jffs2_listxattr, |
| 32 | .removexattr = jffs2_removexattr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | }; |
| 34 | |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 35 | static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 37 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode); |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 38 | char *p = (char *)f->target; |
| 39 | |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 40 | /* |
| 41 | * We don't acquire the f->sem mutex here since the only data we |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 42 | * use is f->target. |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 43 | * |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 44 | * 1. If we are here the inode has already built and f->target has |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 45 | * to point to the target path. |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 46 | * 2. Nobody uses f->target (if the inode is symlink's inode). The |
| 47 | * exception is inode freeing function which frees f->target. But |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 48 | * it can't be called while we are here and before VFS has |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 49 | * stopped using our f->target string which we provide by means of |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 50 | * nd_set_link() call. |
| 51 | */ |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 52 | |
Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 53 | if (!p) { |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 54 | printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n"); |
Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 55 | p = ERR_PTR(-EIO); |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 56 | } |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 57 | D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->target)); |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 58 | |
Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 59 | nd_set_link(nd, p); |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 60 | |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 61 | /* |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 62 | * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe |
| 63 | * since the only way that may cause f->target to be changed is iput() operation. |
| 64 | * But VFS will not use f->target after iput() has been called. |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 65 | */ |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 66 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | } |
| 68 | |