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