]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blob - kernel/sysctl.c
sched: remove stat_gran
[linux-2.6-omap-h63xx.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/module.h>
22 #include <linux/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/capability.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/smp_lock.h>
31 #include <linux/fs.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
49
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
52
53 #ifdef CONFIG_X86
54 #include <asm/nmi.h>
55 #include <asm/stacktrace.h>
56 #endif
57
58 #if defined(CONFIG_SYSCTL)
59
60 /* External variables not in a header file. */
61 extern int C_A_D;
62 extern int print_fatal_signals;
63 extern int sysctl_overcommit_memory;
64 extern int sysctl_overcommit_ratio;
65 extern int sysctl_panic_on_oom;
66 extern int max_threads;
67 extern int core_uses_pid;
68 extern int suid_dumpable;
69 extern char core_pattern[];
70 extern int pid_max;
71 extern int min_free_kbytes;
72 extern int printk_ratelimit_jiffies;
73 extern int printk_ratelimit_burst;
74 extern int pid_max_min, pid_max_max;
75 extern int sysctl_drop_caches;
76 extern int percpu_pagelist_fraction;
77 extern int compat_log;
78 extern int maps_protect;
79 extern int sysctl_stat_interval;
80 extern int audit_argv_kb;
81
82 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83 static int maxolduid = 65535;
84 static int minolduid;
85 static int min_percpu_pagelist_fract = 8;
86
87 static int ngroups_max = NGROUPS_MAX;
88
89 #ifdef CONFIG_KMOD
90 extern char modprobe_path[];
91 #endif
92 #ifdef CONFIG_CHR_DEV_SG
93 extern int sg_big_buff;
94 #endif
95
96 #ifdef __sparc__
97 extern char reboot_command [];
98 extern int stop_a_enabled;
99 extern int scons_pwroff;
100 #endif
101
102 #ifdef __hppa__
103 extern int pwrsw_enabled;
104 extern int unaligned_enabled;
105 #endif
106
107 #ifdef CONFIG_S390
108 #ifdef CONFIG_MATHEMU
109 extern int sysctl_ieee_emulation_warnings;
110 #endif
111 extern int sysctl_userprocess_debug;
112 extern int spin_retry;
113 #endif
114
115 extern int sysctl_hz_timer;
116
117 #ifdef CONFIG_BSD_PROCESS_ACCT
118 extern int acct_parm[];
119 #endif
120
121 #ifdef CONFIG_IA64
122 extern int no_unaligned_warning;
123 #endif
124
125 #ifdef CONFIG_RT_MUTEXES
126 extern int max_lock_depth;
127 #endif
128
129 #ifdef CONFIG_SYSCTL_SYSCALL
130 static int parse_table(int __user *, int, void __user *, size_t __user *,
131                 void __user *, size_t, ctl_table *);
132 #endif
133
134
135 #ifdef CONFIG_PROC_SYSCTL
136 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
137                   void __user *buffer, size_t *lenp, loff_t *ppos);
138 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
139                                void __user *buffer, size_t *lenp, loff_t *ppos);
140 #endif
141
142 static ctl_table root_table[];
143 static struct ctl_table_header root_table_header =
144         { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
145
146 static ctl_table kern_table[];
147 static ctl_table vm_table[];
148 static ctl_table fs_table[];
149 static ctl_table debug_table[];
150 static ctl_table dev_table[];
151 extern ctl_table random_table[];
152 #ifdef CONFIG_UNIX98_PTYS
153 extern ctl_table pty_table[];
154 #endif
155 #ifdef CONFIG_INOTIFY_USER
156 extern ctl_table inotify_table[];
157 #endif
158
159 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
160 int sysctl_legacy_va_layout;
161 #endif
162
163 extern int prove_locking;
164 extern int lock_stat;
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_FS,
191                 .procname       = "fs",
192                 .mode           = 0555,
193                 .child          = fs_table,
194         },
195         {
196                 .ctl_name       = CTL_DEBUG,
197                 .procname       = "debug",
198                 .mode           = 0555,
199                 .child          = debug_table,
200         },
201         {
202                 .ctl_name       = CTL_DEV,
203                 .procname       = "dev",
204                 .mode           = 0555,
205                 .child          = dev_table,
206         },
207 /*
208  * NOTE: do not add new entries to this table unless you have read
209  * Documentation/sysctl/ctl_unnumbered.txt
210  */
211         { .ctl_name = 0 }
212 };
213
214 #ifdef CONFIG_SCHED_DEBUG
215 static unsigned long min_sched_granularity_ns = 100000;         /* 100 usecs */
216 static unsigned long max_sched_granularity_ns = 1000000000;     /* 1 second */
217 static unsigned long min_wakeup_granularity_ns;                 /* 0 usecs */
218 static unsigned long max_wakeup_granularity_ns = 1000000000;    /* 1 second */
219 #endif
220
221 static ctl_table kern_table[] = {
222 #ifdef CONFIG_SCHED_DEBUG
223         {
224                 .ctl_name       = CTL_UNNUMBERED,
225                 .procname       = "sched_min_granularity_ns",
226                 .data           = &sysctl_sched_min_granularity,
227                 .maxlen         = sizeof(unsigned int),
228                 .mode           = 0644,
229                 .proc_handler   = &proc_dointvec_minmax,
230                 .strategy       = &sysctl_intvec,
231                 .extra1         = &min_sched_granularity_ns,
232                 .extra2         = &max_sched_granularity_ns,
233         },
234         {
235                 .ctl_name       = CTL_UNNUMBERED,
236                 .procname       = "sched_latency_ns",
237                 .data           = &sysctl_sched_latency,
238                 .maxlen         = sizeof(unsigned int),
239                 .mode           = 0644,
240                 .proc_handler   = &proc_dointvec_minmax,
241                 .strategy       = &sysctl_intvec,
242                 .extra1         = &min_sched_granularity_ns,
243                 .extra2         = &max_sched_granularity_ns,
244         },
245         {
246                 .ctl_name       = CTL_UNNUMBERED,
247                 .procname       = "sched_wakeup_granularity_ns",
248                 .data           = &sysctl_sched_wakeup_granularity,
249                 .maxlen         = sizeof(unsigned int),
250                 .mode           = 0644,
251                 .proc_handler   = &proc_dointvec_minmax,
252                 .strategy       = &sysctl_intvec,
253                 .extra1         = &min_wakeup_granularity_ns,
254                 .extra2         = &max_wakeup_granularity_ns,
255         },
256         {
257                 .ctl_name       = CTL_UNNUMBERED,
258                 .procname       = "sched_batch_wakeup_granularity_ns",
259                 .data           = &sysctl_sched_batch_wakeup_granularity,
260                 .maxlen         = sizeof(unsigned int),
261                 .mode           = 0644,
262                 .proc_handler   = &proc_dointvec_minmax,
263                 .strategy       = &sysctl_intvec,
264                 .extra1         = &min_wakeup_granularity_ns,
265                 .extra2         = &max_wakeup_granularity_ns,
266         },
267         {
268                 .ctl_name       = CTL_UNNUMBERED,
269                 .procname       = "sched_runtime_limit_ns",
270                 .data           = &sysctl_sched_runtime_limit,
271                 .maxlen         = sizeof(unsigned int),
272                 .mode           = 0644,
273                 .proc_handler   = &proc_dointvec_minmax,
274                 .strategy       = &sysctl_intvec,
275                 .extra1         = &min_sched_granularity_ns,
276                 .extra2         = &max_sched_granularity_ns,
277         },
278         {
279                 .ctl_name       = CTL_UNNUMBERED,
280                 .procname       = "sched_child_runs_first",
281                 .data           = &sysctl_sched_child_runs_first,
282                 .maxlen         = sizeof(unsigned int),
283                 .mode           = 0644,
284                 .proc_handler   = &proc_dointvec,
285         },
286         {
287                 .ctl_name       = CTL_UNNUMBERED,
288                 .procname       = "sched_features",
289                 .data           = &sysctl_sched_features,
290                 .maxlen         = sizeof(unsigned int),
291                 .mode           = 0644,
292                 .proc_handler   = &proc_dointvec,
293         },
294 #endif
295         {
296                 .ctl_name       = CTL_UNNUMBERED,
297                 .procname       = "sched_compat_yield",
298                 .data           = &sysctl_sched_compat_yield,
299                 .maxlen         = sizeof(unsigned int),
300                 .mode           = 0644,
301                 .proc_handler   = &proc_dointvec,
302         },
303 #ifdef CONFIG_PROVE_LOCKING
304         {
305                 .ctl_name       = CTL_UNNUMBERED,
306                 .procname       = "prove_locking",
307                 .data           = &prove_locking,
308                 .maxlen         = sizeof(int),
309                 .mode           = 0644,
310                 .proc_handler   = &proc_dointvec,
311         },
312 #endif
313 #ifdef CONFIG_LOCK_STAT
314         {
315                 .ctl_name       = CTL_UNNUMBERED,
316                 .procname       = "lock_stat",
317                 .data           = &lock_stat,
318                 .maxlen         = sizeof(int),
319                 .mode           = 0644,
320                 .proc_handler   = &proc_dointvec,
321         },
322 #endif
323         {
324                 .ctl_name       = KERN_PANIC,
325                 .procname       = "panic",
326                 .data           = &panic_timeout,
327                 .maxlen         = sizeof(int),
328                 .mode           = 0644,
329                 .proc_handler   = &proc_dointvec,
330         },
331         {
332                 .ctl_name       = KERN_CORE_USES_PID,
333                 .procname       = "core_uses_pid",
334                 .data           = &core_uses_pid,
335                 .maxlen         = sizeof(int),
336                 .mode           = 0644,
337                 .proc_handler   = &proc_dointvec,
338         },
339 #ifdef CONFIG_AUDITSYSCALL
340         {
341                 .ctl_name       = CTL_UNNUMBERED,
342                 .procname       = "audit_argv_kb",
343                 .data           = &audit_argv_kb,
344                 .maxlen         = sizeof(int),
345                 .mode           = 0644,
346                 .proc_handler   = &proc_dointvec,
347         },
348 #endif
349         {
350                 .ctl_name       = KERN_CORE_PATTERN,
351                 .procname       = "core_pattern",
352                 .data           = core_pattern,
353                 .maxlen         = CORENAME_MAX_SIZE,
354                 .mode           = 0644,
355                 .proc_handler   = &proc_dostring,
356                 .strategy       = &sysctl_string,
357         },
358 #ifdef CONFIG_PROC_SYSCTL
359         {
360                 .ctl_name       = KERN_TAINTED,
361                 .procname       = "tainted",
362                 .data           = &tainted,
363                 .maxlen         = sizeof(int),
364                 .mode           = 0644,
365                 .proc_handler   = &proc_dointvec_taint,
366         },
367 #endif
368         {
369                 .ctl_name       = KERN_CAP_BSET,
370                 .procname       = "cap-bound",
371                 .data           = &cap_bset,
372                 .maxlen         = sizeof(kernel_cap_t),
373                 .mode           = 0600,
374                 .proc_handler   = &proc_dointvec_bset,
375         },
376 #ifdef CONFIG_BLK_DEV_INITRD
377         {
378                 .ctl_name       = KERN_REALROOTDEV,
379                 .procname       = "real-root-dev",
380                 .data           = &real_root_dev,
381                 .maxlen         = sizeof(int),
382                 .mode           = 0644,
383                 .proc_handler   = &proc_dointvec,
384         },
385 #endif
386         {
387                 .ctl_name       = CTL_UNNUMBERED,
388                 .procname       = "print-fatal-signals",
389                 .data           = &print_fatal_signals,
390                 .maxlen         = sizeof(int),
391                 .mode           = 0644,
392                 .proc_handler   = &proc_dointvec,
393         },
394 #ifdef __sparc__
395         {
396                 .ctl_name       = KERN_SPARC_REBOOT,
397                 .procname       = "reboot-cmd",
398                 .data           = reboot_command,
399                 .maxlen         = 256,
400                 .mode           = 0644,
401                 .proc_handler   = &proc_dostring,
402                 .strategy       = &sysctl_string,
403         },
404         {
405                 .ctl_name       = KERN_SPARC_STOP_A,
406                 .procname       = "stop-a",
407                 .data           = &stop_a_enabled,
408                 .maxlen         = sizeof (int),
409                 .mode           = 0644,
410                 .proc_handler   = &proc_dointvec,
411         },
412         {
413                 .ctl_name       = KERN_SPARC_SCONS_PWROFF,
414                 .procname       = "scons-poweroff",
415                 .data           = &scons_pwroff,
416                 .maxlen         = sizeof (int),
417                 .mode           = 0644,
418                 .proc_handler   = &proc_dointvec,
419         },
420 #endif
421 #ifdef __hppa__
422         {
423                 .ctl_name       = KERN_HPPA_PWRSW,
424                 .procname       = "soft-power",
425                 .data           = &pwrsw_enabled,
426                 .maxlen         = sizeof (int),
427                 .mode           = 0644,
428                 .proc_handler   = &proc_dointvec,
429         },
430         {
431                 .ctl_name       = KERN_HPPA_UNALIGNED,
432                 .procname       = "unaligned-trap",
433                 .data           = &unaligned_enabled,
434                 .maxlen         = sizeof (int),
435                 .mode           = 0644,
436                 .proc_handler   = &proc_dointvec,
437         },
438 #endif
439         {
440                 .ctl_name       = KERN_CTLALTDEL,
441                 .procname       = "ctrl-alt-del",
442                 .data           = &C_A_D,
443                 .maxlen         = sizeof(int),
444                 .mode           = 0644,
445                 .proc_handler   = &proc_dointvec,
446         },
447         {
448                 .ctl_name       = KERN_PRINTK,
449                 .procname       = "printk",
450                 .data           = &console_loglevel,
451                 .maxlen         = 4*sizeof(int),
452                 .mode           = 0644,
453                 .proc_handler   = &proc_dointvec,
454         },
455 #ifdef CONFIG_KMOD
456         {
457                 .ctl_name       = KERN_MODPROBE,
458                 .procname       = "modprobe",
459                 .data           = &modprobe_path,
460                 .maxlen         = KMOD_PATH_LEN,
461                 .mode           = 0644,
462                 .proc_handler   = &proc_dostring,
463                 .strategy       = &sysctl_string,
464         },
465 #endif
466 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
467         {
468                 .ctl_name       = KERN_HOTPLUG,
469                 .procname       = "hotplug",
470                 .data           = &uevent_helper,
471                 .maxlen         = UEVENT_HELPER_PATH_LEN,
472                 .mode           = 0644,
473                 .proc_handler   = &proc_dostring,
474                 .strategy       = &sysctl_string,
475         },
476 #endif
477 #ifdef CONFIG_CHR_DEV_SG
478         {
479                 .ctl_name       = KERN_SG_BIG_BUFF,
480                 .procname       = "sg-big-buff",
481                 .data           = &sg_big_buff,
482                 .maxlen         = sizeof (int),
483                 .mode           = 0444,
484                 .proc_handler   = &proc_dointvec,
485         },
486 #endif
487 #ifdef CONFIG_BSD_PROCESS_ACCT
488         {
489                 .ctl_name       = KERN_ACCT,
490                 .procname       = "acct",
491                 .data           = &acct_parm,
492                 .maxlen         = 3*sizeof(int),
493                 .mode           = 0644,
494                 .proc_handler   = &proc_dointvec,
495         },
496 #endif
497 #ifdef CONFIG_MAGIC_SYSRQ
498         {
499                 .ctl_name       = KERN_SYSRQ,
500                 .procname       = "sysrq",
501                 .data           = &__sysrq_enabled,
502                 .maxlen         = sizeof (int),
503                 .mode           = 0644,
504                 .proc_handler   = &proc_dointvec,
505         },
506 #endif
507 #ifdef CONFIG_PROC_SYSCTL
508         {
509                 .ctl_name       = KERN_CADPID,
510                 .procname       = "cad_pid",
511                 .data           = NULL,
512                 .maxlen         = sizeof (int),
513                 .mode           = 0600,
514                 .proc_handler   = &proc_do_cad_pid,
515         },
516 #endif
517         {
518                 .ctl_name       = KERN_MAX_THREADS,
519                 .procname       = "threads-max",
520                 .data           = &max_threads,
521                 .maxlen         = sizeof(int),
522                 .mode           = 0644,
523                 .proc_handler   = &proc_dointvec,
524         },
525         {
526                 .ctl_name       = KERN_RANDOM,
527                 .procname       = "random",
528                 .mode           = 0555,
529                 .child          = random_table,
530         },
531 #ifdef CONFIG_UNIX98_PTYS
532         {
533                 .ctl_name       = KERN_PTY,
534                 .procname       = "pty",
535                 .mode           = 0555,
536                 .child          = pty_table,
537         },
538 #endif
539         {
540                 .ctl_name       = KERN_OVERFLOWUID,
541                 .procname       = "overflowuid",
542                 .data           = &overflowuid,
543                 .maxlen         = sizeof(int),
544                 .mode           = 0644,
545                 .proc_handler   = &proc_dointvec_minmax,
546                 .strategy       = &sysctl_intvec,
547                 .extra1         = &minolduid,
548                 .extra2         = &maxolduid,
549         },
550         {
551                 .ctl_name       = KERN_OVERFLOWGID,
552                 .procname       = "overflowgid",
553                 .data           = &overflowgid,
554                 .maxlen         = sizeof(int),
555                 .mode           = 0644,
556                 .proc_handler   = &proc_dointvec_minmax,
557                 .strategy       = &sysctl_intvec,
558                 .extra1         = &minolduid,
559                 .extra2         = &maxolduid,
560         },
561 #ifdef CONFIG_S390
562 #ifdef CONFIG_MATHEMU
563         {
564                 .ctl_name       = KERN_IEEE_EMULATION_WARNINGS,
565                 .procname       = "ieee_emulation_warnings",
566                 .data           = &sysctl_ieee_emulation_warnings,
567                 .maxlen         = sizeof(int),
568                 .mode           = 0644,
569                 .proc_handler   = &proc_dointvec,
570         },
571 #endif
572 #ifdef CONFIG_NO_IDLE_HZ
573         {
574                 .ctl_name       = KERN_HZ_TIMER,
575                 .procname       = "hz_timer",
576                 .data           = &sysctl_hz_timer,
577                 .maxlen         = sizeof(int),
578                 .mode           = 0644,
579                 .proc_handler   = &proc_dointvec,
580         },
581 #endif
582         {
583                 .ctl_name       = KERN_S390_USER_DEBUG_LOGGING,
584                 .procname       = "userprocess_debug",
585                 .data           = &sysctl_userprocess_debug,
586                 .maxlen         = sizeof(int),
587                 .mode           = 0644,
588                 .proc_handler   = &proc_dointvec,
589         },
590 #endif
591         {
592                 .ctl_name       = KERN_PIDMAX,
593                 .procname       = "pid_max",
594                 .data           = &pid_max,
595                 .maxlen         = sizeof (int),
596                 .mode           = 0644,
597                 .proc_handler   = &proc_dointvec_minmax,
598                 .strategy       = sysctl_intvec,
599                 .extra1         = &pid_max_min,
600                 .extra2         = &pid_max_max,
601         },
602         {
603                 .ctl_name       = KERN_PANIC_ON_OOPS,
604                 .procname       = "panic_on_oops",
605                 .data           = &panic_on_oops,
606                 .maxlen         = sizeof(int),
607                 .mode           = 0644,
608                 .proc_handler   = &proc_dointvec,
609         },
610         {
611                 .ctl_name       = KERN_PRINTK_RATELIMIT,
612                 .procname       = "printk_ratelimit",
613                 .data           = &printk_ratelimit_jiffies,
614                 .maxlen         = sizeof(int),
615                 .mode           = 0644,
616                 .proc_handler   = &proc_dointvec_jiffies,
617                 .strategy       = &sysctl_jiffies,
618         },
619         {
620                 .ctl_name       = KERN_PRINTK_RATELIMIT_BURST,
621                 .procname       = "printk_ratelimit_burst",
622                 .data           = &printk_ratelimit_burst,
623                 .maxlen         = sizeof(int),
624                 .mode           = 0644,
625                 .proc_handler   = &proc_dointvec,
626         },
627         {
628                 .ctl_name       = KERN_NGROUPS_MAX,
629                 .procname       = "ngroups_max",
630                 .data           = &ngroups_max,
631                 .maxlen         = sizeof (int),
632                 .mode           = 0444,
633                 .proc_handler   = &proc_dointvec,
634         },
635 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
636         {
637                 .ctl_name       = KERN_UNKNOWN_NMI_PANIC,
638                 .procname       = "unknown_nmi_panic",
639                 .data           = &unknown_nmi_panic,
640                 .maxlen         = sizeof (int),
641                 .mode           = 0644,
642                 .proc_handler   = &proc_dointvec,
643         },
644         {
645                 .ctl_name       = KERN_NMI_WATCHDOG,
646                 .procname       = "nmi_watchdog",
647                 .data           = &nmi_watchdog_enabled,
648                 .maxlen         = sizeof (int),
649                 .mode           = 0644,
650                 .proc_handler   = &proc_nmi_enabled,
651         },
652 #endif
653 #if defined(CONFIG_X86)
654         {
655                 .ctl_name       = KERN_PANIC_ON_NMI,
656                 .procname       = "panic_on_unrecovered_nmi",
657                 .data           = &panic_on_unrecovered_nmi,
658                 .maxlen         = sizeof(int),
659                 .mode           = 0644,
660                 .proc_handler   = &proc_dointvec,
661         },
662         {
663                 .ctl_name       = KERN_BOOTLOADER_TYPE,
664                 .procname       = "bootloader_type",
665                 .data           = &bootloader_type,
666                 .maxlen         = sizeof (int),
667                 .mode           = 0444,
668                 .proc_handler   = &proc_dointvec,
669         },
670         {
671                 .ctl_name       = CTL_UNNUMBERED,
672                 .procname       = "kstack_depth_to_print",
673                 .data           = &kstack_depth_to_print,
674                 .maxlen         = sizeof(int),
675                 .mode           = 0644,
676                 .proc_handler   = &proc_dointvec,
677         },
678 #endif
679 #if defined(CONFIG_MMU)
680         {
681                 .ctl_name       = KERN_RANDOMIZE,
682                 .procname       = "randomize_va_space",
683                 .data           = &randomize_va_space,
684                 .maxlen         = sizeof(int),
685                 .mode           = 0644,
686                 .proc_handler   = &proc_dointvec,
687         },
688 #endif
689 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
690         {
691                 .ctl_name       = KERN_SPIN_RETRY,
692                 .procname       = "spin_retry",
693                 .data           = &spin_retry,
694                 .maxlen         = sizeof (int),
695                 .mode           = 0644,
696                 .proc_handler   = &proc_dointvec,
697         },
698 #endif
699 #if     defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
700         {
701                 .ctl_name       = KERN_ACPI_VIDEO_FLAGS,
702                 .procname       = "acpi_video_flags",
703                 .data           = &acpi_realmode_flags,
704                 .maxlen         = sizeof (unsigned long),
705                 .mode           = 0644,
706                 .proc_handler   = &proc_doulongvec_minmax,
707         },
708 #endif
709 #ifdef CONFIG_IA64
710         {
711                 .ctl_name       = KERN_IA64_UNALIGNED,
712                 .procname       = "ignore-unaligned-usertrap",
713                 .data           = &no_unaligned_warning,
714                 .maxlen         = sizeof (int),
715                 .mode           = 0644,
716                 .proc_handler   = &proc_dointvec,
717         },
718 #endif
719 #ifdef CONFIG_COMPAT
720         {
721                 .ctl_name       = KERN_COMPAT_LOG,
722                 .procname       = "compat-log",
723                 .data           = &compat_log,
724                 .maxlen         = sizeof (int),
725                 .mode           = 0644,
726                 .proc_handler   = &proc_dointvec,
727         },
728 #endif
729 #ifdef CONFIG_RT_MUTEXES
730         {
731                 .ctl_name       = KERN_MAX_LOCK_DEPTH,
732                 .procname       = "max_lock_depth",
733                 .data           = &max_lock_depth,
734                 .maxlen         = sizeof(int),
735                 .mode           = 0644,
736                 .proc_handler   = &proc_dointvec,
737         },
738 #endif
739 #ifdef CONFIG_PROC_FS
740         {
741                 .ctl_name       = CTL_UNNUMBERED,
742                 .procname       = "maps_protect",
743                 .data           = &maps_protect,
744                 .maxlen         = sizeof(int),
745                 .mode           = 0644,
746                 .proc_handler   = &proc_dointvec,
747         },
748 #endif
749         {
750                 .ctl_name       = CTL_UNNUMBERED,
751                 .procname       = "poweroff_cmd",
752                 .data           = &poweroff_cmd,
753                 .maxlen         = POWEROFF_CMD_PATH_LEN,
754                 .mode           = 0644,
755                 .proc_handler   = &proc_dostring,
756                 .strategy       = &sysctl_string,
757         },
758 /*
759  * NOTE: do not add new entries to this table unless you have read
760  * Documentation/sysctl/ctl_unnumbered.txt
761  */
762         { .ctl_name = 0 }
763 };
764
765 /* Constants for minimum and maximum testing in vm_table.
766    We use these as one-element integer vectors. */
767 static int zero;
768 static int two = 2;
769 static int one_hundred = 100;
770
771
772 static ctl_table vm_table[] = {
773         {
774                 .ctl_name       = VM_OVERCOMMIT_MEMORY,
775                 .procname       = "overcommit_memory",
776                 .data           = &sysctl_overcommit_memory,
777                 .maxlen         = sizeof(sysctl_overcommit_memory),
778                 .mode           = 0644,
779                 .proc_handler   = &proc_dointvec,
780         },
781         {
782                 .ctl_name       = VM_PANIC_ON_OOM,
783                 .procname       = "panic_on_oom",
784                 .data           = &sysctl_panic_on_oom,
785                 .maxlen         = sizeof(sysctl_panic_on_oom),
786                 .mode           = 0644,
787                 .proc_handler   = &proc_dointvec,
788         },
789         {
790                 .ctl_name       = VM_OVERCOMMIT_RATIO,
791                 .procname       = "overcommit_ratio",
792                 .data           = &sysctl_overcommit_ratio,
793                 .maxlen         = sizeof(sysctl_overcommit_ratio),
794                 .mode           = 0644,
795                 .proc_handler   = &proc_dointvec,
796         },
797         {
798                 .ctl_name       = VM_PAGE_CLUSTER,
799                 .procname       = "page-cluster", 
800                 .data           = &page_cluster,
801                 .maxlen         = sizeof(int),
802                 .mode           = 0644,
803                 .proc_handler   = &proc_dointvec,
804         },
805         {
806                 .ctl_name       = VM_DIRTY_BACKGROUND,
807                 .procname       = "dirty_background_ratio",
808                 .data           = &dirty_background_ratio,
809                 .maxlen         = sizeof(dirty_background_ratio),
810                 .mode           = 0644,
811                 .proc_handler   = &proc_dointvec_minmax,
812                 .strategy       = &sysctl_intvec,
813                 .extra1         = &zero,
814                 .extra2         = &one_hundred,
815         },
816         {
817                 .ctl_name       = VM_DIRTY_RATIO,
818                 .procname       = "dirty_ratio",
819                 .data           = &vm_dirty_ratio,
820                 .maxlen         = sizeof(vm_dirty_ratio),
821                 .mode           = 0644,
822                 .proc_handler   = &proc_dointvec_minmax,
823                 .strategy       = &sysctl_intvec,
824                 .extra1         = &zero,
825                 .extra2         = &one_hundred,
826         },
827         {
828                 .ctl_name       = VM_DIRTY_WB_CS,
829                 .procname       = "dirty_writeback_centisecs",
830                 .data           = &dirty_writeback_interval,
831                 .maxlen         = sizeof(dirty_writeback_interval),
832                 .mode           = 0644,
833                 .proc_handler   = &dirty_writeback_centisecs_handler,
834         },
835         {
836                 .ctl_name       = VM_DIRTY_EXPIRE_CS,
837                 .procname       = "dirty_expire_centisecs",
838                 .data           = &dirty_expire_interval,
839                 .maxlen         = sizeof(dirty_expire_interval),
840                 .mode           = 0644,
841                 .proc_handler   = &proc_dointvec_userhz_jiffies,
842         },
843         {
844                 .ctl_name       = VM_NR_PDFLUSH_THREADS,
845                 .procname       = "nr_pdflush_threads",
846                 .data           = &nr_pdflush_threads,
847                 .maxlen         = sizeof nr_pdflush_threads,
848                 .mode           = 0444 /* read-only*/,
849                 .proc_handler   = &proc_dointvec,
850         },
851         {
852                 .ctl_name       = VM_SWAPPINESS,
853                 .procname       = "swappiness",
854                 .data           = &vm_swappiness,
855                 .maxlen         = sizeof(vm_swappiness),
856                 .mode           = 0644,
857                 .proc_handler   = &proc_dointvec_minmax,
858                 .strategy       = &sysctl_intvec,
859                 .extra1         = &zero,
860                 .extra2         = &one_hundred,
861         },
862 #ifdef CONFIG_HUGETLB_PAGE
863          {
864                 .ctl_name       = VM_HUGETLB_PAGES,
865                 .procname       = "nr_hugepages",
866                 .data           = &max_huge_pages,
867                 .maxlen         = sizeof(unsigned long),
868                 .mode           = 0644,
869                 .proc_handler   = &hugetlb_sysctl_handler,
870                 .extra1         = (void *)&hugetlb_zero,
871                 .extra2         = (void *)&hugetlb_infinity,
872          },
873          {
874                 .ctl_name       = VM_HUGETLB_GROUP,
875                 .procname       = "hugetlb_shm_group",
876                 .data           = &sysctl_hugetlb_shm_group,
877                 .maxlen         = sizeof(gid_t),
878                 .mode           = 0644,
879                 .proc_handler   = &proc_dointvec,
880          },
881          {
882                 .ctl_name       = CTL_UNNUMBERED,
883                 .procname       = "hugepages_treat_as_movable",
884                 .data           = &hugepages_treat_as_movable,
885                 .maxlen         = sizeof(int),
886                 .mode           = 0644,
887                 .proc_handler   = &hugetlb_treat_movable_handler,
888         },
889 #endif
890         {
891                 .ctl_name       = VM_LOWMEM_RESERVE_RATIO,
892                 .procname       = "lowmem_reserve_ratio",
893                 .data           = &sysctl_lowmem_reserve_ratio,
894                 .maxlen         = sizeof(sysctl_lowmem_reserve_ratio),
895                 .mode           = 0644,
896                 .proc_handler   = &lowmem_reserve_ratio_sysctl_handler,
897                 .strategy       = &sysctl_intvec,
898         },
899         {
900                 .ctl_name       = VM_DROP_PAGECACHE,
901                 .procname       = "drop_caches",
902                 .data           = &sysctl_drop_caches,
903                 .maxlen         = sizeof(int),
904                 .mode           = 0644,
905                 .proc_handler   = drop_caches_sysctl_handler,
906                 .strategy       = &sysctl_intvec,
907         },
908         {
909                 .ctl_name       = VM_MIN_FREE_KBYTES,
910                 .procname       = "min_free_kbytes",
911                 .data           = &min_free_kbytes,
912                 .maxlen         = sizeof(min_free_kbytes),
913                 .mode           = 0644,
914                 .proc_handler   = &min_free_kbytes_sysctl_handler,
915                 .strategy       = &sysctl_intvec,
916                 .extra1         = &zero,
917         },
918         {
919                 .ctl_name       = VM_PERCPU_PAGELIST_FRACTION,
920                 .procname       = "percpu_pagelist_fraction",
921                 .data           = &percpu_pagelist_fraction,
922                 .maxlen         = sizeof(percpu_pagelist_fraction),
923                 .mode           = 0644,
924                 .proc_handler   = &percpu_pagelist_fraction_sysctl_handler,
925                 .strategy       = &sysctl_intvec,
926                 .extra1         = &min_percpu_pagelist_fract,
927         },
928 #ifdef CONFIG_MMU
929         {
930                 .ctl_name       = VM_MAX_MAP_COUNT,
931                 .procname       = "max_map_count",
932                 .data           = &sysctl_max_map_count,
933                 .maxlen         = sizeof(sysctl_max_map_count),
934                 .mode           = 0644,
935                 .proc_handler   = &proc_dointvec
936         },
937 #endif
938         {
939                 .ctl_name       = VM_LAPTOP_MODE,
940                 .procname       = "laptop_mode",
941                 .data           = &laptop_mode,
942                 .maxlen         = sizeof(laptop_mode),
943                 .mode           = 0644,
944                 .proc_handler   = &proc_dointvec_jiffies,
945                 .strategy       = &sysctl_jiffies,
946         },
947         {
948                 .ctl_name       = VM_BLOCK_DUMP,
949                 .procname       = "block_dump",
950                 .data           = &block_dump,
951                 .maxlen         = sizeof(block_dump),
952                 .mode           = 0644,
953                 .proc_handler   = &proc_dointvec,
954                 .strategy       = &sysctl_intvec,
955                 .extra1         = &zero,
956         },
957         {
958                 .ctl_name       = VM_VFS_CACHE_PRESSURE,
959                 .procname       = "vfs_cache_pressure",
960                 .data           = &sysctl_vfs_cache_pressure,
961                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
962                 .mode           = 0644,
963                 .proc_handler   = &proc_dointvec,
964                 .strategy       = &sysctl_intvec,
965                 .extra1         = &zero,
966         },
967 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
968         {
969                 .ctl_name       = VM_LEGACY_VA_LAYOUT,
970                 .procname       = "legacy_va_layout",
971                 .data           = &sysctl_legacy_va_layout,
972                 .maxlen         = sizeof(sysctl_legacy_va_layout),
973                 .mode           = 0644,
974                 .proc_handler   = &proc_dointvec,
975                 .strategy       = &sysctl_intvec,
976                 .extra1         = &zero,
977         },
978 #endif
979 #ifdef CONFIG_NUMA
980         {
981                 .ctl_name       = VM_ZONE_RECLAIM_MODE,
982                 .procname       = "zone_reclaim_mode",
983                 .data           = &zone_reclaim_mode,
984                 .maxlen         = sizeof(zone_reclaim_mode),
985                 .mode           = 0644,
986                 .proc_handler   = &proc_dointvec,
987                 .strategy       = &sysctl_intvec,
988                 .extra1         = &zero,
989         },
990         {
991                 .ctl_name       = VM_MIN_UNMAPPED,
992                 .procname       = "min_unmapped_ratio",
993                 .data           = &sysctl_min_unmapped_ratio,
994                 .maxlen         = sizeof(sysctl_min_unmapped_ratio),
995                 .mode           = 0644,
996                 .proc_handler   = &sysctl_min_unmapped_ratio_sysctl_handler,
997                 .strategy       = &sysctl_intvec,
998                 .extra1         = &zero,
999                 .extra2         = &one_hundred,
1000         },
1001         {
1002                 .ctl_name       = VM_MIN_SLAB,
1003                 .procname       = "min_slab_ratio",
1004                 .data           = &sysctl_min_slab_ratio,
1005                 .maxlen         = sizeof(sysctl_min_slab_ratio),
1006                 .mode           = 0644,
1007                 .proc_handler   = &sysctl_min_slab_ratio_sysctl_handler,
1008                 .strategy       = &sysctl_intvec,
1009                 .extra1         = &zero,
1010                 .extra2         = &one_hundred,
1011         },
1012 #endif
1013 #ifdef CONFIG_SMP
1014         {
1015                 .ctl_name       = CTL_UNNUMBERED,
1016                 .procname       = "stat_interval",
1017                 .data           = &sysctl_stat_interval,
1018                 .maxlen         = sizeof(sysctl_stat_interval),
1019                 .mode           = 0644,
1020                 .proc_handler   = &proc_dointvec_jiffies,
1021                 .strategy       = &sysctl_jiffies,
1022         },
1023 #endif
1024 #ifdef CONFIG_SECURITY
1025         {
1026                 .ctl_name       = CTL_UNNUMBERED,
1027                 .procname       = "mmap_min_addr",
1028                 .data           = &mmap_min_addr,
1029                 .maxlen         = sizeof(unsigned long),
1030                 .mode           = 0644,
1031                 .proc_handler   = &proc_doulongvec_minmax,
1032         },
1033 #endif
1034 #ifdef CONFIG_NUMA
1035         {
1036                 .ctl_name       = CTL_UNNUMBERED,
1037                 .procname       = "numa_zonelist_order",
1038                 .data           = &numa_zonelist_order,
1039                 .maxlen         = NUMA_ZONELIST_ORDER_LEN,
1040                 .mode           = 0644,
1041                 .proc_handler   = &numa_zonelist_order_handler,
1042                 .strategy       = &sysctl_string,
1043         },
1044 #endif
1045 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1046    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1047         {
1048                 .ctl_name       = VM_VDSO_ENABLED,
1049                 .procname       = "vdso_enabled",
1050                 .data           = &vdso_enabled,
1051                 .maxlen         = sizeof(vdso_enabled),
1052                 .mode           = 0644,
1053                 .proc_handler   = &proc_dointvec,
1054                 .strategy       = &sysctl_intvec,
1055                 .extra1         = &zero,
1056         },
1057 #endif
1058 /*
1059  * NOTE: do not add new entries to this table unless you have read
1060  * Documentation/sysctl/ctl_unnumbered.txt
1061  */
1062         { .ctl_name = 0 }
1063 };
1064
1065 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1066 static ctl_table binfmt_misc_table[] = {
1067         { .ctl_name = 0 }
1068 };
1069 #endif
1070
1071 static ctl_table fs_table[] = {
1072         {
1073                 .ctl_name       = FS_NRINODE,
1074                 .procname       = "inode-nr",
1075                 .data           = &inodes_stat,
1076                 .maxlen         = 2*sizeof(int),
1077                 .mode           = 0444,
1078                 .proc_handler   = &proc_dointvec,
1079         },
1080         {
1081                 .ctl_name       = FS_STATINODE,
1082                 .procname       = "inode-state",
1083                 .data           = &inodes_stat,
1084                 .maxlen         = 7*sizeof(int),
1085                 .mode           = 0444,
1086                 .proc_handler   = &proc_dointvec,
1087         },
1088         {
1089                 .ctl_name       = FS_NRFILE,
1090                 .procname       = "file-nr",
1091                 .data           = &files_stat,
1092                 .maxlen         = 3*sizeof(int),
1093                 .mode           = 0444,
1094                 .proc_handler   = &proc_nr_files,
1095         },
1096         {
1097                 .ctl_name       = FS_MAXFILE,
1098                 .procname       = "file-max",
1099                 .data           = &files_stat.max_files,
1100                 .maxlen         = sizeof(int),
1101                 .mode           = 0644,
1102                 .proc_handler   = &proc_dointvec,
1103         },
1104         {
1105                 .ctl_name       = FS_DENTRY,
1106                 .procname       = "dentry-state",
1107                 .data           = &dentry_stat,
1108                 .maxlen         = 6*sizeof(int),
1109                 .mode           = 0444,
1110                 .proc_handler   = &proc_dointvec,
1111         },
1112         {
1113                 .ctl_name       = FS_OVERFLOWUID,
1114                 .procname       = "overflowuid",
1115                 .data           = &fs_overflowuid,
1116                 .maxlen         = sizeof(int),
1117                 .mode           = 0644,
1118                 .proc_handler   = &proc_dointvec_minmax,
1119                 .strategy       = &sysctl_intvec,
1120                 .extra1         = &minolduid,
1121                 .extra2         = &maxolduid,
1122         },
1123         {
1124                 .ctl_name       = FS_OVERFLOWGID,
1125                 .procname       = "overflowgid",
1126                 .data           = &fs_overflowgid,
1127                 .maxlen         = sizeof(int),
1128                 .mode           = 0644,
1129                 .proc_handler   = &proc_dointvec_minmax,
1130                 .strategy       = &sysctl_intvec,
1131                 .extra1         = &minolduid,
1132                 .extra2         = &maxolduid,
1133         },
1134         {
1135                 .ctl_name       = FS_LEASES,
1136                 .procname       = "leases-enable",
1137                 .data           = &leases_enable,
1138                 .maxlen         = sizeof(int),
1139                 .mode           = 0644,
1140                 .proc_handler   = &proc_dointvec,
1141         },
1142 #ifdef CONFIG_DNOTIFY
1143         {
1144                 .ctl_name       = FS_DIR_NOTIFY,
1145                 .procname       = "dir-notify-enable",
1146                 .data           = &dir_notify_enable,
1147                 .maxlen         = sizeof(int),
1148                 .mode           = 0644,
1149                 .proc_handler   = &proc_dointvec,
1150         },
1151 #endif
1152 #ifdef CONFIG_MMU
1153         {
1154                 .ctl_name       = FS_LEASE_TIME,
1155                 .procname       = "lease-break-time",
1156                 .data           = &lease_break_time,
1157                 .maxlen         = sizeof(int),
1158                 .mode           = 0644,
1159                 .proc_handler   = &proc_dointvec_minmax,
1160                 .strategy       = &sysctl_intvec,
1161                 .extra1         = &zero,
1162                 .extra2         = &two,
1163         },
1164         {
1165                 .ctl_name       = FS_AIO_NR,
1166                 .procname       = "aio-nr",
1167                 .data           = &aio_nr,
1168                 .maxlen         = sizeof(aio_nr),
1169                 .mode           = 0444,
1170                 .proc_handler   = &proc_doulongvec_minmax,
1171         },
1172         {
1173                 .ctl_name       = FS_AIO_MAX_NR,
1174                 .procname       = "aio-max-nr",
1175                 .data           = &aio_max_nr,
1176                 .maxlen         = sizeof(aio_max_nr),
1177                 .mode           = 0644,
1178                 .proc_handler   = &proc_doulongvec_minmax,
1179         },
1180 #ifdef CONFIG_INOTIFY_USER
1181         {
1182                 .ctl_name       = FS_INOTIFY,
1183                 .procname       = "inotify",
1184                 .mode           = 0555,
1185                 .child          = inotify_table,
1186         },
1187 #endif  
1188 #endif
1189         {
1190                 .ctl_name       = KERN_SETUID_DUMPABLE,
1191                 .procname       = "suid_dumpable",
1192                 .data           = &suid_dumpable,
1193                 .maxlen         = sizeof(int),
1194                 .mode           = 0644,
1195                 .proc_handler   = &proc_dointvec,
1196         },
1197 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1198         {
1199                 .ctl_name       = CTL_UNNUMBERED,
1200                 .procname       = "binfmt_misc",
1201                 .mode           = 0555,
1202                 .child          = binfmt_misc_table,
1203         },
1204 #endif
1205 /*
1206  * NOTE: do not add new entries to this table unless you have read
1207  * Documentation/sysctl/ctl_unnumbered.txt
1208  */
1209         { .ctl_name = 0 }
1210 };
1211
1212 static ctl_table debug_table[] = {
1213 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1214         {
1215                 .ctl_name       = CTL_UNNUMBERED,
1216                 .procname       = "exception-trace",
1217                 .data           = &show_unhandled_signals,
1218                 .maxlen         = sizeof(int),
1219                 .mode           = 0644,
1220                 .proc_handler   = proc_dointvec
1221         },
1222 #endif
1223         { .ctl_name = 0 }
1224 };
1225
1226 static ctl_table dev_table[] = {
1227         { .ctl_name = 0 }
1228 };
1229
1230 static DEFINE_SPINLOCK(sysctl_lock);
1231
1232 /* called under sysctl_lock */
1233 static int use_table(struct ctl_table_header *p)
1234 {
1235         if (unlikely(p->unregistering))
1236                 return 0;
1237         p->used++;
1238         return 1;
1239 }
1240
1241 /* called under sysctl_lock */
1242 static void unuse_table(struct ctl_table_header *p)
1243 {
1244         if (!--p->used)
1245                 if (unlikely(p->unregistering))
1246                         complete(p->unregistering);
1247 }
1248
1249 /* called under sysctl_lock, will reacquire if has to wait */
1250 static void start_unregistering(struct ctl_table_header *p)
1251 {
1252         /*
1253          * if p->used is 0, nobody will ever touch that entry again;
1254          * we'll eliminate all paths to it before dropping sysctl_lock
1255          */
1256         if (unlikely(p->used)) {
1257                 struct completion wait;
1258                 init_completion(&wait);
1259                 p->unregistering = &wait;
1260                 spin_unlock(&sysctl_lock);
1261                 wait_for_completion(&wait);
1262                 spin_lock(&sysctl_lock);
1263         }
1264         /*
1265          * do not remove from the list until nobody holds it; walking the
1266          * list in do_sysctl() relies on that.
1267          */
1268         list_del_init(&p->ctl_entry);
1269 }
1270
1271 void sysctl_head_finish(struct ctl_table_header *head)
1272 {
1273         if (!head)
1274                 return;
1275         spin_lock(&sysctl_lock);
1276         unuse_table(head);
1277         spin_unlock(&sysctl_lock);
1278 }
1279
1280 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1281 {
1282         struct ctl_table_header *head;
1283         struct list_head *tmp;
1284         spin_lock(&sysctl_lock);
1285         if (prev) {
1286                 tmp = &prev->ctl_entry;
1287                 unuse_table(prev);
1288                 goto next;
1289         }
1290         tmp = &root_table_header.ctl_entry;
1291         for (;;) {
1292                 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1293
1294                 if (!use_table(head))
1295                         goto next;
1296                 spin_unlock(&sysctl_lock);
1297                 return head;
1298         next:
1299                 tmp = tmp->next;
1300                 if (tmp == &root_table_header.ctl_entry)
1301                         break;
1302         }
1303         spin_unlock(&sysctl_lock);
1304         return NULL;
1305 }
1306
1307 #ifdef CONFIG_SYSCTL_SYSCALL
1308 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1309                void __user *newval, size_t newlen)
1310 {
1311         struct ctl_table_header *head;
1312         int error = -ENOTDIR;
1313
1314         if (nlen <= 0 || nlen >= CTL_MAXNAME)
1315                 return -ENOTDIR;
1316         if (oldval) {
1317                 int old_len;
1318                 if (!oldlenp || get_user(old_len, oldlenp))
1319                         return -EFAULT;
1320         }
1321
1322         for (head = sysctl_head_next(NULL); head;
1323                         head = sysctl_head_next(head)) {
1324                 error = parse_table(name, nlen, oldval, oldlenp, 
1325                                         newval, newlen, head->ctl_table);
1326                 if (error != -ENOTDIR) {
1327                         sysctl_head_finish(head);
1328                         break;
1329                 }
1330         }
1331         return error;
1332 }
1333
1334 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1335 {
1336         struct __sysctl_args tmp;
1337         int error;
1338
1339         if (copy_from_user(&tmp, args, sizeof(tmp)))
1340                 return -EFAULT;
1341
1342         lock_kernel();
1343         error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1344                           tmp.newval, tmp.newlen);
1345         unlock_kernel();
1346         return error;
1347 }
1348 #endif /* CONFIG_SYSCTL_SYSCALL */
1349
1350 /*
1351  * sysctl_perm does NOT grant the superuser all rights automatically, because
1352  * some sysctl variables are readonly even to root.
1353  */
1354
1355 static int test_perm(int mode, int op)
1356 {
1357         if (!current->euid)
1358                 mode >>= 6;
1359         else if (in_egroup_p(0))
1360                 mode >>= 3;
1361         if ((mode & op & 0007) == op)
1362                 return 0;
1363         return -EACCES;
1364 }
1365
1366 int sysctl_perm(ctl_table *table, int op)
1367 {
1368         int error;
1369         error = security_sysctl(table, op);
1370         if (error)
1371                 return error;
1372         return test_perm(table->mode, op);
1373 }
1374
1375 #ifdef CONFIG_SYSCTL_SYSCALL
1376 static int parse_table(int __user *name, int nlen,
1377                        void __user *oldval, size_t __user *oldlenp,
1378                        void __user *newval, size_t newlen,
1379                        ctl_table *table)
1380 {
1381         int n;
1382 repeat:
1383         if (!nlen)
1384                 return -ENOTDIR;
1385         if (get_user(n, name))
1386                 return -EFAULT;
1387         for ( ; table->ctl_name || table->procname; table++) {
1388                 if (!table->ctl_name)
1389                         continue;
1390                 if (n == table->ctl_name) {
1391                         int error;
1392                         if (table->child) {
1393                                 if (sysctl_perm(table, 001))
1394                                         return -EPERM;
1395                                 name++;
1396                                 nlen--;
1397                                 table = table->child;
1398                                 goto repeat;
1399                         }
1400                         error = do_sysctl_strategy(table, name, nlen,
1401                                                    oldval, oldlenp,
1402                                                    newval, newlen);
1403                         return error;
1404                 }
1405         }
1406         return -ENOTDIR;
1407 }
1408
1409 /* Perform the actual read/write of a sysctl table entry. */
1410 int do_sysctl_strategy (ctl_table *table, 
1411                         int __user *name, int nlen,
1412                         void __user *oldval, size_t __user *oldlenp,
1413                         void __user *newval, size_t newlen)
1414 {
1415         int op = 0, rc;
1416         size_t len;
1417
1418         if (oldval)
1419                 op |= 004;
1420         if (newval) 
1421                 op |= 002;
1422         if (sysctl_perm(table, op))
1423                 return -EPERM;
1424
1425         if (table->strategy) {
1426                 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1427                                      newval, newlen);
1428                 if (rc < 0)
1429                         return rc;
1430                 if (rc > 0)
1431                         return 0;
1432         }
1433
1434         /* If there is no strategy routine, or if the strategy returns
1435          * zero, proceed with automatic r/w */
1436         if (table->data && table->maxlen) {
1437                 if (oldval && oldlenp) {
1438                         if (get_user(len, oldlenp))
1439                                 return -EFAULT;
1440                         if (len) {
1441                                 if (len > table->maxlen)
1442                                         len = table->maxlen;
1443                                 if(copy_to_user(oldval, table->data, len))
1444                                         return -EFAULT;
1445                                 if(put_user(len, oldlenp))
1446                                         return -EFAULT;
1447                         }
1448                 }
1449                 if (newval && newlen) {
1450                         len = newlen;
1451                         if (len > table->maxlen)
1452                                 len = table->maxlen;
1453                         if(copy_from_user(table->data, newval, len))
1454                                 return -EFAULT;
1455                 }
1456         }
1457         return 0;
1458 }
1459 #endif /* CONFIG_SYSCTL_SYSCALL */
1460
1461 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1462 {
1463         for (; table->ctl_name || table->procname; table++) {
1464                 table->parent = parent;
1465                 if (table->child)
1466                         sysctl_set_parent(table, table->child);
1467         }
1468 }
1469
1470 static __init int sysctl_init(void)
1471 {
1472         sysctl_set_parent(NULL, root_table);
1473         return 0;
1474 }
1475
1476 core_initcall(sysctl_init);
1477
1478 /**
1479  * register_sysctl_table - register a sysctl hierarchy
1480  * @table: the top-level table structure
1481  *
1482  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1483  * array. An entry with a ctl_name of 0 terminates the table. 
1484  *
1485  * The members of the &ctl_table structure are used as follows:
1486  *
1487  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1488  *            must be unique within that level of sysctl
1489  *
1490  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1491  *            enter a sysctl file
1492  *
1493  * data - a pointer to data for use by proc_handler
1494  *
1495  * maxlen - the maximum size in bytes of the data
1496  *
1497  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1498  *
1499  * child - a pointer to the child sysctl table if this entry is a directory, or
1500  *         %NULL.
1501  *
1502  * proc_handler - the text handler routine (described below)
1503  *
1504  * strategy - the strategy routine (described below)
1505  *
1506  * de - for internal use by the sysctl routines
1507  *
1508  * extra1, extra2 - extra pointers usable by the proc handler routines
1509  *
1510  * Leaf nodes in the sysctl tree will be represented by a single file
1511  * under /proc; non-leaf nodes will be represented by directories.
1512  *
1513  * sysctl(2) can automatically manage read and write requests through
1514  * the sysctl table.  The data and maxlen fields of the ctl_table
1515  * struct enable minimal validation of the values being written to be
1516  * performed, and the mode field allows minimal authentication.
1517  *
1518  * More sophisticated management can be enabled by the provision of a
1519  * strategy routine with the table entry.  This will be called before
1520  * any automatic read or write of the data is performed.
1521  *
1522  * The strategy routine may return
1523  *
1524  * < 0 - Error occurred (error is passed to user process)
1525  *
1526  * 0   - OK - proceed with automatic read or write.
1527  *
1528  * > 0 - OK - read or write has been done by the strategy routine, so
1529  *       return immediately.
1530  *
1531  * There must be a proc_handler routine for any terminal nodes
1532  * mirrored under /proc/sys (non-terminals are handled by a built-in
1533  * directory handler).  Several default handlers are available to
1534  * cover common cases -
1535  *
1536  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1537  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 
1538  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1539  *
1540  * It is the handler's job to read the input buffer from user memory
1541  * and process it. The handler should return 0 on success.
1542  *
1543  * This routine returns %NULL on a failure to register, and a pointer
1544  * to the table header on success.
1545  */
1546 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1547 {
1548         struct ctl_table_header *tmp;
1549         tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1550         if (!tmp)
1551                 return NULL;
1552         tmp->ctl_table = table;
1553         INIT_LIST_HEAD(&tmp->ctl_entry);
1554         tmp->used = 0;
1555         tmp->unregistering = NULL;
1556         sysctl_set_parent(NULL, table);
1557         spin_lock(&sysctl_lock);
1558         list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1559         spin_unlock(&sysctl_lock);
1560         return tmp;
1561 }
1562
1563 /**
1564  * unregister_sysctl_table - unregister a sysctl table hierarchy
1565  * @header: the header returned from register_sysctl_table
1566  *
1567  * Unregisters the sysctl table and all children. proc entries may not
1568  * actually be removed until they are no longer used by anyone.
1569  */
1570 void unregister_sysctl_table(struct ctl_table_header * header)
1571 {
1572         might_sleep();
1573         spin_lock(&sysctl_lock);
1574         start_unregistering(header);
1575         spin_unlock(&sysctl_lock);
1576         kfree(header);
1577 }
1578
1579 #else /* !CONFIG_SYSCTL */
1580 struct ctl_table_header *register_sysctl_table(ctl_table * table)
1581 {
1582         return NULL;
1583 }
1584
1585 void unregister_sysctl_table(struct ctl_table_header * table)
1586 {
1587 }
1588
1589 #endif /* CONFIG_SYSCTL */
1590
1591 /*
1592  * /proc/sys support
1593  */
1594
1595 #ifdef CONFIG_PROC_SYSCTL
1596
1597 static int _proc_do_string(void* data, int maxlen, int write,
1598                            struct file *filp, void __user *buffer,
1599                            size_t *lenp, loff_t *ppos)
1600 {
1601         size_t len;
1602         char __user *p;
1603         char c;
1604
1605         if (!data || !maxlen || !*lenp) {
1606                 *lenp = 0;
1607                 return 0;
1608         }
1609
1610         if (write) {
1611                 len = 0;
1612                 p = buffer;
1613                 while (len < *lenp) {
1614                         if (get_user(c, p++))
1615                                 return -EFAULT;
1616                         if (c == 0 || c == '\n')
1617                                 break;
1618                         len++;
1619                 }
1620                 if (len >= maxlen)
1621                         len = maxlen-1;
1622                 if(copy_from_user(data, buffer, len))
1623                         return -EFAULT;
1624                 ((char *) data)[len] = 0;
1625                 *ppos += *lenp;
1626         } else {
1627                 len = strlen(data);
1628                 if (len > maxlen)
1629                         len = maxlen;
1630
1631                 if (*ppos > len) {
1632                         *lenp = 0;
1633                         return 0;
1634                 }
1635
1636                 data += *ppos;
1637                 len  -= *ppos;
1638
1639                 if (len > *lenp)
1640                         len = *lenp;
1641                 if (len)
1642                         if(copy_to_user(buffer, data, len))
1643                                 return -EFAULT;
1644                 if (len < *lenp) {
1645                         if(put_user('\n', ((char __user *) buffer) + len))
1646                                 return -EFAULT;
1647                         len++;
1648                 }
1649                 *lenp = len;
1650                 *ppos += len;
1651         }
1652         return 0;
1653 }
1654
1655 /**
1656  * proc_dostring - read a string sysctl
1657  * @table: the sysctl table
1658  * @write: %TRUE if this is a write to the sysctl file
1659  * @filp: the file structure
1660  * @buffer: the user buffer
1661  * @lenp: the size of the user buffer
1662  * @ppos: file position
1663  *
1664  * Reads/writes a string from/to the user buffer. If the kernel
1665  * buffer provided is not large enough to hold the string, the
1666  * string is truncated. The copied string is %NULL-terminated.
1667  * If the string is being read by the user process, it is copied
1668  * and a newline '\n' is added. It is truncated if the buffer is
1669  * not large enough.
1670  *
1671  * Returns 0 on success.
1672  */
1673 int proc_dostring(ctl_table *table, int write, struct file *filp,
1674                   void __user *buffer, size_t *lenp, loff_t *ppos)
1675 {
1676         return _proc_do_string(table->data, table->maxlen, write, filp,
1677                                buffer, lenp, ppos);
1678 }
1679
1680
1681 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1682                                  int *valp,
1683                                  int write, void *data)
1684 {
1685         if (write) {
1686                 *valp = *negp ? -*lvalp : *lvalp;
1687         } else {
1688                 int val = *valp;
1689                 if (val < 0) {
1690                         *negp = -1;
1691                         *lvalp = (unsigned long)-val;
1692                 } else {
1693                         *negp = 0;
1694                         *lvalp = (unsigned long)val;
1695                 }
1696         }
1697         return 0;
1698 }
1699
1700 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1701                   int write, struct file *filp, void __user *buffer,
1702                   size_t *lenp, loff_t *ppos,
1703                   int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1704                               int write, void *data),
1705                   void *data)
1706 {
1707 #define TMPBUFLEN 21
1708         int *i, vleft, first=1, neg, val;
1709         unsigned long lval;
1710         size_t left, len;
1711         
1712         char buf[TMPBUFLEN], *p;
1713         char __user *s = buffer;
1714         
1715         if (!tbl_data || !table->maxlen || !*lenp ||
1716             (*ppos && !write)) {
1717                 *lenp = 0;
1718                 return 0;
1719         }
1720         
1721         i = (int *) tbl_data;
1722         vleft = table->maxlen / sizeof(*i);
1723         left = *lenp;
1724
1725         if (!conv)
1726                 conv = do_proc_dointvec_conv;
1727
1728         for (; left && vleft--; i++, first=0) {
1729                 if (write) {
1730                         while (left) {
1731                                 char c;
1732                                 if (get_user(c, s))
1733                                         return -EFAULT;
1734                                 if (!isspace(c))
1735                                         break;
1736                                 left--;
1737                                 s++;
1738                         }
1739                         if (!left)
1740                                 break;
1741                         neg = 0;
1742                         len = left;
1743                         if (len > sizeof(buf) - 1)
1744                                 len = sizeof(buf) - 1;
1745                         if (copy_from_user(buf, s, len))
1746                                 return -EFAULT;
1747                         buf[len] = 0;
1748                         p = buf;
1749                         if (*p == '-' && left > 1) {
1750                                 neg = 1;
1751                                 p++;
1752                         }
1753                         if (*p < '0' || *p > '9')
1754                                 break;
1755
1756                         lval = simple_strtoul(p, &p, 0);
1757
1758                         len = p-buf;
1759                         if ((len < left) && *p && !isspace(*p))
1760                                 break;
1761                         if (neg)
1762                                 val = -val;
1763                         s += len;
1764                         left -= len;
1765
1766                         if (conv(&neg, &lval, i, 1, data))
1767                                 break;
1768                 } else {
1769                         p = buf;
1770                         if (!first)
1771                                 *p++ = '\t';
1772         
1773                         if (conv(&neg, &lval, i, 0, data))
1774                                 break;
1775
1776                         sprintf(p, "%s%lu", neg ? "-" : "", lval);
1777                         len = strlen(buf);
1778                         if (len > left)
1779                                 len = left;
1780                         if(copy_to_user(s, buf, len))
1781                                 return -EFAULT;
1782                         left -= len;
1783                         s += len;
1784                 }
1785         }
1786
1787         if (!write && !first && left) {
1788                 if(put_user('\n', s))
1789                         return -EFAULT;
1790                 left--, s++;
1791         }
1792         if (write) {
1793                 while (left) {
1794                         char c;
1795                         if (get_user(c, s++))
1796                                 return -EFAULT;
1797                         if (!isspace(c))
1798                                 break;
1799                         left--;
1800                 }
1801         }
1802         if (write && first)
1803                 return -EINVAL;
1804         *lenp -= left;
1805         *ppos += *lenp;
1806         return 0;
1807 #undef TMPBUFLEN
1808 }
1809
1810 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1811                   void __user *buffer, size_t *lenp, loff_t *ppos,
1812                   int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1813                               int write, void *data),
1814                   void *data)
1815 {
1816         return __do_proc_dointvec(table->data, table, write, filp,
1817                         buffer, lenp, ppos, conv, data);
1818 }
1819
1820 /**
1821  * proc_dointvec - read a vector of integers
1822  * @table: the sysctl table
1823  * @write: %TRUE if this is a write to the sysctl file
1824  * @filp: the file structure
1825  * @buffer: the user buffer
1826  * @lenp: the size of the user buffer
1827  * @ppos: file position
1828  *
1829  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1830  * values from/to the user buffer, treated as an ASCII string. 
1831  *
1832  * Returns 0 on success.
1833  */
1834 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1835                      void __user *buffer, size_t *lenp, loff_t *ppos)
1836 {
1837     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1838                             NULL,NULL);
1839 }
1840
1841 #define OP_SET  0
1842 #define OP_AND  1
1843 #define OP_OR   2
1844
1845 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1846                                       int *valp,
1847                                       int write, void *data)
1848 {
1849         int op = *(int *)data;
1850         if (write) {
1851                 int val = *negp ? -*lvalp : *lvalp;
1852                 switch(op) {
1853                 case OP_SET:    *valp = val; break;
1854                 case OP_AND:    *valp &= val; break;
1855                 case OP_OR:     *valp |= val; break;
1856                 }
1857         } else {
1858                 int val = *valp;
1859                 if (val < 0) {
1860                         *negp = -1;
1861                         *lvalp = (unsigned long)-val;
1862                 } else {
1863                         *negp = 0;
1864                         *lvalp = (unsigned long)val;
1865                 }
1866         }
1867         return 0;
1868 }
1869
1870 /*
1871  *      init may raise the set.
1872  */
1873  
1874 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1875                         void __user *buffer, size_t *lenp, loff_t *ppos)
1876 {
1877         int op;
1878
1879         if (write && !capable(CAP_SYS_MODULE)) {
1880                 return -EPERM;
1881         }
1882
1883         op = is_init(current) ? OP_SET : OP_AND;
1884         return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1885                                 do_proc_dointvec_bset_conv,&op);
1886 }
1887
1888 /*
1889  *      Taint values can only be increased
1890  */
1891 static int proc_dointvec_taint(ctl_table *table, int write, struct file *filp,
1892                                void __user *buffer, size_t *lenp, loff_t *ppos)
1893 {
1894         int op;
1895
1896         if (write && !capable(CAP_SYS_ADMIN))
1897                 return -EPERM;
1898
1899         op = OP_OR;
1900         return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1901                                 do_proc_dointvec_bset_conv,&op);
1902 }
1903
1904 struct do_proc_dointvec_minmax_conv_param {
1905         int *min;
1906         int *max;
1907 };
1908
1909 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 
1910                                         int *valp, 
1911                                         int write, void *data)
1912 {
1913         struct do_proc_dointvec_minmax_conv_param *param = data;
1914         if (write) {
1915                 int val = *negp ? -*lvalp : *lvalp;
1916                 if ((param->min && *param->min > val) ||
1917                     (param->max && *param->max < val))
1918                         return -EINVAL;
1919                 *valp = val;
1920         } else {
1921                 int val = *valp;
1922                 if (val < 0) {
1923                         *negp = -1;
1924                         *lvalp = (unsigned long)-val;
1925                 } else {
1926                         *negp = 0;
1927                         *lvalp = (unsigned long)val;
1928                 }
1929         }
1930         return 0;
1931 }
1932
1933 /**
1934  * proc_dointvec_minmax - read a vector of integers with min/max values
1935  * @table: the sysctl table
1936  * @write: %TRUE if this is a write to the sysctl file
1937  * @filp: the file structure
1938  * @buffer: the user buffer
1939  * @lenp: the size of the user buffer
1940  * @ppos: file position
1941  *
1942  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1943  * values from/to the user buffer, treated as an ASCII string.
1944  *
1945  * This routine will ensure the values are within the range specified by
1946  * table->extra1 (min) and table->extra2 (max).
1947  *
1948  * Returns 0 on success.
1949  */
1950 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1951                   void __user *buffer, size_t *lenp, loff_t *ppos)
1952 {
1953         struct do_proc_dointvec_minmax_conv_param param = {
1954                 .min = (int *) table->extra1,
1955                 .max = (int *) table->extra2,
1956         };
1957         return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1958                                 do_proc_dointvec_minmax_conv, &param);
1959 }
1960
1961 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
1962                                      struct file *filp,
1963                                      void __user *buffer,
1964                                      size_t *lenp, loff_t *ppos,
1965                                      unsigned long convmul,
1966                                      unsigned long convdiv)
1967 {
1968 #define TMPBUFLEN 21
1969         unsigned long *i, *min, *max, val;
1970         int vleft, first=1, neg;
1971         size_t len, left;
1972         char buf[TMPBUFLEN], *p;
1973         char __user *s = buffer;
1974         
1975         if (!data || !table->maxlen || !*lenp ||
1976             (*ppos && !write)) {
1977                 *lenp = 0;
1978                 return 0;
1979         }
1980         
1981         i = (unsigned long *) data;
1982         min = (unsigned long *) table->extra1;
1983         max = (unsigned long *) table->extra2;
1984         vleft = table->maxlen / sizeof(unsigned long);
1985         left = *lenp;
1986         
1987         for (; left && vleft--; i++, min++, max++, first=0) {
1988                 if (write) {
1989                         while (left) {
1990                                 char c;
1991                                 if (get_user(c, s))
1992                                         return -EFAULT;
1993                                 if (!isspace(c))
1994                                         break;
1995                                 left--;
1996                                 s++;
1997                         }
1998                         if (!left)
1999                                 break;
2000                         neg = 0;
2001                         len = left;
2002                         if (len > TMPBUFLEN-1)
2003                                 len = TMPBUFLEN-1;
2004                         if (copy_from_user(buf, s, len))
2005                                 return -EFAULT;
2006                         buf[len] = 0;
2007                         p = buf;
2008                         if (*p == '-' && left > 1) {
2009                                 neg = 1;
2010                                 p++;
2011                         }
2012                         if (*p < '0' || *p > '9')
2013                                 break;
2014                         val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2015                         len = p-buf;
2016                         if ((len < left) && *p && !isspace(*p))
2017                                 break;
2018                         if (neg)
2019                                 val = -val;
2020                         s += len;
2021                         left -= len;
2022
2023                         if(neg)
2024                                 continue;
2025                         if ((min && val < *min) || (max && val > *max))
2026                                 continue;
2027                         *i = val;
2028                 } else {
2029                         p = buf;
2030                         if (!first)
2031                                 *p++ = '\t';
2032                         sprintf(p, "%lu", convdiv * (*i) / convmul);
2033                         len = strlen(buf);
2034                         if (len > left)
2035                                 len = left;
2036                         if(copy_to_user(s, buf, len))
2037                                 return -EFAULT;
2038                         left -= len;
2039                         s += len;
2040                 }
2041         }
2042
2043         if (!write && !first && left) {
2044                 if(put_user('\n', s))
2045                         return -EFAULT;
2046                 left--, s++;
2047         }
2048         if (write) {
2049                 while (left) {
2050                         char c;
2051                         if (get_user(c, s++))
2052                                 return -EFAULT;
2053                         if (!isspace(c))
2054                                 break;
2055                         left--;
2056                 }
2057         }
2058         if (write && first)
2059                 return -EINVAL;
2060         *lenp -= left;
2061         *ppos += *lenp;
2062         return 0;
2063 #undef TMPBUFLEN
2064 }
2065
2066 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2067                                      struct file *filp,
2068                                      void __user *buffer,
2069                                      size_t *lenp, loff_t *ppos,
2070                                      unsigned long convmul,
2071                                      unsigned long convdiv)
2072 {
2073         return __do_proc_doulongvec_minmax(table->data, table, write,
2074                         filp, buffer, lenp, ppos, convmul, convdiv);
2075 }
2076
2077 /**
2078  * proc_doulongvec_minmax - read a vector of long integers with min/max values
2079  * @table: the sysctl table
2080  * @write: %TRUE if this is a write to the sysctl file
2081  * @filp: the file structure
2082  * @buffer: the user buffer
2083  * @lenp: the size of the user buffer
2084  * @ppos: file position
2085  *
2086  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2087  * values from/to the user buffer, treated as an ASCII string.
2088  *
2089  * This routine will ensure the values are within the range specified by
2090  * table->extra1 (min) and table->extra2 (max).
2091  *
2092  * Returns 0 on success.
2093  */
2094 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2095                            void __user *buffer, size_t *lenp, loff_t *ppos)
2096 {
2097     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2098 }
2099
2100 /**
2101  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2102  * @table: the sysctl table
2103  * @write: %TRUE if this is a write to the sysctl file
2104  * @filp: the file structure
2105  * @buffer: the user buffer
2106  * @lenp: the size of the user buffer
2107  * @ppos: file position
2108  *
2109  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2110  * values from/to the user buffer, treated as an ASCII string. The values
2111  * are treated as milliseconds, and converted to jiffies when they are stored.
2112  *
2113  * This routine will ensure the values are within the range specified by
2114  * table->extra1 (min) and table->extra2 (max).
2115  *
2116  * Returns 0 on success.
2117  */
2118 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2119                                       struct file *filp,
2120                                       void __user *buffer,
2121                                       size_t *lenp, loff_t *ppos)
2122 {
2123     return do_proc_doulongvec_minmax(table, write, filp, buffer,
2124                                      lenp, ppos, HZ, 1000l);
2125 }
2126
2127
2128 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2129                                          int *valp,
2130                                          int write, void *data)
2131 {
2132         if (write) {
2133                 if (*lvalp > LONG_MAX / HZ)
2134                         return 1;
2135                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2136         } else {
2137                 int val = *valp;
2138                 unsigned long lval;
2139                 if (val < 0) {
2140                         *negp = -1;
2141                         lval = (unsigned long)-val;
2142                 } else {
2143                         *negp = 0;
2144                         lval = (unsigned long)val;
2145                 }
2146                 *lvalp = lval / HZ;
2147         }
2148         return 0;
2149 }
2150
2151 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2152                                                 int *valp,
2153                                                 int write, void *data)
2154 {
2155         if (write) {
2156                 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2157                         return 1;
2158                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2159         } else {
2160                 int val = *valp;
2161                 unsigned long lval;
2162                 if (val < 0) {
2163                         *negp = -1;
2164                         lval = (unsigned long)-val;
2165                 } else {
2166                         *negp = 0;
2167                         lval = (unsigned long)val;
2168                 }
2169                 *lvalp = jiffies_to_clock_t(lval);
2170         }
2171         return 0;
2172 }
2173
2174 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2175                                             int *valp,
2176                                             int write, void *data)
2177 {
2178         if (write) {
2179                 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2180         } else {
2181                 int val = *valp;
2182                 unsigned long lval;
2183                 if (val < 0) {
2184                         *negp = -1;
2185                         lval = (unsigned long)-val;
2186                 } else {
2187                         *negp = 0;
2188                         lval = (unsigned long)val;
2189                 }
2190                 *lvalp = jiffies_to_msecs(lval);
2191         }
2192         return 0;
2193 }
2194
2195 /**
2196  * proc_dointvec_jiffies - read a vector of integers as seconds
2197  * @table: the sysctl table
2198  * @write: %TRUE if this is a write to the sysctl file
2199  * @filp: the file structure
2200  * @buffer: the user buffer
2201  * @lenp: the size of the user buffer
2202  * @ppos: file position
2203  *
2204  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2205  * values from/to the user buffer, treated as an ASCII string. 
2206  * The values read are assumed to be in seconds, and are converted into
2207  * jiffies.
2208  *
2209  * Returns 0 on success.
2210  */
2211 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2212                           void __user *buffer, size_t *lenp, loff_t *ppos)
2213 {
2214     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2215                             do_proc_dointvec_jiffies_conv,NULL);
2216 }
2217
2218 /**
2219  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2220  * @table: the sysctl table
2221  * @write: %TRUE if this is a write to the sysctl file
2222  * @filp: the file structure
2223  * @buffer: the user buffer
2224  * @lenp: the size of the user buffer
2225  * @ppos: pointer to the file position
2226  *
2227  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2228  * values from/to the user buffer, treated as an ASCII string. 
2229  * The values read are assumed to be in 1/USER_HZ seconds, and 
2230  * are converted into jiffies.
2231  *
2232  * Returns 0 on success.
2233  */
2234 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2235                                  void __user *buffer, size_t *lenp, loff_t *ppos)
2236 {
2237     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2238                             do_proc_dointvec_userhz_jiffies_conv,NULL);
2239 }
2240
2241 /**
2242  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2243  * @table: the sysctl table
2244  * @write: %TRUE if this is a write to the sysctl file
2245  * @filp: the file structure
2246  * @buffer: the user buffer
2247  * @lenp: the size of the user buffer
2248  * @ppos: file position
2249  * @ppos: the current position in the file
2250  *
2251  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2252  * values from/to the user buffer, treated as an ASCII string. 
2253  * The values read are assumed to be in 1/1000 seconds, and 
2254  * are converted into jiffies.
2255  *
2256  * Returns 0 on success.
2257  */
2258 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2259                              void __user *buffer, size_t *lenp, loff_t *ppos)
2260 {
2261         return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2262                                 do_proc_dointvec_ms_jiffies_conv, NULL);
2263 }
2264
2265 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2266                            void __user *buffer, size_t *lenp, loff_t *ppos)
2267 {
2268         struct pid *new_pid;
2269         pid_t tmp;
2270         int r;
2271
2272         tmp = pid_nr(cad_pid);
2273
2274         r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2275                                lenp, ppos, NULL, NULL);
2276         if (r || !write)
2277                 return r;
2278
2279         new_pid = find_get_pid(tmp);
2280         if (!new_pid)
2281                 return -ESRCH;
2282
2283         put_pid(xchg(&cad_pid, new_pid));
2284         return 0;
2285 }
2286
2287 #else /* CONFIG_PROC_FS */
2288
2289 int proc_dostring(ctl_table *table, int write, struct file *filp,
2290                   void __user *buffer, size_t *lenp, loff_t *ppos)
2291 {
2292         return -ENOSYS;
2293 }
2294
2295 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2296                   void __user *buffer, size_t *lenp, loff_t *ppos)
2297 {
2298         return -ENOSYS;
2299 }
2300
2301 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2302                         void __user *buffer, size_t *lenp, loff_t *ppos)
2303 {
2304         return -ENOSYS;
2305 }
2306
2307 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2308                     void __user *buffer, size_t *lenp, loff_t *ppos)
2309 {
2310         return -ENOSYS;
2311 }
2312
2313 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2314                     void __user *buffer, size_t *lenp, loff_t *ppos)
2315 {
2316         return -ENOSYS;
2317 }
2318
2319 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2320                     void __user *buffer, size_t *lenp, loff_t *ppos)
2321 {
2322         return -ENOSYS;
2323 }
2324
2325 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2326                              void __user *buffer, size_t *lenp, loff_t *ppos)
2327 {
2328         return -ENOSYS;
2329 }
2330
2331 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2332                     void __user *buffer, size_t *lenp, loff_t *ppos)
2333 {
2334         return -ENOSYS;
2335 }
2336
2337 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2338                                       struct file *filp,
2339                                       void __user *buffer,
2340                                       size_t *lenp, loff_t *ppos)
2341 {
2342     return -ENOSYS;
2343 }
2344
2345
2346 #endif /* CONFIG_PROC_FS */
2347
2348
2349 #ifdef CONFIG_SYSCTL_SYSCALL
2350 /*
2351  * General sysctl support routines 
2352  */
2353
2354 /* The generic string strategy routine: */
2355 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2356                   void __user *oldval, size_t __user *oldlenp,
2357                   void __user *newval, size_t newlen)
2358 {
2359         if (!table->data || !table->maxlen) 
2360                 return -ENOTDIR;
2361         
2362         if (oldval && oldlenp) {
2363                 size_t bufsize;
2364                 if (get_user(bufsize, oldlenp))
2365                         return -EFAULT;
2366                 if (bufsize) {
2367                         size_t len = strlen(table->data), copied;
2368
2369                         /* This shouldn't trigger for a well-formed sysctl */
2370                         if (len > table->maxlen)
2371                                 len = table->maxlen;
2372
2373                         /* Copy up to a max of bufsize-1 bytes of the string */
2374                         copied = (len >= bufsize) ? bufsize - 1 : len;
2375
2376                         if (copy_to_user(oldval, table->data, copied) ||
2377                             put_user(0, (char __user *)(oldval + copied)))
2378                                 return -EFAULT;
2379                         if (put_user(len, oldlenp))
2380                                 return -EFAULT;
2381                 }
2382         }
2383         if (newval && newlen) {
2384                 size_t len = newlen;
2385                 if (len > table->maxlen)
2386                         len = table->maxlen;
2387                 if(copy_from_user(table->data, newval, len))
2388                         return -EFAULT;
2389                 if (len == table->maxlen)
2390                         len--;
2391                 ((char *) table->data)[len] = 0;
2392         }
2393         return 1;
2394 }
2395
2396 /*
2397  * This function makes sure that all of the integers in the vector
2398  * are between the minimum and maximum values given in the arrays
2399  * table->extra1 and table->extra2, respectively.
2400  */
2401 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2402                 void __user *oldval, size_t __user *oldlenp,
2403                 void __user *newval, size_t newlen)
2404 {
2405
2406         if (newval && newlen) {
2407                 int __user *vec = (int __user *) newval;
2408                 int *min = (int *) table->extra1;
2409                 int *max = (int *) table->extra2;
2410                 size_t length;
2411                 int i;
2412
2413                 if (newlen % sizeof(int) != 0)
2414                         return -EINVAL;
2415
2416                 if (!table->extra1 && !table->extra2)
2417                         return 0;
2418
2419                 if (newlen > table->maxlen)
2420                         newlen = table->maxlen;
2421                 length = newlen / sizeof(int);
2422
2423                 for (i = 0; i < length; i++) {
2424                         int value;
2425                         if (get_user(value, vec + i))
2426                                 return -EFAULT;
2427                         if (min && value < min[i])
2428                                 return -EINVAL;
2429                         if (max && value > max[i])
2430                                 return -EINVAL;
2431                 }
2432         }
2433         return 0;
2434 }
2435
2436 /* Strategy function to convert jiffies to seconds */ 
2437 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2438                 void __user *oldval, size_t __user *oldlenp,
2439                 void __user *newval, size_t newlen)
2440 {
2441         if (oldval && oldlenp) {
2442                 size_t olen;
2443
2444                 if (get_user(olen, oldlenp))
2445                         return -EFAULT;
2446                 if (olen) {
2447                         int val;
2448
2449                         if (olen < sizeof(int))
2450                                 return -EINVAL;
2451
2452                         val = *(int *)(table->data) / HZ;
2453                         if (put_user(val, (int __user *)oldval))
2454                                 return -EFAULT;
2455                         if (put_user(sizeof(int), oldlenp))
2456                                 return -EFAULT;
2457                 }
2458         }
2459         if (newval && newlen) { 
2460                 int new;
2461                 if (newlen != sizeof(int))
2462                         return -EINVAL; 
2463                 if (get_user(new, (int __user *)newval))
2464                         return -EFAULT;
2465                 *(int *)(table->data) = new*HZ; 
2466         }
2467         return 1;
2468 }
2469
2470 /* Strategy function to convert jiffies to seconds */ 
2471 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2472                 void __user *oldval, size_t __user *oldlenp,
2473                 void __user *newval, size_t newlen)
2474 {
2475         if (oldval && oldlenp) {
2476                 size_t olen;
2477
2478                 if (get_user(olen, oldlenp))
2479                         return -EFAULT;
2480                 if (olen) {
2481                         int val;
2482
2483                         if (olen < sizeof(int))
2484                                 return -EINVAL;
2485
2486                         val = jiffies_to_msecs(*(int *)(table->data));
2487                         if (put_user(val, (int __user *)oldval))
2488                                 return -EFAULT;
2489                         if (put_user(sizeof(int), oldlenp))
2490                                 return -EFAULT;
2491                 }
2492         }
2493         if (newval && newlen) { 
2494                 int new;
2495                 if (newlen != sizeof(int))
2496                         return -EINVAL; 
2497                 if (get_user(new, (int __user *)newval))
2498                         return -EFAULT;
2499                 *(int *)(table->data) = msecs_to_jiffies(new);
2500         }
2501         return 1;
2502 }
2503
2504
2505
2506 #else /* CONFIG_SYSCTL_SYSCALL */
2507
2508
2509 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2510 {
2511         static int msg_count;
2512         struct __sysctl_args tmp;
2513         int name[CTL_MAXNAME];
2514         int i;
2515
2516         /* Read in the sysctl name for better debug message logging */
2517         if (copy_from_user(&tmp, args, sizeof(tmp)))
2518                 return -EFAULT;
2519         if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2520                 return -ENOTDIR;
2521         for (i = 0; i < tmp.nlen; i++)
2522                 if (get_user(name[i], tmp.name + i))
2523                         return -EFAULT;
2524
2525         /* Ignore accesses to kernel.version */
2526         if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2527                 goto out;
2528
2529         if (msg_count < 5) {
2530                 msg_count++;
2531                 printk(KERN_INFO
2532                         "warning: process `%s' used the removed sysctl "
2533                         "system call with ", current->comm);
2534                 for (i = 0; i < tmp.nlen; i++)
2535                         printk("%d.", name[i]);
2536                 printk("\n");
2537         }
2538 out:
2539         return -ENOSYS;
2540 }
2541
2542 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2543                   void __user *oldval, size_t __user *oldlenp,
2544                   void __user *newval, size_t newlen)
2545 {
2546         return -ENOSYS;
2547 }
2548
2549 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2550                 void __user *oldval, size_t __user *oldlenp,
2551                 void __user *newval, size_t newlen)
2552 {
2553         return -ENOSYS;
2554 }
2555
2556 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2557                 void __user *oldval, size_t __user *oldlenp,
2558                 void __user *newval, size_t newlen)
2559 {
2560         return -ENOSYS;
2561 }
2562
2563 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2564                 void __user *oldval, size_t __user *oldlenp,
2565                 void __user *newval, size_t newlen)
2566 {
2567         return -ENOSYS;
2568 }
2569
2570 #endif /* CONFIG_SYSCTL_SYSCALL */
2571
2572 /*
2573  * No sense putting this after each symbol definition, twice,
2574  * exception granted :-)
2575  */
2576 EXPORT_SYMBOL(proc_dointvec);
2577 EXPORT_SYMBOL(proc_dointvec_jiffies);
2578 EXPORT_SYMBOL(proc_dointvec_minmax);
2579 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2580 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2581 EXPORT_SYMBOL(proc_dostring);
2582 EXPORT_SYMBOL(proc_doulongvec_minmax);
2583 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2584 EXPORT_SYMBOL(register_sysctl_table);
2585 EXPORT_SYMBOL(sysctl_intvec);
2586 EXPORT_SYMBOL(sysctl_jiffies);
2587 EXPORT_SYMBOL(sysctl_ms_jiffies);
2588 EXPORT_SYMBOL(sysctl_string);
2589 EXPORT_SYMBOL(unregister_sysctl_table);