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 { PROC_ROOT_INO, 1, "." },
56 { PROC_ROOT_INO, 2, ".." },
57 { PROC_LOADAVG, 7, "loadavg" },
58 { PROC_UPTIME, 6, "uptime" },
59 { PROC_MEMINFO, 7, "meminfo" },
60 { PROC_KMSG, 4, "kmsg" },
61 { PROC_VERSION, 7, "version" },
62 { PROC_SELF, 4, "self" },
63 { PROC_NET, 3, "net" },
64 #ifdef CONFIG_DEBUG_MALLOC
65 { PROC_MALLOC, 6, "malloc" },
66 #endif
67 { PROC_KCORE, 5, "kcore" },
68 { PROC_MODULES, 7, "modules" },
69 { PROC_STAT, 4, "stat" },
70 { PROC_DEVICES, 7, "devices" },
71 { PROC_INTERRUPTS, 10,"interrupts" },
72 { PROC_FILESYSTEMS, 11,"filesystems" },
73 { PROC_KSYMS, 5, "ksyms" },
74 { PROC_DMA, 3, "dma" },
75 };
76
77 #define NR_ROOT_DIRENTRY ((sizeof (root_dir))/(sizeof (root_dir[0])))
78
79 static int proc_lookuproot(struct inode * dir,const char * name, int len,
80 struct inode ** result)
81 {
82 unsigned int pid, c;
83 int i, ino;
84
85 *result = NULL;
86 if (!dir)
87 return -ENOENT;
88 if (!S_ISDIR(dir->i_mode)) {
89 iput(dir);
90 return -ENOENT;
91 }
92 i = NR_ROOT_DIRENTRY;
93 while (i-- > 0 && !proc_match(len,name,root_dir+i))
94 ;
95 if (i >= 0) {
96 ino = root_dir[i].low_ino;
97 if (ino == 1) {
98 *result = dir;
99 return 0;
100 }
101 if (ino == 7)
102 ino = (current->pid << 16) + 2;
103 } else {
104 pid = 0;
105 while (len-- > 0) {
106 c = *name - '0';
107 name++;
108 if (c > 9) {
109 pid = 0;
110 break;
111 }
112 pid *= 10;
113 pid += c;
114 if (pid & 0xffff0000) {
115 pid = 0;
116 break;
117 }
118 }
119 for (i = 0 ; i < NR_TASKS ; i++)
120 if (task[i] && task[i]->pid == pid)
121 break;
122 if (!pid || i >= NR_TASKS) {
123 iput(dir);
124 return -ENOENT;
125 }
126 ino = (pid << 16) + 2;
127 }
128 if (!(*result = iget(dir->i_sb,ino))) {
129 iput(dir);
130 return -ENOENT;
131 }
132 iput(dir);
133 return 0;
134 }
135
136 static int proc_readroot(struct inode * inode, struct file * filp,
137 struct dirent * dirent, int count)
138 {
139 struct task_struct * p;
140 unsigned int nr,pid;
141 int i,j;
142
143 if (!inode || !S_ISDIR(inode->i_mode))
144 return -EBADF;
145 repeat:
146 nr = filp->f_pos;
147 if (nr < NR_ROOT_DIRENTRY) {
148 struct proc_dir_entry * de = root_dir + nr;
149
150 filp->f_pos++;
151 i = de->namelen;
152 put_fs_long(de->low_ino, &dirent->d_ino);
153 put_fs_word(i,&dirent->d_reclen);
154 put_fs_byte(0,i+dirent->d_name);
155 j = i;
156 while (i--)
157 put_fs_byte(de->name[i], i+dirent->d_name);
158 return j;
159 }
160 nr -= NR_ROOT_DIRENTRY;
161 if (nr >= NR_TASKS)
162 return 0;
163 filp->f_pos++;
164 p = task[nr];
165 if (!p || !(pid = p->pid))
166 goto repeat;
167 if (pid & 0xffff0000)
168 goto repeat;
169 j = 10;
170 i = 1;
171 while (pid >= j) {
172 j *= 10;
173 i++;
174 }
175 j = i;
176 put_fs_long((pid << 16)+2, &dirent->d_ino);
177 put_fs_word(i, &dirent->d_reclen);
178 put_fs_byte(0, i+dirent->d_name);
179 while (i--) {
180 put_fs_byte('0'+(pid % 10), i+dirent->d_name);
181 pid /= 10;
182 }
183 return j;
184 }