kern_mib.c revision 34925
190792Sgshapiro/*-
290792Sgshapiro * Copyright (c) 1982, 1986, 1989, 1993
390792Sgshapiro *	The Regents of the University of California.  All rights reserved.
490792Sgshapiro *
590792Sgshapiro * This code is derived from software contributed to Berkeley by
690792Sgshapiro * Mike Karels at Berkeley Software Design, Inc.
790792Sgshapiro *
890792Sgshapiro * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
990792Sgshapiro * project, to make these variables more userfriendly.
1090792Sgshapiro *
1190792Sgshapiro * Redistribution and use in source and binary forms, with or without
1290792Sgshapiro * modification, are permitted provided that the following conditions
1390792Sgshapiro * are met:
1490792Sgshapiro * 1. Redistributions of source code must retain the above copyright
1590792Sgshapiro *    notice, this list of conditions and the following disclaimer.
1690792Sgshapiro * 2. Redistributions in binary form must reproduce the above copyright
1790792Sgshapiro *    notice, this list of conditions and the following disclaimer in the
1890792Sgshapiro *    documentation and/or other materials provided with the distribution.
1990792Sgshapiro * 3. All advertising materials mentioning features or use of this software
2090792Sgshapiro *    must display the following acknowledgement:
2190792Sgshapiro *	This product includes software developed by the University of
2290792Sgshapiro *	California, Berkeley and its contributors.
2390792Sgshapiro * 4. Neither the name of the University nor the names of its contributors
2490792Sgshapiro *    may be used to endorse or promote products derived from this software
2590792Sgshapiro *    without specific prior written permission.
2690792Sgshapiro *
2790792Sgshapiro * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2890792Sgshapiro * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2990792Sgshapiro * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3090792Sgshapiro * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3190792Sgshapiro * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3290792Sgshapiro * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3390792Sgshapiro * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3490792Sgshapiro * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3590792Sgshapiro * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3690792Sgshapiro * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3790792Sgshapiro * SUCH DAMAGE.
3890792Sgshapiro *
3990792Sgshapiro *	@(#)kern_sysctl.c	8.4 (Berkeley) 4/14/94
4090792Sgshapiro * $Id: kern_mib.c,v 1.14 1998/03/04 10:25:50 dufault Exp $
4190792Sgshapiro */
4290792Sgshapiro
4390792Sgshapiro#include <sys/param.h>
4490792Sgshapiro#include <sys/kernel.h>
4590792Sgshapiro#include <sys/systm.h>
4690792Sgshapiro#include <sys/sysctl.h>
4790792Sgshapiro#include <sys/proc.h>
4890792Sgshapiro#include <sys/unistd.h>
4990792Sgshapiro
5090792Sgshapiro#include <machine/cpu.h>
5190792Sgshapiro#if defined(SMP)
5290792Sgshapiro#include <machine/smp.h>
5390792Sgshapiro#endif
5490792Sgshapiro
5590792SgshapiroSYSCTL_NODE(, 0,	  sysctl, CTLFLAG_RW, 0,
5690792Sgshapiro	"Sysctl internal magic");
5790792SgshapiroSYSCTL_NODE(, CTL_KERN,	  kern,   CTLFLAG_RW, 0,
5890792Sgshapiro	"High kernel, proc, limits &c");
5990792SgshapiroSYSCTL_NODE(, CTL_VM,	  vm,     CTLFLAG_RW, 0,
6090792Sgshapiro	"Virtual memory");
6190792SgshapiroSYSCTL_NODE(, CTL_VFS,	  vfs,     CTLFLAG_RW, 0,
6290792Sgshapiro	"File system");
6390792SgshapiroSYSCTL_NODE(, CTL_NET,	  net,    CTLFLAG_RW, 0,
6490792Sgshapiro	"Network, (see socket.h)");
6590792SgshapiroSYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
6690792Sgshapiro	"Debugging");
6790792SgshapiroSYSCTL_NODE(, CTL_HW,	  hw,     CTLFLAG_RW, 0,
6890792Sgshapiro	"hardware");
6990792SgshapiroSYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
7090792Sgshapiro	"machine dependent");
7190792SgshapiroSYSCTL_NODE(, CTL_USER,	  user,   CTLFLAG_RW, 0,
7290792Sgshapiro	"user-level");
7390792Sgshapiro
7490792SgshapiroSYSCTL_NODE(, CTL_P1003_1B,  p1003_1b,   CTLFLAG_RW, 0,
7590792Sgshapiro	"p1003_1b, (see p1003_1b.h)");
7690792Sgshapiro
7790792SgshapiroSYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD, osrelease, 0, "");
7890792Sgshapiro
7990792SgshapiroSYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD, 0, BSD, "");
8090792Sgshapiro
8190792SgshapiroSYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD, version, 0, "");
8290792Sgshapiro
8390792SgshapiroSYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD, ostype, 0, "");
8490792Sgshapiro
8590792Sgshapiroextern int osreldate;
8690792SgshapiroSYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD, &osreldate, 0, "");
8790792Sgshapiro
8890792SgshapiroSYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RD, &maxproc, 0, "");
8990792Sgshapiro
9090792SgshapiroSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid,
9190792Sgshapiro	CTLFLAG_RW, &maxprocperuid, 0, "");
9290792Sgshapiro
9390792SgshapiroSYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD, 0, ARG_MAX, "");
9490792Sgshapiro
9590792SgshapiroSYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD, 0, _KPOSIX_VERSION, "");
9690792Sgshapiro
9790792SgshapiroSYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD, 0, NGROUPS_MAX, "");
9890792Sgshapiro
9990792SgshapiroSYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD, 0, 1, "");
10090792Sgshapiro
10190792Sgshapiro#ifdef _POSIX_SAVED_IDS
10290792SgshapiroSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 1, "");
10390792Sgshapiro#else
10490792SgshapiroSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 0, "");
10590792Sgshapiro#endif
10690792Sgshapiro
10790792Sgshapirochar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
10890792Sgshapiro
10990792SgshapiroSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile,
11090792Sgshapiro	CTLFLAG_RW, kernelname, sizeof kernelname, "");
11190792Sgshapiro
11290792Sgshapiro#ifdef SMP
11390792SgshapiroSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, &mp_ncpus, 0, "");
11490792Sgshapiro#else
11590792SgshapiroSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, 0, 1, "");
11690792Sgshapiro#endif
11790792Sgshapiro
11890792SgshapiroSYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD, 0, BYTE_ORDER, "");
11990792Sgshapiro
12090792SgshapiroSYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD, 0, PAGE_SIZE, "");
12190792Sgshapiro
12290792Sgshapirostatic char	machine_arch[] = MACHINE_ARCH;
12390792SgshapiroSYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
12490792Sgshapiro			  machine_arch, 0, "");
12590792Sgshapiro
12690792Sgshapirochar hostname[MAXHOSTNAMELEN];
12790792Sgshapiro
12890792SgshapiroSYSCTL_STRING(_kern, KERN_HOSTNAME, hostname, CTLFLAG_RW,
12990792Sgshapiro	hostname, sizeof(hostname), "");
13090792Sgshapiro
13190792Sgshapiroint securelevel = -1;
13290792Sgshapiro
13390792Sgshapirostatic int
13490792Sgshapirosysctl_kern_securelvl SYSCTL_HANDLER_ARGS
13590792Sgshapiro{
13690792Sgshapiro		int error, level;
137112810Sgshapiro
13890792Sgshapiro		level = securelevel;
13990792Sgshapiro		error = sysctl_handle_int(oidp, &level, 0, req);
14090792Sgshapiro		if (error || !req->newptr)
141112810Sgshapiro			return (error);
14290792Sgshapiro		if (level < securelevel)
14390792Sgshapiro			return (EPERM);
14490792Sgshapiro		securelevel = level;
145		return (error);
146}
147
148SYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, CTLTYPE_INT|CTLFLAG_RW,
149	0, 0, sysctl_kern_securelvl, "I", "");
150
151char domainname[MAXHOSTNAMELEN];
152SYSCTL_STRING(_kern, KERN_NISDOMAINNAME, domainname, CTLFLAG_RW,
153	&domainname, sizeof(domainname), "");
154
155long hostid;
156/* Some trouble here, if sizeof (int) != sizeof (long) */
157SYSCTL_INT(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "");
158
159/*
160 * This is really cheating.  These actually live in the libc, something
161 * which I'm not quite sure is a good idea anyway, but in order for
162 * getnext and friends to actually work, we define dummies here.
163 */
164SYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD, "", 0, "");
165SYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD, 0, 0, "");
166SYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD, 0, 0, "");
167SYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD, 0, 0, "");
168SYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD, 0, 0, "");
169SYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD, 0, 0, "");
170SYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
171SYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD, 0, 0, "");
172SYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD, 0, 0, "");
173SYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD, 0, 0, "");
174SYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD, 0, 0, "");
175SYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD, 0, 0, "");
176SYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD, 0, 0, "");
177SYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD, 0, 0, "");
178SYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD, 0, 0, "");
179SYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD, 0, 0, "");
180SYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD, 0, 0, "");
181SYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD, 0, 0, "");
182SYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD, 0, 0, "");
183SYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD, 0, 0, "");
184