Merge to Fedora kernel-2.6.7-1.492
[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 <linux/dcache.h>
43
44 #include <asm/uaccess.h>
45
46 #ifdef CONFIG_ROOT_NFS
47 #include <linux/nfs_fs.h>
48 #endif
49
50 #if defined(CONFIG_SYSCTL)
51
52 /* External variables not in a header file. */
53 extern int panic_timeout;
54 extern int C_A_D;
55 extern int sysctl_overcommit_memory;
56 extern int sysctl_overcommit_ratio;
57 extern int max_threads;
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         = sizeof(system_utsname.sysname),
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         = sizeof(system_utsname.release),
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         = sizeof(system_utsname.version),
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         = sizeof(system_utsname.nodename),
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         = sizeof(system_utsname.domainname),
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         = KMOD_PATH_LEN,
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         = KMOD_PATH_LEN,
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 #ifdef CONFIG_SYSVIPC
500         {
501                 .ctl_name       = KERN_SHMMAX,
502                 .procname       = "shmmax",
503                 .data           = &shm_ctlmax,
504                 .maxlen         = sizeof (size_t),
505                 .mode           = 0644,
506                 .proc_handler   = &proc_doulongvec_minmax,
507         },
508         {
509                 .ctl_name       = KERN_SHMALL,
510                 .procname       = "shmall",
511                 .data           = &shm_ctlall,
512                 .maxlen         = sizeof (size_t),
513                 .mode           = 0644,
514                 .proc_handler   = &proc_doulongvec_minmax,
515         },
516         {
517                 .ctl_name       = KERN_SHMMNI,
518                 .procname       = "shmmni",
519                 .data           = &shm_ctlmni,
520                 .maxlen         = sizeof (int),
521                 .mode           = 0644,
522                 .proc_handler   = &proc_dointvec,
523         },
524         {
525                 .ctl_name       = KERN_MSGMAX,
526                 .procname       = "msgmax",
527                 .data           = &msg_ctlmax,
528                 .maxlen         = sizeof (int),
529                 .mode           = 0644,
530                 .proc_handler   = &proc_dointvec,
531         },
532         {
533                 .ctl_name       = KERN_MSGMNI,
534                 .procname       = "msgmni",
535                 .data           = &msg_ctlmni,
536                 .maxlen         = sizeof (int),
537                 .mode           = 0644,
538                 .proc_handler   = &proc_dointvec,
539         },
540         {
541                 .ctl_name       = KERN_MSGMNB,
542                 .procname       =  "msgmnb",
543                 .data           = &msg_ctlmnb,
544                 .maxlen         = sizeof (int),
545                 .mode           = 0644,
546                 .proc_handler   = &proc_dointvec,
547         },
548         {
549                 .ctl_name       = KERN_SEM,
550                 .procname       = "sem",
551                 .data           = &sem_ctls,
552                 .maxlen         = 4*sizeof (int),
553                 .mode           = 0644,
554                 .proc_handler   = &proc_dointvec,
555         },
556 #endif
557 #ifdef CONFIG_MAGIC_SYSRQ
558         {
559                 .ctl_name       = KERN_SYSRQ,
560                 .procname       = "sysrq",
561                 .data           = &sysrq_enabled,
562                 .maxlen         = sizeof (int),
563                 .mode           = 0644,
564                 .proc_handler   = &proc_dointvec,
565         },
566 #endif
567         {
568                 .ctl_name       = KERN_CADPID,
569                 .procname       = "cad_pid",
570                 .data           = &cad_pid,
571                 .maxlen         = sizeof (int),
572                 .mode           = 0600,
573                 .proc_handler   = &proc_dointvec,
574         },
575         {
576                 .ctl_name       = KERN_MAX_THREADS,
577                 .procname       = "threads-max",
578                 .data           = &max_threads,
579                 .maxlen         = sizeof(int),
580                 .mode           = 0644,
581                 .proc_handler   = &proc_dointvec,
582         },
583         {
584                 .ctl_name       = KERN_RANDOM,
585                 .procname       = "random",
586                 .mode           = 0555,
587                 .child          = random_table,
588         },
589 #ifdef CONFIG_UNIX98_PTYS
590         {
591                 .ctl_name       = KERN_PTY,
592                 .procname       = "pty",
593                 .mode           = 0555,
594                 .child          = pty_table,
595         },
596 #endif
597         {
598                 .ctl_name       = KERN_OVERFLOWUID,
599                 .procname       = "overflowuid",
600                 .data           = &overflowuid,
601                 .maxlen         = sizeof(int),
602                 .mode           = 0644,
603                 .proc_handler   = &proc_dointvec_minmax,
604                 .strategy       = &sysctl_intvec,
605                 .extra1         = &minolduid,
606                 .extra2         = &maxolduid,
607         },
608         {
609                 .ctl_name       = KERN_OVERFLOWGID,
610                 .procname       = "overflowgid",
611                 .data           = &overflowgid,
612                 .maxlen         = sizeof(int),
613                 .mode           = 0644,
614                 .proc_handler   = &proc_dointvec_minmax,
615                 .strategy       = &sysctl_intvec,
616                 .extra1         = &minolduid,
617                 .extra2         = &maxolduid,
618         },
619 #ifdef CONFIG_ARCH_S390
620 #ifdef CONFIG_MATHEMU
621         {
622                 .ctl_name       = KERN_IEEE_EMULATION_WARNINGS,
623                 .procname       = "ieee_emulation_warnings",
624                 .data           = &sysctl_ieee_emulation_warnings,
625                 .maxlen         = sizeof(int),
626                 .mode           = 0644,
627                 .proc_handler   = &proc_dointvec,
628         },
629 #endif
630 #ifdef CONFIG_NO_IDLE_HZ
631         {
632                 .ctl_name       = KERN_HZ_TIMER,
633                 .procname       = "hz_timer",
634                 .data           = &sysctl_hz_timer,
635                 .maxlen         = sizeof(int),
636                 .mode           = 0644,
637                 .proc_handler   = &proc_dointvec,
638         },
639 #endif
640         {
641                 .ctl_name       = KERN_S390_USER_DEBUG_LOGGING,
642                 .procname       = "userprocess_debug",
643                 .data           = &sysctl_userprocess_debug,
644                 .maxlen         = sizeof(int),
645                 .mode           = 0644,
646                 .proc_handler   = &proc_dointvec,
647         },
648 #endif
649         {
650                 .ctl_name       = KERN_PIDMAX,
651                 .procname       = "pid_max",
652                 .data           = &pid_max,
653                 .maxlen         = sizeof (int),
654                 .mode           = 0644,
655                 .proc_handler   = &proc_dointvec,
656         },
657         {
658                 .ctl_name       = KERN_PANIC_ON_OOPS,
659                 .procname       = "panic_on_oops",
660                 .data           = &panic_on_oops,
661                 .maxlen         = sizeof(int),
662                 .mode           = 0644,
663                 .proc_handler   = &proc_dointvec,
664         },
665         {
666                 .ctl_name       = KERN_PRINTK_RATELIMIT,
667                 .procname       = "printk_ratelimit",
668                 .data           = &printk_ratelimit_jiffies,
669                 .maxlen         = sizeof(int),
670                 .mode           = 0644,
671                 .proc_handler   = &proc_dointvec_jiffies,
672                 .strategy       = &sysctl_jiffies,
673         },
674         {
675                 .ctl_name       = KERN_PRINTK_RATELIMIT_BURST,
676                 .procname       = "printk_ratelimit_burst",
677                 .data           = &printk_ratelimit_burst,
678                 .maxlen         = sizeof(int),
679                 .mode           = 0644,
680                 .proc_handler   = &proc_dointvec,
681         },
682         {
683                 .ctl_name       = KERN_NGROUPS_MAX,
684                 .procname       = "ngroups_max",
685                 .data           = &ngroups_max,
686                 .maxlen         = sizeof (int),
687                 .mode           = 0444,
688                 .proc_handler   = &proc_dointvec,
689         },
690         { .ctl_name = 0 }
691 };
692
693 /* Constants for minimum and maximum testing in vm_table.
694    We use these as one-element integer vectors. */
695 static int zero;
696 static int one_hundred = 100;
697
698
699 static ctl_table vm_table[] = {
700         {
701                 .ctl_name       = VM_OVERCOMMIT_MEMORY,
702                 .procname       = "overcommit_memory",
703                 .data           = &sysctl_overcommit_memory,
704                 .maxlen         = sizeof(sysctl_overcommit_memory),
705                 .mode           = 0644,
706                 .proc_handler   = &proc_dointvec,
707         },
708         {
709                 .ctl_name       = VM_OVERCOMMIT_RATIO,
710                 .procname       = "overcommit_ratio",
711                 .data           = &sysctl_overcommit_ratio,
712                 .maxlen         = sizeof(sysctl_overcommit_ratio),
713                 .mode           = 0644,
714                 .proc_handler   = &proc_dointvec,
715         },
716         {
717                 .ctl_name       = VM_PAGE_CLUSTER,
718                 .procname       = "page-cluster", 
719                 .data           = &page_cluster,
720                 .maxlen         = sizeof(int),
721                 .mode           = 0644,
722                 .proc_handler   = &proc_dointvec,
723         },
724         {
725                 .ctl_name       = VM_DIRTY_BACKGROUND,
726                 .procname       = "dirty_background_ratio",
727                 .data           = &dirty_background_ratio,
728                 .maxlen         = sizeof(dirty_background_ratio),
729                 .mode           = 0644,
730                 .proc_handler   = &proc_dointvec_minmax,
731                 .strategy       = &sysctl_intvec,
732                 .extra1         = &zero,
733                 .extra2         = &one_hundred,
734         },
735         {
736                 .ctl_name       = VM_DIRTY_RATIO,
737                 .procname       = "dirty_ratio",
738                 .data           = &vm_dirty_ratio,
739                 .maxlen         = sizeof(vm_dirty_ratio),
740                 .mode           = 0644,
741                 .proc_handler   = &proc_dointvec_minmax,
742                 .strategy       = &sysctl_intvec,
743                 .extra1         = &zero,
744                 .extra2         = &one_hundred,
745         },
746         {
747                 .ctl_name       = VM_DIRTY_WB_CS,
748                 .procname       = "dirty_writeback_centisecs",
749                 .data           = &dirty_writeback_centisecs,
750                 .maxlen         = sizeof(dirty_writeback_centisecs),
751                 .mode           = 0644,
752                 .proc_handler   = &dirty_writeback_centisecs_handler,
753         },
754         {
755                 .ctl_name       = VM_DIRTY_EXPIRE_CS,
756                 .procname       = "dirty_expire_centisecs",
757                 .data           = &dirty_expire_centisecs,
758                 .maxlen         = sizeof(dirty_expire_centisecs),
759                 .mode           = 0644,
760                 .proc_handler   = &proc_dointvec,
761         },
762         {
763                 .ctl_name       = VM_NR_PDFLUSH_THREADS,
764                 .procname       = "nr_pdflush_threads",
765                 .data           = &nr_pdflush_threads,
766                 .maxlen         = sizeof nr_pdflush_threads,
767                 .mode           = 0444 /* read-only*/,
768                 .proc_handler   = &proc_dointvec,
769         },
770         {
771                 .ctl_name       = VM_SWAPPINESS,
772                 .procname       = "swappiness",
773                 .data           = &vm_swappiness,
774                 .maxlen         = sizeof(vm_swappiness),
775                 .mode           = 0644,
776                 .proc_handler   = &proc_dointvec_minmax,
777                 .strategy       = &sysctl_intvec,
778                 .extra1         = &zero,
779                 .extra2         = &one_hundred,
780         },
781 #ifdef CONFIG_HUGETLB_PAGE
782          {
783                 .ctl_name       = VM_HUGETLB_PAGES,
784                 .procname       = "nr_hugepages",
785                 .data           = &max_huge_pages,
786                 .maxlen         = sizeof(unsigned long),
787                 .mode           = 0644,
788                 .proc_handler   = &hugetlb_sysctl_handler,
789                 .extra1         = (void *)&hugetlb_zero,
790                 .extra2         = (void *)&hugetlb_infinity,
791          },
792 #endif
793         {
794                 .ctl_name       = VM_LOWER_ZONE_PROTECTION,
795                 .procname       = "lower_zone_protection",
796                 .data           = &sysctl_lower_zone_protection,
797                 .maxlen         = sizeof(sysctl_lower_zone_protection),
798                 .mode           = 0644,
799                 .proc_handler   = &lower_zone_protection_sysctl_handler,
800                 .strategy       = &sysctl_intvec,
801                 .extra1         = &zero,
802         },
803         {
804                 .ctl_name       = VM_MIN_FREE_KBYTES,
805                 .procname       = "min_free_kbytes",
806                 .data           = &min_free_kbytes,
807                 .maxlen         = sizeof(min_free_kbytes),
808                 .mode           = 0644,
809                 .proc_handler   = &min_free_kbytes_sysctl_handler,
810                 .strategy       = &sysctl_intvec,
811                 .extra1         = &zero,
812         },
813         {
814                 .ctl_name       = VM_MAX_MAP_COUNT,
815                 .procname       = "max_map_count",
816                 .data           = &sysctl_max_map_count,
817                 .maxlen         = sizeof(sysctl_max_map_count),
818                 .mode           = 0644,
819                 .proc_handler   = &proc_dointvec
820         },
821         {
822                 .ctl_name       = VM_LAPTOP_MODE,
823                 .procname       = "laptop_mode",
824                 .data           = &laptop_mode,
825                 .maxlen         = sizeof(laptop_mode),
826                 .mode           = 0644,
827                 .proc_handler   = &proc_dointvec,
828                 .strategy       = &sysctl_intvec,
829                 .extra1         = &zero,
830         },
831         {
832                 .ctl_name       = VM_BLOCK_DUMP,
833                 .procname       = "block_dump",
834                 .data           = &block_dump,
835                 .maxlen         = sizeof(block_dump),
836                 .mode           = 0644,
837                 .proc_handler   = &proc_dointvec,
838                 .strategy       = &sysctl_intvec,
839                 .extra1         = &zero,
840         },
841         {
842                 .ctl_name       = VM_VFS_CACHE_PRESSURE,
843                 .procname       = "vfs_cache_pressure",
844                 .data           = &sysctl_vfs_cache_pressure,
845                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
846                 .mode           = 0644,
847                 .proc_handler   = &proc_dointvec,
848                 .strategy       = &sysctl_intvec,
849                 .extra1         = &zero,
850         },
851         { .ctl_name = 0 }
852 };
853
854 static ctl_table proc_table[] = {
855         { .ctl_name = 0 }
856 };
857
858 static ctl_table fs_table[] = {
859         {
860                 .ctl_name       = FS_NRINODE,
861                 .procname       = "inode-nr",
862                 .data           = &inodes_stat,
863                 .maxlen         = 2*sizeof(int),
864                 .mode           = 0444,
865                 .proc_handler   = &proc_dointvec,
866         },
867         {
868                 .ctl_name       = FS_STATINODE,
869                 .procname       = "inode-state",
870                 .data           = &inodes_stat,
871                 .maxlen         = 7*sizeof(int),
872                 .mode           = 0444,
873                 .proc_handler   = &proc_dointvec,
874         },
875         {
876                 .ctl_name       = FS_NRFILE,
877                 .procname       = "file-nr",
878                 .data           = &files_stat,
879                 .maxlen         = 3*sizeof(int),
880                 .mode           = 0444,
881                 .proc_handler   = &proc_dointvec,
882         },
883         {
884                 .ctl_name       = FS_MAXFILE,
885                 .procname       = "file-max",
886                 .data           = &files_stat.max_files,
887                 .maxlen         = sizeof(int),
888                 .mode           = 0644,
889                 .proc_handler   = &proc_dointvec,
890         },
891         {
892                 .ctl_name       = FS_DENTRY,
893                 .procname       = "dentry-state",
894                 .data           = &dentry_stat,
895                 .maxlen         = 6*sizeof(int),
896                 .mode           = 0444,
897                 .proc_handler   = &proc_dointvec,
898         },
899         {
900                 .ctl_name       = FS_OVERFLOWUID,
901                 .procname       = "overflowuid",
902                 .data           = &fs_overflowuid,
903                 .maxlen         = sizeof(int),
904                 .mode           = 0644,
905                 .proc_handler   = &proc_dointvec_minmax,
906                 .strategy       = &sysctl_intvec,
907                 .extra1         = &minolduid,
908                 .extra2         = &maxolduid,
909         },
910         {
911                 .ctl_name       = FS_OVERFLOWGID,
912                 .procname       = "overflowgid",
913                 .data           = &fs_overflowgid,
914                 .maxlen         = sizeof(int),
915                 .mode           = 0644,
916                 .proc_handler   = &proc_dointvec_minmax,
917                 .strategy       = &sysctl_intvec,
918                 .extra1         = &minolduid,
919                 .extra2         = &maxolduid,
920         },
921         {
922                 .ctl_name       = FS_LEASES,
923                 .procname       = "leases-enable",
924                 .data           = &leases_enable,
925                 .maxlen         = sizeof(int),
926                 .mode           = 0644,
927                 .proc_handler   = &proc_dointvec,
928         },
929         {
930                 .ctl_name       = FS_DIR_NOTIFY,
931                 .procname       = "dir-notify-enable",
932                 .data           = &dir_notify_enable,
933                 .maxlen         = sizeof(int),
934                 .mode           = 0644,
935                 .proc_handler   = &proc_dointvec,
936         },
937         {
938                 .ctl_name       = FS_LEASE_TIME,
939                 .procname       = "lease-break-time",
940                 .data           = &lease_break_time,
941                 .maxlen         = sizeof(int),
942                 .mode           = 0644,
943                 .proc_handler   = &proc_dointvec,
944         },
945         {
946                 .ctl_name       = FS_AIO_NR,
947                 .procname       = "aio-nr",
948                 .data           = &aio_nr,
949                 .maxlen         = sizeof(aio_nr),
950                 .mode           = 0444,
951                 .proc_handler   = &proc_dointvec,
952         },
953         {
954                 .ctl_name       = FS_AIO_MAX_NR,
955                 .procname       = "aio-max-nr",
956                 .data           = &aio_max_nr,
957                 .maxlen         = sizeof(aio_max_nr),
958                 .mode           = 0644,
959                 .proc_handler   = &proc_dointvec,
960         },
961         { .ctl_name = 0 }
962 };
963
964 static ctl_table debug_table[] = {
965         { .ctl_name = 0 }
966 };
967
968 static ctl_table dev_table[] = {
969         { .ctl_name = 0 }
970 };  
971
972 extern void init_irq_proc (void);
973
974 void __init sysctl_init(void)
975 {
976 #ifdef CONFIG_PROC_FS
977         register_proc_table(root_table, proc_sys_root);
978         init_irq_proc();
979 #endif
980 }
981
982 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
983                void __user *newval, size_t newlen)
984 {
985         struct list_head *tmp;
986
987         if (nlen <= 0 || nlen >= CTL_MAXNAME)
988                 return -ENOTDIR;
989         if (oldval) {
990                 int old_len;
991                 if (!oldlenp || get_user(old_len, oldlenp))
992                         return -EFAULT;
993         }
994         tmp = &root_table_header.ctl_entry;
995         do {
996                 struct ctl_table_header *head =
997                         list_entry(tmp, struct ctl_table_header, ctl_entry);
998                 void *context = NULL;
999                 int error = parse_table(name, nlen, oldval, oldlenp, 
1000                                         newval, newlen, head->ctl_table,
1001                                         &context);
1002                 if (context)
1003                         kfree(context);
1004                 if (error != -ENOTDIR)
1005                         return error;
1006                 tmp = tmp->next;
1007         } while (tmp != &root_table_header.ctl_entry);
1008         return -ENOTDIR;
1009 }
1010
1011 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1012 {
1013         struct __sysctl_args tmp;
1014         int error;
1015
1016         if (copy_from_user(&tmp, args, sizeof(tmp)))
1017                 return -EFAULT;
1018
1019         lock_kernel();
1020         error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1021                           tmp.newval, tmp.newlen);
1022         unlock_kernel();
1023         return error;
1024 }
1025
1026 /*
1027  * ctl_perm does NOT grant the superuser all rights automatically, because
1028  * some sysctl variables are readonly even to root.
1029  */
1030
1031 static int test_perm(int mode, int op)
1032 {
1033         if (!current->euid)
1034                 mode >>= 6;
1035         else if (in_egroup_p(0))
1036                 mode >>= 3;
1037         if ((mode & op & 0007) == op)
1038                 return 0;
1039         return -EACCES;
1040 }
1041
1042 static inline int ctl_perm(ctl_table *table, int op)
1043 {
1044         int error;
1045         error = security_sysctl(table, op);
1046         if (error)
1047                 return error;
1048         return test_perm(table->mode, op);
1049 }
1050
1051 static int parse_table(int __user *name, int nlen,
1052                        void __user *oldval, size_t __user *oldlenp,
1053                        void __user *newval, size_t newlen,
1054                        ctl_table *table, void **context)
1055 {
1056         int n;
1057 repeat:
1058         if (!nlen)
1059                 return -ENOTDIR;
1060         if (get_user(n, name))
1061                 return -EFAULT;
1062         for ( ; table->ctl_name; table++) {
1063                 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1064                         int error;
1065                         if (table->child) {
1066                                 if (ctl_perm(table, 001))
1067                                         return -EPERM;
1068                                 if (table->strategy) {
1069                                         error = table->strategy(
1070                                                 table, name, nlen,
1071                                                 oldval, oldlenp,
1072                                                 newval, newlen, context);
1073                                         if (error)
1074                                                 return error;
1075                                 }
1076                                 name++;
1077                                 nlen--;
1078                                 table = table->child;
1079                                 goto repeat;
1080                         }
1081                         error = do_sysctl_strategy(table, name, nlen,
1082                                                    oldval, oldlenp,
1083                                                    newval, newlen, context);
1084                         return error;
1085                 }
1086         }
1087         return -ENOTDIR;
1088 }
1089
1090 /* Perform the actual read/write of a sysctl table entry. */
1091 int do_sysctl_strategy (ctl_table *table, 
1092                         int __user *name, int nlen,
1093                         void __user *oldval, size_t __user *oldlenp,
1094                         void __user *newval, size_t newlen, void **context)
1095 {
1096         int op = 0, rc;
1097         size_t len;
1098
1099         if (oldval)
1100                 op |= 004;
1101         if (newval) 
1102                 op |= 002;
1103         if (ctl_perm(table, op))
1104                 return -EPERM;
1105
1106         if (table->strategy) {
1107                 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1108                                      newval, newlen, context);
1109                 if (rc < 0)
1110                         return rc;
1111                 if (rc > 0)
1112                         return 0;
1113         }
1114
1115         /* If there is no strategy routine, or if the strategy returns
1116          * zero, proceed with automatic r/w */
1117         if (table->data && table->maxlen) {
1118                 if (oldval && oldlenp) {
1119                         if (get_user(len, oldlenp))
1120                                 return -EFAULT;
1121                         if (len) {
1122                                 if (len > table->maxlen)
1123                                         len = table->maxlen;
1124                                 if(copy_to_user(oldval, table->data, len))
1125                                         return -EFAULT;
1126                                 if(put_user(len, oldlenp))
1127                                         return -EFAULT;
1128                         }
1129                 }
1130                 if (newval && newlen) {
1131                         len = newlen;
1132                         if (len > table->maxlen)
1133                                 len = table->maxlen;
1134                         if(copy_from_user(table->data, newval, len))
1135                                 return -EFAULT;
1136                 }
1137         }
1138         return 0;
1139 }
1140
1141 /**
1142  * register_sysctl_table - register a sysctl hierarchy
1143  * @table: the top-level table structure
1144  * @insert_at_head: whether the entry should be inserted in front or at the end
1145  *
1146  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1147  * array. An entry with a ctl_name of 0 terminates the table. 
1148  *
1149  * The members of the &ctl_table structure are used as follows:
1150  *
1151  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1152  *            must be unique within that level of sysctl
1153  *
1154  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1155  *            enter a sysctl file
1156  *
1157  * data - a pointer to data for use by proc_handler
1158  *
1159  * maxlen - the maximum size in bytes of the data
1160  *
1161  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1162  *
1163  * child - a pointer to the child sysctl table if this entry is a directory, or
1164  *         %NULL.
1165  *
1166  * proc_handler - the text handler routine (described below)
1167  *
1168  * strategy - the strategy routine (described below)
1169  *
1170  * de - for internal use by the sysctl routines
1171  *
1172  * extra1, extra2 - extra pointers usable by the proc handler routines
1173  *
1174  * Leaf nodes in the sysctl tree will be represented by a single file
1175  * under /proc; non-leaf nodes will be represented by directories.
1176  *
1177  * sysctl(2) can automatically manage read and write requests through
1178  * the sysctl table.  The data and maxlen fields of the ctl_table
1179  * struct enable minimal validation of the values being written to be
1180  * performed, and the mode field allows minimal authentication.
1181  *
1182  * More sophisticated management can be enabled by the provision of a
1183  * strategy routine with the table entry.  This will be called before
1184  * any automatic read or write of the data is performed.
1185  *
1186  * The strategy routine may return
1187  *
1188  * < 0 - Error occurred (error is passed to user process)
1189  *
1190  * 0   - OK - proceed with automatic read or write.
1191  *
1192  * > 0 - OK - read or write has been done by the strategy routine, so
1193  *       return immediately.
1194  *
1195  * There must be a proc_handler routine for any terminal nodes
1196  * mirrored under /proc/sys (non-terminals are handled by a built-in
1197  * directory handler).  Several default handlers are available to
1198  * cover common cases -
1199  *
1200  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1201  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 
1202  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1203  *
1204  * It is the handler's job to read the input buffer from user memory
1205  * and process it. The handler should return 0 on success.
1206  *
1207  * This routine returns %NULL on a failure to register, and a pointer
1208  * to the table header on success.
1209  */
1210 struct ctl_table_header *register_sysctl_table(ctl_table * table, 
1211                                                int insert_at_head)
1212 {
1213         struct ctl_table_header *tmp;
1214         tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1215         if (!tmp)
1216                 return NULL;
1217         tmp->ctl_table = table;
1218         INIT_LIST_HEAD(&tmp->ctl_entry);
1219         if (insert_at_head)
1220                 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1221         else
1222                 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1223 #ifdef CONFIG_PROC_FS
1224         register_proc_table(table, proc_sys_root);
1225 #endif
1226         return tmp;
1227 }
1228
1229 /**
1230  * unregister_sysctl_table - unregister a sysctl table hierarchy
1231  * @header: the header returned from register_sysctl_table
1232  *
1233  * Unregisters the sysctl table and all children. proc entries may not
1234  * actually be removed until they are no longer used by anyone.
1235  */
1236 void unregister_sysctl_table(struct ctl_table_header * header)
1237 {
1238         list_del(&header->ctl_entry);
1239 #ifdef CONFIG_PROC_FS
1240         unregister_proc_table(header->ctl_table, proc_sys_root);
1241 #endif
1242         kfree(header);
1243 }
1244
1245 /*
1246  * /proc/sys support
1247  */
1248
1249 #ifdef CONFIG_PROC_FS
1250
1251 /* Scan the sysctl entries in table and add them all into /proc */
1252 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1253 {
1254         struct proc_dir_entry *de;
1255         int len;
1256         mode_t mode;
1257         
1258         for (; table->ctl_name; table++) {
1259                 /* Can't do anything without a proc name. */
1260                 if (!table->procname)
1261                         continue;
1262                 /* Maybe we can't do anything with it... */
1263                 if (!table->proc_handler && !table->child) {
1264                         printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1265                                 table->procname);
1266                         continue;
1267                 }
1268
1269                 len = strlen(table->procname);
1270                 mode = table->mode;
1271
1272                 de = NULL;
1273                 if (table->proc_handler)
1274                         mode |= S_IFREG;
1275                 else {
1276                         mode |= S_IFDIR;
1277                         for (de = root->subdir; de; de = de->next) {
1278                                 if (proc_match(len, table->procname, de))
1279                                         break;
1280                         }
1281                         /* If the subdir exists already, de is non-NULL */
1282                 }
1283
1284                 if (!de) {
1285                         de = create_proc_entry(table->procname, mode, root);
1286                         if (!de)
1287                                 continue;
1288                         de->data = (void *) table;
1289                         if (table->proc_handler)
1290                                 de->proc_fops = &proc_sys_file_operations;
1291                 }
1292                 table->de = de;
1293                 if (de->mode & S_IFDIR)
1294                         register_proc_table(table->child, de);
1295         }
1296 }
1297
1298 /*
1299  * Unregister a /proc sysctl table and any subdirectories.
1300  */
1301 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1302 {
1303         struct proc_dir_entry *de;
1304         for (; table->ctl_name; table++) {
1305                 if (!(de = table->de))
1306                         continue;
1307                 if (de->mode & S_IFDIR) {
1308                         if (!table->child) {
1309                                 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1310                                 continue;
1311                         }
1312                         unregister_proc_table(table->child, de);
1313
1314                         /* Don't unregister directories which still have entries.. */
1315                         if (de->subdir)
1316                                 continue;
1317                 }
1318
1319                 /* Don't unregister proc entries that are still being used.. */
1320                 if (atomic_read(&de->count))
1321                         continue;
1322
1323                 table->de = NULL;
1324                 remove_proc_entry(table->procname, root);
1325         }
1326 }
1327
1328 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1329                           size_t count, loff_t *ppos)
1330 {
1331         int op;
1332         struct proc_dir_entry *de;
1333         struct ctl_table *table;
1334         size_t res;
1335         ssize_t error;
1336         
1337         de = PDE(file->f_dentry->d_inode);
1338         if (!de || !de->data)
1339                 return -ENOTDIR;
1340         table = (struct ctl_table *) de->data;
1341         if (!table || !table->proc_handler)
1342                 return -ENOTDIR;
1343         op = (write ? 002 : 004);
1344         if (ctl_perm(table, op))
1345                 return -EPERM;
1346         
1347         res = count;
1348
1349         /*
1350          * FIXME: we need to pass on ppos to the handler.
1351          */
1352
1353         error = (*table->proc_handler) (table, write, file, buf, &res);
1354         if (error)
1355                 return error;
1356         return res;
1357 }
1358
1359 static int proc_opensys(struct inode *inode, struct file *file)
1360 {
1361         if (file->f_mode & FMODE_WRITE) {
1362                 /*
1363                  * sysctl entries that are not writable,
1364                  * are _NOT_ writable, capabilities or not.
1365                  */
1366                 if (!(inode->i_mode & S_IWUSR))
1367                         return -EPERM;
1368         }
1369
1370         return 0;
1371 }
1372
1373 static ssize_t proc_readsys(struct file * file, char __user * buf,
1374                             size_t count, loff_t *ppos)
1375 {
1376         return do_rw_proc(0, file, buf, count, ppos);
1377 }
1378
1379 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1380                              size_t count, loff_t *ppos)
1381 {
1382         return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1383 }
1384
1385 /**
1386  * proc_dostring - read a string sysctl
1387  * @table: the sysctl table
1388  * @write: %TRUE if this is a write to the sysctl file
1389  * @filp: the file structure
1390  * @buffer: the user buffer
1391  * @lenp: the size of the user buffer
1392  *
1393  * Reads/writes a string from/to the user buffer. If the kernel
1394  * buffer provided is not large enough to hold the string, the
1395  * string is truncated. The copied string is %NULL-terminated.
1396  * If the string is being read by the user process, it is copied
1397  * and a newline '\n' is added. It is truncated if the buffer is
1398  * not large enough.
1399  *
1400  * Returns 0 on success.
1401  */
1402 int proc_dostring(ctl_table *table, int write, struct file *filp,
1403                   void __user *buffer, size_t *lenp)
1404 {
1405         size_t len;
1406         char __user *p;
1407         char c;
1408         
1409         if (!table->data || !table->maxlen || !*lenp ||
1410             (filp->f_pos && !write)) {
1411                 *lenp = 0;
1412                 return 0;
1413         }
1414         
1415         if (write) {
1416                 len = 0;
1417                 p = buffer;
1418                 while (len < *lenp) {
1419                         if (get_user(c, p++))
1420                                 return -EFAULT;
1421                         if (c == 0 || c == '\n')
1422                                 break;
1423                         len++;
1424                 }
1425                 if (len >= table->maxlen)
1426                         len = table->maxlen-1;
1427                 if(copy_from_user(table->data, buffer, len))
1428                         return -EFAULT;
1429                 ((char *) table->data)[len] = 0;
1430                 filp->f_pos += *lenp;
1431         } else {
1432                 len = strlen(table->data);
1433                 if (len > table->maxlen)
1434                         len = table->maxlen;
1435                 if (len > *lenp)
1436                         len = *lenp;
1437                 if (len)
1438                         if(copy_to_user(buffer, table->data, len))
1439                                 return -EFAULT;
1440                 if (len < *lenp) {
1441                         if(put_user('\n', ((char __user *) buffer) + len))
1442                                 return -EFAULT;
1443                         len++;
1444                 }
1445                 *lenp = len;
1446                 filp->f_pos += len;
1447         }
1448         return 0;
1449 }
1450
1451 /*
1452  *      Special case of dostring for the UTS structure. This has locks
1453  *      to observe. Should this be in kernel/sys.c ????
1454  */
1455  
1456 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1457                   void __user *buffer, size_t *lenp)
1458 {
1459         int r;
1460
1461         if (!write) {
1462                 down_read(&uts_sem);
1463                 r=proc_dostring(table,0,filp,buffer,lenp);
1464                 up_read(&uts_sem);
1465         } else {
1466                 down_write(&uts_sem);
1467                 r=proc_dostring(table,1,filp,buffer,lenp);
1468                 up_write(&uts_sem);
1469         }
1470         return r;
1471 }
1472
1473 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1474                                  int *valp,
1475                                  int write, void *data)
1476 {
1477         if (write) {
1478                 *valp = *negp ? -*lvalp : *lvalp;
1479         } else {
1480                 int val = *valp;
1481                 if (val < 0) {
1482                         *negp = -1;
1483                         *lvalp = (unsigned long)-val;
1484                 } else {
1485                         *negp = 0;
1486                         *lvalp = (unsigned long)val;
1487                 }
1488         }
1489         return 0;
1490 }
1491
1492 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1493                   void __user *buffer, size_t *lenp, 
1494                   int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1495                               int write, void *data),
1496                   void *data)
1497 {
1498 #define TMPBUFLEN 20
1499         int *i, vleft, first=1, neg, val;
1500         unsigned long lval;
1501         size_t left, len;
1502         
1503         char buf[TMPBUFLEN], *p;
1504         char __user *s = buffer;
1505         
1506         if (!table->data || !table->maxlen || !*lenp ||
1507             (filp->f_pos && !write)) {
1508                 *lenp = 0;
1509                 return 0;
1510         }
1511         
1512         i = (int *) table->data;
1513         vleft = table->maxlen / sizeof(*i);
1514         left = *lenp;
1515
1516         if (!conv)
1517                 conv = do_proc_dointvec_conv;
1518
1519         for (; left && vleft--; i++, first=0) {
1520                 if (write) {
1521                         while (left) {
1522                                 char c;
1523                                 if (get_user(c, s))
1524                                         return -EFAULT;
1525                                 if (!isspace(c))
1526                                         break;
1527                                 left--;
1528                                 s++;
1529                         }
1530                         if (!left)
1531                                 break;
1532                         neg = 0;
1533                         len = left;
1534                         if (len > sizeof(buf) - 1)
1535                                 len = sizeof(buf) - 1;
1536                         if (copy_from_user(buf, s, len))
1537                                 return -EFAULT;
1538                         buf[len] = 0;
1539                         p = buf;
1540                         if (*p == '-' && left > 1) {
1541                                 neg = 1;
1542                                 left--, p++;
1543                         }
1544                         if (*p < '0' || *p > '9')
1545                                 break;
1546
1547                         lval = simple_strtoul(p, &p, 0);
1548
1549                         len = p-buf;
1550                         if ((len < left) && *p && !isspace(*p))
1551                                 break;
1552                         if (neg)
1553                                 val = -val;
1554                         s += len;
1555                         left -= len;
1556
1557                         if (conv(&neg, &lval, i, 1, data))
1558                                 break;
1559                 } else {
1560                         p = buf;
1561                         if (!first)
1562                                 *p++ = '\t';
1563         
1564                         if (conv(&neg, &lval, i, 0, data))
1565                                 break;
1566
1567                         sprintf(p, "%s%lu", neg ? "-" : "", lval);
1568                         len = strlen(buf);
1569                         if (len > left)
1570                                 len = left;
1571                         if(copy_to_user(s, buf, len))
1572                                 return -EFAULT;
1573                         left -= len;
1574                         s += len;
1575                 }
1576         }
1577
1578         if (!write && !first && left) {
1579                 if(put_user('\n', s))
1580                         return -EFAULT;
1581                 left--, s++;
1582         }
1583         if (write) {
1584                 while (left) {
1585                         char c;
1586                         if (get_user(c, s++))
1587                                 return -EFAULT;
1588                         if (!isspace(c))
1589                                 break;
1590                         left--;
1591                 }
1592         }
1593         if (write && first)
1594                 return -EINVAL;
1595         *lenp -= left;
1596         filp->f_pos += *lenp;
1597         return 0;
1598 #undef TMPBUFLEN
1599 }
1600
1601 /**
1602  * proc_dointvec - read a vector of integers
1603  * @table: the sysctl table
1604  * @write: %TRUE if this is a write to the sysctl file
1605  * @filp: the file structure
1606  * @buffer: the user buffer
1607  * @lenp: the size of the user buffer
1608  *
1609  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1610  * values from/to the user buffer, treated as an ASCII string. 
1611  *
1612  * Returns 0 on success.
1613  */
1614 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1615                      void __user *buffer, size_t *lenp)
1616 {
1617     return do_proc_dointvec(table,write,filp,buffer,lenp,
1618                             NULL,NULL);
1619 }
1620
1621 #define OP_SET  0
1622 #define OP_AND  1
1623 #define OP_OR   2
1624 #define OP_MAX  3
1625 #define OP_MIN  4
1626
1627 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1628                                       int *valp,
1629                                       int write, void *data)
1630 {
1631         int op = *(int *)data;
1632         if (write) {
1633                 int val = *negp ? -*lvalp : *lvalp;
1634                 switch(op) {
1635                 case OP_SET:    *valp = val; break;
1636                 case OP_AND:    *valp &= val; break;
1637                 case OP_OR:     *valp |= val; break;
1638                 case OP_MAX:    if(*valp < val)
1639                                         *valp = val;
1640                                 break;
1641                 case OP_MIN:    if(*valp > val)
1642                                 *valp = val;
1643                                 break;
1644                 }
1645         } else {
1646                 int val = *valp;
1647                 if (val < 0) {
1648                         *negp = -1;
1649                         *lvalp = (unsigned long)-val;
1650                 } else {
1651                         *negp = 0;
1652                         *lvalp = (unsigned long)val;
1653                 }
1654         }
1655         return 0;
1656 }
1657
1658 /*
1659  *      init may raise the set.
1660  */
1661  
1662 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1663                         void __user *buffer, size_t *lenp)
1664 {
1665         int op;
1666
1667         if (!capable(CAP_SYS_MODULE)) {
1668                 return -EPERM;
1669         }
1670
1671         op = (current->pid == 1) ? OP_SET : OP_AND;
1672         return do_proc_dointvec(table,write,filp,buffer,lenp,
1673                                 do_proc_dointvec_bset_conv,&op);
1674 }
1675
1676 struct do_proc_dointvec_minmax_conv_param {
1677         int *min;
1678         int *max;
1679 };
1680
1681 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 
1682                                         int *valp, 
1683                                         int write, void *data)
1684 {
1685         struct do_proc_dointvec_minmax_conv_param *param = data;
1686         if (write) {
1687                 int val = *negp ? -*lvalp : *lvalp;
1688                 if ((param->min && *param->min > val) ||
1689                     (param->max && *param->max < val))
1690                         return -EINVAL;
1691                 *valp = val;
1692         } else {
1693                 int val = *valp;
1694                 if (val < 0) {
1695                         *negp = -1;
1696                         *lvalp = (unsigned long)-val;
1697                 } else {
1698                         *negp = 0;
1699                         *lvalp = (unsigned long)val;
1700                 }
1701         }
1702         return 0;
1703 }
1704
1705 /**
1706  * proc_dointvec_minmax - read a vector of integers with min/max values
1707  * @table: the sysctl table
1708  * @write: %TRUE if this is a write to the sysctl file
1709  * @filp: the file structure
1710  * @buffer: the user buffer
1711  * @lenp: the size of the user buffer
1712  *
1713  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1714  * values from/to the user buffer, treated as an ASCII string.
1715  *
1716  * This routine will ensure the values are within the range specified by
1717  * table->extra1 (min) and table->extra2 (max).
1718  *
1719  * Returns 0 on success.
1720  */
1721 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1722                   void __user *buffer, size_t *lenp)
1723 {
1724         struct do_proc_dointvec_minmax_conv_param param = {
1725                 .min = (int *) table->extra1,
1726                 .max = (int *) table->extra2,
1727         };
1728         return do_proc_dointvec(table, write, filp, buffer, lenp,
1729                                 do_proc_dointvec_minmax_conv, &param);
1730 }
1731
1732 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1733                                      struct file *filp,
1734                                      void __user *buffer, size_t *lenp,
1735                                      unsigned long convmul,
1736                                      unsigned long convdiv)
1737 {
1738 #define TMPBUFLEN 20
1739         unsigned long *i, *min, *max, val;
1740         int vleft, first=1, neg;
1741         size_t len, left;
1742         char buf[TMPBUFLEN], *p;
1743         char __user *s = buffer;
1744         
1745         if (!table->data || !table->maxlen || !*lenp ||
1746             (filp->f_pos && !write)) {
1747                 *lenp = 0;
1748                 return 0;
1749         }
1750         
1751         i = (unsigned long *) table->data;
1752         min = (unsigned long *) table->extra1;
1753         max = (unsigned long *) table->extra2;
1754         vleft = table->maxlen / sizeof(unsigned long);
1755         left = *lenp;
1756         
1757         for (; left && vleft--; i++, min++, max++, first=0) {
1758                 if (write) {
1759                         while (left) {
1760                                 char c;
1761                                 if (get_user(c, s))
1762                                         return -EFAULT;
1763                                 if (!isspace(c))
1764                                         break;
1765                                 left--;
1766                                 s++;
1767                         }
1768                         if (!left)
1769                                 break;
1770                         neg = 0;
1771                         len = left;
1772                         if (len > TMPBUFLEN-1)
1773                                 len = TMPBUFLEN-1;
1774                         if (copy_from_user(buf, s, len))
1775                                 return -EFAULT;
1776                         buf[len] = 0;
1777                         p = buf;
1778                         if (*p == '-' && left > 1) {
1779                                 neg = 1;
1780                                 left--, p++;
1781                         }
1782                         if (*p < '0' || *p > '9')
1783                                 break;
1784                         val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1785                         len = p-buf;
1786                         if ((len < left) && *p && !isspace(*p))
1787                                 break;
1788                         if (neg)
1789                                 val = -val;
1790                         s += len;
1791                         left -= len;
1792
1793                         if(neg)
1794                                 continue;
1795                         if ((min && val < *min) || (max && val > *max))
1796                                 continue;
1797                         *i = val;
1798                 } else {
1799                         p = buf;
1800                         if (!first)
1801                                 *p++ = '\t';
1802                         sprintf(p, "%lu", convdiv * (*i) / convmul);
1803                         len = strlen(buf);
1804                         if (len > left)
1805                                 len = left;
1806                         if(copy_to_user(s, buf, len))
1807                                 return -EFAULT;
1808                         left -= len;
1809                         s += len;
1810                 }
1811         }
1812
1813         if (!write && !first && left) {
1814                 if(put_user('\n', s))
1815                         return -EFAULT;
1816                 left--, s++;
1817         }
1818         if (write) {
1819                 while (left) {
1820                         char c;
1821                         if (get_user(c, s++))
1822                                 return -EFAULT;
1823                         if (!isspace(c))
1824                                 break;
1825                         left--;
1826                 }
1827         }
1828         if (write && first)
1829                 return -EINVAL;
1830         *lenp -= left;
1831         filp->f_pos += *lenp;
1832         return 0;
1833 #undef TMPBUFLEN
1834 }
1835
1836 /**
1837  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1838  * @table: the sysctl table
1839  * @write: %TRUE if this is a write to the sysctl file
1840  * @filp: the file structure
1841  * @buffer: the user buffer
1842  * @lenp: the size of the user buffer
1843  *
1844  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1845  * values from/to the user buffer, treated as an ASCII string.
1846  *
1847  * This routine will ensure the values are within the range specified by
1848  * table->extra1 (min) and table->extra2 (max).
1849  *
1850  * Returns 0 on success.
1851  */
1852 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1853                            void __user *buffer, size_t *lenp)
1854 {
1855     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, 1l, 1l);
1856 }
1857
1858 /**
1859  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1860  * @table: the sysctl table
1861  * @write: %TRUE if this is a write to the sysctl file
1862  * @filp: the file structure
1863  * @buffer: the user buffer
1864  * @lenp: the size of the user buffer
1865  *
1866  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1867  * values from/to the user buffer, treated as an ASCII string. The values
1868  * are treated as milliseconds, and converted to jiffies when they are stored.
1869  *
1870  * This routine will ensure the values are within the range specified by
1871  * table->extra1 (min) and table->extra2 (max).
1872  *
1873  * Returns 0 on success.
1874  */
1875 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1876                                       struct file *filp,
1877                                       void __user *buffer, size_t *lenp)
1878 {
1879     return do_proc_doulongvec_minmax(table, write, filp, buffer,
1880                                      lenp, HZ, 1000l);
1881 }
1882
1883
1884 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1885                                          int *valp,
1886                                          int write, void *data)
1887 {
1888         if (write) {
1889                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1890         } else {
1891                 int val = *valp;
1892                 unsigned long lval;
1893                 if (val < 0) {
1894                         *negp = -1;
1895                         lval = (unsigned long)-val;
1896                 } else {
1897                         *negp = 0;
1898                         lval = (unsigned long)val;
1899                 }
1900                 *lvalp = lval / HZ;
1901         }
1902         return 0;
1903 }
1904
1905 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1906                                                 int *valp,
1907                                                 int write, void *data)
1908 {
1909         if (write) {
1910                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1911         } else {
1912                 int val = *valp;
1913                 unsigned long lval;
1914                 if (val < 0) {
1915                         *negp = -1;
1916                         lval = (unsigned long)-val;
1917                 } else {
1918                         *negp = 0;
1919                         lval = (unsigned long)val;
1920                 }
1921                 *lvalp = jiffies_to_clock_t(lval);
1922         }
1923         return 0;
1924 }
1925
1926 /**
1927  * proc_dointvec_jiffies - read a vector of integers as seconds
1928  * @table: the sysctl table
1929  * @write: %TRUE if this is a write to the sysctl file
1930  * @filp: the file structure
1931  * @buffer: the user buffer
1932  * @lenp: the size of the user buffer
1933  *
1934  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1935  * values from/to the user buffer, treated as an ASCII string. 
1936  * The values read are assumed to be in seconds, and are converted into
1937  * jiffies.
1938  *
1939  * Returns 0 on success.
1940  */
1941 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1942                           void __user *buffer, size_t *lenp)
1943 {
1944     return do_proc_dointvec(table,write,filp,buffer,lenp,
1945                             do_proc_dointvec_jiffies_conv,NULL);
1946 }
1947
1948 /**
1949  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1950  * @table: the sysctl table
1951  * @write: %TRUE if this is a write to the sysctl file
1952  * @filp: the file structure
1953  * @buffer: the user buffer
1954  * @lenp: the size of the user buffer
1955  *
1956  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1957  * values from/to the user buffer, treated as an ASCII string. 
1958  * The values read are assumed to be in 1/USER_HZ seconds, and 
1959  * are converted into jiffies.
1960  *
1961  * Returns 0 on success.
1962  */
1963 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1964                                  void __user *buffer, size_t *lenp)
1965 {
1966     return do_proc_dointvec(table,write,filp,buffer,lenp,
1967                             do_proc_dointvec_userhz_jiffies_conv,NULL);
1968 }
1969
1970 #else /* CONFIG_PROC_FS */
1971
1972 int proc_dostring(ctl_table *table, int write, struct file *filp,
1973                   void __user *buffer, size_t *lenp)
1974 {
1975         return -ENOSYS;
1976 }
1977
1978 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1979                             void __user *buffer, size_t *lenp)
1980 {
1981         return -ENOSYS;
1982 }
1983
1984 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1985                   void __user *buffer, size_t *lenp)
1986 {
1987         return -ENOSYS;
1988 }
1989
1990 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1991                         void __user *buffer, size_t *lenp)
1992 {
1993         return -ENOSYS;
1994 }
1995
1996 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1997                     void __user *buffer, size_t *lenp)
1998 {
1999         return -ENOSYS;
2000 }
2001
2002 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2003                     void __user *buffer, size_t *lenp)
2004 {
2005         return -ENOSYS;
2006 }
2007
2008 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2009                     void __user *buffer, size_t *lenp)
2010 {
2011         return -ENOSYS;
2012 }
2013
2014 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2015                     void __user *buffer, size_t *lenp)
2016 {
2017         return -ENOSYS;
2018 }
2019
2020 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2021                                       struct file *filp,
2022                                       void __user *buffer, size_t *lenp)
2023 {
2024     return -ENOSYS;
2025 }
2026
2027
2028 #endif /* CONFIG_PROC_FS */
2029
2030
2031 /*
2032  * General sysctl support routines 
2033  */
2034
2035 /* The generic string strategy routine: */
2036 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2037                   void __user *oldval, size_t __user *oldlenp,
2038                   void __user *newval, size_t newlen, void **context)
2039 {
2040         size_t l, len;
2041         
2042         if (!table->data || !table->maxlen) 
2043                 return -ENOTDIR;
2044         
2045         if (oldval && oldlenp) {
2046                 if (get_user(len, oldlenp))
2047                         return -EFAULT;
2048                 if (len) {
2049                         l = strlen(table->data);
2050                         if (len > l) len = l;
2051                         if (len >= table->maxlen)
2052                                 len = table->maxlen;
2053                         if(copy_to_user(oldval, table->data, len))
2054                                 return -EFAULT;
2055                         if(put_user(0, ((char __user *) oldval) + len))
2056                                 return -EFAULT;
2057                         if(put_user(len, oldlenp))
2058                                 return -EFAULT;
2059                 }
2060         }
2061         if (newval && newlen) {
2062                 len = newlen;
2063                 if (len > table->maxlen)
2064                         len = table->maxlen;
2065                 if(copy_from_user(table->data, newval, len))
2066                         return -EFAULT;
2067                 if (len == table->maxlen)
2068                         len--;
2069                 ((char *) table->data)[len] = 0;
2070         }
2071         return 0;
2072 }
2073
2074 /*
2075  * This function makes sure that all of the integers in the vector
2076  * are between the minimum and maximum values given in the arrays
2077  * table->extra1 and table->extra2, respectively.
2078  */
2079 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2080                 void __user *oldval, size_t __user *oldlenp,
2081                 void __user *newval, size_t newlen, void **context)
2082 {
2083
2084         if (newval && newlen) {
2085                 int __user *vec = (int __user *) newval;
2086                 int *min = (int *) table->extra1;
2087                 int *max = (int *) table->extra2;
2088                 size_t length;
2089                 int i;
2090
2091                 if (newlen % sizeof(int) != 0)
2092                         return -EINVAL;
2093
2094                 if (!table->extra1 && !table->extra2)
2095                         return 0;
2096
2097                 if (newlen > table->maxlen)
2098                         newlen = table->maxlen;
2099                 length = newlen / sizeof(int);
2100
2101                 for (i = 0; i < length; i++) {
2102                         int value;
2103                         if (get_user(value, vec + i))
2104                                 return -EFAULT;
2105                         if (min && value < min[i])
2106                                 return -EINVAL;
2107                         if (max && value > max[i])
2108                                 return -EINVAL;
2109                 }
2110         }
2111         return 0;
2112 }
2113
2114 /* Strategy function to convert jiffies to seconds */ 
2115 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2116                 void __user *oldval, size_t __user *oldlenp,
2117                 void __user *newval, size_t newlen, void **context)
2118 {
2119         if (oldval) {
2120                 size_t olen;
2121                 if (oldlenp) { 
2122                         if (get_user(olen, oldlenp))
2123                                 return -EFAULT;
2124                         if (olen!=sizeof(int))
2125                                 return -EINVAL; 
2126                 }
2127                 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2128                     (oldlenp && put_user(sizeof(int),oldlenp)))
2129                         return -EFAULT;
2130         }
2131         if (newval && newlen) { 
2132                 int new;
2133                 if (newlen != sizeof(int))
2134                         return -EINVAL; 
2135                 if (get_user(new, (int __user *)newval))
2136                         return -EFAULT;
2137                 *(int *)(table->data) = new*HZ; 
2138         }
2139         return 1;
2140 }
2141
2142
2143 #else /* CONFIG_SYSCTL */
2144
2145
2146 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2147 {
2148         return -ENOSYS;
2149 }
2150
2151 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2152                   void __user *oldval, size_t __user *oldlenp,
2153                   void __user *newval, size_t newlen, void **context)
2154 {
2155         return -ENOSYS;
2156 }
2157
2158 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2159                 void __user *oldval, size_t __user *oldlenp,
2160                 void __user *newval, size_t newlen, void **context)
2161 {
2162         return -ENOSYS;
2163 }
2164
2165 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2166                 void __user *oldval, size_t __user *oldlenp,
2167                 void __user *newval, size_t newlen, void **context)
2168 {
2169         return -ENOSYS;
2170 }
2171
2172 int proc_dostring(ctl_table *table, int write, struct file *filp,
2173                   void __user *buffer, size_t *lenp)
2174 {
2175         return -ENOSYS;
2176 }
2177
2178 int proc_dointvec(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_bset(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_minmax(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_jiffies(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_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2203                           void __user *buffer, size_t *lenp)
2204 {
2205         return -ENOSYS;
2206 }
2207
2208 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2209                     void __user *buffer, size_t *lenp)
2210 {
2211         return -ENOSYS;
2212 }
2213
2214 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2215                                       struct file *filp,
2216                                       void __user *buffer, size_t *lenp)
2217 {
2218     return -ENOSYS;
2219 }
2220
2221 struct ctl_table_header * register_sysctl_table(ctl_table * table, 
2222                                                 int insert_at_head)
2223 {
2224         return NULL;
2225 }
2226
2227 void unregister_sysctl_table(struct ctl_table_header * table)
2228 {
2229 }
2230
2231 #endif /* CONFIG_SYSCTL */
2232
2233 /*
2234  * No sense putting this after each symbol definition, twice,
2235  * exception granted :-)
2236  */
2237 EXPORT_SYMBOL(proc_dointvec);
2238 EXPORT_SYMBOL(proc_dointvec_jiffies);
2239 EXPORT_SYMBOL(proc_dointvec_minmax);
2240 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2241 EXPORT_SYMBOL(proc_dostring);
2242 EXPORT_SYMBOL(proc_doulongvec_minmax);
2243 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2244 EXPORT_SYMBOL(register_sysctl_table);
2245 EXPORT_SYMBOL(sysctl_intvec);
2246 EXPORT_SYMBOL(sysctl_jiffies);
2247 EXPORT_SYMBOL(sysctl_string);
2248 EXPORT_SYMBOL(unregister_sysctl_table);