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