This source file includes following definitions.
- proc_lookupfd
- proc_readfd
1
2
3
4
5
6
7
8
9 #include <asm/segment.h>
10
11 #include <linux/errno.h>
12 #include <linux/sched.h>
13 #include <linux/proc_fs.h>
14 #include <linux/stat.h>
15
16 static int proc_readfd(struct inode *, struct file *, struct dirent *, int);
17 static int proc_lookupfd(struct inode *,const char *,int,struct inode **);
18
19 static struct file_operations proc_fd_operations = {
20 NULL,
21 NULL,
22 NULL,
23 proc_readfd,
24 NULL,
25 NULL,
26 NULL,
27 NULL,
28 NULL,
29 NULL
30 };
31
32
33
34
35 struct inode_operations proc_fd_inode_operations = {
36 &proc_fd_operations,
37 NULL,
38 proc_lookupfd,
39 NULL,
40 NULL,
41 NULL,
42 NULL,
43 NULL,
44 NULL,
45 NULL,
46 NULL,
47 NULL,
48 NULL,
49 NULL,
50 NULL
51 };
52
53 static int proc_lookupfd(struct inode * dir,const char * name, int len,
54 struct inode ** result)
55 {
56 unsigned int ino, pid, fd, c;
57 struct task_struct * p;
58 struct super_block * sb;
59 int i;
60
61 *result = NULL;
62 ino = dir->i_ino;
63 pid = ino >> 16;
64 ino &= 0x0000ffff;
65 ino -= 7;
66 if (!dir)
67 return -ENOENT;
68 sb = dir->i_sb;
69 if (!pid || ino > 1 || !S_ISDIR(dir->i_mode)) {
70 iput(dir);
71 return -ENOENT;
72 }
73 if (!len || (name[0] == '.' && (len == 1 ||
74 (name[1] == '.' && len == 2)))) {
75 if (len < 2) {
76 *result = dir;
77 return 0;
78 }
79 if (!(*result = iget(sb,(pid << 16)+2))) {
80 iput(dir);
81 return -ENOENT;
82 }
83 iput(dir);
84 return 0;
85 }
86 iput(dir);
87 fd = 0;
88 while (len-- > 0) {
89 c = *name - '0';
90 name++;
91 if (c > 9) {
92 fd = 0xfffff;
93 break;
94 }
95 fd *= 10;
96 fd += c;
97 if (fd & 0xffff0000) {
98 fd = 0xfffff;
99 break;
100 }
101 }
102 for (i = 0 ; i < NR_TASKS ; i++)
103 if ((p = task[i]) && p->pid == pid)
104 break;
105 if (!pid || i >= NR_TASKS)
106 return -ENOENT;
107 if (!ino) {
108 if (fd >= NR_OPEN || !p->filp[fd] || !p->filp[fd]->f_inode)
109 return -ENOENT;
110 ino = (pid << 16) + 0x100 + fd;
111 } else {
112 if (fd >= p->numlibraries)
113 return -ENOENT;
114 ino = (pid << 16) + 0x200 + fd;
115 }
116 if (!(*result = iget(sb,ino)))
117 return -ENOENT;
118 return 0;
119 }
120
121 static int proc_readfd(struct inode * inode, struct file * filp,
122 struct dirent * dirent, int count)
123 {
124 struct task_struct * p;
125 unsigned int fd, pid, ino;
126 int i,j;
127
128 if (!inode || !S_ISDIR(inode->i_mode))
129 return -EBADF;
130 ino = inode->i_ino;
131 pid = ino >> 16;
132 ino &= 0x0000ffff;
133 ino -= 7;
134 if (ino > 1)
135 return 0;
136 while (1) {
137 fd = filp->f_pos;
138 filp->f_pos++;
139 if (fd < 2) {
140 i = j = fd+1;
141 if (!fd)
142 fd = inode->i_ino;
143 else
144 fd = (inode->i_ino & 0xffff0000) | 2;
145 put_fs_long(fd, &dirent->d_ino);
146 put_fs_word(i, &dirent->d_reclen);
147 put_fs_byte(0, i+dirent->d_name);
148 while (i--)
149 put_fs_byte('.', i+dirent->d_name);
150 return j;
151 }
152 fd -= 2;
153 for (i = 1 ; i < NR_TASKS ; i++)
154 if ((p = task[i]) && p->pid == pid)
155 break;
156 if (i >= NR_TASKS)
157 return 0;
158 if (!ino) {
159 if (fd >= NR_OPEN)
160 break;
161 if (!p->filp[fd] || !p->filp[fd]->f_inode)
162 continue;
163 } else
164 if (fd >= p->numlibraries)
165 break;
166 j = 10;
167 i = 1;
168 while (fd >= j) {
169 j *= 10;
170 i++;
171 }
172 j = i;
173 if (!ino)
174 ino = (pid << 16) + 0x100 + fd;
175 else
176 ino = (pid << 16) + 0x200 + fd;
177 put_fs_long(ino, &dirent->d_ino);
178 put_fs_word(i, &dirent->d_reclen);
179 put_fs_byte(0, i+dirent->d_name);
180 while (i--) {
181 put_fs_byte('0'+(fd % 10), i+dirent->d_name);
182 fd /= 10;
183 }
184 return j;
185 }
186 return 0;
187 }