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