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 #include <linux/config.h>
16
17 static int proc_readroot(struct inode *, struct file *, struct dirent *, int);
18 static int proc_lookuproot(struct inode *,const char *,int,struct inode **);
19
20 static struct file_operations proc_root_operations = {
21 NULL,
22 NULL,
23 NULL,
24 proc_readroot,
25 NULL,
26 NULL,
27 NULL,
28 NULL,
29 NULL,
30 NULL
31 };
32
33
34
35
36 struct inode_operations proc_root_inode_operations = {
37 &proc_root_operations,
38 NULL,
39 proc_lookuproot,
40 NULL,
41 NULL,
42 NULL,
43 NULL,
44 NULL,
45 NULL,
46 NULL,
47 NULL,
48 NULL,
49 NULL,
50 NULL,
51 NULL
52 };
53
54 static struct proc_dir_entry root_dir[] = {
55 { 1,1,"." },
56 { 1,2,".." },
57 { 2,7,"loadavg" },
58 { 3,6,"uptime" },
59 { 4,7,"meminfo" },
60 { 5,4,"kmsg" },
61 { 6,7,"version" },
62 { 7,4,"self" },
63 { 8,3,"net" },
64 #ifdef CONFIG_DEBUG_MALLOC
65 {13,6,"malloc" },
66 #endif
67 };
68
69 #define NR_ROOT_DIRENTRY ((sizeof (root_dir))/(sizeof (root_dir[0])))
70
71 static int proc_lookuproot(struct inode * dir,const char * name, int len,
72 struct inode ** result)
73 {
74 unsigned int pid, c;
75 int i, ino;
76
77 *result = NULL;
78 if (!dir)
79 return -ENOENT;
80 if (!S_ISDIR(dir->i_mode)) {
81 iput(dir);
82 return -ENOENT;
83 }
84 i = NR_ROOT_DIRENTRY;
85 while (i-- > 0 && !proc_match(len,name,root_dir+i))
86 ;
87 if (i >= 0) {
88 ino = root_dir[i].low_ino;
89 if (ino == 1) {
90 *result = dir;
91 return 0;
92 }
93 if (ino == 7)
94 ino = (current->pid << 16) + 2;
95 } else {
96 pid = 0;
97 while (len-- > 0) {
98 c = *name - '0';
99 name++;
100 if (c > 9) {
101 pid = 0;
102 break;
103 }
104 pid *= 10;
105 pid += c;
106 if (pid & 0xffff0000) {
107 pid = 0;
108 break;
109 }
110 }
111 for (i = 0 ; i < NR_TASKS ; i++)
112 if (task[i] && task[i]->pid == pid)
113 break;
114 if (!pid || i >= NR_TASKS) {
115 iput(dir);
116 return -ENOENT;
117 }
118 ino = (pid << 16) + 2;
119 }
120 if (!(*result = iget(dir->i_sb,ino))) {
121 iput(dir);
122 return -ENOENT;
123 }
124 iput(dir);
125 return 0;
126 }
127
128 static int proc_readroot(struct inode * inode, struct file * filp,
129 struct dirent * dirent, int count)
130 {
131 struct task_struct * p;
132 unsigned int nr,pid;
133 int i,j;
134
135 if (!inode || !S_ISDIR(inode->i_mode))
136 return -EBADF;
137 repeat:
138 nr = filp->f_pos;
139 if (nr < NR_ROOT_DIRENTRY) {
140 struct proc_dir_entry * de = root_dir + nr;
141
142 filp->f_pos++;
143 i = de->namelen;
144 put_fs_long(de->low_ino, &dirent->d_ino);
145 put_fs_word(i,&dirent->d_reclen);
146 put_fs_byte(0,i+dirent->d_name);
147 j = i;
148 while (i--)
149 put_fs_byte(de->name[i], i+dirent->d_name);
150 return j;
151 }
152 nr -= NR_ROOT_DIRENTRY;
153 if (nr >= NR_TASKS)
154 return 0;
155 filp->f_pos++;
156 p = task[nr];
157 if (!p || !(pid = p->pid))
158 goto repeat;
159 if (pid & 0xffff0000)
160 goto repeat;
161 j = 10;
162 i = 1;
163 while (pid >= j) {
164 j *= 10;
165 i++;
166 }
167 j = i;
168 put_fs_long((pid << 16)+2, &dirent->d_ino);
169 put_fs_word(i, &dirent->d_reclen);
170 put_fs_byte(0, i+dirent->d_name);
171 while (i--) {
172 put_fs_byte('0'+(pid % 10), i+dirent->d_name);
173 pid /= 10;
174 }
175 return j;
176 }