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 NULL
49 };
50
51 static int ext2_follow_link(struct inode * dir, struct inode * inode,
52 int flag, int mode, struct inode ** res_inode)
53 {
54 int error;
55 struct buffer_head * bh = NULL;
56 char * link;
57
58 *res_inode = NULL;
59 if (!dir) {
60 dir = current->fs->root;
61 dir->i_count++;
62 }
63 if (!inode) {
64 iput (dir);
65 return -ENOENT;
66 }
67 if (!S_ISLNK(inode->i_mode)) {
68 iput (dir);
69 *res_inode = inode;
70 return 0;
71 }
72 if (current->link_count > 5) {
73 iput (dir);
74 iput (inode);
75 return -ELOOP;
76 }
77 if (inode->i_blocks) {
78 if (!(bh = ext2_bread (inode, 0, 0, &error))) {
79 iput (dir);
80 iput (inode);
81 return -EIO;
82 }
83 link = bh->b_data;
84 } else
85 link = (char *) inode->u.ext2_i.i_data;
86 current->link_count++;
87 error = open_namei (link, flag, mode, res_inode, dir);
88 current->link_count--;
89 iput (inode);
90 if (bh)
91 brelse (bh);
92 return error;
93 }
94
95 static int ext2_readlink (struct inode * inode, char * buffer, int buflen)
96 {
97 struct buffer_head * bh = NULL;
98 char * link;
99 int i, err;
100 char c;
101
102 if (!S_ISLNK(inode->i_mode)) {
103 iput (inode);
104 return -EINVAL;
105 }
106 if (buflen > inode->i_sb->s_blocksize - 1)
107 buflen = inode->i_sb->s_blocksize - 1;
108 if (inode->i_blocks) {
109 bh = ext2_bread (inode, 0, 0, &err);
110 if (!bh) {
111 iput (inode);
112 return 0;
113 }
114 link = bh->b_data;
115 }
116 else
117 link = (char *) inode->u.ext2_i.i_data;
118 i = 0;
119 while (i < buflen && (c = link[i])) {
120 i++;
121 put_fs_byte (c, buffer++);
122 }
123 iput (inode);
124 if (bh)
125 brelse (bh);
126 return i;
127 }