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