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