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