procfs.h revision 1.10 1 /*
2 * Copyright (c) 1993 Jan-Simon Pendry
3 * Copyright (c) 1993
4 * The Regents of the University of California. 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: @(#)procfs.h 8.7 (Berkeley) 6/15/94
38 * $Id: procfs.h,v 1.10 1994/06/15 22:59:02 mycroft Exp $
39 */
40
41 /*
42 * The different types of node in a procfs filesystem
43 */
44 typedef enum {
45 Proot, /* the filesystem root */
46 Pcurproc, /* symbolic link for curproc */
47 Pproc, /* a process-specific sub-directory */
48 Pfile, /* the executable file */
49 Pmem, /* the process's memory image */
50 Pregs, /* the process's register set */
51 Pfpregs, /* the process's FP 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 64 /* 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 #define CNEQ(cnp, s, len) \
79 ((cnp)->cn_namelen == (len) && \
80 (bcmp((s), (cnp)->cn_nameptr, (len)) == 0))
81
82 /*
83 * Format of a directory entry in /proc, ...
84 * This must map onto struct dirent (see <dirent.h>)
85 */
86 #define PROCFS_NAMELEN 8
87 struct pfsdent {
88 u_long d_fileno;
89 u_short d_reclen;
90 u_char d_type;
91 u_char d_namlen;
92 char d_name[PROCFS_NAMELEN];
93 };
94 #define UIO_MX sizeof(struct pfsdent)
95 #define PROCFS_FILENO(pid, type) \
96 (((type) < Pproc) ? \
97 ((type) + 2) : \
98 ((((pid)+1) << 4) + ((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 vfs_namemap vfs_namemap_t;
107 struct vfs_namemap {
108 const char *nm_name;
109 int nm_val;
110 };
111
112 int vfs_getuserstr __P((struct uio *, char *, int *));
113 vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
114
115 #define PFIND(pid) ((pid) ? pfind(pid) : &proc0)
116 int procfs_freevp __P((struct vnode *));
117 int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
118 struct vnode *procfs_findtextvp __P((struct proc *));
119 int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
120 int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
121 int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
122 int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
123 int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
124 int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
125
126 /* functions to check whether or not files should be displayed */
127 int procfs_validfile __P((struct proc *));
128 int procfs_validfpregs __P((struct proc *));
129 int procfs_validregs __P((struct proc *));
130
131 #define PROCFS_LOCKED 0x01
132 #define PROCFS_WANT 0x02
133
134 extern int (**procfs_vnodeop_p)();
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((struct vop_read_args *));
142 int procfs_lookup __P((struct vop_lookup_args *));
143 #define procfs_create ((int (*) __P((struct vop_create_args *))) procfs_badop)
144 #define procfs_mknod ((int (*) __P((struct vop_mknod_args *))) procfs_badop)
145 int procfs_open __P((struct vop_open_args *));
146 int procfs_close __P((struct vop_close_args *));
147 int procfs_access __P((struct vop_access_args *));
148 int procfs_getattr __P((struct vop_getattr_args *));
149 int procfs_setattr __P((struct vop_setattr_args *));
150 #define procfs_read procfs_rw
151 #define procfs_write procfs_rw
152 int procfs_ioctl __P((struct vop_ioctl_args *));
153 #define procfs_select ((int (*) __P((struct vop_select_args *))) procfs_badop)
154 #define procfs_mmap ((int (*) __P((struct vop_mmap_args *))) procfs_badop)
155 #define procfs_fsync ((int (*) __P((struct vop_fsync_args *))) procfs_badop)
156 #define procfs_seek ((int (*) __P((struct vop_seek_args *))) procfs_badop)
157 #define procfs_remove ((int (*) __P((struct vop_remove_args *))) procfs_badop)
158 #define procfs_link ((int (*) __P((struct vop_link_args *))) procfs_badop)
159 #define procfs_rename ((int (*) __P((struct vop_rename_args *))) procfs_badop)
160 #define procfs_mkdir ((int (*) __P((struct vop_mkdir_args *))) procfs_badop)
161 #define procfs_rmdir ((int (*) __P((struct vop_rmdir_args *))) procfs_badop)
162 #define procfs_symlink ((int (*) __P((struct vop_symlink_args *))) procfs_badop)
163 int procfs_readdir __P((struct vop_readdir_args *));
164 int procfs_readlink __P((struct vop_readlink_args *));
165 int procfs_abortop __P((struct vop_abortop_args *));
166 int procfs_inactive __P((struct vop_inactive_args *));
167 int procfs_reclaim __P((struct vop_reclaim_args *));
168 #define procfs_lock ((int (*) __P((struct vop_lock_args *))) nullop)
169 #define procfs_unlock ((int (*) __P((struct vop_unlock_args *))) nullop)
170 int procfs_bmap __P((struct vop_bmap_args *));
171 #define procfs_strategy ((int (*) __P((struct vop_strategy_args *))) procfs_badop)
172 int procfs_print __P((struct vop_print_args *));
173 #define procfs_islocked ((int (*) __P((struct vop_islocked_args *))) nullop)
174 #define procfs_advlock ((int (*) __P((struct vop_advlock_args *))) procfs_badop)
175 #define procfs_blkatoff ((int (*) __P((struct vop_blkatoff_args *))) procfs_badop)
176 #define procfs_valloc ((int (*) __P((struct vop_valloc_args *))) procfs_badop)
177 #define procfs_vfree ((int (*) __P((struct vop_vfree_args *))) nullop)
178 #define procfs_truncate ((int (*) __P((struct vop_truncate_args *))) procfs_badop)
179 #define procfs_update ((int (*) __P((struct vop_update_args *))) nullop)
180 #endif /* KERNEL */
181