]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - kernel/sysctl.c
8e56e2495542be41fa688aa7a15604cb2e3e6897
[karo-tx-linux.git] / kernel / sysctl.c
1 /*
2  * sysctl.c: General linux system control interface
3  *
4  * Begun 24 March 1995, Stephen Tweedie
5  * Added /proc support, Dec 1995
6  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9  * Dynamic registration fixes, Stephen Tweedie.
10  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
12  *  Horn.
13  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
16  *  Wendling.
17  * The list_for_each() macro wasn't appropriate for the sysctl loop.
18  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
19  */
20
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/mm.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/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 *);
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_dointvec,
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_dointvec,
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 void __init sysctl_init(void)
996 {
997 #ifdef CONFIG_PROC_FS
998         register_proc_table(root_table, proc_sys_root);
999         init_irq_proc();
1000 #endif
1001 }
1002
1003 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1004                void __user *newval, size_t newlen)
1005 {
1006         struct list_head *tmp;
1007
1008         if (nlen <= 0 || nlen >= CTL_MAXNAME)
1009                 return -ENOTDIR;
1010         if (oldval) {
1011                 int old_len;
1012                 if (!oldlenp || get_user(old_len, oldlenp))
1013                         return -EFAULT;
1014         }
1015         tmp = &root_table_header.ctl_entry;
1016         do {
1017                 struct ctl_table_header *head =
1018                         list_entry(tmp, struct ctl_table_header, ctl_entry);
1019                 void *context = NULL;
1020                 int error = parse_table(name, nlen, oldval, oldlenp, 
1021                                         newval, newlen, head->ctl_table,
1022                                         &context);
1023                 kfree(context);
1024                 if (error != -ENOTDIR)
1025                         return error;
1026                 tmp = tmp->next;
1027         } while (tmp != &root_table_header.ctl_entry);
1028         return -ENOTDIR;
1029 }
1030
1031 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1032 {
1033         struct __sysctl_args tmp;
1034         int error;
1035
1036         if (copy_from_user(&tmp, args, sizeof(tmp)))
1037                 return -EFAULT;
1038
1039         lock_kernel();
1040         error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1041                           tmp.newval, tmp.newlen);
1042         unlock_kernel();
1043         return error;
1044 }
1045
1046 /*
1047  * ctl_perm does NOT grant the superuser all rights automatically, because
1048  * some sysctl variables are readonly even to root.
1049  */
1050
1051 static int test_perm(int mode, int op)
1052 {
1053         if (!current->euid)
1054                 mode >>= 6;
1055         else if (in_egroup_p(0))
1056                 mode >>= 3;
1057         if ((mode & op & 0007) == op)
1058                 return 0;
1059         return -EACCES;
1060 }
1061
1062 static inline int ctl_perm(ctl_table *table, int op)
1063 {
1064         int error;
1065         error = security_sysctl(table, op);
1066         if (error)
1067                 return error;
1068         return test_perm(table->mode, op);
1069 }
1070
1071 static int parse_table(int __user *name, int nlen,
1072                        void __user *oldval, size_t __user *oldlenp,
1073                        void __user *newval, size_t newlen,
1074                        ctl_table *table, void **context)
1075 {
1076         int n;
1077 repeat:
1078         if (!nlen)
1079                 return -ENOTDIR;
1080         if (get_user(n, name))
1081                 return -EFAULT;
1082         for ( ; table->ctl_name; table++) {
1083                 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1084                         int error;
1085                         if (table->child) {
1086                                 if (ctl_perm(table, 001))
1087                                         return -EPERM;
1088                                 if (table->strategy) {
1089                                         error = table->strategy(
1090                                                 table, name, nlen,
1091                                                 oldval, oldlenp,
1092                                                 newval, newlen, context);
1093                                         if (error)
1094                                                 return error;
1095                                 }
1096                                 name++;
1097                                 nlen--;
1098                                 table = table->child;
1099                                 goto repeat;
1100                         }
1101                         error = do_sysctl_strategy(table, name, nlen,
1102                                                    oldval, oldlenp,
1103                                                    newval, newlen, context);
1104                         return error;
1105                 }
1106         }
1107         return -ENOTDIR;
1108 }
1109
1110 /* Perform the actual read/write of a sysctl table entry. */
1111 int do_sysctl_strategy (ctl_table *table, 
1112                         int __user *name, int nlen,
1113                         void __user *oldval, size_t __user *oldlenp,
1114                         void __user *newval, size_t newlen, void **context)
1115 {
1116         int op = 0, rc;
1117         size_t len;
1118
1119         if (oldval)
1120                 op |= 004;
1121         if (newval) 
1122                 op |= 002;
1123         if (ctl_perm(table, op))
1124                 return -EPERM;
1125
1126         if (table->strategy) {
1127                 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1128                                      newval, newlen, context);
1129                 if (rc < 0)
1130                         return rc;
1131                 if (rc > 0)
1132                         return 0;
1133         }
1134
1135         /* If there is no strategy routine, or if the strategy returns
1136          * zero, proceed with automatic r/w */
1137         if (table->data && table->maxlen) {
1138                 if (oldval && oldlenp) {
1139                         if (get_user(len, oldlenp))
1140                                 return -EFAULT;
1141                         if (len) {
1142                                 if (len > table->maxlen)
1143                                         len = table->maxlen;
1144                                 if(copy_to_user(oldval, table->data, len))
1145                                         return -EFAULT;
1146                                 if(put_user(len, oldlenp))
1147                                         return -EFAULT;
1148                         }
1149                 }
1150                 if (newval && newlen) {
1151                         len = newlen;
1152                         if (len > table->maxlen)
1153                                 len = table->maxlen;
1154                         if(copy_from_user(table->data, newval, len))
1155                                 return -EFAULT;
1156                 }
1157         }
1158         return 0;
1159 }
1160
1161 /**
1162  * register_sysctl_table - register a sysctl hierarchy
1163  * @table: the top-level table structure
1164  * @insert_at_head: whether the entry should be inserted in front or at the end
1165  *
1166  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1167  * array. An entry with a ctl_name of 0 terminates the table. 
1168  *
1169  * The members of the &ctl_table structure are used as follows:
1170  *
1171  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1172  *            must be unique within that level of sysctl
1173  *
1174  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1175  *            enter a sysctl file
1176  *
1177  * data - a pointer to data for use by proc_handler
1178  *
1179  * maxlen - the maximum size in bytes of the data
1180  *
1181  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1182  *
1183  * child - a pointer to the child sysctl table if this entry is a directory, or
1184  *         %NULL.
1185  *
1186  * proc_handler - the text handler routine (described below)
1187  *
1188  * strategy - the strategy routine (described below)
1189  *
1190  * de - for internal use by the sysctl routines
1191  *
1192  * extra1, extra2 - extra pointers usable by the proc handler routines
1193  *
1194  * Leaf nodes in the sysctl tree will be represented by a single file
1195  * under /proc; non-leaf nodes will be represented by directories.
1196  *
1197  * sysctl(2) can automatically manage read and write requests through
1198  * the sysctl table.  The data and maxlen fields of the ctl_table
1199  * struct enable minimal validation of the values being written to be
1200  * performed, and the mode field allows minimal authentication.
1201  *
1202  * More sophisticated management can be enabled by the provision of a
1203  * strategy routine with the table entry.  This will be called before
1204  * any automatic read or write of the data is performed.
1205  *
1206  * The strategy routine may return
1207  *
1208  * < 0 - Error occurred (error is passed to user process)
1209  *
1210  * 0   - OK - proceed with automatic read or write.
1211  *
1212  * > 0 - OK - read or write has been done by the strategy routine, so
1213  *       return immediately.
1214  *
1215  * There must be a proc_handler routine for any terminal nodes
1216  * mirrored under /proc/sys (non-terminals are handled by a built-in
1217  * directory handler).  Several default handlers are available to
1218  * cover common cases -
1219  *
1220  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1221  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 
1222  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1223  *
1224  * It is the handler's job to read the input buffer from user memory
1225  * and process it. The handler should return 0 on success.
1226  *
1227  * This routine returns %NULL on a failure to register, and a pointer
1228  * to the table header on success.
1229  */
1230 struct ctl_table_header *register_sysctl_table(ctl_table * table, 
1231                                                int insert_at_head)
1232 {
1233         struct ctl_table_header *tmp;
1234         tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1235         if (!tmp)
1236                 return NULL;
1237         tmp->ctl_table = table;
1238         INIT_LIST_HEAD(&tmp->ctl_entry);
1239         if (insert_at_head)
1240                 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1241         else
1242                 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1243 #ifdef CONFIG_PROC_FS
1244         register_proc_table(table, proc_sys_root);
1245 #endif
1246         return tmp;
1247 }
1248
1249 /**
1250  * unregister_sysctl_table - unregister a sysctl table hierarchy
1251  * @header: the header returned from register_sysctl_table
1252  *
1253  * Unregisters the sysctl table and all children. proc entries may not
1254  * actually be removed until they are no longer used by anyone.
1255  */
1256 void unregister_sysctl_table(struct ctl_table_header * header)
1257 {
1258         list_del(&header->ctl_entry);
1259 #ifdef CONFIG_PROC_FS
1260         unregister_proc_table(header->ctl_table, proc_sys_root);
1261 #endif
1262         kfree(header);
1263 }
1264
1265 /*
1266  * /proc/sys support
1267  */
1268
1269 #ifdef CONFIG_PROC_FS
1270
1271 /* Scan the sysctl entries in table and add them all into /proc */
1272 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1273 {
1274         struct proc_dir_entry *de;
1275         int len;
1276         mode_t mode;
1277         
1278         for (; table->ctl_name; table++) {
1279                 /* Can't do anything without a proc name. */
1280                 if (!table->procname)
1281                         continue;
1282                 /* Maybe we can't do anything with it... */
1283                 if (!table->proc_handler && !table->child) {
1284                         printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1285                                 table->procname);
1286                         continue;
1287                 }
1288
1289                 len = strlen(table->procname);
1290                 mode = table->mode;
1291
1292                 de = NULL;
1293                 if (table->proc_handler)
1294                         mode |= S_IFREG;
1295                 else {
1296                         mode |= S_IFDIR;
1297                         for (de = root->subdir; de; de = de->next) {
1298                                 if (proc_match(len, table->procname, de))
1299                                         break;
1300                         }
1301                         /* If the subdir exists already, de is non-NULL */
1302                 }
1303
1304                 if (!de) {
1305                         de = create_proc_entry(table->procname, mode, root);
1306                         if (!de)
1307                                 continue;
1308                         de->data = (void *) table;
1309                         if (table->proc_handler)
1310                                 de->proc_fops = &proc_sys_file_operations;
1311                 }
1312                 table->de = de;
1313                 if (de->mode & S_IFDIR)
1314                         register_proc_table(table->child, de);
1315         }
1316 }
1317
1318 /*
1319  * Unregister a /proc sysctl table and any subdirectories.
1320  */
1321 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1322 {
1323         struct proc_dir_entry *de;
1324         for (; table->ctl_name; table++) {
1325                 if (!(de = table->de))
1326                         continue;
1327                 if (de->mode & S_IFDIR) {
1328                         if (!table->child) {
1329                                 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1330                                 continue;
1331                         }
1332                         unregister_proc_table(table->child, de);
1333
1334                         /* Don't unregister directories which still have entries.. */
1335                         if (de->subdir)
1336                                 continue;
1337                 }
1338
1339                 /* Don't unregister proc entries that are still being used.. */
1340                 if (atomic_read(&de->count))
1341                         continue;
1342
1343                 table->de = NULL;
1344                 remove_proc_entry(table->procname, root);
1345         }
1346 }
1347
1348 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1349                           size_t count, loff_t *ppos)
1350 {
1351         int op;
1352         struct proc_dir_entry *de;
1353         struct ctl_table *table;
1354         size_t res;
1355         ssize_t error;
1356         
1357         de = PDE(file->f_dentry->d_inode);
1358         if (!de || !de->data)
1359                 return -ENOTDIR;
1360         table = (struct ctl_table *) de->data;
1361         if (!table || !table->proc_handler)
1362                 return -ENOTDIR;
1363         op = (write ? 002 : 004);
1364         if (ctl_perm(table, op))
1365                 return -EPERM;
1366         
1367         res = count;
1368
1369         error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1370         if (error)
1371                 return error;
1372         return res;
1373 }
1374
1375 static int proc_opensys(struct inode *inode, struct file *file)
1376 {
1377         if (file->f_mode & FMODE_WRITE) {
1378                 /*
1379                  * sysctl entries that are not writable,
1380                  * are _NOT_ writable, capabilities or not.
1381                  */
1382                 if (!(inode->i_mode & S_IWUSR))
1383                         return -EPERM;
1384         }
1385
1386         return 0;
1387 }
1388
1389 static ssize_t proc_readsys(struct file * file, char __user * buf,
1390                             size_t count, loff_t *ppos)
1391 {
1392         return do_rw_proc(0, file, buf, count, ppos);
1393 }
1394
1395 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1396                              size_t count, loff_t *ppos)
1397 {
1398         return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1399 }
1400
1401 /**
1402  * proc_dostring - read a string sysctl
1403  * @table: the sysctl table
1404  * @write: %TRUE if this is a write to the sysctl file
1405  * @filp: the file structure
1406  * @buffer: the user buffer
1407  * @lenp: the size of the user buffer
1408  * @ppos: file position
1409  *
1410  * Reads/writes a string from/to the user buffer. If the kernel
1411  * buffer provided is not large enough to hold the string, the
1412  * string is truncated. The copied string is %NULL-terminated.
1413  * If the string is being read by the user process, it is copied
1414  * and a newline '\n' is added. It is truncated if the buffer is
1415  * not large enough.
1416  *
1417  * Returns 0 on success.
1418  */
1419 int proc_dostring(ctl_table *table, int write, struct file *filp,
1420                   void __user *buffer, size_t *lenp, loff_t *ppos)
1421 {
1422         size_t len;
1423         char __user *p;
1424         char c;
1425         
1426         if (!table->data || !table->maxlen || !*lenp ||
1427             (*ppos && !write)) {
1428                 *lenp = 0;
1429                 return 0;
1430         }
1431         
1432         if (write) {
1433                 len = 0;
1434                 p = buffer;
1435                 while (len < *lenp) {
1436                         if (get_user(c, p++))
1437                                 return -EFAULT;
1438                         if (c == 0 || c == '\n')
1439                                 break;
1440                         len++;
1441                 }
1442                 if (len >= table->maxlen)
1443                         len = table->maxlen-1;
1444                 if(copy_from_user(table->data, buffer, len))
1445                         return -EFAULT;
1446                 ((char *) table->data)[len] = 0;
1447                 *ppos += *lenp;
1448         } else {
1449                 len = strlen(table->data);
1450                 if (len > table->maxlen)
1451                         len = table->maxlen;
1452                 if (len > *lenp)
1453                         len = *lenp;
1454                 if (len)
1455                         if(copy_to_user(buffer, table->data, len))
1456                                 return -EFAULT;
1457                 if (len < *lenp) {
1458                         if(put_user('\n', ((char __user *) buffer) + len))
1459                                 return -EFAULT;
1460                         len++;
1461                 }
1462                 *lenp = len;
1463                 *ppos += len;
1464         }
1465         return 0;
1466 }
1467
1468 /*
1469  *      Special case of dostring for the UTS structure. This has locks
1470  *      to observe. Should this be in kernel/sys.c ????
1471  */
1472  
1473 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1474                   void __user *buffer, size_t *lenp, loff_t *ppos)
1475 {
1476         int r;
1477
1478         if (!write) {
1479                 down_read(&uts_sem);
1480                 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1481                 up_read(&uts_sem);
1482         } else {
1483                 down_write(&uts_sem);
1484                 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1485                 up_write(&uts_sem);
1486         }
1487         return r;
1488 }
1489
1490 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1491                                  int *valp,
1492                                  int write, void *data)
1493 {
1494         if (write) {
1495                 *valp = *negp ? -*lvalp : *lvalp;
1496         } else {
1497                 int val = *valp;
1498                 if (val < 0) {
1499                         *negp = -1;
1500                         *lvalp = (unsigned long)-val;
1501                 } else {
1502                         *negp = 0;
1503                         *lvalp = (unsigned long)val;
1504                 }
1505         }
1506         return 0;
1507 }
1508
1509 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1510                   void __user *buffer, size_t *lenp, loff_t *ppos,
1511                   int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1512                               int write, void *data),
1513                   void *data)
1514 {
1515 #define TMPBUFLEN 21
1516         int *i, vleft, first=1, neg, val;
1517         unsigned long lval;
1518         size_t left, len;
1519         
1520         char buf[TMPBUFLEN], *p;
1521         char __user *s = buffer;
1522         
1523         if (!table->data || !table->maxlen || !*lenp ||
1524             (*ppos && !write)) {
1525                 *lenp = 0;
1526                 return 0;
1527         }
1528         
1529         i = (int *) table->data;
1530         vleft = table->maxlen / sizeof(*i);
1531         left = *lenp;
1532
1533         if (!conv)
1534                 conv = do_proc_dointvec_conv;
1535
1536         for (; left && vleft--; i++, first=0) {
1537                 if (write) {
1538                         while (left) {
1539                                 char c;
1540                                 if (get_user(c, s))
1541                                         return -EFAULT;
1542                                 if (!isspace(c))
1543                                         break;
1544                                 left--;
1545                                 s++;
1546                         }
1547                         if (!left)
1548                                 break;
1549                         neg = 0;
1550                         len = left;
1551                         if (len > sizeof(buf) - 1)
1552                                 len = sizeof(buf) - 1;
1553                         if (copy_from_user(buf, s, len))
1554                                 return -EFAULT;
1555                         buf[len] = 0;
1556                         p = buf;
1557                         if (*p == '-' && left > 1) {
1558                                 neg = 1;
1559                                 left--, p++;
1560                         }
1561                         if (*p < '0' || *p > '9')
1562                                 break;
1563
1564                         lval = simple_strtoul(p, &p, 0);
1565
1566                         len = p-buf;
1567                         if ((len < left) && *p && !isspace(*p))
1568                                 break;
1569                         if (neg)
1570                                 val = -val;
1571                         s += len;
1572                         left -= len;
1573
1574                         if (conv(&neg, &lval, i, 1, data))
1575                                 break;
1576                 } else {
1577                         p = buf;
1578                         if (!first)
1579                                 *p++ = '\t';
1580         
1581                         if (conv(&neg, &lval, i, 0, data))
1582                                 break;
1583
1584                         sprintf(p, "%s%lu", neg ? "-" : "", lval);
1585                         len = strlen(buf);
1586                         if (len > left)
1587                                 len = left;
1588                         if(copy_to_user(s, buf, len))
1589                                 return -EFAULT;
1590                         left -= len;
1591                         s += len;
1592                 }
1593         }
1594
1595         if (!write && !first && left) {
1596                 if(put_user('\n', s))
1597                         return -EFAULT;
1598                 left--, s++;
1599         }
1600         if (write) {
1601                 while (left) {
1602                         char c;
1603                         if (get_user(c, s++))
1604                                 return -EFAULT;
1605                         if (!isspace(c))
1606                                 break;
1607                         left--;
1608                 }
1609         }
1610         if (write && first)
1611                 return -EINVAL;
1612         *lenp -= left;
1613         *ppos += *lenp;
1614         return 0;
1615 #undef TMPBUFLEN
1616 }
1617
1618 /**
1619  * proc_dointvec - read a vector of integers
1620  * @table: the sysctl table
1621  * @write: %TRUE if this is a write to the sysctl file
1622  * @filp: the file structure
1623  * @buffer: the user buffer
1624  * @lenp: the size of the user buffer
1625  * @ppos: file position
1626  *
1627  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1628  * values from/to the user buffer, treated as an ASCII string. 
1629  *
1630  * Returns 0 on success.
1631  */
1632 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1633                      void __user *buffer, size_t *lenp, loff_t *ppos)
1634 {
1635     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1636                             NULL,NULL);
1637 }
1638
1639 #define OP_SET  0
1640 #define OP_AND  1
1641 #define OP_OR   2
1642 #define OP_MAX  3
1643 #define OP_MIN  4
1644
1645 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1646                                       int *valp,
1647                                       int write, void *data)
1648 {
1649         int op = *(int *)data;
1650         if (write) {
1651                 int val = *negp ? -*lvalp : *lvalp;
1652                 switch(op) {
1653                 case OP_SET:    *valp = val; break;
1654                 case OP_AND:    *valp &= val; break;
1655                 case OP_OR:     *valp |= val; break;
1656                 case OP_MAX:    if(*valp < val)
1657                                         *valp = val;
1658                                 break;
1659                 case OP_MIN:    if(*valp > val)
1660                                 *valp = val;
1661                                 break;
1662                 }
1663         } else {
1664                 int val = *valp;
1665                 if (val < 0) {
1666                         *negp = -1;
1667                         *lvalp = (unsigned long)-val;
1668                 } else {
1669                         *negp = 0;
1670                         *lvalp = (unsigned long)val;
1671                 }
1672         }
1673         return 0;
1674 }
1675
1676 /*
1677  *      init may raise the set.
1678  */
1679  
1680 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1681                         void __user *buffer, size_t *lenp, loff_t *ppos)
1682 {
1683         int op;
1684
1685         if (!capable(CAP_SYS_MODULE)) {
1686                 return -EPERM;
1687         }
1688
1689         op = (current->pid == 1) ? OP_SET : OP_AND;
1690         return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1691                                 do_proc_dointvec_bset_conv,&op);
1692 }
1693
1694 struct do_proc_dointvec_minmax_conv_param {
1695         int *min;
1696         int *max;
1697 };
1698
1699 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 
1700                                         int *valp, 
1701                                         int write, void *data)
1702 {
1703         struct do_proc_dointvec_minmax_conv_param *param = data;
1704         if (write) {
1705                 int val = *negp ? -*lvalp : *lvalp;
1706                 if ((param->min && *param->min > val) ||
1707                     (param->max && *param->max < val))
1708                         return -EINVAL;
1709                 *valp = val;
1710         } else {
1711                 int val = *valp;
1712                 if (val < 0) {
1713                         *negp = -1;
1714                         *lvalp = (unsigned long)-val;
1715                 } else {
1716                         *negp = 0;
1717                         *lvalp = (unsigned long)val;
1718                 }
1719         }
1720         return 0;
1721 }
1722
1723 /**
1724  * proc_dointvec_minmax - read a vector of integers with min/max values
1725  * @table: the sysctl table
1726  * @write: %TRUE if this is a write to the sysctl file
1727  * @filp: the file structure
1728  * @buffer: the user buffer
1729  * @lenp: the size of the user buffer
1730  * @ppos: file position
1731  *
1732  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1733  * values from/to the user buffer, treated as an ASCII string.
1734  *
1735  * This routine will ensure the values are within the range specified by
1736  * table->extra1 (min) and table->extra2 (max).
1737  *
1738  * Returns 0 on success.
1739  */
1740 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1741                   void __user *buffer, size_t *lenp, loff_t *ppos)
1742 {
1743         struct do_proc_dointvec_minmax_conv_param param = {
1744                 .min = (int *) table->extra1,
1745                 .max = (int *) table->extra2,
1746         };
1747         return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1748                                 do_proc_dointvec_minmax_conv, &param);
1749 }
1750
1751 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1752                                      struct file *filp,
1753                                      void __user *buffer,
1754                                      size_t *lenp, loff_t *ppos,
1755                                      unsigned long convmul,
1756                                      unsigned long convdiv)
1757 {
1758 #define TMPBUFLEN 21
1759         unsigned long *i, *min, *max, val;
1760         int vleft, first=1, neg;
1761         size_t len, left;
1762         char buf[TMPBUFLEN], *p;
1763         char __user *s = buffer;
1764         
1765         if (!table->data || !table->maxlen || !*lenp ||
1766             (*ppos && !write)) {
1767                 *lenp = 0;
1768                 return 0;
1769         }
1770         
1771         i = (unsigned long *) table->data;
1772         min = (unsigned long *) table->extra1;
1773         max = (unsigned long *) table->extra2;
1774         vleft = table->maxlen / sizeof(unsigned long);
1775         left = *lenp;
1776         
1777         for (; left && vleft--; i++, min++, max++, first=0) {
1778                 if (write) {
1779                         while (left) {
1780                                 char c;
1781                                 if (get_user(c, s))
1782                                         return -EFAULT;
1783                                 if (!isspace(c))
1784                                         break;
1785                                 left--;
1786                                 s++;
1787                         }
1788                         if (!left)
1789                                 break;
1790                         neg = 0;
1791                         len = left;
1792                         if (len > TMPBUFLEN-1)
1793                                 len = TMPBUFLEN-1;
1794                         if (copy_from_user(buf, s, len))
1795                                 return -EFAULT;
1796                         buf[len] = 0;
1797                         p = buf;
1798                         if (*p == '-' && left > 1) {
1799                                 neg = 1;
1800                                 left--, p++;
1801                         }
1802                         if (*p < '0' || *p > '9')
1803                                 break;
1804                         val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1805                         len = p-buf;
1806                         if ((len < left) && *p && !isspace(*p))
1807                                 break;
1808                         if (neg)
1809                                 val = -val;
1810                         s += len;
1811                         left -= len;
1812
1813                         if(neg)
1814                                 continue;
1815                         if ((min && val < *min) || (max && val > *max))
1816                                 continue;
1817                         *i = val;
1818                 } else {
1819                         p = buf;
1820                         if (!first)
1821                                 *p++ = '\t';
1822                         sprintf(p, "%lu", convdiv * (*i) / convmul);
1823                         len = strlen(buf);
1824                         if (len > left)
1825                                 len = left;
1826                         if(copy_to_user(s, buf, len))
1827                                 return -EFAULT;
1828                         left -= len;
1829                         s += len;
1830                 }
1831         }
1832
1833         if (!write && !first && left) {
1834                 if(put_user('\n', s))
1835                         return -EFAULT;
1836                 left--, s++;
1837         }
1838         if (write) {
1839                 while (left) {
1840                         char c;
1841                         if (get_user(c, s++))
1842                                 return -EFAULT;
1843                         if (!isspace(c))
1844                                 break;
1845                         left--;
1846                 }
1847         }
1848         if (write && first)
1849                 return -EINVAL;
1850         *lenp -= left;
1851         *ppos += *lenp;
1852         return 0;
1853 #undef TMPBUFLEN
1854 }
1855
1856 /**
1857  * proc_doulongvec_minmax - read a vector of long integers with min/max values
1858  * @table: the sysctl table
1859  * @write: %TRUE if this is a write to the sysctl file
1860  * @filp: the file structure
1861  * @buffer: the user buffer
1862  * @lenp: the size of the user buffer
1863  * @ppos: file position
1864  *
1865  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1866  * values from/to the user buffer, treated as an ASCII string.
1867  *
1868  * This routine will ensure the values are within the range specified by
1869  * table->extra1 (min) and table->extra2 (max).
1870  *
1871  * Returns 0 on success.
1872  */
1873 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1874                            void __user *buffer, size_t *lenp, loff_t *ppos)
1875 {
1876     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1877 }
1878
1879 /**
1880  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1881  * @table: the sysctl table
1882  * @write: %TRUE if this is a write to the sysctl file
1883  * @filp: the file structure
1884  * @buffer: the user buffer
1885  * @lenp: the size of the user buffer
1886  * @ppos: file position
1887  *
1888  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1889  * values from/to the user buffer, treated as an ASCII string. The values
1890  * are treated as milliseconds, and converted to jiffies when they are stored.
1891  *
1892  * This routine will ensure the values are within the range specified by
1893  * table->extra1 (min) and table->extra2 (max).
1894  *
1895  * Returns 0 on success.
1896  */
1897 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1898                                       struct file *filp,
1899                                       void __user *buffer,
1900                                       size_t *lenp, loff_t *ppos)
1901 {
1902     return do_proc_doulongvec_minmax(table, write, filp, buffer,
1903                                      lenp, ppos, HZ, 1000l);
1904 }
1905
1906
1907 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1908                                          int *valp,
1909                                          int write, void *data)
1910 {
1911         if (write) {
1912                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1913         } else {
1914                 int val = *valp;
1915                 unsigned long lval;
1916                 if (val < 0) {
1917                         *negp = -1;
1918                         lval = (unsigned long)-val;
1919                 } else {
1920                         *negp = 0;
1921                         lval = (unsigned long)val;
1922                 }
1923                 *lvalp = lval / HZ;
1924         }
1925         return 0;
1926 }
1927
1928 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1929                                                 int *valp,
1930                                                 int write, void *data)
1931 {
1932         if (write) {
1933                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1934         } else {
1935                 int val = *valp;
1936                 unsigned long lval;
1937                 if (val < 0) {
1938                         *negp = -1;
1939                         lval = (unsigned long)-val;
1940                 } else {
1941                         *negp = 0;
1942                         lval = (unsigned long)val;
1943                 }
1944                 *lvalp = jiffies_to_clock_t(lval);
1945         }
1946         return 0;
1947 }
1948
1949 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1950                                             int *valp,
1951                                             int write, void *data)
1952 {
1953         if (write) {
1954                 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1955         } else {
1956                 int val = *valp;
1957                 unsigned long lval;
1958                 if (val < 0) {
1959                         *negp = -1;
1960                         lval = (unsigned long)-val;
1961                 } else {
1962                         *negp = 0;
1963                         lval = (unsigned long)val;
1964                 }
1965                 *lvalp = jiffies_to_msecs(lval);
1966         }
1967         return 0;
1968 }
1969
1970 /**
1971  * proc_dointvec_jiffies - read a vector of integers as seconds
1972  * @table: the sysctl table
1973  * @write: %TRUE if this is a write to the sysctl file
1974  * @filp: the file structure
1975  * @buffer: the user buffer
1976  * @lenp: the size of the user buffer
1977  * @ppos: file position
1978  *
1979  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1980  * values from/to the user buffer, treated as an ASCII string. 
1981  * The values read are assumed to be in seconds, and are converted into
1982  * jiffies.
1983  *
1984  * Returns 0 on success.
1985  */
1986 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1987                           void __user *buffer, size_t *lenp, loff_t *ppos)
1988 {
1989     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1990                             do_proc_dointvec_jiffies_conv,NULL);
1991 }
1992
1993 /**
1994  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1995  * @table: the sysctl table
1996  * @write: %TRUE if this is a write to the sysctl file
1997  * @filp: the file structure
1998  * @buffer: the user buffer
1999  * @lenp: the size of the user buffer
2000  *
2001  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2002  * values from/to the user buffer, treated as an ASCII string. 
2003  * The values read are assumed to be in 1/USER_HZ seconds, and 
2004  * are converted into jiffies.
2005  *
2006  * Returns 0 on success.
2007  */
2008 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2009                                  void __user *buffer, size_t *lenp, loff_t *ppos)
2010 {
2011     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2012                             do_proc_dointvec_userhz_jiffies_conv,NULL);
2013 }
2014
2015 /**
2016  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2017  * @table: the sysctl table
2018  * @write: %TRUE if this is a write to the sysctl file
2019  * @filp: the file structure
2020  * @buffer: the user buffer
2021  * @lenp: the size of the user buffer
2022  * @ppos: file position
2023  * @ppos: the current position in the file
2024  *
2025  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2026  * values from/to the user buffer, treated as an ASCII string. 
2027  * The values read are assumed to be in 1/1000 seconds, and 
2028  * are converted into jiffies.
2029  *
2030  * Returns 0 on success.
2031  */
2032 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2033                              void __user *buffer, size_t *lenp, loff_t *ppos)
2034 {
2035         return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2036                                 do_proc_dointvec_ms_jiffies_conv, NULL);
2037 }
2038
2039 #else /* CONFIG_PROC_FS */
2040
2041 int proc_dostring(ctl_table *table, int write, struct file *filp,
2042                   void __user *buffer, size_t *lenp, loff_t *ppos)
2043 {
2044         return -ENOSYS;
2045 }
2046
2047 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2048                             void __user *buffer, size_t *lenp, loff_t *ppos)
2049 {
2050         return -ENOSYS;
2051 }
2052
2053 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2054                   void __user *buffer, size_t *lenp, loff_t *ppos)
2055 {
2056         return -ENOSYS;
2057 }
2058
2059 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2060                         void __user *buffer, size_t *lenp, loff_t *ppos)
2061 {
2062         return -ENOSYS;
2063 }
2064
2065 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2066                     void __user *buffer, size_t *lenp, loff_t *ppos)
2067 {
2068         return -ENOSYS;
2069 }
2070
2071 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2072                     void __user *buffer, size_t *lenp, loff_t *ppos)
2073 {
2074         return -ENOSYS;
2075 }
2076
2077 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2078                     void __user *buffer, size_t *lenp, loff_t *ppos)
2079 {
2080         return -ENOSYS;
2081 }
2082
2083 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2084                              void __user *buffer, size_t *lenp, loff_t *ppos)
2085 {
2086         return -ENOSYS;
2087 }
2088
2089 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2090                     void __user *buffer, size_t *lenp, loff_t *ppos)
2091 {
2092         return -ENOSYS;
2093 }
2094
2095 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2096                                       struct file *filp,
2097                                       void __user *buffer,
2098                                       size_t *lenp, loff_t *ppos)
2099 {
2100     return -ENOSYS;
2101 }
2102
2103
2104 #endif /* CONFIG_PROC_FS */
2105
2106
2107 /*
2108  * General sysctl support routines 
2109  */
2110
2111 /* The generic string strategy routine: */
2112 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2113                   void __user *oldval, size_t __user *oldlenp,
2114                   void __user *newval, size_t newlen, void **context)
2115 {
2116         size_t l, len;
2117         
2118         if (!table->data || !table->maxlen) 
2119                 return -ENOTDIR;
2120         
2121         if (oldval && oldlenp) {
2122                 if (get_user(len, oldlenp))
2123                         return -EFAULT;
2124                 if (len) {
2125                         l = strlen(table->data);
2126                         if (len > l) len = l;
2127                         if (len >= table->maxlen)
2128                                 len = table->maxlen;
2129                         if(copy_to_user(oldval, table->data, len))
2130                                 return -EFAULT;
2131                         if(put_user(0, ((char __user *) oldval) + len))
2132                                 return -EFAULT;
2133                         if(put_user(len, oldlenp))
2134                                 return -EFAULT;
2135                 }
2136         }
2137         if (newval && newlen) {
2138                 len = newlen;
2139                 if (len > table->maxlen)
2140                         len = table->maxlen;
2141                 if(copy_from_user(table->data, newval, len))
2142                         return -EFAULT;
2143                 if (len == table->maxlen)
2144                         len--;
2145                 ((char *) table->data)[len] = 0;
2146         }
2147         return 0;
2148 }
2149
2150 /*
2151  * This function makes sure that all of the integers in the vector
2152  * are between the minimum and maximum values given in the arrays
2153  * table->extra1 and table->extra2, respectively.
2154  */
2155 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2156                 void __user *oldval, size_t __user *oldlenp,
2157                 void __user *newval, size_t newlen, void **context)
2158 {
2159
2160         if (newval && newlen) {
2161                 int __user *vec = (int __user *) newval;
2162                 int *min = (int *) table->extra1;
2163                 int *max = (int *) table->extra2;
2164                 size_t length;
2165                 int i;
2166
2167                 if (newlen % sizeof(int) != 0)
2168                         return -EINVAL;
2169
2170                 if (!table->extra1 && !table->extra2)
2171                         return 0;
2172
2173                 if (newlen > table->maxlen)
2174                         newlen = table->maxlen;
2175                 length = newlen / sizeof(int);
2176
2177                 for (i = 0; i < length; i++) {
2178                         int value;
2179                         if (get_user(value, vec + i))
2180                                 return -EFAULT;
2181                         if (min && value < min[i])
2182                                 return -EINVAL;
2183                         if (max && value > max[i])
2184                                 return -EINVAL;
2185                 }
2186         }
2187         return 0;
2188 }
2189
2190 /* Strategy function to convert jiffies to seconds */ 
2191 int sysctl_jiffies(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         if (oldval) {
2196                 size_t olen;
2197                 if (oldlenp) { 
2198                         if (get_user(olen, oldlenp))
2199                                 return -EFAULT;
2200                         if (olen!=sizeof(int))
2201                                 return -EINVAL; 
2202                 }
2203                 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2204                     (oldlenp && put_user(sizeof(int),oldlenp)))
2205                         return -EFAULT;
2206         }
2207         if (newval && newlen) { 
2208                 int new;
2209                 if (newlen != sizeof(int))
2210                         return -EINVAL; 
2211                 if (get_user(new, (int __user *)newval))
2212                         return -EFAULT;
2213                 *(int *)(table->data) = new*HZ; 
2214         }
2215         return 1;
2216 }
2217
2218 /* Strategy function to convert jiffies to seconds */ 
2219 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2220                 void __user *oldval, size_t __user *oldlenp,
2221                 void __user *newval, size_t newlen, void **context)
2222 {
2223         if (oldval) {
2224                 size_t olen;
2225                 if (oldlenp) { 
2226                         if (get_user(olen, oldlenp))
2227                                 return -EFAULT;
2228                         if (olen!=sizeof(int))
2229                                 return -EINVAL; 
2230                 }
2231                 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2232                     (oldlenp && put_user(sizeof(int),oldlenp)))
2233                         return -EFAULT;
2234         }
2235         if (newval && newlen) { 
2236                 int new;
2237                 if (newlen != sizeof(int))
2238                         return -EINVAL; 
2239                 if (get_user(new, (int __user *)newval))
2240                         return -EFAULT;
2241                 *(int *)(table->data) = msecs_to_jiffies(new);
2242         }
2243         return 1;
2244 }
2245
2246 #else /* CONFIG_SYSCTL */
2247
2248
2249 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2250 {
2251         return -ENOSYS;
2252 }
2253
2254 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2255                   void __user *oldval, size_t __user *oldlenp,
2256                   void __user *newval, size_t newlen, void **context)
2257 {
2258         return -ENOSYS;
2259 }
2260
2261 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2262                 void __user *oldval, size_t __user *oldlenp,
2263                 void __user *newval, size_t newlen, void **context)
2264 {
2265         return -ENOSYS;
2266 }
2267
2268 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2269                 void __user *oldval, size_t __user *oldlenp,
2270                 void __user *newval, size_t newlen, void **context)
2271 {
2272         return -ENOSYS;
2273 }
2274
2275 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2276                 void __user *oldval, size_t __user *oldlenp,
2277                 void __user *newval, size_t newlen, void **context)
2278 {
2279         return -ENOSYS;
2280 }
2281
2282 int proc_dostring(ctl_table *table, int write, struct file *filp,
2283                   void __user *buffer, size_t *lenp, loff_t *ppos)
2284 {
2285         return -ENOSYS;
2286 }
2287
2288 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2289                   void __user *buffer, size_t *lenp, loff_t *ppos)
2290 {
2291         return -ENOSYS;
2292 }
2293
2294 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2295                         void __user *buffer, size_t *lenp, loff_t *ppos)
2296 {
2297         return -ENOSYS;
2298 }
2299
2300 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2301                     void __user *buffer, size_t *lenp, loff_t *ppos)
2302 {
2303         return -ENOSYS;
2304 }
2305
2306 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2307                           void __user *buffer, size_t *lenp, loff_t *ppos)
2308 {
2309         return -ENOSYS;
2310 }
2311
2312 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2313                           void __user *buffer, size_t *lenp, loff_t *ppos)
2314 {
2315         return -ENOSYS;
2316 }
2317
2318 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2319                              void __user *buffer, size_t *lenp, loff_t *ppos)
2320 {
2321         return -ENOSYS;
2322 }
2323
2324 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2325                     void __user *buffer, size_t *lenp, loff_t *ppos)
2326 {
2327         return -ENOSYS;
2328 }
2329
2330 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2331                                       struct file *filp,
2332                                       void __user *buffer,
2333                                       size_t *lenp, loff_t *ppos)
2334 {
2335     return -ENOSYS;
2336 }
2337
2338 struct ctl_table_header * register_sysctl_table(ctl_table * table, 
2339                                                 int insert_at_head)
2340 {
2341         return NULL;
2342 }
2343
2344 void unregister_sysctl_table(struct ctl_table_header * table)
2345 {
2346 }
2347
2348 #endif /* CONFIG_SYSCTL */
2349
2350 /*
2351  * No sense putting this after each symbol definition, twice,
2352  * exception granted :-)
2353  */
2354 EXPORT_SYMBOL(proc_dointvec);
2355 EXPORT_SYMBOL(proc_dointvec_jiffies);
2356 EXPORT_SYMBOL(proc_dointvec_minmax);
2357 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2358 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2359 EXPORT_SYMBOL(proc_dostring);
2360 EXPORT_SYMBOL(proc_doulongvec_minmax);
2361 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2362 EXPORT_SYMBOL(register_sysctl_table);
2363 EXPORT_SYMBOL(sysctl_intvec);
2364 EXPORT_SYMBOL(sysctl_jiffies);
2365 EXPORT_SYMBOL(sysctl_ms_jiffies);
2366 EXPORT_SYMBOL(sysctl_string);
2367 EXPORT_SYMBOL(unregister_sysctl_table);