procfs.h revision 1.7 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.7 1994/02/06 14:01:16 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 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 #define PROCFS_LOCKED 0x01
133 #define PROCFS_WANT 0x02
134
135 extern struct vnodeops procfs_vnodeops;
136 extern struct vfsops procfs_vfsops;
137
138 /*
139 * Prototypes for procfs vnode ops
140 */
141 int procfs_badop(); /* varargs */
142 int procfs_rw __P((
143 struct vnode *vp,
144 struct uio *uio,
145 int ioflag,
146 struct ucred *cred));
147 int procfs_lookup __P((
148 struct vnode *vp,
149 struct nameidata *ndp,
150 struct proc *p));
151 #define procfs_create ((int (*) __P(( \
152 struct nameidata *ndp, \
153 struct vattr *vap, \
154 struct proc *p))) procfs_badop)
155 #define procfs_mknod ((int (*) __P(( \
156 struct nameidata *ndp, \
157 struct vattr *vap, \
158 struct ucred *cred, \
159 struct proc *p))) procfs_badop)
160 int procfs_open __P((
161 struct vnode *vp,
162 int mode,
163 struct ucred *cred,
164 struct proc *p));
165 int procfs_close __P((
166 struct vnode *vp,
167 int fflag,
168 struct ucred *cred,
169 struct proc *p));
170 int procfs_access __P((
171 struct vnode *vp,
172 int mode,
173 struct ucred *cred,
174 struct proc *p));
175 int procfs_getattr __P((
176 struct vnode *vp,
177 struct vattr *vap,
178 struct ucred *cred,
179 struct proc *p));
180 int procfs_setattr __P((
181 struct vnode *vp,
182 struct vattr *vap,
183 struct ucred *cred,
184 struct proc *p));
185 #define procfs_read procfs_rw
186 #define procfs_write procfs_rw
187 int procfs_ioctl __P((
188 struct vnode *vp,
189 int command,
190 caddr_t data,
191 int fflag,
192 struct ucred *cred,
193 struct proc *p));
194 #define procfs_select ((int (*) __P(( \
195 struct vnode *vp, \
196 int which, \
197 int fflags, \
198 struct ucred *cred, \
199 struct proc *p))) procfs_badop)
200 #define procfs_mmap ((int (*) __P(( \
201 struct vnode *vp, \
202 int fflags, \
203 struct ucred *cred, \
204 struct proc *p))) procfs_badop)
205 #define procfs_fsync ((int (*) __P(( \
206 struct vnode *vp, \
207 int fflags, \
208 struct ucred *cred, \
209 int waitfor, \
210 struct proc *p))) procfs_badop)
211 #define procfs_seek ((int (*) __P(( \
212 struct vnode *vp, \
213 off_t oldoff, \
214 off_t newoff, \
215 struct ucred *cred))) procfs_badop)
216 #define procfs_remove ((int (*) __P(( \
217 struct nameidata *ndp, \
218 struct proc *p))) procfs_badop)
219 #define procfs_link ((int (*) __P(( \
220 struct vnode *vp, \
221 struct nameidata *ndp, \
222 struct proc *p))) procfs_badop)
223 #define procfs_rename ((int (*) __P(( \
224 struct nameidata *fndp, \
225 struct nameidata *tdnp, \
226 struct proc *p))) procfs_badop)
227 #define procfs_mkdir ((int (*) __P(( \
228 struct nameidata *ndp, \
229 struct vattr *vap, \
230 struct proc *p))) procfs_badop)
231 #define procfs_rmdir ((int (*) __P(( \
232 struct nameidata *ndp, \
233 struct proc *p))) procfs_badop)
234 #define procfs_symlink ((int (*) __P(( \
235 struct nameidata *ndp, \
236 struct vattr *vap, \
237 char *target, \
238 struct proc *p))) procfs_badop)
239 int procfs_readdir __P((
240 struct vnode *vp,
241 struct uio *uio,
242 struct ucred *cred,
243 int *eofflagp,
244 u_int *cookies,
245 int ncookies));
246 int procfs_readlink __P((
247 struct vnode *vp,
248 struct uio *uio,
249 struct ucred *cred));
250 int procfs_abortop __P((
251 struct nameidata *ndp));
252 int procfs_inactive __P((
253 struct vnode *vp,
254 struct proc *p));
255 int procfs_reclaim __P((
256 struct vnode *vp));
257 #define procfs_lock ((int (*) __P(( \
258 struct vnode *vp))) nullop)
259 #define procfs_unlock ((int (*) __P(( \
260 struct vnode *vp))) nullop)
261 int procfs_bmap __P((
262 struct vnode *vp,
263 daddr_t bn,
264 struct vnode **vpp,
265 daddr_t *bnp));
266 #define procfs_strategy ((int (*) __P(( \
267 struct buf *bp))) procfs_badop)
268 int procfs_print __P((
269 struct vnode *vp));
270 #define procfs_islocked ((int (*) __P(( \
271 struct vnode *vp))) nullop)
272 #define procfs_advlock ((int (*) __P(( \
273 struct vnode *vp, \
274 caddr_t id, \
275 int op, \
276 struct flock *fl, \
277 int flags))) procfs_badop)
278
279 #endif /* KERNEL */
280