1 /*
2 * sysctl.h: General linux system control interface
3 *
4 * Begun 24 March 1995, Stephen Tweedie
5 */
6
7 #include <linux/lists.h>
8
9 #ifndef _LINUX_SYSCTL_H
10 #define _LINUX_SYSCTL_H
11
12 #define CTL_MAXNAME 10
13
14 struct __sysctl_args {
15 int *name;
16 int nlen;
17 void *oldval;
18 size_t *oldlenp;
19 void *newval;
20 size_t newlen;
21 unsigned long __unused[4];
22 };
23
24 /* Define sysctl names first */
25
26 /* Top-level names: */
27
28 /* For internal pattern-matching use only: */
29 #ifdef __KERNEL__
30 #define CTL_ANY -1 /* Matches any name */
31 #define CTL_NONE 0
32 #endif
33
34 #define CTL_KERN 1 /* General kernel info and control */
35 #define CTL_VM 2 /* VM management */
36 #define CTL_NET 3 /* Networking */
37 #define CTL_PROC 4 /* Process info */
38 #define CTL_FS 5 /* Filesystems */
39 #define CTL_DEBUG 6 /* Debugging */
40 #define CTL_DEV 7 /* Devices */
41 #define CTL_MAXID 8
42
43 /* CTL_KERN names: */
44 #define KERN_OSTYPE 1 /* string: system version */
45 #define KERN_OSRELEASE 2 /* string: system release */
46 #define KERN_OSREV 3 /* int: system revision */
47 #define KERN_VERSION 4 /* string: compile time info */
48 #define KERN_SECUREMASK 5 /* struct: maximum rights mask */
49 #define KERN_PROF 6 /* table: profiling information */
50 #define KERN_NODENAME 7
51 #define KERN_DOMAINNAME 8
52 #define KERN_NRINODE 9
53 #define KERN_MAXINODE 10
54 #define KERN_NRFILE 11
55 #define KERN_MAXFILE 12
56 #define KERN_MAXID 13
57 #define KERN_SECURELVL 14 /* int: system security level */
58
59 /* CTL_VM names: */
60 #define VM_SWAPCTL 1 /* struct: Set vm swapping control */
61 #define VM_KSWAPD 2 /* struct: control background pagout */
62 #define VM_FREEPG 3 /* struct: Set free page thresholds */
63 #define VM_MAXID 4
64
65 /* CTL_NET names: */
66
67 /* CTL_PROC names: */
68
69 /* CTL_FS names: */
70
71 /* CTL_DEBUG names: */
72
73 /* CTL_DEV names: */
74
75 #ifdef __KERNEL__
76
77 extern asmlinkage int sys_sysctl(struct __sysctl_args *);
78 extern void init_sysctl(void);
79
80 typedef struct ctl_table ctl_table;
81
82 typedef int ctl_handler (ctl_table *table, int *name, int nlen,
83 void *oldval, size_t *oldlenp,
84 void *newval, size_t newlen,
85 void **context);
86
87 typedef int proc_handler (ctl_table *ctl, int write, struct file * filp,
88 void *buffer, size_t *lenp);
89
90 extern int proc_dostring(ctl_table *, int, struct file *,
91 void *, size_t *);
92 extern int proc_dointvec(ctl_table *, int, struct file *,
93 void *, size_t *);
94
95 extern int do_sysctl (int *name, int nlen,
96 void *oldval, size_t *oldlenp,
97 void *newval, size_t newlen);
98
99 extern int do_sysctl_strategy (ctl_table *table,
100 int *name, int nlen,
101 void *oldval, size_t *oldlenp,
102 void *newval, size_t newlen, void ** context);
103
104 extern ctl_handler sysctl_string;
105
106 extern int do_string (
107 void *oldval, size_t *oldlenp, void *newval, size_t newlen,
108 int rdwr, char *data, size_t max);
109 extern int do_int (
110 void *oldval, size_t *oldlenp, void *newval, size_t newlen,
111 int rdwr, int *data);
112 extern int do_struct (
113 void *oldval, size_t *oldlenp, void *newval, size_t newlen,
114 int rdwr, void *data, size_t len);
115
116
117 /*
118 * Register a set of sysctl names by calling register_sysctl_table
119 * with an initialised array of ctl_table's. An entry with zero
120 * ctl_name terminates the table. table->de will be set up by the
121 * registration and need not be initialised in advance.
122 *
123 * sysctl names can be mirrored automatically under /proc/sys. The
124 * procname supplied controls /proc naming.
125 *
126 * The table's mode will be honoured both for sys_sysctl(2) and
127 * proc-fs access.
128 *
129 * Leaf nodes in the sysctl tree will be represented by a single file
130 * under /proc; non-leaf nodes will be represented by directories. A
131 * null procname disables /proc mirroring at this node.
132 *
133 * sysctl(2) can automatically manage read and write requests through
134 * the sysctl table. The data and maxlen fields of the ctl_table
135 * struct enable minimal validation of the values being written to be
136 * performed, and the mode field allows minimal authentication.
137 *
138 * More sophisticated management can be enabled by the provision of a
139 * strategy routine with the table entry. This will be called before
140 * any automatic read or write of the data is performed.
141 *
142 * The strategy routine may return:
143 * <0: Error occurred (error is passed to user process)
144 * 0: OK - proceed with automatic read or write.
145 * >0: OK - read or write has been done by the strategy routine, so
146 * return immediately.
147 *
148 * There must be a proc_handler routine for any terminal nodes
149 * mirrored under /proc/sys (non-terminals are handled by a built-in
150 * directory handler). Several default handlers are available to
151 * cover common cases.
152 */
153
154 /* A sysctl table is an array of struct ctl_table: */
155 struct ctl_table
156 {
157 int ctl_name; /* Binary ID */
158 const char *procname; /* Text ID for /proc/sys, or zero */
159 void *data;
160 int maxlen;
161 mode_t mode;
162 ctl_table *child;
163 proc_handler *proc_handler; /* Callback for text formatting */
164 ctl_handler *strategy; /* Callback function for all r/w */
165 struct proc_dir_entry *de; /* /proc control block */
166 };
167
168 /* struct ctl_table_header is used to maintain dynamic lists of
169 ctl_table trees. */
170 struct ctl_table_header
171 {
172 ctl_table *ctl_table;
173 DLNODE(struct ctl_table_header) ctl_entry;
174 };
175
176 struct ctl_table_header * register_sysctl_table(ctl_table * table,
177 int insert_at_head);
178 void unregister_sysctl_table(struct ctl_table_header * table);
179
180 #else /* __KERNEL__ */
181
182 #endif /* __KERNEL__ */
183
184 #endif /* _LINUX_SYSCTL_H */