kern_mib.c revision 28885
115103Sphk/*-
215103Sphk * Copyright (c) 1982, 1986, 1989, 1993
315103Sphk *	The Regents of the University of California.  All rights reserved.
415103Sphk *
515103Sphk * This code is derived from software contributed to Berkeley by
615103Sphk * Mike Karels at Berkeley Software Design, Inc.
715103Sphk *
815103Sphk * Quite extensively rewritten by Poul-Henning Kamp of the FreeBSD
915103Sphk * project, to make these variables more userfriendly.
1015103Sphk *
1115103Sphk * Redistribution and use in source and binary forms, with or without
1215103Sphk * modification, are permitted provided that the following conditions
1315103Sphk * are met:
1415103Sphk * 1. Redistributions of source code must retain the above copyright
1515103Sphk *    notice, this list of conditions and the following disclaimer.
1615103Sphk * 2. Redistributions in binary form must reproduce the above copyright
1715103Sphk *    notice, this list of conditions and the following disclaimer in the
1815103Sphk *    documentation and/or other materials provided with the distribution.
1915103Sphk * 3. All advertising materials mentioning features or use of this software
2015103Sphk *    must display the following acknowledgement:
2115103Sphk *	This product includes software developed by the University of
2215103Sphk *	California, Berkeley and its contributors.
2315103Sphk * 4. Neither the name of the University nor the names of its contributors
2415103Sphk *    may be used to endorse or promote products derived from this software
2515103Sphk *    without specific prior written permission.
2615103Sphk *
2715103Sphk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2815103Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2915103Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
3015103Sphk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
3115103Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3215103Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3315103Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3415103Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3515103Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3615103Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3715103Sphk * SUCH DAMAGE.
3815103Sphk *
3915103Sphk *	@(#)kern_sysctl.c	8.4 (Berkeley) 4/14/94
4028885Skato * $Id: kern_mib.c,v 1.9 1997/06/25 07:31:47 joerg Exp $
4115103Sphk */
4215103Sphk
4315103Sphk#include <sys/param.h>
4415103Sphk#include <sys/kernel.h>
4515103Sphk#include <sys/systm.h>
4615103Sphk#include <sys/sysctl.h>
4715103Sphk#include <sys/proc.h>
4815103Sphk#include <sys/unistd.h>
4915103Sphk
5015103SphkSYSCTL_NODE(, 0,	  sysctl, CTLFLAG_RW, 0,
5115103Sphk	"Sysctl internal magic");
5215103SphkSYSCTL_NODE(, CTL_KERN,	  kern,   CTLFLAG_RW, 0,
5315103Sphk	"High kernel, proc, limits &c");
5415103SphkSYSCTL_NODE(, CTL_VM,	  vm,     CTLFLAG_RW, 0,
5515103Sphk	"Virtual memory");
5623382SbdeSYSCTL_NODE(, CTL_VFS,	  vfs,     CTLFLAG_RW, 0,
5715103Sphk	"File system");
5815103SphkSYSCTL_NODE(, CTL_NET,	  net,    CTLFLAG_RW, 0,
5915103Sphk	"Network, (see socket.h)");
6015103SphkSYSCTL_NODE(, CTL_DEBUG,  debug,  CTLFLAG_RW, 0,
6115103Sphk	"Debugging");
6215103SphkSYSCTL_NODE(, CTL_HW,	  hw,     CTLFLAG_RW, 0,
6315103Sphk	"hardware");
6415103SphkSYSCTL_NODE(, CTL_MACHDEP, machdep, CTLFLAG_RW, 0,
6515103Sphk	"machine dependent");
6615103SphkSYSCTL_NODE(, CTL_USER,	  user,   CTLFLAG_RW, 0,
6715103Sphk	"user-level");
6815103Sphk
6915103SphkSYSCTL_STRING(_kern, KERN_OSRELEASE, osrelease, CTLFLAG_RD, osrelease, 0, "");
7015103Sphk
7115103SphkSYSCTL_INT(_kern, KERN_OSREV, osrevision, CTLFLAG_RD, 0, BSD, "");
7215103Sphk
7315103SphkSYSCTL_STRING(_kern, KERN_VERSION, version, CTLFLAG_RD, version, 0, "");
7415103Sphk
7515103SphkSYSCTL_STRING(_kern, KERN_OSTYPE, ostype, CTLFLAG_RD, ostype, 0, "");
7615103Sphk
7715103Sphkextern int osreldate;
7815103SphkSYSCTL_INT(_kern, KERN_OSRELDATE, osreldate, CTLFLAG_RD, &osreldate, 0, "");
7915103Sphk
8018539SbdeSYSCTL_INT(_kern, KERN_MAXPROC, maxproc, CTLFLAG_RW, &maxproc, 0, "");
8115103Sphk
8215103SphkSYSCTL_INT(_kern, KERN_MAXPROCPERUID, maxprocperuid,
8318539Sbde	CTLFLAG_RW, &maxprocperuid, 0, "");
8415103Sphk
8515103SphkSYSCTL_INT(_kern, KERN_ARGMAX, argmax, CTLFLAG_RD, 0, ARG_MAX, "");
8615103Sphk
8715103SphkSYSCTL_INT(_kern, KERN_POSIX1, posix1version, CTLFLAG_RD, 0, _POSIX_VERSION, "");
8815103Sphk
8915103SphkSYSCTL_INT(_kern, KERN_NGROUPS, ngroups, CTLFLAG_RD, 0, NGROUPS_MAX, "");
9015103Sphk
9115103SphkSYSCTL_INT(_kern, KERN_JOB_CONTROL, job_control, CTLFLAG_RD, 0, 1, "");
9215103Sphk
9315103Sphk#ifdef _POSIX_SAVED_IDS
9415103SphkSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 1, "");
9515103Sphk#else
9615103SphkSYSCTL_INT(_kern, KERN_SAVED_IDS, saved_ids, CTLFLAG_RD, 0, 0, "");
9715103Sphk#endif
9815103Sphk
9915103Sphkchar kernelname[MAXPATHLEN] = "/kernel";	/* XXX bloat */
10015103Sphk
10115103SphkSYSCTL_STRING(_kern, KERN_BOOTFILE, bootfile,
10215103Sphk	CTLFLAG_RW, kernelname, sizeof kernelname, "");
10315103Sphk
10415103SphkSYSCTL_INT(_hw, HW_NCPU, ncpu, CTLFLAG_RD, 0, 1, "");
10515103Sphk
10615103SphkSYSCTL_INT(_hw, HW_BYTEORDER, byteorder, CTLFLAG_RD, 0, BYTE_ORDER, "");
10715103Sphk
10815103SphkSYSCTL_INT(_hw, HW_PAGESIZE, pagesize, CTLFLAG_RD, 0, PAGE_SIZE, "");
10915103Sphk
11028885Skatostatic char	machine_arch[] = MACHINE_ARCH;
11128885SkatoSYSCTL_STRING(_hw, HW_MACHINE_ARCH, machine_arch, CTLFLAG_RD,
11228885Skato			  machine_arch, 0, "");
11328885Skato
11415103Sphkchar hostname[MAXHOSTNAMELEN];
11515103Sphk
11615103SphkSYSCTL_STRING(_kern, KERN_HOSTNAME, hostname, CTLFLAG_RW,
11715103Sphk	hostname, sizeof(hostname), "");
11815103Sphk
11915103Sphkint securelevel = -1;
12015103Sphk
12115103Sphkstatic int
12215103Sphksysctl_kern_securelvl SYSCTL_HANDLER_ARGS
12315103Sphk{
12415103Sphk		int error, level;
12515103Sphk
12615103Sphk		level = securelevel;
12715103Sphk		error = sysctl_handle_int(oidp, &level, 0, req);
12815103Sphk		if (error || !req->newptr)
12915103Sphk			return (error);
13026923Sjoerg		if (level < securelevel)
13115103Sphk			return (EPERM);
13215103Sphk		securelevel = level;
13315103Sphk		return (error);
13415103Sphk}
13515103Sphk
13615103SphkSYSCTL_PROC(_kern, KERN_SECURELVL, securelevel, CTLTYPE_INT|CTLFLAG_RW,
13715103Sphk	0, 0, sysctl_kern_securelvl, "I", "");
13815103Sphk
13915103Sphkchar domainname[MAXHOSTNAMELEN];
14017281SwollmanSYSCTL_STRING(_kern, KERN_NISDOMAINNAME, domainname, CTLFLAG_RW,
14115103Sphk	&domainname, sizeof(domainname), "");
14215103Sphk
14315103Sphklong hostid;
14415103Sphk/* Some trouble here, if sizeof (int) != sizeof (long) */
14515103SphkSYSCTL_INT(_kern, KERN_HOSTID, hostid, CTLFLAG_RW, &hostid, 0, "");
14615103Sphk
14715103Sphk/*
14815103Sphk * This is really cheating.  These actually live in the libc, something
14915103Sphk * which I'm not quite sure is a good idea anyway, but in order for
15015103Sphk * getnext and friends to actually work, we define dummies here.
15115103Sphk */
15218540SbdeSYSCTL_STRING(_user, USER_CS_PATH, cs_path, CTLFLAG_RD, "", 0, "");
15318540SbdeSYSCTL_INT(_user, USER_BC_BASE_MAX, bc_base_max, CTLFLAG_RD, 0, 0, "");
15418540SbdeSYSCTL_INT(_user, USER_BC_DIM_MAX, bc_dim_max, CTLFLAG_RD, 0, 0, "");
15518540SbdeSYSCTL_INT(_user, USER_BC_SCALE_MAX, bc_scale_max, CTLFLAG_RD, 0, 0, "");
15618540SbdeSYSCTL_INT(_user, USER_BC_STRING_MAX, bc_string_max, CTLFLAG_RD, 0, 0, "");
15718540SbdeSYSCTL_INT(_user, USER_COLL_WEIGHTS_MAX, coll_weights_max, CTLFLAG_RD, 0, 0, "");
15818540SbdeSYSCTL_INT(_user, USER_EXPR_NEST_MAX, expr_nest_max, CTLFLAG_RD, 0, 0, "");
15918540SbdeSYSCTL_INT(_user, USER_LINE_MAX, line_max, CTLFLAG_RD, 0, 0, "");
16018540SbdeSYSCTL_INT(_user, USER_RE_DUP_MAX, re_dup_max, CTLFLAG_RD, 0, 0, "");
16118540SbdeSYSCTL_INT(_user, USER_POSIX2_VERSION, posix2_version, CTLFLAG_RD, 0, 0, "");
16218540SbdeSYSCTL_INT(_user, USER_POSIX2_C_BIND, posix2_c_bind, CTLFLAG_RD, 0, 0, "");
16318540SbdeSYSCTL_INT(_user, USER_POSIX2_C_DEV, posix2_c_dev, CTLFLAG_RD, 0, 0, "");
16418540SbdeSYSCTL_INT(_user, USER_POSIX2_CHAR_TERM, posix2_char_term, CTLFLAG_RD, 0, 0, "");
16518540SbdeSYSCTL_INT(_user, USER_POSIX2_FORT_DEV, posix2_fort_dev, CTLFLAG_RD, 0, 0, "");
16618540SbdeSYSCTL_INT(_user, USER_POSIX2_FORT_RUN, posix2_fort_run, CTLFLAG_RD, 0, 0, "");
16718540SbdeSYSCTL_INT(_user, USER_POSIX2_LOCALEDEF, posix2_localedef, CTLFLAG_RD, 0, 0, "");
16818540SbdeSYSCTL_INT(_user, USER_POSIX2_SW_DEV, posix2_sw_dev, CTLFLAG_RD, 0, 0, "");
16918540SbdeSYSCTL_INT(_user, USER_POSIX2_UPE, posix2_upe, CTLFLAG_RD, 0, 0, "");
17018540SbdeSYSCTL_INT(_user, USER_STREAM_MAX, stream_max, CTLFLAG_RD, 0, 0, "");
17118540SbdeSYSCTL_INT(_user, USER_TZNAME_MAX, tzname_max, CTLFLAG_RD, 0, 0, "");
172