blob: 6fd5ee4f90b737af87395ad8ba9ee4fc03f03832 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010010 * $Id: symlink.c,v 1.18 2005/11/06 11:03:27 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 *
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 Viro008b1502005-08-20 00:17:39 +010021static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23struct inode_operations jffs2_symlink_inode_operations =
24{
25 .readlink = generic_readlink,
26 .follow_link = jffs2_follow_link,
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 .setattr = jffs2_setattr
28};
29
Al Viro008b1502005-08-20 00:17:39 +010030static void *jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
Linus Torvalds1da177e2005-04-16 15:20:36 -070031{
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000032 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010033 char *p = (char *)f->target;
34
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000035 /*
36 * We don't acquire the f->sem mutex here since the only data we
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010037 * use is f->target.
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000038 *
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010039 * 1. If we are here the inode has already built and f->target has
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000040 * to point to the target path.
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010041 * 2. Nobody uses f->target (if the inode is symlink's inode). The
42 * exception is inode freeing function which frees f->target. But
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000043 * it can't be called while we are here and before VFS has
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010044 * stopped using our f->target string which we provide by means of
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000045 * nd_set_link() call.
46 */
47
Al Viro2fb1e302005-08-19 22:42:16 +010048 if (!p) {
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000049 printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n");
Al Viro2fb1e302005-08-19 22:42:16 +010050 p = ERR_PTR(-EIO);
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000051 }
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010052 D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->target));
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000053
Al Viro2fb1e302005-08-19 22:42:16 +010054 nd_set_link(nd, p);
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000055
56 /*
Artem B. Bityutskiy2b79adc2005-07-17 12:13:51 +010057 * We will unlock the f->sem mutex but VFS will use the f->target string. This is safe
58 * since the only way that may cause f->target to be changed is iput() operation.
59 * But VFS will not use f->target after iput() has been called.
Artem B. Bityuckiy32f1a952005-03-01 10:50:52 +000060 */
Al Viro008b1502005-08-20 00:17:39 +010061 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63