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
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
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>
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>
48 #include <linux/vserver/cvirt.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
53 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
54 void __user *buffer, size_t *lenp, loff_t *ppos);
56 #if defined(CONFIG_SYSCTL)
58 /* External variables not in a header file. */
60 extern int sysctl_overcommit_memory;
61 extern int sysctl_overcommit_ratio;
62 extern int sysctl_panic_on_oom;
63 extern int max_threads;
64 extern int sysrq_enabled;
65 extern int core_uses_pid;
66 extern int suid_dumpable;
67 extern char core_pattern[];
70 extern int min_free_kbytes;
71 extern int printk_ratelimit_jiffies;
72 extern int printk_ratelimit_burst;
73 extern int pid_max_min, pid_max_max;
74 extern int sysctl_drop_caches;
75 extern int percpu_pagelist_fraction;
76 extern int compat_log;
78 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
79 int unknown_nmi_panic;
80 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
81 void __user *, size_t *, loff_t *);
84 extern unsigned int vdso_enabled, vdso_populate;
86 int exec_shield = (1<<0);
87 /* exec_shield is a bitmask:
88 0: off; vdso at STACK_TOP, 1 page below TASK_SIZE
89 (1<<0) 1: on [also on if !=0]
90 (1<<1) 2: force noexecstack regardless of PT_GNU_STACK
92 (1<<2) 4: vdso just below .text of main (unless too low)
93 (1<<3) 8: vdso just below .text of PT_INTERP (unless too low)
94 are ignored because the vdso is placed completely randomly
97 static int __init setup_exec_shield(char *str)
99 get_option (&str, &exec_shield);
104 __setup("exec-shield=", setup_exec_shield);
106 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107 static int maxolduid = 65535;
108 static int minolduid;
109 static int min_percpu_pagelist_fract = 8;
111 static int ngroups_max = NGROUPS_MAX;
114 extern char modprobe_path[];
116 extern char vshelper_path[];
117 #ifdef CONFIG_CHR_DEV_SG
118 extern int sg_big_buff;
120 #ifdef CONFIG_SYSVIPC
121 extern size_t shm_ctlmax;
122 extern size_t shm_ctlall;
123 extern int shm_ctlmni;
124 extern int msg_ctlmax;
125 extern int msg_ctlmnb;
126 extern int msg_ctlmni;
127 extern int sem_ctls[];
131 extern char reboot_command [];
132 extern int stop_a_enabled;
133 extern int scons_pwroff;
137 extern int pwrsw_enabled;
138 extern int unaligned_enabled;
142 #ifdef CONFIG_MATHEMU
143 extern int sysctl_ieee_emulation_warnings;
145 extern int sysctl_userprocess_debug;
146 extern int spin_retry;
149 extern int sysctl_hz_timer;
151 #ifdef CONFIG_BSD_PROCESS_ACCT
152 extern int acct_parm[];
156 extern int no_unaligned_warning;
159 #ifdef CONFIG_RT_MUTEXES
160 extern int max_lock_depth;
163 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
164 ctl_table *, void **);
165 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
166 void __user *buffer, size_t *lenp, loff_t *ppos);
168 static ctl_table root_table[];
169 static struct ctl_table_header root_table_header =
170 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
172 static ctl_table kern_table[];
173 static ctl_table vm_table[];
174 static ctl_table fs_table[];
175 static ctl_table debug_table[];
176 static ctl_table dev_table[];
177 extern ctl_table random_table[];
178 #ifdef CONFIG_UNIX98_PTYS
179 extern ctl_table pty_table[];
181 #ifdef CONFIG_INOTIFY_USER
182 extern ctl_table inotify_table[];
185 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
186 int sysctl_legacy_va_layout;
189 /* /proc declarations: */
191 #ifdef CONFIG_PROC_FS
193 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
194 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
195 static int proc_opensys(struct inode *, struct file *);
197 struct file_operations proc_sys_file_operations = {
198 .open = proc_opensys,
199 .read = proc_readsys,
200 .write = proc_writesys,
203 extern struct proc_dir_entry *proc_sys_root;
205 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
206 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
209 /* The default sysctl tables: */
211 static ctl_table root_table[] = {
213 .ctl_name = CTL_KERN,
214 .procname = "kernel",
239 .ctl_name = CTL_DEBUG,
242 .child = debug_table,
254 static ctl_table kern_table[] = {
256 .ctl_name = KERN_OSTYPE,
257 .procname = "ostype",
258 .data = system_utsname.sysname,
259 .maxlen = sizeof(system_utsname.sysname),
261 .proc_handler = &proc_doutsstring,
262 .virt_handler = &vx_uts_virt_handler,
263 .strategy = &sysctl_string,
266 .ctl_name = KERN_OSRELEASE,
267 .procname = "osrelease",
268 .data = system_utsname.release,
269 .maxlen = sizeof(system_utsname.release),
271 .proc_handler = &proc_doutsstring,
272 .virt_handler = &vx_uts_virt_handler,
273 .strategy = &sysctl_string,
276 .ctl_name = KERN_VERSION,
277 .procname = "version",
278 .data = system_utsname.version,
279 .maxlen = sizeof(system_utsname.version),
281 .proc_handler = &proc_doutsstring,
282 .virt_handler = &vx_uts_virt_handler,
283 .strategy = &sysctl_string,
286 .ctl_name = KERN_NODENAME,
287 .procname = "hostname",
288 .data = system_utsname.nodename,
289 .maxlen = sizeof(system_utsname.nodename),
291 .proc_handler = &proc_doutsstring,
292 .virt_handler = &vx_uts_virt_handler,
293 .strategy = &sysctl_string,
296 .ctl_name = KERN_DOMAINNAME,
297 .procname = "domainname",
298 .data = system_utsname.domainname,
299 .maxlen = sizeof(system_utsname.domainname),
301 .proc_handler = &proc_doutsstring,
302 .virt_handler = &vx_uts_virt_handler,
303 .strategy = &sysctl_string,
306 .ctl_name = KERN_PANIC,
308 .data = &panic_timeout,
309 .maxlen = sizeof(int),
311 .proc_handler = &proc_dointvec,
314 .ctl_name = KERN_EXEC_SHIELD,
315 .procname = "exec-shield",
316 .data = &exec_shield,
317 .maxlen = sizeof(int),
319 .proc_handler = &proc_dointvec,
322 .ctl_name = KERN_PRINT_FATAL,
323 .procname = "print-fatal-signals",
324 .data = &print_fatal_signals,
325 .maxlen = sizeof(int),
327 .proc_handler = &proc_dointvec,
331 .ctl_name = KERN_VDSO,
333 .data = &vdso_enabled,
334 .maxlen = sizeof(int),
336 .proc_handler = &proc_dointvec,
339 .ctl_name = KERN_VDSO,
340 .procname = "vdso_populate",
341 .data = &vdso_populate,
342 .maxlen = sizeof(int),
344 .proc_handler = &proc_dointvec,
348 .ctl_name = KERN_CORE_USES_PID,
349 .procname = "core_uses_pid",
350 .data = &core_uses_pid,
351 .maxlen = sizeof(int),
353 .proc_handler = &proc_dointvec,
356 .ctl_name = KERN_CORE_PATTERN,
357 .procname = "core_pattern",
358 .data = core_pattern,
361 .proc_handler = &proc_dostring,
362 .strategy = &sysctl_string,
365 .ctl_name = KERN_TAINTED,
366 .procname = "tainted",
368 .maxlen = sizeof(int),
370 .proc_handler = &proc_dointvec,
373 .ctl_name = KERN_CAP_BSET,
374 .procname = "cap-bound",
376 .maxlen = sizeof(kernel_cap_t),
378 .proc_handler = &proc_dointvec_bset,
380 #ifdef CONFIG_BLK_DEV_INITRD
382 .ctl_name = KERN_REALROOTDEV,
383 .procname = "real-root-dev",
384 .data = &real_root_dev,
385 .maxlen = sizeof(int),
387 .proc_handler = &proc_dointvec,
392 .ctl_name = KERN_SPARC_REBOOT,
393 .procname = "reboot-cmd",
394 .data = reboot_command,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
401 .ctl_name = KERN_SPARC_STOP_A,
402 .procname = "stop-a",
403 .data = &stop_a_enabled,
404 .maxlen = sizeof (int),
406 .proc_handler = &proc_dointvec,
409 .ctl_name = KERN_SPARC_SCONS_PWROFF,
410 .procname = "scons-poweroff",
411 .data = &scons_pwroff,
412 .maxlen = sizeof (int),
414 .proc_handler = &proc_dointvec,
419 .ctl_name = KERN_HPPA_PWRSW,
420 .procname = "soft-power",
421 .data = &pwrsw_enabled,
422 .maxlen = sizeof (int),
424 .proc_handler = &proc_dointvec,
427 .ctl_name = KERN_HPPA_UNALIGNED,
428 .procname = "unaligned-trap",
429 .data = &unaligned_enabled,
430 .maxlen = sizeof (int),
432 .proc_handler = &proc_dointvec,
436 .ctl_name = KERN_CTLALTDEL,
437 .procname = "ctrl-alt-del",
439 .maxlen = sizeof(int),
441 .proc_handler = &proc_dointvec,
444 .ctl_name = KERN_PRINTK,
445 .procname = "printk",
446 .data = &console_loglevel,
447 .maxlen = 4*sizeof(int),
449 .proc_handler = &proc_dointvec,
453 .ctl_name = KERN_MODPROBE,
454 .procname = "modprobe",
455 .data = &modprobe_path,
456 .maxlen = KMOD_PATH_LEN,
458 .proc_handler = &proc_dostring,
459 .strategy = &sysctl_string,
462 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
464 .ctl_name = KERN_HOTPLUG,
465 .procname = "hotplug",
466 .data = &uevent_helper,
467 .maxlen = UEVENT_HELPER_PATH_LEN,
469 .proc_handler = &proc_dostring,
470 .strategy = &sysctl_string,
474 .ctl_name = KERN_VSHELPER,
475 .procname = "vshelper",
476 .data = &vshelper_path,
479 .proc_handler = &proc_dostring,
480 .strategy = &sysctl_string,
482 #ifdef CONFIG_CHR_DEV_SG
484 .ctl_name = KERN_SG_BIG_BUFF,
485 .procname = "sg-big-buff",
486 .data = &sg_big_buff,
487 .maxlen = sizeof (int),
489 .proc_handler = &proc_dointvec,
492 #ifdef CONFIG_BSD_PROCESS_ACCT
494 .ctl_name = KERN_ACCT,
497 .maxlen = 3*sizeof(int),
499 .proc_handler = &proc_dointvec,
502 #ifdef CONFIG_SYSVIPC
504 .ctl_name = KERN_SHMMAX,
505 .procname = "shmmax",
507 .maxlen = sizeof (size_t),
509 .proc_handler = &proc_doulongvec_minmax,
512 .ctl_name = KERN_SHMALL,
513 .procname = "shmall",
515 .maxlen = sizeof (size_t),
517 .proc_handler = &proc_doulongvec_minmax,
520 .ctl_name = KERN_SHMMNI,
521 .procname = "shmmni",
523 .maxlen = sizeof (int),
525 .proc_handler = &proc_dointvec,
528 .ctl_name = KERN_MSGMAX,
529 .procname = "msgmax",
531 .maxlen = sizeof (int),
533 .proc_handler = &proc_dointvec,
536 .ctl_name = KERN_MSGMNI,
537 .procname = "msgmni",
539 .maxlen = sizeof (int),
541 .proc_handler = &proc_dointvec,
544 .ctl_name = KERN_MSGMNB,
545 .procname = "msgmnb",
547 .maxlen = sizeof (int),
549 .proc_handler = &proc_dointvec,
552 .ctl_name = KERN_SEM,
555 .maxlen = 4*sizeof (int),
557 .proc_handler = &proc_dointvec,
560 #ifdef CONFIG_MAGIC_SYSRQ
562 .ctl_name = KERN_SYSRQ,
564 .data = &sysrq_enabled,
565 .maxlen = sizeof (int),
567 .proc_handler = &proc_dointvec,
571 .ctl_name = KERN_CADPID,
572 .procname = "cad_pid",
574 .maxlen = sizeof (int),
576 .proc_handler = &proc_dointvec,
579 .ctl_name = KERN_MAX_THREADS,
580 .procname = "threads-max",
581 .data = &max_threads,
582 .maxlen = sizeof(int),
584 .proc_handler = &proc_dointvec,
587 .ctl_name = KERN_RANDOM,
588 .procname = "random",
590 .child = random_table,
592 #ifdef CONFIG_UNIX98_PTYS
594 .ctl_name = KERN_PTY,
601 .ctl_name = KERN_OVERFLOWUID,
602 .procname = "overflowuid",
603 .data = &overflowuid,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec_minmax,
607 .strategy = &sysctl_intvec,
608 .extra1 = &minolduid,
609 .extra2 = &maxolduid,
612 .ctl_name = KERN_OVERFLOWGID,
613 .procname = "overflowgid",
614 .data = &overflowgid,
615 .maxlen = sizeof(int),
617 .proc_handler = &proc_dointvec_minmax,
618 .strategy = &sysctl_intvec,
619 .extra1 = &minolduid,
620 .extra2 = &maxolduid,
623 #ifdef CONFIG_MATHEMU
625 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
626 .procname = "ieee_emulation_warnings",
627 .data = &sysctl_ieee_emulation_warnings,
628 .maxlen = sizeof(int),
630 .proc_handler = &proc_dointvec,
633 #ifdef CONFIG_NO_IDLE_HZ
635 .ctl_name = KERN_HZ_TIMER,
636 .procname = "hz_timer",
637 .data = &sysctl_hz_timer,
638 .maxlen = sizeof(int),
640 .proc_handler = &proc_dointvec,
644 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
645 .procname = "userprocess_debug",
646 .data = &sysctl_userprocess_debug,
647 .maxlen = sizeof(int),
649 .proc_handler = &proc_dointvec,
653 .ctl_name = KERN_PIDMAX,
654 .procname = "pid_max",
656 .maxlen = sizeof (int),
658 .proc_handler = &proc_dointvec_minmax,
659 .strategy = sysctl_intvec,
660 .extra1 = &pid_max_min,
661 .extra2 = &pid_max_max,
664 .ctl_name = KERN_PANIC_ON_OOPS,
665 .procname = "panic_on_oops",
666 .data = &panic_on_oops,
667 .maxlen = sizeof(int),
669 .proc_handler = &proc_dointvec,
672 .ctl_name = KERN_PRINTK_RATELIMIT,
673 .procname = "printk_ratelimit",
674 .data = &printk_ratelimit_jiffies,
675 .maxlen = sizeof(int),
677 .proc_handler = &proc_dointvec_jiffies,
678 .strategy = &sysctl_jiffies,
681 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
682 .procname = "printk_ratelimit_burst",
683 .data = &printk_ratelimit_burst,
684 .maxlen = sizeof(int),
686 .proc_handler = &proc_dointvec,
689 .ctl_name = KERN_NGROUPS_MAX,
690 .procname = "ngroups_max",
691 .data = &ngroups_max,
692 .maxlen = sizeof (int),
694 .proc_handler = &proc_dointvec,
696 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
698 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
699 .procname = "unknown_nmi_panic",
700 .data = &unknown_nmi_panic,
701 .maxlen = sizeof (int),
703 .proc_handler = &proc_unknown_nmi_panic,
706 #if defined(CONFIG_X86)
708 .ctl_name = KERN_BOOTLOADER_TYPE,
709 .procname = "bootloader_type",
710 .data = &bootloader_type,
711 .maxlen = sizeof (int),
713 .proc_handler = &proc_dointvec,
716 #if defined(CONFIG_MMU)
718 .ctl_name = KERN_RANDOMIZE,
719 .procname = "randomize_va_space",
720 .data = &randomize_va_space,
721 .maxlen = sizeof(int),
723 .proc_handler = &proc_dointvec,
726 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
728 .ctl_name = KERN_SPIN_RETRY,
729 .procname = "spin_retry",
731 .maxlen = sizeof (int),
733 .proc_handler = &proc_dointvec,
736 #ifdef CONFIG_ACPI_SLEEP
738 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
739 .procname = "acpi_video_flags",
740 .data = &acpi_video_flags,
741 .maxlen = sizeof (unsigned long),
743 .proc_handler = &proc_doulongvec_minmax,
748 .ctl_name = KERN_IA64_UNALIGNED,
749 .procname = "ignore-unaligned-usertrap",
750 .data = &no_unaligned_warning,
751 .maxlen = sizeof (int),
753 .proc_handler = &proc_dointvec,
758 .ctl_name = KERN_COMPAT_LOG,
759 .procname = "compat-log",
761 .maxlen = sizeof (int),
763 .proc_handler = &proc_dointvec,
766 #ifdef CONFIG_RT_MUTEXES
768 .ctl_name = KERN_MAX_LOCK_DEPTH,
769 .procname = "max_lock_depth",
770 .data = &max_lock_depth,
771 .maxlen = sizeof(int),
773 .proc_handler = &proc_dointvec,
780 /* Constants for minimum and maximum testing in vm_table.
781 We use these as one-element integer vectors. */
783 static int one_hundred = 100;
786 static ctl_table vm_table[] = {
788 .ctl_name = VM_OVERCOMMIT_MEMORY,
789 .procname = "overcommit_memory",
790 .data = &sysctl_overcommit_memory,
791 .maxlen = sizeof(sysctl_overcommit_memory),
793 .proc_handler = &proc_dointvec,
796 .ctl_name = VM_PANIC_ON_OOM,
797 .procname = "panic_on_oom",
798 .data = &sysctl_panic_on_oom,
799 .maxlen = sizeof(sysctl_panic_on_oom),
801 .proc_handler = &proc_dointvec,
804 .ctl_name = VM_OVERCOMMIT_RATIO,
805 .procname = "overcommit_ratio",
806 .data = &sysctl_overcommit_ratio,
807 .maxlen = sizeof(sysctl_overcommit_ratio),
809 .proc_handler = &proc_dointvec,
812 .ctl_name = VM_PAGE_CLUSTER,
813 .procname = "page-cluster",
814 .data = &page_cluster,
815 .maxlen = sizeof(int),
817 .proc_handler = &proc_dointvec,
820 .ctl_name = VM_DIRTY_BACKGROUND,
821 .procname = "dirty_background_ratio",
822 .data = &dirty_background_ratio,
823 .maxlen = sizeof(dirty_background_ratio),
825 .proc_handler = &proc_dointvec_minmax,
826 .strategy = &sysctl_intvec,
828 .extra2 = &one_hundred,
831 .ctl_name = VM_DIRTY_RATIO,
832 .procname = "dirty_ratio",
833 .data = &vm_dirty_ratio,
834 .maxlen = sizeof(vm_dirty_ratio),
836 .proc_handler = &proc_dointvec_minmax,
837 .strategy = &sysctl_intvec,
839 .extra2 = &one_hundred,
842 .ctl_name = VM_DIRTY_WB_CS,
843 .procname = "dirty_writeback_centisecs",
844 .data = &dirty_writeback_interval,
845 .maxlen = sizeof(dirty_writeback_interval),
847 .proc_handler = &dirty_writeback_centisecs_handler,
850 .ctl_name = VM_DIRTY_EXPIRE_CS,
851 .procname = "dirty_expire_centisecs",
852 .data = &dirty_expire_interval,
853 .maxlen = sizeof(dirty_expire_interval),
855 .proc_handler = &proc_dointvec_userhz_jiffies,
858 .ctl_name = VM_NR_PDFLUSH_THREADS,
859 .procname = "nr_pdflush_threads",
860 .data = &nr_pdflush_threads,
861 .maxlen = sizeof nr_pdflush_threads,
862 .mode = 0444 /* read-only*/,
863 .proc_handler = &proc_dointvec,
866 .ctl_name = VM_SWAPPINESS,
867 .procname = "swappiness",
868 .data = &vm_swappiness,
869 .maxlen = sizeof(vm_swappiness),
871 .proc_handler = &proc_dointvec_minmax,
872 .strategy = &sysctl_intvec,
874 .extra2 = &one_hundred,
876 #ifdef CONFIG_HUGETLB_PAGE
878 .ctl_name = VM_HUGETLB_PAGES,
879 .procname = "nr_hugepages",
880 .data = &max_huge_pages,
881 .maxlen = sizeof(unsigned long),
883 .proc_handler = &hugetlb_sysctl_handler,
884 .extra1 = (void *)&hugetlb_zero,
885 .extra2 = (void *)&hugetlb_infinity,
888 .ctl_name = VM_HUGETLB_GROUP,
889 .procname = "hugetlb_shm_group",
890 .data = &sysctl_hugetlb_shm_group,
891 .maxlen = sizeof(gid_t),
893 .proc_handler = &proc_dointvec,
897 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
898 .procname = "lowmem_reserve_ratio",
899 .data = &sysctl_lowmem_reserve_ratio,
900 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
902 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
903 .strategy = &sysctl_intvec,
906 .ctl_name = VM_DROP_PAGECACHE,
907 .procname = "drop_caches",
908 .data = &sysctl_drop_caches,
909 .maxlen = sizeof(int),
911 .proc_handler = drop_caches_sysctl_handler,
912 .strategy = &sysctl_intvec,
915 .ctl_name = VM_MIN_FREE_KBYTES,
916 .procname = "min_free_kbytes",
917 .data = &min_free_kbytes,
918 .maxlen = sizeof(min_free_kbytes),
920 .proc_handler = &min_free_kbytes_sysctl_handler,
921 .strategy = &sysctl_intvec,
925 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
926 .procname = "percpu_pagelist_fraction",
927 .data = &percpu_pagelist_fraction,
928 .maxlen = sizeof(percpu_pagelist_fraction),
930 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
931 .strategy = &sysctl_intvec,
932 .extra1 = &min_percpu_pagelist_fract,
936 .ctl_name = VM_MAX_MAP_COUNT,
937 .procname = "max_map_count",
938 .data = &sysctl_max_map_count,
939 .maxlen = sizeof(sysctl_max_map_count),
941 .proc_handler = &proc_dointvec
945 .ctl_name = VM_LAPTOP_MODE,
946 .procname = "laptop_mode",
947 .data = &laptop_mode,
948 .maxlen = sizeof(laptop_mode),
950 .proc_handler = &proc_dointvec_jiffies,
951 .strategy = &sysctl_jiffies,
954 .ctl_name = VM_BLOCK_DUMP,
955 .procname = "block_dump",
957 .maxlen = sizeof(block_dump),
959 .proc_handler = &proc_dointvec,
960 .strategy = &sysctl_intvec,
964 .ctl_name = VM_VFS_CACHE_PRESSURE,
965 .procname = "vfs_cache_pressure",
966 .data = &sysctl_vfs_cache_pressure,
967 .maxlen = sizeof(sysctl_vfs_cache_pressure),
969 .proc_handler = &proc_dointvec,
970 .strategy = &sysctl_intvec,
973 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
975 .ctl_name = VM_LEGACY_VA_LAYOUT,
976 .procname = "legacy_va_layout",
977 .data = &sysctl_legacy_va_layout,
978 .maxlen = sizeof(sysctl_legacy_va_layout),
980 .proc_handler = &proc_dointvec,
981 .strategy = &sysctl_intvec,
987 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
988 .procname = "swap_token_timeout",
989 .data = &swap_token_default_timeout,
990 .maxlen = sizeof(swap_token_default_timeout),
992 .proc_handler = &proc_dointvec_jiffies,
993 .strategy = &sysctl_jiffies,
998 .ctl_name = VM_ZONE_RECLAIM_MODE,
999 .procname = "zone_reclaim_mode",
1000 .data = &zone_reclaim_mode,
1001 .maxlen = sizeof(zone_reclaim_mode),
1003 .proc_handler = &proc_dointvec,
1004 .strategy = &sysctl_intvec,
1008 .ctl_name = VM_MIN_UNMAPPED,
1009 .procname = "min_unmapped_ratio",
1010 .data = &sysctl_min_unmapped_ratio,
1011 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1013 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1014 .strategy = &sysctl_intvec,
1016 .extra2 = &one_hundred,
1019 .ctl_name = VM_MIN_SLAB,
1020 .procname = "min_slab_ratio",
1021 .data = &sysctl_min_slab_ratio,
1022 .maxlen = sizeof(sysctl_min_slab_ratio),
1024 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1025 .strategy = &sysctl_intvec,
1027 .extra2 = &one_hundred,
1030 #ifdef CONFIG_X86_32
1032 .ctl_name = VM_VDSO_ENABLED,
1033 .procname = "vdso_enabled",
1034 .data = &vdso_enabled,
1035 .maxlen = sizeof(vdso_enabled),
1037 .proc_handler = &proc_dointvec,
1038 .strategy = &sysctl_intvec,
1045 static ctl_table fs_table[] = {
1047 .ctl_name = FS_NRINODE,
1048 .procname = "inode-nr",
1049 .data = &inodes_stat,
1050 .maxlen = 2*sizeof(int),
1052 .proc_handler = &proc_dointvec,
1055 .ctl_name = FS_STATINODE,
1056 .procname = "inode-state",
1057 .data = &inodes_stat,
1058 .maxlen = 7*sizeof(int),
1060 .proc_handler = &proc_dointvec,
1063 .ctl_name = FS_NRFILE,
1064 .procname = "file-nr",
1065 .data = &files_stat,
1066 .maxlen = 3*sizeof(int),
1068 .proc_handler = &proc_nr_files,
1071 .ctl_name = FS_MAXFILE,
1072 .procname = "file-max",
1073 .data = &files_stat.max_files,
1074 .maxlen = sizeof(int),
1076 .proc_handler = &proc_dointvec,
1079 .ctl_name = FS_DENTRY,
1080 .procname = "dentry-state",
1081 .data = &dentry_stat,
1082 .maxlen = 6*sizeof(int),
1084 .proc_handler = &proc_dointvec,
1087 .ctl_name = FS_OVERFLOWUID,
1088 .procname = "overflowuid",
1089 .data = &fs_overflowuid,
1090 .maxlen = sizeof(int),
1092 .proc_handler = &proc_dointvec_minmax,
1093 .strategy = &sysctl_intvec,
1094 .extra1 = &minolduid,
1095 .extra2 = &maxolduid,
1098 .ctl_name = FS_OVERFLOWGID,
1099 .procname = "overflowgid",
1100 .data = &fs_overflowgid,
1101 .maxlen = sizeof(int),
1103 .proc_handler = &proc_dointvec_minmax,
1104 .strategy = &sysctl_intvec,
1105 .extra1 = &minolduid,
1106 .extra2 = &maxolduid,
1109 .ctl_name = FS_LEASES,
1110 .procname = "leases-enable",
1111 .data = &leases_enable,
1112 .maxlen = sizeof(int),
1114 .proc_handler = &proc_dointvec,
1116 #ifdef CONFIG_DNOTIFY
1118 .ctl_name = FS_DIR_NOTIFY,
1119 .procname = "dir-notify-enable",
1120 .data = &dir_notify_enable,
1121 .maxlen = sizeof(int),
1123 .proc_handler = &proc_dointvec,
1128 .ctl_name = FS_LEASE_TIME,
1129 .procname = "lease-break-time",
1130 .data = &lease_break_time,
1131 .maxlen = sizeof(int),
1133 .proc_handler = &proc_dointvec,
1136 .ctl_name = FS_AIO_NR,
1137 .procname = "aio-nr",
1139 .maxlen = sizeof(aio_nr),
1141 .proc_handler = &proc_doulongvec_minmax,
1144 .ctl_name = FS_AIO_MAX_NR,
1145 .procname = "aio-max-nr",
1146 .data = &aio_max_nr,
1147 .maxlen = sizeof(aio_max_nr),
1149 .proc_handler = &proc_doulongvec_minmax,
1151 #ifdef CONFIG_INOTIFY_USER
1153 .ctl_name = FS_INOTIFY,
1154 .procname = "inotify",
1156 .child = inotify_table,
1161 .ctl_name = KERN_SETUID_DUMPABLE,
1162 .procname = "suid_dumpable",
1163 .data = &suid_dumpable,
1164 .maxlen = sizeof(int),
1166 .proc_handler = &proc_dointvec,
1171 static ctl_table debug_table[] = {
1175 static ctl_table dev_table[] = {
1179 extern void init_irq_proc (void);
1181 static DEFINE_SPINLOCK(sysctl_lock);
1183 /* called under sysctl_lock */
1184 static int use_table(struct ctl_table_header *p)
1186 if (unlikely(p->unregistering))
1192 /* called under sysctl_lock */
1193 static void unuse_table(struct ctl_table_header *p)
1196 if (unlikely(p->unregistering))
1197 complete(p->unregistering);
1200 /* called under sysctl_lock, will reacquire if has to wait */
1201 static void start_unregistering(struct ctl_table_header *p)
1204 * if p->used is 0, nobody will ever touch that entry again;
1205 * we'll eliminate all paths to it before dropping sysctl_lock
1207 if (unlikely(p->used)) {
1208 struct completion wait;
1209 init_completion(&wait);
1210 p->unregistering = &wait;
1211 spin_unlock(&sysctl_lock);
1212 wait_for_completion(&wait);
1213 spin_lock(&sysctl_lock);
1216 * do not remove from the list until nobody holds it; walking the
1217 * list in do_sysctl() relies on that.
1219 list_del_init(&p->ctl_entry);
1222 void __init sysctl_init(void)
1224 #ifdef CONFIG_PROC_FS
1225 register_proc_table(root_table, proc_sys_root, &root_table_header);
1230 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1231 void __user *newval, size_t newlen)
1233 struct list_head *tmp;
1234 int error = -ENOTDIR;
1236 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1240 if (!oldlenp || get_user(old_len, oldlenp))
1243 spin_lock(&sysctl_lock);
1244 tmp = &root_table_header.ctl_entry;
1246 struct ctl_table_header *head =
1247 list_entry(tmp, struct ctl_table_header, ctl_entry);
1248 void *context = NULL;
1250 if (!use_table(head))
1253 spin_unlock(&sysctl_lock);
1255 error = parse_table(name, nlen, oldval, oldlenp,
1256 newval, newlen, head->ctl_table,
1260 spin_lock(&sysctl_lock);
1262 if (error != -ENOTDIR)
1264 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1265 spin_unlock(&sysctl_lock);
1269 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1271 struct __sysctl_args tmp;
1274 if (copy_from_user(&tmp, args, sizeof(tmp)))
1278 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1279 tmp.newval, tmp.newlen);
1285 * ctl_perm does NOT grant the superuser all rights automatically, because
1286 * some sysctl variables are readonly even to root.
1289 static int test_perm(int mode, int op)
1293 else if (in_egroup_p(0))
1295 if ((mode & op & 0007) == op)
1300 static inline int ctl_perm(ctl_table *table, int op)
1303 error = security_sysctl(table, op);
1306 return test_perm(table->mode, op);
1309 static int parse_table(int __user *name, int nlen,
1310 void __user *oldval, size_t __user *oldlenp,
1311 void __user *newval, size_t newlen,
1312 ctl_table *table, void **context)
1318 if (get_user(n, name))
1320 for ( ; table->ctl_name; table++) {
1321 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1324 if (ctl_perm(table, 001))
1326 if (table->strategy) {
1327 error = table->strategy(
1330 newval, newlen, context);
1336 table = table->child;
1339 error = do_sysctl_strategy(table, name, nlen,
1341 newval, newlen, context);
1348 /* Perform the actual read/write of a sysctl table entry. */
1349 int do_sysctl_strategy (ctl_table *table,
1350 int __user *name, int nlen,
1351 void __user *oldval, size_t __user *oldlenp,
1352 void __user *newval, size_t newlen, void **context)
1361 if (ctl_perm(table, op))
1364 if (table->strategy) {
1365 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1366 newval, newlen, context);
1373 /* If there is no strategy routine, or if the strategy returns
1374 * zero, proceed with automatic r/w */
1375 if (table->data && table->maxlen) {
1376 if (oldval && oldlenp) {
1377 if (get_user(len, oldlenp))
1380 if (len > table->maxlen)
1381 len = table->maxlen;
1382 if(copy_to_user(oldval, table->data, len))
1384 if(put_user(len, oldlenp))
1388 if (newval && newlen) {
1390 if (len > table->maxlen)
1391 len = table->maxlen;
1392 if(copy_from_user(table->data, newval, len))
1400 * register_sysctl_table - register a sysctl hierarchy
1401 * @table: the top-level table structure
1402 * @insert_at_head: whether the entry should be inserted in front or at the end
1404 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1405 * array. An entry with a ctl_name of 0 terminates the table.
1407 * The members of the &ctl_table structure are used as follows:
1409 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1410 * must be unique within that level of sysctl
1412 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1413 * enter a sysctl file
1415 * data - a pointer to data for use by proc_handler
1417 * maxlen - the maximum size in bytes of the data
1419 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1421 * child - a pointer to the child sysctl table if this entry is a directory, or
1424 * proc_handler - the text handler routine (described below)
1426 * strategy - the strategy routine (described below)
1428 * de - for internal use by the sysctl routines
1430 * extra1, extra2 - extra pointers usable by the proc handler routines
1432 * Leaf nodes in the sysctl tree will be represented by a single file
1433 * under /proc; non-leaf nodes will be represented by directories.
1435 * sysctl(2) can automatically manage read and write requests through
1436 * the sysctl table. The data and maxlen fields of the ctl_table
1437 * struct enable minimal validation of the values being written to be
1438 * performed, and the mode field allows minimal authentication.
1440 * More sophisticated management can be enabled by the provision of a
1441 * strategy routine with the table entry. This will be called before
1442 * any automatic read or write of the data is performed.
1444 * The strategy routine may return
1446 * < 0 - Error occurred (error is passed to user process)
1448 * 0 - OK - proceed with automatic read or write.
1450 * > 0 - OK - read or write has been done by the strategy routine, so
1451 * return immediately.
1453 * There must be a proc_handler routine for any terminal nodes
1454 * mirrored under /proc/sys (non-terminals are handled by a built-in
1455 * directory handler). Several default handlers are available to
1456 * cover common cases -
1458 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1459 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1460 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1462 * It is the handler's job to read the input buffer from user memory
1463 * and process it. The handler should return 0 on success.
1465 * This routine returns %NULL on a failure to register, and a pointer
1466 * to the table header on success.
1468 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1471 struct ctl_table_header *tmp;
1472 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1475 tmp->ctl_table = table;
1476 INIT_LIST_HEAD(&tmp->ctl_entry);
1478 tmp->unregistering = NULL;
1479 spin_lock(&sysctl_lock);
1481 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1483 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1484 spin_unlock(&sysctl_lock);
1485 #ifdef CONFIG_PROC_FS
1486 register_proc_table(table, proc_sys_root, tmp);
1492 * unregister_sysctl_table - unregister a sysctl table hierarchy
1493 * @header: the header returned from register_sysctl_table
1495 * Unregisters the sysctl table and all children. proc entries may not
1496 * actually be removed until they are no longer used by anyone.
1498 void unregister_sysctl_table(struct ctl_table_header * header)
1501 spin_lock(&sysctl_lock);
1502 start_unregistering(header);
1503 #ifdef CONFIG_PROC_FS
1504 unregister_proc_table(header->ctl_table, proc_sys_root);
1506 spin_unlock(&sysctl_lock);
1514 #ifdef CONFIG_PROC_FS
1516 /* Scan the sysctl entries in table and add them all into /proc */
1517 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1519 struct proc_dir_entry *de;
1523 for (; table->ctl_name; table++) {
1524 /* Can't do anything without a proc name. */
1525 if (!table->procname)
1527 /* Maybe we can't do anything with it... */
1528 if (!table->proc_handler && !table->child) {
1529 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1534 len = strlen(table->procname);
1538 if (table->proc_handler)
1542 for (de = root->subdir; de; de = de->next) {
1543 if (proc_match(len, table->procname, de))
1546 /* If the subdir exists already, de is non-NULL */
1550 de = create_proc_entry(table->procname, mode, root);
1554 de->data = (void *) table;
1555 if (table->proc_handler)
1556 de->proc_fops = &proc_sys_file_operations;
1559 if (de->mode & S_IFDIR)
1560 register_proc_table(table->child, de, set);
1565 * Unregister a /proc sysctl table and any subdirectories.
1567 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1569 struct proc_dir_entry *de;
1570 for (; table->ctl_name; table++) {
1571 if (!(de = table->de))
1573 if (de->mode & S_IFDIR) {
1574 if (!table->child) {
1575 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1578 unregister_proc_table(table->child, de);
1580 /* Don't unregister directories which still have entries.. */
1586 * In any case, mark the entry as goner; we'll keep it
1587 * around if it's busy, but we'll know to do nothing with
1588 * its fields. We are under sysctl_lock here.
1592 /* Don't unregister proc entries that are still being used.. */
1593 if (atomic_read(&de->count))
1597 remove_proc_entry(table->procname, root);
1601 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1602 size_t count, loff_t *ppos)
1605 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1606 struct ctl_table *table;
1608 ssize_t error = -ENOTDIR;
1610 spin_lock(&sysctl_lock);
1611 if (de && de->data && use_table(de->set)) {
1613 * at that point we know that sysctl was not unregistered
1614 * and won't be until we finish
1616 spin_unlock(&sysctl_lock);
1617 table = (struct ctl_table *) de->data;
1618 if (!table || !table->proc_handler)
1621 op = (write ? 002 : 004);
1622 if (ctl_perm(table, op))
1625 /* careful: calling conventions are nasty here */
1627 error = (*table->proc_handler)(table, write, file,
1632 spin_lock(&sysctl_lock);
1633 unuse_table(de->set);
1635 spin_unlock(&sysctl_lock);
1639 static int proc_opensys(struct inode *inode, struct file *file)
1641 if (file->f_mode & FMODE_WRITE) {
1643 * sysctl entries that are not writable,
1644 * are _NOT_ writable, capabilities or not.
1646 if (!(inode->i_mode & S_IWUSR))
1653 static ssize_t proc_readsys(struct file * file, char __user * buf,
1654 size_t count, loff_t *ppos)
1656 return do_rw_proc(0, file, buf, count, ppos);
1659 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1660 size_t count, loff_t *ppos)
1662 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1666 * proc_dostring - read a string sysctl
1667 * @table: the sysctl table
1668 * @write: %TRUE if this is a write to the sysctl file
1669 * @filp: the file structure
1670 * @buffer: the user buffer
1671 * @lenp: the size of the user buffer
1672 * @ppos: file position
1674 * Reads/writes a string from/to the user buffer. If the kernel
1675 * buffer provided is not large enough to hold the string, the
1676 * string is truncated. The copied string is %NULL-terminated.
1677 * If the string is being read by the user process, it is copied
1678 * and a newline '\n' is added. It is truncated if the buffer is
1681 * Returns 0 on success.
1683 int proc_dostring(ctl_table *table, int write, struct file *filp,
1684 void __user *buffer, size_t *lenp, loff_t *ppos)
1692 maxlen = table->maxlen;
1694 if (!data || !maxlen || !*lenp || (*ppos && !write))
1697 if (table->virt_handler)
1698 table->virt_handler(table, write, filp->f_xid, &data, &maxlen);
1703 while (len < *lenp) {
1704 if (get_user(c, p++))
1706 if (c == 0 || c == '\n')
1712 if(copy_from_user(data, buffer, len))
1714 ((char *) data)[len] = 0;
1723 if(copy_to_user(buffer, data, len))
1726 if(put_user('\n', ((char __user *) buffer) + len))
1737 * Special case of dostring for the UTS structure. This has locks
1738 * to observe. Should this be in kernel/sys.c ????
1741 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1742 void __user *buffer, size_t *lenp, loff_t *ppos)
1747 down_read(&uts_sem);
1748 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1751 down_write(&uts_sem);
1752 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1758 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1760 int write, void *data)
1763 *valp = *negp ? -*lvalp : *lvalp;
1768 *lvalp = (unsigned long)-val;
1771 *lvalp = (unsigned long)val;
1777 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1778 void __user *buffer, size_t *lenp, loff_t *ppos,
1779 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1780 int write, void *data),
1783 #define TMPBUFLEN 21
1784 int *i, vleft, first=1, neg, val;
1788 char buf[TMPBUFLEN], *p;
1789 char __user *s = buffer;
1791 if (!table->data || !table->maxlen || !*lenp ||
1792 (*ppos && !write)) {
1797 i = (int *) table->data;
1798 vleft = table->maxlen / sizeof(*i);
1802 conv = do_proc_dointvec_conv;
1804 for (; left && vleft--; i++, first=0) {
1819 if (len > sizeof(buf) - 1)
1820 len = sizeof(buf) - 1;
1821 if (copy_from_user(buf, s, len))
1825 if (*p == '-' && left > 1) {
1829 if (*p < '0' || *p > '9')
1832 lval = simple_strtoul(p, &p, 0);
1835 if ((len < left) && *p && !isspace(*p))
1842 if (conv(&neg, &lval, i, 1, data))
1849 if (conv(&neg, &lval, i, 0, data))
1852 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1856 if(copy_to_user(s, buf, len))
1863 if (!write && !first && left) {
1864 if(put_user('\n', s))
1871 if (get_user(c, s++))
1887 * proc_dointvec - read a vector of integers
1888 * @table: the sysctl table
1889 * @write: %TRUE if this is a write to the sysctl file
1890 * @filp: the file structure
1891 * @buffer: the user buffer
1892 * @lenp: the size of the user buffer
1893 * @ppos: file position
1895 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1896 * values from/to the user buffer, treated as an ASCII string.
1898 * Returns 0 on success.
1900 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1901 void __user *buffer, size_t *lenp, loff_t *ppos)
1903 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1913 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1915 int write, void *data)
1917 int op = *(int *)data;
1919 int val = *negp ? -*lvalp : *lvalp;
1921 case OP_SET: *valp = val; break;
1922 case OP_AND: *valp &= val; break;
1923 case OP_OR: *valp |= val; break;
1924 case OP_MAX: if(*valp < val)
1927 case OP_MIN: if(*valp > val)
1935 *lvalp = (unsigned long)-val;
1938 *lvalp = (unsigned long)val;
1945 * init may raise the set.
1948 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1949 void __user *buffer, size_t *lenp, loff_t *ppos)
1953 if (!capable(CAP_SYS_MODULE)) {
1957 op = (current->pid == 1) ? OP_SET : OP_AND;
1958 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1959 do_proc_dointvec_bset_conv,&op);
1962 struct do_proc_dointvec_minmax_conv_param {
1967 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1969 int write, void *data)
1971 struct do_proc_dointvec_minmax_conv_param *param = data;
1973 int val = *negp ? -*lvalp : *lvalp;
1974 if ((param->min && *param->min > val) ||
1975 (param->max && *param->max < val))
1982 *lvalp = (unsigned long)-val;
1985 *lvalp = (unsigned long)val;
1992 * proc_dointvec_minmax - read a vector of integers with min/max values
1993 * @table: the sysctl table
1994 * @write: %TRUE if this is a write to the sysctl file
1995 * @filp: the file structure
1996 * @buffer: the user buffer
1997 * @lenp: the size of the user buffer
1998 * @ppos: file position
2000 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2001 * values from/to the user buffer, treated as an ASCII string.
2003 * This routine will ensure the values are within the range specified by
2004 * table->extra1 (min) and table->extra2 (max).
2006 * Returns 0 on success.
2008 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2009 void __user *buffer, size_t *lenp, loff_t *ppos)
2011 struct do_proc_dointvec_minmax_conv_param param = {
2012 .min = (int *) table->extra1,
2013 .max = (int *) table->extra2,
2015 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2016 do_proc_dointvec_minmax_conv, ¶m);
2019 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2021 void __user *buffer,
2022 size_t *lenp, loff_t *ppos,
2023 unsigned long convmul,
2024 unsigned long convdiv)
2026 #define TMPBUFLEN 21
2027 unsigned long *i, *min, *max, val;
2028 int vleft, first=1, neg;
2030 char buf[TMPBUFLEN], *p;
2031 char __user *s = buffer;
2033 if (!table->data || !table->maxlen || !*lenp ||
2034 (*ppos && !write)) {
2039 i = (unsigned long *) table->data;
2040 min = (unsigned long *) table->extra1;
2041 max = (unsigned long *) table->extra2;
2042 vleft = table->maxlen / sizeof(unsigned long);
2045 for (; left && vleft--; i++, min++, max++, first=0) {
2060 if (len > TMPBUFLEN-1)
2062 if (copy_from_user(buf, s, len))
2066 if (*p == '-' && left > 1) {
2070 if (*p < '0' || *p > '9')
2072 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2074 if ((len < left) && *p && !isspace(*p))
2083 if ((min && val < *min) || (max && val > *max))
2090 sprintf(p, "%lu", convdiv * (*i) / convmul);
2094 if(copy_to_user(s, buf, len))
2101 if (!write && !first && left) {
2102 if(put_user('\n', s))
2109 if (get_user(c, s++))
2125 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2126 * @table: the sysctl table
2127 * @write: %TRUE if this is a write to the sysctl file
2128 * @filp: the file structure
2129 * @buffer: the user buffer
2130 * @lenp: the size of the user buffer
2131 * @ppos: file position
2133 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2134 * values from/to the user buffer, treated as an ASCII string.
2136 * This routine will ensure the values are within the range specified by
2137 * table->extra1 (min) and table->extra2 (max).
2139 * Returns 0 on success.
2141 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2142 void __user *buffer, size_t *lenp, loff_t *ppos)
2144 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2148 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2149 * @table: the sysctl table
2150 * @write: %TRUE if this is a write to the sysctl file
2151 * @filp: the file structure
2152 * @buffer: the user buffer
2153 * @lenp: the size of the user buffer
2154 * @ppos: file position
2156 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2157 * values from/to the user buffer, treated as an ASCII string. The values
2158 * are treated as milliseconds, and converted to jiffies when they are stored.
2160 * This routine will ensure the values are within the range specified by
2161 * table->extra1 (min) and table->extra2 (max).
2163 * Returns 0 on success.
2165 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2167 void __user *buffer,
2168 size_t *lenp, loff_t *ppos)
2170 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2171 lenp, ppos, HZ, 1000l);
2175 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2177 int write, void *data)
2180 if (*lvalp > LONG_MAX / HZ)
2182 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2188 lval = (unsigned long)-val;
2191 lval = (unsigned long)val;
2198 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2200 int write, void *data)
2203 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2205 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2211 lval = (unsigned long)-val;
2214 lval = (unsigned long)val;
2216 *lvalp = jiffies_to_clock_t(lval);
2221 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2223 int write, void *data)
2226 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2232 lval = (unsigned long)-val;
2235 lval = (unsigned long)val;
2237 *lvalp = jiffies_to_msecs(lval);
2243 * proc_dointvec_jiffies - read a vector of integers as seconds
2244 * @table: the sysctl table
2245 * @write: %TRUE if this is a write to the sysctl file
2246 * @filp: the file structure
2247 * @buffer: the user buffer
2248 * @lenp: the size of the user buffer
2249 * @ppos: file position
2251 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2252 * values from/to the user buffer, treated as an ASCII string.
2253 * The values read are assumed to be in seconds, and are converted into
2256 * Returns 0 on success.
2258 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2259 void __user *buffer, size_t *lenp, loff_t *ppos)
2261 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2262 do_proc_dointvec_jiffies_conv,NULL);
2266 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2267 * @table: the sysctl table
2268 * @write: %TRUE if this is a write to the sysctl file
2269 * @filp: the file structure
2270 * @buffer: the user buffer
2271 * @lenp: the size of the user buffer
2272 * @ppos: pointer to the file position
2274 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2275 * values from/to the user buffer, treated as an ASCII string.
2276 * The values read are assumed to be in 1/USER_HZ seconds, and
2277 * are converted into jiffies.
2279 * Returns 0 on success.
2281 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2284 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2285 do_proc_dointvec_userhz_jiffies_conv,NULL);
2289 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2290 * @table: the sysctl table
2291 * @write: %TRUE if this is a write to the sysctl file
2292 * @filp: the file structure
2293 * @buffer: the user buffer
2294 * @lenp: the size of the user buffer
2295 * @ppos: file position
2296 * @ppos: the current position in the file
2298 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2299 * values from/to the user buffer, treated as an ASCII string.
2300 * The values read are assumed to be in 1/1000 seconds, and
2301 * are converted into jiffies.
2303 * Returns 0 on success.
2305 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2306 void __user *buffer, size_t *lenp, loff_t *ppos)
2308 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2309 do_proc_dointvec_ms_jiffies_conv, NULL);
2312 #else /* CONFIG_PROC_FS */
2314 int proc_dostring(ctl_table *table, int write, struct file *filp,
2315 void __user *buffer, size_t *lenp, loff_t *ppos)
2320 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2321 void __user *buffer, size_t *lenp, loff_t *ppos)
2326 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2327 void __user *buffer, size_t *lenp, loff_t *ppos)
2332 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2333 void __user *buffer, size_t *lenp, loff_t *ppos)
2338 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2339 void __user *buffer, size_t *lenp, loff_t *ppos)
2344 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2345 void __user *buffer, size_t *lenp, loff_t *ppos)
2350 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2351 void __user *buffer, size_t *lenp, loff_t *ppos)
2356 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2357 void __user *buffer, size_t *lenp, loff_t *ppos)
2362 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2363 void __user *buffer, size_t *lenp, loff_t *ppos)
2368 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2370 void __user *buffer,
2371 size_t *lenp, loff_t *ppos)
2377 #endif /* CONFIG_PROC_FS */
2381 * General sysctl support routines
2384 /* The generic string strategy routine: */
2385 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2386 void __user *oldval, size_t __user *oldlenp,
2387 void __user *newval, size_t newlen, void **context)
2389 if (!table->data || !table->maxlen)
2392 if (oldval && oldlenp) {
2394 if (get_user(bufsize, oldlenp))
2397 size_t len = strlen(table->data), copied;
2399 /* This shouldn't trigger for a well-formed sysctl */
2400 if (len > table->maxlen)
2401 len = table->maxlen;
2403 /* Copy up to a max of bufsize-1 bytes of the string */
2404 copied = (len >= bufsize) ? bufsize - 1 : len;
2406 if (copy_to_user(oldval, table->data, copied) ||
2407 put_user(0, (char __user *)(oldval + copied)))
2409 if (put_user(len, oldlenp))
2413 if (newval && newlen) {
2414 size_t len = newlen;
2415 if (len > table->maxlen)
2416 len = table->maxlen;
2417 if(copy_from_user(table->data, newval, len))
2419 if (len == table->maxlen)
2421 ((char *) table->data)[len] = 0;
2427 * This function makes sure that all of the integers in the vector
2428 * are between the minimum and maximum values given in the arrays
2429 * table->extra1 and table->extra2, respectively.
2431 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2432 void __user *oldval, size_t __user *oldlenp,
2433 void __user *newval, size_t newlen, void **context)
2436 if (newval && newlen) {
2437 int __user *vec = (int __user *) newval;
2438 int *min = (int *) table->extra1;
2439 int *max = (int *) table->extra2;
2443 if (newlen % sizeof(int) != 0)
2446 if (!table->extra1 && !table->extra2)
2449 if (newlen > table->maxlen)
2450 newlen = table->maxlen;
2451 length = newlen / sizeof(int);
2453 for (i = 0; i < length; i++) {
2455 if (get_user(value, vec + i))
2457 if (min && value < min[i])
2459 if (max && value > max[i])
2466 /* Strategy function to convert jiffies to seconds */
2467 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2468 void __user *oldval, size_t __user *oldlenp,
2469 void __user *newval, size_t newlen, void **context)
2474 if (get_user(olen, oldlenp))
2476 if (olen!=sizeof(int))
2479 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2480 (oldlenp && put_user(sizeof(int),oldlenp)))
2483 if (newval && newlen) {
2485 if (newlen != sizeof(int))
2487 if (get_user(new, (int __user *)newval))
2489 *(int *)(table->data) = new*HZ;
2494 /* Strategy function to convert jiffies to seconds */
2495 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2496 void __user *oldval, size_t __user *oldlenp,
2497 void __user *newval, size_t newlen, void **context)
2502 if (get_user(olen, oldlenp))
2504 if (olen!=sizeof(int))
2507 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2508 (oldlenp && put_user(sizeof(int),oldlenp)))
2511 if (newval && newlen) {
2513 if (newlen != sizeof(int))
2515 if (get_user(new, (int __user *)newval))
2517 *(int *)(table->data) = msecs_to_jiffies(new);
2522 #else /* CONFIG_SYSCTL */
2525 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2530 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2531 void __user *oldval, size_t __user *oldlenp,
2532 void __user *newval, size_t newlen, void **context)
2537 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2538 void __user *oldval, size_t __user *oldlenp,
2539 void __user *newval, size_t newlen, void **context)
2544 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2545 void __user *oldval, size_t __user *oldlenp,
2546 void __user *newval, size_t newlen, void **context)
2551 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2552 void __user *oldval, size_t __user *oldlenp,
2553 void __user *newval, size_t newlen, void **context)
2558 int proc_dostring(ctl_table *table, int write, struct file *filp,
2559 void __user *buffer, size_t *lenp, loff_t *ppos)
2564 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2565 void __user *buffer, size_t *lenp, loff_t *ppos)
2570 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2571 void __user *buffer, size_t *lenp, loff_t *ppos)
2576 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2577 void __user *buffer, size_t *lenp, loff_t *ppos)
2582 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2583 void __user *buffer, size_t *lenp, loff_t *ppos)
2588 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2589 void __user *buffer, size_t *lenp, loff_t *ppos)
2594 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2595 void __user *buffer, size_t *lenp, loff_t *ppos)
2600 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2601 void __user *buffer, size_t *lenp, loff_t *ppos)
2606 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2608 void __user *buffer,
2609 size_t *lenp, loff_t *ppos)
2614 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2620 void unregister_sysctl_table(struct ctl_table_header * table)
2624 #endif /* CONFIG_SYSCTL */
2627 * No sense putting this after each symbol definition, twice,
2628 * exception granted :-)
2630 EXPORT_SYMBOL(proc_dointvec);
2631 EXPORT_SYMBOL(proc_dointvec_jiffies);
2632 EXPORT_SYMBOL(proc_dointvec_minmax);
2633 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2634 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2635 EXPORT_SYMBOL(proc_dostring);
2636 EXPORT_SYMBOL(proc_doulongvec_minmax);
2637 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2638 EXPORT_SYMBOL(register_sysctl_table);
2639 EXPORT_SYMBOL(sysctl_intvec);
2640 EXPORT_SYMBOL(sysctl_jiffies);
2641 EXPORT_SYMBOL(sysctl_ms_jiffies);
2642 EXPORT_SYMBOL(sysctl_string);
2643 EXPORT_SYMBOL(unregister_sysctl_table);