| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * JFFS2 -- Journalling Flash File System, Version 2. | 
|  | 3 | * | 
| David Woodhouse | c00c310 | 2007-04-25 14:16:47 +0100 | [diff] [blame] | 4 | * Copyright © 2001-2007 Red Hat, Inc. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * | 
|  | 6 | * Created by David Woodhouse <dwmw2@infradead.org> | 
|  | 7 | * | 
|  | 8 | * For licensing information, see the file 'LICENCE' in this directory. | 
|  | 9 | * | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | */ | 
|  | 11 |  | 
| Joe Perches | 5a52895 | 2012-02-15 15:56:45 -0800 | [diff] [blame] | 12 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | 
|  | 13 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/kernel.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/fs.h> | 
|  | 16 | #include <linux/namei.h> | 
|  | 17 | #include "nodelist.h" | 
|  | 18 |  | 
| Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 19 | static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 |  | 
| Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 21 | const struct inode_operations jffs2_symlink_inode_operations = | 
| Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 22 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | .readlink =	generic_readlink, | 
|  | 24 | .follow_link =	jffs2_follow_link, | 
| Christoph Hellwig | 4e34e71 | 2011-07-23 17:37:31 +0200 | [diff] [blame] | 25 | .get_acl =	jffs2_get_acl, | 
| KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 26 | .setattr =	jffs2_setattr, | 
|  | 27 | .setxattr =	jffs2_setxattr, | 
|  | 28 | .getxattr =	jffs2_getxattr, | 
|  | 29 | .listxattr =	jffs2_listxattr, | 
|  | 30 | .removexattr =	jffs2_removexattr | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | }; | 
|  | 32 |  | 
| Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 33 | static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | { | 
| Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 35 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode); | 
| Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 36 | char *p = (char *)f->target; | 
|  | 37 |  | 
| Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 38 | /* | 
|  | 39 | * 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] | 40 | * use is f->target. | 
| Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 41 | * | 
| Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 42 | * 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] | 43 | * to point to the target path. | 
| Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 44 | * 2. Nobody uses f->target (if the inode is symlink's inode). The | 
|  | 45 | * exception is inode freeing function which frees f->target. But | 
| Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 46 | * 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] | 47 | * 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] | 48 | * nd_set_link() call. | 
|  | 49 | */ | 
| Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 50 |  | 
| Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 51 | if (!p) { | 
| Joe Perches | da320f0 | 2012-02-15 15:56:44 -0800 | [diff] [blame] | 52 | pr_err("%s(): can't find symlink target\n", __func__); | 
| Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 53 | p = ERR_PTR(-EIO); | 
| Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 54 | } | 
| Joe Perches | 9c261b3 | 2012-02-15 15:56:43 -0800 | [diff] [blame] | 55 | jffs2_dbg(1, "%s(): target path is '%s'\n", | 
|  | 56 | __func__, (char *)f->target); | 
| Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 57 |  | 
| Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 58 | nd_set_link(nd, p); | 
| Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 59 |  | 
| Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 60 | /* | 
| Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 61 | * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe | 
|  | 62 | * since the only way that may cause f->target to be changed is iput() operation. | 
|  | 63 | * 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] | 64 | */ | 
| Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 65 | return NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | } | 
|  | 67 |  |