]> git.saurik.com Git - apple/xnu.git/blob - bsd/miscfs/procfs/procfs.h
xnu-201.42.3.tar.gz
[apple/xnu.git] / bsd / miscfs / procfs / procfs.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /* $NetBSD: procfs.h,v 1.13 1995/03/29 22:08:30 briggs Exp $ */
23
24 /*
25 * Copyright (c) 1993 Jan-Simon Pendry
26 * Copyright (c) 1993
27 * The Regents of the University of California. All rights reserved.
28 *
29 * This code is derived from software contributed to Berkeley by
30 * Jan-Simon Pendry.
31 *
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
34 * are met:
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
47 *
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * SUCH DAMAGE.
59 *
60 * @(#)procfs.h 8.7 (Berkeley) 6/15/94
61 */
62
63 /*
64 * The different types of node in a procfs filesystem
65 */
66 typedef enum {
67 Proot, /* the filesystem root */
68 Pcurproc, /* symbolic link for curproc */
69 Pproc, /* a process-specific sub-directory */
70 Pfile, /* the executable file */
71 Pmem, /* the process's memory image */
72 Pregs, /* the process's register set */
73 Pfpregs, /* the process's FP register set */
74 Pctl, /* process control */
75 Pstatus, /* process status */
76 Pnote, /* process notifier */
77 Pnotepg /* process group notifier */
78 } pfstype;
79
80 /*
81 * control data for the proc file system.
82 */
83 struct pfsnode {
84 struct pfsnode *pfs_next; /* next on list */
85 struct vnode *pfs_vnode; /* vnode associated with this pfsnode */
86 pfstype pfs_type; /* type of procfs node */
87 pid_t pfs_pid; /* associated process */
88 u_short pfs_mode; /* mode bits for stat() */
89 u_long pfs_flags; /* open flags */
90 u_long pfs_fileno; /* unique file id */
91 };
92
93 #define PROCFS_NOTELEN 64 /* max length of a note (/proc/$pid/note) */
94 #define PROCFS_CTLLEN 8 /* max length of a ctl msg (/proc/$pid/ctl */
95
96 /*
97 * Kernel stuff follows
98 */
99 #ifdef KERNEL
100 #define CNEQ(cnp, s, len) \
101 ((cnp)->cn_namelen == (len) && \
102 (bcmp((s), (cnp)->cn_nameptr, (len)) == 0))
103
104 /*
105 * Format of a directory entry in /proc, ...
106 * This must map onto struct dirent (see <dirent.h>)
107 */
108 #define PROCFS_NAMELEN 8
109 struct pfsdent {
110 u_int32_t d_fileno;
111 u_int16_t d_reclen;
112 u_int8_t d_type;
113 u_int8_t d_namlen;
114 char d_name[PROCFS_NAMELEN];
115 };
116 #define UIO_MX sizeof(struct pfsdent)
117 #define PROCFS_FILENO(pid, type) \
118 (((type) < Pproc) ? \
119 ((type) + 2) : \
120 ((((pid)+1) << 4) + ((int) (type))))
121
122 /*
123 * Convert between pfsnode vnode
124 */
125 #define VTOPFS(vp) ((struct pfsnode *)(vp)->v_data)
126 #define PFSTOV(pfs) ((pfs)->pfs_vnode)
127
128 typedef struct vfs_namemap vfs_namemap_t;
129 struct vfs_namemap {
130 const char *nm_name;
131 int nm_val;
132 };
133
134 int vfs_getuserstr __P((struct uio *, char *, int *));
135 vfs_namemap_t *vfs_findname __P((vfs_namemap_t *, char *, int));
136
137 #define PFIND(pid) ((pid) ? pfind(pid) : &kernel_proc)
138 int procfs_freevp __P((struct vnode *));
139 int procfs_allocvp __P((struct mount *, struct vnode **, long, pfstype));
140 struct vnode *procfs_findtextvp __P((struct proc *));
141 int procfs_donote __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
142 int procfs_doregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
143 int procfs_dofpregs __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
144 int procfs_domem __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
145 int procfs_doctl __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
146 int procfs_dostatus __P((struct proc *, struct proc *, struct pfsnode *pfsp, struct uio *uio));
147
148 /* functions to check whether or not files should be displayed */
149 int procfs_validfile __P((struct proc *));
150 int procfs_validfpregs __P((struct proc *));
151 int procfs_validregs __P((struct proc *));
152
153 #define PROCFS_LOCKED 0x01
154 #define PROCFS_WANT 0x02
155
156 extern int (**procfs_vnodeop_p)(void *);
157 extern struct vfsops procfs_vfsops;
158
159 /*
160 * Prototypes for procfs vnode ops
161 */
162 int procfs_badop(); /* varargs */
163 int procfs_rw __P((struct vop_read_args *));
164 int procfs_lookup __P((struct vop_lookup_args *));
165 #define procfs_create ((int (*) __P((struct vop_create_args *))) procfs_badop)
166 #define procfs_mknod ((int (*) __P((struct vop_mknod_args *))) procfs_badop)
167 int procfs_open __P((struct vop_open_args *));
168 int procfs_close __P((struct vop_close_args *));
169 int procfs_access __P((struct vop_access_args *));
170 int procfs_getattr __P((struct vop_getattr_args *));
171 int procfs_setattr __P((struct vop_setattr_args *));
172 #define procfs_read procfs_rw
173 #define procfs_write procfs_rw
174 int procfs_ioctl __P((struct vop_ioctl_args *));
175 #define procfs_select ((int (*) __P((struct vop_select_args *))) procfs_badop)
176 #define procfs_mmap ((int (*) __P((struct vop_mmap_args *))) procfs_badop)
177 #define procfs_fsync ((int (*) __P((struct vop_fsync_args *))) procfs_badop)
178 #define procfs_seek ((int (*) __P((struct vop_seek_args *))) procfs_badop)
179 #define procfs_remove ((int (*) __P((struct vop_remove_args *))) procfs_badop)
180 #define procfs_link ((int (*) __P((struct vop_link_args *))) procfs_badop)
181 #define procfs_rename ((int (*) __P((struct vop_rename_args *))) procfs_badop)
182 #define procfs_mkdir ((int (*) __P((struct vop_mkdir_args *))) procfs_badop)
183 #define procfs_rmdir ((int (*) __P((struct vop_rmdir_args *))) procfs_badop)
184 #define procfs_symlink ((int (*) __P((struct vop_symlink_args *))) procfs_badop)
185 int procfs_readdir __P((struct vop_readdir_args *));
186 int procfs_readlink __P((struct vop_readlink_args *));
187 int procfs_abortop __P((struct vop_abortop_args *));
188 int procfs_inactive __P((struct vop_inactive_args *));
189 int procfs_reclaim __P((struct vop_reclaim_args *));
190 #define procfs_lock ((int (*) __P((struct vop_lock_args *))) nullop)
191 #define procfs_unlock ((int (*) __P((struct vop_unlock_args *))) nullop)
192 int procfs_bmap __P((struct vop_bmap_args *));
193 #define procfs_strategy ((int (*) __P((struct vop_strategy_args *))) procfs_badop)
194 int procfs_print __P((struct vop_print_args *));
195 #define procfs_islocked ((int (*) __P((struct vop_islocked_args *))) nullop)
196 #define procfs_advlock ((int (*) __P((struct vop_advlock_args *))) procfs_badop)
197 #define procfs_blkatoff ((int (*) __P((struct vop_blkatoff_args *))) procfs_badop)
198 #define procfs_valloc ((int (*) __P((struct vop_valloc_args *))) procfs_badop)
199 #define procfs_vfree ((int (*) __P((struct vop_vfree_args *))) nullop)
200 #define procfs_truncate ((int (*) __P((struct vop_truncate_args *))) procfs_badop)
201 #define procfs_update ((int (*) __P((struct vop_update_args *))) nullop)
202 #endif /* KERNEL */