This source file includes following definitions.
- proc_match
- proc_lookupbase
- proc_readbase
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_readbase(struct inode *, struct file *, struct dirent *, int);
17 static int proc_lookupbase(struct inode *,const char *,int,struct inode **);
18
19 static struct file_operations proc_base_operations = {
20 NULL,
21 NULL,
22 NULL,
23 proc_readbase,
24 NULL,
25 NULL,
26 NULL,
27 NULL,
28 NULL,
29 NULL
30 };
31
32
33
34
35 struct inode_operations proc_base_inode_operations = {
36 &proc_base_operations,
37 NULL,
38 proc_lookupbase,
39 NULL,
40 NULL,
41 NULL,
42 NULL,
43 NULL,
44 NULL,
45 NULL,
46 NULL,
47 NULL,
48 NULL,
49 NULL,
50 NULL
51 };
52
53 static struct proc_dir_entry base_dir[] = {
54 { 1,2,".." },
55 { 2,1,"." },
56 { 3,3,"mem" },
57 { 4,3,"cwd" },
58 { 5,4,"root" },
59 { 6,3,"exe" },
60 { 7,2,"fd" },
61 { 8,4,"mmap" },
62 { 9,7,"environ" },
63 { 10,7,"cmdline" },
64 { 11,4,"stat" },
65 { 12,5,"statm" },
66 { 15,4,"maps" }
67 };
68
69 #define NR_BASE_DIRENTRY ((sizeof (base_dir))/(sizeof (base_dir[0])))
70
71 int proc_match(int len,const char * name,struct proc_dir_entry * de)
72 {
73 register int same;
74
75 if (!de || !de->low_ino)
76 return 0;
77
78 if (!len && (de->name[0]=='.') && (de->name[1]=='\0'))
79 return 1;
80 if (de->namelen != len)
81 return 0;
82 __asm__ __volatile__(
83 "cld\n\t"
84 "repe ; cmpsb\n\t"
85 "setz %%al"
86 :"=a" (same)
87 :"0" (0),"S" ((long) name),"D" ((long) de->name),"c" (len)
88 :"cx","di","si");
89 return same;
90 }
91
92 static int proc_lookupbase(struct inode * dir,const char * name, int len,
93 struct inode ** result)
94 {
95 unsigned int pid, ino;
96 int i;
97
98 *result = NULL;
99 if (!dir)
100 return -ENOENT;
101 if (!S_ISDIR(dir->i_mode)) {
102 iput(dir);
103 return -ENOENT;
104 }
105 ino = dir->i_ino;
106 pid = ino >> 16;
107 i = NR_BASE_DIRENTRY;
108 while (i-- > 0 && !proc_match(len,name,base_dir+i))
109 ;
110 if (i < 0) {
111 iput(dir);
112 return -ENOENT;
113 }
114 if (base_dir[i].low_ino == 1)
115 ino = 1;
116 else
117 ino = (pid << 16) + base_dir[i].low_ino;
118 for (i = 0 ; i < NR_TASKS ; i++)
119 if (task[i] && task[i]->pid == pid)
120 break;
121 if (!pid || i >= NR_TASKS) {
122 iput(dir);
123 return -ENOENT;
124 }
125 if (!(*result = iget(dir->i_sb,ino))) {
126 iput(dir);
127 return -ENOENT;
128 }
129 iput(dir);
130 return 0;
131 }
132
133 static int proc_readbase(struct inode * inode, struct file * filp,
134 struct dirent * dirent, int count)
135 {
136 struct proc_dir_entry * de;
137 unsigned int pid, ino;
138 int i,j;
139
140 if (!inode || !S_ISDIR(inode->i_mode))
141 return -EBADF;
142 ino = inode->i_ino;
143 pid = ino >> 16;
144 for (i = 0 ; i < NR_TASKS ; i++)
145 if (task[i] && task[i]->pid == pid)
146 break;
147 if (!pid || i >= NR_TASKS)
148 return 0;
149 if (((unsigned) filp->f_pos) < NR_BASE_DIRENTRY) {
150 de = base_dir + filp->f_pos;
151 filp->f_pos++;
152 i = de->namelen;
153 ino = de->low_ino;
154 if (ino != 1)
155 ino |= (pid << 16);
156 put_fs_long(ino, &dirent->d_ino);
157 put_fs_word(i,&dirent->d_reclen);
158 put_fs_byte(0,i+dirent->d_name);
159 j = i;
160 while (i--)
161 put_fs_byte(de->name[i], i+dirent->d_name);
162 return j;
163 }
164 return 0;
165 }