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