This source file includes following definitions.
- nfs_follow_link
- nfs_readlink
1
2
3
4
5
6
7
8
9
10
11 #include <asm/segment.h>
12
13 #include <linux/sched.h>
14 #include <linux/errno.h>
15 #include <linux/nfs_fs.h>
16 #include <linux/stat.h>
17 #include <linux/mm.h>
18 #include <linux/malloc.h>
19 #include <linux/string.h>
20
21 static int nfs_readlink(struct inode *, char *, int);
22 static int nfs_follow_link(struct inode *, struct inode *, int, int,
23 struct inode **);
24
25
26
27
28 struct inode_operations nfs_symlink_inode_operations = {
29 NULL,
30 NULL,
31 NULL,
32 NULL,
33 NULL,
34 NULL,
35 NULL,
36 NULL,
37 NULL,
38 NULL,
39 nfs_readlink,
40 nfs_follow_link,
41 NULL,
42 NULL,
43 NULL
44 };
45
46 static int nfs_follow_link(struct inode *dir, struct inode *inode,
47 int flag, int mode, struct inode **res_inode)
48 {
49 int error, *mem;
50 unsigned int len;
51 char *res, *res2;
52
53 *res_inode = NULL;
54 if (!dir) {
55 dir = current->fs->root;
56 dir->i_count++;
57 }
58 if (!inode) {
59 iput(dir);
60 return -ENOENT;
61 }
62 if (!S_ISLNK(inode->i_mode)) {
63 iput(dir);
64 *res_inode = inode;
65 return 0;
66 }
67 if (current->link_count > 5) {
68 iput(inode);
69 iput(dir);
70 return -ELOOP;
71 }
72 error = nfs_proc_readlink(NFS_SERVER(inode), NFS_FH(inode), &mem,
73 &res, &len, NFS_MAXPATHLEN);
74 if ((res2 = (char *) kmalloc(NFS_MAXPATHLEN + 1, GFP_KERNEL)) == NULL) {
75 printk("NFS: no memory in nfs_follow_link\n");
76 error = -EIO;
77 }
78 if (error) {
79 iput(inode);
80 iput(dir);
81 kfree(mem);
82 return error;
83 }
84 memcpy(res2, res, len);
85 res2[len] = '\0';
86 kfree(mem);
87 iput(inode);
88 current->link_count++;
89 error = open_namei(res2, flag, mode, res_inode, dir);
90 current->link_count--;
91 kfree_s(res2, NFS_MAXPATHLEN + 1);
92 return error;
93 }
94
95 static int nfs_readlink(struct inode *inode, char *buffer, int buflen)
96 {
97 int error, *mem;
98 unsigned int len;
99 char *res;
100
101 if (!S_ISLNK(inode->i_mode)) {
102 iput(inode);
103 return -EINVAL;
104 }
105 if (buflen > NFS_MAXPATHLEN)
106 buflen = NFS_MAXPATHLEN;
107 error = nfs_proc_readlink(NFS_SERVER(inode), NFS_FH(inode), &mem,
108 &res, &len, buflen);
109 iput(inode);
110 if (! error) {
111 memcpy_tofs(buffer, res, len);
112 put_fs_byte('\0', buffer + len);
113 error = len;
114 }
115 kfree(mem);
116 return error;
117 }