This source file includes following definitions.
- proc_lookuproot
- proc_readroot
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_readroot(struct inode *, struct file *, struct dirent *, int);
17 static int proc_lookuproot(struct inode *,const char *,int,struct inode **);
18
19 static struct file_operations proc_root_operations = {
20 NULL,
21 NULL,
22 NULL,
23 proc_readroot,
24 NULL,
25 NULL,
26 NULL,
27 NULL,
28 NULL
29 };
30
31
32
33
34 struct inode_operations proc_root_inode_operations = {
35 &proc_root_operations,
36 NULL,
37 proc_lookuproot,
38 NULL,
39 NULL,
40 NULL,
41 NULL,
42 NULL,
43 NULL,
44 NULL,
45 NULL,
46 NULL,
47 NULL,
48 NULL
49 };
50
51 static int proc_lookuproot(struct inode * dir,const char * name, int len,
52 struct inode ** result)
53 {
54 unsigned int pid, c;
55 int i, ino;
56
57 *result = NULL;
58 if (!dir)
59 return -ENOENT;
60 if (!S_ISDIR(dir->i_mode)) {
61 iput(dir);
62 return -ENOENT;
63 }
64 pid = 0;
65 if (!len || (get_fs_byte(name) == '.' && (len == 1 ||
66 (get_fs_byte(name+1) == '.' && len == 2)))) {
67 *result = dir;
68 return 0;
69 }
70 while (len-- > 0) {
71 c = get_fs_byte(name) - '0';
72 name++;
73 if (c > 9) {
74 pid = 0;
75 break;
76 }
77 pid *= 10;
78 pid += c;
79 if (pid & 0xffff0000) {
80 pid = 0;
81 break;
82 }
83 }
84 for (i = 0 ; i < NR_TASKS ; i++)
85 if (task[i] && task[i]->pid == pid)
86 break;
87 if (!pid || i >= NR_TASKS) {
88 iput(dir);
89 return -ENOENT;
90 }
91 ino = (pid << 16) + 2;
92 if (!(*result = iget(dir->i_sb,ino))) {
93 iput(dir);
94 return -ENOENT;
95 }
96 iput(dir);
97 return 0;
98 }
99
100 static int proc_readroot(struct inode * inode, struct file * filp,
101 struct dirent * dirent, int count)
102 {
103 struct task_struct * p;
104 unsigned int pid;
105 int i,j;
106
107 if (!inode || !S_ISDIR(inode->i_mode))
108 return -EBADF;
109 while ((pid = filp->f_pos) < NR_TASKS+2) {
110 filp->f_pos++;
111 if (pid < 2) {
112 i = j = pid+1;
113 put_fs_long(1, &dirent->d_ino);
114 put_fs_word(i, &dirent->d_reclen);
115 put_fs_byte(0, i+dirent->d_name);
116 while (i--)
117 put_fs_byte('.', i+dirent->d_name);
118 return j;
119 }
120 p = task[pid-2];
121 if (!p || !(pid = p->pid))
122 continue;
123 if (pid & 0xffff0000)
124 continue;
125 j = 10;
126 i = 1;
127 while (pid >= j) {
128 j *= 10;
129 i++;
130 }
131 j = i;
132 put_fs_long((pid << 16)+2, &dirent->d_ino);
133 put_fs_word(i, &dirent->d_reclen);
134 put_fs_byte(0, i+dirent->d_name);
135 while (i--) {
136 put_fs_byte('0'+(pid % 10), i+dirent->d_name);
137 pid /= 10;
138 }
139 return j;
140 }
141 return 0;
142 }