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