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