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