xref: /original-bsd/sys/sys/sysctl.h (revision cb36a3b0)
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.23 (Berkeley) 05/01/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_MAXID	8		/* number of valid top-level ids */
66 
67 #define CTL_NAMES { \
68 	{ 0, 0 }, \
69 	{ "kern", CTLTYPE_NODE }, \
70 	{ "vm", CTLTYPE_NODE }, \
71 	{ "fs", CTLTYPE_NODE }, \
72 	{ "net", CTLTYPE_NODE }, \
73 	{ "debug", CTLTYPE_NODE }, \
74 	{ "hw", CTLTYPE_NODE }, \
75 	{ "machdep", CTLTYPE_NODE }, \
76 }
77 
78 /*
79  * CTL_KERN identifiers
80  */
81 #define	KERN_OSTYPE	 1		/* string: system version */
82 #define	KERN_OSRELEASE	 2		/* string: system release */
83 #define	KERN_OSREV	 3		/* int: system revision */
84 #define	KERN_VERSION	 4		/* string: compile time info */
85 #define	KERN_MAXVNODES	 5		/* int: max vnodes */
86 #define	KERN_MAXPROC	 6		/* int: max simultaneous processes */
87 #define	KERN_MAXFILES	 7		/* int: max open files */
88 #define	KERN_ARGMAX	 8		/* int: max arguments to exec */
89 #define	KERN_SECURELVL	 9		/* int: system security level */
90 #define	KERN_HOSTNAME	10		/* string: hostname */
91 #define	KERN_HOSTID	11		/* int: host identifier */
92 #define	KERN_CLOCKRATE	12		/* struct: struct clockrate */
93 #define	KERN_VNODE	13		/* struct: vnode structures */
94 #define	KERN_PROC	14		/* struct: process entries */
95 #define	KERN_FILE	15		/* struct: file entries */
96 #define	KERN_PROF	16		/* node: kernel profiling info */
97 #define	KERN_POSIX1	17		/* int: POSIX.1 version */
98 #define	KERN_MAXID	18		/* number of valid kern ids */
99 
100 #define CTL_KERN_NAMES { \
101 	{ 0, 0 }, \
102 	{ "ostype", CTLTYPE_STRING }, \
103 	{ "osrelease", CTLTYPE_STRING }, \
104 	{ "osrevision", CTLTYPE_INT }, \
105 	{ "version", CTLTYPE_STRING }, \
106 	{ "maxvnodes", CTLTYPE_INT }, \
107 	{ "maxproc", CTLTYPE_INT }, \
108 	{ "maxfiles", CTLTYPE_INT }, \
109 	{ "argmax", CTLTYPE_INT }, \
110 	{ "securelevel", CTLTYPE_INT }, \
111 	{ "hostname", CTLTYPE_STRING }, \
112 	{ "hostid", CTLTYPE_INT }, \
113 	{ "clockrate", CTLTYPE_STRUCT }, \
114 	{ "vnode", CTLTYPE_STRUCT }, \
115 	{ "proc", CTLTYPE_STRUCT }, \
116 	{ "file", CTLTYPE_STRUCT }, \
117 	{ "profiling", CTLTYPE_NODE }, \
118 	{ "posix1version", CTLTYPE_INT }, \
119 }
120 
121 /*
122  * KERN_PROC subtypes
123  */
124 #define KERN_PROC_ALL		0	/* everything */
125 #define	KERN_PROC_PID		1	/* by process id */
126 #define	KERN_PROC_PGRP		2	/* by process group id */
127 #define	KERN_PROC_SESSION	3	/* by session of pid */
128 #define	KERN_PROC_TTY		4	/* by controlling tty */
129 #define	KERN_PROC_UID		5	/* by effective uid */
130 #define	KERN_PROC_RUID		6	/* by real uid */
131 
132 /*
133  * KERN_PROC subtype ops return arrays of augmented proc structures:
134  */
135 struct kinfo_proc {
136 	struct	proc kp_proc;			/* proc structure */
137 	struct	eproc {
138 		struct	proc *e_paddr;		/* address of proc */
139 		struct	session *e_sess;	/* session pointer */
140 		struct	pcred e_pcred;		/* process credentials */
141 		struct	ucred e_ucred;		/* current credentials */
142 #ifdef sparc
143 		struct {
144 			segsz_t	vm_rssize;	/* resident set size */
145 			segsz_t	vm_tsize;	/* text size */
146 			segsz_t	vm_dsize;	/* data size */
147 			segsz_t	vm_ssize;	/* stack size */
148 		} e_vm;
149 #else
150 		struct	vmspace e_vm;		/* address space */
151 #endif
152 		pid_t	e_ppid;			/* parent process id */
153 		pid_t	e_pgid;			/* process group id */
154 		short	e_jobc;			/* job control counter */
155 		dev_t	e_tdev;			/* controlling tty dev */
156 		pid_t	e_tpgid;		/* tty process group id */
157 		struct	session *e_tsess;	/* tty session pointer */
158 #define	WMESGLEN	7
159 		char	e_wmesg[WMESGLEN+1];	/* wchan message */
160 		segsz_t e_xsize;		/* text size */
161 		short	e_xrssize;		/* text rss */
162 		short	e_xccount;		/* text references */
163 		short	e_xswrss;
164 		long	e_flag;
165 #define	EPROC_CTTY	0x01	/* controlling tty vnode active */
166 #define	EPROC_SLEADER	0x02	/* session leader */
167 		char	e_login[MAXLOGNAME];	/* setlogin() name */
168 		long	e_spare[4];
169 	} kp_eproc;
170 };
171 
172 /*
173  * CTL_HW identifiers
174  */
175 #define	HW_MACHINE	 1		/* string: machine class */
176 #define	HW_MODEL	 2		/* string: specific machine model */
177 #define	HW_NCPU		 3		/* int: number of cpus */
178 #define	HW_BYTEORDER	 4		/* int: machine byte order */
179 #define	HW_PHYSMEM	 5		/* int: total memory */
180 #define	HW_USERMEM	 6		/* int: non-kernel memory */
181 #define	HW_PAGESIZE	 7		/* int: software page size */
182 #define	HW_DISKNAMES	 8		/* strings: disk drive names */
183 #define	HW_DISKSTATS	 9		/* struct: diskstats[] */
184 #define	HW_MAXID	10		/* number of valid hw ids */
185 
186 #define CTL_HW_NAMES { \
187 	{ 0, 0 }, \
188 	{ "machine", CTLTYPE_STRING }, \
189 	{ "model", CTLTYPE_STRING }, \
190 	{ "ncpu", CTLTYPE_INT }, \
191 	{ "byteorder", CTLTYPE_INT }, \
192 	{ "physmem", CTLTYPE_INT }, \
193 	{ "usermem", CTLTYPE_INT }, \
194 	{ "pagesize", CTLTYPE_INT }, \
195 	{ "disknames", CTLTYPE_STRUCT }, \
196 	{ "diskstats", CTLTYPE_STRUCT }, \
197 }
198 
199 /*
200  * CTL_DEBUG definitions
201  *
202  * Second level identifier specifies which debug variable.
203  * Third level identifier specifies which stucture component.
204  */
205 #define	CTL_DEBUG_NAME		0	/* string: variable name */
206 #define	CTL_DEBUG_VALUE		1	/* int: variable value */
207 #define	CTL_DEBUG_MAXID		20
208 
209 #ifdef	KERNEL
210 #ifdef	DEBUG
211 /*
212  * CTL_DEBUG variables.
213  *
214  * These are declared as separate variables so that they can be
215  * individually initialized at the location of their associated
216  * variable. The loader prevents multiple use by issuing errors
217  * if a variable is initialized in more than one place. They are
218  * aggregated into an array in debug_sysctl(), so that it can
219  * conveniently locate them when querried. If more debugging
220  * variables are added, they must also be declared here and also
221  * entered into the array.
222  */
223 struct ctldebug {
224 	char	*debugname;	/* name of debugging variable */
225 	int	*debugvar;	/* pointer to debugging variable */
226 };
227 extern struct ctldebug debug0, debug1, debug2, debug3, debug4;
228 extern struct ctldebug debug5, debug6, debug7, debug8, debug9;
229 extern struct ctldebug debug10, debug11, debug12, debug13, debug14;
230 extern struct ctldebug debug15, debug16, debug17, debug18, debug19;
231 #endif	/* DEBUG */
232 
233 /*
234  * Internal sysctl function calling convention:
235  *
236  *	(*sysctlfn)(name, namelen, oldval, oldlenp, newval, newlen);
237  *
238  * The name parameter points at the next component of the name to be
239  * interpreted.  The namelen parameter is the number of integers in
240  * the name.
241  */
242 typedef int (sysctlfn)
243     __P((int *, u_int, void *, size_t *, void *, size_t, struct proc *));
244 
245 int sysctl_int __P((void *, size_t *, void *, size_t, int *));
246 int sysctl_rdint __P((void *, size_t *, void *, int));
247 int sysctl_string __P((void *, size_t *, void *, size_t, char *, int));
248 int sysctl_rdstring __P((void *, size_t *, void *, char *));
249 int sysctl_rdstruct __P((void *, size_t *, void *, void *, int));
250 void fill_eproc __P((struct proc *, struct eproc *));
251 
252 #else	/* !KERNEL */
253 #include <sys/cdefs.h>
254 
255 __BEGIN_DECLS
256 int	sysctl __P((int *, u_int, void *, size_t *, void *, size_t));
257 __END_DECLS
258 #endif	/* KERNEL */
259 #endif	/* !_SYS_SYSCTL_H_ */
260