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