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 };
45
46 static int ext_follow_link(struct inode * dir, struct inode * inode,
47 int flag, int mode, struct inode ** res_inode)
48 {
49 int error;
50 unsigned short fs;
51 struct buffer_head * bh;
52
53 *res_inode = NULL;
54 if (!dir) {
55 dir = current->root;
56 dir->i_count++;
57 }
58 if (!inode) {
59 iput(dir);
60 return -ENOENT;
61 }
62 if (!S_ISLNK(inode->i_mode)) {
63 iput(dir);
64 *res_inode = inode;
65 return 0;
66 }
67 if (current->link_count > 5) {
68 iput(dir);
69 iput(inode);
70 return -ELOOP;
71 }
72 if (!(bh = ext_bread(inode, 0, 0))) {
73 iput(inode);
74 iput(dir);
75 return -EIO;
76 }
77 iput(inode);
78 __asm__("mov %%fs,%0":"=r" (fs));
79 __asm__("mov %0,%%fs"::"r" ((unsigned short) 0x10));
80 current->link_count++;
81 error = open_namei(bh->b_data,flag,mode,res_inode,dir);
82 current->link_count--;
83 __asm__("mov %0,%%fs"::"r" (fs));
84 brelse(bh);
85 return error;
86 }
87
88 static int ext_readlink(struct inode * inode, char * buffer, int buflen)
89 {
90 struct buffer_head * bh;
91 int i;
92 char c;
93
94 if (!S_ISLNK(inode->i_mode)) {
95 iput(inode);
96 return -EINVAL;
97 }
98 if (buflen > 1023)
99 buflen = 1023;
100 bh = ext_bread(inode, 0, 0);
101 iput(inode);
102 if (!bh)
103 return 0;
104 i = 0;
105 while (i<buflen && (c = bh->b_data[i])) {
106 i++;
107 put_fs_byte(c,buffer++);
108 }
109 brelse(bh);
110 return i;
111 }