xref: /original-bsd/sys/sys/sysctl.h (revision b43cd7f2)
1 /*
2  * Copyright (c) 1989, 1993 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Mike Karels at Berkeley Software Design, Inc.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)sysctl.h	7.26 (Berkeley) 05/23/93
11  */
12 
13 #ifndef _SYS_SYSCTL_H_
14 #define	_SYS_SYSCTL_H_
15 
16 /*
17  * These are for the eproc structure defined below.
18  */
19 #ifndef KERNEL
20 #include <sys/time.h>
21 #include <sys/ucred.h>
22 #include <sys/proc.h>
23 #include <vm/vm.h>
24 #endif
25 
26 /*
27  * Definitions for sysctl call.  The sysctl call uses a hierarchical name
28  * for objects that can be examined or modified.  The name is expressed as
29  * a sequence of integers.  Like a file path name, the meaning of each
30  * component depends on its place in the hierarchy.  The top-level and kern
31  * identifiers are defined here, and other identifiers are defined in the
32  * respective subsystem header files.
33  */
34 
35 #define CTL_MAXNAME	12	/* largest number of components supported */
36 
37 /*
38  * Each subsystem defined by sysctl defines a list of variables
39  * for that subsystem. Each name is either a node with further
40  * levels defined below it, or it is a leaf of some particular
41  * type given below. Each sysctl level defines a set of name/type
42  * pairs to be used by sysctl(1) in manipulating the subsystem.
43  */
44 struct ctlname {
45 	char	*ctl_name;	/* subsystem name */
46 	int	ctl_type;	/* type of name */
47 };
48 #define	CTLTYPE_NODE	1	/* name is a node */
49 #define	CTLTYPE_INT	2	/* name describes an integer */
50 #define	CTLTYPE_STRING	3	/* name describes a string */
51 #define	CTLTYPE_QUAD	4	/* name describes a 64-bit number */
52 #define	CTLTYPE_STRUCT	5	/* name describes a structure */
53 
54 /*
55  * Top-level identifiers
56  */
57 #define	CTL_UNSPEC	0		/* unused */
58 #define	CTL_KERN	1		/* "high kernel": proc, limits */
59 #define	CTL_VM		2		/* virtual memory */
60 #define	CTL_FS		3		/* file system, mount type is next */
61 #define	CTL_NET		4		/* network, see socket.h */
62 #define	CTL_DEBUG	5		/* debugging parameters */
63 #define	CTL_HW		6		/* generic cpu/io */
64 #define	CTL_MACHDEP	7		/* machine dependent */
65 #define	CTL_USER	8		/* user-level */
66 #define	CTL_MAXID	9		/* number of valid top-level ids */
67 
68 #define CTL_NAMES { \
69 	{ 0, 0 }, \
70 	{ "kern", CTLTYPE_NODE }, \
71 	{ "vm", CTLTYPE_NODE }, \
72 	{ "fs", CTLTYPE_NODE }, \
73 	{ "net", CTLTYPE_NODE }, \
74 	{ "debug", CTLTYPE_NODE }, \
75 	{ "hw", CTLTYPE_NODE }, \
76 	{ "machdep", CTLTYPE_NODE }, \
77 	{ "user", CTLTYPE_NODE }, \
78 }
79 
80 /*
81  * CTL_KERN identifiers
82  */
83 #define	KERN_OSTYPE	 	 1	/* string: system version */
84 #define	KERN_OSRELEASE	 	 2	/* string: system release */
85 #define	KERN_OSREV	 	 3	/* int: system revision */
86 #define	KERN_VERSION	 	 4	/* string: compile time info */
87 #define	KERN_MAXVNODES	 	 5	/* int: max vnodes */
88 #define	KERN_MAXPROC	 	 6	/* int: max processes */
89 #define	KERN_MAXFILES	 	 7	/* int: max open files */
90 #define	KERN_ARGMAX	 	 8	/* int: max arguments to exec */
91 #define	KERN_SECURELVL	 	 9	/* int: system security level */
92 #define	KERN_HOSTNAME		10	/* string: hostname */
93 #define	KERN_HOSTID		11	/* int: host identifier */
94 #define	KERN_CLOCKRATE		12	/* struct: struct clockrate */
95 #define	KERN_VNODE		13	/* struct: vnode structures */
96 #define	KERN_PROC		14	/* struct: process entries */
97 #define	KERN_FILE		15	/* struct: file entries */
98 #define	KERN_PROF		16	/* node: kernel profiling info */
99 #define	KERN_POSIX1		17	/* int: POSIX.1 version */
100 #define	KERN_NGROUPS		18	/* int: # of supplemental group ids */
101 #define	KERN_JOB_CONTROL	19	/* int: is job control available */
102 #define	KERN_SAVED_IDS		20	/* int: saved set-user/group-ID */
103 #define	KERN_LINK_MAX		21	/* int: max file link count */
104 #define	KERN_MAX_CANON		22	/* int: max bytes in term canon input */
105 #define	KERN_MAX_INPUT		23	/* int: max bytes in term input */
106 #define	KERN_NAME_MAX		24	/* int: max bytes in file name */
107 #define	KERN_PATH_MAX		25	/* int: max bytes in pathname */
108 #define	KERN_PIPE_BUF		26	/* int: max bytes for atomic pipe  */
109 #define	KERN_CHOWN_RESTRICTED	27	/* int: chown requires privilege */
110 #define	KERN_NO_TRUNC		28	/* int: no path truncation */
111 #define	KERN_VDISABLE		29	/* int: terminal character disable */
112 #define	KERN_BOOTTIME		30	/* struct: time kernel was booted */
113 #define	KERN_MAXUPROC	 	31	/* int: max processes per uid */
114 #define	KERN_MAXUFILES	 	32	/* int: max open files per uid */
115 #define	KERN_MAXID		33	/* number of valid kern ids */
116 
117 #define CTL_KERN_NAMES { \
118 	{ 0, 0 }, \
119 	{ "ostype", CTLTYPE_STRING }, \
120 	{ "osrelease", CTLTYPE_STRING }, \
121 	{ "osrevision", CTLTYPE_INT }, \
122 	{ "version", CTLTYPE_STRING }, \
123 	{ "maxvnodes", CTLTYPE_INT }, \
124 	{ "maxproc", CTLTYPE_INT }, \
125 	{ "maxfiles", CTLTYPE_INT }, \
126 	{ "argmax", CTLTYPE_INT }, \
127 	{ "securelevel", CTLTYPE_INT }, \
128 	{ "hostname", CTLTYPE_STRING }, \
129 	{ "hostid", CTLTYPE_INT }, \
130 	{ "clockrate", CTLTYPE_STRUCT }, \
131 	{ "vnode", CTLTYPE_STRUCT }, \
132 	{ "proc", CTLTYPE_STRUCT }, \
133 	{ "file", CTLTYPE_STRUCT }, \
134 	{ "profiling", CTLTYPE_NODE }, \
135 	{ "posix1version", CTLTYPE_INT }, \
136 	{ "ngroups", CTLTYPE_INT }, \
137 	{ "job_control", CTLTYPE_INT }, \
138 	{ "saved_ids", CTLTYPE_INT }, \
139 	{ "link_max", CTLTYPE_INT }, \
140 	{ "max_canon", CTLTYPE_INT }, \
141 	{ "max_input", CTLTYPE_INT }, \
142 	{ "name_max", CTLTYPE_INT }, \
143 	{ "path_max", CTLTYPE_INT }, \
144 	{ "pipe_buf", CTLTYPE_INT }, \
145 	{ "chown_restricted", CTLTYPE_INT }, \
146 	{ "no_trunc", CTLTYPE_INT }, \
147 	{ "vdisable", CTLTYPE_INT }, \
148 	{ "boottime", CTLTYPE_STRUCT }, \
149 	{ "maxuproc", CTLTYPE_INT }, \
150 	{ "maxufiles", CTLTYPE_INT }, \
151 }
152 
153 /*
154  * KERN_PROC subtypes
155  */
156 #define KERN_PROC_ALL		0	/* everything */
157 #define	KERN_PROC_PID		1	/* by process id */
158 #define	KERN_PROC_PGRP		2	/* by process group id */
159 #define	KERN_PROC_SESSION	3	/* by session of pid */
160 #define	KERN_PROC_TTY		4	/* by controlling tty */
161 #define	KERN_PROC_UID		5	/* by effective uid */
162 #define	KERN_PROC_RUID		6	/* by real uid */
163 
164 /*
165  * KERN_PROC subtype ops return arrays of augmented proc structures:
166  */
167 struct kinfo_proc {
168 	struct	proc kp_proc;			/* proc structure */
169 	struct	eproc {
170 		struct	proc *e_paddr;		/* address of proc */
171 		struct	session *e_sess;	/* session pointer */
172 		struct	pcred e_pcred;		/* process credentials */
173 		struct	ucred e_ucred;		/* current credentials */
174 #ifdef sparc
175 		struct {
176 			segsz_t	vm_rssize;	/* resident set size */
177 			segsz_t	vm_tsize;	/* text size */
178 			segsz_t	vm_dsize;	/* data size */
179 			segsz_t	vm_ssize;	/* stack size */
180 		} e_vm;
181 #else
182 		struct	vmspace e_vm;		/* address space */
183 #endif
184 		pid_t	e_ppid;			/* parent process id */
185 		pid_t	e_pgid;			/* process group id */
186 		short	e_jobc;			/* job control counter */
187 		dev_t	e_tdev;			/* controlling tty dev */
188 		pid_t	e_tpgid;		/* tty process group id */
189 		struct	session *e_tsess;	/* tty session pointer */
190 #define	WMESGLEN	7
191 		char	e_wmesg[WMESGLEN+1];	/* wchan message */
192 		segsz_t e_xsize;		/* text size */
193 		short	e_xrssize;		/* text rss */
194 		short	e_xccount;		/* text references */
195 		short	e_xswrss;
196 		long	e_flag;
197 #define	EPROC_CTTY	0x01	/* controlling tty vnode active */
198 #define	EPROC_SLEADER	0x02	/* session leader */
199 		char	e_login[MAXLOGNAME];	/* setlogin() name */
200 		long	e_spare[4];
201 	} kp_eproc;
202 };
203 
204 /*
205  * CTL_HW identifiers
206  */
207 #define	HW_MACHINE	 1		/* string: machine class */
208 #define	HW_MODEL	 2		/* string: specific machine model */
209 #define	HW_NCPU		 3		/* int: number of cpus */
210 #define	HW_BYTEORDER	 4		/* int: machine byte order */
211 #define	HW_PHYSMEM	 5		/* int: total memory */
212 #define	HW_USERMEM	 6		/* int: non-kernel memory */
213 #define	HW_PAGESIZE	 7		/* int: software page size */
214 #define	HW_DISKNAMES	 8		/* strings: disk drive names */
215 #define	HW_DISKSTATS	 9		/* struct: diskstats[] */
216 #define	HW_MAXID	10		/* number of valid hw ids */
217 
218 #define CTL_HW_NAMES { \
219 	{ 0, 0 }, \
220 	{ "machine", CTLTYPE_STRING }, \
221 	{ "model", CTLTYPE_STRING }, \
222 	{ "ncpu", CTLTYPE_INT }, \
223 	{ "byteorder", CTLTYPE_INT }, \
224 	{ "physmem", CTLTYPE_INT }, \
225 	{ "usermem", CTLTYPE_INT }, \
226 	{ "pagesize", CTLTYPE_INT }, \
227 	{ "disknames", CTLTYPE_STRUCT }, \
228 	{ "diskstats", CTLTYPE_STRUCT }, \
229 }
230 
231 /*
232  * CTL_USER definitions
233  */
234 #define	USER_CS_PATH		 1	/* string: _CS_PATH */
235 #define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
236 #define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
237 #define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
238 #define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
239 #define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
240 #define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
241 #define	USER_LINE_MAX		 8	/* int: LINE_MAX */
242 #define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
243 #define	USER_POSIX2_VERSION	10	/* int: POSIX2_VERSION */
244 #define	USER_POSIX2_C_BIND	11	/* int: POSIX2_C_BIND */
245 #define	USER_POSIX2_C_DEV	12	/* int: POSIX2_C_DEV */
246 #define	USER_POSIX2_CHAR_TERM	13	/* int: POSIX2_CHAR_TERM */
247 #define	USER_POSIX2_FORT_DEV	14	/* int: POSIX2_FORT_DEV */
248 #define	USER_POSIX2_FORT_RUN	15	/* int: POSIX2_FORT_RUN */
249 #define	USER_POSIX2_LOCALEDEF	16	/* int: POSIX2_LOCALEDEF */
250 #define	USER_POSIX2_SW_DEV	17	/* int: POSIX2_SW_DEV */
251 #define	USER_POSIX2_UPE		18	/* int: POSIX2_UPE */
252 #define	USER_STREAM_MAX		19	/* int: POSIX2_STREAM_MAX */
253 #define	USER_TZNAME_MAX		20	/* int: POSIX2_TZNAME_MAX */
254 #define	USER_MAXID		21	/* number of valid user ids */
255 
256 #define	CTL_USER_NAMES { \
257 	{ 0, 0 }, \
258 	{ "cs_path", CTLTYPE_STRING }, \
259 	{ "bc_base_max", CTLTYPE_INT }, \
260 	{ "bc_dim_max", CTLTYPE_INT }, \
261 	{ "bc_scale_max", CTLTYPE_INT }, \
262 	{ "bc_string_max", CTLTYPE_INT }, \
263 	{ "coll_weights_max", CTLTYPE_INT }, \
264 	{ "expr_nest_max", CTLTYPE_INT }, \
265 	{ "line_max", CTLTYPE_INT }, \
266 	{ "re_dup_max", CTLTYPE_INT }, \
267 	{ "posix2_version", CTLTYPE_INT }, \
268 	{ "posix2_c_bind", CTLTYPE_INT }, \
269 	{ "posix2_c_dev", CTLTYPE_INT }, \
270 	{ "posix2_char_term", CTLTYPE_INT }, \
271 	{ "posix2_fort_dev", CTLTYPE_INT }, \
272 	{ "posix2_fort_run", CTLTYPE_INT }, \
273 	{ "posix2_localedef", CTLTYPE_INT }, \
274 	{ "posix2_sw_dev", CTLTYPE_INT }, \
275 	{ "posix2_upe", CTLTYPE_INT }, \
276 	{ "stream_max", CTLTYPE_INT }, \
277 	{ "tzname_max", CTLTYPE_INT }, \
278 }
279 
280 /*
281  * CTL_DEBUG definitions
282  *
283  * Second level identifier specifies which debug variable.
284  * Third level identifier specifies which stucture component.
285  */
286 #define	CTL_DEBUG_NAME		0	/* string: variable name */
287 #define	CTL_DEBUG_VALUE		1	/* int: variable value */
288 #define	CTL_DEBUG_MAXID		20
289 
290 #ifdef	KERNEL
291 #ifdef	DEBUG
292 /*
293  * CTL_DEBUG variables.
294  *
295  * These are declared as separate variables so that they can be
296  * individually initialized at the location of their associated
297  * variable. The loader prevents multiple use by issuing errors
298  * if a variable is initialized in more than one place. They are
299  * aggregated into an array in debug_sysctl(), so that it can
300  * conveniently locate them when querried. If more debugging
301  * variables are added, they must also be declared here and also
302  * entered into the array.
303  */
304 struct ctldebug {
305 	char	*debugname;	/* name of debugging variable */
306 	int	*debugvar;	/* pointer to debugging variable */
307 };
308 extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
309 extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
310 extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
311 extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
312 #endif	/* DEBUG */
313 
314 /*
315  * Internal sysctl function calling convention:
316  *
317  *	(*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen);
318  *
319  * The name parameter points at the next component of the name to be
320  * interpreted.  The namelen parameter is the number of integers in
321  * the name.
322  */
323 typedef int (sysctlfn)
324     __P((int *, u_int, void *, size_t *, void *, size_t, struct proc *));
325 
326 int sysctl_int __P((void *, size_t *, void *, size_t, int *));
327 int sysctl_rdint __P((void *, size_t *, void *, int));
328 int sysctl_string __P((void *, size_t *, void *, size_t, char *, int));
329 int sysctl_rdstring __P((void *, size_t *, void *, char *));
330 int sysctl_rdstruct __P((void *, size_t *, void *, void *, int));
331 void fill_eproc __P((struct proc *, struct eproc *));
332 
333 #else	/* !KERNEL */
334 #include <sys/cdefs.h>
335 
336 __BEGIN_DECLS
337 int	sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
338 __END_DECLS
339 #endif	/* KERNEL */
340 #endif	/* !_SYS_SYSCTL_H_ */
341