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