This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / kernel / sysctl.c
1 /*
2  * sysctl.c: General linux system control interface
3  *
4  * Begun 24 March 1995, Stephen Tweedie
5  * Added /proc support, Dec 1995
6  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9  * Dynamic registration fixes, Stephen Tweedie.
10  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12  *  Horn.
13  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16  *  Wendling.
17  * The list_for_each() macro wasn't appropriate for the sysctl loop.
18  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
19  */
20
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/mm.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/sysrq.h>
35 #include <linux/highuid.h>
36 #include <linux/writeback.h>
37 #include <linux/hugetlb.h>
38 #include <linux/security.h>
39 #include <linux/initrd.h>
40 #include <linux/times.h>
41 #include <linux/limits.h>
42 #include <asm/uaccess.h>
43
44 #ifdef CONFIG_ROOT_NFS
45 #include <linux/nfs_fs.h>
46 #endif
47
48 #if defined(CONFIG_SYSCTL)
49
50 /* External variables not in a header file. */
51 extern int panic_timeout;
52 extern int C_A_D;
53 extern int sysctl_overcommit_memory;
54 extern int sysctl_overcommit_ratio;
55 extern int max_threads;
56 extern atomic_t nr_queued_signals;
57 extern int max_queued_signals;
58 extern int sysrq_enabled;
59 extern int core_uses_pid;
60 extern char core_pattern[];
61 extern int cad_pid;
62 extern int pid_max;
63 extern int sysctl_lower_zone_protection;
64 extern int min_free_kbytes;
65 extern int printk_ratelimit_jiffies;
66 extern int printk_ratelimit_burst;
67
68 extern unsigned int vdso_enabled;
69
70 int exec_shield = 1;
71 int exec_shield_randomize = 1;
72
73 static int __init setup_exec_shield(char *str)
74 {
75         get_option (&str, &exec_shield);
76
77         return 1;
78 }
79
80 __setup("exec-shield=", setup_exec_shield);
81
82 static int __init setup_exec_shield_randomize(char *str)
83 {
84         get_option (&str, &exec_shield_randomize);
85
86         return 1;
87 }
88
89 __setup("exec-shield-randomize=", setup_exec_shield_randomize);
90
91 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
92 static int maxolduid = 65535;
93 static int minolduid;
94
95 static int ngroups_max = NGROUPS_MAX;
96
97 #ifdef CONFIG_KMOD
98 extern char modprobe_path[];
99 #endif
100 #ifdef CONFIG_HOTPLUG
101 extern char hotplug_path[];
102 #endif
103 extern char vshelper_path[];
104 #ifdef CONFIG_CHR_DEV_SG
105 extern int sg_big_buff;
106 #endif
107 #ifdef CONFIG_SYSVIPC
108 extern size_t shm_ctlmax;
109 extern size_t shm_ctlall;
110 extern int shm_ctlmni;
111 extern int msg_ctlmax;
112 extern int msg_ctlmnb;
113 extern int msg_ctlmni;
114 extern int sem_ctls[];
115 #endif
116
117 #ifdef __sparc__
118 extern char reboot_command [];
119 extern int stop_a_enabled;
120 extern int scons_pwroff;
121 #endif
122
123 #ifdef __hppa__
124 extern int pwrsw_enabled;
125 extern int unaligned_enabled;
126 #endif
127
128 #ifdef CONFIG_ARCH_S390
129 #ifdef CONFIG_MATHEMU
130 extern int sysctl_ieee_emulation_warnings;
131 #endif
132 extern int sysctl_userprocess_debug;
133 #endif
134
135 extern int sysctl_hz_timer;
136
137 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
138 extern unsigned long powersave_nap;
139 int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
140                   void *buffer, size_t *lenp);
141 #endif
142
143 #ifdef CONFIG_BSD_PROCESS_ACCT
144 extern int acct_parm[];
145 #endif
146
147 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
148                        ctl_table *, void **);
149 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
150                   void __user *buffer, size_t *lenp);
151
152 static ctl_table root_table[];
153 static struct ctl_table_header root_table_header =
154         { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
155
156 static ctl_table kern_table[];
157 static ctl_table vm_table[];
158 #ifdef CONFIG_NET
159 extern ctl_table net_table[];
160 #endif
161 static ctl_table proc_table[];
162 static ctl_table fs_table[];
163 static ctl_table debug_table[];
164 static ctl_table dev_table[];
165 extern ctl_table random_table[];
166 #ifdef CONFIG_UNIX98_PTYS
167 extern ctl_table pty_table[];
168 #endif
169
170 /* /proc declarations: */
171
172 #ifdef CONFIG_PROC_FS
173
174 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
175 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
176 static int proc_opensys(struct inode *, struct file *);
177
178 struct file_operations proc_sys_file_operations = {
179         .open           = proc_opensys,
180         .read           = proc_readsys,
181         .write          = proc_writesys,
182 };
183
184 extern struct proc_dir_entry *proc_sys_root;
185
186 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
187 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
188 #endif
189
190 /* The default sysctl tables: */
191
192 static ctl_table root_table[] = {
193         {
194                 .ctl_name       = CTL_KERN,
195                 .procname       = "kernel",
196                 .mode           = 0555,
197                 .child          = kern_table,
198         },
199         {
200                 .ctl_name       = CTL_VM,
201                 .procname       = "vm",
202                 .mode           = 0555,
203                 .child          = vm_table,
204         },
205 #ifdef CONFIG_NET
206         {
207                 .ctl_name       = CTL_NET,
208                 .procname       = "net",
209                 .mode           = 0555,
210                 .child          = net_table,
211         },
212 #endif
213         {
214                 .ctl_name       = CTL_PROC,
215                 .procname       = "proc",
216                 .mode           = 0555,
217                 .child          = proc_table,
218         },
219         {
220                 .ctl_name       = CTL_FS,
221                 .procname       = "fs",
222                 .mode           = 0555,
223                 .child          = fs_table,
224         },
225         {
226                 .ctl_name       = CTL_DEBUG,
227                 .procname       = "debug",
228                 .mode           = 0555,
229                 .child          = debug_table,
230         },
231         {
232                 .ctl_name       = CTL_DEV,
233                 .procname       = "dev",
234                 .mode           = 0555,
235                 .child          = dev_table,
236         },
237         { .ctl_name = 0 }
238 };
239
240 static ctl_table kern_table[] = {
241         {
242                 .ctl_name       = KERN_OSTYPE,
243                 .procname       = "ostype",
244                 .data           = system_utsname.sysname,
245                 .maxlen         = 64,
246                 .mode           = 0444,
247                 .proc_handler   = &proc_doutsstring,
248                 .strategy       = &sysctl_string,
249         },
250         {
251                 .ctl_name       = KERN_OSRELEASE,
252                 .procname       = "osrelease",
253                 .data           = system_utsname.release,
254                 .maxlen         = 64,
255                 .mode           = 0444,
256                 .proc_handler   = &proc_doutsstring,
257                 .strategy       = &sysctl_string,
258         },
259         {
260                 .ctl_name       = KERN_VERSION,
261                 .procname       = "version",
262                 .data           = system_utsname.version,
263                 .maxlen         = 64,
264                 .mode           = 0444,
265                 .proc_handler   = &proc_doutsstring,
266                 .strategy       = &sysctl_string,
267         },
268         {
269                 .ctl_name       = KERN_NODENAME,
270                 .procname       = "hostname",
271                 .data           = system_utsname.nodename,
272                 .maxlen         = 64,
273                 .mode           = 0644,
274                 .proc_handler   = &proc_doutsstring,
275                 .strategy       = &sysctl_string,
276         },
277         {
278                 .ctl_name       = KERN_DOMAINNAME,
279                 .procname       = "domainname",
280                 .data           = system_utsname.domainname,
281                 .maxlen         = 64,
282                 .mode           = 0644,
283                 .proc_handler   = &proc_doutsstring,
284                 .strategy       = &sysctl_string,
285         },
286         {
287                 .ctl_name       = KERN_PANIC,
288                 .procname       = "panic",
289                 .data           = &panic_timeout,
290                 .maxlen         = sizeof(int),
291                 .mode           = 0644,
292                 .proc_handler   = &proc_dointvec,
293         },
294         {
295                 .ctl_name       = KERN_PANIC,
296                 .procname       = "exec-shield",
297                 .data           = &exec_shield,
298                 .maxlen         = sizeof(int),
299                 .mode           = 0644,
300                 .proc_handler   = &proc_dointvec,
301         },
302         {
303                 .ctl_name       = KERN_PANIC,
304                 .procname       = "exec-shield-randomize",
305                 .data           = &exec_shield_randomize,
306                 .maxlen         = sizeof(int),
307                 .mode           = 0644,
308                 .proc_handler   = &proc_dointvec,
309         },
310         {
311                 .ctl_name       = KERN_PANIC,
312                 .procname       = "print-fatal-signals",
313                 .data           = &print_fatal_signals,
314                 .maxlen         = sizeof(int),
315                 .mode           = 0644,
316                 .proc_handler   = &proc_dointvec,
317         },
318 #if __i386__
319         {
320                 .ctl_name       = KERN_PANIC,
321                 .procname       = "vdso",
322                 .data           = &vdso_enabled,
323                 .maxlen         = sizeof(int),
324                 .mode           = 0644,
325                 .proc_handler   = &proc_dointvec,
326         },
327 #endif
328         {
329                 .ctl_name       = KERN_CORE_USES_PID,
330                 .procname       = "core_uses_pid",
331                 .data           = &core_uses_pid,
332                 .maxlen         = sizeof(int),
333                 .mode           = 0644,
334                 .proc_handler   = &proc_dointvec,
335         },
336         {
337                 .ctl_name       = KERN_CORE_PATTERN,
338                 .procname       = "core_pattern",
339                 .data           = core_pattern,
340                 .maxlen         = 64,
341                 .mode           = 0644,
342                 .proc_handler   = &proc_dostring,
343                 .strategy       = &sysctl_string,
344         },
345         {
346                 .ctl_name       = KERN_TAINTED,
347                 .procname       = "tainted",
348                 .data           = &tainted,
349                 .maxlen         = sizeof(int),
350                 .mode           = 0644,
351                 .proc_handler   = &proc_dointvec,
352         },
353         {
354                 .ctl_name       = KERN_CAP_BSET,
355                 .procname       = "cap-bound",
356                 .data           = &cap_bset,
357                 .maxlen         = sizeof(kernel_cap_t),
358                 .mode           = 0600,
359                 .proc_handler   = &proc_dointvec_bset,
360         },
361 #ifdef CONFIG_BLK_DEV_INITRD
362         {
363                 .ctl_name       = KERN_REALROOTDEV,
364                 .procname       = "real-root-dev",
365                 .data           = &real_root_dev,
366                 .maxlen         = sizeof(int),
367                 .mode           = 0644,
368                 .proc_handler   = &proc_dointvec,
369         },
370 #endif
371 #ifdef __sparc__
372         {
373                 .ctl_name       = KERN_SPARC_REBOOT,
374                 .procname       = "reboot-cmd",
375                 .data           = reboot_command,
376                 .maxlen         = 256,
377                 .mode           = 0644,
378                 .proc_handler   = &proc_dostring,
379                 .strategy       = &sysctl_string,
380         },
381         {
382                 .ctl_name       = KERN_SPARC_STOP_A,
383                 .procname       = "stop-a",
384                 .data           = &stop_a_enabled,
385                 .maxlen         = sizeof (int),
386                 .mode           = 0644,
387                 .proc_handler   = &proc_dointvec,
388         },
389         {
390                 .ctl_name       = KERN_SPARC_SCONS_PWROFF,
391                 .procname       = "scons-poweroff",
392                 .data           = &scons_pwroff,
393                 .maxlen         = sizeof (int),
394                 .mode           = 0644,
395                 .proc_handler   = &proc_dointvec,
396         },
397 #endif
398 #ifdef __hppa__
399         {
400                 .ctl_name       = KERN_HPPA_PWRSW,
401                 .procname       = "soft-power",
402                 .data           = &pwrsw_enabled,
403                 .maxlen         = sizeof (int),
404                 .mode           = 0644,
405                 .proc_handler   = &proc_dointvec,
406         },
407         {
408                 .ctl_name       = KERN_HPPA_UNALIGNED,
409                 .procname       = "unaligned-trap",
410                 .data           = &unaligned_enabled,
411                 .maxlen         = sizeof (int),
412                 .mode           = 0644,
413                 .proc_handler   = &proc_dointvec,
414         },
415 #endif
416 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
417         {
418                 .ctl_name       = KERN_PPC_POWERSAVE_NAP,
419                 .procname       = "powersave-nap",
420                 .data           = &powersave_nap,
421                 .maxlen         = sizeof(int),
422                 .mode           = 0644,
423                 .proc_handler   = &proc_dointvec,
424         },
425         {
426                 .ctl_name       = KERN_PPC_L2CR,
427                 .procname       = "l2cr",
428                 .mode           = 0644,
429                 .proc_handler   = &proc_dol2crvec,
430         },
431 #endif
432         {
433                 .ctl_name       = KERN_CTLALTDEL,
434                 .procname       = "ctrl-alt-del",
435                 .data           = &C_A_D,
436                 .maxlen         = sizeof(int),
437                 .mode           = 0644,
438                 .proc_handler   = &proc_dointvec,
439         },
440         {
441                 .ctl_name       = KERN_PRINTK,
442                 .procname       = "printk",
443                 .data           = &console_loglevel,
444                 .maxlen         = 4*sizeof(int),
445                 .mode           = 0644,
446                 .proc_handler   = &proc_dointvec,
447         },
448 #ifdef CONFIG_KMOD
449         {
450                 .ctl_name       = KERN_MODPROBE,
451                 .procname       = "modprobe",
452                 .data           = &modprobe_path,
453                 .maxlen         = 256,
454                 .mode           = 0644,
455                 .proc_handler   = &proc_dostring,
456                 .strategy       = &sysctl_string,
457         },
458 #endif
459 #ifdef CONFIG_HOTPLUG
460         {
461                 .ctl_name       = KERN_HOTPLUG,
462                 .procname       = "hotplug",
463                 .data           = &hotplug_path,
464                 .maxlen         = 256,
465                 .mode           = 0644,
466                 .proc_handler   = &proc_dostring,
467                 .strategy       = &sysctl_string,
468         },
469 #endif
470         {
471                 .ctl_name       = KERN_VSHELPER,
472                 .procname       = "vshelper",
473                 .data           = &vshelper_path,
474                 .maxlen         = 256,
475                 .mode           = 0644,
476                 .proc_handler   = &proc_dostring,
477                 .strategy       = &sysctl_string,
478         },
479 #ifdef CONFIG_CHR_DEV_SG
480         {
481                 .ctl_name       = KERN_SG_BIG_BUFF,
482                 .procname       = "sg-big-buff",
483                 .data           = &sg_big_buff,
484                 .maxlen         = sizeof (int),
485                 .mode           = 0444,
486                 .proc_handler   = &proc_dointvec,
487         },
488 #endif
489 #ifdef CONFIG_BSD_PROCESS_ACCT
490         {
491                 .ctl_name       = KERN_ACCT,
492                 .procname       = "acct",
493                 .data           = &acct_parm,
494                 .maxlen         = 3*sizeof(int),
495                 .mode           = 0644,
496                 .proc_handler   = &proc_dointvec,
497         },
498 #endif
499         {
500                 .ctl_name       = KERN_RTSIGNR,
501                 .procname       = "rtsig-nr",
502                 .data           = &nr_queued_signals,
503                 .maxlen         = sizeof(int),
504                 .mode           = 0444,
505                 .proc_handler   = &proc_dointvec,
506         },
507         {
508                 .ctl_name       = KERN_RTSIGMAX,
509                 .procname       = "rtsig-max",
510                 .data           = &max_queued_signals,
511                 .maxlen         = sizeof(int),
512                 .mode           = 0644,
513                 .proc_handler   = &proc_dointvec,
514         },
515 #ifdef CONFIG_SYSVIPC
516         {
517                 .ctl_name       = KERN_SHMMAX,
518                 .procname       = "shmmax",
519                 .data           = &shm_ctlmax,
520                 .maxlen         = sizeof (size_t),
521                 .mode           = 0644,
522                 .proc_handler   = &proc_doulongvec_minmax,
523         },
524         {
525                 .ctl_name       = KERN_SHMALL,
526                 .procname       = "shmall",
527                 .data           = &shm_ctlall,
528                 .maxlen         = sizeof (size_t),
529                 .mode           = 0644,
530                 .proc_handler   = &proc_doulongvec_minmax,
531         },
532         {
533                 .ctl_name       = KERN_SHMMNI,
534                 .procname       = "shmmni",
535                 .data           = &shm_ctlmni,
536                 .maxlen         = sizeof (int),
537                 .mode           = 0644,
538                 .proc_handler   = &proc_dointvec,
539         },
540         {
541                 .ctl_name       = KERN_MSGMAX,
542                 .procname       = "msgmax",
543                 .data           = &msg_ctlmax,
544                 .maxlen         = sizeof (int),
545                 .mode           = 0644,
546                 .proc_handler   = &proc_dointvec,
547         },
548         {
549                 .ctl_name       = KERN_MSGMNI,
550                 .procname       = "msgmni",
551                 .data           = &msg_ctlmni,
552                 .maxlen         = sizeof (int),
553                 .mode           = 0644,
554                 .proc_handler   = &proc_dointvec,
555         },
556         {
557                 .ctl_name       = KERN_MSGMNB,
558                 .procname       =  "msgmnb",
559                 .data           = &msg_ctlmnb,
560                 .maxlen         = sizeof (int),
561                 .mode           = 0644,
562                 .proc_handler   = &proc_dointvec,
563         },
564         {
565                 .ctl_name       = KERN_SEM,
566                 .procname       = "sem",
567                 .data           = &sem_ctls,
568                 .maxlen         = 4*sizeof (int),
569                 .mode           = 0644,
570                 .proc_handler   = &proc_dointvec,
571         },
572 #endif
573 #ifdef CONFIG_MAGIC_SYSRQ
574         {
575                 .ctl_name       = KERN_SYSRQ,
576                 .procname       = "sysrq",
577                 .data           = &sysrq_enabled,
578                 .maxlen         = sizeof (int),
579                 .mode           = 0644,
580                 .proc_handler   = &proc_dointvec,
581         },
582 #endif
583         {
584                 .ctl_name       = KERN_CADPID,
585                 .procname       = "cad_pid",
586                 .data           = &cad_pid,
587                 .maxlen         = sizeof (int),
588                 .mode           = 0600,
589                 .proc_handler   = &proc_dointvec,
590         },
591         {
592                 .ctl_name       = KERN_MAX_THREADS,
593                 .procname       = "threads-max",
594                 .data           = &max_threads,
595                 .maxlen         = sizeof(int),
596                 .mode           = 0644,
597                 .proc_handler   = &proc_dointvec,
598         },
599         {
600                 .ctl_name       = KERN_RANDOM,
601                 .procname       = "random",
602                 .mode           = 0555,
603                 .child          = random_table,
604         },
605 #ifdef CONFIG_UNIX98_PTYS
606         {
607                 .ctl_name       = KERN_PTY,
608                 .procname       = "pty",
609                 .mode           = 0555,
610                 .child          = pty_table,
611         },
612 #endif
613         {
614                 .ctl_name       = KERN_OVERFLOWUID,
615                 .procname       = "overflowuid",
616                 .data           = &overflowuid,
617                 .maxlen         = sizeof(int),
618                 .mode           = 0644,
619                 .proc_handler   = &proc_dointvec_minmax,
620                 .strategy       = &sysctl_intvec,
621                 .extra1         = &minolduid,
622                 .extra2         = &maxolduid,
623         },
624         {
625                 .ctl_name       = KERN_OVERFLOWGID,
626                 .procname       = "overflowgid",
627                 .data           = &overflowgid,
628                 .maxlen         = sizeof(int),
629                 .mode           = 0644,
630                 .proc_handler   = &proc_dointvec_minmax,
631                 .strategy       = &sysctl_intvec,
632                 .extra1         = &minolduid,
633                 .extra2         = &maxolduid,
634         },
635 #ifdef CONFIG_ARCH_S390
636 #ifdef CONFIG_MATHEMU
637         {
638                 .ctl_name       = KERN_IEEE_EMULATION_WARNINGS,
639                 .procname       = "ieee_emulation_warnings",
640                 .data           = &sysctl_ieee_emulation_warnings,
641                 .maxlen         = sizeof(int),
642                 .mode           = 0644,
643                 .proc_handler   = &proc_dointvec,
644         },
645 #endif
646 #ifdef CONFIG_NO_IDLE_HZ
647         {
648                 .ctl_name       = KERN_HZ_TIMER,
649                 .procname       = "hz_timer",
650                 .data           = &sysctl_hz_timer,
651                 .maxlen         = sizeof(int),
652                 .mode           = 0644,
653                 .proc_handler   = &proc_dointvec,
654         },
655 #endif
656         {
657                 .ctl_name       = KERN_S390_USER_DEBUG_LOGGING,
658                 .procname       = "userprocess_debug",
659                 .data           = &sysctl_userprocess_debug,
660                 .maxlen         = sizeof(int),
661                 .mode           = 0644,
662                 .proc_handler   = &proc_dointvec,
663         },
664 #endif
665         {
666                 .ctl_name       = KERN_PIDMAX,
667                 .procname       = "pid_max",
668                 .data           = &pid_max,
669                 .maxlen         = sizeof (int),
670                 .mode           = 0644,
671                 .proc_handler   = &proc_dointvec,
672         },
673         {
674                 .ctl_name       = KERN_PANIC_ON_OOPS,
675                 .procname       = "panic_on_oops",
676                 .data           = &panic_on_oops,
677                 .maxlen         = sizeof(int),
678                 .mode           = 0644,
679                 .proc_handler   = &proc_dointvec,
680         },
681         {
682                 .ctl_name       = KERN_PRINTK_RATELIMIT,
683                 .procname       = "printk_ratelimit",
684                 .data           = &printk_ratelimit_jiffies,
685                 .maxlen         = sizeof(int),
686                 .mode           = 0644,
687                 .proc_handler   = &proc_dointvec_jiffies,
688                 .strategy       = &sysctl_jiffies,
689         },
690         {
691                 .ctl_name       = KERN_PRINTK_RATELIMIT_BURST,
692                 .procname       = "printk_ratelimit_burst",
693                 .data           = &printk_ratelimit_burst,
694                 .maxlen         = sizeof(int),
695                 .mode           = 0644,
696                 .proc_handler   = &proc_dointvec,
697         },
698         {
699                 .ctl_name       = KERN_NGROUPS_MAX,
700                 .procname       = "ngroups_max",
701                 .data           = &ngroups_max,
702                 .maxlen         = sizeof (int),
703                 .mode           = 0444,
704                 .proc_handler   = &proc_dointvec,
705         },
706         { .ctl_name = 0 }
707 };
708
709 /* Constants for minimum and maximum testing in vm_table.
710    We use these as one-element integer vectors. */
711 static int zero;
712 static int one_hundred = 100;
713
714
715 static ctl_table vm_table[] = {
716         {
717                 .ctl_name       = VM_OVERCOMMIT_MEMORY,
718                 .procname       = "overcommit_memory",
719                 .data           = &sysctl_overcommit_memory,
720                 .maxlen         = sizeof(sysctl_overcommit_memory),
721                 .mode           = 0644,
722                 .proc_handler   = &proc_dointvec,
723         },
724         {
725                 .ctl_name       = VM_OVERCOMMIT_RATIO,
726                 .procname       = "overcommit_ratio",
727                 .data           = &sysctl_overcommit_ratio,
728                 .maxlen         = sizeof(sysctl_overcommit_ratio),
729                 .mode           = 0644,
730                 .proc_handler   = &proc_dointvec,
731         },
732         {
733                 .ctl_name       = VM_PAGE_CLUSTER,
734                 .procname       = "page-cluster", 
735                 .data           = &page_cluster,
736                 .maxlen         = sizeof(int),
737                 .mode           = 0644,
738                 .proc_handler   = &proc_dointvec,
739         },
740         {
741                 .ctl_name       = VM_DIRTY_BACKGROUND,
742                 .procname       = "dirty_background_ratio",
743                 .data           = &dirty_background_ratio,
744                 .maxlen         = sizeof(dirty_background_ratio),
745                 .mode           = 0644,
746                 .proc_handler   = &proc_dointvec_minmax,
747                 .strategy       = &sysctl_intvec,
748                 .extra1         = &zero,
749                 .extra2         = &one_hundred,
750         },
751         {
752                 .ctl_name       = VM_DIRTY_RATIO,
753                 .procname       = "dirty_ratio",
754                 .data           = &vm_dirty_ratio,
755                 .maxlen         = sizeof(vm_dirty_ratio),
756                 .mode           = 0644,
757                 .proc_handler   = &proc_dointvec_minmax,
758                 .strategy       = &sysctl_intvec,
759                 .extra1         = &zero,
760                 .extra2         = &one_hundred,
761         },
762         {
763                 .ctl_name       = VM_DIRTY_WB_CS,
764                 .procname       = "dirty_writeback_centisecs",
765                 .data           = &dirty_writeback_centisecs,
766                 .maxlen         = sizeof(dirty_writeback_centisecs),
767                 .mode           = 0644,
768                 .proc_handler   = &dirty_writeback_centisecs_handler,
769         },
770         {
771                 .ctl_name       = VM_DIRTY_EXPIRE_CS,
772                 .procname       = "dirty_expire_centisecs",
773                 .data           = &dirty_expire_centisecs,
774                 .maxlen         = sizeof(dirty_expire_centisecs),
775                 .mode           = 0644,
776                 .proc_handler   = &proc_dointvec,
777         },
778         {
779                 .ctl_name       = VM_NR_PDFLUSH_THREADS,
780                 .procname       = "nr_pdflush_threads",
781                 .data           = &nr_pdflush_threads,
782                 .maxlen         = sizeof nr_pdflush_threads,
783                 .mode           = 0444 /* read-only*/,
784                 .proc_handler   = &proc_dointvec,
785         },
786         {
787                 .ctl_name       = VM_SWAPPINESS,
788                 .procname       = "swappiness",
789                 .data           = &vm_swappiness,
790                 .maxlen         = sizeof(vm_swappiness),
791                 .mode           = 0644,
792                 .proc_handler   = &proc_dointvec_minmax,
793                 .strategy       = &sysctl_intvec,
794                 .extra1         = &zero,
795                 .extra2         = &one_hundred,
796         },
797 #ifdef CONFIG_HUGETLB_PAGE
798          {
799                 .ctl_name       = VM_HUGETLB_PAGES,
800                 .procname       = "nr_hugepages",
801                 .data           = &max_huge_pages,
802                 .maxlen         = sizeof(unsigned long),
803                 .mode           = 0644,
804                 .proc_handler   = &hugetlb_sysctl_handler,
805                 .extra1         = (void *)&hugetlb_zero,
806                 .extra2         = (void *)&hugetlb_infinity,
807          },
808 #endif
809         {
810                 .ctl_name       = VM_LOWER_ZONE_PROTECTION,
811                 .procname       = "lower_zone_protection",
812                 .data           = &sysctl_lower_zone_protection,
813                 .maxlen         = sizeof(sysctl_lower_zone_protection),
814                 .mode           = 0644,
815                 .proc_handler   = &lower_zone_protection_sysctl_handler,
816                 .strategy       = &sysctl_intvec,
817                 .extra1         = &zero,
818         },
819         {
820                 .ctl_name       = VM_MIN_FREE_KBYTES,
821                 .procname       = "min_free_kbytes",
822                 .data           = &min_free_kbytes,
823                 .maxlen         = sizeof(min_free_kbytes),
824                 .mode           = 0644,
825                 .proc_handler   = &min_free_kbytes_sysctl_handler,
826                 .strategy       = &sysctl_intvec,
827                 .extra1         = &zero,
828         },
829         {
830                 .ctl_name       = VM_MAX_MAP_COUNT,
831                 .procname       = "max_map_count",
832                 .data           = &sysctl_max_map_count,
833                 .maxlen         = sizeof(sysctl_max_map_count),
834                 .mode           = 0644,
835                 .proc_handler   = &proc_dointvec
836         },
837         {
838                 .ctl_name       = VM_LAPTOP_MODE,
839                 .procname       = "laptop_mode",
840                 .data           = &laptop_mode,
841                 .maxlen         = sizeof(laptop_mode),
842                 .mode           = 0644,
843                 .proc_handler   = &proc_dointvec,
844                 .strategy       = &sysctl_intvec,
845                 .extra1         = &zero,
846         },
847         {
848                 .ctl_name       = VM_BLOCK_DUMP,
849                 .procname       = "block_dump",
850                 .data           = &block_dump,
851                 .maxlen         = sizeof(block_dump),
852                 .mode           = 0644,
853                 .proc_handler   = &proc_dointvec,
854                 .strategy       = &sysctl_intvec,
855                 .extra1         = &zero,
856         },
857         { .ctl_name = 0 }
858 };
859
860 static ctl_table proc_table[] = {
861         { .ctl_name = 0 }
862 };
863
864 static ctl_table fs_table[] = {
865         {
866                 .ctl_name       = FS_NRINODE,
867                 .procname       = "inode-nr",
868                 .data           = &inodes_stat,
869                 .maxlen         = 2*sizeof(int),
870                 .mode           = 0444,
871                 .proc_handler   = &proc_dointvec,
872         },
873         {
874                 .ctl_name       = FS_STATINODE,
875                 .procname       = "inode-state",
876                 .data           = &inodes_stat,
877                 .maxlen         = 7*sizeof(int),
878                 .mode           = 0444,
879                 .proc_handler   = &proc_dointvec,
880         },
881         {
882                 .ctl_name       = FS_NRFILE,
883                 .procname       = "file-nr",
884                 .data           = &files_stat,
885                 .maxlen         = 3*sizeof(int),
886                 .mode           = 0444,
887                 .proc_handler   = &proc_dointvec,
888         },
889         {
890                 .ctl_name       = FS_MAXFILE,
891                 .procname       = "file-max",
892                 .data           = &files_stat.max_files,
893                 .maxlen         = sizeof(int),
894                 .mode           = 0644,
895                 .proc_handler   = &proc_dointvec,
896         },
897         {
898                 .ctl_name       = FS_DENTRY,
899                 .procname       = "dentry-state",
900                 .data           = &dentry_stat,
901                 .maxlen         = 6*sizeof(int),
902                 .mode           = 0444,
903                 .proc_handler   = &proc_dointvec,
904         },
905         {
906                 .ctl_name       = FS_OVERFLOWUID,
907                 .procname       = "overflowuid",
908                 .data           = &fs_overflowuid,
909                 .maxlen         = sizeof(int),
910                 .mode           = 0644,
911                 .proc_handler   = &proc_dointvec_minmax,
912                 .strategy       = &sysctl_intvec,
913                 .extra1         = &minolduid,
914                 .extra2         = &maxolduid,
915         },
916         {
917                 .ctl_name       = FS_OVERFLOWGID,
918                 .procname       = "overflowgid",
919                 .data           = &fs_overflowgid,
920                 .maxlen         = sizeof(int),
921                 .mode           = 0644,
922                 .proc_handler   = &proc_dointvec_minmax,
923                 .strategy       = &sysctl_intvec,
924                 .extra1         = &minolduid,
925                 .extra2         = &maxolduid,
926         },
927         {
928                 .ctl_name       = FS_LEASES,
929                 .procname       = "leases-enable",
930                 .data           = &leases_enable,
931                 .maxlen         = sizeof(int),
932                 .mode           = 0644,
933                 .proc_handler   = &proc_dointvec,
934         },
935         {
936                 .ctl_name       = FS_DIR_NOTIFY,
937                 .procname       = "dir-notify-enable",
938                 .data           = &dir_notify_enable,
939                 .maxlen         = sizeof(int),
940                 .mode           = 0644,
941                 .proc_handler   = &proc_dointvec,
942         },
943         {
944                 .ctl_name       = FS_LEASE_TIME,
945                 .procname       = "lease-break-time",
946                 .data           = &lease_break_time,
947                 .maxlen         = sizeof(int),
948                 .mode           = 0644,
949                 .proc_handler   = &proc_dointvec,
950         },
951         {
952                 .ctl_name       = FS_AIO_NR,
953                 .procname       = "aio-nr",
954                 .data           = &aio_nr,
955                 .maxlen         = sizeof(aio_nr),
956                 .mode           = 0444,
957                 .proc_handler   = &proc_dointvec,
958         },
959         {
960                 .ctl_name       = FS_AIO_MAX_NR,
961                 .procname       = "aio-max-nr",
962                 .data           = &aio_max_nr,
963                 .maxlen         = sizeof(aio_max_nr),
964                 .mode           = 0644,
965                 .proc_handler   = &proc_dointvec,
966         },
967         { .ctl_name = 0 }
968 };
969
970 static ctl_table debug_table[] = {
971         { .ctl_name = 0 }
972 };
973
974 static ctl_table dev_table[] = {
975         { .ctl_name = 0 }
976 };  
977
978 extern void init_irq_proc (void);
979
980 void __init sysctl_init(void)
981 {
982 #ifdef CONFIG_PROC_FS
983         register_proc_table(root_table, proc_sys_root);
984         init_irq_proc();
985 #endif
986 }
987
988 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
989                void __user *newval, size_t newlen)
990 {
991         struct list_head *tmp;
992
993         if (nlen <= 0 || nlen >= CTL_MAXNAME)
994                 return -ENOTDIR;
995         if (oldval) {
996                 int old_len;
997                 if (!oldlenp || get_user(old_len, oldlenp))
998                         return -EFAULT;
999         }
1000         tmp = &root_table_header.ctl_entry;
1001         do {
1002                 struct ctl_table_header *head =
1003                         list_entry(tmp, struct ctl_table_header, ctl_entry);
1004                 void *context = NULL;
1005                 int error = parse_table(name, nlen, oldval, oldlenp, 
1006                                         newval, newlen, head->ctl_table,
1007                                         &context);
1008                 if (context)
1009                         kfree(context);
1010                 if (error != -ENOTDIR)
1011                         return error;
1012                 tmp = tmp->next;
1013         } while (tmp != &root_table_header.ctl_entry);
1014         return -ENOTDIR;
1015 }
1016
1017 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1018 {
1019         struct __sysctl_args tmp;
1020         int error;
1021
1022         if (copy_from_user(&tmp, args, sizeof(tmp)))
1023                 return -EFAULT;
1024
1025         lock_kernel();
1026         error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1027                           tmp.newval, tmp.newlen);
1028         unlock_kernel();
1029         return error;
1030 }
1031
1032 /*
1033  * ctl_perm does NOT grant the superuser all rights automatically, because
1034  * some sysctl variables are readonly even to root.
1035  */
1036
1037 static int test_perm(int mode, int op)
1038 {
1039         if (!current->euid)
1040                 mode >>= 6;
1041         else if (in_egroup_p(0))
1042                 mode >>= 3;
1043         if ((mode & op & 0007) == op)
1044                 return 0;
1045         return -EACCES;
1046 }
1047
1048 static inline int ctl_perm(ctl_table *table, int op)
1049 {
1050         int error;
1051         error = security_sysctl(table, op);
1052         if (error)
1053                 return error;
1054         return test_perm(table->mode, op);
1055 }
1056
1057 static int parse_table(int __user *name, int nlen,
1058                        void __user *oldval, size_t __user *oldlenp,
1059                        void __user *newval, size_t newlen,
1060                        ctl_table *table, void **context)
1061 {
1062         int n;
1063 repeat:
1064         if (!nlen)
1065                 return -ENOTDIR;
1066         if (get_user(n, name))
1067                 return -EFAULT;
1068         for ( ; table->ctl_name; table++) {
1069                 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1070                         int error;
1071                         if (table->child) {
1072                                 if (ctl_perm(table, 001))
1073                                         return -EPERM;
1074                                 if (table->strategy) {
1075                                         error = table->strategy(
1076                                                 table, name, nlen,
1077                                                 oldval, oldlenp,
1078                                                 newval, newlen, context);
1079                                         if (error)
1080                                                 return error;
1081                                 }
1082                                 name++;
1083                                 nlen--;
1084                                 table = table->child;
1085                                 goto repeat;
1086                         }
1087                         error = do_sysctl_strategy(table, name, nlen,
1088                                                    oldval, oldlenp,
1089                                                    newval, newlen, context);
1090                         return error;
1091                 }
1092         }
1093         return -ENOTDIR;
1094 }
1095
1096 /* Perform the actual read/write of a sysctl table entry. */
1097 int do_sysctl_strategy (ctl_table *table, 
1098                         int __user *name, int nlen,
1099                         void __user *oldval, size_t __user *oldlenp,
1100                         void __user *newval, size_t newlen, void **context)
1101 {
1102         int op = 0, rc;
1103         size_t len;
1104
1105         if (oldval)
1106                 op |= 004;
1107         if (newval) 
1108                 op |= 002;
1109         if (ctl_perm(table, op))
1110                 return -EPERM;
1111
1112         if (table->strategy) {
1113                 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1114                                      newval, newlen, context);
1115                 if (rc < 0)
1116                         return rc;
1117                 if (rc > 0)
1118                         return 0;
1119         }
1120
1121         /* If there is no strategy routine, or if the strategy returns
1122          * zero, proceed with automatic r/w */
1123         if (table->data && table->maxlen) {
1124                 if (oldval && oldlenp) {
1125                         if (get_user(len, oldlenp))
1126                                 return -EFAULT;
1127                         if (len) {
1128                                 if (len > table->maxlen)
1129                                         len = table->maxlen;
1130                                 if(copy_to_user(oldval, table->data, len))
1131                                         return -EFAULT;
1132                                 if(put_user(len, oldlenp))
1133                                         return -EFAULT;
1134                         }
1135                 }
1136                 if (newval && newlen) {
1137                         len = newlen;
1138                         if (len > table->maxlen)
1139                                 len = table->maxlen;
1140                         if(copy_from_user(table->data, newval, len))
1141                                 return -EFAULT;
1142                 }
1143         }
1144         return 0;
1145 }
1146
1147 /**
1148  * register_sysctl_table - register a sysctl hierarchy
1149  * @table: the top-level table structure
1150  * @insert_at_head: whether the entry should be inserted in front or at the end
1151  *
1152  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1153  * array. An entry with a ctl_name of 0 terminates the table. 
1154  *
1155  * The members of the &ctl_table structure are used as follows:
1156  *
1157  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1158  *            must be unique within that level of sysctl
1159  *
1160  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1161  *            enter a sysctl file
1162  *
1163  * data - a pointer to data for use by proc_handler
1164  *
1165  * maxlen - the maximum size in bytes of the data
1166  *
1167  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1168  *
1169  * child - a pointer to the child sysctl table if this entry is a directory, or
1170  *         %NULL.
1171  *
1172  * proc_handler - the text handler routine (described below)
1173  *
1174  * strategy - the strategy routine (described below)
1175  *
1176  * de - for internal use by the sysctl routines
1177  *
1178  * extra1, extra2 - extra pointers usable by the proc handler routines
1179  *
1180  * Leaf nodes in the sysctl tree will be represented by a single file
1181  * under /proc; non-leaf nodes will be represented by directories.
1182  *
1183  * sysctl(2) can automatically manage read and write requests through
1184  * the sysctl table.  The data and maxlen fields of the ctl_table
1185  * struct enable minimal validation of the values being written to be
1186  * performed, and the mode field allows minimal authentication.
1187  *
1188  * More sophisticated management can be enabled by the provision of a
1189  * strategy routine with the table entry.  This will be called before
1190  * any automatic read or write of the data is performed.
1191  *
1192  * The strategy routine may return
1193  *
1194  * < 0 - Error occurred (error is passed to user process)
1195  *
1196  * 0   - OK - proceed with automatic read or write.
1197  *
1198  * > 0 - OK - read or write has been done by the strategy routine, so
1199  *       return immediately.
1200  *
1201  * There must be a proc_handler routine for any terminal nodes
1202  * mirrored under /proc/sys (non-terminals are handled by a built-in
1203  * directory handler).  Several default handlers are available to
1204  * cover common cases -
1205  *
1206  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1207  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 
1208  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1209  *
1210  * It is the handler's job to read the input buffer from user memory
1211  * and process it. The handler should return 0 on success.
1212  *
1213  * This routine returns %NULL on a failure to register, and a pointer
1214  * to the table header on success.
1215  */
1216 struct ctl_table_header *register_sysctl_table(ctl_table * table, 
1217                                                int insert_at_head)
1218 {
1219         struct ctl_table_header *tmp;
1220         tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1221         if (!tmp)
1222                 return NULL;
1223         tmp->ctl_table = table;
1224         INIT_LIST_HEAD(&tmp->ctl_entry);
1225         if (insert_at_head)
1226                 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1227         else
1228                 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1229 #ifdef CONFIG_PROC_FS
1230         register_proc_table(table, proc_sys_root);
1231 #endif
1232         return tmp;
1233 }
1234
1235 /**
1236  * unregister_sysctl_table - unregister a sysctl table hierarchy
1237  * @header: the header returned from register_sysctl_table
1238  *
1239  * Unregisters the sysctl table and all children. proc entries may not
1240  * actually be removed until they are no longer used by anyone.
1241  */
1242 void unregister_sysctl_table(struct ctl_table_header * header)
1243 {
1244         list_del(&header->ctl_entry);
1245 #ifdef CONFIG_PROC_FS
1246         unregister_proc_table(header->ctl_table, proc_sys_root);
1247 #endif
1248         kfree(header);
1249 }
1250
1251 /*
1252  * /proc/sys support
1253  */
1254
1255 #ifdef CONFIG_PROC_FS
1256
1257 /* Scan the sysctl entries in table and add them all into /proc */
1258 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1259 {
1260         struct proc_dir_entry *de;
1261         int len;
1262         mode_t mode;
1263         
1264         for (; table->ctl_name; table++) {
1265                 /* Can't do anything without a proc name. */
1266                 if (!table->procname)
1267                         continue;
1268                 /* Maybe we can't do anything with it... */
1269                 if (!table->proc_handler && !table->child) {
1270                         printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1271                                 table->procname);
1272                         continue;
1273                 }
1274
1275                 len = strlen(table->procname);
1276                 mode = table->mode;
1277
1278                 de = NULL;
1279                 if (table->proc_handler)
1280                         mode |= S_IFREG;
1281                 else {
1282                         mode |= S_IFDIR;
1283                         for (de = root->subdir; de; de = de->next) {
1284                                 if (proc_match(len, table->procname, de))
1285                                         break;
1286                         }
1287                         /* If the subdir exists already, de is non-NULL */
1288                 }
1289
1290                 if (!de) {
1291                         de = create_proc_entry(table->procname, mode, root);
1292                         if (!de)
1293                                 continue;
1294                         de->data = (void *) table;
1295                         if (table->proc_handler)
1296                                 de->proc_fops = &proc_sys_file_operations;
1297                 }
1298                 table->de = de;
1299                 if (de->mode & S_IFDIR)
1300                         register_proc_table(table->child, de);
1301         }
1302 }
1303
1304 /*
1305  * Unregister a /proc sysctl table and any subdirectories.
1306  */
1307 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1308 {
1309         struct proc_dir_entry *de;
1310         for (; table->ctl_name; table++) {
1311                 if (!(de = table->de))
1312                         continue;
1313                 if (de->mode & S_IFDIR) {
1314                         if (!table->child) {
1315                                 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1316                                 continue;
1317                         }
1318                         unregister_proc_table(table->child, de);
1319
1320                         /* Don't unregister directories which still have entries.. */
1321                         if (de->subdir)
1322                                 continue;
1323                 }
1324
1325                 /* Don't unregister proc entries that are still being used.. */
1326                 if (atomic_read(&de->count))
1327                         continue;
1328
1329                 table->de = NULL;
1330                 remove_proc_entry(table->procname, root);
1331         }
1332 }
1333
1334 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1335                           size_t count, loff_t *ppos)
1336 {
1337         int op;
1338         struct proc_dir_entry *de;
1339         struct ctl_table *table;
1340         size_t res;
1341         ssize_t error;
1342         
1343         de = PDE(file->f_dentry->d_inode);
1344         if (!de || !de->data)
1345                 return -ENOTDIR;
1346         table = (struct ctl_table *) de->data;
1347         if (!table || !table->proc_handler)
1348                 return -ENOTDIR;
1349         op = (write ? 002 : 004);
1350         if (ctl_perm(table, op))
1351                 return -EPERM;
1352         
1353         res = count;
1354
1355         /*
1356          * FIXME: we need to pass on ppos to the handler.
1357          */
1358
1359         error = (*table->proc_handler) (table, write, file, buf, &res);
1360         if (error)
1361                 return error;
1362         return res;
1363 }
1364
1365 static int proc_opensys(struct inode *inode, struct file *file)
1366 {
1367         if (file->f_mode & FMODE_WRITE) {
1368                 /*
1369                  * sysctl entries that are not writable,
1370                  * are _NOT_ writable, capabilities or not.
1371                  */
1372                 if (!(inode->i_mode & S_IWUSR))
1373                         return -EPERM;
1374         }
1375
1376         return 0;
1377 }
1378
1379 static ssize_t proc_readsys(struct file * file, char __user * buf,
1380                             size_t count, loff_t *ppos)
1381 {
1382         return do_rw_proc(0, file, buf, count, ppos);
1383 }
1384
1385 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1386                              size_t count, loff_t *ppos)
1387 {
1388         return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1389 }
1390
1391 /**
1392  * proc_dostring - read a string sysctl
1393  * @table: the sysctl table
1394  * @write: %TRUE if this is a write to the sysctl file
1395  * @filp: the file structure
1396  * @buffer: the user buffer
1397  * @lenp: the size of the user buffer
1398  *
1399  * Reads/writes a string from/to the user buffer. If the kernel
1400  * buffer provided is not large enough to hold the string, the
1401  * string is truncated. The copied string is %NULL-terminated.
1402  * If the string is being read by the user process, it is copied
1403  * and a newline '\n' is added. It is truncated if the buffer is
1404  * not large enough.
1405  *
1406  * Returns 0 on success.
1407  */
1408 int proc_dostring(ctl_table *table, int write, struct file *filp,
1409                   void __user *buffer, size_t *lenp)
1410 {
1411         size_t len;
1412         char __user *p;
1413         char c;
1414         
1415         if (!table->data || !table->maxlen || !*lenp ||
1416             (filp->f_pos && !write)) {
1417                 *lenp = 0;
1418                 return 0;
1419         }
1420         
1421         if (write) {
1422                 len = 0;
1423                 p = buffer;
1424                 while (len < *lenp) {
1425                         if (get_user(c, p++))
1426                                 return -EFAULT;
1427                         if (c == 0 || c == '\n')
1428                                 break;
1429                         len++;
1430                 }
1431                 if (len >= table->maxlen)
1432                         len = table->maxlen-1;
1433                 if(copy_from_user(table->data, buffer, len))
1434                         return -EFAULT;
1435                 ((char *) table->data)[len] = 0;
1436                 filp->f_pos += *lenp;
1437         } else {
1438                 len = strlen(table->data);
1439                 if (len > table->maxlen)
1440                         len = table->maxlen;
1441                 if (len > *lenp)
1442                         len = *lenp;
1443                 if (len)
1444                         if(copy_to_user(buffer, table->data, len))
1445                                 return -EFAULT;
1446                 if (len < *lenp) {
1447                         if(put_user('\n', ((char __user *) buffer) + len))
1448                                 return -EFAULT;
1449                         len++;
1450                 }
1451                 *lenp = len;
1452                 filp->f_pos += len;
1453         }
1454         return 0;
1455 }
1456
1457 /*
1458  *      Special case of dostring for the UTS structure. This has locks
1459  *      to observe. Should this be in kernel/sys.c ????
1460  */
1461  
1462 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1463                   void __user *buffer, size_t *lenp)
1464 {
1465         int r;
1466
1467         if (!write) {
1468                 down_read(&uts_sem);
1469                 r=proc_dostring(table,0,filp,buffer,lenp);
1470                 up_read(&uts_sem);
1471         } else {
1472                 down_write(&uts_sem);
1473                 r=proc_dostring(table,1,filp,buffer,lenp);
1474                 up_write(&uts_sem);
1475         }
1476         return r;
1477 }
1478
1479 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1480                                  int *valp,
1481                                  int write, void *data)
1482 {
1483         if (write) {
1484                 *valp = *negp ? -*lvalp : *lvalp;
1485         } else {
1486                 int val = *valp;
1487                 if (val < 0) {
1488                         *negp = -1;
1489                         *lvalp = (unsigned long)-val;
1490                 } else {
1491                         *negp = 0;
1492                         *lvalp = (unsigned long)val;
1493                 }
1494         }
1495         return 0;
1496 }
1497
1498 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1499                   void __user *buffer, size_t *lenp, 
1500                   int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1501                               int write, void *data),
1502                   void *data)
1503 {
1504 #define TMPBUFLEN 20
1505         int *i, vleft, first=1, neg, val;
1506         unsigned long lval;
1507         size_t left, len;
1508         
1509         char buf[TMPBUFLEN], *p;
1510         char __user *s = buffer;
1511         
1512         if (!table->data || !table->maxlen || !*lenp ||
1513             (filp->f_pos && !write)) {
1514                 *lenp = 0;
1515                 return 0;
1516         }
1517         
1518         i = (int *) table->data;
1519         vleft = table->maxlen / sizeof(*i);
1520         left = *lenp;
1521
1522         if (!conv)
1523                 conv = do_proc_dointvec_conv;
1524
1525         for (; left && vleft--; i++, first=0) {
1526                 if (write) {
1527                         while (left) {
1528                                 char c;
1529                                 if (get_user(c, s))
1530                                         return -EFAULT;
1531                                 if (!isspace(c))
1532                                         break;
1533                                 left--;
1534                                 s++;
1535                         }
1536                         if (!left)
1537                                 break;
1538                         neg = 0;
1539                         len = left;
1540                         if (len > sizeof(buf) - 1)
1541                                 len = sizeof(buf) - 1;
1542                         if (copy_from_user(buf, s, len))
1543                                 return -EFAULT;
1544                         buf[len] = 0;
1545                         p = buf;
1546                         if (*p == '-' && left > 1) {
1547                                 neg = 1;
1548                                 left--, p++;
1549                         }
1550                         if (*p < '0' || *p > '9')
1551                                 break;
1552
1553                         lval = simple_strtoul(p, &p, 0);
1554
1555                         len = p-buf;
1556                         if ((len < left) && *p && !isspace(*p))
1557                                 break;
1558                         if (neg)
1559                                 val = -val;
1560                         s += len;
1561                         left -= len;
1562
1563                         if (conv(&neg, &lval, i, 1, data))
1564                                 break;
1565                 } else {
1566                         p = buf;
1567                         if (!first)
1568                                 *p++ = '\t';
1569         
1570                         if (conv(&neg, &lval, i, 0, data))
1571                                 break;
1572
1573                         sprintf(p, "%s%lu", neg ? "-" : "", lval);
1574                         len = strlen(buf);
1575                         if (len > left)
1576                                 len = left;
1577                         if(copy_to_user(s, buf, len))
1578                                 return -EFAULT;
1579                         left -= len;
1580                         s += len;
1581                 }
1582         }
1583
1584         if (!write && !first && left) {
1585                 if(put_user('\n', s))
1586                         return -EFAULT;
1587                 left--, s++;
1588         }
1589         if (write) {
1590                 while (left) {
1591                         char c;
1592                         if (get_user(c, s++))
1593                                 return -EFAULT;
1594                         if (!isspace(c))
1595                                 break;
1596                         left--;
1597                 }
1598         }
1599         if (write && first)
1600                 return -EINVAL;
1601         *lenp -= left;
1602         filp->f_pos += *lenp;
1603         return 0;
1604 #undef TMPBUFLEN
1605 }
1606
1607 /**
1608  * proc_dointvec - read a vector of integers
1609  * @table: the sysctl table
1610  * @write: %TRUE if this is a write to the sysctl file
1611  * @filp: the file structure
1612  * @buffer: the user buffer
1613  * @lenp: the size of the user buffer
1614  *
1615  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1616  * values from/to the user buffer, treated as an ASCII string. 
1617  *
1618  * Returns 0 on success.
1619  */
1620 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1621                      void __user *buffer, size_t *lenp)
1622 {
1623     return do_proc_dointvec(table,write,filp,buffer,lenp,
1624                             NULL,NULL);
1625 }
1626
1627 #define OP_SET  0
1628 #define OP_AND  1
1629 #define OP_OR   2
1630 #define OP_MAX  3
1631 #define OP_MIN  4
1632
1633 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1634                                       int *valp,
1635                                       int write, void *data)
1636 {
1637         int op = *(int *)data;
1638         if (write) {
1639                 int val = *negp ? -*lvalp : *lvalp;
1640                 switch(op) {
1641                 case OP_SET:    *valp = val; break;
1642                 case OP_AND:    *valp &= val; break;
1643                 case OP_OR:     *valp |= val; break;
1644                 case OP_MAX:    if(*valp < val)
1645                                         *valp = val;
1646                                 break;
1647                 case OP_MIN:    if(*valp > val)
1648                                 *valp = val;
1649                                 break;
1650                 }
1651         } else {
1652                 int val = *valp;
1653                 if (val < 0) {
1654                         *negp = -1;
1655                         *lvalp = (unsigned long)-val;
1656                 } else {
1657                         *negp = 0;
1658                         *lvalp = (unsigned long)val;
1659                 }
1660         }
1661         return 0;
1662 }
1663
1664 /*
1665  *      init may raise the set.
1666  */
1667  
1668 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1669                         void __user *buffer, size_t *lenp)
1670 {
1671         int op;
1672
1673         if (!capable(CAP_SYS_MODULE)) {
1674                 return -EPERM;
1675         }
1676
1677         op = (current->pid == 1) ? OP_SET : OP_AND;
1678         return do_proc_dointvec(table,write,filp,buffer,lenp,
1679                                 do_proc_dointvec_bset_conv,&op);
1680 }
1681
1682 struct do_proc_dointvec_minmax_conv_param {
1683         int *min;
1684         int *max;
1685 };
1686
1687 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 
1688                                         int *valp, 
1689                                         int write, void *data)
1690 {
1691         struct do_proc_dointvec_minmax_conv_param *param = data;
1692         if (write) {
1693                 int val = *negp ? -*lvalp : *lvalp;
1694                 if ((param->min && *param->min > val) ||
1695                     (param->max && *param->max < val))
1696                         return -EINVAL;
1697                 *valp = val;
1698         } else {
1699                 int val = *valp;
1700                 if (val < 0) {
1701                         *negp = -1;
1702                         *lvalp = (unsigned long)-val;
1703                 } else {
1704                         *negp = 0;
1705                         *lvalp = (unsigned long)val;
1706                 }
1707         }
1708         return 0;
1709 }
1710
1711 /**
1712  * proc_dointvec_minmax - read a vector of integers with min/max values
1713  * @table: the sysctl table
1714  * @write: %TRUE if this is a write to the sysctl file
1715  * @filp: the file structure
1716  * @buffer: the user buffer
1717  * @lenp: the size of the user buffer
1718  *
1719  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1720  * values from/to the user buffer, treated as an ASCII string.
1721  *
1722  * This routine will ensure the values are within the range specified by
1723  * table->extra1 (min) and table->extra2 (max).
1724  *
1725  * Returns 0 on success.
1726  */
1727 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1728                   void __user *buffer, size_t *lenp)
1729 {
1730         struct do_proc_dointvec_minmax_conv_param param = {
1731                 .min = (int *) table->extra1,
1732                 .max = (int *) table->extra2,
1733         };
1734         return do_proc_dointvec(table, write, filp, buffer, lenp,
1735                                 do_proc_dointvec_minmax_conv, &param);
1736 }
1737
1738 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1739                                      struct file *filp,
1740                                      void __user *buffer, size_t *lenp,
1741                                      unsigned long convmul,
1742                                      unsigned long convdiv)
1743 {
1744 #define TMPBUFLEN 20
1745         unsigned long *i, *min, *max, val;
1746         int vleft, first=1, neg;
1747         size_t len, left;
1748         char buf[TMPBUFLEN], *p;
1749         char __user *s = buffer;
1750         
1751         if (!table->data || !table->maxlen || !*lenp ||
1752             (filp->f_pos && !write)) {
1753                 *lenp = 0;
1754                 return 0;
1755         }
1756         
1757         i = (unsigned long *) table->data;
1758         min = (unsigned long *) table->extra1;
1759         max = (unsigned long *) table->extra2;
1760         vleft = table->maxlen / sizeof(unsigned long);
1761         left = *lenp;
1762         
1763         for (; left && vleft--; i++, min++, max++, first=0) {
1764                 if (write) {
1765                         while (left) {
1766                                 char c;
1767                                 if (get_user(c, s))
1768                                         return -EFAULT;
1769                                 if (!isspace(c))
1770                                         break;
1771                                 left--;
1772                                 s++;
1773                         }
1774                         if (!left)
1775                                 break;
1776                         neg = 0;
1777                         len = left;
1778                         if (len > TMPBUFLEN-1)
1779                                 len = TMPBUFLEN-1;
1780                         if (copy_from_user(buf, s, len))
1781                                 return -EFAULT;
1782                         buf[len] = 0;
1783                         p = buf;
1784                         if (*p == '-' && left > 1) {
1785                                 neg = 1;
1786                                 left--, p++;
1787                         }
1788                         if (*p < '0' || *p > '9')
1789                                 break;
1790                         val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1791                         len = p-buf;
1792                         if ((len < left) && *p && !isspace(*p))
1793                                 break;
1794                         if (neg)
1795                                 val = -val;
1796                         s += len;
1797                         left -= len;
1798
1799                         if(neg)
1800                                 continue;
1801                         if ((min && val < *min) || (max && val > *max))
1802                                 continue;
1803                         *i = val;
1804                 } else {
1805                         p = buf;
1806                         if (!first)
1807                                 *p++ = '\t';
1808                         sprintf(p, "%lu", convdiv * (*i) / convmul);
1809                         len = strlen(buf);
1810                         if (len > left)
1811                                 len = left;
1812                         if(copy_to_user(s, buf, len))
1813                                 return -EFAULT;
1814                         left -= len;
1815                         s += len;
1816                 }
1817         }
1818
1819         if (!write && !first && left) {
1820                 if(put_user('\n', s))
1821                         return -EFAULT;
1822                 left--, s++;
1823         }
1824         if (write) {
1825                 while (left) {
1826                         char c;
1827                         if (get_user(c, s++))
1828                                 return -EFAULT;
1829                         if (!isspace(c))
1830                                 break;
1831                         left--;
1832                 }
1833         }
1834         if (write && first)
1835                 return -EINVAL;
1836         *lenp -= left;
1837         filp->f_pos += *lenp;
1838         return 0;
1839 #undef TMPBUFLEN
1840 }
1841
1842 /**
1843  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1844  * @table: the sysctl table
1845  * @write: %TRUE if this is a write to the sysctl file
1846  * @filp: the file structure
1847  * @buffer: the user buffer
1848  * @lenp: the size of the user buffer
1849  *
1850  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1851  * values from/to the user buffer, treated as an ASCII string.
1852  *
1853  * This routine will ensure the values are within the range specified by
1854  * table->extra1 (min) and table->extra2 (max).
1855  *
1856  * Returns 0 on success.
1857  */
1858 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1859                            void __user *buffer, size_t *lenp)
1860 {
1861     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, 1l, 1l);
1862 }
1863
1864 /**
1865  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1866  * @table: the sysctl table
1867  * @write: %TRUE if this is a write to the sysctl file
1868  * @filp: the file structure
1869  * @buffer: the user buffer
1870  * @lenp: the size of the user buffer
1871  *
1872  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1873  * values from/to the user buffer, treated as an ASCII string. The values
1874  * are treated as milliseconds, and converted to jiffies when they are stored.
1875  *
1876  * This routine will ensure the values are within the range specified by
1877  * table->extra1 (min) and table->extra2 (max).
1878  *
1879  * Returns 0 on success.
1880  */
1881 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1882                                       struct file *filp,
1883                                       void __user *buffer, size_t *lenp)
1884 {
1885     return do_proc_doulongvec_minmax(table, write, filp, buffer,
1886                                      lenp, HZ, 1000l);
1887 }
1888
1889
1890 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1891                                          int *valp,
1892                                          int write, void *data)
1893 {
1894         if (write) {
1895                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1896         } else {
1897                 int val = *valp;
1898                 unsigned long lval;
1899                 if (val < 0) {
1900                         *negp = -1;
1901                         lval = (unsigned long)-val;
1902                 } else {
1903                         *negp = 0;
1904                         lval = (unsigned long)val;
1905                 }
1906                 *lvalp = lval / HZ;
1907         }
1908         return 0;
1909 }
1910
1911 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1912                                                 int *valp,
1913                                                 int write, void *data)
1914 {
1915         if (write) {
1916                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1917         } else {
1918                 int val = *valp;
1919                 unsigned long lval;
1920                 if (val < 0) {
1921                         *negp = -1;
1922                         lval = (unsigned long)-val;
1923                 } else {
1924                         *negp = 0;
1925                         lval = (unsigned long)val;
1926                 }
1927                 *lvalp = jiffies_to_clock_t(lval);
1928         }
1929         return 0;
1930 }
1931
1932 /**
1933  * proc_dointvec_jiffies - read a vector of integers as seconds
1934  * @table: the sysctl table
1935  * @write: %TRUE if this is a write to the sysctl file
1936  * @filp: the file structure
1937  * @buffer: the user buffer
1938  * @lenp: the size of the user buffer
1939  *
1940  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1941  * values from/to the user buffer, treated as an ASCII string. 
1942  * The values read are assumed to be in seconds, and are converted into
1943  * jiffies.
1944  *
1945  * Returns 0 on success.
1946  */
1947 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1948                           void __user *buffer, size_t *lenp)
1949 {
1950     return do_proc_dointvec(table,write,filp,buffer,lenp,
1951                             do_proc_dointvec_jiffies_conv,NULL);
1952 }
1953
1954 /**
1955  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1956  * @table: the sysctl table
1957  * @write: %TRUE if this is a write to the sysctl file
1958  * @filp: the file structure
1959  * @buffer: the user buffer
1960  * @lenp: the size of the user buffer
1961  *
1962  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1963  * values from/to the user buffer, treated as an ASCII string. 
1964  * The values read are assumed to be in 1/USER_HZ seconds, and 
1965  * are converted into jiffies.
1966  *
1967  * Returns 0 on success.
1968  */
1969 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1970                                  void __user *buffer, size_t *lenp)
1971 {
1972     return do_proc_dointvec(table,write,filp,buffer,lenp,
1973                             do_proc_dointvec_userhz_jiffies_conv,NULL);
1974 }
1975
1976 #else /* CONFIG_PROC_FS */
1977
1978 int proc_dostring(ctl_table *table, int write, struct file *filp,
1979                   void *buffer, size_t *lenp)
1980 {
1981         return -ENOSYS;
1982 }
1983
1984 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1985                             void *buffer, size_t *lenp)
1986 {
1987         return -ENOSYS;
1988 }
1989
1990 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1991                   void *buffer, size_t *lenp)
1992 {
1993         return -ENOSYS;
1994 }
1995
1996 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1997                         void *buffer, size_t *lenp)
1998 {
1999         return -ENOSYS;
2000 }
2001
2002 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2003                     void *buffer, size_t *lenp)
2004 {
2005         return -ENOSYS;
2006 }
2007
2008 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2009                     void *buffer, size_t *lenp)
2010 {
2011         return -ENOSYS;
2012 }
2013
2014 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2015                     void *buffer, size_t *lenp)
2016 {
2017         return -ENOSYS;
2018 }
2019
2020 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2021                     void *buffer, size_t *lenp)
2022 {
2023         return -ENOSYS;
2024 }
2025
2026 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2027                                       struct file *filp,
2028                                       void *buffer, size_t *lenp)
2029 {
2030     return -ENOSYS;
2031 }
2032
2033
2034 #endif /* CONFIG_PROC_FS */
2035
2036
2037 /*
2038  * General sysctl support routines 
2039  */
2040
2041 /* The generic string strategy routine: */
2042 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2043                   void __user *oldval, size_t __user *oldlenp,
2044                   void __user *newval, size_t newlen, void **context)
2045 {
2046         size_t l, len;
2047         
2048         if (!table->data || !table->maxlen) 
2049                 return -ENOTDIR;
2050         
2051         if (oldval && oldlenp) {
2052                 if (get_user(len, oldlenp))
2053                         return -EFAULT;
2054                 if (len) {
2055                         l = strlen(table->data);
2056                         if (len > l) len = l;
2057                         if (len >= table->maxlen)
2058                                 len = table->maxlen;
2059                         if(copy_to_user(oldval, table->data, len))
2060                                 return -EFAULT;
2061                         if(put_user(0, ((char __user *) oldval) + len))
2062                                 return -EFAULT;
2063                         if(put_user(len, oldlenp))
2064                                 return -EFAULT;
2065                 }
2066         }
2067         if (newval && newlen) {
2068                 len = newlen;
2069                 if (len > table->maxlen)
2070                         len = table->maxlen;
2071                 if(copy_from_user(table->data, newval, len))
2072                         return -EFAULT;
2073                 if (len == table->maxlen)
2074                         len--;
2075                 ((char *) table->data)[len] = 0;
2076         }
2077         return 0;
2078 }
2079
2080 /*
2081  * This function makes sure that all of the integers in the vector
2082  * are between the minimum and maximum values given in the arrays
2083  * table->extra1 and table->extra2, respectively.
2084  */
2085 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2086                 void __user *oldval, size_t __user *oldlenp,
2087                 void __user *newval, size_t newlen, void **context)
2088 {
2089
2090         if (newval && newlen) {
2091                 int __user *vec = (int __user *) newval;
2092                 int *min = (int *) table->extra1;
2093                 int *max = (int *) table->extra2;
2094                 size_t length;
2095                 int i;
2096
2097                 if (newlen % sizeof(int) != 0)
2098                         return -EINVAL;
2099
2100                 if (!table->extra1 && !table->extra2)
2101                         return 0;
2102
2103                 if (newlen > table->maxlen)
2104                         newlen = table->maxlen;
2105                 length = newlen / sizeof(int);
2106
2107                 for (i = 0; i < length; i++) {
2108                         int value;
2109                         if (get_user(value, vec + i))
2110                                 return -EFAULT;
2111                         if (min && value < min[i])
2112                                 return -EINVAL;
2113                         if (max && value > max[i])
2114                                 return -EINVAL;
2115                 }
2116         }
2117         return 0;
2118 }
2119
2120 /* Strategy function to convert jiffies to seconds */ 
2121 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2122                 void __user *oldval, size_t __user *oldlenp,
2123                 void __user *newval, size_t newlen, void **context)
2124 {
2125         if (oldval) {
2126                 size_t olen;
2127                 if (oldlenp) { 
2128                         if (get_user(olen, oldlenp))
2129                                 return -EFAULT;
2130                         if (olen!=sizeof(int))
2131                                 return -EINVAL; 
2132                 }
2133                 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2134                     (oldlenp && put_user(sizeof(int),oldlenp)))
2135                         return -EFAULT;
2136         }
2137         if (newval && newlen) { 
2138                 int new;
2139                 if (newlen != sizeof(int))
2140                         return -EINVAL; 
2141                 if (get_user(new, (int __user *)newval))
2142                         return -EFAULT;
2143                 *(int *)(table->data) = new*HZ; 
2144         }
2145         return 1;
2146 }
2147
2148
2149 #else /* CONFIG_SYSCTL */
2150
2151
2152 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2153 {
2154         return -ENOSYS;
2155 }
2156
2157 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2158                   void __user *oldval, size_t __user *oldlenp,
2159                   void __user *newval, size_t newlen, void **context)
2160 {
2161         return -ENOSYS;
2162 }
2163
2164 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2165                 void __user *oldval, size_t __user *oldlenp,
2166                 void __user *newval, size_t newlen, void **context)
2167 {
2168         return -ENOSYS;
2169 }
2170
2171 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2172                 void __user *oldval, size_t __user *oldlenp,
2173                 void __user *newval, size_t newlen, void **context)
2174 {
2175         return -ENOSYS;
2176 }
2177
2178 int proc_dostring(ctl_table *table, int write, struct file *filp,
2179                   void __user *buffer, size_t *lenp)
2180 {
2181         return -ENOSYS;
2182 }
2183
2184 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2185                   void __user *buffer, size_t *lenp)
2186 {
2187         return -ENOSYS;
2188 }
2189
2190 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2191                         void __user *buffer, size_t *lenp)
2192 {
2193         return -ENOSYS;
2194 }
2195
2196 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2197                     void __user *buffer, size_t *lenp)
2198 {
2199         return -ENOSYS;
2200 }
2201
2202 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2203                           void *buffer, size_t *lenp)
2204 {
2205         return -ENOSYS;
2206 }
2207
2208 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2209                           void *buffer, size_t *lenp)
2210 {
2211         return -ENOSYS;
2212 }
2213
2214 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2215                     void __user *buffer, size_t *lenp)
2216 {
2217         return -ENOSYS;
2218 }
2219
2220 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2221                                       struct file *filp,
2222                                       void __user *buffer, size_t *lenp)
2223 {
2224     return -ENOSYS;
2225 }
2226
2227 struct ctl_table_header * register_sysctl_table(ctl_table * table, 
2228                                                 int insert_at_head)
2229 {
2230         return 0;
2231 }
2232
2233 void unregister_sysctl_table(struct ctl_table_header * table)
2234 {
2235 }
2236
2237 #endif /* CONFIG_SYSCTL */
2238
2239 /*
2240  * No sense putting this after each symbol definition, twice,
2241  * exception granted :-)
2242  */
2243 EXPORT_SYMBOL(proc_dointvec);
2244 EXPORT_SYMBOL(proc_dointvec_jiffies);
2245 EXPORT_SYMBOL(proc_dointvec_minmax);
2246 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2247 EXPORT_SYMBOL(proc_dostring);
2248 EXPORT_SYMBOL(proc_doulongvec_minmax);
2249 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2250 EXPORT_SYMBOL(register_sysctl_table);
2251 EXPORT_SYMBOL(sysctl_intvec);
2252 EXPORT_SYMBOL(sysctl_jiffies);
2253 EXPORT_SYMBOL(sysctl_string);
2254 EXPORT_SYMBOL(unregister_sysctl_table);