procfs.h revision 1.8 1 /*
2 * Copyright (c) 1993 The Regents of the University of California.
3 * Copyright (c) 1993 Jan-Simon Pendry
4 * All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Jan-Simon Pendry.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by the University of
20 * California, Berkeley and its contributors.
21 * 4. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 *
37 * From:
38 * Id: procfs.h,v 4.1 1993/12/17 10:47:45 jsp Rel
39 *
40 * $Id: procfs.h,v 1.8 1994/04/12 02:55:51 cgd Exp $
41 */
42
43 /*
44 * The different types of node in a procfs filesystem
45 */
46 typedef enum {
47 Proot, /* the filesystem root */
48 Pproc, /* a process-specific sub-directory */
49 Pfile, /* the executable file */
50 Pmem, /* the process's memory image */
51 Pregs, /* the process's register set */
52 Pfpregs, /* the process's floating point register set */
53 Pctl, /* process control */
54 Pstatus, /* process status */
55 Pnote, /* process notifier */
56 Pnotepg /* process group notifier */
57 } pfstype;
58
59 /*
60 * control data for the proc file system.
61 */
62 struct pfsnode {
63 struct pfsnode *pfs_next; /* next on list */
64 struct vnode *pfs_vnode; /* vnode associated with this pfsnode */
65 pfstype pfs_type; /* type of procfs node */
66 pid_t pfs_pid; /* associated process */
67 u_short pfs_mode; /* mode bits for stat() */
68 u_long pfs_flags; /* open flags */
69 u_long pfs_fileno; /* unique file id */
70 };
71
72 #define PROCFS_NOTELEN 8 /* max length of a note (/proc/$pid/note) */
73 #define PROCFS_CTLLEN 8 /* max length of a ctl msg (/proc/$pid/ctl */
74
75 /*
76 * Kernel stuff follows
77 */
78 #ifdef KERNEL
79
80 #define NDEQ(ndp, s, len) \
81 ((ndp)->ni_namelen == (len) && \
82 (bcmp((s), (ndp)->ni_ptr, (len)) == 0))
83
84 /*
85 * Format of a directory entry in /proc, ...
86 * This must map onto struct dirent (see <dirent.h>)
87 */
88 #define PROCFS_NAMELEN 8
89 struct pfsdent {
90 u_long d_fileno;
91 u_short d_reclen;
92 u_short d_namlen;
93 char d_name[PROCFS_NAMELEN];
94 };
95 #define UIO_MX sizeof(struct pfsdent)
96 #define PROCFS_FILENO(pid, type) \
97 (((type) == Proot) ? \
98 ((pid) + 2) : \
99 ((((pid)+1) << 4) + ((int) (type))))
100
101 /*
102 * Convert between pfsnode vnode
103 */
104 #define VTOPFS(vp) ((struct pfsnode *)(vp)->v_data)
105 #define PFSTOV(pfs) ((pfs)->pfs_vnode)
106
107 typedef struct procfs_namemap procfs_namemap_t;
108 struct procfs_namemap {
109 const char *nm_name;
110 int nm_val;
111 };
112
113 extern int procfs_getuserstr __P((struct uio *, char *, int *));
114 extern procfs_namemap_t *procfs_findname __P((procfs_namemap_t *, char *, int));
115
116 struct reg;
117
118 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
119 extern int procfs_freevp __P((struct vnode *));
120 extern int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
121 extern struct vnode *procfs_findtextvp __P((struct proc *));
122 extern int procfs_sstep __P((struct proc *));
123 extern int procfs_read_regs __P((struct proc *, struct reg *));
124 extern int procfs_write_regs __P((struct proc *, struct reg *));
125 extern int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
126 extern int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
127 extern int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
128 extern int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
129 extern int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
130 extern int procfs_rw __P((struct vnode *, struct uio *, int, struct ucred *));
131
132 /* functions to check whether or not files should be displayed */
133 extern int procfs_validfile __P((struct proc *));
134 extern int procfs_validfpregs __P((struct proc *));
135 extern int procfs_validregs __P((struct proc *));
136
137 #define PROCFS_LOCKED 0x01
138 #define PROCFS_WANT 0x02
139
140 extern struct vnodeops procfs_vnodeops;
141 extern struct vfsops procfs_vfsops;
142
143 /*
144 * Prototypes for procfs vnode ops
145 */
146 int procfs_badop(); /* varargs */
147 int procfs_rw __P((
148 struct vnode *vp,
149 struct uio *uio,
150 int ioflag,
151 struct ucred *cred));
152 int procfs_lookup __P((
153 struct vnode *vp,
154 struct nameidata *ndp,
155 struct proc *p));
156 #define procfs_create ((int (*) __P(( \
157 struct nameidata *ndp, \
158 struct vattr *vap, \
159 struct proc *p))) procfs_badop)
160 #define procfs_mknod ((int (*) __P(( \
161 struct nameidata *ndp, \
162 struct vattr *vap, \
163 struct ucred *cred, \
164 struct proc *p))) procfs_badop)
165 int procfs_open __P((
166 struct vnode *vp,
167 int mode,
168 struct ucred *cred,
169 struct proc *p));
170 int procfs_close __P((
171 struct vnode *vp,
172 int fflag,
173 struct ucred *cred,
174 struct proc *p));
175 int procfs_access __P((
176 struct vnode *vp,
177 int mode,
178 struct ucred *cred,
179 struct proc *p));
180 int procfs_getattr __P((
181 struct vnode *vp,
182 struct vattr *vap,
183 struct ucred *cred,
184 struct proc *p));
185 int procfs_setattr __P((
186 struct vnode *vp,
187 struct vattr *vap,
188 struct ucred *cred,
189 struct proc *p));
190 #define procfs_read procfs_rw
191 #define procfs_write procfs_rw
192 int procfs_ioctl __P((
193 struct vnode *vp,
194 int command,
195 caddr_t data,
196 int fflag,
197 struct ucred *cred,
198 struct proc *p));
199 #define procfs_select ((int (*) __P(( \
200 struct vnode *vp, \
201 int which, \
202 int fflags, \
203 struct ucred *cred, \
204 struct proc *p))) procfs_badop)
205 #define procfs_mmap ((int (*) __P(( \
206 struct vnode *vp, \
207 int fflags, \
208 struct ucred *cred, \
209 struct proc *p))) procfs_badop)
210 #define procfs_fsync ((int (*) __P(( \
211 struct vnode *vp, \
212 int fflags, \
213 struct ucred *cred, \
214 int waitfor, \
215 struct proc *p))) procfs_badop)
216 #define procfs_seek ((int (*) __P(( \
217 struct vnode *vp, \
218 off_t oldoff, \
219 off_t newoff, \
220 struct ucred *cred))) procfs_badop)
221 #define procfs_remove ((int (*) __P(( \
222 struct nameidata *ndp, \
223 struct proc *p))) procfs_badop)
224 #define procfs_link ((int (*) __P(( \
225 struct vnode *vp, \
226 struct nameidata *ndp, \
227 struct proc *p))) procfs_badop)
228 #define procfs_rename ((int (*) __P(( \
229 struct nameidata *fndp, \
230 struct nameidata *tdnp, \
231 struct proc *p))) procfs_badop)
232 #define procfs_mkdir ((int (*) __P(( \
233 struct nameidata *ndp, \
234 struct vattr *vap, \
235 struct proc *p))) procfs_badop)
236 #define procfs_rmdir ((int (*) __P(( \
237 struct nameidata *ndp, \
238 struct proc *p))) procfs_badop)
239 #define procfs_symlink ((int (*) __P(( \
240 struct nameidata *ndp, \
241 struct vattr *vap, \
242 char *target, \
243 struct proc *p))) procfs_badop)
244 int procfs_readdir __P((
245 struct vnode *vp,
246 struct uio *uio,
247 struct ucred *cred,
248 int *eofflagp,
249 u_int *cookies,
250 int ncookies));
251 int procfs_readlink __P((
252 struct vnode *vp,
253 struct uio *uio,
254 struct ucred *cred));
255 int procfs_abortop __P((
256 struct nameidata *ndp));
257 int procfs_inactive __P((
258 struct vnode *vp,
259 struct proc *p));
260 int procfs_reclaim __P((
261 struct vnode *vp));
262 #define procfs_lock ((int (*) __P(( \
263 struct vnode *vp))) nullop)
264 #define procfs_unlock ((int (*) __P(( \
265 struct vnode *vp))) nullop)
266 int procfs_bmap __P((
267 struct vnode *vp,
268 daddr_t bn,
269 struct vnode **vpp,
270 daddr_t *bnp));
271 #define procfs_strategy ((int (*) __P(( \
272 struct buf *bp))) procfs_badop)
273 int procfs_print __P((
274 struct vnode *vp));
275 #define procfs_islocked ((int (*) __P(( \
276 struct vnode *vp))) nullop)
277 #define procfs_advlock ((int (*) __P(( \
278 struct vnode *vp, \
279 caddr_t id, \
280 int op, \
281 struct flock *fl, \
282 int flags))) procfs_badop)
283
284 #endif /* KERNEL */
285