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