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