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, |
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) { |
Joe Perches | da320f0 | 2012-02-15 15:56:44 -0800 | [diff] [blame] | 51 | pr_err("%s(): can't find symlink target\n", __func__); |
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 | } |
Joe Perches | 9c261b3 | 2012-02-15 15:56:43 -0800 | [diff] [blame] | 54 | jffs2_dbg(1, "%s(): target path is '%s'\n", |
| 55 | __func__, (char *)f->target); |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 56 | |
Al Viro | 2fb1e30 | 2005-08-19 22:42:16 +0100 | [diff] [blame] | 57 | nd_set_link(nd, p); |
Thomas Gleixner | 182ec4e | 2005-11-07 11:16:07 +0000 | [diff] [blame] | 58 | |
Artem B. Bityuckiy | 32f1a95 | 2005-03-01 10:50:52 +0000 | [diff] [blame] | 59 | /* |
Artem B. Bityutskiy | 2b79adc | 2005-07-17 12:13:51 +0100 | [diff] [blame] | 60 | * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe |
| 61 | * since the only way that may cause f->target to be changed is iput() operation. |
| 62 | * 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] | 63 | */ |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 64 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | } |
| 66 | |