[PATCH] Generic ioremap_page_range: parisc conversion
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / sysctl.c
blob9846db93a595ec91b56a0ed8ded69cd9ea730b27
1 /*
2 * sysctl.c: General linux system control interface
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
21 #include <linux/module.h>
22 #include <linux/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/capability.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
52 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
53 void __user *buffer, size_t *lenp, loff_t *ppos);
55 #ifdef CONFIG_X86
56 #include <asm/nmi.h>
57 #include <asm/stacktrace.h>
58 #endif
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
63 extern int C_A_D;
64 extern int sysctl_overcommit_memory;
65 extern int sysctl_overcommit_ratio;
66 extern int sysctl_panic_on_oom;
67 extern int max_threads;
68 extern int sysrq_enabled;
69 extern int core_uses_pid;
70 extern int suid_dumpable;
71 extern char core_pattern[];
72 extern int pid_max;
73 extern int min_free_kbytes;
74 extern int printk_ratelimit_jiffies;
75 extern int printk_ratelimit_burst;
76 extern int pid_max_min, pid_max_max;
77 extern int sysctl_drop_caches;
78 extern int percpu_pagelist_fraction;
79 extern int compat_log;
81 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
82 static int maxolduid = 65535;
83 static int minolduid;
84 static int min_percpu_pagelist_fract = 8;
86 static int ngroups_max = NGROUPS_MAX;
88 #ifdef CONFIG_KMOD
89 extern char modprobe_path[];
90 #endif
91 #ifdef CONFIG_CHR_DEV_SG
92 extern int sg_big_buff;
93 #endif
94 #ifdef CONFIG_SYSVIPC
95 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
96 void __user *buffer, size_t *lenp, loff_t *ppos);
97 #endif
99 #ifdef __sparc__
100 extern char reboot_command [];
101 extern int stop_a_enabled;
102 extern int scons_pwroff;
103 #endif
105 #ifdef __hppa__
106 extern int pwrsw_enabled;
107 extern int unaligned_enabled;
108 #endif
110 #ifdef CONFIG_S390
111 #ifdef CONFIG_MATHEMU
112 extern int sysctl_ieee_emulation_warnings;
113 #endif
114 extern int sysctl_userprocess_debug;
115 extern int spin_retry;
116 #endif
118 extern int sysctl_hz_timer;
120 #ifdef CONFIG_BSD_PROCESS_ACCT
121 extern int acct_parm[];
122 #endif
124 #ifdef CONFIG_IA64
125 extern int no_unaligned_warning;
126 #endif
128 #ifdef CONFIG_RT_MUTEXES
129 extern int max_lock_depth;
130 #endif
132 #ifdef CONFIG_SYSCTL_SYSCALL
133 static int parse_table(int __user *, int, void __user *, size_t __user *,
134 void __user *, size_t, ctl_table *, void **);
135 #endif
137 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
138 void __user *buffer, size_t *lenp, loff_t *ppos);
140 #ifdef CONFIG_PROC_SYSCTL
141 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
142 void __user *buffer, size_t *lenp, loff_t *ppos);
143 #endif
145 static ctl_table root_table[];
146 static struct ctl_table_header root_table_header =
147 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
149 static ctl_table kern_table[];
150 static ctl_table vm_table[];
151 static ctl_table fs_table[];
152 static ctl_table debug_table[];
153 static ctl_table dev_table[];
154 extern ctl_table random_table[];
155 #ifdef CONFIG_UNIX98_PTYS
156 extern ctl_table pty_table[];
157 #endif
158 #ifdef CONFIG_INOTIFY_USER
159 extern ctl_table inotify_table[];
160 #endif
162 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
163 int sysctl_legacy_va_layout;
164 #endif
166 /* /proc declarations: */
168 #ifdef CONFIG_PROC_SYSCTL
170 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
171 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
172 static int proc_opensys(struct inode *, struct file *);
174 const struct file_operations proc_sys_file_operations = {
175 .open = proc_opensys,
176 .read = proc_readsys,
177 .write = proc_writesys,
180 extern struct proc_dir_entry *proc_sys_root;
182 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
183 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
184 #endif
186 /* The default sysctl tables: */
188 static ctl_table root_table[] = {
190 .ctl_name = CTL_KERN,
191 .procname = "kernel",
192 .mode = 0555,
193 .child = kern_table,
196 .ctl_name = CTL_VM,
197 .procname = "vm",
198 .mode = 0555,
199 .child = vm_table,
201 #ifdef CONFIG_NET
203 .ctl_name = CTL_NET,
204 .procname = "net",
205 .mode = 0555,
206 .child = net_table,
208 #endif
210 .ctl_name = CTL_FS,
211 .procname = "fs",
212 .mode = 0555,
213 .child = fs_table,
216 .ctl_name = CTL_DEBUG,
217 .procname = "debug",
218 .mode = 0555,
219 .child = debug_table,
222 .ctl_name = CTL_DEV,
223 .procname = "dev",
224 .mode = 0555,
225 .child = dev_table,
228 { .ctl_name = 0 }
231 static ctl_table kern_table[] = {
232 #ifndef CONFIG_UTS_NS
234 .ctl_name = KERN_OSTYPE,
235 .procname = "ostype",
236 .data = init_uts_ns.name.sysname,
237 .maxlen = sizeof(init_uts_ns.name.sysname),
238 .mode = 0444,
239 .proc_handler = &proc_do_uts_string,
240 .strategy = &sysctl_string,
243 .ctl_name = KERN_OSRELEASE,
244 .procname = "osrelease",
245 .data = init_uts_ns.name.release,
246 .maxlen = sizeof(init_uts_ns.name.release),
247 .mode = 0444,
248 .proc_handler = &proc_do_uts_string,
249 .strategy = &sysctl_string,
252 .ctl_name = KERN_VERSION,
253 .procname = "version",
254 .data = init_uts_ns.name.version,
255 .maxlen = sizeof(init_uts_ns.name.version),
256 .mode = 0444,
257 .proc_handler = &proc_do_uts_string,
258 .strategy = &sysctl_string,
261 .ctl_name = KERN_NODENAME,
262 .procname = "hostname",
263 .data = init_uts_ns.name.nodename,
264 .maxlen = sizeof(init_uts_ns.name.nodename),
265 .mode = 0644,
266 .proc_handler = &proc_do_uts_string,
267 .strategy = &sysctl_string,
270 .ctl_name = KERN_DOMAINNAME,
271 .procname = "domainname",
272 .data = init_uts_ns.name.domainname,
273 .maxlen = sizeof(init_uts_ns.name.domainname),
274 .mode = 0644,
275 .proc_handler = &proc_do_uts_string,
276 .strategy = &sysctl_string,
278 #else /* !CONFIG_UTS_NS */
280 .ctl_name = KERN_OSTYPE,
281 .procname = "ostype",
282 .data = NULL,
283 /* could maybe use __NEW_UTS_LEN here? */
284 .maxlen = FIELD_SIZEOF(struct new_utsname, sysname),
285 .mode = 0444,
286 .proc_handler = &proc_do_uts_string,
287 .strategy = &sysctl_string,
290 .ctl_name = KERN_OSRELEASE,
291 .procname = "osrelease",
292 .data = NULL,
293 .maxlen = FIELD_SIZEOF(struct new_utsname, release),
294 .mode = 0444,
295 .proc_handler = &proc_do_uts_string,
296 .strategy = &sysctl_string,
299 .ctl_name = KERN_VERSION,
300 .procname = "version",
301 .data = NULL,
302 .maxlen = FIELD_SIZEOF(struct new_utsname, version),
303 .mode = 0444,
304 .proc_handler = &proc_do_uts_string,
305 .strategy = &sysctl_string,
308 .ctl_name = KERN_NODENAME,
309 .procname = "hostname",
310 .data = NULL,
311 .maxlen = FIELD_SIZEOF(struct new_utsname, nodename),
312 .mode = 0644,
313 .proc_handler = &proc_do_uts_string,
314 .strategy = &sysctl_string,
317 .ctl_name = KERN_DOMAINNAME,
318 .procname = "domainname",
319 .data = NULL,
320 .maxlen = FIELD_SIZEOF(struct new_utsname, domainname),
321 .mode = 0644,
322 .proc_handler = &proc_do_uts_string,
323 .strategy = &sysctl_string,
325 #endif /* !CONFIG_UTS_NS */
327 .ctl_name = KERN_PANIC,
328 .procname = "panic",
329 .data = &panic_timeout,
330 .maxlen = sizeof(int),
331 .mode = 0644,
332 .proc_handler = &proc_dointvec,
335 .ctl_name = KERN_CORE_USES_PID,
336 .procname = "core_uses_pid",
337 .data = &core_uses_pid,
338 .maxlen = sizeof(int),
339 .mode = 0644,
340 .proc_handler = &proc_dointvec,
343 .ctl_name = KERN_CORE_PATTERN,
344 .procname = "core_pattern",
345 .data = core_pattern,
346 .maxlen = 128,
347 .mode = 0644,
348 .proc_handler = &proc_dostring,
349 .strategy = &sysctl_string,
352 .ctl_name = KERN_TAINTED,
353 .procname = "tainted",
354 .data = &tainted,
355 .maxlen = sizeof(int),
356 .mode = 0444,
357 .proc_handler = &proc_dointvec,
360 .ctl_name = KERN_CAP_BSET,
361 .procname = "cap-bound",
362 .data = &cap_bset,
363 .maxlen = sizeof(kernel_cap_t),
364 .mode = 0600,
365 .proc_handler = &proc_dointvec_bset,
367 #ifdef CONFIG_BLK_DEV_INITRD
369 .ctl_name = KERN_REALROOTDEV,
370 .procname = "real-root-dev",
371 .data = &real_root_dev,
372 .maxlen = sizeof(int),
373 .mode = 0644,
374 .proc_handler = &proc_dointvec,
376 #endif
377 #ifdef __sparc__
379 .ctl_name = KERN_SPARC_REBOOT,
380 .procname = "reboot-cmd",
381 .data = reboot_command,
382 .maxlen = 256,
383 .mode = 0644,
384 .proc_handler = &proc_dostring,
385 .strategy = &sysctl_string,
388 .ctl_name = KERN_SPARC_STOP_A,
389 .procname = "stop-a",
390 .data = &stop_a_enabled,
391 .maxlen = sizeof (int),
392 .mode = 0644,
393 .proc_handler = &proc_dointvec,
396 .ctl_name = KERN_SPARC_SCONS_PWROFF,
397 .procname = "scons-poweroff",
398 .data = &scons_pwroff,
399 .maxlen = sizeof (int),
400 .mode = 0644,
401 .proc_handler = &proc_dointvec,
403 #endif
404 #ifdef __hppa__
406 .ctl_name = KERN_HPPA_PWRSW,
407 .procname = "soft-power",
408 .data = &pwrsw_enabled,
409 .maxlen = sizeof (int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
414 .ctl_name = KERN_HPPA_UNALIGNED,
415 .procname = "unaligned-trap",
416 .data = &unaligned_enabled,
417 .maxlen = sizeof (int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
421 #endif
423 .ctl_name = KERN_CTLALTDEL,
424 .procname = "ctrl-alt-del",
425 .data = &C_A_D,
426 .maxlen = sizeof(int),
427 .mode = 0644,
428 .proc_handler = &proc_dointvec,
431 .ctl_name = KERN_PRINTK,
432 .procname = "printk",
433 .data = &console_loglevel,
434 .maxlen = 4*sizeof(int),
435 .mode = 0644,
436 .proc_handler = &proc_dointvec,
438 #ifdef CONFIG_KMOD
440 .ctl_name = KERN_MODPROBE,
441 .procname = "modprobe",
442 .data = &modprobe_path,
443 .maxlen = KMOD_PATH_LEN,
444 .mode = 0644,
445 .proc_handler = &proc_dostring,
446 .strategy = &sysctl_string,
448 #endif
449 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
451 .ctl_name = KERN_HOTPLUG,
452 .procname = "hotplug",
453 .data = &uevent_helper,
454 .maxlen = UEVENT_HELPER_PATH_LEN,
455 .mode = 0644,
456 .proc_handler = &proc_dostring,
457 .strategy = &sysctl_string,
459 #endif
460 #ifdef CONFIG_CHR_DEV_SG
462 .ctl_name = KERN_SG_BIG_BUFF,
463 .procname = "sg-big-buff",
464 .data = &sg_big_buff,
465 .maxlen = sizeof (int),
466 .mode = 0444,
467 .proc_handler = &proc_dointvec,
469 #endif
470 #ifdef CONFIG_BSD_PROCESS_ACCT
472 .ctl_name = KERN_ACCT,
473 .procname = "acct",
474 .data = &acct_parm,
475 .maxlen = 3*sizeof(int),
476 .mode = 0644,
477 .proc_handler = &proc_dointvec,
479 #endif
480 #ifdef CONFIG_SYSVIPC
482 .ctl_name = KERN_SHMMAX,
483 .procname = "shmmax",
484 .data = NULL,
485 .maxlen = sizeof (size_t),
486 .mode = 0644,
487 .proc_handler = &proc_do_ipc_string,
490 .ctl_name = KERN_SHMALL,
491 .procname = "shmall",
492 .data = NULL,
493 .maxlen = sizeof (size_t),
494 .mode = 0644,
495 .proc_handler = &proc_do_ipc_string,
498 .ctl_name = KERN_SHMMNI,
499 .procname = "shmmni",
500 .data = NULL,
501 .maxlen = sizeof (int),
502 .mode = 0644,
503 .proc_handler = &proc_do_ipc_string,
506 .ctl_name = KERN_MSGMAX,
507 .procname = "msgmax",
508 .data = NULL,
509 .maxlen = sizeof (int),
510 .mode = 0644,
511 .proc_handler = &proc_do_ipc_string,
514 .ctl_name = KERN_MSGMNI,
515 .procname = "msgmni",
516 .data = NULL,
517 .maxlen = sizeof (int),
518 .mode = 0644,
519 .proc_handler = &proc_do_ipc_string,
522 .ctl_name = KERN_MSGMNB,
523 .procname = "msgmnb",
524 .data = NULL,
525 .maxlen = sizeof (int),
526 .mode = 0644,
527 .proc_handler = &proc_do_ipc_string,
530 .ctl_name = KERN_SEM,
531 .procname = "sem",
532 .data = NULL,
533 .maxlen = 4*sizeof (int),
534 .mode = 0644,
535 .proc_handler = &proc_do_ipc_string,
537 #endif
538 #ifdef CONFIG_MAGIC_SYSRQ
540 .ctl_name = KERN_SYSRQ,
541 .procname = "sysrq",
542 .data = &sysrq_enabled,
543 .maxlen = sizeof (int),
544 .mode = 0644,
545 .proc_handler = &proc_dointvec,
547 #endif
548 #ifdef CONFIG_PROC_SYSCTL
550 .ctl_name = KERN_CADPID,
551 .procname = "cad_pid",
552 .data = NULL,
553 .maxlen = sizeof (int),
554 .mode = 0600,
555 .proc_handler = &proc_do_cad_pid,
557 #endif
559 .ctl_name = KERN_MAX_THREADS,
560 .procname = "threads-max",
561 .data = &max_threads,
562 .maxlen = sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec,
567 .ctl_name = KERN_RANDOM,
568 .procname = "random",
569 .mode = 0555,
570 .child = random_table,
572 #ifdef CONFIG_UNIX98_PTYS
574 .ctl_name = KERN_PTY,
575 .procname = "pty",
576 .mode = 0555,
577 .child = pty_table,
579 #endif
581 .ctl_name = KERN_OVERFLOWUID,
582 .procname = "overflowuid",
583 .data = &overflowuid,
584 .maxlen = sizeof(int),
585 .mode = 0644,
586 .proc_handler = &proc_dointvec_minmax,
587 .strategy = &sysctl_intvec,
588 .extra1 = &minolduid,
589 .extra2 = &maxolduid,
592 .ctl_name = KERN_OVERFLOWGID,
593 .procname = "overflowgid",
594 .data = &overflowgid,
595 .maxlen = sizeof(int),
596 .mode = 0644,
597 .proc_handler = &proc_dointvec_minmax,
598 .strategy = &sysctl_intvec,
599 .extra1 = &minolduid,
600 .extra2 = &maxolduid,
602 #ifdef CONFIG_S390
603 #ifdef CONFIG_MATHEMU
605 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
606 .procname = "ieee_emulation_warnings",
607 .data = &sysctl_ieee_emulation_warnings,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec,
612 #endif
613 #ifdef CONFIG_NO_IDLE_HZ
615 .ctl_name = KERN_HZ_TIMER,
616 .procname = "hz_timer",
617 .data = &sysctl_hz_timer,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec,
622 #endif
624 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
625 .procname = "userprocess_debug",
626 .data = &sysctl_userprocess_debug,
627 .maxlen = sizeof(int),
628 .mode = 0644,
629 .proc_handler = &proc_dointvec,
631 #endif
633 .ctl_name = KERN_PIDMAX,
634 .procname = "pid_max",
635 .data = &pid_max,
636 .maxlen = sizeof (int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec_minmax,
639 .strategy = sysctl_intvec,
640 .extra1 = &pid_max_min,
641 .extra2 = &pid_max_max,
644 .ctl_name = KERN_PANIC_ON_OOPS,
645 .procname = "panic_on_oops",
646 .data = &panic_on_oops,
647 .maxlen = sizeof(int),
648 .mode = 0644,
649 .proc_handler = &proc_dointvec,
652 .ctl_name = KERN_PRINTK_RATELIMIT,
653 .procname = "printk_ratelimit",
654 .data = &printk_ratelimit_jiffies,
655 .maxlen = sizeof(int),
656 .mode = 0644,
657 .proc_handler = &proc_dointvec_jiffies,
658 .strategy = &sysctl_jiffies,
661 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
662 .procname = "printk_ratelimit_burst",
663 .data = &printk_ratelimit_burst,
664 .maxlen = sizeof(int),
665 .mode = 0644,
666 .proc_handler = &proc_dointvec,
669 .ctl_name = KERN_NGROUPS_MAX,
670 .procname = "ngroups_max",
671 .data = &ngroups_max,
672 .maxlen = sizeof (int),
673 .mode = 0444,
674 .proc_handler = &proc_dointvec,
676 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
678 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
679 .procname = "unknown_nmi_panic",
680 .data = &unknown_nmi_panic,
681 .maxlen = sizeof (int),
682 .mode = 0644,
683 .proc_handler = &proc_dointvec,
686 .ctl_name = KERN_NMI_WATCHDOG,
687 .procname = "nmi_watchdog",
688 .data = &nmi_watchdog_enabled,
689 .maxlen = sizeof (int),
690 .mode = 0644,
691 .proc_handler = &proc_nmi_enabled,
693 #endif
694 #if defined(CONFIG_X86)
696 .ctl_name = KERN_PANIC_ON_NMI,
697 .procname = "panic_on_unrecovered_nmi",
698 .data = &panic_on_unrecovered_nmi,
699 .maxlen = sizeof(int),
700 .mode = 0644,
701 .proc_handler = &proc_dointvec,
704 .ctl_name = KERN_BOOTLOADER_TYPE,
705 .procname = "bootloader_type",
706 .data = &bootloader_type,
707 .maxlen = sizeof (int),
708 .mode = 0444,
709 .proc_handler = &proc_dointvec,
712 .ctl_name = CTL_UNNUMBERED,
713 .procname = "kstack_depth_to_print",
714 .data = &kstack_depth_to_print,
715 .maxlen = sizeof(int),
716 .mode = 0644,
717 .proc_handler = &proc_dointvec,
719 #endif
720 #if defined(CONFIG_MMU)
722 .ctl_name = KERN_RANDOMIZE,
723 .procname = "randomize_va_space",
724 .data = &randomize_va_space,
725 .maxlen = sizeof(int),
726 .mode = 0644,
727 .proc_handler = &proc_dointvec,
729 #endif
730 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
732 .ctl_name = KERN_SPIN_RETRY,
733 .procname = "spin_retry",
734 .data = &spin_retry,
735 .maxlen = sizeof (int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
739 #endif
740 #ifdef CONFIG_ACPI_SLEEP
742 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
743 .procname = "acpi_video_flags",
744 .data = &acpi_video_flags,
745 .maxlen = sizeof (unsigned long),
746 .mode = 0644,
747 .proc_handler = &proc_doulongvec_minmax,
749 #endif
750 #ifdef CONFIG_IA64
752 .ctl_name = KERN_IA64_UNALIGNED,
753 .procname = "ignore-unaligned-usertrap",
754 .data = &no_unaligned_warning,
755 .maxlen = sizeof (int),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
759 #endif
760 #ifdef CONFIG_COMPAT
762 .ctl_name = KERN_COMPAT_LOG,
763 .procname = "compat-log",
764 .data = &compat_log,
765 .maxlen = sizeof (int),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec,
769 #endif
770 #ifdef CONFIG_RT_MUTEXES
772 .ctl_name = KERN_MAX_LOCK_DEPTH,
773 .procname = "max_lock_depth",
774 .data = &max_lock_depth,
775 .maxlen = sizeof(int),
776 .mode = 0644,
777 .proc_handler = &proc_dointvec,
779 #endif
781 { .ctl_name = 0 }
784 /* Constants for minimum and maximum testing in vm_table.
785 We use these as one-element integer vectors. */
786 static int zero;
787 static int one_hundred = 100;
790 static ctl_table vm_table[] = {
792 .ctl_name = VM_OVERCOMMIT_MEMORY,
793 .procname = "overcommit_memory",
794 .data = &sysctl_overcommit_memory,
795 .maxlen = sizeof(sysctl_overcommit_memory),
796 .mode = 0644,
797 .proc_handler = &proc_dointvec,
800 .ctl_name = VM_PANIC_ON_OOM,
801 .procname = "panic_on_oom",
802 .data = &sysctl_panic_on_oom,
803 .maxlen = sizeof(sysctl_panic_on_oom),
804 .mode = 0644,
805 .proc_handler = &proc_dointvec,
808 .ctl_name = VM_OVERCOMMIT_RATIO,
809 .procname = "overcommit_ratio",
810 .data = &sysctl_overcommit_ratio,
811 .maxlen = sizeof(sysctl_overcommit_ratio),
812 .mode = 0644,
813 .proc_handler = &proc_dointvec,
816 .ctl_name = VM_PAGE_CLUSTER,
817 .procname = "page-cluster",
818 .data = &page_cluster,
819 .maxlen = sizeof(int),
820 .mode = 0644,
821 .proc_handler = &proc_dointvec,
824 .ctl_name = VM_DIRTY_BACKGROUND,
825 .procname = "dirty_background_ratio",
826 .data = &dirty_background_ratio,
827 .maxlen = sizeof(dirty_background_ratio),
828 .mode = 0644,
829 .proc_handler = &proc_dointvec_minmax,
830 .strategy = &sysctl_intvec,
831 .extra1 = &zero,
832 .extra2 = &one_hundred,
835 .ctl_name = VM_DIRTY_RATIO,
836 .procname = "dirty_ratio",
837 .data = &vm_dirty_ratio,
838 .maxlen = sizeof(vm_dirty_ratio),
839 .mode = 0644,
840 .proc_handler = &proc_dointvec_minmax,
841 .strategy = &sysctl_intvec,
842 .extra1 = &zero,
843 .extra2 = &one_hundred,
846 .ctl_name = VM_DIRTY_WB_CS,
847 .procname = "dirty_writeback_centisecs",
848 .data = &dirty_writeback_interval,
849 .maxlen = sizeof(dirty_writeback_interval),
850 .mode = 0644,
851 .proc_handler = &dirty_writeback_centisecs_handler,
854 .ctl_name = VM_DIRTY_EXPIRE_CS,
855 .procname = "dirty_expire_centisecs",
856 .data = &dirty_expire_interval,
857 .maxlen = sizeof(dirty_expire_interval),
858 .mode = 0644,
859 .proc_handler = &proc_dointvec_userhz_jiffies,
862 .ctl_name = VM_NR_PDFLUSH_THREADS,
863 .procname = "nr_pdflush_threads",
864 .data = &nr_pdflush_threads,
865 .maxlen = sizeof nr_pdflush_threads,
866 .mode = 0444 /* read-only*/,
867 .proc_handler = &proc_dointvec,
870 .ctl_name = VM_SWAPPINESS,
871 .procname = "swappiness",
872 .data = &vm_swappiness,
873 .maxlen = sizeof(vm_swappiness),
874 .mode = 0644,
875 .proc_handler = &proc_dointvec_minmax,
876 .strategy = &sysctl_intvec,
877 .extra1 = &zero,
878 .extra2 = &one_hundred,
880 #ifdef CONFIG_HUGETLB_PAGE
882 .ctl_name = VM_HUGETLB_PAGES,
883 .procname = "nr_hugepages",
884 .data = &max_huge_pages,
885 .maxlen = sizeof(unsigned long),
886 .mode = 0644,
887 .proc_handler = &hugetlb_sysctl_handler,
888 .extra1 = (void *)&hugetlb_zero,
889 .extra2 = (void *)&hugetlb_infinity,
892 .ctl_name = VM_HUGETLB_GROUP,
893 .procname = "hugetlb_shm_group",
894 .data = &sysctl_hugetlb_shm_group,
895 .maxlen = sizeof(gid_t),
896 .mode = 0644,
897 .proc_handler = &proc_dointvec,
899 #endif
901 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
902 .procname = "lowmem_reserve_ratio",
903 .data = &sysctl_lowmem_reserve_ratio,
904 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
905 .mode = 0644,
906 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
907 .strategy = &sysctl_intvec,
910 .ctl_name = VM_DROP_PAGECACHE,
911 .procname = "drop_caches",
912 .data = &sysctl_drop_caches,
913 .maxlen = sizeof(int),
914 .mode = 0644,
915 .proc_handler = drop_caches_sysctl_handler,
916 .strategy = &sysctl_intvec,
919 .ctl_name = VM_MIN_FREE_KBYTES,
920 .procname = "min_free_kbytes",
921 .data = &min_free_kbytes,
922 .maxlen = sizeof(min_free_kbytes),
923 .mode = 0644,
924 .proc_handler = &min_free_kbytes_sysctl_handler,
925 .strategy = &sysctl_intvec,
926 .extra1 = &zero,
929 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
930 .procname = "percpu_pagelist_fraction",
931 .data = &percpu_pagelist_fraction,
932 .maxlen = sizeof(percpu_pagelist_fraction),
933 .mode = 0644,
934 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
935 .strategy = &sysctl_intvec,
936 .extra1 = &min_percpu_pagelist_fract,
938 #ifdef CONFIG_MMU
940 .ctl_name = VM_MAX_MAP_COUNT,
941 .procname = "max_map_count",
942 .data = &sysctl_max_map_count,
943 .maxlen = sizeof(sysctl_max_map_count),
944 .mode = 0644,
945 .proc_handler = &proc_dointvec
947 #endif
949 .ctl_name = VM_LAPTOP_MODE,
950 .procname = "laptop_mode",
951 .data = &laptop_mode,
952 .maxlen = sizeof(laptop_mode),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec_jiffies,
955 .strategy = &sysctl_jiffies,
958 .ctl_name = VM_BLOCK_DUMP,
959 .procname = "block_dump",
960 .data = &block_dump,
961 .maxlen = sizeof(block_dump),
962 .mode = 0644,
963 .proc_handler = &proc_dointvec,
964 .strategy = &sysctl_intvec,
965 .extra1 = &zero,
968 .ctl_name = VM_VFS_CACHE_PRESSURE,
969 .procname = "vfs_cache_pressure",
970 .data = &sysctl_vfs_cache_pressure,
971 .maxlen = sizeof(sysctl_vfs_cache_pressure),
972 .mode = 0644,
973 .proc_handler = &proc_dointvec,
974 .strategy = &sysctl_intvec,
975 .extra1 = &zero,
977 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
979 .ctl_name = VM_LEGACY_VA_LAYOUT,
980 .procname = "legacy_va_layout",
981 .data = &sysctl_legacy_va_layout,
982 .maxlen = sizeof(sysctl_legacy_va_layout),
983 .mode = 0644,
984 .proc_handler = &proc_dointvec,
985 .strategy = &sysctl_intvec,
986 .extra1 = &zero,
988 #endif
989 #ifdef CONFIG_NUMA
991 .ctl_name = VM_ZONE_RECLAIM_MODE,
992 .procname = "zone_reclaim_mode",
993 .data = &zone_reclaim_mode,
994 .maxlen = sizeof(zone_reclaim_mode),
995 .mode = 0644,
996 .proc_handler = &proc_dointvec,
997 .strategy = &sysctl_intvec,
998 .extra1 = &zero,
1001 .ctl_name = VM_MIN_UNMAPPED,
1002 .procname = "min_unmapped_ratio",
1003 .data = &sysctl_min_unmapped_ratio,
1004 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1005 .mode = 0644,
1006 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1007 .strategy = &sysctl_intvec,
1008 .extra1 = &zero,
1009 .extra2 = &one_hundred,
1012 .ctl_name = VM_MIN_SLAB,
1013 .procname = "min_slab_ratio",
1014 .data = &sysctl_min_slab_ratio,
1015 .maxlen = sizeof(sysctl_min_slab_ratio),
1016 .mode = 0644,
1017 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1018 .strategy = &sysctl_intvec,
1019 .extra1 = &zero,
1020 .extra2 = &one_hundred,
1022 #endif
1023 #ifdef CONFIG_X86_32
1025 .ctl_name = VM_VDSO_ENABLED,
1026 .procname = "vdso_enabled",
1027 .data = &vdso_enabled,
1028 .maxlen = sizeof(vdso_enabled),
1029 .mode = 0644,
1030 .proc_handler = &proc_dointvec,
1031 .strategy = &sysctl_intvec,
1032 .extra1 = &zero,
1034 #endif
1035 { .ctl_name = 0 }
1038 static ctl_table fs_table[] = {
1040 .ctl_name = FS_NRINODE,
1041 .procname = "inode-nr",
1042 .data = &inodes_stat,
1043 .maxlen = 2*sizeof(int),
1044 .mode = 0444,
1045 .proc_handler = &proc_dointvec,
1048 .ctl_name = FS_STATINODE,
1049 .procname = "inode-state",
1050 .data = &inodes_stat,
1051 .maxlen = 7*sizeof(int),
1052 .mode = 0444,
1053 .proc_handler = &proc_dointvec,
1056 .ctl_name = FS_NRFILE,
1057 .procname = "file-nr",
1058 .data = &files_stat,
1059 .maxlen = 3*sizeof(int),
1060 .mode = 0444,
1061 .proc_handler = &proc_nr_files,
1064 .ctl_name = FS_MAXFILE,
1065 .procname = "file-max",
1066 .data = &files_stat.max_files,
1067 .maxlen = sizeof(int),
1068 .mode = 0644,
1069 .proc_handler = &proc_dointvec,
1072 .ctl_name = FS_DENTRY,
1073 .procname = "dentry-state",
1074 .data = &dentry_stat,
1075 .maxlen = 6*sizeof(int),
1076 .mode = 0444,
1077 .proc_handler = &proc_dointvec,
1080 .ctl_name = FS_OVERFLOWUID,
1081 .procname = "overflowuid",
1082 .data = &fs_overflowuid,
1083 .maxlen = sizeof(int),
1084 .mode = 0644,
1085 .proc_handler = &proc_dointvec_minmax,
1086 .strategy = &sysctl_intvec,
1087 .extra1 = &minolduid,
1088 .extra2 = &maxolduid,
1091 .ctl_name = FS_OVERFLOWGID,
1092 .procname = "overflowgid",
1093 .data = &fs_overflowgid,
1094 .maxlen = sizeof(int),
1095 .mode = 0644,
1096 .proc_handler = &proc_dointvec_minmax,
1097 .strategy = &sysctl_intvec,
1098 .extra1 = &minolduid,
1099 .extra2 = &maxolduid,
1102 .ctl_name = FS_LEASES,
1103 .procname = "leases-enable",
1104 .data = &leases_enable,
1105 .maxlen = sizeof(int),
1106 .mode = 0644,
1107 .proc_handler = &proc_dointvec,
1109 #ifdef CONFIG_DNOTIFY
1111 .ctl_name = FS_DIR_NOTIFY,
1112 .procname = "dir-notify-enable",
1113 .data = &dir_notify_enable,
1114 .maxlen = sizeof(int),
1115 .mode = 0644,
1116 .proc_handler = &proc_dointvec,
1118 #endif
1119 #ifdef CONFIG_MMU
1121 .ctl_name = FS_LEASE_TIME,
1122 .procname = "lease-break-time",
1123 .data = &lease_break_time,
1124 .maxlen = sizeof(int),
1125 .mode = 0644,
1126 .proc_handler = &proc_dointvec,
1129 .ctl_name = FS_AIO_NR,
1130 .procname = "aio-nr",
1131 .data = &aio_nr,
1132 .maxlen = sizeof(aio_nr),
1133 .mode = 0444,
1134 .proc_handler = &proc_doulongvec_minmax,
1137 .ctl_name = FS_AIO_MAX_NR,
1138 .procname = "aio-max-nr",
1139 .data = &aio_max_nr,
1140 .maxlen = sizeof(aio_max_nr),
1141 .mode = 0644,
1142 .proc_handler = &proc_doulongvec_minmax,
1144 #ifdef CONFIG_INOTIFY_USER
1146 .ctl_name = FS_INOTIFY,
1147 .procname = "inotify",
1148 .mode = 0555,
1149 .child = inotify_table,
1151 #endif
1152 #endif
1154 .ctl_name = KERN_SETUID_DUMPABLE,
1155 .procname = "suid_dumpable",
1156 .data = &suid_dumpable,
1157 .maxlen = sizeof(int),
1158 .mode = 0644,
1159 .proc_handler = &proc_dointvec,
1161 { .ctl_name = 0 }
1164 static ctl_table debug_table[] = {
1165 { .ctl_name = 0 }
1168 static ctl_table dev_table[] = {
1169 { .ctl_name = 0 }
1172 extern void init_irq_proc (void);
1174 static DEFINE_SPINLOCK(sysctl_lock);
1176 /* called under sysctl_lock */
1177 static int use_table(struct ctl_table_header *p)
1179 if (unlikely(p->unregistering))
1180 return 0;
1181 p->used++;
1182 return 1;
1185 /* called under sysctl_lock */
1186 static void unuse_table(struct ctl_table_header *p)
1188 if (!--p->used)
1189 if (unlikely(p->unregistering))
1190 complete(p->unregistering);
1193 /* called under sysctl_lock, will reacquire if has to wait */
1194 static void start_unregistering(struct ctl_table_header *p)
1197 * if p->used is 0, nobody will ever touch that entry again;
1198 * we'll eliminate all paths to it before dropping sysctl_lock
1200 if (unlikely(p->used)) {
1201 struct completion wait;
1202 init_completion(&wait);
1203 p->unregistering = &wait;
1204 spin_unlock(&sysctl_lock);
1205 wait_for_completion(&wait);
1206 spin_lock(&sysctl_lock);
1209 * do not remove from the list until nobody holds it; walking the
1210 * list in do_sysctl() relies on that.
1212 list_del_init(&p->ctl_entry);
1215 void __init sysctl_init(void)
1217 #ifdef CONFIG_PROC_SYSCTL
1218 register_proc_table(root_table, proc_sys_root, &root_table_header);
1219 init_irq_proc();
1220 #endif
1223 #ifdef CONFIG_SYSCTL_SYSCALL
1224 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1225 void __user *newval, size_t newlen)
1227 struct list_head *tmp;
1228 int error = -ENOTDIR;
1230 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1231 return -ENOTDIR;
1232 if (oldval) {
1233 int old_len;
1234 if (!oldlenp || get_user(old_len, oldlenp))
1235 return -EFAULT;
1237 spin_lock(&sysctl_lock);
1238 tmp = &root_table_header.ctl_entry;
1239 do {
1240 struct ctl_table_header *head =
1241 list_entry(tmp, struct ctl_table_header, ctl_entry);
1242 void *context = NULL;
1244 if (!use_table(head))
1245 continue;
1247 spin_unlock(&sysctl_lock);
1249 error = parse_table(name, nlen, oldval, oldlenp,
1250 newval, newlen, head->ctl_table,
1251 &context);
1252 kfree(context);
1254 spin_lock(&sysctl_lock);
1255 unuse_table(head);
1256 if (error != -ENOTDIR)
1257 break;
1258 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1259 spin_unlock(&sysctl_lock);
1260 return error;
1263 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1265 struct __sysctl_args tmp;
1266 int error;
1268 if (copy_from_user(&tmp, args, sizeof(tmp)))
1269 return -EFAULT;
1271 lock_kernel();
1272 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1273 tmp.newval, tmp.newlen);
1274 unlock_kernel();
1275 return error;
1277 #endif /* CONFIG_SYSCTL_SYSCALL */
1280 * ctl_perm does NOT grant the superuser all rights automatically, because
1281 * some sysctl variables are readonly even to root.
1284 static int test_perm(int mode, int op)
1286 if (!current->euid)
1287 mode >>= 6;
1288 else if (in_egroup_p(0))
1289 mode >>= 3;
1290 if ((mode & op & 0007) == op)
1291 return 0;
1292 return -EACCES;
1295 static inline int ctl_perm(ctl_table *table, int op)
1297 int error;
1298 error = security_sysctl(table, op);
1299 if (error)
1300 return error;
1301 return test_perm(table->mode, op);
1304 #ifdef CONFIG_SYSCTL_SYSCALL
1305 static int parse_table(int __user *name, int nlen,
1306 void __user *oldval, size_t __user *oldlenp,
1307 void __user *newval, size_t newlen,
1308 ctl_table *table, void **context)
1310 int n;
1311 repeat:
1312 if (!nlen)
1313 return -ENOTDIR;
1314 if (get_user(n, name))
1315 return -EFAULT;
1316 for ( ; table->ctl_name || table->procname; table++) {
1317 if (!table->ctl_name)
1318 continue;
1319 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1320 int error;
1321 if (table->child) {
1322 if (ctl_perm(table, 001))
1323 return -EPERM;
1324 if (table->strategy) {
1325 error = table->strategy(
1326 table, name, nlen,
1327 oldval, oldlenp,
1328 newval, newlen, context);
1329 if (error)
1330 return error;
1332 name++;
1333 nlen--;
1334 table = table->child;
1335 goto repeat;
1337 error = do_sysctl_strategy(table, name, nlen,
1338 oldval, oldlenp,
1339 newval, newlen, context);
1340 return error;
1343 return -ENOTDIR;
1346 /* Perform the actual read/write of a sysctl table entry. */
1347 int do_sysctl_strategy (ctl_table *table,
1348 int __user *name, int nlen,
1349 void __user *oldval, size_t __user *oldlenp,
1350 void __user *newval, size_t newlen, void **context)
1352 int op = 0, rc;
1353 size_t len;
1355 if (oldval)
1356 op |= 004;
1357 if (newval)
1358 op |= 002;
1359 if (ctl_perm(table, op))
1360 return -EPERM;
1362 if (table->strategy) {
1363 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1364 newval, newlen, context);
1365 if (rc < 0)
1366 return rc;
1367 if (rc > 0)
1368 return 0;
1371 /* If there is no strategy routine, or if the strategy returns
1372 * zero, proceed with automatic r/w */
1373 if (table->data && table->maxlen) {
1374 if (oldval && oldlenp) {
1375 if (get_user(len, oldlenp))
1376 return -EFAULT;
1377 if (len) {
1378 if (len > table->maxlen)
1379 len = table->maxlen;
1380 if(copy_to_user(oldval, table->data, len))
1381 return -EFAULT;
1382 if(put_user(len, oldlenp))
1383 return -EFAULT;
1386 if (newval && newlen) {
1387 len = newlen;
1388 if (len > table->maxlen)
1389 len = table->maxlen;
1390 if(copy_from_user(table->data, newval, len))
1391 return -EFAULT;
1394 return 0;
1396 #endif /* CONFIG_SYSCTL_SYSCALL */
1399 * register_sysctl_table - register a sysctl hierarchy
1400 * @table: the top-level table structure
1401 * @insert_at_head: whether the entry should be inserted in front or at the end
1403 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1404 * array. An entry with a ctl_name of 0 terminates the table.
1406 * The members of the &ctl_table structure are used as follows:
1408 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1409 * must be unique within that level of sysctl
1411 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1412 * enter a sysctl file
1414 * data - a pointer to data for use by proc_handler
1416 * maxlen - the maximum size in bytes of the data
1418 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1420 * child - a pointer to the child sysctl table if this entry is a directory, or
1421 * %NULL.
1423 * proc_handler - the text handler routine (described below)
1425 * strategy - the strategy routine (described below)
1427 * de - for internal use by the sysctl routines
1429 * extra1, extra2 - extra pointers usable by the proc handler routines
1431 * Leaf nodes in the sysctl tree will be represented by a single file
1432 * under /proc; non-leaf nodes will be represented by directories.
1434 * sysctl(2) can automatically manage read and write requests through
1435 * the sysctl table. The data and maxlen fields of the ctl_table
1436 * struct enable minimal validation of the values being written to be
1437 * performed, and the mode field allows minimal authentication.
1439 * More sophisticated management can be enabled by the provision of a
1440 * strategy routine with the table entry. This will be called before
1441 * any automatic read or write of the data is performed.
1443 * The strategy routine may return
1445 * < 0 - Error occurred (error is passed to user process)
1447 * 0 - OK - proceed with automatic read or write.
1449 * > 0 - OK - read or write has been done by the strategy routine, so
1450 * return immediately.
1452 * There must be a proc_handler routine for any terminal nodes
1453 * mirrored under /proc/sys (non-terminals are handled by a built-in
1454 * directory handler). Several default handlers are available to
1455 * cover common cases -
1457 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1458 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1459 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1461 * It is the handler's job to read the input buffer from user memory
1462 * and process it. The handler should return 0 on success.
1464 * This routine returns %NULL on a failure to register, and a pointer
1465 * to the table header on success.
1467 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1468 int insert_at_head)
1470 struct ctl_table_header *tmp;
1471 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1472 if (!tmp)
1473 return NULL;
1474 tmp->ctl_table = table;
1475 INIT_LIST_HEAD(&tmp->ctl_entry);
1476 tmp->used = 0;
1477 tmp->unregistering = NULL;
1478 spin_lock(&sysctl_lock);
1479 if (insert_at_head)
1480 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1481 else
1482 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1483 spin_unlock(&sysctl_lock);
1484 #ifdef CONFIG_PROC_SYSCTL
1485 register_proc_table(table, proc_sys_root, tmp);
1486 #endif
1487 return tmp;
1491 * unregister_sysctl_table - unregister a sysctl table hierarchy
1492 * @header: the header returned from register_sysctl_table
1494 * Unregisters the sysctl table and all children. proc entries may not
1495 * actually be removed until they are no longer used by anyone.
1497 void unregister_sysctl_table(struct ctl_table_header * header)
1499 might_sleep();
1500 spin_lock(&sysctl_lock);
1501 start_unregistering(header);
1502 #ifdef CONFIG_PROC_SYSCTL
1503 unregister_proc_table(header->ctl_table, proc_sys_root);
1504 #endif
1505 spin_unlock(&sysctl_lock);
1506 kfree(header);
1509 #else /* !CONFIG_SYSCTL */
1510 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1511 int insert_at_head)
1513 return NULL;
1516 void unregister_sysctl_table(struct ctl_table_header * table)
1520 #endif /* CONFIG_SYSCTL */
1523 * /proc/sys support
1526 #ifdef CONFIG_PROC_SYSCTL
1528 /* Scan the sysctl entries in table and add them all into /proc */
1529 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1531 struct proc_dir_entry *de;
1532 int len;
1533 mode_t mode;
1535 for (; table->ctl_name || table->procname; table++) {
1536 /* Can't do anything without a proc name. */
1537 if (!table->procname)
1538 continue;
1539 /* Maybe we can't do anything with it... */
1540 if (!table->proc_handler && !table->child) {
1541 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1542 table->procname);
1543 continue;
1546 len = strlen(table->procname);
1547 mode = table->mode;
1549 de = NULL;
1550 if (table->proc_handler)
1551 mode |= S_IFREG;
1552 else {
1553 mode |= S_IFDIR;
1554 for (de = root->subdir; de; de = de->next) {
1555 if (proc_match(len, table->procname, de))
1556 break;
1558 /* If the subdir exists already, de is non-NULL */
1561 if (!de) {
1562 de = create_proc_entry(table->procname, mode, root);
1563 if (!de)
1564 continue;
1565 de->set = set;
1566 de->data = (void *) table;
1567 if (table->proc_handler)
1568 de->proc_fops = &proc_sys_file_operations;
1570 table->de = de;
1571 if (de->mode & S_IFDIR)
1572 register_proc_table(table->child, de, set);
1577 * Unregister a /proc sysctl table and any subdirectories.
1579 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1581 struct proc_dir_entry *de;
1582 for (; table->ctl_name || table->procname; table++) {
1583 if (!(de = table->de))
1584 continue;
1585 if (de->mode & S_IFDIR) {
1586 if (!table->child) {
1587 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1588 continue;
1590 unregister_proc_table(table->child, de);
1592 /* Don't unregister directories which still have entries.. */
1593 if (de->subdir)
1594 continue;
1598 * In any case, mark the entry as goner; we'll keep it
1599 * around if it's busy, but we'll know to do nothing with
1600 * its fields. We are under sysctl_lock here.
1602 de->data = NULL;
1604 /* Don't unregister proc entries that are still being used.. */
1605 if (atomic_read(&de->count))
1606 continue;
1608 table->de = NULL;
1609 remove_proc_entry(table->procname, root);
1613 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1614 size_t count, loff_t *ppos)
1616 int op;
1617 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
1618 struct ctl_table *table;
1619 size_t res;
1620 ssize_t error = -ENOTDIR;
1622 spin_lock(&sysctl_lock);
1623 if (de && de->data && use_table(de->set)) {
1625 * at that point we know that sysctl was not unregistered
1626 * and won't be until we finish
1628 spin_unlock(&sysctl_lock);
1629 table = (struct ctl_table *) de->data;
1630 if (!table || !table->proc_handler)
1631 goto out;
1632 error = -EPERM;
1633 op = (write ? 002 : 004);
1634 if (ctl_perm(table, op))
1635 goto out;
1637 /* careful: calling conventions are nasty here */
1638 res = count;
1639 error = (*table->proc_handler)(table, write, file,
1640 buf, &res, ppos);
1641 if (!error)
1642 error = res;
1643 out:
1644 spin_lock(&sysctl_lock);
1645 unuse_table(de->set);
1647 spin_unlock(&sysctl_lock);
1648 return error;
1651 static int proc_opensys(struct inode *inode, struct file *file)
1653 if (file->f_mode & FMODE_WRITE) {
1655 * sysctl entries that are not writable,
1656 * are _NOT_ writable, capabilities or not.
1658 if (!(inode->i_mode & S_IWUSR))
1659 return -EPERM;
1662 return 0;
1665 static ssize_t proc_readsys(struct file * file, char __user * buf,
1666 size_t count, loff_t *ppos)
1668 return do_rw_proc(0, file, buf, count, ppos);
1671 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1672 size_t count, loff_t *ppos)
1674 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1677 static int _proc_do_string(void* data, int maxlen, int write,
1678 struct file *filp, void __user *buffer,
1679 size_t *lenp, loff_t *ppos)
1681 size_t len;
1682 char __user *p;
1683 char c;
1685 if (!data || !maxlen || !*lenp ||
1686 (*ppos && !write)) {
1687 *lenp = 0;
1688 return 0;
1691 if (write) {
1692 len = 0;
1693 p = buffer;
1694 while (len < *lenp) {
1695 if (get_user(c, p++))
1696 return -EFAULT;
1697 if (c == 0 || c == '\n')
1698 break;
1699 len++;
1701 if (len >= maxlen)
1702 len = maxlen-1;
1703 if(copy_from_user(data, buffer, len))
1704 return -EFAULT;
1705 ((char *) data)[len] = 0;
1706 *ppos += *lenp;
1707 } else {
1708 len = strlen(data);
1709 if (len > maxlen)
1710 len = maxlen;
1711 if (len > *lenp)
1712 len = *lenp;
1713 if (len)
1714 if(copy_to_user(buffer, data, len))
1715 return -EFAULT;
1716 if (len < *lenp) {
1717 if(put_user('\n', ((char __user *) buffer) + len))
1718 return -EFAULT;
1719 len++;
1721 *lenp = len;
1722 *ppos += len;
1724 return 0;
1728 * proc_dostring - read a string sysctl
1729 * @table: the sysctl table
1730 * @write: %TRUE if this is a write to the sysctl file
1731 * @filp: the file structure
1732 * @buffer: the user buffer
1733 * @lenp: the size of the user buffer
1734 * @ppos: file position
1736 * Reads/writes a string from/to the user buffer. If the kernel
1737 * buffer provided is not large enough to hold the string, the
1738 * string is truncated. The copied string is %NULL-terminated.
1739 * If the string is being read by the user process, it is copied
1740 * and a newline '\n' is added. It is truncated if the buffer is
1741 * not large enough.
1743 * Returns 0 on success.
1745 int proc_dostring(ctl_table *table, int write, struct file *filp,
1746 void __user *buffer, size_t *lenp, loff_t *ppos)
1748 return _proc_do_string(table->data, table->maxlen, write, filp,
1749 buffer, lenp, ppos);
1753 * Special case of dostring for the UTS structure. This has locks
1754 * to observe. Should this be in kernel/sys.c ????
1757 #ifndef CONFIG_UTS_NS
1758 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1759 void __user *buffer, size_t *lenp, loff_t *ppos)
1761 int r;
1763 if (!write) {
1764 down_read(&uts_sem);
1765 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1766 up_read(&uts_sem);
1767 } else {
1768 down_write(&uts_sem);
1769 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1770 up_write(&uts_sem);
1772 return r;
1774 #else /* !CONFIG_UTS_NS */
1775 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1776 void __user *buffer, size_t *lenp, loff_t *ppos)
1778 int r;
1779 struct uts_namespace* uts_ns = current->nsproxy->uts_ns;
1780 char* which;
1782 switch (table->ctl_name) {
1783 case KERN_OSTYPE:
1784 which = uts_ns->name.sysname;
1785 break;
1786 case KERN_NODENAME:
1787 which = uts_ns->name.nodename;
1788 break;
1789 case KERN_OSRELEASE:
1790 which = uts_ns->name.release;
1791 break;
1792 case KERN_VERSION:
1793 which = uts_ns->name.version;
1794 break;
1795 case KERN_DOMAINNAME:
1796 which = uts_ns->name.domainname;
1797 break;
1798 default:
1799 r = -EINVAL;
1800 goto out;
1803 if (!write) {
1804 down_read(&uts_sem);
1805 r=_proc_do_string(which,table->maxlen,0,filp,buffer,lenp, ppos);
1806 up_read(&uts_sem);
1807 } else {
1808 down_write(&uts_sem);
1809 r=_proc_do_string(which,table->maxlen,1,filp,buffer,lenp, ppos);
1810 up_write(&uts_sem);
1812 out:
1813 return r;
1815 #endif /* !CONFIG_UTS_NS */
1817 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1818 int *valp,
1819 int write, void *data)
1821 if (write) {
1822 *valp = *negp ? -*lvalp : *lvalp;
1823 } else {
1824 int val = *valp;
1825 if (val < 0) {
1826 *negp = -1;
1827 *lvalp = (unsigned long)-val;
1828 } else {
1829 *negp = 0;
1830 *lvalp = (unsigned long)val;
1833 return 0;
1836 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1837 int write, struct file *filp, void __user *buffer,
1838 size_t *lenp, loff_t *ppos,
1839 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1840 int write, void *data),
1841 void *data)
1843 #define TMPBUFLEN 21
1844 int *i, vleft, first=1, neg, val;
1845 unsigned long lval;
1846 size_t left, len;
1848 char buf[TMPBUFLEN], *p;
1849 char __user *s = buffer;
1851 if (!tbl_data || !table->maxlen || !*lenp ||
1852 (*ppos && !write)) {
1853 *lenp = 0;
1854 return 0;
1857 i = (int *) tbl_data;
1858 vleft = table->maxlen / sizeof(*i);
1859 left = *lenp;
1861 if (!conv)
1862 conv = do_proc_dointvec_conv;
1864 for (; left && vleft--; i++, first=0) {
1865 if (write) {
1866 while (left) {
1867 char c;
1868 if (get_user(c, s))
1869 return -EFAULT;
1870 if (!isspace(c))
1871 break;
1872 left--;
1873 s++;
1875 if (!left)
1876 break;
1877 neg = 0;
1878 len = left;
1879 if (len > sizeof(buf) - 1)
1880 len = sizeof(buf) - 1;
1881 if (copy_from_user(buf, s, len))
1882 return -EFAULT;
1883 buf[len] = 0;
1884 p = buf;
1885 if (*p == '-' && left > 1) {
1886 neg = 1;
1887 p++;
1889 if (*p < '0' || *p > '9')
1890 break;
1892 lval = simple_strtoul(p, &p, 0);
1894 len = p-buf;
1895 if ((len < left) && *p && !isspace(*p))
1896 break;
1897 if (neg)
1898 val = -val;
1899 s += len;
1900 left -= len;
1902 if (conv(&neg, &lval, i, 1, data))
1903 break;
1904 } else {
1905 p = buf;
1906 if (!first)
1907 *p++ = '\t';
1909 if (conv(&neg, &lval, i, 0, data))
1910 break;
1912 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1913 len = strlen(buf);
1914 if (len > left)
1915 len = left;
1916 if(copy_to_user(s, buf, len))
1917 return -EFAULT;
1918 left -= len;
1919 s += len;
1923 if (!write && !first && left) {
1924 if(put_user('\n', s))
1925 return -EFAULT;
1926 left--, s++;
1928 if (write) {
1929 while (left) {
1930 char c;
1931 if (get_user(c, s++))
1932 return -EFAULT;
1933 if (!isspace(c))
1934 break;
1935 left--;
1938 if (write && first)
1939 return -EINVAL;
1940 *lenp -= left;
1941 *ppos += *lenp;
1942 return 0;
1943 #undef TMPBUFLEN
1946 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1947 void __user *buffer, size_t *lenp, loff_t *ppos,
1948 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1949 int write, void *data),
1950 void *data)
1952 return __do_proc_dointvec(table->data, table, write, filp,
1953 buffer, lenp, ppos, conv, data);
1957 * proc_dointvec - read a vector of integers
1958 * @table: the sysctl table
1959 * @write: %TRUE if this is a write to the sysctl file
1960 * @filp: the file structure
1961 * @buffer: the user buffer
1962 * @lenp: the size of the user buffer
1963 * @ppos: file position
1965 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1966 * values from/to the user buffer, treated as an ASCII string.
1968 * Returns 0 on success.
1970 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1971 void __user *buffer, size_t *lenp, loff_t *ppos)
1973 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1974 NULL,NULL);
1977 #define OP_SET 0
1978 #define OP_AND 1
1979 #define OP_OR 2
1980 #define OP_MAX 3
1981 #define OP_MIN 4
1983 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1984 int *valp,
1985 int write, void *data)
1987 int op = *(int *)data;
1988 if (write) {
1989 int val = *negp ? -*lvalp : *lvalp;
1990 switch(op) {
1991 case OP_SET: *valp = val; break;
1992 case OP_AND: *valp &= val; break;
1993 case OP_OR: *valp |= val; break;
1994 case OP_MAX: if(*valp < val)
1995 *valp = val;
1996 break;
1997 case OP_MIN: if(*valp > val)
1998 *valp = val;
1999 break;
2001 } else {
2002 int val = *valp;
2003 if (val < 0) {
2004 *negp = -1;
2005 *lvalp = (unsigned long)-val;
2006 } else {
2007 *negp = 0;
2008 *lvalp = (unsigned long)val;
2011 return 0;
2015 * init may raise the set.
2018 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2019 void __user *buffer, size_t *lenp, loff_t *ppos)
2021 int op;
2023 if (!capable(CAP_SYS_MODULE)) {
2024 return -EPERM;
2027 op = is_init(current) ? OP_SET : OP_AND;
2028 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2029 do_proc_dointvec_bset_conv,&op);
2032 struct do_proc_dointvec_minmax_conv_param {
2033 int *min;
2034 int *max;
2037 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2038 int *valp,
2039 int write, void *data)
2041 struct do_proc_dointvec_minmax_conv_param *param = data;
2042 if (write) {
2043 int val = *negp ? -*lvalp : *lvalp;
2044 if ((param->min && *param->min > val) ||
2045 (param->max && *param->max < val))
2046 return -EINVAL;
2047 *valp = val;
2048 } else {
2049 int val = *valp;
2050 if (val < 0) {
2051 *negp = -1;
2052 *lvalp = (unsigned long)-val;
2053 } else {
2054 *negp = 0;
2055 *lvalp = (unsigned long)val;
2058 return 0;
2062 * proc_dointvec_minmax - read a vector of integers with min/max values
2063 * @table: the sysctl table
2064 * @write: %TRUE if this is a write to the sysctl file
2065 * @filp: the file structure
2066 * @buffer: the user buffer
2067 * @lenp: the size of the user buffer
2068 * @ppos: file position
2070 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2071 * values from/to the user buffer, treated as an ASCII string.
2073 * This routine will ensure the values are within the range specified by
2074 * table->extra1 (min) and table->extra2 (max).
2076 * Returns 0 on success.
2078 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2079 void __user *buffer, size_t *lenp, loff_t *ppos)
2081 struct do_proc_dointvec_minmax_conv_param param = {
2082 .min = (int *) table->extra1,
2083 .max = (int *) table->extra2,
2085 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2086 do_proc_dointvec_minmax_conv, &param);
2089 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2090 struct file *filp,
2091 void __user *buffer,
2092 size_t *lenp, loff_t *ppos,
2093 unsigned long convmul,
2094 unsigned long convdiv)
2096 #define TMPBUFLEN 21
2097 unsigned long *i, *min, *max, val;
2098 int vleft, first=1, neg;
2099 size_t len, left;
2100 char buf[TMPBUFLEN], *p;
2101 char __user *s = buffer;
2103 if (!data || !table->maxlen || !*lenp ||
2104 (*ppos && !write)) {
2105 *lenp = 0;
2106 return 0;
2109 i = (unsigned long *) data;
2110 min = (unsigned long *) table->extra1;
2111 max = (unsigned long *) table->extra2;
2112 vleft = table->maxlen / sizeof(unsigned long);
2113 left = *lenp;
2115 for (; left && vleft--; i++, min++, max++, first=0) {
2116 if (write) {
2117 while (left) {
2118 char c;
2119 if (get_user(c, s))
2120 return -EFAULT;
2121 if (!isspace(c))
2122 break;
2123 left--;
2124 s++;
2126 if (!left)
2127 break;
2128 neg = 0;
2129 len = left;
2130 if (len > TMPBUFLEN-1)
2131 len = TMPBUFLEN-1;
2132 if (copy_from_user(buf, s, len))
2133 return -EFAULT;
2134 buf[len] = 0;
2135 p = buf;
2136 if (*p == '-' && left > 1) {
2137 neg = 1;
2138 p++;
2140 if (*p < '0' || *p > '9')
2141 break;
2142 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2143 len = p-buf;
2144 if ((len < left) && *p && !isspace(*p))
2145 break;
2146 if (neg)
2147 val = -val;
2148 s += len;
2149 left -= len;
2151 if(neg)
2152 continue;
2153 if ((min && val < *min) || (max && val > *max))
2154 continue;
2155 *i = val;
2156 } else {
2157 p = buf;
2158 if (!first)
2159 *p++ = '\t';
2160 sprintf(p, "%lu", convdiv * (*i) / convmul);
2161 len = strlen(buf);
2162 if (len > left)
2163 len = left;
2164 if(copy_to_user(s, buf, len))
2165 return -EFAULT;
2166 left -= len;
2167 s += len;
2171 if (!write && !first && left) {
2172 if(put_user('\n', s))
2173 return -EFAULT;
2174 left--, s++;
2176 if (write) {
2177 while (left) {
2178 char c;
2179 if (get_user(c, s++))
2180 return -EFAULT;
2181 if (!isspace(c))
2182 break;
2183 left--;
2186 if (write && first)
2187 return -EINVAL;
2188 *lenp -= left;
2189 *ppos += *lenp;
2190 return 0;
2191 #undef TMPBUFLEN
2194 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2195 struct file *filp,
2196 void __user *buffer,
2197 size_t *lenp, loff_t *ppos,
2198 unsigned long convmul,
2199 unsigned long convdiv)
2201 return __do_proc_doulongvec_minmax(table->data, table, write,
2202 filp, buffer, lenp, ppos, convmul, convdiv);
2206 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2207 * @table: the sysctl table
2208 * @write: %TRUE if this is a write to the sysctl file
2209 * @filp: the file structure
2210 * @buffer: the user buffer
2211 * @lenp: the size of the user buffer
2212 * @ppos: file position
2214 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2215 * values from/to the user buffer, treated as an ASCII string.
2217 * This routine will ensure the values are within the range specified by
2218 * table->extra1 (min) and table->extra2 (max).
2220 * Returns 0 on success.
2222 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2223 void __user *buffer, size_t *lenp, loff_t *ppos)
2225 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2229 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2230 * @table: the sysctl table
2231 * @write: %TRUE if this is a write to the sysctl file
2232 * @filp: the file structure
2233 * @buffer: the user buffer
2234 * @lenp: the size of the user buffer
2235 * @ppos: file position
2237 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2238 * values from/to the user buffer, treated as an ASCII string. The values
2239 * are treated as milliseconds, and converted to jiffies when they are stored.
2241 * This routine will ensure the values are within the range specified by
2242 * table->extra1 (min) and table->extra2 (max).
2244 * Returns 0 on success.
2246 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2247 struct file *filp,
2248 void __user *buffer,
2249 size_t *lenp, loff_t *ppos)
2251 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2252 lenp, ppos, HZ, 1000l);
2256 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2257 int *valp,
2258 int write, void *data)
2260 if (write) {
2261 if (*lvalp > LONG_MAX / HZ)
2262 return 1;
2263 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2264 } else {
2265 int val = *valp;
2266 unsigned long lval;
2267 if (val < 0) {
2268 *negp = -1;
2269 lval = (unsigned long)-val;
2270 } else {
2271 *negp = 0;
2272 lval = (unsigned long)val;
2274 *lvalp = lval / HZ;
2276 return 0;
2279 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2280 int *valp,
2281 int write, void *data)
2283 if (write) {
2284 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2285 return 1;
2286 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2287 } else {
2288 int val = *valp;
2289 unsigned long lval;
2290 if (val < 0) {
2291 *negp = -1;
2292 lval = (unsigned long)-val;
2293 } else {
2294 *negp = 0;
2295 lval = (unsigned long)val;
2297 *lvalp = jiffies_to_clock_t(lval);
2299 return 0;
2302 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2303 int *valp,
2304 int write, void *data)
2306 if (write) {
2307 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2308 } else {
2309 int val = *valp;
2310 unsigned long lval;
2311 if (val < 0) {
2312 *negp = -1;
2313 lval = (unsigned long)-val;
2314 } else {
2315 *negp = 0;
2316 lval = (unsigned long)val;
2318 *lvalp = jiffies_to_msecs(lval);
2320 return 0;
2324 * proc_dointvec_jiffies - read a vector of integers as seconds
2325 * @table: the sysctl table
2326 * @write: %TRUE if this is a write to the sysctl file
2327 * @filp: the file structure
2328 * @buffer: the user buffer
2329 * @lenp: the size of the user buffer
2330 * @ppos: file position
2332 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2333 * values from/to the user buffer, treated as an ASCII string.
2334 * The values read are assumed to be in seconds, and are converted into
2335 * jiffies.
2337 * Returns 0 on success.
2339 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2340 void __user *buffer, size_t *lenp, loff_t *ppos)
2342 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2343 do_proc_dointvec_jiffies_conv,NULL);
2347 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2348 * @table: the sysctl table
2349 * @write: %TRUE if this is a write to the sysctl file
2350 * @filp: the file structure
2351 * @buffer: the user buffer
2352 * @lenp: the size of the user buffer
2353 * @ppos: pointer to the file position
2355 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2356 * values from/to the user buffer, treated as an ASCII string.
2357 * The values read are assumed to be in 1/USER_HZ seconds, and
2358 * are converted into jiffies.
2360 * Returns 0 on success.
2362 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2363 void __user *buffer, size_t *lenp, loff_t *ppos)
2365 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2366 do_proc_dointvec_userhz_jiffies_conv,NULL);
2370 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2371 * @table: the sysctl table
2372 * @write: %TRUE if this is a write to the sysctl file
2373 * @filp: the file structure
2374 * @buffer: the user buffer
2375 * @lenp: the size of the user buffer
2376 * @ppos: file position
2377 * @ppos: the current position in the file
2379 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2380 * values from/to the user buffer, treated as an ASCII string.
2381 * The values read are assumed to be in 1/1000 seconds, and
2382 * are converted into jiffies.
2384 * Returns 0 on success.
2386 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2387 void __user *buffer, size_t *lenp, loff_t *ppos)
2389 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2390 do_proc_dointvec_ms_jiffies_conv, NULL);
2393 #ifdef CONFIG_SYSVIPC
2394 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2395 void __user *buffer, size_t *lenp, loff_t *ppos)
2397 void *data;
2398 struct ipc_namespace *ns;
2400 ns = current->nsproxy->ipc_ns;
2402 switch (table->ctl_name) {
2403 case KERN_SHMMAX:
2404 data = &ns->shm_ctlmax;
2405 goto proc_minmax;
2406 case KERN_SHMALL:
2407 data = &ns->shm_ctlall;
2408 goto proc_minmax;
2409 case KERN_SHMMNI:
2410 data = &ns->shm_ctlmni;
2411 break;
2412 case KERN_MSGMAX:
2413 data = &ns->msg_ctlmax;
2414 break;
2415 case KERN_MSGMNI:
2416 data = &ns->msg_ctlmni;
2417 break;
2418 case KERN_MSGMNB:
2419 data = &ns->msg_ctlmnb;
2420 break;
2421 case KERN_SEM:
2422 data = &ns->sem_ctls;
2423 break;
2424 default:
2425 return -EINVAL;
2428 return __do_proc_dointvec(data, table, write, filp, buffer,
2429 lenp, ppos, NULL, NULL);
2430 proc_minmax:
2431 return __do_proc_doulongvec_minmax(data, table, write, filp, buffer,
2432 lenp, ppos, 1l, 1l);
2434 #endif
2436 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2437 void __user *buffer, size_t *lenp, loff_t *ppos)
2439 struct pid *new_pid;
2440 pid_t tmp;
2441 int r;
2443 tmp = pid_nr(cad_pid);
2445 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2446 lenp, ppos, NULL, NULL);
2447 if (r || !write)
2448 return r;
2450 new_pid = find_get_pid(tmp);
2451 if (!new_pid)
2452 return -ESRCH;
2454 put_pid(xchg(&cad_pid, new_pid));
2455 return 0;
2458 #else /* CONFIG_PROC_FS */
2460 int proc_dostring(ctl_table *table, int write, struct file *filp,
2461 void __user *buffer, size_t *lenp, loff_t *ppos)
2463 return -ENOSYS;
2466 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2467 void __user *buffer, size_t *lenp, loff_t *ppos)
2469 return -ENOSYS;
2472 #ifdef CONFIG_SYSVIPC
2473 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2474 void __user *buffer, size_t *lenp, loff_t *ppos)
2476 return -ENOSYS;
2478 #endif
2480 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2481 void __user *buffer, size_t *lenp, loff_t *ppos)
2483 return -ENOSYS;
2486 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2487 void __user *buffer, size_t *lenp, loff_t *ppos)
2489 return -ENOSYS;
2492 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2493 void __user *buffer, size_t *lenp, loff_t *ppos)
2495 return -ENOSYS;
2498 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2499 void __user *buffer, size_t *lenp, loff_t *ppos)
2501 return -ENOSYS;
2504 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2505 void __user *buffer, size_t *lenp, loff_t *ppos)
2507 return -ENOSYS;
2510 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2511 void __user *buffer, size_t *lenp, loff_t *ppos)
2513 return -ENOSYS;
2516 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2517 void __user *buffer, size_t *lenp, loff_t *ppos)
2519 return -ENOSYS;
2522 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2523 struct file *filp,
2524 void __user *buffer,
2525 size_t *lenp, loff_t *ppos)
2527 return -ENOSYS;
2531 #endif /* CONFIG_PROC_FS */
2534 #ifdef CONFIG_SYSCTL_SYSCALL
2536 * General sysctl support routines
2539 /* The generic string strategy routine: */
2540 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2541 void __user *oldval, size_t __user *oldlenp,
2542 void __user *newval, size_t newlen, void **context)
2544 if (!table->data || !table->maxlen)
2545 return -ENOTDIR;
2547 if (oldval && oldlenp) {
2548 size_t bufsize;
2549 if (get_user(bufsize, oldlenp))
2550 return -EFAULT;
2551 if (bufsize) {
2552 size_t len = strlen(table->data), copied;
2554 /* This shouldn't trigger for a well-formed sysctl */
2555 if (len > table->maxlen)
2556 len = table->maxlen;
2558 /* Copy up to a max of bufsize-1 bytes of the string */
2559 copied = (len >= bufsize) ? bufsize - 1 : len;
2561 if (copy_to_user(oldval, table->data, copied) ||
2562 put_user(0, (char __user *)(oldval + copied)))
2563 return -EFAULT;
2564 if (put_user(len, oldlenp))
2565 return -EFAULT;
2568 if (newval && newlen) {
2569 size_t len = newlen;
2570 if (len > table->maxlen)
2571 len = table->maxlen;
2572 if(copy_from_user(table->data, newval, len))
2573 return -EFAULT;
2574 if (len == table->maxlen)
2575 len--;
2576 ((char *) table->data)[len] = 0;
2578 return 1;
2582 * This function makes sure that all of the integers in the vector
2583 * are between the minimum and maximum values given in the arrays
2584 * table->extra1 and table->extra2, respectively.
2586 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2587 void __user *oldval, size_t __user *oldlenp,
2588 void __user *newval, size_t newlen, void **context)
2591 if (newval && newlen) {
2592 int __user *vec = (int __user *) newval;
2593 int *min = (int *) table->extra1;
2594 int *max = (int *) table->extra2;
2595 size_t length;
2596 int i;
2598 if (newlen % sizeof(int) != 0)
2599 return -EINVAL;
2601 if (!table->extra1 && !table->extra2)
2602 return 0;
2604 if (newlen > table->maxlen)
2605 newlen = table->maxlen;
2606 length = newlen / sizeof(int);
2608 for (i = 0; i < length; i++) {
2609 int value;
2610 if (get_user(value, vec + i))
2611 return -EFAULT;
2612 if (min && value < min[i])
2613 return -EINVAL;
2614 if (max && value > max[i])
2615 return -EINVAL;
2618 return 0;
2621 /* Strategy function to convert jiffies to seconds */
2622 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2623 void __user *oldval, size_t __user *oldlenp,
2624 void __user *newval, size_t newlen, void **context)
2626 if (oldval) {
2627 size_t olen;
2628 if (oldlenp) {
2629 if (get_user(olen, oldlenp))
2630 return -EFAULT;
2631 if (olen!=sizeof(int))
2632 return -EINVAL;
2634 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2635 (oldlenp && put_user(sizeof(int),oldlenp)))
2636 return -EFAULT;
2638 if (newval && newlen) {
2639 int new;
2640 if (newlen != sizeof(int))
2641 return -EINVAL;
2642 if (get_user(new, (int __user *)newval))
2643 return -EFAULT;
2644 *(int *)(table->data) = new*HZ;
2646 return 1;
2649 /* Strategy function to convert jiffies to seconds */
2650 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2651 void __user *oldval, size_t __user *oldlenp,
2652 void __user *newval, size_t newlen, void **context)
2654 if (oldval) {
2655 size_t olen;
2656 if (oldlenp) {
2657 if (get_user(olen, oldlenp))
2658 return -EFAULT;
2659 if (olen!=sizeof(int))
2660 return -EINVAL;
2662 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2663 (oldlenp && put_user(sizeof(int),oldlenp)))
2664 return -EFAULT;
2666 if (newval && newlen) {
2667 int new;
2668 if (newlen != sizeof(int))
2669 return -EINVAL;
2670 if (get_user(new, (int __user *)newval))
2671 return -EFAULT;
2672 *(int *)(table->data) = msecs_to_jiffies(new);
2674 return 1;
2677 #else /* CONFIG_SYSCTL_SYSCALL */
2680 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2682 static int msg_count;
2683 struct __sysctl_args tmp;
2684 int name[CTL_MAXNAME];
2685 int i;
2687 /* Read in the sysctl name for better debug message logging */
2688 if (copy_from_user(&tmp, args, sizeof(tmp)))
2689 return -EFAULT;
2690 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2691 return -ENOTDIR;
2692 for (i = 0; i < tmp.nlen; i++)
2693 if (get_user(name[i], tmp.name + i))
2694 return -EFAULT;
2696 /* Ignore accesses to kernel.version */
2697 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2698 goto out;
2700 if (msg_count < 5) {
2701 msg_count++;
2702 printk(KERN_INFO
2703 "warning: process `%s' used the removed sysctl "
2704 "system call with ", current->comm);
2705 for (i = 0; i < tmp.nlen; i++)
2706 printk("%d.", name[i]);
2707 printk("\n");
2709 out:
2710 return -ENOSYS;
2713 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2714 void __user *oldval, size_t __user *oldlenp,
2715 void __user *newval, size_t newlen, void **context)
2717 return -ENOSYS;
2720 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2721 void __user *oldval, size_t __user *oldlenp,
2722 void __user *newval, size_t newlen, void **context)
2724 return -ENOSYS;
2727 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2728 void __user *oldval, size_t __user *oldlenp,
2729 void __user *newval, size_t newlen, void **context)
2731 return -ENOSYS;
2734 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2735 void __user *oldval, size_t __user *oldlenp,
2736 void __user *newval, size_t newlen, void **context)
2738 return -ENOSYS;
2741 #endif /* CONFIG_SYSCTL_SYSCALL */
2744 * No sense putting this after each symbol definition, twice,
2745 * exception granted :-)
2747 EXPORT_SYMBOL(proc_dointvec);
2748 EXPORT_SYMBOL(proc_dointvec_jiffies);
2749 EXPORT_SYMBOL(proc_dointvec_minmax);
2750 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2751 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2752 EXPORT_SYMBOL(proc_dostring);
2753 EXPORT_SYMBOL(proc_doulongvec_minmax);
2754 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2755 EXPORT_SYMBOL(register_sysctl_table);
2756 EXPORT_SYMBOL(sysctl_intvec);
2757 EXPORT_SYMBOL(sysctl_jiffies);
2758 EXPORT_SYMBOL(sysctl_ms_jiffies);
2759 EXPORT_SYMBOL(sysctl_string);
2760 EXPORT_SYMBOL(unregister_sysctl_table);