xref: /original-bsd/sys/sys/sysctl.h (revision 27393bdf)
1 /*
2  * Copyright (c) 1989, 1993
3  *	The Regents of the University of California.  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	8.2 (Berkeley) 03/30/95
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_VFS		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 	{ "vfs", 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_BOOTTIME		21	/* struct: time kernel was booted */
104 #define	KERN_MAXID		22	/* number of valid kern ids */
105 
106 #define CTL_KERN_NAMES { \
107 	{ 0, 0 }, \
108 	{ "ostype", CTLTYPE_STRING }, \
109 	{ "osrelease", CTLTYPE_STRING }, \
110 	{ "osrevision", CTLTYPE_INT }, \
111 	{ "version", CTLTYPE_STRING }, \
112 	{ "maxvnodes", CTLTYPE_INT }, \
113 	{ "maxproc", CTLTYPE_INT }, \
114 	{ "maxfiles", CTLTYPE_INT }, \
115 	{ "argmax", CTLTYPE_INT }, \
116 	{ "securelevel", CTLTYPE_INT }, \
117 	{ "hostname", CTLTYPE_STRING }, \
118 	{ "hostid", CTLTYPE_INT }, \
119 	{ "clockrate", CTLTYPE_STRUCT }, \
120 	{ "vnode", CTLTYPE_STRUCT }, \
121 	{ "proc", CTLTYPE_STRUCT }, \
122 	{ "file", CTLTYPE_STRUCT }, \
123 	{ "profiling", CTLTYPE_NODE }, \
124 	{ "posix1version", CTLTYPE_INT }, \
125 	{ "ngroups", CTLTYPE_INT }, \
126 	{ "job_control", CTLTYPE_INT }, \
127 	{ "saved_ids", CTLTYPE_INT }, \
128 	{ "boottime", CTLTYPE_STRUCT }, \
129 }
130 
131 /*
132  * KERN_PROC subtypes
133  */
134 #define KERN_PROC_ALL		0	/* everything */
135 #define	KERN_PROC_PID		1	/* by process id */
136 #define	KERN_PROC_PGRP		2	/* by process group id */
137 #define	KERN_PROC_SESSION	3	/* by session of pid */
138 #define	KERN_PROC_TTY		4	/* by controlling tty */
139 #define	KERN_PROC_UID		5	/* by effective uid */
140 #define	KERN_PROC_RUID		6	/* by real uid */
141 
142 /*
143  * KERN_PROC subtype ops return arrays of augmented proc structures:
144  */
145 struct kinfo_proc {
146 	struct	proc kp_proc;			/* proc structure */
147 	struct	eproc {
148 		struct	proc *e_paddr;		/* address of proc */
149 		struct	session *e_sess;	/* session pointer */
150 		struct	pcred e_pcred;		/* process credentials */
151 		struct	ucred e_ucred;		/* current credentials */
152 #ifdef sparc
153 		struct {
154 			segsz_t	vm_rssize;	/* resident set size */
155 			segsz_t	vm_tsize;	/* text size */
156 			segsz_t	vm_dsize;	/* data size */
157 			segsz_t	vm_ssize;	/* stack size */
158 		} e_vm;
159 #else
160 		struct	vmspace e_vm;		/* address space */
161 #endif
162 		pid_t	e_ppid;			/* parent process id */
163 		pid_t	e_pgid;			/* process group id */
164 		short	e_jobc;			/* job control counter */
165 		dev_t	e_tdev;			/* controlling tty dev */
166 		pid_t	e_tpgid;		/* tty process group id */
167 		struct	session *e_tsess;	/* tty session pointer */
168 #define	WMESGLEN	7
169 		char	e_wmesg[WMESGLEN+1];	/* wchan message */
170 		segsz_t e_xsize;		/* text size */
171 		short	e_xrssize;		/* text rss */
172 		short	e_xccount;		/* text references */
173 		short	e_xswrss;
174 		long	e_flag;
175 #define	EPROC_CTTY	0x01	/* controlling tty vnode active */
176 #define	EPROC_SLEADER	0x02	/* session leader */
177 		char	e_login[MAXLOGNAME];	/* setlogin() name */
178 		long	e_spare[4];
179 	} kp_eproc;
180 };
181 
182 /*
183  * CTL_HW identifiers
184  */
185 #define	HW_MACHINE	 1		/* string: machine class */
186 #define	HW_MODEL	 2		/* string: specific machine model */
187 #define	HW_NCPU		 3		/* int: number of cpus */
188 #define	HW_BYTEORDER	 4		/* int: machine byte order */
189 #define	HW_PHYSMEM	 5		/* int: total memory */
190 #define	HW_USERMEM	 6		/* int: non-kernel memory */
191 #define	HW_PAGESIZE	 7		/* int: software page size */
192 #define	HW_DISKNAMES	 8		/* strings: disk drive names */
193 #define	HW_DISKSTATS	 9		/* struct: diskstats[] */
194 #define	HW_MAXID	10		/* number of valid hw ids */
195 
196 #define CTL_HW_NAMES { \
197 	{ 0, 0 }, \
198 	{ "machine", CTLTYPE_STRING }, \
199 	{ "model", CTLTYPE_STRING }, \
200 	{ "ncpu", CTLTYPE_INT }, \
201 	{ "byteorder", CTLTYPE_INT }, \
202 	{ "physmem", CTLTYPE_INT }, \
203 	{ "usermem", CTLTYPE_INT }, \
204 	{ "pagesize", CTLTYPE_INT }, \
205 	{ "disknames", CTLTYPE_STRUCT }, \
206 	{ "diskstats", CTLTYPE_STRUCT }, \
207 }
208 
209 /*
210  * CTL_USER definitions
211  */
212 #define	USER_CS_PATH		 1	/* string: _CS_PATH */
213 #define	USER_BC_BASE_MAX	 2	/* int: BC_BASE_MAX */
214 #define	USER_BC_DIM_MAX		 3	/* int: BC_DIM_MAX */
215 #define	USER_BC_SCALE_MAX	 4	/* int: BC_SCALE_MAX */
216 #define	USER_BC_STRING_MAX	 5	/* int: BC_STRING_MAX */
217 #define	USER_COLL_WEIGHTS_MAX	 6	/* int: COLL_WEIGHTS_MAX */
218 #define	USER_EXPR_NEST_MAX	 7	/* int: EXPR_NEST_MAX */
219 #define	USER_LINE_MAX		 8	/* int: LINE_MAX */
220 #define	USER_RE_DUP_MAX		 9	/* int: RE_DUP_MAX */
221 #define	USER_POSIX2_VERSION	10	/* int: POSIX2_VERSION */
222 #define	USER_POSIX2_C_BIND	11	/* int: POSIX2_C_BIND */
223 #define	USER_POSIX2_C_DEV	12	/* int: POSIX2_C_DEV */
224 #define	USER_POSIX2_CHAR_TERM	13	/* int: POSIX2_CHAR_TERM */
225 #define	USER_POSIX2_FORT_DEV	14	/* int: POSIX2_FORT_DEV */
226 #define	USER_POSIX2_FORT_RUN	15	/* int: POSIX2_FORT_RUN */
227 #define	USER_POSIX2_LOCALEDEF	16	/* int: POSIX2_LOCALEDEF */
228 #define	USER_POSIX2_SW_DEV	17	/* int: POSIX2_SW_DEV */
229 #define	USER_POSIX2_UPE		18	/* int: POSIX2_UPE */
230 #define	USER_STREAM_MAX		19	/* int: POSIX2_STREAM_MAX */
231 #define	USER_TZNAME_MAX		20	/* int: POSIX2_TZNAME_MAX */
232 #define	USER_MAXID		21	/* number of valid user ids */
233 
234 #define	CTL_USER_NAMES { \
235 	{ 0, 0 }, \
236 	{ "cs_path", CTLTYPE_STRING }, \
237 	{ "bc_base_max", CTLTYPE_INT }, \
238 	{ "bc_dim_max", CTLTYPE_INT }, \
239 	{ "bc_scale_max", CTLTYPE_INT }, \
240 	{ "bc_string_max", CTLTYPE_INT }, \
241 	{ "coll_weights_max", CTLTYPE_INT }, \
242 	{ "expr_nest_max", CTLTYPE_INT }, \
243 	{ "line_max", CTLTYPE_INT }, \
244 	{ "re_dup_max", CTLTYPE_INT }, \
245 	{ "posix2_version", CTLTYPE_INT }, \
246 	{ "posix2_c_bind", CTLTYPE_INT }, \
247 	{ "posix2_c_dev", CTLTYPE_INT }, \
248 	{ "posix2_char_term", CTLTYPE_INT }, \
249 	{ "posix2_fort_dev", CTLTYPE_INT }, \
250 	{ "posix2_fort_run", CTLTYPE_INT }, \
251 	{ "posix2_localedef", CTLTYPE_INT }, \
252 	{ "posix2_sw_dev", CTLTYPE_INT }, \
253 	{ "posix2_upe", CTLTYPE_INT }, \
254 	{ "stream_max", CTLTYPE_INT }, \
255 	{ "tzname_max", CTLTYPE_INT }, \
256 }
257 
258 /*
259  * CTL_DEBUG definitions
260  *
261  * Second level identifier specifies which debug variable.
262  * Third level identifier specifies which stucture component.
263  */
264 #define	CTL_DEBUG_NAME		0	/* string: variable name */
265 #define	CTL_DEBUG_VALUE		1	/* int: variable value */
266 #define	CTL_DEBUG_MAXID		20
267 
268 #ifdef	KERNEL
269 #ifdef	DEBUG
270 /*
271  * CTL_DEBUG variables.
272  *
273  * These are declared as separate variables so that they can be
274  * individually initialized at the location of their associated
275  * variable. The loader prevents multiple use by issuing errors
276  * if a variable is initialized in more than one place. They are
277  * aggregated into an array in debug_sysctl(), so that it can
278  * conveniently locate them when querried. If more debugging
279  * variables are added, they must also be declared here and also
280  * entered into the array.
281  */
282 struct ctldebug {
283 	char	*debugname;	/* name of debugging variable */
284 	int	*debugvar;	/* pointer to debugging variable */
285 };
286 extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
287 extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
288 extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
289 extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
290 #endif	/* DEBUG */
291 
292 /*
293  * Internal sysctl function calling convention:
294  *
295  *	(*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen);
296  *
297  * The name parameter points at the next component of the name to be
298  * interpreted.  The namelen parameter is the number of integers in
299  * the name.
300  */
301 typedef int (sysctlfn)
302     __P((int *, u_int, void *, size_t *, void *, size_t, struct proc *));
303 
304 int sysctl_int __P((void *, size_t *, void *, size_t, int *));
305 int sysctl_rdint __P((void *, size_t *, void *, int));
306 int sysctl_string __P((void *, size_t *, void *, size_t, char *, int));
307 int sysctl_rdstring __P((void *, size_t *, void *, char *));
308 int sysctl_rdstruct __P((void *, size_t *, void *, void *, int));
309 void fill_eproc __P((struct proc *, struct eproc *));
310 
311 #else	/* !KERNEL */
312 #include <sys/cdefs.h>
313 
314 __BEGIN_DECLS
315 int	sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
316 __END_DECLS
317 #endif	/* KERNEL */
318 #endif	/* !_SYS_SYSCTL_H_ */
319