1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
/*
* linux/fs/nfs/symlink.c
*
* Copyright (C) 1992 Rick Sladkey
*
* Optimization changes Copyright (C) 1994 Florian La Roche
*
* nfs symlink handling code
*/
#include <linux/sched.h>
#include <linux/errno.h>
#include <linux/nfs_fs.h>
#include <linux/stat.h>
#include <linux/mm.h>
#include <linux/malloc.h>
#include <linux/string.h>
#include <asm/uaccess.h>
static int nfs_readlink(struct inode *, char *, int);
static struct dentry *nfs_follow_link(struct inode *, struct dentry *);
/*
* symlinks can't do much...
*/
struct inode_operations nfs_symlink_inode_operations = {
NULL, /* no file-operations */
NULL, /* create */
NULL, /* lookup */
NULL, /* link */
NULL, /* unlink */
NULL, /* symlink */
NULL, /* mkdir */
NULL, /* rmdir */
NULL, /* mknod */
NULL, /* rename */
nfs_readlink, /* readlink */
nfs_follow_link, /* follow_link */
NULL, /* readpage */
NULL, /* writepage */
NULL, /* bmap */
NULL, /* truncate */
NULL /* permission */
};
static int nfs_readlink(struct inode *inode, char *buffer, int buflen)
{
int error;
unsigned int len;
char *res;
void *mem;
dfprintk(VFS, "nfs: readlink(%x/%ld)\n", inode->i_dev, inode->i_ino);
if (buflen > NFS_MAXPATHLEN)
buflen = NFS_MAXPATHLEN;
error = nfs_proc_readlink(NFS_SERVER(inode), NFS_FH(inode), &mem,
&res, &len, buflen);
if (! error) {
copy_to_user(buffer, res, len);
put_user('\0', buffer + len);
error = len;
kfree(mem);
}
return error;
}
static struct dentry * nfs_follow_link(struct inode * inode, struct dentry *base)
{
int error;
unsigned int len;
char *res;
void *mem;
char *path;
dfprintk(VFS, "nfs: follow_link(%x/%ld)\n", inode->i_dev, inode->i_ino);
error = nfs_proc_readlink(NFS_SERVER(inode), NFS_FH(inode), &mem,
&res, &len, NFS_MAXPATHLEN);
if (error) {
dput(base);
return ERR_PTR(error);
}
path = kmalloc(len + 1, GFP_KERNEL);
if (!path) {
dput(base);
kfree(mem);
return ERR_PTR(-ENOMEM);
}
memcpy(path, res, len);
path[len] = 0;
kfree(mem);
base = lookup_dentry(path, base, 1);
kfree(path);
return base;
}
|