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