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/config.h>
22 #include <linux/module.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/capability.h>
29 #include <linux/ctype.h>
30 #include <linux/utsname.h>
31 #include <linux/capability.h>
32 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/security.h>
42 #include <linux/initrd.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
49 #include <linux/vserver/cvirt.h>
51 #include <asm/uaccess.h>
52 #include <asm/processor.h>
54 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
55 void __user *buffer, size_t *lenp, loff_t *ppos);
57 #if defined(CONFIG_SYSCTL)
59 /* External variables not in a header file. */
61 extern int sysctl_overcommit_memory;
62 extern int sysctl_overcommit_ratio;
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;
77 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
78 int unknown_nmi_panic;
79 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
80 void __user *, size_t *, loff_t *);
83 extern unsigned int vdso_enabled, vdso_populate;
85 int exec_shield = (1<<3) | (1<<0);
86 /* exec_shield is a bitmask:
87 0: off; vdso at STACK_TOP, 1 page below TASK_SIZE
88 (1<<0) 1: on [also on if !=0]
89 (1<<1) 2: noexecstack by default
90 (1<<2) 4: vdso just below .text of main (unless too low)
91 (1<<3) 8: vdso just below .text of PT_INTERP (unless too low)
92 Yes, vdso placement is overloaded here; but exec_shield off
93 is a strong incentive to place vdso at STACK_TOP, so the bit
94 for vdso just below .text comes along for the ride.
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 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
160 ctl_table *, void **);
161 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
162 void __user *buffer, size_t *lenp, loff_t *ppos);
164 static ctl_table root_table[];
165 static struct ctl_table_header root_table_header =
166 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
168 static ctl_table kern_table[];
169 static ctl_table vm_table[];
170 static ctl_table proc_table[];
171 static ctl_table fs_table[];
172 static ctl_table debug_table[];
173 static ctl_table dev_table[];
174 extern ctl_table random_table[];
175 #ifdef CONFIG_UNIX98_PTYS
176 extern ctl_table pty_table[];
178 #ifdef CONFIG_INOTIFY
179 extern ctl_table inotify_table[];
182 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183 int sysctl_legacy_va_layout;
186 /* /proc declarations: */
188 #ifdef CONFIG_PROC_FS
190 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
191 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
192 static int proc_opensys(struct inode *, struct file *);
194 struct file_operations proc_sys_file_operations = {
195 .open = proc_opensys,
196 .read = proc_readsys,
197 .write = proc_writesys,
200 extern struct proc_dir_entry *proc_sys_root;
202 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
203 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
206 /* The default sysctl tables: */
208 static ctl_table root_table[] = {
210 .ctl_name = CTL_KERN,
211 .procname = "kernel",
230 .ctl_name = CTL_PROC,
242 .ctl_name = CTL_DEBUG,
245 .child = debug_table,
257 static ctl_table kern_table[] = {
259 .ctl_name = KERN_OSTYPE,
260 .procname = "ostype",
261 .data = system_utsname.sysname,
262 .maxlen = sizeof(system_utsname.sysname),
264 .proc_handler = &proc_doutsstring,
265 .virt_handler = &vx_uts_virt_handler,
266 .strategy = &sysctl_string,
269 .ctl_name = KERN_OSRELEASE,
270 .procname = "osrelease",
271 .data = system_utsname.release,
272 .maxlen = sizeof(system_utsname.release),
274 .proc_handler = &proc_doutsstring,
275 .virt_handler = &vx_uts_virt_handler,
276 .strategy = &sysctl_string,
279 .ctl_name = KERN_VERSION,
280 .procname = "version",
281 .data = system_utsname.version,
282 .maxlen = sizeof(system_utsname.version),
284 .proc_handler = &proc_doutsstring,
285 .virt_handler = &vx_uts_virt_handler,
286 .strategy = &sysctl_string,
289 .ctl_name = KERN_NODENAME,
290 .procname = "hostname",
291 .data = system_utsname.nodename,
292 .maxlen = sizeof(system_utsname.nodename),
294 .proc_handler = &proc_doutsstring,
295 .virt_handler = &vx_uts_virt_handler,
296 .strategy = &sysctl_string,
299 .ctl_name = KERN_DOMAINNAME,
300 .procname = "domainname",
301 .data = system_utsname.domainname,
302 .maxlen = sizeof(system_utsname.domainname),
304 .proc_handler = &proc_doutsstring,
305 .virt_handler = &vx_uts_virt_handler,
306 .strategy = &sysctl_string,
309 .ctl_name = KERN_PANIC,
311 .data = &panic_timeout,
312 .maxlen = sizeof(int),
314 .proc_handler = &proc_dointvec,
317 .ctl_name = KERN_EXEC_SHIELD,
318 .procname = "exec-shield",
319 .data = &exec_shield,
320 .maxlen = sizeof(int),
322 .proc_handler = &proc_dointvec,
325 .ctl_name = KERN_PRINT_FATAL,
326 .procname = "print-fatal-signals",
327 .data = &print_fatal_signals,
328 .maxlen = sizeof(int),
330 .proc_handler = &proc_dointvec,
334 .ctl_name = KERN_VDSO,
336 .data = &vdso_enabled,
337 .maxlen = sizeof(int),
339 .proc_handler = &proc_dointvec,
342 .ctl_name = KERN_VDSO,
343 .procname = "vdso_populate",
344 .data = &vdso_populate,
345 .maxlen = sizeof(int),
347 .proc_handler = &proc_dointvec,
351 .ctl_name = KERN_CORE_USES_PID,
352 .procname = "core_uses_pid",
353 .data = &core_uses_pid,
354 .maxlen = sizeof(int),
356 .proc_handler = &proc_dointvec,
359 .ctl_name = KERN_CORE_PATTERN,
360 .procname = "core_pattern",
361 .data = core_pattern,
364 .proc_handler = &proc_dostring,
365 .strategy = &sysctl_string,
368 .ctl_name = KERN_TAINTED,
369 .procname = "tainted",
371 .maxlen = sizeof(int),
373 .proc_handler = &proc_dointvec,
376 .ctl_name = KERN_CAP_BSET,
377 .procname = "cap-bound",
379 .maxlen = sizeof(kernel_cap_t),
381 .proc_handler = &proc_dointvec_bset,
383 #ifdef CONFIG_BLK_DEV_INITRD
385 .ctl_name = KERN_REALROOTDEV,
386 .procname = "real-root-dev",
387 .data = &real_root_dev,
388 .maxlen = sizeof(int),
390 .proc_handler = &proc_dointvec,
395 .ctl_name = KERN_SPARC_REBOOT,
396 .procname = "reboot-cmd",
397 .data = reboot_command,
400 .proc_handler = &proc_dostring,
401 .strategy = &sysctl_string,
404 .ctl_name = KERN_SPARC_STOP_A,
405 .procname = "stop-a",
406 .data = &stop_a_enabled,
407 .maxlen = sizeof (int),
409 .proc_handler = &proc_dointvec,
412 .ctl_name = KERN_SPARC_SCONS_PWROFF,
413 .procname = "scons-poweroff",
414 .data = &scons_pwroff,
415 .maxlen = sizeof (int),
417 .proc_handler = &proc_dointvec,
422 .ctl_name = KERN_HPPA_PWRSW,
423 .procname = "soft-power",
424 .data = &pwrsw_enabled,
425 .maxlen = sizeof (int),
427 .proc_handler = &proc_dointvec,
430 .ctl_name = KERN_HPPA_UNALIGNED,
431 .procname = "unaligned-trap",
432 .data = &unaligned_enabled,
433 .maxlen = sizeof (int),
435 .proc_handler = &proc_dointvec,
439 .ctl_name = KERN_CTLALTDEL,
440 .procname = "ctrl-alt-del",
442 .maxlen = sizeof(int),
444 .proc_handler = &proc_dointvec,
447 .ctl_name = KERN_PRINTK,
448 .procname = "printk",
449 .data = &console_loglevel,
450 .maxlen = 4*sizeof(int),
452 .proc_handler = &proc_dointvec,
456 .ctl_name = KERN_MODPROBE,
457 .procname = "modprobe",
458 .data = &modprobe_path,
459 .maxlen = KMOD_PATH_LEN,
461 .proc_handler = &proc_dostring,
462 .strategy = &sysctl_string,
465 #ifdef CONFIG_HOTPLUG
467 .ctl_name = KERN_HOTPLUG,
468 .procname = "hotplug",
469 .data = &uevent_helper,
470 .maxlen = UEVENT_HELPER_PATH_LEN,
472 .proc_handler = &proc_dostring,
473 .strategy = &sysctl_string,
477 .ctl_name = KERN_VSHELPER,
478 .procname = "vshelper",
479 .data = &vshelper_path,
482 .proc_handler = &proc_dostring,
483 .strategy = &sysctl_string,
485 #ifdef CONFIG_CHR_DEV_SG
487 .ctl_name = KERN_SG_BIG_BUFF,
488 .procname = "sg-big-buff",
489 .data = &sg_big_buff,
490 .maxlen = sizeof (int),
492 .proc_handler = &proc_dointvec,
495 #ifdef CONFIG_BSD_PROCESS_ACCT
497 .ctl_name = KERN_ACCT,
500 .maxlen = 3*sizeof(int),
502 .proc_handler = &proc_dointvec,
505 #ifdef CONFIG_SYSVIPC
507 .ctl_name = KERN_SHMMAX,
508 .procname = "shmmax",
510 .maxlen = sizeof (size_t),
512 .proc_handler = &proc_doulongvec_minmax,
515 .ctl_name = KERN_SHMALL,
516 .procname = "shmall",
518 .maxlen = sizeof (size_t),
520 .proc_handler = &proc_doulongvec_minmax,
523 .ctl_name = KERN_SHMMNI,
524 .procname = "shmmni",
526 .maxlen = sizeof (int),
528 .proc_handler = &proc_dointvec,
531 .ctl_name = KERN_MSGMAX,
532 .procname = "msgmax",
534 .maxlen = sizeof (int),
536 .proc_handler = &proc_dointvec,
539 .ctl_name = KERN_MSGMNI,
540 .procname = "msgmni",
542 .maxlen = sizeof (int),
544 .proc_handler = &proc_dointvec,
547 .ctl_name = KERN_MSGMNB,
548 .procname = "msgmnb",
550 .maxlen = sizeof (int),
552 .proc_handler = &proc_dointvec,
555 .ctl_name = KERN_SEM,
558 .maxlen = 4*sizeof (int),
560 .proc_handler = &proc_dointvec,
563 #ifdef CONFIG_MAGIC_SYSRQ
565 .ctl_name = KERN_SYSRQ,
567 .data = &sysrq_enabled,
568 .maxlen = sizeof (int),
570 .proc_handler = &proc_dointvec,
574 .ctl_name = KERN_CADPID,
575 .procname = "cad_pid",
577 .maxlen = sizeof (int),
579 .proc_handler = &proc_dointvec,
582 .ctl_name = KERN_MAX_THREADS,
583 .procname = "threads-max",
584 .data = &max_threads,
585 .maxlen = sizeof(int),
587 .proc_handler = &proc_dointvec,
590 .ctl_name = KERN_RANDOM,
591 .procname = "random",
593 .child = random_table,
595 #ifdef CONFIG_UNIX98_PTYS
597 .ctl_name = KERN_PTY,
604 .ctl_name = KERN_OVERFLOWUID,
605 .procname = "overflowuid",
606 .data = &overflowuid,
607 .maxlen = sizeof(int),
609 .proc_handler = &proc_dointvec_minmax,
610 .strategy = &sysctl_intvec,
611 .extra1 = &minolduid,
612 .extra2 = &maxolduid,
615 .ctl_name = KERN_OVERFLOWGID,
616 .procname = "overflowgid",
617 .data = &overflowgid,
618 .maxlen = sizeof(int),
620 .proc_handler = &proc_dointvec_minmax,
621 .strategy = &sysctl_intvec,
622 .extra1 = &minolduid,
623 .extra2 = &maxolduid,
626 #ifdef CONFIG_MATHEMU
628 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
629 .procname = "ieee_emulation_warnings",
630 .data = &sysctl_ieee_emulation_warnings,
631 .maxlen = sizeof(int),
633 .proc_handler = &proc_dointvec,
636 #ifdef CONFIG_NO_IDLE_HZ
638 .ctl_name = KERN_HZ_TIMER,
639 .procname = "hz_timer",
640 .data = &sysctl_hz_timer,
641 .maxlen = sizeof(int),
643 .proc_handler = &proc_dointvec,
647 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
648 .procname = "userprocess_debug",
649 .data = &sysctl_userprocess_debug,
650 .maxlen = sizeof(int),
652 .proc_handler = &proc_dointvec,
656 .ctl_name = KERN_PIDMAX,
657 .procname = "pid_max",
659 .maxlen = sizeof (int),
661 .proc_handler = &proc_dointvec_minmax,
662 .strategy = sysctl_intvec,
663 .extra1 = &pid_max_min,
664 .extra2 = &pid_max_max,
667 .ctl_name = KERN_PANIC_ON_OOPS,
668 .procname = "panic_on_oops",
669 .data = &panic_on_oops,
670 .maxlen = sizeof(int),
672 .proc_handler = &proc_dointvec,
675 .ctl_name = KERN_PRINTK_RATELIMIT,
676 .procname = "printk_ratelimit",
677 .data = &printk_ratelimit_jiffies,
678 .maxlen = sizeof(int),
680 .proc_handler = &proc_dointvec_jiffies,
681 .strategy = &sysctl_jiffies,
684 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
685 .procname = "printk_ratelimit_burst",
686 .data = &printk_ratelimit_burst,
687 .maxlen = sizeof(int),
689 .proc_handler = &proc_dointvec,
692 .ctl_name = KERN_NGROUPS_MAX,
693 .procname = "ngroups_max",
694 .data = &ngroups_max,
695 .maxlen = sizeof (int),
697 .proc_handler = &proc_dointvec,
699 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
701 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
702 .procname = "unknown_nmi_panic",
703 .data = &unknown_nmi_panic,
704 .maxlen = sizeof (int),
706 .proc_handler = &proc_unknown_nmi_panic,
709 #if defined(CONFIG_X86)
711 .ctl_name = KERN_BOOTLOADER_TYPE,
712 .procname = "bootloader_type",
713 .data = &bootloader_type,
714 .maxlen = sizeof (int),
716 .proc_handler = &proc_dointvec,
719 #if defined(CONFIG_MMU)
721 .ctl_name = KERN_RANDOMIZE,
722 .procname = "randomize_va_space",
723 .data = &randomize_va_space,
724 .maxlen = sizeof(int),
726 .proc_handler = &proc_dointvec,
729 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
731 .ctl_name = KERN_SPIN_RETRY,
732 .procname = "spin_retry",
734 .maxlen = sizeof (int),
736 .proc_handler = &proc_dointvec,
739 #ifdef CONFIG_ACPI_SLEEP
741 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
742 .procname = "acpi_video_flags",
743 .data = &acpi_video_flags,
744 .maxlen = sizeof (unsigned long),
746 .proc_handler = &proc_doulongvec_minmax,
751 .ctl_name = KERN_IA64_UNALIGNED,
752 .procname = "ignore-unaligned-usertrap",
753 .data = &no_unaligned_warning,
754 .maxlen = sizeof (int),
756 .proc_handler = &proc_dointvec,
762 /* Constants for minimum and maximum testing in vm_table.
763 We use these as one-element integer vectors. */
765 static int one_hundred = 100;
768 static ctl_table vm_table[] = {
770 .ctl_name = VM_OVERCOMMIT_MEMORY,
771 .procname = "overcommit_memory",
772 .data = &sysctl_overcommit_memory,
773 .maxlen = sizeof(sysctl_overcommit_memory),
775 .proc_handler = &proc_dointvec,
778 .ctl_name = VM_OVERCOMMIT_RATIO,
779 .procname = "overcommit_ratio",
780 .data = &sysctl_overcommit_ratio,
781 .maxlen = sizeof(sysctl_overcommit_ratio),
783 .proc_handler = &proc_dointvec,
786 .ctl_name = VM_PAGE_CLUSTER,
787 .procname = "page-cluster",
788 .data = &page_cluster,
789 .maxlen = sizeof(int),
791 .proc_handler = &proc_dointvec,
794 .ctl_name = VM_DIRTY_BACKGROUND,
795 .procname = "dirty_background_ratio",
796 .data = &dirty_background_ratio,
797 .maxlen = sizeof(dirty_background_ratio),
799 .proc_handler = &proc_dointvec_minmax,
800 .strategy = &sysctl_intvec,
802 .extra2 = &one_hundred,
805 .ctl_name = VM_DIRTY_RATIO,
806 .procname = "dirty_ratio",
807 .data = &vm_dirty_ratio,
808 .maxlen = sizeof(vm_dirty_ratio),
810 .proc_handler = &proc_dointvec_minmax,
811 .strategy = &sysctl_intvec,
813 .extra2 = &one_hundred,
816 .ctl_name = VM_DIRTY_WB_CS,
817 .procname = "dirty_writeback_centisecs",
818 .data = &dirty_writeback_interval,
819 .maxlen = sizeof(dirty_writeback_interval),
821 .proc_handler = &dirty_writeback_centisecs_handler,
824 .ctl_name = VM_DIRTY_EXPIRE_CS,
825 .procname = "dirty_expire_centisecs",
826 .data = &dirty_expire_interval,
827 .maxlen = sizeof(dirty_expire_interval),
829 .proc_handler = &proc_dointvec_userhz_jiffies,
832 .ctl_name = VM_NR_PDFLUSH_THREADS,
833 .procname = "nr_pdflush_threads",
834 .data = &nr_pdflush_threads,
835 .maxlen = sizeof nr_pdflush_threads,
836 .mode = 0444 /* read-only*/,
837 .proc_handler = &proc_dointvec,
840 .ctl_name = VM_SWAPPINESS,
841 .procname = "swappiness",
842 .data = &vm_swappiness,
843 .maxlen = sizeof(vm_swappiness),
845 .proc_handler = &proc_dointvec_minmax,
846 .strategy = &sysctl_intvec,
848 .extra2 = &one_hundred,
850 #ifdef CONFIG_HUGETLB_PAGE
852 .ctl_name = VM_HUGETLB_PAGES,
853 .procname = "nr_hugepages",
854 .data = &max_huge_pages,
855 .maxlen = sizeof(unsigned long),
857 .proc_handler = &hugetlb_sysctl_handler,
858 .extra1 = (void *)&hugetlb_zero,
859 .extra2 = (void *)&hugetlb_infinity,
862 .ctl_name = VM_HUGETLB_GROUP,
863 .procname = "hugetlb_shm_group",
864 .data = &sysctl_hugetlb_shm_group,
865 .maxlen = sizeof(gid_t),
867 .proc_handler = &proc_dointvec,
871 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
872 .procname = "lowmem_reserve_ratio",
873 .data = &sysctl_lowmem_reserve_ratio,
874 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
876 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
877 .strategy = &sysctl_intvec,
880 .ctl_name = VM_DROP_PAGECACHE,
881 .procname = "drop_caches",
882 .data = &sysctl_drop_caches,
883 .maxlen = sizeof(int),
885 .proc_handler = drop_caches_sysctl_handler,
886 .strategy = &sysctl_intvec,
889 .ctl_name = VM_MIN_FREE_KBYTES,
890 .procname = "min_free_kbytes",
891 .data = &min_free_kbytes,
892 .maxlen = sizeof(min_free_kbytes),
894 .proc_handler = &min_free_kbytes_sysctl_handler,
895 .strategy = &sysctl_intvec,
899 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
900 .procname = "percpu_pagelist_fraction",
901 .data = &percpu_pagelist_fraction,
902 .maxlen = sizeof(percpu_pagelist_fraction),
904 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
905 .strategy = &sysctl_intvec,
906 .extra1 = &min_percpu_pagelist_fract,
910 .ctl_name = VM_MAX_MAP_COUNT,
911 .procname = "max_map_count",
912 .data = &sysctl_max_map_count,
913 .maxlen = sizeof(sysctl_max_map_count),
915 .proc_handler = &proc_dointvec
919 .ctl_name = VM_LAPTOP_MODE,
920 .procname = "laptop_mode",
921 .data = &laptop_mode,
922 .maxlen = sizeof(laptop_mode),
924 .proc_handler = &proc_dointvec_jiffies,
925 .strategy = &sysctl_jiffies,
928 .ctl_name = VM_BLOCK_DUMP,
929 .procname = "block_dump",
931 .maxlen = sizeof(block_dump),
933 .proc_handler = &proc_dointvec,
934 .strategy = &sysctl_intvec,
938 .ctl_name = VM_VFS_CACHE_PRESSURE,
939 .procname = "vfs_cache_pressure",
940 .data = &sysctl_vfs_cache_pressure,
941 .maxlen = sizeof(sysctl_vfs_cache_pressure),
943 .proc_handler = &proc_dointvec,
944 .strategy = &sysctl_intvec,
947 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
949 .ctl_name = VM_LEGACY_VA_LAYOUT,
950 .procname = "legacy_va_layout",
951 .data = &sysctl_legacy_va_layout,
952 .maxlen = sizeof(sysctl_legacy_va_layout),
954 .proc_handler = &proc_dointvec,
955 .strategy = &sysctl_intvec,
961 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
962 .procname = "swap_token_timeout",
963 .data = &swap_token_default_timeout,
964 .maxlen = sizeof(swap_token_default_timeout),
966 .proc_handler = &proc_dointvec_jiffies,
967 .strategy = &sysctl_jiffies,
972 .ctl_name = VM_ZONE_RECLAIM_MODE,
973 .procname = "zone_reclaim_mode",
974 .data = &zone_reclaim_mode,
975 .maxlen = sizeof(zone_reclaim_mode),
977 .proc_handler = &proc_dointvec,
978 .strategy = &sysctl_intvec,
982 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
983 .procname = "zone_reclaim_interval",
984 .data = &zone_reclaim_interval,
985 .maxlen = sizeof(zone_reclaim_interval),
987 .proc_handler = &proc_dointvec_jiffies,
988 .strategy = &sysctl_jiffies,
994 static ctl_table proc_table[] = {
998 static ctl_table fs_table[] = {
1000 .ctl_name = FS_NRINODE,
1001 .procname = "inode-nr",
1002 .data = &inodes_stat,
1003 .maxlen = 2*sizeof(int),
1005 .proc_handler = &proc_dointvec,
1008 .ctl_name = FS_STATINODE,
1009 .procname = "inode-state",
1010 .data = &inodes_stat,
1011 .maxlen = 7*sizeof(int),
1013 .proc_handler = &proc_dointvec,
1016 .ctl_name = FS_NRFILE,
1017 .procname = "file-nr",
1018 .data = &files_stat,
1019 .maxlen = 3*sizeof(int),
1021 .proc_handler = &proc_nr_files,
1024 .ctl_name = FS_MAXFILE,
1025 .procname = "file-max",
1026 .data = &files_stat.max_files,
1027 .maxlen = sizeof(int),
1029 .proc_handler = &proc_dointvec,
1032 .ctl_name = FS_DENTRY,
1033 .procname = "dentry-state",
1034 .data = &dentry_stat,
1035 .maxlen = 6*sizeof(int),
1037 .proc_handler = &proc_dointvec,
1040 .ctl_name = FS_OVERFLOWUID,
1041 .procname = "overflowuid",
1042 .data = &fs_overflowuid,
1043 .maxlen = sizeof(int),
1045 .proc_handler = &proc_dointvec_minmax,
1046 .strategy = &sysctl_intvec,
1047 .extra1 = &minolduid,
1048 .extra2 = &maxolduid,
1051 .ctl_name = FS_OVERFLOWGID,
1052 .procname = "overflowgid",
1053 .data = &fs_overflowgid,
1054 .maxlen = sizeof(int),
1056 .proc_handler = &proc_dointvec_minmax,
1057 .strategy = &sysctl_intvec,
1058 .extra1 = &minolduid,
1059 .extra2 = &maxolduid,
1062 .ctl_name = FS_LEASES,
1063 .procname = "leases-enable",
1064 .data = &leases_enable,
1065 .maxlen = sizeof(int),
1067 .proc_handler = &proc_dointvec,
1069 #ifdef CONFIG_DNOTIFY
1071 .ctl_name = FS_DIR_NOTIFY,
1072 .procname = "dir-notify-enable",
1073 .data = &dir_notify_enable,
1074 .maxlen = sizeof(int),
1076 .proc_handler = &proc_dointvec,
1081 .ctl_name = FS_LEASE_TIME,
1082 .procname = "lease-break-time",
1083 .data = &lease_break_time,
1084 .maxlen = sizeof(int),
1086 .proc_handler = &proc_dointvec,
1089 .ctl_name = FS_AIO_NR,
1090 .procname = "aio-nr",
1092 .maxlen = sizeof(aio_nr),
1094 .proc_handler = &proc_doulongvec_minmax,
1097 .ctl_name = FS_AIO_MAX_NR,
1098 .procname = "aio-max-nr",
1099 .data = &aio_max_nr,
1100 .maxlen = sizeof(aio_max_nr),
1102 .proc_handler = &proc_doulongvec_minmax,
1104 #ifdef CONFIG_INOTIFY
1106 .ctl_name = FS_INOTIFY,
1107 .procname = "inotify",
1109 .child = inotify_table,
1114 .ctl_name = KERN_SETUID_DUMPABLE,
1115 .procname = "suid_dumpable",
1116 .data = &suid_dumpable,
1117 .maxlen = sizeof(int),
1119 .proc_handler = &proc_dointvec,
1124 static ctl_table debug_table[] = {
1128 static ctl_table dev_table[] = {
1132 extern void init_irq_proc (void);
1134 static DEFINE_SPINLOCK(sysctl_lock);
1136 /* called under sysctl_lock */
1137 static int use_table(struct ctl_table_header *p)
1139 if (unlikely(p->unregistering))
1145 /* called under sysctl_lock */
1146 static void unuse_table(struct ctl_table_header *p)
1149 if (unlikely(p->unregistering))
1150 complete(p->unregistering);
1153 /* called under sysctl_lock, will reacquire if has to wait */
1154 static void start_unregistering(struct ctl_table_header *p)
1157 * if p->used is 0, nobody will ever touch that entry again;
1158 * we'll eliminate all paths to it before dropping sysctl_lock
1160 if (unlikely(p->used)) {
1161 struct completion wait;
1162 init_completion(&wait);
1163 p->unregistering = &wait;
1164 spin_unlock(&sysctl_lock);
1165 wait_for_completion(&wait);
1166 spin_lock(&sysctl_lock);
1169 * do not remove from the list until nobody holds it; walking the
1170 * list in do_sysctl() relies on that.
1172 list_del_init(&p->ctl_entry);
1175 void __init sysctl_init(void)
1177 #ifdef CONFIG_PROC_FS
1178 register_proc_table(root_table, proc_sys_root, &root_table_header);
1183 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1184 void __user *newval, size_t newlen)
1186 struct list_head *tmp;
1187 int error = -ENOTDIR;
1189 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1193 if (!oldlenp || get_user(old_len, oldlenp))
1196 spin_lock(&sysctl_lock);
1197 tmp = &root_table_header.ctl_entry;
1199 struct ctl_table_header *head =
1200 list_entry(tmp, struct ctl_table_header, ctl_entry);
1201 void *context = NULL;
1203 if (!use_table(head))
1206 spin_unlock(&sysctl_lock);
1208 error = parse_table(name, nlen, oldval, oldlenp,
1209 newval, newlen, head->ctl_table,
1213 spin_lock(&sysctl_lock);
1215 if (error != -ENOTDIR)
1217 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1218 spin_unlock(&sysctl_lock);
1222 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1224 struct __sysctl_args tmp;
1227 if (copy_from_user(&tmp, args, sizeof(tmp)))
1231 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1232 tmp.newval, tmp.newlen);
1238 * ctl_perm does NOT grant the superuser all rights automatically, because
1239 * some sysctl variables are readonly even to root.
1242 static int test_perm(int mode, int op)
1246 else if (in_egroup_p(0))
1248 if ((mode & op & 0007) == op)
1253 static inline int ctl_perm(ctl_table *table, int op)
1256 error = security_sysctl(table, op);
1259 return test_perm(table->mode, op);
1262 static int parse_table(int __user *name, int nlen,
1263 void __user *oldval, size_t __user *oldlenp,
1264 void __user *newval, size_t newlen,
1265 ctl_table *table, void **context)
1271 if (get_user(n, name))
1273 for ( ; table->ctl_name; table++) {
1274 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1277 if (ctl_perm(table, 001))
1279 if (table->strategy) {
1280 error = table->strategy(
1283 newval, newlen, context);
1289 table = table->child;
1292 error = do_sysctl_strategy(table, name, nlen,
1294 newval, newlen, context);
1301 /* Perform the actual read/write of a sysctl table entry. */
1302 int do_sysctl_strategy (ctl_table *table,
1303 int __user *name, int nlen,
1304 void __user *oldval, size_t __user *oldlenp,
1305 void __user *newval, size_t newlen, void **context)
1314 if (ctl_perm(table, op))
1317 if (table->strategy) {
1318 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1319 newval, newlen, context);
1326 /* If there is no strategy routine, or if the strategy returns
1327 * zero, proceed with automatic r/w */
1328 if (table->data && table->maxlen) {
1329 if (oldval && oldlenp) {
1330 if (get_user(len, oldlenp))
1333 if (len > table->maxlen)
1334 len = table->maxlen;
1335 if(copy_to_user(oldval, table->data, len))
1337 if(put_user(len, oldlenp))
1341 if (newval && newlen) {
1343 if (len > table->maxlen)
1344 len = table->maxlen;
1345 if(copy_from_user(table->data, newval, len))
1353 * register_sysctl_table - register a sysctl hierarchy
1354 * @table: the top-level table structure
1355 * @insert_at_head: whether the entry should be inserted in front or at the end
1357 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1358 * array. An entry with a ctl_name of 0 terminates the table.
1360 * The members of the &ctl_table structure are used as follows:
1362 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1363 * must be unique within that level of sysctl
1365 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1366 * enter a sysctl file
1368 * data - a pointer to data for use by proc_handler
1370 * maxlen - the maximum size in bytes of the data
1372 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1374 * child - a pointer to the child sysctl table if this entry is a directory, or
1377 * proc_handler - the text handler routine (described below)
1379 * strategy - the strategy routine (described below)
1381 * de - for internal use by the sysctl routines
1383 * extra1, extra2 - extra pointers usable by the proc handler routines
1385 * Leaf nodes in the sysctl tree will be represented by a single file
1386 * under /proc; non-leaf nodes will be represented by directories.
1388 * sysctl(2) can automatically manage read and write requests through
1389 * the sysctl table. The data and maxlen fields of the ctl_table
1390 * struct enable minimal validation of the values being written to be
1391 * performed, and the mode field allows minimal authentication.
1393 * More sophisticated management can be enabled by the provision of a
1394 * strategy routine with the table entry. This will be called before
1395 * any automatic read or write of the data is performed.
1397 * The strategy routine may return
1399 * < 0 - Error occurred (error is passed to user process)
1401 * 0 - OK - proceed with automatic read or write.
1403 * > 0 - OK - read or write has been done by the strategy routine, so
1404 * return immediately.
1406 * There must be a proc_handler routine for any terminal nodes
1407 * mirrored under /proc/sys (non-terminals are handled by a built-in
1408 * directory handler). Several default handlers are available to
1409 * cover common cases -
1411 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1412 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1413 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1415 * It is the handler's job to read the input buffer from user memory
1416 * and process it. The handler should return 0 on success.
1418 * This routine returns %NULL on a failure to register, and a pointer
1419 * to the table header on success.
1421 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1424 struct ctl_table_header *tmp;
1425 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1428 tmp->ctl_table = table;
1429 INIT_LIST_HEAD(&tmp->ctl_entry);
1431 tmp->unregistering = NULL;
1432 spin_lock(&sysctl_lock);
1434 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1436 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1437 spin_unlock(&sysctl_lock);
1438 #ifdef CONFIG_PROC_FS
1439 register_proc_table(table, proc_sys_root, tmp);
1445 * unregister_sysctl_table - unregister a sysctl table hierarchy
1446 * @header: the header returned from register_sysctl_table
1448 * Unregisters the sysctl table and all children. proc entries may not
1449 * actually be removed until they are no longer used by anyone.
1451 void unregister_sysctl_table(struct ctl_table_header * header)
1454 spin_lock(&sysctl_lock);
1455 start_unregistering(header);
1456 #ifdef CONFIG_PROC_FS
1457 unregister_proc_table(header->ctl_table, proc_sys_root);
1459 spin_unlock(&sysctl_lock);
1467 #ifdef CONFIG_PROC_FS
1469 /* Scan the sysctl entries in table and add them all into /proc */
1470 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1472 struct proc_dir_entry *de;
1476 for (; table->ctl_name; table++) {
1477 /* Can't do anything without a proc name. */
1478 if (!table->procname)
1480 /* Maybe we can't do anything with it... */
1481 if (!table->proc_handler && !table->child) {
1482 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1487 len = strlen(table->procname);
1491 if (table->proc_handler)
1495 for (de = root->subdir; de; de = de->next) {
1496 if (proc_match(len, table->procname, de))
1499 /* If the subdir exists already, de is non-NULL */
1503 de = create_proc_entry(table->procname, mode, root);
1507 de->data = (void *) table;
1508 if (table->proc_handler)
1509 de->proc_fops = &proc_sys_file_operations;
1512 if (de->mode & S_IFDIR)
1513 register_proc_table(table->child, de, set);
1518 * Unregister a /proc sysctl table and any subdirectories.
1520 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1522 struct proc_dir_entry *de;
1523 for (; table->ctl_name; table++) {
1524 if (!(de = table->de))
1526 if (de->mode & S_IFDIR) {
1527 if (!table->child) {
1528 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1531 unregister_proc_table(table->child, de);
1533 /* Don't unregister directories which still have entries.. */
1539 * In any case, mark the entry as goner; we'll keep it
1540 * around if it's busy, but we'll know to do nothing with
1541 * its fields. We are under sysctl_lock here.
1545 /* Don't unregister proc entries that are still being used.. */
1546 if (atomic_read(&de->count))
1550 remove_proc_entry(table->procname, root);
1554 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1555 size_t count, loff_t *ppos)
1558 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1559 struct ctl_table *table;
1561 ssize_t error = -ENOTDIR;
1563 spin_lock(&sysctl_lock);
1564 if (de && de->data && use_table(de->set)) {
1566 * at that point we know that sysctl was not unregistered
1567 * and won't be until we finish
1569 spin_unlock(&sysctl_lock);
1570 table = (struct ctl_table *) de->data;
1571 if (!table || !table->proc_handler)
1574 op = (write ? 002 : 004);
1575 if (ctl_perm(table, op))
1578 /* careful: calling conventions are nasty here */
1580 error = (*table->proc_handler)(table, write, file,
1585 spin_lock(&sysctl_lock);
1586 unuse_table(de->set);
1588 spin_unlock(&sysctl_lock);
1592 static int proc_opensys(struct inode *inode, struct file *file)
1594 if (file->f_mode & FMODE_WRITE) {
1596 * sysctl entries that are not writable,
1597 * are _NOT_ writable, capabilities or not.
1599 if (!(inode->i_mode & S_IWUSR))
1606 static ssize_t proc_readsys(struct file * file, char __user * buf,
1607 size_t count, loff_t *ppos)
1609 return do_rw_proc(0, file, buf, count, ppos);
1612 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1613 size_t count, loff_t *ppos)
1615 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1619 * proc_dostring - read a string sysctl
1620 * @table: the sysctl table
1621 * @write: %TRUE if this is a write to the sysctl file
1622 * @filp: the file structure
1623 * @buffer: the user buffer
1624 * @lenp: the size of the user buffer
1625 * @ppos: file position
1627 * Reads/writes a string from/to the user buffer. If the kernel
1628 * buffer provided is not large enough to hold the string, the
1629 * string is truncated. The copied string is %NULL-terminated.
1630 * If the string is being read by the user process, it is copied
1631 * and a newline '\n' is added. It is truncated if the buffer is
1634 * Returns 0 on success.
1636 int proc_dostring(ctl_table *table, int write, struct file *filp,
1637 void __user *buffer, size_t *lenp, loff_t *ppos)
1645 maxlen = table->maxlen;
1647 if (!data || !maxlen || !*lenp || (*ppos && !write))
1650 if (table->virt_handler)
1651 table->virt_handler(table, write, filp->f_xid, &data, &maxlen);
1656 while (len < *lenp) {
1657 if (get_user(c, p++))
1659 if (c == 0 || c == '\n')
1665 if(copy_from_user(data, buffer, len))
1667 ((char *) data)[len] = 0;
1676 if(copy_to_user(buffer, data, len))
1679 if(put_user('\n', ((char __user *) buffer) + len))
1690 * Special case of dostring for the UTS structure. This has locks
1691 * to observe. Should this be in kernel/sys.c ????
1694 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1695 void __user *buffer, size_t *lenp, loff_t *ppos)
1700 down_read(&uts_sem);
1701 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1704 down_write(&uts_sem);
1705 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1711 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1713 int write, void *data)
1716 *valp = *negp ? -*lvalp : *lvalp;
1721 *lvalp = (unsigned long)-val;
1724 *lvalp = (unsigned long)val;
1730 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1731 void __user *buffer, size_t *lenp, loff_t *ppos,
1732 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1733 int write, void *data),
1736 #define TMPBUFLEN 21
1737 int *i, vleft, first=1, neg, val;
1741 char buf[TMPBUFLEN], *p;
1742 char __user *s = buffer;
1744 if (!table->data || !table->maxlen || !*lenp ||
1745 (*ppos && !write)) {
1750 i = (int *) table->data;
1751 vleft = table->maxlen / sizeof(*i);
1755 conv = do_proc_dointvec_conv;
1757 for (; left && vleft--; i++, first=0) {
1772 if (len > sizeof(buf) - 1)
1773 len = sizeof(buf) - 1;
1774 if (copy_from_user(buf, s, len))
1778 if (*p == '-' && left > 1) {
1782 if (*p < '0' || *p > '9')
1785 lval = simple_strtoul(p, &p, 0);
1788 if ((len < left) && *p && !isspace(*p))
1795 if (conv(&neg, &lval, i, 1, data))
1802 if (conv(&neg, &lval, i, 0, data))
1805 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1809 if(copy_to_user(s, buf, len))
1816 if (!write && !first && left) {
1817 if(put_user('\n', s))
1824 if (get_user(c, s++))
1840 * proc_dointvec - read a vector of integers
1841 * @table: the sysctl table
1842 * @write: %TRUE if this is a write to the sysctl file
1843 * @filp: the file structure
1844 * @buffer: the user buffer
1845 * @lenp: the size of the user buffer
1846 * @ppos: file position
1848 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1849 * values from/to the user buffer, treated as an ASCII string.
1851 * Returns 0 on success.
1853 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1854 void __user *buffer, size_t *lenp, loff_t *ppos)
1856 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1866 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1868 int write, void *data)
1870 int op = *(int *)data;
1872 int val = *negp ? -*lvalp : *lvalp;
1874 case OP_SET: *valp = val; break;
1875 case OP_AND: *valp &= val; break;
1876 case OP_OR: *valp |= val; break;
1877 case OP_MAX: if(*valp < val)
1880 case OP_MIN: if(*valp > val)
1888 *lvalp = (unsigned long)-val;
1891 *lvalp = (unsigned long)val;
1898 * init may raise the set.
1901 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1902 void __user *buffer, size_t *lenp, loff_t *ppos)
1906 if (!capable(CAP_SYS_MODULE)) {
1910 op = (current->pid == 1) ? OP_SET : OP_AND;
1911 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1912 do_proc_dointvec_bset_conv,&op);
1915 struct do_proc_dointvec_minmax_conv_param {
1920 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1922 int write, void *data)
1924 struct do_proc_dointvec_minmax_conv_param *param = data;
1926 int val = *negp ? -*lvalp : *lvalp;
1927 if ((param->min && *param->min > val) ||
1928 (param->max && *param->max < val))
1935 *lvalp = (unsigned long)-val;
1938 *lvalp = (unsigned long)val;
1945 * proc_dointvec_minmax - read a vector of integers with min/max values
1946 * @table: the sysctl table
1947 * @write: %TRUE if this is a write to the sysctl file
1948 * @filp: the file structure
1949 * @buffer: the user buffer
1950 * @lenp: the size of the user buffer
1951 * @ppos: file position
1953 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1954 * values from/to the user buffer, treated as an ASCII string.
1956 * This routine will ensure the values are within the range specified by
1957 * table->extra1 (min) and table->extra2 (max).
1959 * Returns 0 on success.
1961 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1962 void __user *buffer, size_t *lenp, loff_t *ppos)
1964 struct do_proc_dointvec_minmax_conv_param param = {
1965 .min = (int *) table->extra1,
1966 .max = (int *) table->extra2,
1968 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1969 do_proc_dointvec_minmax_conv, ¶m);
1972 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1974 void __user *buffer,
1975 size_t *lenp, loff_t *ppos,
1976 unsigned long convmul,
1977 unsigned long convdiv)
1979 #define TMPBUFLEN 21
1980 unsigned long *i, *min, *max, val;
1981 int vleft, first=1, neg;
1983 char buf[TMPBUFLEN], *p;
1984 char __user *s = buffer;
1986 if (!table->data || !table->maxlen || !*lenp ||
1987 (*ppos && !write)) {
1992 i = (unsigned long *) table->data;
1993 min = (unsigned long *) table->extra1;
1994 max = (unsigned long *) table->extra2;
1995 vleft = table->maxlen / sizeof(unsigned long);
1998 for (; left && vleft--; i++, min++, max++, first=0) {
2013 if (len > TMPBUFLEN-1)
2015 if (copy_from_user(buf, s, len))
2019 if (*p == '-' && left > 1) {
2023 if (*p < '0' || *p > '9')
2025 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2027 if ((len < left) && *p && !isspace(*p))
2036 if ((min && val < *min) || (max && val > *max))
2043 sprintf(p, "%lu", convdiv * (*i) / convmul);
2047 if(copy_to_user(s, buf, len))
2054 if (!write && !first && left) {
2055 if(put_user('\n', s))
2062 if (get_user(c, s++))
2078 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2079 * @table: the sysctl table
2080 * @write: %TRUE if this is a write to the sysctl file
2081 * @filp: the file structure
2082 * @buffer: the user buffer
2083 * @lenp: the size of the user buffer
2084 * @ppos: file position
2086 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2087 * values from/to the user buffer, treated as an ASCII string.
2089 * This routine will ensure the values are within the range specified by
2090 * table->extra1 (min) and table->extra2 (max).
2092 * Returns 0 on success.
2094 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2095 void __user *buffer, size_t *lenp, loff_t *ppos)
2097 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2101 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2102 * @table: the sysctl table
2103 * @write: %TRUE if this is a write to the sysctl file
2104 * @filp: the file structure
2105 * @buffer: the user buffer
2106 * @lenp: the size of the user buffer
2107 * @ppos: file position
2109 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2110 * values from/to the user buffer, treated as an ASCII string. The values
2111 * are treated as milliseconds, and converted to jiffies when they are stored.
2113 * This routine will ensure the values are within the range specified by
2114 * table->extra1 (min) and table->extra2 (max).
2116 * Returns 0 on success.
2118 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2120 void __user *buffer,
2121 size_t *lenp, loff_t *ppos)
2123 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2124 lenp, ppos, HZ, 1000l);
2128 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2130 int write, void *data)
2133 if (*lvalp > LONG_MAX / HZ)
2135 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2141 lval = (unsigned long)-val;
2144 lval = (unsigned long)val;
2151 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2153 int write, void *data)
2156 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2158 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2164 lval = (unsigned long)-val;
2167 lval = (unsigned long)val;
2169 *lvalp = jiffies_to_clock_t(lval);
2174 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2176 int write, void *data)
2179 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2185 lval = (unsigned long)-val;
2188 lval = (unsigned long)val;
2190 *lvalp = jiffies_to_msecs(lval);
2196 * proc_dointvec_jiffies - read a vector of integers as seconds
2197 * @table: the sysctl table
2198 * @write: %TRUE if this is a write to the sysctl file
2199 * @filp: the file structure
2200 * @buffer: the user buffer
2201 * @lenp: the size of the user buffer
2202 * @ppos: file position
2204 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2205 * values from/to the user buffer, treated as an ASCII string.
2206 * The values read are assumed to be in seconds, and are converted into
2209 * Returns 0 on success.
2211 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2212 void __user *buffer, size_t *lenp, loff_t *ppos)
2214 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2215 do_proc_dointvec_jiffies_conv,NULL);
2219 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2220 * @table: the sysctl table
2221 * @write: %TRUE if this is a write to the sysctl file
2222 * @filp: the file structure
2223 * @buffer: the user buffer
2224 * @lenp: the size of the user buffer
2225 * @ppos: pointer to the file position
2227 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2228 * values from/to the user buffer, treated as an ASCII string.
2229 * The values read are assumed to be in 1/USER_HZ seconds, and
2230 * are converted into jiffies.
2232 * Returns 0 on success.
2234 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2235 void __user *buffer, size_t *lenp, loff_t *ppos)
2237 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2238 do_proc_dointvec_userhz_jiffies_conv,NULL);
2242 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2243 * @table: the sysctl table
2244 * @write: %TRUE if this is a write to the sysctl file
2245 * @filp: the file structure
2246 * @buffer: the user buffer
2247 * @lenp: the size of the user buffer
2248 * @ppos: file position
2249 * @ppos: the current position in the file
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 1/1000 seconds, and
2254 * are converted into jiffies.
2256 * Returns 0 on success.
2258 int proc_dointvec_ms_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_ms_jiffies_conv, NULL);
2265 #else /* CONFIG_PROC_FS */
2267 int proc_dostring(ctl_table *table, int write, struct file *filp,
2268 void __user *buffer, size_t *lenp, loff_t *ppos)
2273 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2274 void __user *buffer, size_t *lenp, loff_t *ppos)
2279 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2280 void __user *buffer, size_t *lenp, loff_t *ppos)
2285 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2286 void __user *buffer, size_t *lenp, loff_t *ppos)
2291 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2292 void __user *buffer, size_t *lenp, loff_t *ppos)
2297 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2298 void __user *buffer, size_t *lenp, loff_t *ppos)
2303 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2304 void __user *buffer, size_t *lenp, loff_t *ppos)
2309 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2310 void __user *buffer, size_t *lenp, loff_t *ppos)
2315 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2316 void __user *buffer, size_t *lenp, loff_t *ppos)
2321 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2323 void __user *buffer,
2324 size_t *lenp, loff_t *ppos)
2330 #endif /* CONFIG_PROC_FS */
2334 * General sysctl support routines
2337 /* The generic string strategy routine: */
2338 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2339 void __user *oldval, size_t __user *oldlenp,
2340 void __user *newval, size_t newlen, void **context)
2342 if (!table->data || !table->maxlen)
2345 if (oldval && oldlenp) {
2347 if (get_user(bufsize, oldlenp))
2350 size_t len = strlen(table->data), copied;
2352 /* This shouldn't trigger for a well-formed sysctl */
2353 if (len > table->maxlen)
2354 len = table->maxlen;
2356 /* Copy up to a max of bufsize-1 bytes of the string */
2357 copied = (len >= bufsize) ? bufsize - 1 : len;
2359 if (copy_to_user(oldval, table->data, copied) ||
2360 put_user(0, (char __user *)(oldval + copied)))
2362 if (put_user(len, oldlenp))
2366 if (newval && newlen) {
2367 size_t len = newlen;
2368 if (len > table->maxlen)
2369 len = table->maxlen;
2370 if(copy_from_user(table->data, newval, len))
2372 if (len == table->maxlen)
2374 ((char *) table->data)[len] = 0;
2380 * This function makes sure that all of the integers in the vector
2381 * are between the minimum and maximum values given in the arrays
2382 * table->extra1 and table->extra2, respectively.
2384 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2385 void __user *oldval, size_t __user *oldlenp,
2386 void __user *newval, size_t newlen, void **context)
2389 if (newval && newlen) {
2390 int __user *vec = (int __user *) newval;
2391 int *min = (int *) table->extra1;
2392 int *max = (int *) table->extra2;
2396 if (newlen % sizeof(int) != 0)
2399 if (!table->extra1 && !table->extra2)
2402 if (newlen > table->maxlen)
2403 newlen = table->maxlen;
2404 length = newlen / sizeof(int);
2406 for (i = 0; i < length; i++) {
2408 if (get_user(value, vec + i))
2410 if (min && value < min[i])
2412 if (max && value > max[i])
2419 /* Strategy function to convert jiffies to seconds */
2420 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2421 void __user *oldval, size_t __user *oldlenp,
2422 void __user *newval, size_t newlen, void **context)
2427 if (get_user(olen, oldlenp))
2429 if (olen!=sizeof(int))
2432 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2433 (oldlenp && put_user(sizeof(int),oldlenp)))
2436 if (newval && newlen) {
2438 if (newlen != sizeof(int))
2440 if (get_user(new, (int __user *)newval))
2442 *(int *)(table->data) = new*HZ;
2447 /* Strategy function to convert jiffies to seconds */
2448 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2449 void __user *oldval, size_t __user *oldlenp,
2450 void __user *newval, size_t newlen, void **context)
2455 if (get_user(olen, oldlenp))
2457 if (olen!=sizeof(int))
2460 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2461 (oldlenp && put_user(sizeof(int),oldlenp)))
2464 if (newval && newlen) {
2466 if (newlen != sizeof(int))
2468 if (get_user(new, (int __user *)newval))
2470 *(int *)(table->data) = msecs_to_jiffies(new);
2475 #else /* CONFIG_SYSCTL */
2478 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2483 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2484 void __user *oldval, size_t __user *oldlenp,
2485 void __user *newval, size_t newlen, void **context)
2490 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2491 void __user *oldval, size_t __user *oldlenp,
2492 void __user *newval, size_t newlen, void **context)
2497 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2498 void __user *oldval, size_t __user *oldlenp,
2499 void __user *newval, size_t newlen, void **context)
2504 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2505 void __user *oldval, size_t __user *oldlenp,
2506 void __user *newval, size_t newlen, void **context)
2511 int proc_dostring(ctl_table *table, int write, struct file *filp,
2512 void __user *buffer, size_t *lenp, loff_t *ppos)
2517 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2518 void __user *buffer, size_t *lenp, loff_t *ppos)
2523 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2524 void __user *buffer, size_t *lenp, loff_t *ppos)
2529 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2530 void __user *buffer, size_t *lenp, loff_t *ppos)
2535 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2536 void __user *buffer, size_t *lenp, loff_t *ppos)
2541 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2542 void __user *buffer, size_t *lenp, loff_t *ppos)
2547 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2548 void __user *buffer, size_t *lenp, loff_t *ppos)
2553 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2554 void __user *buffer, size_t *lenp, loff_t *ppos)
2559 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2561 void __user *buffer,
2562 size_t *lenp, loff_t *ppos)
2567 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2573 void unregister_sysctl_table(struct ctl_table_header * table)
2577 #endif /* CONFIG_SYSCTL */
2580 * No sense putting this after each symbol definition, twice,
2581 * exception granted :-)
2583 EXPORT_SYMBOL(proc_dointvec);
2584 EXPORT_SYMBOL(proc_dointvec_jiffies);
2585 EXPORT_SYMBOL(proc_dointvec_minmax);
2586 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2587 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2588 EXPORT_SYMBOL(proc_dostring);
2589 EXPORT_SYMBOL(proc_doulongvec_minmax);
2590 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2591 EXPORT_SYMBOL(register_sysctl_table);
2592 EXPORT_SYMBOL(sysctl_intvec);
2593 EXPORT_SYMBOL(sysctl_jiffies);
2594 EXPORT_SYMBOL(sysctl_ms_jiffies);
2595 EXPORT_SYMBOL(sysctl_string);
2596 EXPORT_SYMBOL(unregister_sysctl_table);