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