procfs.h revision 1.25 1 /* $NetBSD: procfs.h,v 1.25 1999/03/13 00:57:13 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1993 Jan-Simon Pendry
5 * Copyright (c) 1993
6 * The Regents of the University of California. All rights reserved.
7 *
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the University of
22 * California, Berkeley and its contributors.
23 * 4. Neither the name of the University nor the names of its contributors
24 * may be used to endorse or promote products derived from this software
25 * without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 * SUCH DAMAGE.
38 *
39 * @(#)procfs.h 8.9 (Berkeley) 5/14/95
40 */
41
42 #if defined(_KERNEL) && !defined(_LKM)
43 #include "opt_uvm.h"
44 #endif
45
46 /*
47 * The different types of node in a procfs filesystem
48 */
49 typedef enum {
50 Proot, /* the filesystem root */
51 Pcurproc, /* symbolic link for curproc */
52 Pproc, /* a process-specific sub-directory */
53 Pfile, /* the executable file */
54 Pmem, /* the process's memory image */
55 Pregs, /* the process's register set */
56 Pfpregs, /* the process's FP register set */
57 Pctl, /* process control */
58 Pstatus, /* process status */
59 Pnote, /* process notifier */
60 Pnotepg, /* process group notifier */
61 Pmap, /* memory map */
62 Pcmdline /* process command line args */
63 } pfstype;
64
65 /*
66 * control data for the proc file system.
67 */
68 struct pfsnode {
69 struct pfsnode *pfs_next; /* next on list */
70 struct vnode *pfs_vnode; /* vnode associated with this pfsnode */
71 pfstype pfs_type; /* type of procfs node */
72 pid_t pfs_pid; /* associated process */
73 mode_t pfs_mode; /* mode bits for stat() */
74 u_long pfs_flags; /* open flags */
75 u_long pfs_fileno; /* unique file id */
76 };
77
78 #define PROCFS_NOTELEN 64 /* max length of a note (/proc/$pid/note) */
79 #define PROCFS_CTLLEN 8 /* max length of a ctl msg (/proc/$pid/ctl */
80
81 /*
82 * Kernel stuff follows
83 */
84 #ifdef _KERNEL
85 #define CNEQ(cnp, s, len) \
86 ((cnp)->cn_namelen == (len) && \
87 (memcmp((s), (cnp)->cn_nameptr, (len)) == 0))
88
89 #define UIO_MX 32
90
91 #define PROCFS_FILENO(pid, type) \
92 (((type) < Pproc) ? \
93 ((type) + 2) : \
94 ((((pid)+1) << 4) + ((int) (type))))
95
96 /*
97 * Convert between pfsnode vnode
98 */
99 #define VTOPFS(vp) ((struct pfsnode *)(vp)->v_data)
100 #define PFSTOV(pfs) ((pfs)->pfs_vnode)
101
102 typedef struct vfs_namemap vfs_namemap_t;
103 struct vfs_namemap {
104 const char *nm_name;
105 int nm_val;
106 };
107
108 int vfs_getuserstr __P((struct uio *, char *, int *));
109 vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
110
111 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
112 int procfs_freevp __P((struct vnode *));
113 int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
114 struct vnode *procfs_findtextvp __P((struct proc *));
115 int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *,
116 struct uio *));
117 int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *,
118 struct uio *));
119 int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *,
120 struct uio *));
121 int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *,
122 struct uio *));
123 int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *,
124 struct uio *));
125 int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *,
126 struct uio *));
127 int procfs_domap __P((struct proc *, struct proc *, struct pfsnode *,
128 struct uio *));
129 int procfs_docmdline __P((struct proc *, struct proc *, struct pfsnode *,
130 struct uio *));
131
132 int procfs_checkioperm __P((struct proc *, struct proc *));
133
134 #if !defined(UVM)
135 int procfs_rwmem __P((struct proc *, struct uio *));
136 #endif
137
138 /* functions to check whether or not files should be displayed */
139 int procfs_validfile __P((struct proc *));
140 int procfs_validfpregs __P((struct proc *));
141 int procfs_validregs __P((struct proc *));
142 int procfs_validmap __P((struct proc *));
143
144 int procfs_rw __P((void *));
145
146 #define PROCFS_LOCKED 0x01
147 #define PROCFS_WANT 0x02
148
149 extern int (**procfs_vnodeop_p) __P((void *));
150 extern struct vfsops procfs_vfsops;
151
152 int procfs_root __P((struct mount *, struct vnode **));
153
154 #endif /* _KERNEL */
155