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