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