This source file includes following definitions.
- proc_put_inode
- proc_put_super
- 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 void proc_put_inode(struct inode *inode)
20 {
21 if (inode->i_nlink)
22 return;
23 inode->i_size = 0;
24 }
25
26 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 };
42
43 struct super_block *proc_read_super(struct super_block *s,void *data,
44 int silent)
45 {
46 lock_super(s);
47 s->s_blocksize = 1024;
48 s->s_magic = PROC_SUPER_MAGIC;
49 s->s_op = &proc_sops;
50 unlock_super(s);
51 if (!(s->s_mounted = iget(s,PROC_ROOT_INO))) {
52 s->s_dev = 0;
53 printk("get root inode failed\n");
54 return NULL;
55 }
56 return s;
57 }
58
59 void proc_statfs(struct super_block *sb, struct statfs *buf)
60 {
61 put_fs_long(PROC_SUPER_MAGIC, &buf->f_type);
62 put_fs_long(1024, &buf->f_bsize);
63 put_fs_long(0, &buf->f_blocks);
64 put_fs_long(0, &buf->f_bfree);
65 put_fs_long(0, &buf->f_bavail);
66 put_fs_long(0, &buf->f_files);
67 put_fs_long(0, &buf->f_ffree);
68 put_fs_long(NAME_MAX, &buf->f_namelen);
69
70 }
71
72 void proc_read_inode(struct inode * inode)
73 {
74 unsigned long ino, pid;
75 struct task_struct * p;
76 int i;
77
78 inode->i_op = NULL;
79 inode->i_mode = 0;
80 inode->i_uid = 0;
81 inode->i_gid = 0;
82 inode->i_nlink = 1;
83 inode->i_size = 0;
84 inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME;
85 inode->i_blocks = inode->i_blksize = 0;
86 ino = inode->i_ino;
87 pid = ino >> 16;
88 p = task[0];
89 for (i = 0; i < NR_TASKS ; i++)
90 if ((p = task[i]) && (p->pid == pid))
91 break;
92 if (!p || i >= NR_TASKS)
93 return;
94 if (ino == PROC_ROOT_INO) {
95 inode->i_mode = S_IFDIR | 0555;
96 inode->i_nlink = 2;
97 for (i = 1 ; i < NR_TASKS ; i++)
98 if (task[i])
99 inode->i_nlink++;
100 inode->i_op = &proc_root_inode_operations;
101 return;
102 }
103 if (!pid) {
104 inode->i_mode = S_IFREG | 0444;
105 inode->i_op = &proc_array_inode_operations;
106 if (ino == 5) {
107 inode->i_mode = S_IFREG | 0400;
108 inode->i_op = &proc_kmsg_inode_operations;
109 }
110 return;
111 }
112 ino &= 0x0000ffff;
113 inode->i_uid = p->euid;
114 inode->i_gid = p->egid;
115 switch (ino) {
116 case 2:
117 inode->i_nlink = 4;
118 inode->i_mode = S_IFDIR | 0555;
119 inode->i_op = &proc_base_inode_operations;
120 return;
121 case 3:
122 inode->i_op = &proc_mem_inode_operations;
123 inode->i_mode = S_IFREG | 0600;
124 return;
125 case 4:
126 case 5:
127 case 6:
128 inode->i_op = &proc_link_inode_operations;
129 inode->i_size = 64;
130 inode->i_mode = S_IFLNK | 0700;
131 return;
132 case 7:
133 case 8:
134 inode->i_mode = S_IFDIR | 0500;
135 inode->i_op = &proc_fd_inode_operations;
136 inode->i_nlink = 2;
137 return;
138 case 9:
139 case 10:
140 case 11:
141 case 12:
142 inode->i_mode = S_IFREG | 0444;
143 inode->i_op = &proc_array_inode_operations;
144 return;
145 }
146 switch (ino >> 8) {
147 case 1:
148 ino &= 0xff;
149 if (ino >= NR_OPEN || !p->filp[ino])
150 return;
151 inode->i_op = &proc_link_inode_operations;
152 inode->i_size = 64;
153 inode->i_mode = S_IFLNK | 0700;
154 return;
155 case 2:
156 ino &= 0xff;
157 if (ino >= p->numlibraries)
158 return;
159 inode->i_op = &proc_link_inode_operations;
160 inode->i_size = 64;
161 inode->i_mode = S_IFLNK | 0700;
162 return;
163 }
164 return;
165 }
166
167 void proc_write_inode(struct inode * inode)
168 {
169 inode->i_dirt=0;
170 }