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