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