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>
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 #if defined(CONFIG_SYSCTL)
57 /* External variables not in a header file. */
59 extern int sysctl_overcommit_memory;
60 extern int sysctl_overcommit_ratio;
61 extern int sysctl_panic_on_oom;
62 extern int max_threads;
63 extern int sysrq_enabled;
64 extern int core_uses_pid;
65 extern int suid_dumpable;
66 extern char core_pattern[];
69 extern int min_free_kbytes;
70 extern int printk_ratelimit_jiffies;
71 extern int printk_ratelimit_burst;
72 extern int pid_max_min, pid_max_max;
73 extern int sysctl_drop_caches;
74 extern int percpu_pagelist_fraction;
75 extern int compat_log;
77 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
78 int unknown_nmi_panic;
79 int nmi_watchdog_enabled;
80 extern int proc_nmi_enabled(struct ctl_table *, int , struct file *,
81 void __user *, size_t *, loff_t *);
84 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
85 static int maxolduid = 65535;
87 static int min_percpu_pagelist_fract = 8;
89 static int ngroups_max = NGROUPS_MAX;
92 extern char modprobe_path[];
94 #ifdef CONFIG_CHR_DEV_SG
95 extern int sg_big_buff;
98 extern size_t shm_ctlmax;
99 extern size_t shm_ctlall;
100 extern int shm_ctlmni;
101 extern int msg_ctlmax;
102 extern int msg_ctlmnb;
103 extern int msg_ctlmni;
104 extern int sem_ctls[];
108 extern char reboot_command [];
109 extern int stop_a_enabled;
110 extern int scons_pwroff;
114 extern int pwrsw_enabled;
115 extern int unaligned_enabled;
119 #ifdef CONFIG_MATHEMU
120 extern int sysctl_ieee_emulation_warnings;
122 extern int sysctl_userprocess_debug;
123 extern int spin_retry;
126 extern int sysctl_hz_timer;
128 #ifdef CONFIG_BSD_PROCESS_ACCT
129 extern int acct_parm[];
133 extern int no_unaligned_warning;
136 #ifdef CONFIG_RT_MUTEXES
137 extern int max_lock_depth;
140 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
141 ctl_table *, void **);
142 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
143 void __user *buffer, size_t *lenp, loff_t *ppos);
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[];
158 #ifdef CONFIG_INOTIFY_USER
159 extern ctl_table inotify_table[];
162 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
163 int sysctl_legacy_va_layout;
166 /* /proc declarations: */
168 #ifdef CONFIG_PROC_FS
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 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 *);
186 /* The default sysctl tables: */
188 static ctl_table root_table[] = {
190 .ctl_name = CTL_KERN,
191 .procname = "kernel",
216 .ctl_name = CTL_DEBUG,
219 .child = debug_table,
231 static ctl_table kern_table[] = {
233 .ctl_name = KERN_OSTYPE,
234 .procname = "ostype",
235 .data = system_utsname.sysname,
236 .maxlen = sizeof(system_utsname.sysname),
238 .proc_handler = &proc_doutsstring,
239 .strategy = &sysctl_string,
242 .ctl_name = KERN_OSRELEASE,
243 .procname = "osrelease",
244 .data = system_utsname.release,
245 .maxlen = sizeof(system_utsname.release),
247 .proc_handler = &proc_doutsstring,
248 .strategy = &sysctl_string,
251 .ctl_name = KERN_VERSION,
252 .procname = "version",
253 .data = system_utsname.version,
254 .maxlen = sizeof(system_utsname.version),
256 .proc_handler = &proc_doutsstring,
257 .strategy = &sysctl_string,
260 .ctl_name = KERN_NODENAME,
261 .procname = "hostname",
262 .data = system_utsname.nodename,
263 .maxlen = sizeof(system_utsname.nodename),
265 .proc_handler = &proc_doutsstring,
266 .strategy = &sysctl_string,
269 .ctl_name = KERN_DOMAINNAME,
270 .procname = "domainname",
271 .data = system_utsname.domainname,
272 .maxlen = sizeof(system_utsname.domainname),
274 .proc_handler = &proc_doutsstring,
275 .strategy = &sysctl_string,
278 .ctl_name = KERN_PANIC,
280 .data = &panic_timeout,
281 .maxlen = sizeof(int),
283 .proc_handler = &proc_dointvec,
286 .ctl_name = KERN_CORE_USES_PID,
287 .procname = "core_uses_pid",
288 .data = &core_uses_pid,
289 .maxlen = sizeof(int),
291 .proc_handler = &proc_dointvec,
294 .ctl_name = KERN_CORE_PATTERN,
295 .procname = "core_pattern",
296 .data = core_pattern,
299 .proc_handler = &proc_dostring,
300 .strategy = &sysctl_string,
303 .ctl_name = KERN_TAINTED,
304 .procname = "tainted",
306 .maxlen = sizeof(int),
308 .proc_handler = &proc_dointvec,
311 .ctl_name = KERN_CAP_BSET,
312 .procname = "cap-bound",
314 .maxlen = sizeof(kernel_cap_t),
316 .proc_handler = &proc_dointvec_bset,
318 #ifdef CONFIG_BLK_DEV_INITRD
320 .ctl_name = KERN_REALROOTDEV,
321 .procname = "real-root-dev",
322 .data = &real_root_dev,
323 .maxlen = sizeof(int),
325 .proc_handler = &proc_dointvec,
330 .ctl_name = KERN_SPARC_REBOOT,
331 .procname = "reboot-cmd",
332 .data = reboot_command,
335 .proc_handler = &proc_dostring,
336 .strategy = &sysctl_string,
339 .ctl_name = KERN_SPARC_STOP_A,
340 .procname = "stop-a",
341 .data = &stop_a_enabled,
342 .maxlen = sizeof (int),
344 .proc_handler = &proc_dointvec,
347 .ctl_name = KERN_SPARC_SCONS_PWROFF,
348 .procname = "scons-poweroff",
349 .data = &scons_pwroff,
350 .maxlen = sizeof (int),
352 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_HPPA_PWRSW,
358 .procname = "soft-power",
359 .data = &pwrsw_enabled,
360 .maxlen = sizeof (int),
362 .proc_handler = &proc_dointvec,
365 .ctl_name = KERN_HPPA_UNALIGNED,
366 .procname = "unaligned-trap",
367 .data = &unaligned_enabled,
368 .maxlen = sizeof (int),
370 .proc_handler = &proc_dointvec,
374 .ctl_name = KERN_CTLALTDEL,
375 .procname = "ctrl-alt-del",
377 .maxlen = sizeof(int),
379 .proc_handler = &proc_dointvec,
382 .ctl_name = KERN_PRINTK,
383 .procname = "printk",
384 .data = &console_loglevel,
385 .maxlen = 4*sizeof(int),
387 .proc_handler = &proc_dointvec,
391 .ctl_name = KERN_MODPROBE,
392 .procname = "modprobe",
393 .data = &modprobe_path,
394 .maxlen = KMOD_PATH_LEN,
396 .proc_handler = &proc_dostring,
397 .strategy = &sysctl_string,
400 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
402 .ctl_name = KERN_HOTPLUG,
403 .procname = "hotplug",
404 .data = &uevent_helper,
405 .maxlen = UEVENT_HELPER_PATH_LEN,
407 .proc_handler = &proc_dostring,
408 .strategy = &sysctl_string,
411 #ifdef CONFIG_CHR_DEV_SG
413 .ctl_name = KERN_SG_BIG_BUFF,
414 .procname = "sg-big-buff",
415 .data = &sg_big_buff,
416 .maxlen = sizeof (int),
418 .proc_handler = &proc_dointvec,
421 #ifdef CONFIG_BSD_PROCESS_ACCT
423 .ctl_name = KERN_ACCT,
426 .maxlen = 3*sizeof(int),
428 .proc_handler = &proc_dointvec,
431 #ifdef CONFIG_SYSVIPC
433 .ctl_name = KERN_SHMMAX,
434 .procname = "shmmax",
436 .maxlen = sizeof (size_t),
438 .proc_handler = &proc_doulongvec_minmax,
441 .ctl_name = KERN_SHMALL,
442 .procname = "shmall",
444 .maxlen = sizeof (size_t),
446 .proc_handler = &proc_doulongvec_minmax,
449 .ctl_name = KERN_SHMMNI,
450 .procname = "shmmni",
452 .maxlen = sizeof (int),
454 .proc_handler = &proc_dointvec,
457 .ctl_name = KERN_MSGMAX,
458 .procname = "msgmax",
460 .maxlen = sizeof (int),
462 .proc_handler = &proc_dointvec,
465 .ctl_name = KERN_MSGMNI,
466 .procname = "msgmni",
468 .maxlen = sizeof (int),
470 .proc_handler = &proc_dointvec,
473 .ctl_name = KERN_MSGMNB,
474 .procname = "msgmnb",
476 .maxlen = sizeof (int),
478 .proc_handler = &proc_dointvec,
481 .ctl_name = KERN_SEM,
484 .maxlen = 4*sizeof (int),
486 .proc_handler = &proc_dointvec,
489 #ifdef CONFIG_MAGIC_SYSRQ
491 .ctl_name = KERN_SYSRQ,
493 .data = &sysrq_enabled,
494 .maxlen = sizeof (int),
496 .proc_handler = &proc_dointvec,
500 .ctl_name = KERN_CADPID,
501 .procname = "cad_pid",
503 .maxlen = sizeof (int),
505 .proc_handler = &proc_dointvec,
508 .ctl_name = KERN_MAX_THREADS,
509 .procname = "threads-max",
510 .data = &max_threads,
511 .maxlen = sizeof(int),
513 .proc_handler = &proc_dointvec,
516 .ctl_name = KERN_RANDOM,
517 .procname = "random",
519 .child = random_table,
521 #ifdef CONFIG_UNIX98_PTYS
523 .ctl_name = KERN_PTY,
530 .ctl_name = KERN_OVERFLOWUID,
531 .procname = "overflowuid",
532 .data = &overflowuid,
533 .maxlen = sizeof(int),
535 .proc_handler = &proc_dointvec_minmax,
536 .strategy = &sysctl_intvec,
537 .extra1 = &minolduid,
538 .extra2 = &maxolduid,
541 .ctl_name = KERN_OVERFLOWGID,
542 .procname = "overflowgid",
543 .data = &overflowgid,
544 .maxlen = sizeof(int),
546 .proc_handler = &proc_dointvec_minmax,
547 .strategy = &sysctl_intvec,
548 .extra1 = &minolduid,
549 .extra2 = &maxolduid,
552 #ifdef CONFIG_MATHEMU
554 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
555 .procname = "ieee_emulation_warnings",
556 .data = &sysctl_ieee_emulation_warnings,
557 .maxlen = sizeof(int),
559 .proc_handler = &proc_dointvec,
562 #ifdef CONFIG_NO_IDLE_HZ
564 .ctl_name = KERN_HZ_TIMER,
565 .procname = "hz_timer",
566 .data = &sysctl_hz_timer,
567 .maxlen = sizeof(int),
569 .proc_handler = &proc_dointvec,
573 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
574 .procname = "userprocess_debug",
575 .data = &sysctl_userprocess_debug,
576 .maxlen = sizeof(int),
578 .proc_handler = &proc_dointvec,
582 .ctl_name = KERN_PIDMAX,
583 .procname = "pid_max",
585 .maxlen = sizeof (int),
587 .proc_handler = &proc_dointvec_minmax,
588 .strategy = sysctl_intvec,
589 .extra1 = &pid_max_min,
590 .extra2 = &pid_max_max,
593 .ctl_name = KERN_PANIC_ON_OOPS,
594 .procname = "panic_on_oops",
595 .data = &panic_on_oops,
596 .maxlen = sizeof(int),
598 .proc_handler = &proc_dointvec,
601 .ctl_name = KERN_PRINTK_RATELIMIT,
602 .procname = "printk_ratelimit",
603 .data = &printk_ratelimit_jiffies,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec_jiffies,
607 .strategy = &sysctl_jiffies,
610 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
611 .procname = "printk_ratelimit_burst",
612 .data = &printk_ratelimit_burst,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
618 .ctl_name = KERN_NGROUPS_MAX,
619 .procname = "ngroups_max",
620 .data = &ngroups_max,
621 .maxlen = sizeof (int),
623 .proc_handler = &proc_dointvec,
625 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
627 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
628 .procname = "unknown_nmi_panic",
629 .data = &unknown_nmi_panic,
630 .maxlen = sizeof (int),
632 .proc_handler = &proc_dointvec,
635 .ctl_name = KERN_NMI_WATCHDOG,
636 .procname = "nmi_watchdog",
637 .data = &nmi_watchdog_enabled,
638 .maxlen = sizeof (int),
640 .proc_handler = &proc_nmi_enabled,
643 #if defined(CONFIG_X86)
645 .ctl_name = KERN_BOOTLOADER_TYPE,
646 .procname = "bootloader_type",
647 .data = &bootloader_type,
648 .maxlen = sizeof (int),
650 .proc_handler = &proc_dointvec,
653 #if defined(CONFIG_MMU)
655 .ctl_name = KERN_RANDOMIZE,
656 .procname = "randomize_va_space",
657 .data = &randomize_va_space,
658 .maxlen = sizeof(int),
660 .proc_handler = &proc_dointvec,
663 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
665 .ctl_name = KERN_SPIN_RETRY,
666 .procname = "spin_retry",
668 .maxlen = sizeof (int),
670 .proc_handler = &proc_dointvec,
673 #ifdef CONFIG_ACPI_SLEEP
675 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
676 .procname = "acpi_video_flags",
677 .data = &acpi_video_flags,
678 .maxlen = sizeof (unsigned long),
680 .proc_handler = &proc_doulongvec_minmax,
685 .ctl_name = KERN_IA64_UNALIGNED,
686 .procname = "ignore-unaligned-usertrap",
687 .data = &no_unaligned_warning,
688 .maxlen = sizeof (int),
690 .proc_handler = &proc_dointvec,
695 .ctl_name = KERN_COMPAT_LOG,
696 .procname = "compat-log",
698 .maxlen = sizeof (int),
700 .proc_handler = &proc_dointvec,
703 #ifdef CONFIG_RT_MUTEXES
705 .ctl_name = KERN_MAX_LOCK_DEPTH,
706 .procname = "max_lock_depth",
707 .data = &max_lock_depth,
708 .maxlen = sizeof(int),
710 .proc_handler = &proc_dointvec,
717 /* Constants for minimum and maximum testing in vm_table.
718 We use these as one-element integer vectors. */
720 static int one_hundred = 100;
723 static ctl_table vm_table[] = {
725 .ctl_name = VM_OVERCOMMIT_MEMORY,
726 .procname = "overcommit_memory",
727 .data = &sysctl_overcommit_memory,
728 .maxlen = sizeof(sysctl_overcommit_memory),
730 .proc_handler = &proc_dointvec,
733 .ctl_name = VM_PANIC_ON_OOM,
734 .procname = "panic_on_oom",
735 .data = &sysctl_panic_on_oom,
736 .maxlen = sizeof(sysctl_panic_on_oom),
738 .proc_handler = &proc_dointvec,
741 .ctl_name = VM_OVERCOMMIT_RATIO,
742 .procname = "overcommit_ratio",
743 .data = &sysctl_overcommit_ratio,
744 .maxlen = sizeof(sysctl_overcommit_ratio),
746 .proc_handler = &proc_dointvec,
749 .ctl_name = VM_PAGE_CLUSTER,
750 .procname = "page-cluster",
751 .data = &page_cluster,
752 .maxlen = sizeof(int),
754 .proc_handler = &proc_dointvec,
757 .ctl_name = VM_DIRTY_BACKGROUND,
758 .procname = "dirty_background_ratio",
759 .data = &dirty_background_ratio,
760 .maxlen = sizeof(dirty_background_ratio),
762 .proc_handler = &proc_dointvec_minmax,
763 .strategy = &sysctl_intvec,
765 .extra2 = &one_hundred,
768 .ctl_name = VM_DIRTY_RATIO,
769 .procname = "dirty_ratio",
770 .data = &vm_dirty_ratio,
771 .maxlen = sizeof(vm_dirty_ratio),
773 .proc_handler = &proc_dointvec_minmax,
774 .strategy = &sysctl_intvec,
776 .extra2 = &one_hundred,
779 .ctl_name = VM_DIRTY_WB_CS,
780 .procname = "dirty_writeback_centisecs",
781 .data = &dirty_writeback_interval,
782 .maxlen = sizeof(dirty_writeback_interval),
784 .proc_handler = &dirty_writeback_centisecs_handler,
787 .ctl_name = VM_DIRTY_EXPIRE_CS,
788 .procname = "dirty_expire_centisecs",
789 .data = &dirty_expire_interval,
790 .maxlen = sizeof(dirty_expire_interval),
792 .proc_handler = &proc_dointvec_userhz_jiffies,
795 .ctl_name = VM_NR_PDFLUSH_THREADS,
796 .procname = "nr_pdflush_threads",
797 .data = &nr_pdflush_threads,
798 .maxlen = sizeof nr_pdflush_threads,
799 .mode = 0444 /* read-only*/,
800 .proc_handler = &proc_dointvec,
803 .ctl_name = VM_SWAPPINESS,
804 .procname = "swappiness",
805 .data = &vm_swappiness,
806 .maxlen = sizeof(vm_swappiness),
808 .proc_handler = &proc_dointvec_minmax,
809 .strategy = &sysctl_intvec,
811 .extra2 = &one_hundred,
813 #ifdef CONFIG_HUGETLB_PAGE
815 .ctl_name = VM_HUGETLB_PAGES,
816 .procname = "nr_hugepages",
817 .data = &max_huge_pages,
818 .maxlen = sizeof(unsigned long),
820 .proc_handler = &hugetlb_sysctl_handler,
821 .extra1 = (void *)&hugetlb_zero,
822 .extra2 = (void *)&hugetlb_infinity,
825 .ctl_name = VM_HUGETLB_GROUP,
826 .procname = "hugetlb_shm_group",
827 .data = &sysctl_hugetlb_shm_group,
828 .maxlen = sizeof(gid_t),
830 .proc_handler = &proc_dointvec,
834 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
835 .procname = "lowmem_reserve_ratio",
836 .data = &sysctl_lowmem_reserve_ratio,
837 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
839 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
840 .strategy = &sysctl_intvec,
843 .ctl_name = VM_DROP_PAGECACHE,
844 .procname = "drop_caches",
845 .data = &sysctl_drop_caches,
846 .maxlen = sizeof(int),
848 .proc_handler = drop_caches_sysctl_handler,
849 .strategy = &sysctl_intvec,
852 .ctl_name = VM_MIN_FREE_KBYTES,
853 .procname = "min_free_kbytes",
854 .data = &min_free_kbytes,
855 .maxlen = sizeof(min_free_kbytes),
857 .proc_handler = &min_free_kbytes_sysctl_handler,
858 .strategy = &sysctl_intvec,
862 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
863 .procname = "percpu_pagelist_fraction",
864 .data = &percpu_pagelist_fraction,
865 .maxlen = sizeof(percpu_pagelist_fraction),
867 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
868 .strategy = &sysctl_intvec,
869 .extra1 = &min_percpu_pagelist_fract,
873 .ctl_name = VM_MAX_MAP_COUNT,
874 .procname = "max_map_count",
875 .data = &sysctl_max_map_count,
876 .maxlen = sizeof(sysctl_max_map_count),
878 .proc_handler = &proc_dointvec
882 .ctl_name = VM_LAPTOP_MODE,
883 .procname = "laptop_mode",
884 .data = &laptop_mode,
885 .maxlen = sizeof(laptop_mode),
887 .proc_handler = &proc_dointvec_jiffies,
888 .strategy = &sysctl_jiffies,
891 .ctl_name = VM_BLOCK_DUMP,
892 .procname = "block_dump",
894 .maxlen = sizeof(block_dump),
896 .proc_handler = &proc_dointvec,
897 .strategy = &sysctl_intvec,
901 .ctl_name = VM_VFS_CACHE_PRESSURE,
902 .procname = "vfs_cache_pressure",
903 .data = &sysctl_vfs_cache_pressure,
904 .maxlen = sizeof(sysctl_vfs_cache_pressure),
906 .proc_handler = &proc_dointvec,
907 .strategy = &sysctl_intvec,
910 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
912 .ctl_name = VM_LEGACY_VA_LAYOUT,
913 .procname = "legacy_va_layout",
914 .data = &sysctl_legacy_va_layout,
915 .maxlen = sizeof(sysctl_legacy_va_layout),
917 .proc_handler = &proc_dointvec,
918 .strategy = &sysctl_intvec,
924 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
925 .procname = "swap_token_timeout",
926 .data = &swap_token_default_timeout,
927 .maxlen = sizeof(swap_token_default_timeout),
929 .proc_handler = &proc_dointvec_jiffies,
930 .strategy = &sysctl_jiffies,
935 .ctl_name = VM_ZONE_RECLAIM_MODE,
936 .procname = "zone_reclaim_mode",
937 .data = &zone_reclaim_mode,
938 .maxlen = sizeof(zone_reclaim_mode),
940 .proc_handler = &proc_dointvec,
941 .strategy = &sysctl_intvec,
945 .ctl_name = VM_MIN_UNMAPPED,
946 .procname = "min_unmapped_ratio",
947 .data = &sysctl_min_unmapped_ratio,
948 .maxlen = sizeof(sysctl_min_unmapped_ratio),
950 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
951 .strategy = &sysctl_intvec,
953 .extra2 = &one_hundred,
958 .ctl_name = VM_VDSO_ENABLED,
959 .procname = "vdso_enabled",
960 .data = &vdso_enabled,
961 .maxlen = sizeof(vdso_enabled),
963 .proc_handler = &proc_dointvec,
964 .strategy = &sysctl_intvec,
971 static ctl_table fs_table[] = {
973 .ctl_name = FS_NRINODE,
974 .procname = "inode-nr",
975 .data = &inodes_stat,
976 .maxlen = 2*sizeof(int),
978 .proc_handler = &proc_dointvec,
981 .ctl_name = FS_STATINODE,
982 .procname = "inode-state",
983 .data = &inodes_stat,
984 .maxlen = 7*sizeof(int),
986 .proc_handler = &proc_dointvec,
989 .ctl_name = FS_NRFILE,
990 .procname = "file-nr",
992 .maxlen = 3*sizeof(int),
994 .proc_handler = &proc_nr_files,
997 .ctl_name = FS_MAXFILE,
998 .procname = "file-max",
999 .data = &files_stat.max_files,
1000 .maxlen = sizeof(int),
1002 .proc_handler = &proc_dointvec,
1005 .ctl_name = FS_DENTRY,
1006 .procname = "dentry-state",
1007 .data = &dentry_stat,
1008 .maxlen = 6*sizeof(int),
1010 .proc_handler = &proc_dointvec,
1013 .ctl_name = FS_OVERFLOWUID,
1014 .procname = "overflowuid",
1015 .data = &fs_overflowuid,
1016 .maxlen = sizeof(int),
1018 .proc_handler = &proc_dointvec_minmax,
1019 .strategy = &sysctl_intvec,
1020 .extra1 = &minolduid,
1021 .extra2 = &maxolduid,
1024 .ctl_name = FS_OVERFLOWGID,
1025 .procname = "overflowgid",
1026 .data = &fs_overflowgid,
1027 .maxlen = sizeof(int),
1029 .proc_handler = &proc_dointvec_minmax,
1030 .strategy = &sysctl_intvec,
1031 .extra1 = &minolduid,
1032 .extra2 = &maxolduid,
1035 .ctl_name = FS_LEASES,
1036 .procname = "leases-enable",
1037 .data = &leases_enable,
1038 .maxlen = sizeof(int),
1040 .proc_handler = &proc_dointvec,
1042 #ifdef CONFIG_DNOTIFY
1044 .ctl_name = FS_DIR_NOTIFY,
1045 .procname = "dir-notify-enable",
1046 .data = &dir_notify_enable,
1047 .maxlen = sizeof(int),
1049 .proc_handler = &proc_dointvec,
1054 .ctl_name = FS_LEASE_TIME,
1055 .procname = "lease-break-time",
1056 .data = &lease_break_time,
1057 .maxlen = sizeof(int),
1059 .proc_handler = &proc_dointvec,
1062 .ctl_name = FS_AIO_NR,
1063 .procname = "aio-nr",
1065 .maxlen = sizeof(aio_nr),
1067 .proc_handler = &proc_doulongvec_minmax,
1070 .ctl_name = FS_AIO_MAX_NR,
1071 .procname = "aio-max-nr",
1072 .data = &aio_max_nr,
1073 .maxlen = sizeof(aio_max_nr),
1075 .proc_handler = &proc_doulongvec_minmax,
1077 #ifdef CONFIG_INOTIFY_USER
1079 .ctl_name = FS_INOTIFY,
1080 .procname = "inotify",
1082 .child = inotify_table,
1087 .ctl_name = KERN_SETUID_DUMPABLE,
1088 .procname = "suid_dumpable",
1089 .data = &suid_dumpable,
1090 .maxlen = sizeof(int),
1092 .proc_handler = &proc_dointvec,
1097 static ctl_table debug_table[] = {
1101 static ctl_table dev_table[] = {
1105 extern void init_irq_proc (void);
1107 static DEFINE_SPINLOCK(sysctl_lock);
1109 /* called under sysctl_lock */
1110 static int use_table(struct ctl_table_header *p)
1112 if (unlikely(p->unregistering))
1118 /* called under sysctl_lock */
1119 static void unuse_table(struct ctl_table_header *p)
1122 if (unlikely(p->unregistering))
1123 complete(p->unregistering);
1126 /* called under sysctl_lock, will reacquire if has to wait */
1127 static void start_unregistering(struct ctl_table_header *p)
1130 * if p->used is 0, nobody will ever touch that entry again;
1131 * we'll eliminate all paths to it before dropping sysctl_lock
1133 if (unlikely(p->used)) {
1134 struct completion wait;
1135 init_completion(&wait);
1136 p->unregistering = &wait;
1137 spin_unlock(&sysctl_lock);
1138 wait_for_completion(&wait);
1139 spin_lock(&sysctl_lock);
1142 * do not remove from the list until nobody holds it; walking the
1143 * list in do_sysctl() relies on that.
1145 list_del_init(&p->ctl_entry);
1148 void __init sysctl_init(void)
1150 #ifdef CONFIG_PROC_FS
1151 register_proc_table(root_table, proc_sys_root, &root_table_header);
1156 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1157 void __user *newval, size_t newlen)
1159 struct list_head *tmp;
1160 int error = -ENOTDIR;
1162 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1166 if (!oldlenp || get_user(old_len, oldlenp))
1169 spin_lock(&sysctl_lock);
1170 tmp = &root_table_header.ctl_entry;
1172 struct ctl_table_header *head =
1173 list_entry(tmp, struct ctl_table_header, ctl_entry);
1174 void *context = NULL;
1176 if (!use_table(head))
1179 spin_unlock(&sysctl_lock);
1181 error = parse_table(name, nlen, oldval, oldlenp,
1182 newval, newlen, head->ctl_table,
1186 spin_lock(&sysctl_lock);
1188 if (error != -ENOTDIR)
1190 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1191 spin_unlock(&sysctl_lock);
1195 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1197 struct __sysctl_args tmp;
1200 if (copy_from_user(&tmp, args, sizeof(tmp)))
1204 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1205 tmp.newval, tmp.newlen);
1211 * ctl_perm does NOT grant the superuser all rights automatically, because
1212 * some sysctl variables are readonly even to root.
1215 static int test_perm(int mode, int op)
1219 else if (in_egroup_p(0))
1221 if ((mode & op & 0007) == op)
1226 static inline int ctl_perm(ctl_table *table, int op)
1229 error = security_sysctl(table, op);
1232 return test_perm(table->mode, op);
1235 static int parse_table(int __user *name, int nlen,
1236 void __user *oldval, size_t __user *oldlenp,
1237 void __user *newval, size_t newlen,
1238 ctl_table *table, void **context)
1244 if (get_user(n, name))
1246 for ( ; table->ctl_name; table++) {
1247 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1250 if (ctl_perm(table, 001))
1252 if (table->strategy) {
1253 error = table->strategy(
1256 newval, newlen, context);
1262 table = table->child;
1265 error = do_sysctl_strategy(table, name, nlen,
1267 newval, newlen, context);
1274 /* Perform the actual read/write of a sysctl table entry. */
1275 int do_sysctl_strategy (ctl_table *table,
1276 int __user *name, int nlen,
1277 void __user *oldval, size_t __user *oldlenp,
1278 void __user *newval, size_t newlen, void **context)
1287 if (ctl_perm(table, op))
1290 if (table->strategy) {
1291 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1292 newval, newlen, context);
1299 /* If there is no strategy routine, or if the strategy returns
1300 * zero, proceed with automatic r/w */
1301 if (table->data && table->maxlen) {
1302 if (oldval && oldlenp) {
1303 if (get_user(len, oldlenp))
1306 if (len > table->maxlen)
1307 len = table->maxlen;
1308 if(copy_to_user(oldval, table->data, len))
1310 if(put_user(len, oldlenp))
1314 if (newval && newlen) {
1316 if (len > table->maxlen)
1317 len = table->maxlen;
1318 if(copy_from_user(table->data, newval, len))
1326 * register_sysctl_table - register a sysctl hierarchy
1327 * @table: the top-level table structure
1328 * @insert_at_head: whether the entry should be inserted in front or at the end
1330 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1331 * array. An entry with a ctl_name of 0 terminates the table.
1333 * The members of the &ctl_table structure are used as follows:
1335 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1336 * must be unique within that level of sysctl
1338 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1339 * enter a sysctl file
1341 * data - a pointer to data for use by proc_handler
1343 * maxlen - the maximum size in bytes of the data
1345 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1347 * child - a pointer to the child sysctl table if this entry is a directory, or
1350 * proc_handler - the text handler routine (described below)
1352 * strategy - the strategy routine (described below)
1354 * de - for internal use by the sysctl routines
1356 * extra1, extra2 - extra pointers usable by the proc handler routines
1358 * Leaf nodes in the sysctl tree will be represented by a single file
1359 * under /proc; non-leaf nodes will be represented by directories.
1361 * sysctl(2) can automatically manage read and write requests through
1362 * the sysctl table. The data and maxlen fields of the ctl_table
1363 * struct enable minimal validation of the values being written to be
1364 * performed, and the mode field allows minimal authentication.
1366 * More sophisticated management can be enabled by the provision of a
1367 * strategy routine with the table entry. This will be called before
1368 * any automatic read or write of the data is performed.
1370 * The strategy routine may return
1372 * < 0 - Error occurred (error is passed to user process)
1374 * 0 - OK - proceed with automatic read or write.
1376 * > 0 - OK - read or write has been done by the strategy routine, so
1377 * return immediately.
1379 * There must be a proc_handler routine for any terminal nodes
1380 * mirrored under /proc/sys (non-terminals are handled by a built-in
1381 * directory handler). Several default handlers are available to
1382 * cover common cases -
1384 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1385 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1386 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1388 * It is the handler's job to read the input buffer from user memory
1389 * and process it. The handler should return 0 on success.
1391 * This routine returns %NULL on a failure to register, and a pointer
1392 * to the table header on success.
1394 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1397 struct ctl_table_header *tmp;
1398 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1401 tmp->ctl_table = table;
1402 INIT_LIST_HEAD(&tmp->ctl_entry);
1404 tmp->unregistering = NULL;
1405 spin_lock(&sysctl_lock);
1407 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1409 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1410 spin_unlock(&sysctl_lock);
1411 #ifdef CONFIG_PROC_FS
1412 register_proc_table(table, proc_sys_root, tmp);
1418 * unregister_sysctl_table - unregister a sysctl table hierarchy
1419 * @header: the header returned from register_sysctl_table
1421 * Unregisters the sysctl table and all children. proc entries may not
1422 * actually be removed until they are no longer used by anyone.
1424 void unregister_sysctl_table(struct ctl_table_header * header)
1427 spin_lock(&sysctl_lock);
1428 start_unregistering(header);
1429 #ifdef CONFIG_PROC_FS
1430 unregister_proc_table(header->ctl_table, proc_sys_root);
1432 spin_unlock(&sysctl_lock);
1440 #ifdef CONFIG_PROC_FS
1442 /* Scan the sysctl entries in table and add them all into /proc */
1443 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1445 struct proc_dir_entry *de;
1449 for (; table->ctl_name; table++) {
1450 /* Can't do anything without a proc name. */
1451 if (!table->procname)
1453 /* Maybe we can't do anything with it... */
1454 if (!table->proc_handler && !table->child) {
1455 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1460 len = strlen(table->procname);
1464 if (table->proc_handler)
1468 for (de = root->subdir; de; de = de->next) {
1469 if (proc_match(len, table->procname, de))
1472 /* If the subdir exists already, de is non-NULL */
1476 de = create_proc_entry(table->procname, mode, root);
1480 de->data = (void *) table;
1481 if (table->proc_handler)
1482 de->proc_fops = &proc_sys_file_operations;
1485 if (de->mode & S_IFDIR)
1486 register_proc_table(table->child, de, set);
1491 * Unregister a /proc sysctl table and any subdirectories.
1493 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1495 struct proc_dir_entry *de;
1496 for (; table->ctl_name; table++) {
1497 if (!(de = table->de))
1499 if (de->mode & S_IFDIR) {
1500 if (!table->child) {
1501 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1504 unregister_proc_table(table->child, de);
1506 /* Don't unregister directories which still have entries.. */
1512 * In any case, mark the entry as goner; we'll keep it
1513 * around if it's busy, but we'll know to do nothing with
1514 * its fields. We are under sysctl_lock here.
1518 /* Don't unregister proc entries that are still being used.. */
1519 if (atomic_read(&de->count))
1523 remove_proc_entry(table->procname, root);
1527 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1528 size_t count, loff_t *ppos)
1531 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1532 struct ctl_table *table;
1534 ssize_t error = -ENOTDIR;
1536 spin_lock(&sysctl_lock);
1537 if (de && de->data && use_table(de->set)) {
1539 * at that point we know that sysctl was not unregistered
1540 * and won't be until we finish
1542 spin_unlock(&sysctl_lock);
1543 table = (struct ctl_table *) de->data;
1544 if (!table || !table->proc_handler)
1547 op = (write ? 002 : 004);
1548 if (ctl_perm(table, op))
1551 /* careful: calling conventions are nasty here */
1553 error = (*table->proc_handler)(table, write, file,
1558 spin_lock(&sysctl_lock);
1559 unuse_table(de->set);
1561 spin_unlock(&sysctl_lock);
1565 static int proc_opensys(struct inode *inode, struct file *file)
1567 if (file->f_mode & FMODE_WRITE) {
1569 * sysctl entries that are not writable,
1570 * are _NOT_ writable, capabilities or not.
1572 if (!(inode->i_mode & S_IWUSR))
1579 static ssize_t proc_readsys(struct file * file, char __user * buf,
1580 size_t count, loff_t *ppos)
1582 return do_rw_proc(0, file, buf, count, ppos);
1585 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1586 size_t count, loff_t *ppos)
1588 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1592 * proc_dostring - read a string sysctl
1593 * @table: the sysctl table
1594 * @write: %TRUE if this is a write to the sysctl file
1595 * @filp: the file structure
1596 * @buffer: the user buffer
1597 * @lenp: the size of the user buffer
1598 * @ppos: file position
1600 * Reads/writes a string from/to the user buffer. If the kernel
1601 * buffer provided is not large enough to hold the string, the
1602 * string is truncated. The copied string is %NULL-terminated.
1603 * If the string is being read by the user process, it is copied
1604 * and a newline '\n' is added. It is truncated if the buffer is
1607 * Returns 0 on success.
1609 int proc_dostring(ctl_table *table, int write, struct file *filp,
1610 void __user *buffer, size_t *lenp, loff_t *ppos)
1616 if (!table->data || !table->maxlen || !*lenp ||
1617 (*ppos && !write)) {
1625 while (len < *lenp) {
1626 if (get_user(c, p++))
1628 if (c == 0 || c == '\n')
1632 if (len >= table->maxlen)
1633 len = table->maxlen-1;
1634 if(copy_from_user(table->data, buffer, len))
1636 ((char *) table->data)[len] = 0;
1639 len = strlen(table->data);
1640 if (len > table->maxlen)
1641 len = table->maxlen;
1645 if(copy_to_user(buffer, table->data, len))
1648 if(put_user('\n', ((char __user *) buffer) + len))
1659 * Special case of dostring for the UTS structure. This has locks
1660 * to observe. Should this be in kernel/sys.c ????
1663 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1664 void __user *buffer, size_t *lenp, loff_t *ppos)
1669 down_read(&uts_sem);
1670 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1673 down_write(&uts_sem);
1674 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1680 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1682 int write, void *data)
1685 *valp = *negp ? -*lvalp : *lvalp;
1690 *lvalp = (unsigned long)-val;
1693 *lvalp = (unsigned long)val;
1699 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1700 void __user *buffer, size_t *lenp, loff_t *ppos,
1701 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1702 int write, void *data),
1705 #define TMPBUFLEN 21
1706 int *i, vleft, first=1, neg, val;
1710 char buf[TMPBUFLEN], *p;
1711 char __user *s = buffer;
1713 if (!table->data || !table->maxlen || !*lenp ||
1714 (*ppos && !write)) {
1719 i = (int *) table->data;
1720 vleft = table->maxlen / sizeof(*i);
1724 conv = do_proc_dointvec_conv;
1726 for (; left && vleft--; i++, first=0) {
1741 if (len > sizeof(buf) - 1)
1742 len = sizeof(buf) - 1;
1743 if (copy_from_user(buf, s, len))
1747 if (*p == '-' && left > 1) {
1751 if (*p < '0' || *p > '9')
1754 lval = simple_strtoul(p, &p, 0);
1757 if ((len < left) && *p && !isspace(*p))
1764 if (conv(&neg, &lval, i, 1, data))
1771 if (conv(&neg, &lval, i, 0, data))
1774 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1778 if(copy_to_user(s, buf, len))
1785 if (!write && !first && left) {
1786 if(put_user('\n', s))
1793 if (get_user(c, s++))
1809 * proc_dointvec - read a vector of integers
1810 * @table: the sysctl table
1811 * @write: %TRUE if this is a write to the sysctl file
1812 * @filp: the file structure
1813 * @buffer: the user buffer
1814 * @lenp: the size of the user buffer
1815 * @ppos: file position
1817 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1818 * values from/to the user buffer, treated as an ASCII string.
1820 * Returns 0 on success.
1822 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1823 void __user *buffer, size_t *lenp, loff_t *ppos)
1825 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1835 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1837 int write, void *data)
1839 int op = *(int *)data;
1841 int val = *negp ? -*lvalp : *lvalp;
1843 case OP_SET: *valp = val; break;
1844 case OP_AND: *valp &= val; break;
1845 case OP_OR: *valp |= val; break;
1846 case OP_MAX: if(*valp < val)
1849 case OP_MIN: if(*valp > val)
1857 *lvalp = (unsigned long)-val;
1860 *lvalp = (unsigned long)val;
1867 * init may raise the set.
1870 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1871 void __user *buffer, size_t *lenp, loff_t *ppos)
1875 if (!capable(CAP_SYS_MODULE)) {
1879 op = (current->pid == 1) ? OP_SET : OP_AND;
1880 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1881 do_proc_dointvec_bset_conv,&op);
1884 struct do_proc_dointvec_minmax_conv_param {
1889 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1891 int write, void *data)
1893 struct do_proc_dointvec_minmax_conv_param *param = data;
1895 int val = *negp ? -*lvalp : *lvalp;
1896 if ((param->min && *param->min > val) ||
1897 (param->max && *param->max < val))
1904 *lvalp = (unsigned long)-val;
1907 *lvalp = (unsigned long)val;
1914 * proc_dointvec_minmax - read a vector of integers with min/max values
1915 * @table: the sysctl table
1916 * @write: %TRUE if this is a write to the sysctl file
1917 * @filp: the file structure
1918 * @buffer: the user buffer
1919 * @lenp: the size of the user buffer
1920 * @ppos: file position
1922 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1923 * values from/to the user buffer, treated as an ASCII string.
1925 * This routine will ensure the values are within the range specified by
1926 * table->extra1 (min) and table->extra2 (max).
1928 * Returns 0 on success.
1930 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1931 void __user *buffer, size_t *lenp, loff_t *ppos)
1933 struct do_proc_dointvec_minmax_conv_param param = {
1934 .min = (int *) table->extra1,
1935 .max = (int *) table->extra2,
1937 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1938 do_proc_dointvec_minmax_conv, ¶m);
1941 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1943 void __user *buffer,
1944 size_t *lenp, loff_t *ppos,
1945 unsigned long convmul,
1946 unsigned long convdiv)
1948 #define TMPBUFLEN 21
1949 unsigned long *i, *min, *max, val;
1950 int vleft, first=1, neg;
1952 char buf[TMPBUFLEN], *p;
1953 char __user *s = buffer;
1955 if (!table->data || !table->maxlen || !*lenp ||
1956 (*ppos && !write)) {
1961 i = (unsigned long *) table->data;
1962 min = (unsigned long *) table->extra1;
1963 max = (unsigned long *) table->extra2;
1964 vleft = table->maxlen / sizeof(unsigned long);
1967 for (; left && vleft--; i++, min++, max++, first=0) {
1982 if (len > TMPBUFLEN-1)
1984 if (copy_from_user(buf, s, len))
1988 if (*p == '-' && left > 1) {
1992 if (*p < '0' || *p > '9')
1994 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1996 if ((len < left) && *p && !isspace(*p))
2005 if ((min && val < *min) || (max && val > *max))
2012 sprintf(p, "%lu", convdiv * (*i) / convmul);
2016 if(copy_to_user(s, buf, len))
2023 if (!write && !first && left) {
2024 if(put_user('\n', s))
2031 if (get_user(c, s++))
2047 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2048 * @table: the sysctl table
2049 * @write: %TRUE if this is a write to the sysctl file
2050 * @filp: the file structure
2051 * @buffer: the user buffer
2052 * @lenp: the size of the user buffer
2053 * @ppos: file position
2055 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2056 * values from/to the user buffer, treated as an ASCII string.
2058 * This routine will ensure the values are within the range specified by
2059 * table->extra1 (min) and table->extra2 (max).
2061 * Returns 0 on success.
2063 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2064 void __user *buffer, size_t *lenp, loff_t *ppos)
2066 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2070 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2071 * @table: the sysctl table
2072 * @write: %TRUE if this is a write to the sysctl file
2073 * @filp: the file structure
2074 * @buffer: the user buffer
2075 * @lenp: the size of the user buffer
2076 * @ppos: file position
2078 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2079 * values from/to the user buffer, treated as an ASCII string. The values
2080 * are treated as milliseconds, and converted to jiffies when they are stored.
2082 * This routine will ensure the values are within the range specified by
2083 * table->extra1 (min) and table->extra2 (max).
2085 * Returns 0 on success.
2087 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2089 void __user *buffer,
2090 size_t *lenp, loff_t *ppos)
2092 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2093 lenp, ppos, HZ, 1000l);
2097 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2099 int write, void *data)
2102 if (*lvalp > LONG_MAX / HZ)
2104 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2110 lval = (unsigned long)-val;
2113 lval = (unsigned long)val;
2120 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2122 int write, void *data)
2125 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2127 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2133 lval = (unsigned long)-val;
2136 lval = (unsigned long)val;
2138 *lvalp = jiffies_to_clock_t(lval);
2143 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2145 int write, void *data)
2148 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2154 lval = (unsigned long)-val;
2157 lval = (unsigned long)val;
2159 *lvalp = jiffies_to_msecs(lval);
2165 * proc_dointvec_jiffies - read a vector of integers as seconds
2166 * @table: the sysctl table
2167 * @write: %TRUE if this is a write to the sysctl file
2168 * @filp: the file structure
2169 * @buffer: the user buffer
2170 * @lenp: the size of the user buffer
2171 * @ppos: file position
2173 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2174 * values from/to the user buffer, treated as an ASCII string.
2175 * The values read are assumed to be in seconds, and are converted into
2178 * Returns 0 on success.
2180 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2181 void __user *buffer, size_t *lenp, loff_t *ppos)
2183 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2184 do_proc_dointvec_jiffies_conv,NULL);
2188 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2189 * @table: the sysctl table
2190 * @write: %TRUE if this is a write to the sysctl file
2191 * @filp: the file structure
2192 * @buffer: the user buffer
2193 * @lenp: the size of the user buffer
2194 * @ppos: pointer to the file position
2196 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2197 * values from/to the user buffer, treated as an ASCII string.
2198 * The values read are assumed to be in 1/USER_HZ seconds, and
2199 * are converted into jiffies.
2201 * Returns 0 on success.
2203 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2204 void __user *buffer, size_t *lenp, loff_t *ppos)
2206 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2207 do_proc_dointvec_userhz_jiffies_conv,NULL);
2211 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2212 * @table: the sysctl table
2213 * @write: %TRUE if this is a write to the sysctl file
2214 * @filp: the file structure
2215 * @buffer: the user buffer
2216 * @lenp: the size of the user buffer
2217 * @ppos: file position
2218 * @ppos: the current position in the file
2220 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2221 * values from/to the user buffer, treated as an ASCII string.
2222 * The values read are assumed to be in 1/1000 seconds, and
2223 * are converted into jiffies.
2225 * Returns 0 on success.
2227 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2228 void __user *buffer, size_t *lenp, loff_t *ppos)
2230 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2231 do_proc_dointvec_ms_jiffies_conv, NULL);
2234 #else /* CONFIG_PROC_FS */
2236 int proc_dostring(ctl_table *table, int write, struct file *filp,
2237 void __user *buffer, size_t *lenp, loff_t *ppos)
2242 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2243 void __user *buffer, size_t *lenp, loff_t *ppos)
2248 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2249 void __user *buffer, size_t *lenp, loff_t *ppos)
2254 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2255 void __user *buffer, size_t *lenp, loff_t *ppos)
2260 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2261 void __user *buffer, size_t *lenp, loff_t *ppos)
2266 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2267 void __user *buffer, size_t *lenp, loff_t *ppos)
2272 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2273 void __user *buffer, size_t *lenp, loff_t *ppos)
2278 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2279 void __user *buffer, size_t *lenp, loff_t *ppos)
2284 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2285 void __user *buffer, size_t *lenp, loff_t *ppos)
2290 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2292 void __user *buffer,
2293 size_t *lenp, loff_t *ppos)
2299 #endif /* CONFIG_PROC_FS */
2303 * General sysctl support routines
2306 /* The generic string strategy routine: */
2307 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2308 void __user *oldval, size_t __user *oldlenp,
2309 void __user *newval, size_t newlen, void **context)
2311 if (!table->data || !table->maxlen)
2314 if (oldval && oldlenp) {
2316 if (get_user(bufsize, oldlenp))
2319 size_t len = strlen(table->data), copied;
2321 /* This shouldn't trigger for a well-formed sysctl */
2322 if (len > table->maxlen)
2323 len = table->maxlen;
2325 /* Copy up to a max of bufsize-1 bytes of the string */
2326 copied = (len >= bufsize) ? bufsize - 1 : len;
2328 if (copy_to_user(oldval, table->data, copied) ||
2329 put_user(0, (char __user *)(oldval + copied)))
2331 if (put_user(len, oldlenp))
2335 if (newval && newlen) {
2336 size_t len = newlen;
2337 if (len > table->maxlen)
2338 len = table->maxlen;
2339 if(copy_from_user(table->data, newval, len))
2341 if (len == table->maxlen)
2343 ((char *) table->data)[len] = 0;
2349 * This function makes sure that all of the integers in the vector
2350 * are between the minimum and maximum values given in the arrays
2351 * table->extra1 and table->extra2, respectively.
2353 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2354 void __user *oldval, size_t __user *oldlenp,
2355 void __user *newval, size_t newlen, void **context)
2358 if (newval && newlen) {
2359 int __user *vec = (int __user *) newval;
2360 int *min = (int *) table->extra1;
2361 int *max = (int *) table->extra2;
2365 if (newlen % sizeof(int) != 0)
2368 if (!table->extra1 && !table->extra2)
2371 if (newlen > table->maxlen)
2372 newlen = table->maxlen;
2373 length = newlen / sizeof(int);
2375 for (i = 0; i < length; i++) {
2377 if (get_user(value, vec + i))
2379 if (min && value < min[i])
2381 if (max && value > max[i])
2388 /* Strategy function to convert jiffies to seconds */
2389 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2390 void __user *oldval, size_t __user *oldlenp,
2391 void __user *newval, size_t newlen, void **context)
2396 if (get_user(olen, oldlenp))
2398 if (olen!=sizeof(int))
2401 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2402 (oldlenp && put_user(sizeof(int),oldlenp)))
2405 if (newval && newlen) {
2407 if (newlen != sizeof(int))
2409 if (get_user(new, (int __user *)newval))
2411 *(int *)(table->data) = new*HZ;
2416 /* Strategy function to convert jiffies to seconds */
2417 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2418 void __user *oldval, size_t __user *oldlenp,
2419 void __user *newval, size_t newlen, void **context)
2424 if (get_user(olen, oldlenp))
2426 if (olen!=sizeof(int))
2429 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2430 (oldlenp && put_user(sizeof(int),oldlenp)))
2433 if (newval && newlen) {
2435 if (newlen != sizeof(int))
2437 if (get_user(new, (int __user *)newval))
2439 *(int *)(table->data) = msecs_to_jiffies(new);
2444 #else /* CONFIG_SYSCTL */
2447 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2452 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2453 void __user *oldval, size_t __user *oldlenp,
2454 void __user *newval, size_t newlen, void **context)
2459 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2460 void __user *oldval, size_t __user *oldlenp,
2461 void __user *newval, size_t newlen, void **context)
2466 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2467 void __user *oldval, size_t __user *oldlenp,
2468 void __user *newval, size_t newlen, void **context)
2473 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2474 void __user *oldval, size_t __user *oldlenp,
2475 void __user *newval, size_t newlen, void **context)
2480 int proc_dostring(ctl_table *table, int write, struct file *filp,
2481 void __user *buffer, size_t *lenp, loff_t *ppos)
2486 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2487 void __user *buffer, size_t *lenp, loff_t *ppos)
2492 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2493 void __user *buffer, size_t *lenp, loff_t *ppos)
2498 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2499 void __user *buffer, size_t *lenp, loff_t *ppos)
2504 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2505 void __user *buffer, size_t *lenp, loff_t *ppos)
2510 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2511 void __user *buffer, size_t *lenp, loff_t *ppos)
2516 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2517 void __user *buffer, size_t *lenp, loff_t *ppos)
2522 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2523 void __user *buffer, size_t *lenp, loff_t *ppos)
2528 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2530 void __user *buffer,
2531 size_t *lenp, loff_t *ppos)
2536 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2542 void unregister_sysctl_table(struct ctl_table_header * table)
2546 #endif /* CONFIG_SYSCTL */
2549 * No sense putting this after each symbol definition, twice,
2550 * exception granted :-)
2552 EXPORT_SYMBOL(proc_dointvec);
2553 EXPORT_SYMBOL(proc_dointvec_jiffies);
2554 EXPORT_SYMBOL(proc_dointvec_minmax);
2555 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2556 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2557 EXPORT_SYMBOL(proc_dostring);
2558 EXPORT_SYMBOL(proc_doulongvec_minmax);
2559 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2560 EXPORT_SYMBOL(register_sysctl_table);
2561 EXPORT_SYMBOL(sysctl_intvec);
2562 EXPORT_SYMBOL(sysctl_jiffies);
2563 EXPORT_SYMBOL(sysctl_ms_jiffies);
2564 EXPORT_SYMBOL(sysctl_string);
2565 EXPORT_SYMBOL(unregister_sysctl_table);