procfs.h revision 1.5 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.5 1994/01/20 21:23:04 ws 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 Pctl, /* process control */
53 Pstatus, /* process status */
54 Pnote, /* process notifier */
55 Pnotepg /* process group notifier */
56 } pfstype;
57
58 /*
59 * control data for the proc file system.
60 */
61 struct pfsnode {
62 struct pfsnode *pfs_next; /* next on list */
63 struct vnode *pfs_vnode; /* vnode associated with this pfsnode */
64 pfstype pfs_type; /* type of procfs node */
65 pid_t pfs_pid; /* associated process */
66 u_short pfs_mode; /* mode bits for stat() */
67 u_long pfs_flags; /* open flags */
68 u_long pfs_fileno; /* unique file id */
69 };
70
71 #define PROCFS_NOTELEN 8 /* max length of a note (/proc/$pid/note) */
72 #define PROCFS_CTLLEN 8 /* max length of a ctl msg (/proc/$pid/ctl */
73
74 /*
75 * Kernel stuff follows
76 */
77 #ifdef KERNEL
78
79 #define NDEQ(ndp, s, len) \
80 ((ndp)->ni_namelen == (len) && \
81 (bcmp((s), (ndp)->ni_ptr, (len)) == 0))
82
83 /*
84 * Format of a directory entry in /proc, ...
85 * This must map onto struct dirent (see <dirent.h>)
86 */
87 #define PROCFS_NAMELEN 8
88 struct pfsdent {
89 u_long d_fileno;
90 u_short d_reclen;
91 u_short d_namlen;
92 char d_name[PROCFS_NAMELEN];
93 };
94 #define UIO_MX sizeof(struct pfsdent)
95 #define PROCFS_FILENO(pid, type) \
96 (((type) == Proot) ? \
97 ((pid) + 2) : \
98 ((((pid)+1) << 3) + ((int) (type))))
99
100 /*
101 * Convert between pfsnode vnode
102 */
103 #define VTOPFS(vp) ((struct pfsnode *)(vp)->v_data)
104 #define PFSTOV(pfs) ((pfs)->pfs_vnode)
105
106 typedef struct procfs_namemap procfs_namemap_t;
107 struct procfs_namemap {
108 const char *nm_name;
109 int nm_val;
110 };
111
112 extern int procfs_getuserstr __P((struct uio *, char *, int *));
113 extern procfs_namemap_t *procfs_findname __P((procfs_namemap_t *, char *, int));
114
115 struct reg;
116
117 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
118 extern int procfs_freevp __P((struct vnode *));
119 extern int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
120 extern struct vnode *procfs_findtextvp __P((struct proc *));
121 extern int procfs_sstep __P((struct proc *));
122 extern int procfs_read_regs __P((struct proc *, struct reg *));
123 extern int procfs_write_regs __P((struct proc *, struct reg *));
124 extern int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
125 extern int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
126 extern int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
127 extern int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
128 extern int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
129 extern int procfs_rw __P((struct vnode *, struct uio *, int, struct ucred *));
130
131 #define PROCFS_LOCKED 0x01
132 #define PROCFS_WANT 0x02
133
134 extern struct vnodeops procfs_vnodeops;
135 extern struct vfsops procfs_vfsops;
136
137 /*
138 * Prototypes for procfs vnode ops
139 */
140 int procfs_badop(); /* varargs */
141 int procfs_rw __P((
142 struct vnode *vp,
143 struct uio *uio,
144 int ioflag,
145 struct ucred *cred));
146 int procfs_lookup __P((
147 struct vnode *vp,
148 struct nameidata *ndp,
149 struct proc *p));
150 #define procfs_create ((int (*) __P(( \
151 struct nameidata *ndp, \
152 struct vattr *vap, \
153 struct proc *p))) procfs_badop)
154 #define procfs_mknod ((int (*) __P(( \
155 struct nameidata *ndp, \
156 struct vattr *vap, \
157 struct ucred *cred, \
158 struct proc *p))) procfs_badop)
159 int procfs_open __P((
160 struct vnode *vp,
161 int mode,
162 struct ucred *cred,
163 struct proc *p));
164 int procfs_close __P((
165 struct vnode *vp,
166 int fflag,
167 struct ucred *cred,
168 struct proc *p));
169 int procfs_access __P((
170 struct vnode *vp,
171 int mode,
172 struct ucred *cred,
173 struct proc *p));
174 int procfs_getattr __P((
175 struct vnode *vp,
176 struct vattr *vap,
177 struct ucred *cred,
178 struct proc *p));
179 int procfs_setattr __P((
180 struct vnode *vp,
181 struct vattr *vap,
182 struct ucred *cred,
183 struct proc *p));
184 #define procfs_read procfs_rw
185 #define procfs_write procfs_rw
186 int procfs_ioctl __P((
187 struct vnode *vp,
188 int command,
189 caddr_t data,
190 int fflag,
191 struct ucred *cred,
192 struct proc *p));
193 #define procfs_select ((int (*) __P(( \
194 struct vnode *vp, \
195 int which, \
196 int fflags, \
197 struct ucred *cred, \
198 struct proc *p))) procfs_badop)
199 #define procfs_mmap ((int (*) __P(( \
200 struct vnode *vp, \
201 int fflags, \
202 struct ucred *cred, \
203 struct proc *p))) procfs_badop)
204 #define procfs_fsync ((int (*) __P(( \
205 struct vnode *vp, \
206 int fflags, \
207 struct ucred *cred, \
208 int waitfor, \
209 struct proc *p))) procfs_badop)
210 #define procfs_seek ((int (*) __P(( \
211 struct vnode *vp, \
212 off_t oldoff, \
213 off_t newoff, \
214 struct ucred *cred))) procfs_badop)
215 #define procfs_remove ((int (*) __P(( \
216 struct nameidata *ndp, \
217 struct proc *p))) procfs_badop)
218 #define procfs_link ((int (*) __P(( \
219 struct vnode *vp, \
220 struct nameidata *ndp, \
221 struct proc *p))) procfs_badop)
222 #define procfs_rename ((int (*) __P(( \
223 struct nameidata *fndp, \
224 struct nameidata *tdnp, \
225 struct proc *p))) procfs_badop)
226 #define procfs_mkdir ((int (*) __P(( \
227 struct nameidata *ndp, \
228 struct vattr *vap, \
229 struct proc *p))) procfs_badop)
230 #define procfs_rmdir ((int (*) __P(( \
231 struct nameidata *ndp, \
232 struct proc *p))) procfs_badop)
233 #define procfs_symlink ((int (*) __P(( \
234 struct nameidata *ndp, \
235 struct vattr *vap, \
236 char *target, \
237 struct proc *p))) procfs_badop)
238 int procfs_readdir __P((
239 struct vnode *vp,
240 struct uio *uio,
241 struct ucred *cred,
242 int *eofflagp,
243 u_int *cookies,
244 int ncookies));
245 int procfs_readlink __P((
246 struct vnode *vp,
247 struct uio *uio,
248 struct ucred *cred));
249 int procfs_abortop __P((
250 struct nameidata *ndp));
251 int procfs_inactive __P((
252 struct vnode *vp,
253 struct proc *p));
254 int procfs_reclaim __P((
255 struct vnode *vp));
256 #define procfs_lock ((int (*) __P(( \
257 struct vnode *vp))) nullop)
258 #define procfs_unlock ((int (*) __P(( \
259 struct vnode *vp))) nullop)
260 int procfs_bmap __P((
261 struct vnode *vp,
262 daddr_t bn,
263 struct vnode **vpp,
264 daddr_t *bnp));
265 #define procfs_strategy ((int (*) __P(( \
266 struct buf *bp))) procfs_badop)
267 int procfs_print __P((
268 struct vnode *vp));
269 #define procfs_islocked ((int (*) __P(( \
270 struct vnode *vp))) nullop)
271 #define procfs_advlock ((int (*) __P(( \
272 struct vnode *vp, \
273 caddr_t id, \
274 int op, \
275 struct flock *fl, \
276 int flags))) procfs_badop)
277
278 #endif /* KERNEL */
279