blob: 1fefa25d0fa586a14caae06efea7363794be38fc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
David Woodhousec00c3102007-04-25 14:16:47 +01004 * Copyright © 2001-2007 Red Hat, Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Created by David Woodhouse <dwmw2@infradead.org>
7 *
8 * For licensing information, see the file 'LICENCE' in this directory.
9 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 */
11
Joe Perches5a528952012-02-15 15:56:45 -080012#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015#include <linux/fs.h>
16#include <linux/namei.h>
17#include "nodelist.h"
18
Al Viro008b1502005-08-20 00:17:39 +010019static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Arjan van de Ven92e1d5b2007-02-12 00:55:39 -080021const struct inode_operations jffs2_symlink_inode_operations =
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000022{
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 .readlink = generic_readlink,
24 .follow_link = jffs2_follow_link,
KaiGai Koheiaa98d7c2006-05-13 15:09:47 +090025 .setattr = jffs2_setattr,
26 .setxattr = jffs2_setxattr,
27 .getxattr = jffs2_getxattr,
28 .listxattr = jffs2_listxattr,
29 .removexattr = jffs2_removexattr
Linus Torvalds1da177e2005-04-16 15:20:36 -070030};
31
Al Viro008b1502005-08-20 00:17:39 +010032static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070033{
David Howells2b0143b2015-03-17 22:25:59 +000034 struct jffs2_inode_info *f = JFFS2_INODE_INFO(d_inode(dentry));
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010035 char *p = (char *)f->target;
36
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000037 /*
38 * We don't acquire the f->sem mutex here since the only data we
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010039 * use is f->target.
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000040 *
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010041 * 1. If we are here the inode has already built and f->target has
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000042 * to point to the target path.
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010043 * 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. Bityuckiy32f1a952005-03-01 10:50:52 +000045 * it can't be called while we are here and before VFS has
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010046 * stopped using our f->target string which we provide by means of
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000047 * nd_set_link() call.
48 */
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000049
Al Viro2fb1e302005-08-19 22:42:16 +010050 if (!p) {
Joe Perchesda320f02012-02-15 15:56:44 -080051 pr_err("%s(): can't find symlink target\n", __func__);
Al Viro2fb1e302005-08-19 22:42:16 +010052 p = ERR_PTR(-EIO);
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000053 }
Joe Perches9c261b32012-02-15 15:56:43 -080054 jffs2_dbg(1, "%s(): target path is '%s'\n",
55 __func__, (char *)f->target);
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000056
Al Viro2fb1e302005-08-19 22:42:16 +010057 nd_set_link(nd, p);
Thomas Gleixner182ec4e2005-11-07 11:16:07 +000058
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000059 /*
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010060 * 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. Bityuckiy32f1a952005-03-01 10:50:52 +000063 */
Al Viro008b1502005-08-20 00:17:39 +010064 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070065}
66