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