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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/kernel.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/fs.h> |
| 15 | #include <linux/namei.h> |
| 16 | #include "nodelist.h" |
| 17 | |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 18 | static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
Arjan van de Ven | 92e1d5b | 2007-02-12 00:55:39 -0800 | [diff] [blame] | 20 | const struct inode_operations jffs2_symlink_inode_operations = |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 21 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | .readlink = generic_readlink, |
| 23 | .follow_link = jffs2_follow_link, |
Linus Torvalds | 18f4c64 | 2009-08-28 12:29:03 -0700 | [diff] [blame] | 24 | .check_acl = jffs2_check_acl, |
KaiGai Kohei | aa98d7c | 2006-05-13 15:09:47 +0900 | [diff] [blame] | 25 | .setattr = jffs2_setattr, |
| 26 | .setxattr = jffs2_setxattr, |
| 27 | .getxattr = jffs2_getxattr, |
| 28 | .listxattr = jffs2_listxattr, |
| 29 | .removexattr = jffs2_removexattr |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | }; |
| 31 | |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 32 | static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | { |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 34 | struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode); |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 35 | char *p = (char *)f->target; |
| 36 | |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 37 | /* |
| 38 | * 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] | 39 | * use is f->target. |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 40 | * |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 41 | * 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] | 42 | * to point to the target path. |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 43 | * 2. Nobody uses f->target (if the inode is symlink's inode). The |
| 44 | * exception is inode freeing function which frees f->target. But |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 45 | * 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] | 46 | * 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] | 47 | * nd_set_link() call. |
| 48 | */ |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 49 | |
Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 50 | if (!p) { |
Qi Yong | c7cf0c6 | 2006-10-16 19:42:23 +0800 | [diff] [blame] | 51 | printk(KERN_ERR "jffs2_follow_link(): can't find symlink target\n"); |
Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 52 | p = ERR_PTR(-EIO); |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 53 | } |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 54 | 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] | 55 | |
Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 56 | nd_set_link(nd, p); |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 57 | |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 58 | /* |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 59 | * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe |
| 60 | * since the only way that may cause f->target to be changed is iput() operation. |
| 61 | * 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] | 62 | */ |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 63 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | } |
| 65 | |