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