procfs.h revision 1.13 1 /* $NetBSD: procfs.h,v 1.13 1995/03/29 22:08:30 briggs 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.7 (Berkeley) 6/15/94
40 */
41
42 /*
43 * The different types of node in a procfs filesystem
44 */
45 typedef enum {
46 Proot, /* the filesystem root */
47 Pcurproc, /* symbolic link for curproc */
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 FP 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 64 /* 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 #define CNEQ(cnp, s, len) \
80 ((cnp)->cn_namelen == (len) && \
81 (bcmp((s), (cnp)->cn_nameptr, (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_int32_t d_fileno;
90 u_int16_t d_reclen;
91 u_int8_t d_type;
92 u_int8_t d_namlen;
93 char d_name[PROCFS_NAMELEN];
94 };
95 #define UIO_MX sizeof(struct pfsdent)
96 #define PROCFS_FILENO(pid, type) \
97 (((type) < Pproc) ? \
98 ((type) + 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 vfs_namemap vfs_namemap_t;
108 struct vfs_namemap {
109 const char *nm_name;
110 int nm_val;
111 };
112
113 int vfs_getuserstr __P((struct uio *, char *, int *));
114 vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
115
116 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
117 int procfs_freevp __P((struct vnode *));
118 int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
119 struct vnode *procfs_findtextvp __P((struct proc *));
120 int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
121 int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
122 int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
123 int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
124 int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
125 int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
126
127 /* functions to check whether or not files should be displayed */
128 int procfs_validfile __P((struct proc *));
129 int procfs_validfpregs __P((struct proc *));
130 int procfs_validregs __P((struct proc *));
131
132 #define PROCFS_LOCKED 0x01
133 #define PROCFS_WANT 0x02
134
135 extern int (**procfs_vnodeop_p)();
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((struct vop_read_args *));
143 int procfs_lookup __P((struct vop_lookup_args *));
144 #define procfs_create ((int (*) __P((struct vop_create_args *))) procfs_badop)
145 #define procfs_mknod ((int (*) __P((struct vop_mknod_args *))) procfs_badop)
146 int procfs_open __P((struct vop_open_args *));
147 int procfs_close __P((struct vop_close_args *));
148 int procfs_access __P((struct vop_access_args *));
149 int procfs_getattr __P((struct vop_getattr_args *));
150 int procfs_setattr __P((struct vop_setattr_args *));
151 #define procfs_read procfs_rw
152 #define procfs_write procfs_rw
153 int procfs_ioctl __P((struct vop_ioctl_args *));
154 #define procfs_select ((int (*) __P((struct vop_select_args *))) procfs_badop)
155 #define procfs_mmap ((int (*) __P((struct vop_mmap_args *))) procfs_badop)
156 #define procfs_fsync ((int (*) __P((struct vop_fsync_args *))) procfs_badop)
157 #define procfs_seek ((int (*) __P((struct vop_seek_args *))) procfs_badop)
158 #define procfs_remove ((int (*) __P((struct vop_remove_args *))) procfs_badop)
159 #define procfs_link ((int (*) __P((struct vop_link_args *))) procfs_badop)
160 #define procfs_rename ((int (*) __P((struct vop_rename_args *))) procfs_badop)
161 #define procfs_mkdir ((int (*) __P((struct vop_mkdir_args *))) procfs_badop)
162 #define procfs_rmdir ((int (*) __P((struct vop_rmdir_args *))) procfs_badop)
163 #define procfs_symlink ((int (*) __P((struct vop_symlink_args *))) procfs_badop)
164 int procfs_readdir __P((struct vop_readdir_args *));
165 int procfs_readlink __P((struct vop_readlink_args *));
166 int procfs_abortop __P((struct vop_abortop_args *));
167 int procfs_inactive __P((struct vop_inactive_args *));
168 int procfs_reclaim __P((struct vop_reclaim_args *));
169 #define procfs_lock ((int (*) __P((struct vop_lock_args *))) nullop)
170 #define procfs_unlock ((int (*) __P((struct vop_unlock_args *))) nullop)
171 int procfs_bmap __P((struct vop_bmap_args *));
172 #define procfs_strategy ((int (*) __P((struct vop_strategy_args *))) procfs_badop)
173 int procfs_print __P((struct vop_print_args *));
174 #define procfs_islocked ((int (*) __P((struct vop_islocked_args *))) nullop)
175 #define procfs_advlock ((int (*) __P((struct vop_advlock_args *))) procfs_badop)
176 #define procfs_blkatoff ((int (*) __P((struct vop_blkatoff_args *))) procfs_badop)
177 #define procfs_valloc ((int (*) __P((struct vop_valloc_args *))) procfs_badop)
178 #define procfs_vfree ((int (*) __P((struct vop_vfree_args *))) nullop)
179 #define procfs_truncate ((int (*) __P((struct vop_truncate_args *))) procfs_badop)
180 #define procfs_update ((int (*) __P((struct vop_update_args *))) nullop)
181 #endif /* _KERNEL */
182