xref: /freebsd/sys/kern/kern_sysctl.c (revision 3c8e79dd2b99547582a695f32df782e1259eddc7)
1df8bae1dSRodney W. Grimes /*-
2df8bae1dSRodney W. Grimes  * Copyright (c) 1982, 1986, 1989, 1993
3df8bae1dSRodney W. Grimes  *	The Regents of the University of California.  All rights reserved.
4df8bae1dSRodney W. Grimes  *
5df8bae1dSRodney W. Grimes  * This code is derived from software contributed to Berkeley by
6df8bae1dSRodney W. Grimes  * Mike Karels at Berkeley Software Design, Inc.
7df8bae1dSRodney W. Grimes  *
8df8bae1dSRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
9df8bae1dSRodney W. Grimes  * modification, are permitted provided that the following conditions
10df8bae1dSRodney W. Grimes  * are met:
11df8bae1dSRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
12df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
13df8bae1dSRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
14df8bae1dSRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
15df8bae1dSRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
16df8bae1dSRodney W. Grimes  * 3. All advertising materials mentioning features or use of this software
17df8bae1dSRodney W. Grimes  *    must display the following acknowledgement:
18df8bae1dSRodney W. Grimes  *	This product includes software developed by the University of
19df8bae1dSRodney W. Grimes  *	California, Berkeley and its contributors.
20df8bae1dSRodney W. Grimes  * 4. Neither the name of the University nor the names of its contributors
21df8bae1dSRodney W. Grimes  *    may be used to endorse or promote products derived from this software
22df8bae1dSRodney W. Grimes  *    without specific prior written permission.
23df8bae1dSRodney W. Grimes  *
24df8bae1dSRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25df8bae1dSRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26df8bae1dSRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27df8bae1dSRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28df8bae1dSRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29df8bae1dSRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30df8bae1dSRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31df8bae1dSRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32df8bae1dSRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33df8bae1dSRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34df8bae1dSRodney W. Grimes  * SUCH DAMAGE.
35df8bae1dSRodney W. Grimes  *
36df8bae1dSRodney W. Grimes  *	@(#)kern_sysctl.c	8.4 (Berkeley) 4/14/94
373c8e79ddSBruce Evans  * $Id: kern_sysctl.c,v 1.35 1995/11/10 16:22:41 phk Exp $
38df8bae1dSRodney W. Grimes  */
39df8bae1dSRodney W. Grimes 
40df8bae1dSRodney W. Grimes /*
41df8bae1dSRodney W. Grimes  * sysctl system call.
42df8bae1dSRodney W. Grimes  */
43df8bae1dSRodney W. Grimes 
44df8bae1dSRodney W. Grimes #include <sys/param.h>
45df8bae1dSRodney W. Grimes #include <sys/systm.h>
46df8bae1dSRodney W. Grimes #include <sys/kernel.h>
47df8bae1dSRodney W. Grimes #include <sys/malloc.h>
48df8bae1dSRodney W. Grimes #include <sys/proc.h>
49df8bae1dSRodney W. Grimes #include <sys/file.h>
50df8bae1dSRodney W. Grimes #include <sys/vnode.h>
51df8bae1dSRodney W. Grimes #include <sys/unistd.h>
52df8bae1dSRodney W. Grimes #include <sys/buf.h>
53df8bae1dSRodney W. Grimes #include <sys/ioctl.h>
54df8bae1dSRodney W. Grimes #include <sys/tty.h>
555bb4f738SGarrett Wollman #include <sys/conf.h>
56df8bae1dSRodney W. Grimes #include <vm/vm.h>
57df8bae1dSRodney W. Grimes #include <sys/sysctl.h>
583a34a5c3SPoul-Henning Kamp #include <sys/user.h>
59df8bae1dSRodney W. Grimes 
60787d58f2SPoul-Henning Kamp extern struct linker_set sysctl_;
61787d58f2SPoul-Henning Kamp 
62b396cd83SPoul-Henning Kamp /* BEGIN_MIB */
63787d58f2SPoul-Henning Kamp SYSCTL_NODE(, 0,	  sysctl, CTLFLAG_RW, 0,
64787d58f2SPoul-Henning Kamp 	"Sysctl internal magic");
652e210993SPoul-Henning Kamp SYSCTL_NODE(, CTL_KERN,	  kern,   CTLFLAG_RW, 0,
662e210993SPoul-Henning Kamp 	"High kernel, proc, limits &c");
672e210993SPoul-Henning Kamp SYSCTL_NODE(, CTL_VM,	  vm,     CTLFLAG_RW, 0,
682e210993SPoul-Henning Kamp 	"Virtual memory");
692e210993SPoul-Henning Kamp SYSCTL_NODE(, CTL_FS,	  fs,     CTLFLAG_RW, 0,
702e210993SPoul-Henning Kamp 	"File system");
712e210993SPoul-Henning Kamp SYSCTL_NODE(, CTL_NET,	  net,    CTLFLAG_RW, 0,
722e210993SPoul-Henning Kamp 	"Network, (see socket.h)");
732e210993SPoul-Henning Kamp SYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
742e210993SPoul-Henning Kamp 	"Debugging");
752e210993SPoul-Henning Kamp SYSCTL_NODE(, CTL_HW,	  hw,     CTLFLAG_RW, 0,
762e210993SPoul-Henning Kamp 	"hardware");
772e210993SPoul-Henning Kamp SYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
782e210993SPoul-Henning Kamp 	"machine dependent");
792e210993SPoul-Henning Kamp SYSCTL_NODE(, CTL_USER,	  user,   CTLFLAG_RW, 0,
802e210993SPoul-Henning Kamp 	"user-level");
81b396cd83SPoul-Henning Kamp 
822e210993SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD, osrelease, 0, "");
83b396cd83SPoul-Henning Kamp 
842e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD, 0, BSD, "");
85b396cd83SPoul-Henning Kamp 
862e210993SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD, version, 0, "");
87b396cd83SPoul-Henning Kamp 
882e210993SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD, ostype, 0, "");
89b396cd83SPoul-Henning Kamp 
90b396cd83SPoul-Henning Kamp extern int osreldate;
912e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD, &osreldate, 0, "");
92b396cd83SPoul-Henning Kamp 
932e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_MAXVNODES, maxvnodes, CTLFLAG_RD, &desiredvnodes, 0, "");
94b396cd83SPoul-Henning Kamp 
952e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD, &maxproc, 0, "");
96b396cd83SPoul-Henning Kamp 
97b396cd83SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid,
983a34a5c3SPoul-Henning Kamp 	CTLFLAG_RD, &maxprocperuid, 0, "");
99b396cd83SPoul-Henning Kamp 
100b396cd83SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_MAXFILESPERPROC, maxfilesperproc,
1013a34a5c3SPoul-Henning Kamp 	CTLFLAG_RD, &maxfilesperproc, 0, "");
102b396cd83SPoul-Henning Kamp 
1032e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD, 0, ARG_MAX, "");
104b396cd83SPoul-Henning Kamp 
1052e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD, 0, _POSIX_VERSION, "");
106b396cd83SPoul-Henning Kamp 
1072e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD, 0, NGROUPS_MAX, "");
108b396cd83SPoul-Henning Kamp 
1092e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD, 0, 1, "");
110b396cd83SPoul-Henning Kamp 
1112e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_MAXFILES, maxfiles, CTLFLAG_RW, &maxfiles, 0, "");
112b396cd83SPoul-Henning Kamp 
113b396cd83SPoul-Henning Kamp #ifdef _POSIX_SAVED_IDS
1142e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 1, "");
115b396cd83SPoul-Henning Kamp #else
1162e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 0, "");
117b396cd83SPoul-Henning Kamp #endif
118b396cd83SPoul-Henning Kamp 
119b396cd83SPoul-Henning Kamp char kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
120b396cd83SPoul-Henning Kamp 
121b396cd83SPoul-Henning Kamp SYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile,
1223a34a5c3SPoul-Henning Kamp 	CTLFLAG_RW, kernelname, sizeof kernelname, "");
123b396cd83SPoul-Henning Kamp 
124b396cd83SPoul-Henning Kamp SYSCTL_STRUCT(_kern, KERN_BOOTTIME, boottime,
1253a34a5c3SPoul-Henning Kamp 	CTLFLAG_RW, &boottime, timeval, "");
126b396cd83SPoul-Henning Kamp 
1272e210993SPoul-Henning Kamp SYSCTL_STRING(_hw, HW_MACHINE, machine, CTLFLAG_RD, machine, 0, "");
128b396cd83SPoul-Henning Kamp 
129787d58f2SPoul-Henning Kamp SYSCTL_STRING(_hw, HW_MODEL, model, CTLFLAG_RD, cpu_model, 0, "");
130b396cd83SPoul-Henning Kamp 
1312e210993SPoul-Henning Kamp SYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, 0, 1, "");
132b396cd83SPoul-Henning Kamp 
1332e210993SPoul-Henning Kamp SYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD, 0, BYTE_ORDER, "");
134b396cd83SPoul-Henning Kamp 
1352e210993SPoul-Henning Kamp SYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD, 0, PAGE_SIZE, "");
136b396cd83SPoul-Henning Kamp 
137b396cd83SPoul-Henning Kamp /* END_MIB */
138b396cd83SPoul-Henning Kamp 
139b396cd83SPoul-Henning Kamp extern int vfs_update_wakeup;
140b396cd83SPoul-Henning Kamp extern int vfs_update_interval;
141b396cd83SPoul-Henning Kamp static int
1423a34a5c3SPoul-Henning Kamp sysctl_kern_updateinterval SYSCTL_HANDLER_ARGS
143b396cd83SPoul-Henning Kamp {
1443a34a5c3SPoul-Henning Kamp 	int error = sysctl_handle_int(oidp,
1453a34a5c3SPoul-Henning Kamp 		oidp->oid_arg1, oidp->oid_arg2,
1463a34a5c3SPoul-Henning Kamp 		oldp, oldlenp, newp, newlen);
1473a34a5c3SPoul-Henning Kamp 	if (!error)
148b396cd83SPoul-Henning Kamp 		wakeup(&vfs_update_wakeup);
1493a34a5c3SPoul-Henning Kamp 	return error;
150b396cd83SPoul-Henning Kamp }
151b396cd83SPoul-Henning Kamp 
1522e210993SPoul-Henning Kamp SYSCTL_PROC(_kern, KERN_UPDATEINTERVAL, update, CTLTYPE_INT|CTLFLAG_RW,
1533a34a5c3SPoul-Henning Kamp 	&vfs_update_interval, 0, sysctl_kern_updateinterval, "");
154b396cd83SPoul-Henning Kamp 
1552e210993SPoul-Henning Kamp 
1562e210993SPoul-Henning Kamp char hostname[MAXHOSTNAMELEN];
1572e210993SPoul-Henning Kamp int hostnamelen;
1582e210993SPoul-Henning Kamp static int
1592e210993SPoul-Henning Kamp sysctl_kern_hostname SYSCTL_HANDLER_ARGS
1602e210993SPoul-Henning Kamp {
1612e210993SPoul-Henning Kamp 	int error = sysctl_handle_string(oidp,
1622e210993SPoul-Henning Kamp 		oidp->oid_arg1, oidp->oid_arg2,
1632e210993SPoul-Henning Kamp 		oldp, oldlenp, newp, newlen);
1642e210993SPoul-Henning Kamp 	if (newp && (error == 0 || error == ENOMEM))
1652e210993SPoul-Henning Kamp 		hostnamelen = newlen;
1662e210993SPoul-Henning Kamp 	return error;
1672e210993SPoul-Henning Kamp }
1682e210993SPoul-Henning Kamp 
1692e210993SPoul-Henning Kamp SYSCTL_PROC(_kern, KERN_HOSTNAME, hostname, CTLTYPE_STRING|CTLFLAG_RW,
1702e210993SPoul-Henning Kamp 	&hostname, sizeof(hostname), sysctl_kern_hostname, "");
1712e210993SPoul-Henning Kamp 
172787d58f2SPoul-Henning Kamp static int
1733c8e79ddSBruce Evans sysctl_order_cmp(const void *a, const void *b)
174787d58f2SPoul-Henning Kamp {
1753c8e79ddSBruce Evans 	const struct sysctl_oid **pa, **pb;
1763c8e79ddSBruce Evans 
1773c8e79ddSBruce Evans 	pa = (const struct sysctl_oid **)a;
1783c8e79ddSBruce Evans 	pb = (const struct sysctl_oid **)b;
1793c8e79ddSBruce Evans 	if (*pa == NULL)
1803c8e79ddSBruce Evans 		return (1);
1813c8e79ddSBruce Evans 	if (*pb == NULL)
1823c8e79ddSBruce Evans 		return (-1);
183787d58f2SPoul-Henning Kamp 	return ((*pa)->oid_number - (*pb)->oid_number);
184787d58f2SPoul-Henning Kamp }
185787d58f2SPoul-Henning Kamp 
186787d58f2SPoul-Henning Kamp static void
187787d58f2SPoul-Henning Kamp sysctl_order(void *arg)
188787d58f2SPoul-Henning Kamp {
189b8da2396SPoul-Henning Kamp 	int j;
190787d58f2SPoul-Henning Kamp 	struct linker_set *l = (struct linker_set *) arg;
191787d58f2SPoul-Henning Kamp 	struct sysctl_oid **oidpp;
192787d58f2SPoul-Henning Kamp 
193787d58f2SPoul-Henning Kamp 	j = l->ls_length;
194787d58f2SPoul-Henning Kamp 	oidpp = (struct sysctl_oid **) l->ls_items;
195787d58f2SPoul-Henning Kamp 	for (; j--; oidpp++) {
196787d58f2SPoul-Henning Kamp 		if (!*oidpp)
197787d58f2SPoul-Henning Kamp 			continue;
198787d58f2SPoul-Henning Kamp 		if ((*oidpp)->oid_arg1 == arg) {
199787d58f2SPoul-Henning Kamp 			*oidpp = 0;
200787d58f2SPoul-Henning Kamp 			continue;
201787d58f2SPoul-Henning Kamp 		}
202787d58f2SPoul-Henning Kamp 		if (((*oidpp)->oid_kind & CTLTYPE) == CTLTYPE_NODE)
203787d58f2SPoul-Henning Kamp 			if (!(*oidpp)->oid_handler)
204787d58f2SPoul-Henning Kamp 				sysctl_order((*oidpp)->oid_arg1);
205787d58f2SPoul-Henning Kamp 	}
206787d58f2SPoul-Henning Kamp 	qsort(l->ls_items, l->ls_length, sizeof l->ls_items[0],
207787d58f2SPoul-Henning Kamp 		sysctl_order_cmp);
208787d58f2SPoul-Henning Kamp }
209787d58f2SPoul-Henning Kamp 
210787d58f2SPoul-Henning Kamp SYSINIT(sysctl,SI_SUB_KMEM,SI_ORDER_ANY,sysctl_order,&sysctl_);
211787d58f2SPoul-Henning Kamp 
212787d58f2SPoul-Henning Kamp static void
213787d58f2SPoul-Henning Kamp sysctl_sysctl_debug_dump_node(struct linker_set *l,int i)
214787d58f2SPoul-Henning Kamp {
215787d58f2SPoul-Henning Kamp 	int j,k;
216787d58f2SPoul-Henning Kamp 	struct sysctl_oid **oidpp;
217787d58f2SPoul-Henning Kamp 
218787d58f2SPoul-Henning Kamp 	j = l->ls_length;
219787d58f2SPoul-Henning Kamp 	oidpp = (struct sysctl_oid **) l->ls_items;
220787d58f2SPoul-Henning Kamp 	for (; j--; oidpp++) {
221787d58f2SPoul-Henning Kamp 
222787d58f2SPoul-Henning Kamp 		if (!*oidpp)
223787d58f2SPoul-Henning Kamp 			continue;
224787d58f2SPoul-Henning Kamp 
225787d58f2SPoul-Henning Kamp 		for (k=0; k<i; k++)
226787d58f2SPoul-Henning Kamp 			printf(" ");
227787d58f2SPoul-Henning Kamp 
228787d58f2SPoul-Henning Kamp 		if ((*oidpp)->oid_number > 100) {
229b8da2396SPoul-Henning Kamp 			printf("Junk! %p  # %d  %s  k %x  a1 %p  a2 %x  h %p\n",
230787d58f2SPoul-Henning Kamp 				*oidpp,
231787d58f2SPoul-Henning Kamp 		 		(*oidpp)->oid_number, (*oidpp)->oid_name,
232787d58f2SPoul-Henning Kamp 		 		(*oidpp)->oid_kind, (*oidpp)->oid_arg1,
233787d58f2SPoul-Henning Kamp 		 		(*oidpp)->oid_arg2, (*oidpp)->oid_handler);
234787d58f2SPoul-Henning Kamp 			continue;
235787d58f2SPoul-Henning Kamp 		}
236787d58f2SPoul-Henning Kamp 		printf("%d %s ", (*oidpp)->oid_number, (*oidpp)->oid_name);
237787d58f2SPoul-Henning Kamp 
238787d58f2SPoul-Henning Kamp 		printf("%c%c",
239787d58f2SPoul-Henning Kamp 			(*oidpp)->oid_kind & CTLFLAG_RD ? 'R':' ',
240787d58f2SPoul-Henning Kamp 			(*oidpp)->oid_kind & CTLFLAG_WR ? 'W':' ');
241787d58f2SPoul-Henning Kamp 
242787d58f2SPoul-Henning Kamp 		switch ((*oidpp)->oid_kind & CTLTYPE) {
243787d58f2SPoul-Henning Kamp 			case CTLTYPE_NODE:
244787d58f2SPoul-Henning Kamp 				if ((*oidpp)->oid_handler) {
245787d58f2SPoul-Henning Kamp 					printf(" Node(proc)\n");
246787d58f2SPoul-Henning Kamp 				} else {
247787d58f2SPoul-Henning Kamp 					printf(" Node\n");
248787d58f2SPoul-Henning Kamp 					sysctl_sysctl_debug_dump_node(
249787d58f2SPoul-Henning Kamp 						(*oidpp)->oid_arg1,i+2);
250787d58f2SPoul-Henning Kamp 				}
251787d58f2SPoul-Henning Kamp 				break;
252787d58f2SPoul-Henning Kamp 			case CTLTYPE_INT:    printf(" Int\n"); break;
253787d58f2SPoul-Henning Kamp 			case CTLTYPE_STRING: printf(" String\n"); break;
254787d58f2SPoul-Henning Kamp 			case CTLTYPE_QUAD:   printf(" Quad\n"); break;
255787d58f2SPoul-Henning Kamp 			case CTLTYPE_OPAQUE: printf(" Opaque/struct\n"); break;
256787d58f2SPoul-Henning Kamp 			default:	     printf("\n");
257787d58f2SPoul-Henning Kamp 		}
258787d58f2SPoul-Henning Kamp 
259787d58f2SPoul-Henning Kamp 	}
260787d58f2SPoul-Henning Kamp }
261787d58f2SPoul-Henning Kamp 
262787d58f2SPoul-Henning Kamp 
263787d58f2SPoul-Henning Kamp static int
264787d58f2SPoul-Henning Kamp sysctl_sysctl_debug SYSCTL_HANDLER_ARGS
265787d58f2SPoul-Henning Kamp {
266787d58f2SPoul-Henning Kamp 	sysctl_sysctl_debug_dump_node(&sysctl_,0);
267787d58f2SPoul-Henning Kamp 	return ENOENT;
268787d58f2SPoul-Henning Kamp }
269787d58f2SPoul-Henning Kamp 
270787d58f2SPoul-Henning Kamp SYSCTL_PROC(_sysctl, 0, debug, CTLTYPE_STRING|CTLFLAG_RD,
271787d58f2SPoul-Henning Kamp 	0, 0, sysctl_sysctl_debug, "");
2722e210993SPoul-Henning Kamp 
2732e210993SPoul-Henning Kamp char domainname[MAXHOSTNAMELEN];
2742e210993SPoul-Henning Kamp int domainnamelen;
2752e210993SPoul-Henning Kamp static int
2762e210993SPoul-Henning Kamp sysctl_kern_domainname SYSCTL_HANDLER_ARGS
2772e210993SPoul-Henning Kamp {
2782e210993SPoul-Henning Kamp 	int error = sysctl_handle_string(oidp,
2792e210993SPoul-Henning Kamp 		oidp->oid_arg1, oidp->oid_arg2,
2802e210993SPoul-Henning Kamp 		oldp, oldlenp, newp, newlen);
2812e210993SPoul-Henning Kamp 	if (newp && (error == 0 || error == ENOMEM))
2822e210993SPoul-Henning Kamp 		domainnamelen = newlen;
2832e210993SPoul-Henning Kamp 	return error;
2842e210993SPoul-Henning Kamp }
2852e210993SPoul-Henning Kamp 
2862e210993SPoul-Henning Kamp SYSCTL_PROC(_kern, KERN_DOMAINNAME, domainname, CTLTYPE_STRING|CTLFLAG_RW,
2872e210993SPoul-Henning Kamp 	&domainname, sizeof(domainname), sysctl_kern_domainname, "");
2882e210993SPoul-Henning Kamp 
2892e210993SPoul-Henning Kamp long hostid;
2902e210993SPoul-Henning Kamp /* Some trouble here, if sizeof (int) != sizeof (long) */
2912e210993SPoul-Henning Kamp SYSCTL_INT(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "");
2922e210993SPoul-Henning Kamp 
2933a34a5c3SPoul-Henning Kamp int
2943a34a5c3SPoul-Henning Kamp sysctl_handle_int SYSCTL_HANDLER_ARGS
295b396cd83SPoul-Henning Kamp {
296b396cd83SPoul-Henning Kamp 	/* If there isn't sufficient space to return */
297b396cd83SPoul-Henning Kamp 	if (oldp && *oldlenp < sizeof(int))
298b396cd83SPoul-Henning Kamp 		return (ENOMEM);
299b396cd83SPoul-Henning Kamp 
300b396cd83SPoul-Henning Kamp 	/* If it is a constant, don't write */
3013a34a5c3SPoul-Henning Kamp 	if (newp && !arg1)
302b396cd83SPoul-Henning Kamp 		return (EPERM);
303b396cd83SPoul-Henning Kamp 
304b396cd83SPoul-Henning Kamp 	/* If we get more than an int */
305b396cd83SPoul-Henning Kamp 	if (newp && newlen != sizeof(int))
306b396cd83SPoul-Henning Kamp 		return (EINVAL);
307b396cd83SPoul-Henning Kamp 
308b396cd83SPoul-Henning Kamp 	*oldlenp = sizeof(int);
3093a34a5c3SPoul-Henning Kamp 	if (oldp && arg1 )
3102e210993SPoul-Henning Kamp 		bcopy(arg1, oldp, sizeof(int));
311b396cd83SPoul-Henning Kamp 	else if (oldp)
3122e210993SPoul-Henning Kamp 		bcopy(&arg2, oldp, sizeof(int));
3132e210993SPoul-Henning Kamp 	if (newp)
3142e210993SPoul-Henning Kamp 		bcopy(newp, arg1, sizeof(int));
3152e210993SPoul-Henning Kamp 	return (0);
316b396cd83SPoul-Henning Kamp }
317b396cd83SPoul-Henning Kamp 
3183a34a5c3SPoul-Henning Kamp int
3193a34a5c3SPoul-Henning Kamp sysctl_handle_string SYSCTL_HANDLER_ARGS
320b396cd83SPoul-Henning Kamp {
3212e210993SPoul-Henning Kamp 	int len, error=0;
3223a34a5c3SPoul-Henning Kamp 	char *str = (char *)arg1;
323b396cd83SPoul-Henning Kamp 
324b396cd83SPoul-Henning Kamp 	len = strlen(str) + 1;
325b396cd83SPoul-Henning Kamp 
326b396cd83SPoul-Henning Kamp 	if (oldp && *oldlenp < len) {
327b396cd83SPoul-Henning Kamp 		len = *oldlenp;
3282e210993SPoul-Henning Kamp 		error=ENOMEM;
329b396cd83SPoul-Henning Kamp 	}
330b396cd83SPoul-Henning Kamp 
3313a34a5c3SPoul-Henning Kamp 	if (newp && newlen >= arg2)
332b396cd83SPoul-Henning Kamp 		return (EINVAL);
333b396cd83SPoul-Henning Kamp 
334b396cd83SPoul-Henning Kamp 	if (oldp) {
335b396cd83SPoul-Henning Kamp 		*oldlenp = len;
3362e210993SPoul-Henning Kamp 		bcopy(str, oldp, len);
337b396cd83SPoul-Henning Kamp 	}
3382e210993SPoul-Henning Kamp 
3392e210993SPoul-Henning Kamp 	if (newp) {
3402e210993SPoul-Henning Kamp 		bcopy(newp, str, newlen);
341b396cd83SPoul-Henning Kamp 		str[newlen] = 0;
342b396cd83SPoul-Henning Kamp 	}
3432e210993SPoul-Henning Kamp 	return (error);
344b396cd83SPoul-Henning Kamp }
345b396cd83SPoul-Henning Kamp 
3463a34a5c3SPoul-Henning Kamp int
3473a34a5c3SPoul-Henning Kamp sysctl_handle_opaque SYSCTL_HANDLER_ARGS
348b396cd83SPoul-Henning Kamp {
3492e210993SPoul-Henning Kamp 	if (oldp && *oldlenp < arg2)
350b396cd83SPoul-Henning Kamp 		return (ENOMEM);
351b396cd83SPoul-Henning Kamp 
3523a34a5c3SPoul-Henning Kamp 	if (newp && newlen != arg2)
353b396cd83SPoul-Henning Kamp 		return (EINVAL);
354b396cd83SPoul-Henning Kamp 
355b396cd83SPoul-Henning Kamp 	if (oldp) {
3563a34a5c3SPoul-Henning Kamp 		*oldlenp = arg2;
3572e210993SPoul-Henning Kamp 		bcopy(arg1, oldp, arg2);
358b396cd83SPoul-Henning Kamp 	}
3592e210993SPoul-Henning Kamp 	if (newp)
3602e210993SPoul-Henning Kamp 		bcopy(newp, arg1, arg2);
3612e210993SPoul-Henning Kamp 	return (0);
362b396cd83SPoul-Henning Kamp }
363b396cd83SPoul-Henning Kamp 
3643a34a5c3SPoul-Henning Kamp #ifdef DEBUG
3653a34a5c3SPoul-Henning Kamp static sysctlfn debug_sysctl;
3663a34a5c3SPoul-Henning Kamp #endif
367b396cd83SPoul-Henning Kamp 
368df8bae1dSRodney W. Grimes /*
369df8bae1dSRodney W. Grimes  * Locking and stats
370df8bae1dSRodney W. Grimes  */
371df8bae1dSRodney W. Grimes static struct sysctl_lock {
372df8bae1dSRodney W. Grimes 	int	sl_lock;
373df8bae1dSRodney W. Grimes 	int	sl_want;
374df8bae1dSRodney W. Grimes 	int	sl_locked;
375df8bae1dSRodney W. Grimes } memlock;
376df8bae1dSRodney W. Grimes 
3772e210993SPoul-Henning Kamp 
3782e210993SPoul-Henning Kamp 
3792e210993SPoul-Henning Kamp /*
3802e210993SPoul-Henning Kamp  * Traverse our tree, and find the right node, execute whatever it points
3812e210993SPoul-Henning Kamp  * at, and return the resulting error code.
3822e210993SPoul-Henning Kamp  * We work entirely in kernel-space at this time.
3832e210993SPoul-Henning Kamp  */
3842e210993SPoul-Henning Kamp 
3852e210993SPoul-Henning Kamp 
3862e210993SPoul-Henning Kamp int
3872e210993SPoul-Henning Kamp sysctl_root SYSCTL_HANDLER_ARGS
3882e210993SPoul-Henning Kamp {
3892e210993SPoul-Henning Kamp 	int *name = (int *) arg1;
3902e210993SPoul-Henning Kamp 	int namelen = arg2;
3912e210993SPoul-Henning Kamp 	int indx, i, j;
3922e210993SPoul-Henning Kamp 	struct sysctl_oid **oidpp;
3932e210993SPoul-Henning Kamp 	struct linker_set *lsp = &sysctl_;
3942e210993SPoul-Henning Kamp 
3952e210993SPoul-Henning Kamp 	j = lsp->ls_length;
3962e210993SPoul-Henning Kamp 	oidpp = (struct sysctl_oid **) lsp->ls_items;
3972e210993SPoul-Henning Kamp 
3982e210993SPoul-Henning Kamp 	indx = 0;
3992e210993SPoul-Henning Kamp 	while (j-- && indx < CTL_MAXNAME) {
400787d58f2SPoul-Henning Kamp 		if (*oidpp && ((*oidpp)->oid_number == name[indx])) {
4012e210993SPoul-Henning Kamp 			indx++;
4022e210993SPoul-Henning Kamp 			if (((*oidpp)->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
4032e210993SPoul-Henning Kamp 				if ((*oidpp)->oid_handler)
4042e210993SPoul-Henning Kamp 					goto found;
4052e210993SPoul-Henning Kamp 				if (indx == namelen)
4062e210993SPoul-Henning Kamp 					return ENOENT;
4072e210993SPoul-Henning Kamp 				lsp = (struct linker_set*)(*oidpp)->oid_arg1;
4082e210993SPoul-Henning Kamp 				j = lsp->ls_length;
4092e210993SPoul-Henning Kamp 				oidpp = (struct sysctl_oid **)lsp->ls_items;
4102e210993SPoul-Henning Kamp 			} else {
4112e210993SPoul-Henning Kamp 				if (indx != namelen)
4122e210993SPoul-Henning Kamp 					return EISDIR;
4132e210993SPoul-Henning Kamp 				goto found;
4142e210993SPoul-Henning Kamp 			}
4152e210993SPoul-Henning Kamp 		} else {
4162e210993SPoul-Henning Kamp 			oidpp++;
4172e210993SPoul-Henning Kamp 		}
4182e210993SPoul-Henning Kamp 	}
4192e210993SPoul-Henning Kamp 	return EJUSTRETURN;
4202e210993SPoul-Henning Kamp found:
4212e210993SPoul-Henning Kamp 
4222e210993SPoul-Henning Kamp 	/* If writing isn't allowed */
4232e210993SPoul-Henning Kamp 	if (newp && !((*oidpp)->oid_kind & CTLFLAG_WR))
4242e210993SPoul-Henning Kamp 		return (EPERM);
4252e210993SPoul-Henning Kamp 
4262e210993SPoul-Henning Kamp 	if (!(*oidpp)->oid_handler)
4272e210993SPoul-Henning Kamp 		return EINVAL;
4282e210993SPoul-Henning Kamp 
4292e210993SPoul-Henning Kamp 	if (((*oidpp)->oid_kind & CTLTYPE) == CTLTYPE_NODE) {
4302e210993SPoul-Henning Kamp 		i = ((*oidpp)->oid_handler) (*oidpp,
4312e210993SPoul-Henning Kamp 					name + indx, namelen - indx,
4322e210993SPoul-Henning Kamp 					oldp, oldlenp, newp, newlen);
4332e210993SPoul-Henning Kamp 	} else {
4342e210993SPoul-Henning Kamp 		i = ((*oidpp)->oid_handler) (*oidpp,
4352e210993SPoul-Henning Kamp 					(*oidpp)->oid_arg1, (*oidpp)->oid_arg2,
4362e210993SPoul-Henning Kamp 					oldp, oldlenp, newp, newlen);
4372e210993SPoul-Henning Kamp 	}
4382e210993SPoul-Henning Kamp 	return (i);
4392e210993SPoul-Henning Kamp }
4402e210993SPoul-Henning Kamp 
441b8da2396SPoul-Henning Kamp struct sysctl_args {
442b8da2396SPoul-Henning Kamp 	int	*name;
443b8da2396SPoul-Henning Kamp 	u_int	namelen;
444b8da2396SPoul-Henning Kamp 	void	*old;
445b8da2396SPoul-Henning Kamp 	size_t	*oldlenp;
446b8da2396SPoul-Henning Kamp 	void	*new;
447b8da2396SPoul-Henning Kamp 	size_t	newlen;
448b8da2396SPoul-Henning Kamp };
449b8da2396SPoul-Henning Kamp 
450df8bae1dSRodney W. Grimes int
451df8bae1dSRodney W. Grimes __sysctl(p, uap, retval)
452df8bae1dSRodney W. Grimes 	struct proc *p;
453df8bae1dSRodney W. Grimes 	register struct sysctl_args *uap;
454df8bae1dSRodney W. Grimes 	int *retval;
455df8bae1dSRodney W. Grimes {
456b8da2396SPoul-Henning Kamp 	int error, name[CTL_MAXNAME];
457b396cd83SPoul-Henning Kamp 
458df8bae1dSRodney W. Grimes 	if (uap->namelen > CTL_MAXNAME || uap->namelen < 2)
459df8bae1dSRodney W. Grimes 		return (EINVAL);
460b396cd83SPoul-Henning Kamp 
461797f2d22SPoul-Henning Kamp  	error = copyin(uap->name, &name, uap->namelen * sizeof(int));
462797f2d22SPoul-Henning Kamp  	if (error)
463df8bae1dSRodney W. Grimes 		return (error);
464df8bae1dSRodney W. Grimes 
465b8da2396SPoul-Henning Kamp 	return (userland_sysctl(p, name, uap->namelen,
466b8da2396SPoul-Henning Kamp 		uap->old, uap->oldlenp, 0,
467b8da2396SPoul-Henning Kamp 		uap->new, uap->newlen, retval));
468b8da2396SPoul-Henning Kamp }
469b8da2396SPoul-Henning Kamp 
4706ff1bbebSPoul-Henning Kamp static sysctlfn kern_sysctl;
4716ff1bbebSPoul-Henning Kamp 
472b8da2396SPoul-Henning Kamp /*
473b8da2396SPoul-Henning Kamp  * This is used from various compatibility syscalls too.  That's why name
474b8da2396SPoul-Henning Kamp  * must be in kernel space.
475b8da2396SPoul-Henning Kamp  */
476b8da2396SPoul-Henning Kamp int
477b8da2396SPoul-Henning Kamp userland_sysctl(struct proc *p, int *name, u_int namelen, void *old, size_t *oldlenp, int inkernel, void *new, size_t newlen, int *retval)
478b8da2396SPoul-Henning Kamp {
479b8da2396SPoul-Henning Kamp 	int error = 0, dolock = 1, i;
480b8da2396SPoul-Henning Kamp 	u_int savelen = 0, oldlen = 0;
481b8da2396SPoul-Henning Kamp 	sysctlfn *fn;
482b8da2396SPoul-Henning Kamp 	void *oldp = 0;
483b8da2396SPoul-Henning Kamp 	void *newp = 0;
484b8da2396SPoul-Henning Kamp 
485b8da2396SPoul-Henning Kamp 	if (new != NULL && (error = suser(p->p_ucred, &p->p_acflag)))
486b396cd83SPoul-Henning Kamp 		return (error);
487b396cd83SPoul-Henning Kamp 
488b8da2396SPoul-Henning Kamp 	if (oldlenp) {
489b8da2396SPoul-Henning Kamp 		if (inkernel) {
490b8da2396SPoul-Henning Kamp 			oldlen = *oldlenp;
491b8da2396SPoul-Henning Kamp 		} else {
492b8da2396SPoul-Henning Kamp 			error = copyin(oldlenp, &oldlen, sizeof(oldlen));
493b8da2396SPoul-Henning Kamp 			if (error)
494b8da2396SPoul-Henning Kamp 				return (error);
495b8da2396SPoul-Henning Kamp 		}
496b8da2396SPoul-Henning Kamp 	}
497b8da2396SPoul-Henning Kamp 
498b8da2396SPoul-Henning Kamp 	if (old)
4992e210993SPoul-Henning Kamp 		oldp = malloc(oldlen, M_TEMP, M_WAITOK);
5002e210993SPoul-Henning Kamp 
501b8da2396SPoul-Henning Kamp 	if (newlen) {
502b8da2396SPoul-Henning Kamp 		newp = malloc(newlen, M_TEMP, M_WAITOK);
503b8da2396SPoul-Henning Kamp 		error = copyin(new, newp, newlen);
504b396cd83SPoul-Henning Kamp 	}
5052e210993SPoul-Henning Kamp 	if (error) {
5062e210993SPoul-Henning Kamp 		if (oldp)
5072e210993SPoul-Henning Kamp 			free(oldp, M_TEMP);
5082e210993SPoul-Henning Kamp 		if (newp)
5092e210993SPoul-Henning Kamp 			free(newp, M_TEMP);
5102e210993SPoul-Henning Kamp 		return error;
511b396cd83SPoul-Henning Kamp 	}
512b396cd83SPoul-Henning Kamp 
51369feb388SPoul-Henning Kamp 	error = sysctl_root(0, name, namelen, oldp, &oldlen, newp, newlen);
514b396cd83SPoul-Henning Kamp 
5152e210993SPoul-Henning Kamp         if (!error || error == ENOMEM) {
51669feb388SPoul-Henning Kamp 		if (retval)
51769feb388SPoul-Henning Kamp 			*retval = oldlen;
518b8da2396SPoul-Henning Kamp 		if (oldlenp) {
519b8da2396SPoul-Henning Kamp 			if (inkernel) {
520b8da2396SPoul-Henning Kamp 				*oldlenp = oldlen;
521b8da2396SPoul-Henning Kamp 			} else {
522b8da2396SPoul-Henning Kamp 				i = copyout(&oldlen, oldlenp, sizeof(oldlen));
523b396cd83SPoul-Henning Kamp 				if (i)
524b396cd83SPoul-Henning Kamp 					error = i;
5252e210993SPoul-Henning Kamp 			}
526b8da2396SPoul-Henning Kamp 		}
5272e210993SPoul-Henning Kamp 		if ((error == ENOMEM || !error ) && oldp) {
528b8da2396SPoul-Henning Kamp 			i = copyout(oldp, old, oldlen);
5292e210993SPoul-Henning Kamp 			if (i)
5302e210993SPoul-Henning Kamp 				error = i;
5312e210993SPoul-Henning Kamp 			free(oldp, M_TEMP);
5322e210993SPoul-Henning Kamp 		}
5332e210993SPoul-Henning Kamp 		if (newp)
5342e210993SPoul-Henning Kamp 			free(newp, M_TEMP);
5352e210993SPoul-Henning Kamp 		return (error);
5362e210993SPoul-Henning Kamp 	}
537b396cd83SPoul-Henning Kamp 
5382e210993SPoul-Henning Kamp 	if (oldp)
5392e210993SPoul-Henning Kamp 		free(oldp, M_TEMP);
5402e210993SPoul-Henning Kamp 	if (newp)
5412e210993SPoul-Henning Kamp 		free(newp, M_TEMP);
5422e210993SPoul-Henning Kamp 
543df8bae1dSRodney W. Grimes 	switch (name[0]) {
544df8bae1dSRodney W. Grimes 	case CTL_KERN:
545df8bae1dSRodney W. Grimes 		fn = kern_sysctl;
546e9e2a852SAndrey A. Chernov 		if (name[1] != KERN_VNODE)      /* XXX */
547df8bae1dSRodney W. Grimes 			dolock = 0;
548df8bae1dSRodney W. Grimes 		break;
549df8bae1dSRodney W. Grimes 	case CTL_HW:
550df8bae1dSRodney W. Grimes 		fn = hw_sysctl;
551df8bae1dSRodney W. Grimes 		break;
552df8bae1dSRodney W. Grimes 	case CTL_VM:
553df8bae1dSRodney W. Grimes 		fn = vm_sysctl;
554df8bae1dSRodney W. Grimes 		break;
555df8bae1dSRodney W. Grimes 	case CTL_NET:
556df8bae1dSRodney W. Grimes 		fn = net_sysctl;
557df8bae1dSRodney W. Grimes 		break;
558df8bae1dSRodney W. Grimes 	case CTL_FS:
559df8bae1dSRodney W. Grimes 		fn = fs_sysctl;
560df8bae1dSRodney W. Grimes 		break;
561df8bae1dSRodney W. Grimes #ifdef DEBUG
562df8bae1dSRodney W. Grimes 	case CTL_DEBUG:
563df8bae1dSRodney W. Grimes 		fn = debug_sysctl;
564df8bae1dSRodney W. Grimes 		break;
565df8bae1dSRodney W. Grimes #endif
566df8bae1dSRodney W. Grimes 	default:
567df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
568df8bae1dSRodney W. Grimes 	}
569b8da2396SPoul-Henning Kamp 	if (old != NULL) {
570b8da2396SPoul-Henning Kamp 		if (!useracc(old, oldlen, B_WRITE))
571df8bae1dSRodney W. Grimes 			return (EFAULT);
572df8bae1dSRodney W. Grimes 		while (memlock.sl_lock) {
573df8bae1dSRodney W. Grimes 			memlock.sl_want = 1;
57482478919SDavid Greenman 			(void) tsleep((caddr_t)&memlock, PRIBIO+1, "sysctl", 0);
575df8bae1dSRodney W. Grimes 			memlock.sl_locked++;
576df8bae1dSRodney W. Grimes 		}
577df8bae1dSRodney W. Grimes 		memlock.sl_lock = 1;
578df8bae1dSRodney W. Grimes 		if (dolock)
579b8da2396SPoul-Henning Kamp 			vslock(old, oldlen);
580df8bae1dSRodney W. Grimes 		savelen = oldlen;
581df8bae1dSRodney W. Grimes 	}
582b396cd83SPoul-Henning Kamp 
583b396cd83SPoul-Henning Kamp 
584b8da2396SPoul-Henning Kamp 	error = (*fn)(name + 1, namelen - 1, old, &oldlen,
585b8da2396SPoul-Henning Kamp 	    new, newlen, p);
5862e210993SPoul-Henning Kamp 
5872e210993SPoul-Henning Kamp 
588b8da2396SPoul-Henning Kamp 	if (old != NULL) {
589df8bae1dSRodney W. Grimes 		if (dolock)
590b8da2396SPoul-Henning Kamp 			vsunlock(old, savelen, B_WRITE);
591df8bae1dSRodney W. Grimes 		memlock.sl_lock = 0;
592df8bae1dSRodney W. Grimes 		if (memlock.sl_want) {
593df8bae1dSRodney W. Grimes 			memlock.sl_want = 0;
594df8bae1dSRodney W. Grimes 			wakeup((caddr_t)&memlock);
595df8bae1dSRodney W. Grimes 		}
596df8bae1dSRodney W. Grimes 	}
597787d58f2SPoul-Henning Kamp #if 0
598787d58f2SPoul-Henning Kamp 	if (error) {
599787d58f2SPoul-Henning Kamp 		printf("SYSCTL_ERROR: ");
600b8da2396SPoul-Henning Kamp 		for(i=0;i<namelen;i++)
601787d58f2SPoul-Henning Kamp 			printf("%d ", name[i]);
602787d58f2SPoul-Henning Kamp 		printf("= %d\n", error);
603787d58f2SPoul-Henning Kamp 	}
604787d58f2SPoul-Henning Kamp #endif
605df8bae1dSRodney W. Grimes 	if (error)
606df8bae1dSRodney W. Grimes 		return (error);
607b8da2396SPoul-Henning Kamp 	if (retval)
608df8bae1dSRodney W. Grimes 		*retval = oldlen;
609b8da2396SPoul-Henning Kamp 	if (oldlenp) {
610b8da2396SPoul-Henning Kamp 		if (inkernel) {
611b8da2396SPoul-Henning Kamp 			*oldlenp = oldlen;
612b8da2396SPoul-Henning Kamp 		} else {
613b8da2396SPoul-Henning Kamp 			error = copyout(&oldlen, oldlenp, sizeof(oldlen));
614b8da2396SPoul-Henning Kamp 		}
615b8da2396SPoul-Henning Kamp 	}
616b8da2396SPoul-Henning Kamp 	return (error);
617df8bae1dSRodney W. Grimes }
618df8bae1dSRodney W. Grimes 
619df8bae1dSRodney W. Grimes /*
620df8bae1dSRodney W. Grimes  * Attributes stored in the kernel.
621df8bae1dSRodney W. Grimes  */
6226ae6a09bSGarrett Wollman int securelevel = -1;
623df8bae1dSRodney W. Grimes 
624df8bae1dSRodney W. Grimes /*
625df8bae1dSRodney W. Grimes  * kernel related system variables.
626df8bae1dSRodney W. Grimes  */
6273c8e79ddSBruce Evans static int
628df8bae1dSRodney W. Grimes kern_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
629df8bae1dSRodney W. Grimes 	int *name;
630df8bae1dSRodney W. Grimes 	u_int namelen;
631df8bae1dSRodney W. Grimes 	void *oldp;
632df8bae1dSRodney W. Grimes 	size_t *oldlenp;
633df8bae1dSRodney W. Grimes 	void *newp;
634df8bae1dSRodney W. Grimes 	size_t newlen;
635df8bae1dSRodney W. Grimes 	struct proc *p;
636df8bae1dSRodney W. Grimes {
6372e210993SPoul-Henning Kamp 	int error, level;
6385bb4f738SGarrett Wollman 	dev_t ndumpdev;
639df8bae1dSRodney W. Grimes 
640df8bae1dSRodney W. Grimes 	/* all sysctl names at this level are terminal */
6413f31c649SGarrett Wollman 	if (namelen != 1 && !(name[0] == KERN_PROC || name[0] == KERN_PROF
6423f31c649SGarrett Wollman 			      || name[0] == KERN_NTP_PLL))
643df8bae1dSRodney W. Grimes 		return (ENOTDIR);		/* overloaded */
644df8bae1dSRodney W. Grimes 
645df8bae1dSRodney W. Grimes 	switch (name[0]) {
646b396cd83SPoul-Henning Kamp 
647df8bae1dSRodney W. Grimes 	case KERN_SECURELVL:
648df8bae1dSRodney W. Grimes 		level = securelevel;
649df8bae1dSRodney W. Grimes 		if ((error = sysctl_int(oldp, oldlenp, newp, newlen, &level)) ||
650df8bae1dSRodney W. Grimes 		    newp == NULL)
651df8bae1dSRodney W. Grimes 			return (error);
652df8bae1dSRodney W. Grimes 		if (level < securelevel && p->p_pid != 1)
653df8bae1dSRodney W. Grimes 			return (EPERM);
654df8bae1dSRodney W. Grimes 		securelevel = level;
655df8bae1dSRodney W. Grimes 		return (0);
656df8bae1dSRodney W. Grimes 	case KERN_VNODE:
657df8bae1dSRodney W. Grimes 		return (sysctl_vnode(oldp, oldlenp));
658df8bae1dSRodney W. Grimes 	case KERN_PROC:
659df8bae1dSRodney W. Grimes 		return (sysctl_doproc(name + 1, namelen - 1, oldp, oldlenp));
660df8bae1dSRodney W. Grimes 	case KERN_FILE:
661df8bae1dSRodney W. Grimes 		return (sysctl_file(oldp, oldlenp));
662df8bae1dSRodney W. Grimes #ifdef GPROF
663df8bae1dSRodney W. Grimes 	case KERN_PROF:
664df8bae1dSRodney W. Grimes 		return (sysctl_doprof(name + 1, namelen - 1, oldp, oldlenp,
665df8bae1dSRodney W. Grimes 		    newp, newlen));
666df8bae1dSRodney W. Grimes #endif
6673f31c649SGarrett Wollman 	case KERN_NTP_PLL:
6683f31c649SGarrett Wollman 		return (ntp_sysctl(name + 1, namelen - 1, oldp, oldlenp,
6693f31c649SGarrett Wollman 				   newp, newlen, p));
6705bb4f738SGarrett Wollman 	case KERN_DUMPDEV:
6715bb4f738SGarrett Wollman 		ndumpdev = dumpdev;
6725bb4f738SGarrett Wollman 		error = sysctl_struct(oldp, oldlenp, newp, newlen, &ndumpdev,
6735bb4f738SGarrett Wollman 				      sizeof ndumpdev);
6745bb4f738SGarrett Wollman 		if (!error && ndumpdev != dumpdev) {
6755bb4f738SGarrett Wollman 			error = setdumpdev(ndumpdev);
6765bb4f738SGarrett Wollman 		}
6775bb4f738SGarrett Wollman 		return error;
678df8bae1dSRodney W. Grimes 	default:
679df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
680df8bae1dSRodney W. Grimes 	}
681df8bae1dSRodney W. Grimes 	/* NOTREACHED */
682df8bae1dSRodney W. Grimes }
683df8bae1dSRodney W. Grimes 
684df8bae1dSRodney W. Grimes /*
685df8bae1dSRodney W. Grimes  * hardware related system variables.
686df8bae1dSRodney W. Grimes  */
68726f9a767SRodney W. Grimes int
688df8bae1dSRodney W. Grimes hw_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
689df8bae1dSRodney W. Grimes 	int *name;
690df8bae1dSRodney W. Grimes 	u_int namelen;
691df8bae1dSRodney W. Grimes 	void *oldp;
692df8bae1dSRodney W. Grimes 	size_t *oldlenp;
693df8bae1dSRodney W. Grimes 	void *newp;
694df8bae1dSRodney W. Grimes 	size_t newlen;
695df8bae1dSRodney W. Grimes 	struct proc *p;
696df8bae1dSRodney W. Grimes {
6978478cabaSGarrett Wollman 	/* almost all sysctl names at this level are terminal */
6988478cabaSGarrett Wollman 	if (namelen != 1 && name[0] != HW_DEVCONF)
699df8bae1dSRodney W. Grimes 		return (ENOTDIR);		/* overloaded */
700df8bae1dSRodney W. Grimes 
701df8bae1dSRodney W. Grimes 	switch (name[0]) {
702df8bae1dSRodney W. Grimes 	case HW_PHYSMEM:
703df8bae1dSRodney W. Grimes 		return (sysctl_rdint(oldp, oldlenp, newp, ctob(physmem)));
704df8bae1dSRodney W. Grimes 	case HW_USERMEM:
705df8bae1dSRodney W. Grimes 		return (sysctl_rdint(oldp, oldlenp, newp,
706df8bae1dSRodney W. Grimes 		    ctob(physmem - cnt.v_wire_count)));
7078478cabaSGarrett Wollman 	case HW_DEVCONF:
7088478cabaSGarrett Wollman 		return (dev_sysctl(name + 1, namelen - 1, oldp, oldlenp,
7098478cabaSGarrett Wollman 				   newp, newlen, p));
710df8bae1dSRodney W. Grimes 	default:
711df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
712df8bae1dSRodney W. Grimes 	}
713df8bae1dSRodney W. Grimes 	/* NOTREACHED */
714df8bae1dSRodney W. Grimes }
715df8bae1dSRodney W. Grimes 
716df8bae1dSRodney W. Grimes #ifdef DEBUG
717df8bae1dSRodney W. Grimes /*
718df8bae1dSRodney W. Grimes  * Debugging related system variables.
719df8bae1dSRodney W. Grimes  */
720df8bae1dSRodney W. Grimes struct ctldebug debug0, debug1, debug2, debug3, debug4;
721df8bae1dSRodney W. Grimes struct ctldebug debug5, debug6, debug7, debug8, debug9;
722df8bae1dSRodney W. Grimes struct ctldebug debug10, debug11, debug12, debug13, debug14;
723df8bae1dSRodney W. Grimes struct ctldebug debug15, debug16, debug17, debug18, debug19;
724df8bae1dSRodney W. Grimes static struct ctldebug *debugvars[CTL_DEBUG_MAXID] = {
725df8bae1dSRodney W. Grimes 	&debug0, &debug1, &debug2, &debug3, &debug4,
726df8bae1dSRodney W. Grimes 	&debug5, &debug6, &debug7, &debug8, &debug9,
727df8bae1dSRodney W. Grimes 	&debug10, &debug11, &debug12, &debug13, &debug14,
728df8bae1dSRodney W. Grimes 	&debug15, &debug16, &debug17, &debug18, &debug19,
729df8bae1dSRodney W. Grimes };
7306124ac44SBruce Evans static int
731df8bae1dSRodney W. Grimes debug_sysctl(name, namelen, oldp, oldlenp, newp, newlen, p)
732df8bae1dSRodney W. Grimes 	int *name;
733df8bae1dSRodney W. Grimes 	u_int namelen;
734df8bae1dSRodney W. Grimes 	void *oldp;
735df8bae1dSRodney W. Grimes 	size_t *oldlenp;
736df8bae1dSRodney W. Grimes 	void *newp;
737df8bae1dSRodney W. Grimes 	size_t newlen;
738df8bae1dSRodney W. Grimes 	struct proc *p;
739df8bae1dSRodney W. Grimes {
740df8bae1dSRodney W. Grimes 	struct ctldebug *cdp;
741df8bae1dSRodney W. Grimes 
742df8bae1dSRodney W. Grimes 	/* all sysctl names at this level are name and field */
743df8bae1dSRodney W. Grimes 	if (namelen != 2)
744df8bae1dSRodney W. Grimes 		return (ENOTDIR);		/* overloaded */
745df8bae1dSRodney W. Grimes 	cdp = debugvars[name[0]];
746df8bae1dSRodney W. Grimes 	if (cdp->debugname == 0)
747df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
748df8bae1dSRodney W. Grimes 	switch (name[1]) {
749df8bae1dSRodney W. Grimes 	case CTL_DEBUG_NAME:
750df8bae1dSRodney W. Grimes 		return (sysctl_rdstring(oldp, oldlenp, newp, cdp->debugname));
751df8bae1dSRodney W. Grimes 	case CTL_DEBUG_VALUE:
752df8bae1dSRodney W. Grimes 		return (sysctl_int(oldp, oldlenp, newp, newlen, cdp->debugvar));
753df8bae1dSRodney W. Grimes 	default:
754df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
755df8bae1dSRodney W. Grimes 	}
756df8bae1dSRodney W. Grimes 	/* NOTREACHED */
757df8bae1dSRodney W. Grimes }
758df8bae1dSRodney W. Grimes #endif /* DEBUG */
759df8bae1dSRodney W. Grimes 
760df8bae1dSRodney W. Grimes /*
761df8bae1dSRodney W. Grimes  * Validate parameters and get old / set new parameters
762df8bae1dSRodney W. Grimes  * for an integer-valued sysctl function.
763df8bae1dSRodney W. Grimes  */
76426f9a767SRodney W. Grimes int
765df8bae1dSRodney W. Grimes sysctl_int(oldp, oldlenp, newp, newlen, valp)
766df8bae1dSRodney W. Grimes 	void *oldp;
767df8bae1dSRodney W. Grimes 	size_t *oldlenp;
768df8bae1dSRodney W. Grimes 	void *newp;
769df8bae1dSRodney W. Grimes 	size_t newlen;
770df8bae1dSRodney W. Grimes 	int *valp;
771df8bae1dSRodney W. Grimes {
772df8bae1dSRodney W. Grimes 	int error = 0;
773df8bae1dSRodney W. Grimes 
774df8bae1dSRodney W. Grimes 	if (oldp && *oldlenp < sizeof(int))
775df8bae1dSRodney W. Grimes 		return (ENOMEM);
776df8bae1dSRodney W. Grimes 	if (newp && newlen != sizeof(int))
777df8bae1dSRodney W. Grimes 		return (EINVAL);
778df8bae1dSRodney W. Grimes 	*oldlenp = sizeof(int);
779df8bae1dSRodney W. Grimes 	if (oldp)
780df8bae1dSRodney W. Grimes 		error = copyout(valp, oldp, sizeof(int));
781df8bae1dSRodney W. Grimes 	if (error == 0 && newp)
782df8bae1dSRodney W. Grimes 		error = copyin(newp, valp, sizeof(int));
783df8bae1dSRodney W. Grimes 	return (error);
784df8bae1dSRodney W. Grimes }
785df8bae1dSRodney W. Grimes 
786df8bae1dSRodney W. Grimes /*
787df8bae1dSRodney W. Grimes  * As above, but read-only.
788df8bae1dSRodney W. Grimes  */
78926f9a767SRodney W. Grimes int
790df8bae1dSRodney W. Grimes sysctl_rdint(oldp, oldlenp, newp, val)
791df8bae1dSRodney W. Grimes 	void *oldp;
792df8bae1dSRodney W. Grimes 	size_t *oldlenp;
793df8bae1dSRodney W. Grimes 	void *newp;
794df8bae1dSRodney W. Grimes 	int val;
795df8bae1dSRodney W. Grimes {
796df8bae1dSRodney W. Grimes 	int error = 0;
797df8bae1dSRodney W. Grimes 
798df8bae1dSRodney W. Grimes 	if (oldp && *oldlenp < sizeof(int))
799df8bae1dSRodney W. Grimes 		return (ENOMEM);
800df8bae1dSRodney W. Grimes 	if (newp)
801df8bae1dSRodney W. Grimes 		return (EPERM);
802df8bae1dSRodney W. Grimes 	*oldlenp = sizeof(int);
803df8bae1dSRodney W. Grimes 	if (oldp)
804df8bae1dSRodney W. Grimes 		error = copyout((caddr_t)&val, oldp, sizeof(int));
805df8bae1dSRodney W. Grimes 	return (error);
806df8bae1dSRodney W. Grimes }
807df8bae1dSRodney W. Grimes 
808df8bae1dSRodney W. Grimes /*
809df8bae1dSRodney W. Grimes  * Validate parameters and get old / set new parameters
810df8bae1dSRodney W. Grimes  * for a string-valued sysctl function.
811df8bae1dSRodney W. Grimes  */
81226f9a767SRodney W. Grimes int
813df8bae1dSRodney W. Grimes sysctl_string(oldp, oldlenp, newp, newlen, str, maxlen)
814df8bae1dSRodney W. Grimes 	void *oldp;
815df8bae1dSRodney W. Grimes 	size_t *oldlenp;
816df8bae1dSRodney W. Grimes 	void *newp;
817df8bae1dSRodney W. Grimes 	size_t newlen;
818df8bae1dSRodney W. Grimes 	char *str;
819df8bae1dSRodney W. Grimes 	int maxlen;
820df8bae1dSRodney W. Grimes {
821e1453736SMike Pritchard 	int len, error = 0, rval = 0;
822df8bae1dSRodney W. Grimes 
823df8bae1dSRodney W. Grimes 	len = strlen(str) + 1;
824e1453736SMike Pritchard 	if (oldp && *oldlenp < len) {
825f81fcd41SGuido van Rooij 		len = *oldlenp;
826e1453736SMike Pritchard 		rval = ENOMEM;
827e1453736SMike Pritchard 	}
828df8bae1dSRodney W. Grimes 	if (newp && newlen >= maxlen)
829df8bae1dSRodney W. Grimes 		return (EINVAL);
830df8bae1dSRodney W. Grimes 	if (oldp) {
831df8bae1dSRodney W. Grimes 		*oldlenp = len;
832df8bae1dSRodney W. Grimes 		error = copyout(str, oldp, len);
833e1453736SMike Pritchard 		if (error)
834e1453736SMike Pritchard 			rval = error;
835df8bae1dSRodney W. Grimes 	}
836e1453736SMike Pritchard 	if ((error == 0 || error == ENOMEM) && newp) {
837df8bae1dSRodney W. Grimes 		error = copyin(newp, str, newlen);
838e1453736SMike Pritchard 		if (error)
839e1453736SMike Pritchard 			rval = error;
840df8bae1dSRodney W. Grimes 		str[newlen] = 0;
841df8bae1dSRodney W. Grimes 	}
842e1453736SMike Pritchard 	return (rval);
843df8bae1dSRodney W. Grimes }
844df8bae1dSRodney W. Grimes 
845df8bae1dSRodney W. Grimes /*
846df8bae1dSRodney W. Grimes  * As above, but read-only.
847df8bae1dSRodney W. Grimes  */
84826f9a767SRodney W. Grimes int
849df8bae1dSRodney W. Grimes sysctl_rdstring(oldp, oldlenp, newp, str)
850df8bae1dSRodney W. Grimes 	void *oldp;
851df8bae1dSRodney W. Grimes 	size_t *oldlenp;
852df8bae1dSRodney W. Grimes 	void *newp;
853df8bae1dSRodney W. Grimes 	char *str;
854df8bae1dSRodney W. Grimes {
855e1453736SMike Pritchard 	int len, error = 0, rval = 0;
856df8bae1dSRodney W. Grimes 
857df8bae1dSRodney W. Grimes 	len = strlen(str) + 1;
858e1453736SMike Pritchard 	if (oldp && *oldlenp < len) {
859e1453736SMike Pritchard 		len = *oldlenp;
860e1453736SMike Pritchard 		rval = ENOMEM;
861e1453736SMike Pritchard 	}
862df8bae1dSRodney W. Grimes 	if (newp)
863df8bae1dSRodney W. Grimes 		return (EPERM);
864df8bae1dSRodney W. Grimes 	*oldlenp = len;
865df8bae1dSRodney W. Grimes 	if (oldp)
866df8bae1dSRodney W. Grimes 		error = copyout(str, oldp, len);
867e1453736SMike Pritchard 		if (error)
868e1453736SMike Pritchard 			rval = error;
869e1453736SMike Pritchard 	return (rval);
870df8bae1dSRodney W. Grimes }
871df8bae1dSRodney W. Grimes 
872df8bae1dSRodney W. Grimes /*
873df8bae1dSRodney W. Grimes  * Validate parameters and get old / set new parameters
874df8bae1dSRodney W. Grimes  * for a structure oriented sysctl function.
875df8bae1dSRodney W. Grimes  */
87626f9a767SRodney W. Grimes int
877df8bae1dSRodney W. Grimes sysctl_struct(oldp, oldlenp, newp, newlen, sp, len)
878df8bae1dSRodney W. Grimes 	void *oldp;
879df8bae1dSRodney W. Grimes 	size_t *oldlenp;
880df8bae1dSRodney W. Grimes 	void *newp;
881df8bae1dSRodney W. Grimes 	size_t newlen;
882df8bae1dSRodney W. Grimes 	void *sp;
883df8bae1dSRodney W. Grimes 	int len;
884df8bae1dSRodney W. Grimes {
885df8bae1dSRodney W. Grimes 	int error = 0;
886df8bae1dSRodney W. Grimes 
887df8bae1dSRodney W. Grimes 	if (oldp && *oldlenp < len)
888df8bae1dSRodney W. Grimes 		return (ENOMEM);
889df8bae1dSRodney W. Grimes 	if (newp && newlen > len)
890df8bae1dSRodney W. Grimes 		return (EINVAL);
891df8bae1dSRodney W. Grimes 	if (oldp) {
892df8bae1dSRodney W. Grimes 		*oldlenp = len;
893df8bae1dSRodney W. Grimes 		error = copyout(sp, oldp, len);
894df8bae1dSRodney W. Grimes 	}
895df8bae1dSRodney W. Grimes 	if (error == 0 && newp)
896df8bae1dSRodney W. Grimes 		error = copyin(newp, sp, len);
897df8bae1dSRodney W. Grimes 	return (error);
898df8bae1dSRodney W. Grimes }
899df8bae1dSRodney W. Grimes 
900df8bae1dSRodney W. Grimes /*
901df8bae1dSRodney W. Grimes  * Validate parameters and get old parameters
902df8bae1dSRodney W. Grimes  * for a structure oriented sysctl function.
903df8bae1dSRodney W. Grimes  */
90426f9a767SRodney W. Grimes int
905df8bae1dSRodney W. Grimes sysctl_rdstruct(oldp, oldlenp, newp, sp, len)
906df8bae1dSRodney W. Grimes 	void *oldp;
907df8bae1dSRodney W. Grimes 	size_t *oldlenp;
908df8bae1dSRodney W. Grimes 	void *newp, *sp;
909df8bae1dSRodney W. Grimes 	int len;
910df8bae1dSRodney W. Grimes {
911df8bae1dSRodney W. Grimes 	int error = 0;
912df8bae1dSRodney W. Grimes 
913df8bae1dSRodney W. Grimes 	if (oldp && *oldlenp < len)
914df8bae1dSRodney W. Grimes 		return (ENOMEM);
915df8bae1dSRodney W. Grimes 	if (newp)
916df8bae1dSRodney W. Grimes 		return (EPERM);
917df8bae1dSRodney W. Grimes 	*oldlenp = len;
918df8bae1dSRodney W. Grimes 	if (oldp)
919df8bae1dSRodney W. Grimes 		error = copyout(sp, oldp, len);
920df8bae1dSRodney W. Grimes 	return (error);
921df8bae1dSRodney W. Grimes }
922df8bae1dSRodney W. Grimes 
923df8bae1dSRodney W. Grimes /*
924df8bae1dSRodney W. Grimes  * Get file structures.
925df8bae1dSRodney W. Grimes  */
92626f9a767SRodney W. Grimes int
927df8bae1dSRodney W. Grimes sysctl_file(where, sizep)
928df8bae1dSRodney W. Grimes 	char *where;
929df8bae1dSRodney W. Grimes 	size_t *sizep;
930df8bae1dSRodney W. Grimes {
931df8bae1dSRodney W. Grimes 	int buflen, error;
932df8bae1dSRodney W. Grimes 	struct file *fp;
933df8bae1dSRodney W. Grimes 	char *start = where;
934df8bae1dSRodney W. Grimes 
935df8bae1dSRodney W. Grimes 	buflen = *sizep;
936df8bae1dSRodney W. Grimes 	if (where == NULL) {
937df8bae1dSRodney W. Grimes 		/*
938df8bae1dSRodney W. Grimes 		 * overestimate by 10 files
939df8bae1dSRodney W. Grimes 		 */
940df8bae1dSRodney W. Grimes 		*sizep = sizeof(filehead) + (nfiles + 10) * sizeof(struct file);
941df8bae1dSRodney W. Grimes 		return (0);
942df8bae1dSRodney W. Grimes 	}
943df8bae1dSRodney W. Grimes 
944df8bae1dSRodney W. Grimes 	/*
945df8bae1dSRodney W. Grimes 	 * first copyout filehead
946df8bae1dSRodney W. Grimes 	 */
947df8bae1dSRodney W. Grimes 	if (buflen < sizeof(filehead)) {
948df8bae1dSRodney W. Grimes 		*sizep = 0;
949df8bae1dSRodney W. Grimes 		return (0);
950df8bae1dSRodney W. Grimes 	}
951797f2d22SPoul-Henning Kamp 	error = copyout((caddr_t)&filehead, where, sizeof(filehead));
952797f2d22SPoul-Henning Kamp 	if (error)
953df8bae1dSRodney W. Grimes 		return (error);
954df8bae1dSRodney W. Grimes 	buflen -= sizeof(filehead);
955df8bae1dSRodney W. Grimes 	where += sizeof(filehead);
956df8bae1dSRodney W. Grimes 
957df8bae1dSRodney W. Grimes 	/*
958df8bae1dSRodney W. Grimes 	 * followed by an array of file structures
959df8bae1dSRodney W. Grimes 	 */
960df8bae1dSRodney W. Grimes 	for (fp = filehead; fp != NULL; fp = fp->f_filef) {
961df8bae1dSRodney W. Grimes 		if (buflen < sizeof(struct file)) {
962df8bae1dSRodney W. Grimes 			*sizep = where - start;
963df8bae1dSRodney W. Grimes 			return (ENOMEM);
964df8bae1dSRodney W. Grimes 		}
965797f2d22SPoul-Henning Kamp 		error = copyout((caddr_t)fp, where, sizeof (struct file));
966797f2d22SPoul-Henning Kamp 		if (error)
967df8bae1dSRodney W. Grimes 			return (error);
968df8bae1dSRodney W. Grimes 		buflen -= sizeof(struct file);
969df8bae1dSRodney W. Grimes 		where += sizeof(struct file);
970df8bae1dSRodney W. Grimes 	}
971df8bae1dSRodney W. Grimes 	*sizep = where - start;
972df8bae1dSRodney W. Grimes 	return (0);
973df8bae1dSRodney W. Grimes }
974df8bae1dSRodney W. Grimes 
975df8bae1dSRodney W. Grimes /*
976df8bae1dSRodney W. Grimes  * try over estimating by 5 procs
977df8bae1dSRodney W. Grimes  */
978df8bae1dSRodney W. Grimes #define KERN_PROCSLOP	(5 * sizeof (struct kinfo_proc))
979df8bae1dSRodney W. Grimes 
98026f9a767SRodney W. Grimes int
981df8bae1dSRodney W. Grimes sysctl_doproc(name, namelen, where, sizep)
982df8bae1dSRodney W. Grimes 	int *name;
983df8bae1dSRodney W. Grimes 	u_int namelen;
984df8bae1dSRodney W. Grimes 	char *where;
985df8bae1dSRodney W. Grimes 	size_t *sizep;
986df8bae1dSRodney W. Grimes {
987df8bae1dSRodney W. Grimes 	register struct proc *p;
988df8bae1dSRodney W. Grimes 	register struct kinfo_proc *dp = (struct kinfo_proc *)where;
989df8bae1dSRodney W. Grimes 	register int needed = 0;
990df8bae1dSRodney W. Grimes 	int buflen = where != NULL ? *sizep : 0;
991df8bae1dSRodney W. Grimes 	int doingzomb;
992df8bae1dSRodney W. Grimes 	struct eproc eproc;
993df8bae1dSRodney W. Grimes 	int error = 0;
994df8bae1dSRodney W. Grimes 
995df8bae1dSRodney W. Grimes 	if (namelen != 2 && !(namelen == 1 && name[0] == KERN_PROC_ALL))
996df8bae1dSRodney W. Grimes 		return (EINVAL);
997df8bae1dSRodney W. Grimes 	p = (struct proc *)allproc;
998df8bae1dSRodney W. Grimes 	doingzomb = 0;
999df8bae1dSRodney W. Grimes again:
1000df8bae1dSRodney W. Grimes 	for (; p != NULL; p = p->p_next) {
1001df8bae1dSRodney W. Grimes 		/*
1002df8bae1dSRodney W. Grimes 		 * Skip embryonic processes.
1003df8bae1dSRodney W. Grimes 		 */
1004df8bae1dSRodney W. Grimes 		if (p->p_stat == SIDL)
1005df8bae1dSRodney W. Grimes 			continue;
1006df8bae1dSRodney W. Grimes 		/*
1007df8bae1dSRodney W. Grimes 		 * TODO - make more efficient (see notes below).
1008df8bae1dSRodney W. Grimes 		 * do by session.
1009df8bae1dSRodney W. Grimes 		 */
1010df8bae1dSRodney W. Grimes 		switch (name[0]) {
1011df8bae1dSRodney W. Grimes 
1012df8bae1dSRodney W. Grimes 		case KERN_PROC_PID:
1013df8bae1dSRodney W. Grimes 			/* could do this with just a lookup */
1014df8bae1dSRodney W. Grimes 			if (p->p_pid != (pid_t)name[1])
1015df8bae1dSRodney W. Grimes 				continue;
1016df8bae1dSRodney W. Grimes 			break;
1017df8bae1dSRodney W. Grimes 
1018df8bae1dSRodney W. Grimes 		case KERN_PROC_PGRP:
1019df8bae1dSRodney W. Grimes 			/* could do this by traversing pgrp */
1020be6a1d14SDavid Greenman 			if (p->p_pgrp == NULL || p->p_pgrp->pg_id != (pid_t)name[1])
1021df8bae1dSRodney W. Grimes 				continue;
1022df8bae1dSRodney W. Grimes 			break;
1023df8bae1dSRodney W. Grimes 
1024df8bae1dSRodney W. Grimes 		case KERN_PROC_TTY:
1025df8bae1dSRodney W. Grimes 			if ((p->p_flag & P_CONTROLT) == 0 ||
1026be6a1d14SDavid Greenman 			    p->p_session == NULL ||
1027df8bae1dSRodney W. Grimes 			    p->p_session->s_ttyp == NULL ||
1028df8bae1dSRodney W. Grimes 			    p->p_session->s_ttyp->t_dev != (dev_t)name[1])
1029df8bae1dSRodney W. Grimes 				continue;
1030df8bae1dSRodney W. Grimes 			break;
1031df8bae1dSRodney W. Grimes 
1032df8bae1dSRodney W. Grimes 		case KERN_PROC_UID:
1033be6a1d14SDavid Greenman 			if (p->p_ucred == NULL || p->p_ucred->cr_uid != (uid_t)name[1])
1034df8bae1dSRodney W. Grimes 				continue;
1035df8bae1dSRodney W. Grimes 			break;
1036df8bae1dSRodney W. Grimes 
1037df8bae1dSRodney W. Grimes 		case KERN_PROC_RUID:
1038be6a1d14SDavid Greenman 			if (p->p_ucred == NULL || p->p_cred->p_ruid != (uid_t)name[1])
1039df8bae1dSRodney W. Grimes 				continue;
1040df8bae1dSRodney W. Grimes 			break;
1041df8bae1dSRodney W. Grimes 		}
1042df8bae1dSRodney W. Grimes 		if (buflen >= sizeof(struct kinfo_proc)) {
1043df8bae1dSRodney W. Grimes 			fill_eproc(p, &eproc);
1044797f2d22SPoul-Henning Kamp 			error = copyout((caddr_t)p, &dp->kp_proc,
1045797f2d22SPoul-Henning Kamp 			    sizeof(struct proc));
1046797f2d22SPoul-Henning Kamp 			if (error)
1047df8bae1dSRodney W. Grimes 				return (error);
1048797f2d22SPoul-Henning Kamp 			error = copyout((caddr_t)&eproc, &dp->kp_eproc,
1049797f2d22SPoul-Henning Kamp 			    sizeof(eproc));
1050797f2d22SPoul-Henning Kamp 			if (error)
1051df8bae1dSRodney W. Grimes 				return (error);
1052df8bae1dSRodney W. Grimes 			dp++;
1053df8bae1dSRodney W. Grimes 			buflen -= sizeof(struct kinfo_proc);
1054df8bae1dSRodney W. Grimes 		}
1055df8bae1dSRodney W. Grimes 		needed += sizeof(struct kinfo_proc);
1056df8bae1dSRodney W. Grimes 	}
1057df8bae1dSRodney W. Grimes 	if (doingzomb == 0) {
1058df8bae1dSRodney W. Grimes 		p = zombproc;
1059df8bae1dSRodney W. Grimes 		doingzomb++;
1060df8bae1dSRodney W. Grimes 		goto again;
1061df8bae1dSRodney W. Grimes 	}
1062df8bae1dSRodney W. Grimes 	if (where != NULL) {
1063df8bae1dSRodney W. Grimes 		*sizep = (caddr_t)dp - where;
1064df8bae1dSRodney W. Grimes 		if (needed > *sizep)
1065df8bae1dSRodney W. Grimes 			return (ENOMEM);
1066df8bae1dSRodney W. Grimes 	} else {
1067df8bae1dSRodney W. Grimes 		needed += KERN_PROCSLOP;
1068df8bae1dSRodney W. Grimes 		*sizep = needed;
1069df8bae1dSRodney W. Grimes 	}
1070df8bae1dSRodney W. Grimes 	return (0);
1071df8bae1dSRodney W. Grimes }
1072df8bae1dSRodney W. Grimes 
1073df8bae1dSRodney W. Grimes /*
1074df8bae1dSRodney W. Grimes  * Fill in an eproc structure for the specified process.
1075df8bae1dSRodney W. Grimes  */
1076df8bae1dSRodney W. Grimes void
1077df8bae1dSRodney W. Grimes fill_eproc(p, ep)
1078df8bae1dSRodney W. Grimes 	register struct proc *p;
1079df8bae1dSRodney W. Grimes 	register struct eproc *ep;
1080df8bae1dSRodney W. Grimes {
1081df8bae1dSRodney W. Grimes 	register struct tty *tp;
1082df8bae1dSRodney W. Grimes 
1083be6a1d14SDavid Greenman 	bzero(ep, sizeof(*ep));
1084be6a1d14SDavid Greenman 
1085df8bae1dSRodney W. Grimes 	ep->e_paddr = p;
10861c8fc26cSDavid Greenman 	if (p->p_cred) {
1087df8bae1dSRodney W. Grimes 		ep->e_pcred = *p->p_cred;
1088be6a1d14SDavid Greenman 		if (p->p_ucred)
1089df8bae1dSRodney W. Grimes 			ep->e_ucred = *p->p_ucred;
10901c8fc26cSDavid Greenman 	}
10911c8fc26cSDavid Greenman 	if (p->p_stat != SIDL && p->p_stat != SZOMB && p->p_vmspace != NULL) {
1092df8bae1dSRodney W. Grimes 		register struct vmspace *vm = p->p_vmspace;
1093df8bae1dSRodney W. Grimes 
1094df8bae1dSRodney W. Grimes #ifdef pmap_resident_count
1095df8bae1dSRodney W. Grimes 		ep->e_vm.vm_rssize = pmap_resident_count(&vm->vm_pmap); /*XXX*/
1096df8bae1dSRodney W. Grimes #else
1097df8bae1dSRodney W. Grimes 		ep->e_vm.vm_rssize = vm->vm_rssize;
1098df8bae1dSRodney W. Grimes #endif
1099df8bae1dSRodney W. Grimes 		ep->e_vm.vm_tsize = vm->vm_tsize;
1100df8bae1dSRodney W. Grimes 		ep->e_vm.vm_dsize = vm->vm_dsize;
1101df8bae1dSRodney W. Grimes 		ep->e_vm.vm_ssize = vm->vm_ssize;
1102df8bae1dSRodney W. Grimes #ifndef sparc
1103df8bae1dSRodney W. Grimes 		ep->e_vm.vm_pmap = vm->vm_pmap;
1104df8bae1dSRodney W. Grimes #endif
1105df8bae1dSRodney W. Grimes 	}
1106df8bae1dSRodney W. Grimes 	if (p->p_pptr)
1107df8bae1dSRodney W. Grimes 		ep->e_ppid = p->p_pptr->p_pid;
1108be6a1d14SDavid Greenman 	if (p->p_pgrp) {
1109be6a1d14SDavid Greenman 		ep->e_sess = p->p_pgrp->pg_session;
1110df8bae1dSRodney W. Grimes 		ep->e_pgid = p->p_pgrp->pg_id;
1111df8bae1dSRodney W. Grimes 		ep->e_jobc = p->p_pgrp->pg_jobc;
1112be6a1d14SDavid Greenman 	}
1113df8bae1dSRodney W. Grimes 	if ((p->p_flag & P_CONTROLT) &&
1114be6a1d14SDavid Greenman 	    (ep->e_sess != NULL) &&
1115be6a1d14SDavid Greenman 	    ((tp = ep->e_sess->s_ttyp) != NULL)) {
1116df8bae1dSRodney W. Grimes 		ep->e_tdev = tp->t_dev;
1117df8bae1dSRodney W. Grimes 		ep->e_tpgid = tp->t_pgrp ? tp->t_pgrp->pg_id : NO_PID;
1118df8bae1dSRodney W. Grimes 		ep->e_tsess = tp->t_session;
1119df8bae1dSRodney W. Grimes 	} else
1120df8bae1dSRodney W. Grimes 		ep->e_tdev = NODEV;
1121be6a1d14SDavid Greenman 	if (ep->e_sess && ep->e_sess->s_ttyvp)
1122be6a1d14SDavid Greenman 		ep->e_flag = EPROC_CTTY;
1123df8bae1dSRodney W. Grimes 	if (SESS_LEADER(p))
1124df8bae1dSRodney W. Grimes 		ep->e_flag |= EPROC_SLEADER;
1125be6a1d14SDavid Greenman 	if (p->p_wmesg) {
1126df8bae1dSRodney W. Grimes 		strncpy(ep->e_wmesg, p->p_wmesg, WMESGLEN);
1127be6a1d14SDavid Greenman 		ep->e_wmesg[WMESGLEN] = 0;
1128be6a1d14SDavid Greenman 	}
1129df8bae1dSRodney W. Grimes }
1130df8bae1dSRodney W. Grimes 
1131df8bae1dSRodney W. Grimes #ifdef COMPAT_43
1132df8bae1dSRodney W. Grimes #include <sys/socket.h>
1133df8bae1dSRodney W. Grimes #define	KINFO_PROC		(0<<8)
1134df8bae1dSRodney W. Grimes #define	KINFO_RT		(1<<8)
1135df8bae1dSRodney W. Grimes #define	KINFO_VNODE		(2<<8)
1136df8bae1dSRodney W. Grimes #define	KINFO_FILE		(3<<8)
1137df8bae1dSRodney W. Grimes #define	KINFO_METER		(4<<8)
1138df8bae1dSRodney W. Grimes #define	KINFO_LOADAVG		(5<<8)
1139df8bae1dSRodney W. Grimes #define	KINFO_CLOCKRATE		(6<<8)
1140df8bae1dSRodney W. Grimes 
11416ece4a51SPeter Wemm /* Non-standard BSDI extension - only present on their 4.3 net-2 releases */
11426ece4a51SPeter Wemm #define	KINFO_BSDI_SYSINFO	(101<<8)
11436ece4a51SPeter Wemm 
11446ece4a51SPeter Wemm /*
11456ece4a51SPeter Wemm  * XXX this is bloat, but I hope it's better here than on the potentially
11466ece4a51SPeter Wemm  * limited kernel stack...  -Peter
11476ece4a51SPeter Wemm  */
11486ece4a51SPeter Wemm 
11496ece4a51SPeter Wemm struct {
11506ece4a51SPeter Wemm 	int	bsdi_machine;		/* "i386" on BSD/386 */
11516ece4a51SPeter Wemm /*      ^^^ this is an offset to the string, relative to the struct start */
11526ece4a51SPeter Wemm 	char	*pad0;
11536ece4a51SPeter Wemm 	long	pad1;
11546ece4a51SPeter Wemm 	long	pad2;
11556ece4a51SPeter Wemm 	long	pad3;
11566ece4a51SPeter Wemm 	u_long	pad4;
11576ece4a51SPeter Wemm 	u_long	pad5;
11586ece4a51SPeter Wemm 	u_long	pad6;
11596ece4a51SPeter Wemm 
11606ece4a51SPeter Wemm 	int	bsdi_ostype;		/* "BSD/386" on BSD/386 */
11616ece4a51SPeter Wemm 	int	bsdi_osrelease;		/* "1.1" on BSD/386 */
11626ece4a51SPeter Wemm 	long	pad7;
11636ece4a51SPeter Wemm 	long	pad8;
11646ece4a51SPeter Wemm 	char	*pad9;
11656ece4a51SPeter Wemm 
11666ece4a51SPeter Wemm 	long	pad10;
11676ece4a51SPeter Wemm 	long	pad11;
11686ece4a51SPeter Wemm 	int	pad12;
11696ece4a51SPeter Wemm 	long	pad13;
11706ece4a51SPeter Wemm 	quad_t	pad14;
11716ece4a51SPeter Wemm 	long	pad15;
11726ece4a51SPeter Wemm 
11736ece4a51SPeter Wemm 	struct	timeval pad16;
11746ece4a51SPeter Wemm 	/* we dont set this, because BSDI's uname used gethostname() instead */
11756ece4a51SPeter Wemm 	int	bsdi_hostname;		/* hostname on BSD/386 */
11766ece4a51SPeter Wemm 
11776ece4a51SPeter Wemm 	/* the actual string data is appended here */
11786ece4a51SPeter Wemm 
11796ece4a51SPeter Wemm } bsdi_si;
11806ece4a51SPeter Wemm /*
11816ece4a51SPeter Wemm  * this data is appended to the end of the bsdi_si structure during copyout.
11826ece4a51SPeter Wemm  * The "char *" offsets are relative to the base of the bsdi_si struct.
11836ece4a51SPeter Wemm  * This contains "FreeBSD\02.0-BUILT-nnnnnn\0i386\0", and these strings
11846ece4a51SPeter Wemm  * should not exceed the length of the buffer here... (or else!! :-)
11856ece4a51SPeter Wemm  */
11866ece4a51SPeter Wemm char bsdi_strings[80];	/* It had better be less than this! */
11876ece4a51SPeter Wemm 
1188df8bae1dSRodney W. Grimes struct getkerninfo_args {
1189df8bae1dSRodney W. Grimes 	int	op;
1190df8bae1dSRodney W. Grimes 	char	*where;
1191df8bae1dSRodney W. Grimes 	int	*size;
1192df8bae1dSRodney W. Grimes 	int	arg;
1193df8bae1dSRodney W. Grimes };
1194df8bae1dSRodney W. Grimes 
119526f9a767SRodney W. Grimes int
1196df8bae1dSRodney W. Grimes ogetkerninfo(p, uap, retval)
1197df8bae1dSRodney W. Grimes 	struct proc *p;
1198df8bae1dSRodney W. Grimes 	register struct getkerninfo_args *uap;
1199df8bae1dSRodney W. Grimes 	int *retval;
1200df8bae1dSRodney W. Grimes {
1201b8da2396SPoul-Henning Kamp 	int error, name[6];
1202df8bae1dSRodney W. Grimes 	u_int size;
1203df8bae1dSRodney W. Grimes 
1204df8bae1dSRodney W. Grimes 	switch (uap->op & 0xff00) {
1205df8bae1dSRodney W. Grimes 
1206df8bae1dSRodney W. Grimes 	case KINFO_RT:
1207b8da2396SPoul-Henning Kamp 		name[0] = CTL_NET;
1208b8da2396SPoul-Henning Kamp 		name[1] = PF_ROUTE;
1209b8da2396SPoul-Henning Kamp 		name[2] = 0;
1210b8da2396SPoul-Henning Kamp 		name[3] = (uap->op & 0xff0000) >> 16;
1211b8da2396SPoul-Henning Kamp 		name[4] = uap->op & 0xff;
1212b8da2396SPoul-Henning Kamp 		name[5] = uap->arg;
1213b8da2396SPoul-Henning Kamp 		error = userland_sysctl(p, name, 6, uap->where, uap->size,
1214b8da2396SPoul-Henning Kamp 			0, 0, 0, 0);
1215df8bae1dSRodney W. Grimes 		break;
1216df8bae1dSRodney W. Grimes 
1217df8bae1dSRodney W. Grimes 	case KINFO_VNODE:
1218b8da2396SPoul-Henning Kamp 		name[0] = CTL_KERN;
1219b8da2396SPoul-Henning Kamp 		name[1] = KERN_VNODE;
1220b8da2396SPoul-Henning Kamp 		error = userland_sysctl(p, name, 2, uap->where, uap->size,
1221b8da2396SPoul-Henning Kamp 			0, 0, 0, 0);
1222df8bae1dSRodney W. Grimes 		break;
1223df8bae1dSRodney W. Grimes 
1224df8bae1dSRodney W. Grimes 	case KINFO_PROC:
1225b8da2396SPoul-Henning Kamp 		name[0] = CTL_KERN;
1226b8da2396SPoul-Henning Kamp 		name[1] = KERN_PROC;
1227b8da2396SPoul-Henning Kamp 		name[2] = uap->op & 0xff;
1228b8da2396SPoul-Henning Kamp 		name[3] = uap->arg;
1229b8da2396SPoul-Henning Kamp 		error = userland_sysctl(p, name, 4, uap->where, uap->size,
1230b8da2396SPoul-Henning Kamp 			0, 0, 0, 0);
1231df8bae1dSRodney W. Grimes 		break;
1232df8bae1dSRodney W. Grimes 
1233df8bae1dSRodney W. Grimes 	case KINFO_FILE:
1234b8da2396SPoul-Henning Kamp 		name[0] = CTL_KERN;
1235b8da2396SPoul-Henning Kamp 		name[1] = KERN_FILE;
1236b8da2396SPoul-Henning Kamp 		error = userland_sysctl(p, name, 2, uap->where, uap->size,
1237b8da2396SPoul-Henning Kamp 			0, 0, 0, 0);
1238df8bae1dSRodney W. Grimes 		break;
1239df8bae1dSRodney W. Grimes 
1240df8bae1dSRodney W. Grimes 	case KINFO_METER:
1241b8da2396SPoul-Henning Kamp 		name[0] = CTL_VM;
1242b8da2396SPoul-Henning Kamp 		name[1] = VM_METER;
1243b8da2396SPoul-Henning Kamp 		error = userland_sysctl(p, name, 2, uap->where, uap->size,
1244b8da2396SPoul-Henning Kamp 			0, 0, 0, 0);
1245df8bae1dSRodney W. Grimes 		break;
1246df8bae1dSRodney W. Grimes 
1247df8bae1dSRodney W. Grimes 	case KINFO_LOADAVG:
1248b8da2396SPoul-Henning Kamp 		name[0] = CTL_VM;
1249b8da2396SPoul-Henning Kamp 		name[1] = VM_LOADAVG;
1250b8da2396SPoul-Henning Kamp 		error = userland_sysctl(p, name, 2, uap->where, uap->size,
1251b8da2396SPoul-Henning Kamp 			0, 0, 0, 0);
1252df8bae1dSRodney W. Grimes 		break;
1253df8bae1dSRodney W. Grimes 
1254df8bae1dSRodney W. Grimes 	case KINFO_CLOCKRATE:
1255b8da2396SPoul-Henning Kamp 		name[0] = CTL_KERN;
1256b8da2396SPoul-Henning Kamp 		name[1] = KERN_CLOCKRATE;
1257b8da2396SPoul-Henning Kamp 		error = userland_sysctl(p, name, 2, uap->where, uap->size,
1258b8da2396SPoul-Henning Kamp 			0, 0, 0, 0);
1259df8bae1dSRodney W. Grimes 		break;
1260df8bae1dSRodney W. Grimes 
12616ece4a51SPeter Wemm 	case KINFO_BSDI_SYSINFO: {
12626ece4a51SPeter Wemm 		/*
12636ece4a51SPeter Wemm 		 * this is pretty crude, but it's just enough for uname()
12646ece4a51SPeter Wemm 		 * from BSDI's 1.x libc to work.
12656ece4a51SPeter Wemm 		 *
12666ece4a51SPeter Wemm 		 * In particular, it doesn't return the same results when
12676ece4a51SPeter Wemm 		 * the supplied buffer is too small.  BSDI's version apparently
12686ece4a51SPeter Wemm 		 * will return the amount copied, and set the *size to how
12696ece4a51SPeter Wemm 		 * much was needed.  The emulation framework here isn't capable
12706ece4a51SPeter Wemm 		 * of that, so we just set both to the amount copied.
12716ece4a51SPeter Wemm 		 * BSDI's 2.x product apparently fails with ENOMEM in this
12726ece4a51SPeter Wemm 		 * scenario.
12736ece4a51SPeter Wemm 		 */
12746ece4a51SPeter Wemm 
12756ece4a51SPeter Wemm 		u_int needed;
12766ece4a51SPeter Wemm 		u_int left;
12776ece4a51SPeter Wemm 		char *s;
12786ece4a51SPeter Wemm 
12796ece4a51SPeter Wemm 		bzero((char *)&bsdi_si, sizeof(bsdi_si));
12806ece4a51SPeter Wemm 		bzero(bsdi_strings, sizeof(bsdi_strings));
12816ece4a51SPeter Wemm 
12826ece4a51SPeter Wemm 		s = bsdi_strings;
12836ece4a51SPeter Wemm 
12846ece4a51SPeter Wemm 		bsdi_si.bsdi_ostype = (s - bsdi_strings) + sizeof(bsdi_si);
12856ece4a51SPeter Wemm 		strcpy(s, ostype);
12866ece4a51SPeter Wemm 		s += strlen(s) + 1;
12876ece4a51SPeter Wemm 
12886ece4a51SPeter Wemm 		bsdi_si.bsdi_osrelease = (s - bsdi_strings) + sizeof(bsdi_si);
12896ece4a51SPeter Wemm 		strcpy(s, osrelease);
12906ece4a51SPeter Wemm 		s += strlen(s) + 1;
12916ece4a51SPeter Wemm 
12926ece4a51SPeter Wemm 		bsdi_si.bsdi_machine = (s - bsdi_strings) + sizeof(bsdi_si);
12936ece4a51SPeter Wemm 		strcpy(s, machine);
12946ece4a51SPeter Wemm 		s += strlen(s) + 1;
12956ece4a51SPeter Wemm 
12966ece4a51SPeter Wemm 		needed = sizeof(bsdi_si) + (s - bsdi_strings);
12976ece4a51SPeter Wemm 
12986ece4a51SPeter Wemm 		if (uap->where == NULL) {
12996ece4a51SPeter Wemm 			/* process is asking how much buffer to supply.. */
13006ece4a51SPeter Wemm 			size = needed;
13016ece4a51SPeter Wemm 			error = 0;
13026ece4a51SPeter Wemm 			break;
13036ece4a51SPeter Wemm 		}
13046ece4a51SPeter Wemm 
13056ece4a51SPeter Wemm 
13066ece4a51SPeter Wemm 		/* if too much buffer supplied, trim it down */
13076ece4a51SPeter Wemm 		if (size > needed)
13086ece4a51SPeter Wemm 			size = needed;
13096ece4a51SPeter Wemm 
13106ece4a51SPeter Wemm 		/* how much of the buffer is remaining */
13116ece4a51SPeter Wemm 		left = size;
13126ece4a51SPeter Wemm 
13136ece4a51SPeter Wemm 		if ((error = copyout((char *)&bsdi_si, uap->where, left)) != 0)
13146ece4a51SPeter Wemm 			break;
13156ece4a51SPeter Wemm 
13166ece4a51SPeter Wemm 		/* is there any point in continuing? */
13176ece4a51SPeter Wemm 		if (left > sizeof(bsdi_si)) {
13186ece4a51SPeter Wemm 			left -= sizeof(bsdi_si);
13196ece4a51SPeter Wemm 			error = copyout(&bsdi_strings,
13206ece4a51SPeter Wemm 					uap->where + sizeof(bsdi_si), left);
13216ece4a51SPeter Wemm 		}
13226ece4a51SPeter Wemm 		break;
13236ece4a51SPeter Wemm 	}
13246ece4a51SPeter Wemm 
1325df8bae1dSRodney W. Grimes 	default:
1326df8bae1dSRodney W. Grimes 		return (EOPNOTSUPP);
1327df8bae1dSRodney W. Grimes 	}
1328df8bae1dSRodney W. Grimes 	if (error)
1329df8bae1dSRodney W. Grimes 		return (error);
1330df8bae1dSRodney W. Grimes 	*retval = size;
1331df8bae1dSRodney W. Grimes 	if (uap->size)
1332df8bae1dSRodney W. Grimes 		error = copyout((caddr_t)&size, (caddr_t)uap->size,
1333df8bae1dSRodney W. Grimes 		    sizeof(size));
1334df8bae1dSRodney W. Grimes 	return (error);
1335df8bae1dSRodney W. Grimes }
1336df8bae1dSRodney W. Grimes #endif /* COMPAT_43 */
1337