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