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