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