This source file includes following definitions.
- proc_put_inode
- proc_put_super
- parse_options
- proc_get_inode
- proc_read_super
- proc_statfs
- proc_read_inode
- proc_write_inode
1
2
3
4
5
6
7 #include <linux/sched.h>
8 #include <linux/proc_fs.h>
9 #include <linux/kernel.h>
10 #include <linux/mm.h>
11 #include <linux/string.h>
12 #include <linux/stat.h>
13 #include <linux/locks.h>
14 #include <linux/limits.h>
15
16 #include <asm/system.h>
17 #include <asm/segment.h>
18
19 static void proc_put_inode(struct inode *inode)
20 {
21 if (inode->i_nlink)
22 return;
23 inode->i_size = 0;
24 }
25
26 static void proc_put_super(struct super_block *sb)
27 {
28 lock_super(sb);
29 sb->s_dev = 0;
30 unlock_super(sb);
31 }
32
33 static struct super_operations proc_sops = {
34 proc_read_inode,
35 NULL,
36 proc_write_inode,
37 proc_put_inode,
38 proc_put_super,
39 NULL,
40 proc_statfs,
41 NULL
42 };
43
44
45 static int parse_options(char *options,uid_t *uid,gid_t *gid)
46 {
47 char *this_char,*value;
48
49 *uid = current->uid;
50 *gid = current->gid;
51 if (!options) return 1;
52 for (this_char = strtok(options,","); this_char; this_char = strtok(NULL,",")) {
53 if ((value = strchr(this_char,'=')) != NULL)
54 *value++ = 0;
55 if (!strcmp(this_char,"uid")) {
56 if (!value || !*value)
57 return 0;
58 *uid = simple_strtoul(value,&value,0);
59 if (*value)
60 return 0;
61 }
62 else if (!strcmp(this_char,"gid")) {
63 if (!value || !*value)
64 return 0;
65 *gid = simple_strtoul(value,&value,0);
66 if (*value)
67 return 0;
68 }
69 else return 1;
70 }
71 return 1;
72 }
73
74 struct inode * proc_get_inode(struct super_block * s, int ino, struct proc_dir_entry * de)
75 {
76 struct inode * inode = iget(s, ino);
77 if (inode) {
78 inode->u.generic_ip = (void *) de;
79 if (de) {
80 if (de->mode) {
81 inode->i_mode = de->mode;
82 inode->i_uid = de->uid;
83 inode->i_gid = de->gid;
84 }
85 if (de->size)
86 inode->i_size = de->size;
87 if (de->ops)
88 inode->i_op = de->ops;
89 if (de->nlink)
90 inode->i_nlink = de->nlink;
91 if (de->fill_inode)
92 de->fill_inode(inode);
93 }
94 }
95 return inode;
96 }
97
98 struct super_block *proc_read_super(struct super_block *s,void *data,
99 int silent)
100 {
101 proc_root_init();
102 lock_super(s);
103 s->s_blocksize = 1024;
104 s->s_blocksize_bits = 10;
105 s->s_magic = PROC_SUPER_MAGIC;
106 s->s_op = &proc_sops;
107 unlock_super(s);
108 if (!(s->s_mounted = proc_get_inode(s, PROC_ROOT_INO, &proc_root))) {
109 s->s_dev = 0;
110 printk("get root inode failed\n");
111 return NULL;
112 }
113 parse_options(data, &s->s_mounted->i_uid, &s->s_mounted->i_gid);
114 return s;
115 }
116
117 void proc_statfs(struct super_block *sb, struct statfs *buf, int bufsiz)
118 {
119 struct statfs tmp;
120
121 tmp.f_type = PROC_SUPER_MAGIC;
122 tmp.f_bsize = PAGE_SIZE/sizeof(long);
123 tmp.f_blocks = 0;
124 tmp.f_bfree = 0;
125 tmp.f_bavail = 0;
126 tmp.f_files = 0;
127 tmp.f_ffree = 0;
128 tmp.f_namelen = NAME_MAX;
129 memcpy_tofs(buf, &tmp, bufsiz);
130 }
131
132 void proc_read_inode(struct inode * inode)
133 {
134 unsigned long ino, pid;
135 struct task_struct * p;
136 int i;
137
138 inode->i_op = NULL;
139 inode->i_mode = 0;
140 inode->i_uid = 0;
141 inode->i_gid = 0;
142 inode->i_nlink = 1;
143 inode->i_size = 0;
144 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
145 inode->i_blocks = 0;
146 inode->i_blksize = 1024;
147 ino = inode->i_ino;
148 pid = ino >> 16;
149 p = task[0];
150 for (i = 0; i < NR_TASKS ; i++)
151 if ((p = task[i]) && (p->pid == pid))
152 break;
153 if (!p || i >= NR_TASKS)
154 return;
155 if (ino == PROC_ROOT_INO) {
156 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
157 inode->i_nlink = 2;
158 for (i = 1 ; i < NR_TASKS ; i++)
159 if (task[i])
160 inode->i_nlink++;
161 return;
162 }
163
164 if (!pid) {
165 switch (ino) {
166 case PROC_KMSG:
167 inode->i_mode = S_IFREG | S_IRUSR;
168 inode->i_op = &proc_kmsg_inode_operations;
169 break;
170 case PROC_NET:
171 inode->i_nlink = 2;
172 break;
173 case PROC_SCSI:
174 inode->i_mode = S_IFDIR | S_IRUGO | S_IXUGO;
175 inode->i_nlink = 2;
176 inode->i_op = &proc_scsi_inode_operations;
177 break;
178 case PROC_KCORE:
179 inode->i_mode = S_IFREG | S_IRUSR;
180 inode->i_op = &proc_kcore_inode_operations;
181 inode->i_size = (MAP_NR(high_memory) << PAGE_SHIFT) + PAGE_SIZE;
182 break;
183 case PROC_PROFILE:
184 inode->i_mode = S_IFREG | S_IRUGO | S_IWUSR;
185 inode->i_op = &proc_profile_inode_operations;
186 inode->i_size = (1+prof_len) * sizeof(unsigned long);
187 break;
188 default:
189 inode->i_mode = S_IFREG | S_IRUGO;
190 inode->i_op = &proc_array_inode_operations;
191 break;
192 }
193 return;
194 }
195 ino &= 0x0000ffff;
196 if (ino == PROC_PID_INO || p->dumpable) {
197 inode->i_uid = p->euid;
198 inode->i_gid = p->egid;
199 }
200 switch (ino) {
201 case PROC_PID_INO:
202 inode->i_nlink = 4;
203 return;
204 case PROC_PID_MEM:
205 inode->i_op = &proc_mem_inode_operations;
206 inode->i_mode = S_IFREG | S_IRUSR | S_IWUSR;
207 return;
208 case PROC_PID_CWD:
209 case PROC_PID_ROOT:
210 case PROC_PID_EXE:
211 inode->i_op = &proc_link_inode_operations;
212 inode->i_size = 64;
213 inode->i_mode = S_IFLNK | S_IRWXU;
214 return;
215 case PROC_PID_FD:
216 inode->i_mode = S_IFDIR | S_IRUSR | S_IXUSR;
217 inode->i_op = &proc_fd_inode_operations;
218 inode->i_nlink = 2;
219 return;
220 case PROC_PID_ENVIRON:
221 inode->i_mode = S_IFREG | S_IRUSR;
222 inode->i_op = &proc_array_inode_operations;
223 return;
224 case PROC_PID_CMDLINE:
225 case PROC_PID_STAT:
226 case PROC_PID_STATM:
227 inode->i_mode = S_IFREG | S_IRUGO;
228 inode->i_op = &proc_array_inode_operations;
229 return;
230 case PROC_PID_MAPS:
231 inode->i_mode = S_IFIFO | S_IRUGO;
232 inode->i_op = &proc_arraylong_inode_operations;
233 return;
234 }
235 switch (ino >> 8) {
236 case PROC_PID_FD_DIR:
237 ino &= 0xff;
238 if (ino >= NR_OPEN || !p->files->fd[ino])
239 return;
240 inode->i_op = &proc_link_inode_operations;
241 inode->i_size = 64;
242 inode->i_mode = S_IFLNK;
243 if (p->files->fd[ino]->f_mode & 1)
244 inode->i_mode |= S_IRUSR | S_IXUSR;
245 if (p->files->fd[ino]->f_mode & 2)
246 inode->i_mode |= S_IWUSR | S_IXUSR;
247 return;
248 }
249 return;
250 }
251
252 void proc_write_inode(struct inode * inode)
253 {
254 inode->i_dirt=0;
255 }