1 /*
2 * JFFS2 -- Journalling Flash File System, Version 2.
3 *
4 * Copyright (C) 2001, 2002 Red Hat, Inc.
5 *
6 * Created by David Woodhouse <dwmw2@cambridge.redhat.com>
7 *
8 * The original JFFS, from which the design for JFFS2 was derived,
9 * was designed and implemented by Axis Communications AB.
10 *
11 * The contents of this file are subject to the Red Hat eCos Public
12 * License Version 1.1 (the "Licence"); you may not use this file
13 * except in compliance with the Licence. You may obtain a copy of
14 * the Licence at http://www.redhat.com/
15 *
16 * Software distributed under the Licence is distributed on an "AS IS"
17 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
18 * See the Licence for the specific language governing rights and
19 * limitations under the Licence.
20 *
21 * The Original Code is JFFS2 - Journalling Flash File System, version 2
22 *
23 * Alternatively, the contents of this file may be used under the
24 * terms of the GNU General Public License version 2 (the "GPL"), in
25 * which case the provisions of the GPL are applicable instead of the
26 * above. If you wish to allow the use of your version of this file
27 * only under the terms of the GPL and not to allow others to use your
28 * version of this file under the RHEPL, indicate your decision by
29 * deleting the provisions above and replace them with the notice and
30 * other provisions required by the GPL. If you do not delete the
31 * provisions above, a recipient may use your version of this file
32 * under either the RHEPL or the GPL.
33 *
34 * $Id: symlink.c,v 1.5.2.1 2002/01/15 10:39:06 dwmw2 Exp $
35 *
36 */
37
38
39 #include <linux/kernel.h>
40 #include <linux/slab.h>
41 #include <linux/fs.h>
42 #include <linux/jffs2.h>
43 #include "nodelist.h"
44
45 int jffs2_readlink(struct dentry *dentry, char *buffer, int buflen);
46 int jffs2_follow_link(struct dentry *dentry, struct nameidata *nd);
47
48 struct inode_operations jffs2_symlink_inode_operations =
49 {
50 readlink: jffs2_readlink,
51 follow_link: jffs2_follow_link,
52 setattr: jffs2_setattr
53 };
54
jffs2_getlink(struct dentry * dentry)55 static char *jffs2_getlink(struct dentry *dentry)
56 {
57 struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode);
58 char *buf;
59 int ret;
60
61 down(&f->sem);
62 if (!f->metadata) {
63 up(&f->sem);
64 printk(KERN_NOTICE "No metadata for symlink inode #%lu\n", dentry->d_inode->i_ino);
65 return ERR_PTR(-EINVAL);
66 }
67 buf = kmalloc(f->metadata->size+1, GFP_USER);
68 if (!buf) {
69 up(&f->sem);
70 return ERR_PTR(-ENOMEM);
71 }
72 buf[f->metadata->size]=0;
73
74 ret = jffs2_read_dnode(JFFS2_SB_INFO(dentry->d_inode->i_sb), f->metadata, buf, 0, f->metadata->size);
75 up(&f->sem);
76 if (ret) {
77 kfree(buf);
78 return ERR_PTR(ret);
79 }
80 return buf;
81
82 }
jffs2_readlink(struct dentry * dentry,char * buffer,int buflen)83 int jffs2_readlink(struct dentry *dentry, char *buffer, int buflen)
84 {
85 unsigned char *kbuf;
86 int ret;
87
88 kbuf = jffs2_getlink(dentry);
89 if (IS_ERR(kbuf))
90 return PTR_ERR(kbuf);
91
92 ret = vfs_readlink(dentry, buffer, buflen, kbuf);
93 kfree(kbuf);
94 return ret;
95 }
96
jffs2_follow_link(struct dentry * dentry,struct nameidata * nd)97 int jffs2_follow_link(struct dentry *dentry, struct nameidata *nd)
98 {
99 unsigned char *buf;
100 int ret;
101
102 buf = jffs2_getlink(dentry);
103
104 if (IS_ERR(buf))
105 return PTR_ERR(buf);
106
107 ret = vfs_follow_link(nd, buf);
108 kfree(buf);
109 return ret;
110 }
111