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>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
53 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
54 void __user *buffer, size_t *lenp, loff_t *ppos);
56 #if defined(CONFIG_SYSCTL)
58 /* External variables not in a header file. */
60 extern int sysctl_overcommit_memory;
61 extern int sysctl_overcommit_ratio;
62 extern int sysctl_panic_on_oom;
63 extern int max_threads;
64 extern int sysrq_enabled;
65 extern int core_uses_pid;
66 extern int suid_dumpable;
67 extern char core_pattern[];
70 extern int min_free_kbytes;
71 extern int printk_ratelimit_jiffies;
72 extern int printk_ratelimit_burst;
73 extern int pid_max_min, pid_max_max;
74 extern int sysctl_drop_caches;
75 extern int percpu_pagelist_fraction;
76 extern int compat_log;
78 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
79 int unknown_nmi_panic;
80 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
81 void __user *, size_t *, loff_t *);
84 /* 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_unknown_nmi_panic,
635 #if defined(CONFIG_X86)
637 .ctl_name = KERN_BOOTLOADER_TYPE,
638 .procname = "bootloader_type",
639 .data = &bootloader_type,
640 .maxlen = sizeof (int),
642 .proc_handler = &proc_dointvec,
645 #if defined(CONFIG_MMU)
647 .ctl_name = KERN_RANDOMIZE,
648 .procname = "randomize_va_space",
649 .data = &randomize_va_space,
650 .maxlen = sizeof(int),
652 .proc_handler = &proc_dointvec,
655 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
657 .ctl_name = KERN_SPIN_RETRY,
658 .procname = "spin_retry",
660 .maxlen = sizeof (int),
662 .proc_handler = &proc_dointvec,
665 #ifdef CONFIG_ACPI_SLEEP
667 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
668 .procname = "acpi_video_flags",
669 .data = &acpi_video_flags,
670 .maxlen = sizeof (unsigned long),
672 .proc_handler = &proc_doulongvec_minmax,
677 .ctl_name = KERN_IA64_UNALIGNED,
678 .procname = "ignore-unaligned-usertrap",
679 .data = &no_unaligned_warning,
680 .maxlen = sizeof (int),
682 .proc_handler = &proc_dointvec,
687 .ctl_name = KERN_COMPAT_LOG,
688 .procname = "compat-log",
690 .maxlen = sizeof (int),
692 .proc_handler = &proc_dointvec,
695 #ifdef CONFIG_RT_MUTEXES
697 .ctl_name = KERN_MAX_LOCK_DEPTH,
698 .procname = "max_lock_depth",
699 .data = &max_lock_depth,
700 .maxlen = sizeof(int),
702 .proc_handler = &proc_dointvec,
709 /* Constants for minimum and maximum testing in vm_table.
710 We use these as one-element integer vectors. */
712 static int one_hundred = 100;
715 static ctl_table vm_table[] = {
717 .ctl_name = VM_OVERCOMMIT_MEMORY,
718 .procname = "overcommit_memory",
719 .data = &sysctl_overcommit_memory,
720 .maxlen = sizeof(sysctl_overcommit_memory),
722 .proc_handler = &proc_dointvec,
725 .ctl_name = VM_PANIC_ON_OOM,
726 .procname = "panic_on_oom",
727 .data = &sysctl_panic_on_oom,
728 .maxlen = sizeof(sysctl_panic_on_oom),
730 .proc_handler = &proc_dointvec,
733 .ctl_name = VM_OVERCOMMIT_RATIO,
734 .procname = "overcommit_ratio",
735 .data = &sysctl_overcommit_ratio,
736 .maxlen = sizeof(sysctl_overcommit_ratio),
738 .proc_handler = &proc_dointvec,
741 .ctl_name = VM_PAGE_CLUSTER,
742 .procname = "page-cluster",
743 .data = &page_cluster,
744 .maxlen = sizeof(int),
746 .proc_handler = &proc_dointvec,
749 .ctl_name = VM_DIRTY_BACKGROUND,
750 .procname = "dirty_background_ratio",
751 .data = &dirty_background_ratio,
752 .maxlen = sizeof(dirty_background_ratio),
754 .proc_handler = &proc_dointvec_minmax,
755 .strategy = &sysctl_intvec,
757 .extra2 = &one_hundred,
760 .ctl_name = VM_DIRTY_RATIO,
761 .procname = "dirty_ratio",
762 .data = &vm_dirty_ratio,
763 .maxlen = sizeof(vm_dirty_ratio),
765 .proc_handler = &proc_dointvec_minmax,
766 .strategy = &sysctl_intvec,
768 .extra2 = &one_hundred,
771 .ctl_name = VM_DIRTY_WB_CS,
772 .procname = "dirty_writeback_centisecs",
773 .data = &dirty_writeback_interval,
774 .maxlen = sizeof(dirty_writeback_interval),
776 .proc_handler = &dirty_writeback_centisecs_handler,
779 .ctl_name = VM_DIRTY_EXPIRE_CS,
780 .procname = "dirty_expire_centisecs",
781 .data = &dirty_expire_interval,
782 .maxlen = sizeof(dirty_expire_interval),
784 .proc_handler = &proc_dointvec_userhz_jiffies,
787 .ctl_name = VM_NR_PDFLUSH_THREADS,
788 .procname = "nr_pdflush_threads",
789 .data = &nr_pdflush_threads,
790 .maxlen = sizeof nr_pdflush_threads,
791 .mode = 0444 /* read-only*/,
792 .proc_handler = &proc_dointvec,
795 .ctl_name = VM_SWAPPINESS,
796 .procname = "swappiness",
797 .data = &vm_swappiness,
798 .maxlen = sizeof(vm_swappiness),
800 .proc_handler = &proc_dointvec_minmax,
801 .strategy = &sysctl_intvec,
803 .extra2 = &one_hundred,
805 #ifdef CONFIG_HUGETLB_PAGE
807 .ctl_name = VM_HUGETLB_PAGES,
808 .procname = "nr_hugepages",
809 .data = &max_huge_pages,
810 .maxlen = sizeof(unsigned long),
812 .proc_handler = &hugetlb_sysctl_handler,
813 .extra1 = (void *)&hugetlb_zero,
814 .extra2 = (void *)&hugetlb_infinity,
817 .ctl_name = VM_HUGETLB_GROUP,
818 .procname = "hugetlb_shm_group",
819 .data = &sysctl_hugetlb_shm_group,
820 .maxlen = sizeof(gid_t),
822 .proc_handler = &proc_dointvec,
826 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
827 .procname = "lowmem_reserve_ratio",
828 .data = &sysctl_lowmem_reserve_ratio,
829 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
831 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
832 .strategy = &sysctl_intvec,
835 .ctl_name = VM_DROP_PAGECACHE,
836 .procname = "drop_caches",
837 .data = &sysctl_drop_caches,
838 .maxlen = sizeof(int),
840 .proc_handler = drop_caches_sysctl_handler,
841 .strategy = &sysctl_intvec,
844 .ctl_name = VM_MIN_FREE_KBYTES,
845 .procname = "min_free_kbytes",
846 .data = &min_free_kbytes,
847 .maxlen = sizeof(min_free_kbytes),
849 .proc_handler = &min_free_kbytes_sysctl_handler,
850 .strategy = &sysctl_intvec,
854 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
855 .procname = "percpu_pagelist_fraction",
856 .data = &percpu_pagelist_fraction,
857 .maxlen = sizeof(percpu_pagelist_fraction),
859 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
860 .strategy = &sysctl_intvec,
861 .extra1 = &min_percpu_pagelist_fract,
865 .ctl_name = VM_MAX_MAP_COUNT,
866 .procname = "max_map_count",
867 .data = &sysctl_max_map_count,
868 .maxlen = sizeof(sysctl_max_map_count),
870 .proc_handler = &proc_dointvec
874 .ctl_name = VM_LAPTOP_MODE,
875 .procname = "laptop_mode",
876 .data = &laptop_mode,
877 .maxlen = sizeof(laptop_mode),
879 .proc_handler = &proc_dointvec_jiffies,
880 .strategy = &sysctl_jiffies,
883 .ctl_name = VM_BLOCK_DUMP,
884 .procname = "block_dump",
886 .maxlen = sizeof(block_dump),
888 .proc_handler = &proc_dointvec,
889 .strategy = &sysctl_intvec,
893 .ctl_name = VM_VFS_CACHE_PRESSURE,
894 .procname = "vfs_cache_pressure",
895 .data = &sysctl_vfs_cache_pressure,
896 .maxlen = sizeof(sysctl_vfs_cache_pressure),
898 .proc_handler = &proc_dointvec,
899 .strategy = &sysctl_intvec,
902 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
904 .ctl_name = VM_LEGACY_VA_LAYOUT,
905 .procname = "legacy_va_layout",
906 .data = &sysctl_legacy_va_layout,
907 .maxlen = sizeof(sysctl_legacy_va_layout),
909 .proc_handler = &proc_dointvec,
910 .strategy = &sysctl_intvec,
916 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
917 .procname = "swap_token_timeout",
918 .data = &swap_token_default_timeout,
919 .maxlen = sizeof(swap_token_default_timeout),
921 .proc_handler = &proc_dointvec_jiffies,
922 .strategy = &sysctl_jiffies,
927 .ctl_name = VM_ZONE_RECLAIM_MODE,
928 .procname = "zone_reclaim_mode",
929 .data = &zone_reclaim_mode,
930 .maxlen = sizeof(zone_reclaim_mode),
932 .proc_handler = &proc_dointvec,
933 .strategy = &sysctl_intvec,
937 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
938 .procname = "zone_reclaim_interval",
939 .data = &zone_reclaim_interval,
940 .maxlen = sizeof(zone_reclaim_interval),
942 .proc_handler = &proc_dointvec_jiffies,
943 .strategy = &sysctl_jiffies,
948 .ctl_name = VM_VDSO_ENABLED,
949 .procname = "vdso_enabled",
950 .data = &vdso_enabled,
951 .maxlen = sizeof(vdso_enabled),
953 .proc_handler = &proc_dointvec,
954 .strategy = &sysctl_intvec,
961 static ctl_table fs_table[] = {
963 .ctl_name = FS_NRINODE,
964 .procname = "inode-nr",
965 .data = &inodes_stat,
966 .maxlen = 2*sizeof(int),
968 .proc_handler = &proc_dointvec,
971 .ctl_name = FS_STATINODE,
972 .procname = "inode-state",
973 .data = &inodes_stat,
974 .maxlen = 7*sizeof(int),
976 .proc_handler = &proc_dointvec,
979 .ctl_name = FS_NRFILE,
980 .procname = "file-nr",
982 .maxlen = 3*sizeof(int),
984 .proc_handler = &proc_nr_files,
987 .ctl_name = FS_MAXFILE,
988 .procname = "file-max",
989 .data = &files_stat.max_files,
990 .maxlen = sizeof(int),
992 .proc_handler = &proc_dointvec,
995 .ctl_name = FS_DENTRY,
996 .procname = "dentry-state",
997 .data = &dentry_stat,
998 .maxlen = 6*sizeof(int),
1000 .proc_handler = &proc_dointvec,
1003 .ctl_name = FS_OVERFLOWUID,
1004 .procname = "overflowuid",
1005 .data = &fs_overflowuid,
1006 .maxlen = sizeof(int),
1008 .proc_handler = &proc_dointvec_minmax,
1009 .strategy = &sysctl_intvec,
1010 .extra1 = &minolduid,
1011 .extra2 = &maxolduid,
1014 .ctl_name = FS_OVERFLOWGID,
1015 .procname = "overflowgid",
1016 .data = &fs_overflowgid,
1017 .maxlen = sizeof(int),
1019 .proc_handler = &proc_dointvec_minmax,
1020 .strategy = &sysctl_intvec,
1021 .extra1 = &minolduid,
1022 .extra2 = &maxolduid,
1025 .ctl_name = FS_LEASES,
1026 .procname = "leases-enable",
1027 .data = &leases_enable,
1028 .maxlen = sizeof(int),
1030 .proc_handler = &proc_dointvec,
1032 #ifdef CONFIG_DNOTIFY
1034 .ctl_name = FS_DIR_NOTIFY,
1035 .procname = "dir-notify-enable",
1036 .data = &dir_notify_enable,
1037 .maxlen = sizeof(int),
1039 .proc_handler = &proc_dointvec,
1044 .ctl_name = FS_LEASE_TIME,
1045 .procname = "lease-break-time",
1046 .data = &lease_break_time,
1047 .maxlen = sizeof(int),
1049 .proc_handler = &proc_dointvec,
1052 .ctl_name = FS_AIO_NR,
1053 .procname = "aio-nr",
1055 .maxlen = sizeof(aio_nr),
1057 .proc_handler = &proc_doulongvec_minmax,
1060 .ctl_name = FS_AIO_MAX_NR,
1061 .procname = "aio-max-nr",
1062 .data = &aio_max_nr,
1063 .maxlen = sizeof(aio_max_nr),
1065 .proc_handler = &proc_doulongvec_minmax,
1067 #ifdef CONFIG_INOTIFY_USER
1069 .ctl_name = FS_INOTIFY,
1070 .procname = "inotify",
1072 .child = inotify_table,
1077 .ctl_name = KERN_SETUID_DUMPABLE,
1078 .procname = "suid_dumpable",
1079 .data = &suid_dumpable,
1080 .maxlen = sizeof(int),
1082 .proc_handler = &proc_dointvec,
1087 static ctl_table debug_table[] = {
1091 static ctl_table dev_table[] = {
1095 extern void init_irq_proc (void);
1097 static DEFINE_SPINLOCK(sysctl_lock);
1099 /* called under sysctl_lock */
1100 static int use_table(struct ctl_table_header *p)
1102 if (unlikely(p->unregistering))
1108 /* called under sysctl_lock */
1109 static void unuse_table(struct ctl_table_header *p)
1112 if (unlikely(p->unregistering))
1113 complete(p->unregistering);
1116 /* called under sysctl_lock, will reacquire if has to wait */
1117 static void start_unregistering(struct ctl_table_header *p)
1120 * if p->used is 0, nobody will ever touch that entry again;
1121 * we'll eliminate all paths to it before dropping sysctl_lock
1123 if (unlikely(p->used)) {
1124 struct completion wait;
1125 init_completion(&wait);
1126 p->unregistering = &wait;
1127 spin_unlock(&sysctl_lock);
1128 wait_for_completion(&wait);
1129 spin_lock(&sysctl_lock);
1132 * do not remove from the list until nobody holds it; walking the
1133 * list in do_sysctl() relies on that.
1135 list_del_init(&p->ctl_entry);
1138 void __init sysctl_init(void)
1140 #ifdef CONFIG_PROC_FS
1141 register_proc_table(root_table, proc_sys_root, &root_table_header);
1146 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1147 void __user *newval, size_t newlen)
1149 struct list_head *tmp;
1150 int error = -ENOTDIR;
1152 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1156 if (!oldlenp || get_user(old_len, oldlenp))
1159 spin_lock(&sysctl_lock);
1160 tmp = &root_table_header.ctl_entry;
1162 struct ctl_table_header *head =
1163 list_entry(tmp, struct ctl_table_header, ctl_entry);
1164 void *context = NULL;
1166 if (!use_table(head))
1169 spin_unlock(&sysctl_lock);
1171 error = parse_table(name, nlen, oldval, oldlenp,
1172 newval, newlen, head->ctl_table,
1176 spin_lock(&sysctl_lock);
1178 if (error != -ENOTDIR)
1180 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1181 spin_unlock(&sysctl_lock);
1185 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1187 struct __sysctl_args tmp;
1190 if (copy_from_user(&tmp, args, sizeof(tmp)))
1194 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1195 tmp.newval, tmp.newlen);
1201 * ctl_perm does NOT grant the superuser all rights automatically, because
1202 * some sysctl variables are readonly even to root.
1205 static int test_perm(int mode, int op)
1209 else if (in_egroup_p(0))
1211 if ((mode & op & 0007) == op)
1216 static inline int ctl_perm(ctl_table *table, int op)
1219 error = security_sysctl(table, op);
1222 return test_perm(table->mode, op);
1225 static int parse_table(int __user *name, int nlen,
1226 void __user *oldval, size_t __user *oldlenp,
1227 void __user *newval, size_t newlen,
1228 ctl_table *table, void **context)
1234 if (get_user(n, name))
1236 for ( ; table->ctl_name; table++) {
1237 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1240 if (ctl_perm(table, 001))
1242 if (table->strategy) {
1243 error = table->strategy(
1246 newval, newlen, context);
1252 table = table->child;
1255 error = do_sysctl_strategy(table, name, nlen,
1257 newval, newlen, context);
1264 /* Perform the actual read/write of a sysctl table entry. */
1265 int do_sysctl_strategy (ctl_table *table,
1266 int __user *name, int nlen,
1267 void __user *oldval, size_t __user *oldlenp,
1268 void __user *newval, size_t newlen, void **context)
1277 if (ctl_perm(table, op))
1280 if (table->strategy) {
1281 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1282 newval, newlen, context);
1289 /* If there is no strategy routine, or if the strategy returns
1290 * zero, proceed with automatic r/w */
1291 if (table->data && table->maxlen) {
1292 if (oldval && oldlenp) {
1293 if (get_user(len, oldlenp))
1296 if (len > table->maxlen)
1297 len = table->maxlen;
1298 if(copy_to_user(oldval, table->data, len))
1300 if(put_user(len, oldlenp))
1304 if (newval && newlen) {
1306 if (len > table->maxlen)
1307 len = table->maxlen;
1308 if(copy_from_user(table->data, newval, len))
1316 * register_sysctl_table - register a sysctl hierarchy
1317 * @table: the top-level table structure
1318 * @insert_at_head: whether the entry should be inserted in front or at the end
1320 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1321 * array. An entry with a ctl_name of 0 terminates the table.
1323 * The members of the &ctl_table structure are used as follows:
1325 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1326 * must be unique within that level of sysctl
1328 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1329 * enter a sysctl file
1331 * data - a pointer to data for use by proc_handler
1333 * maxlen - the maximum size in bytes of the data
1335 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1337 * child - a pointer to the child sysctl table if this entry is a directory, or
1340 * proc_handler - the text handler routine (described below)
1342 * strategy - the strategy routine (described below)
1344 * de - for internal use by the sysctl routines
1346 * extra1, extra2 - extra pointers usable by the proc handler routines
1348 * Leaf nodes in the sysctl tree will be represented by a single file
1349 * under /proc; non-leaf nodes will be represented by directories.
1351 * sysctl(2) can automatically manage read and write requests through
1352 * the sysctl table. The data and maxlen fields of the ctl_table
1353 * struct enable minimal validation of the values being written to be
1354 * performed, and the mode field allows minimal authentication.
1356 * More sophisticated management can be enabled by the provision of a
1357 * strategy routine with the table entry. This will be called before
1358 * any automatic read or write of the data is performed.
1360 * The strategy routine may return
1362 * < 0 - Error occurred (error is passed to user process)
1364 * 0 - OK - proceed with automatic read or write.
1366 * > 0 - OK - read or write has been done by the strategy routine, so
1367 * return immediately.
1369 * There must be a proc_handler routine for any terminal nodes
1370 * mirrored under /proc/sys (non-terminals are handled by a built-in
1371 * directory handler). Several default handlers are available to
1372 * cover common cases -
1374 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1375 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1376 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1378 * It is the handler's job to read the input buffer from user memory
1379 * and process it. The handler should return 0 on success.
1381 * This routine returns %NULL on a failure to register, and a pointer
1382 * to the table header on success.
1384 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1387 struct ctl_table_header *tmp;
1388 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1391 tmp->ctl_table = table;
1392 INIT_LIST_HEAD(&tmp->ctl_entry);
1394 tmp->unregistering = NULL;
1395 spin_lock(&sysctl_lock);
1397 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1399 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1400 spin_unlock(&sysctl_lock);
1401 #ifdef CONFIG_PROC_FS
1402 register_proc_table(table, proc_sys_root, tmp);
1408 * unregister_sysctl_table - unregister a sysctl table hierarchy
1409 * @header: the header returned from register_sysctl_table
1411 * Unregisters the sysctl table and all children. proc entries may not
1412 * actually be removed until they are no longer used by anyone.
1414 void unregister_sysctl_table(struct ctl_table_header * header)
1417 spin_lock(&sysctl_lock);
1418 start_unregistering(header);
1419 #ifdef CONFIG_PROC_FS
1420 unregister_proc_table(header->ctl_table, proc_sys_root);
1422 spin_unlock(&sysctl_lock);
1430 #ifdef CONFIG_PROC_FS
1432 /* Scan the sysctl entries in table and add them all into /proc */
1433 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1435 struct proc_dir_entry *de;
1439 for (; table->ctl_name; table++) {
1440 /* Can't do anything without a proc name. */
1441 if (!table->procname)
1443 /* Maybe we can't do anything with it... */
1444 if (!table->proc_handler && !table->child) {
1445 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1450 len = strlen(table->procname);
1454 if (table->proc_handler)
1458 for (de = root->subdir; de; de = de->next) {
1459 if (proc_match(len, table->procname, de))
1462 /* If the subdir exists already, de is non-NULL */
1466 de = create_proc_entry(table->procname, mode, root);
1470 de->data = (void *) table;
1471 if (table->proc_handler)
1472 de->proc_fops = &proc_sys_file_operations;
1475 if (de->mode & S_IFDIR)
1476 register_proc_table(table->child, de, set);
1481 * Unregister a /proc sysctl table and any subdirectories.
1483 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1485 struct proc_dir_entry *de;
1486 for (; table->ctl_name; table++) {
1487 if (!(de = table->de))
1489 if (de->mode & S_IFDIR) {
1490 if (!table->child) {
1491 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1494 unregister_proc_table(table->child, de);
1496 /* Don't unregister directories which still have entries.. */
1502 * In any case, mark the entry as goner; we'll keep it
1503 * around if it's busy, but we'll know to do nothing with
1504 * its fields. We are under sysctl_lock here.
1508 /* Don't unregister proc entries that are still being used.. */
1509 if (atomic_read(&de->count))
1513 remove_proc_entry(table->procname, root);
1517 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1518 size_t count, loff_t *ppos)
1521 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1522 struct ctl_table *table;
1524 ssize_t error = -ENOTDIR;
1526 spin_lock(&sysctl_lock);
1527 if (de && de->data && use_table(de->set)) {
1529 * at that point we know that sysctl was not unregistered
1530 * and won't be until we finish
1532 spin_unlock(&sysctl_lock);
1533 table = (struct ctl_table *) de->data;
1534 if (!table || !table->proc_handler)
1537 op = (write ? 002 : 004);
1538 if (ctl_perm(table, op))
1541 /* careful: calling conventions are nasty here */
1543 error = (*table->proc_handler)(table, write, file,
1548 spin_lock(&sysctl_lock);
1549 unuse_table(de->set);
1551 spin_unlock(&sysctl_lock);
1555 static int proc_opensys(struct inode *inode, struct file *file)
1557 if (file->f_mode & FMODE_WRITE) {
1559 * sysctl entries that are not writable,
1560 * are _NOT_ writable, capabilities or not.
1562 if (!(inode->i_mode & S_IWUSR))
1569 static ssize_t proc_readsys(struct file * file, char __user * buf,
1570 size_t count, loff_t *ppos)
1572 return do_rw_proc(0, file, buf, count, ppos);
1575 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1576 size_t count, loff_t *ppos)
1578 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1582 * proc_dostring - read a string sysctl
1583 * @table: the sysctl table
1584 * @write: %TRUE if this is a write to the sysctl file
1585 * @filp: the file structure
1586 * @buffer: the user buffer
1587 * @lenp: the size of the user buffer
1588 * @ppos: file position
1590 * Reads/writes a string from/to the user buffer. If the kernel
1591 * buffer provided is not large enough to hold the string, the
1592 * string is truncated. The copied string is %NULL-terminated.
1593 * If the string is being read by the user process, it is copied
1594 * and a newline '\n' is added. It is truncated if the buffer is
1597 * Returns 0 on success.
1599 int proc_dostring(ctl_table *table, int write, struct file *filp,
1600 void __user *buffer, size_t *lenp, loff_t *ppos)
1606 if (!table->data || !table->maxlen || !*lenp ||
1607 (*ppos && !write)) {
1615 while (len < *lenp) {
1616 if (get_user(c, p++))
1618 if (c == 0 || c == '\n')
1622 if (len >= table->maxlen)
1623 len = table->maxlen-1;
1624 if(copy_from_user(table->data, buffer, len))
1626 ((char *) table->data)[len] = 0;
1629 len = strlen(table->data);
1630 if (len > table->maxlen)
1631 len = table->maxlen;
1635 if(copy_to_user(buffer, table->data, len))
1638 if(put_user('\n', ((char __user *) buffer) + len))
1649 * Special case of dostring for the UTS structure. This has locks
1650 * to observe. Should this be in kernel/sys.c ????
1653 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1654 void __user *buffer, size_t *lenp, loff_t *ppos)
1659 down_read(&uts_sem);
1660 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1663 down_write(&uts_sem);
1664 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1670 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1672 int write, void *data)
1675 *valp = *negp ? -*lvalp : *lvalp;
1680 *lvalp = (unsigned long)-val;
1683 *lvalp = (unsigned long)val;
1689 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1690 void __user *buffer, size_t *lenp, loff_t *ppos,
1691 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1692 int write, void *data),
1695 #define TMPBUFLEN 21
1696 int *i, vleft, first=1, neg, val;
1700 char buf[TMPBUFLEN], *p;
1701 char __user *s = buffer;
1703 if (!table->data || !table->maxlen || !*lenp ||
1704 (*ppos && !write)) {
1709 i = (int *) table->data;
1710 vleft = table->maxlen / sizeof(*i);
1714 conv = do_proc_dointvec_conv;
1716 for (; left && vleft--; i++, first=0) {
1731 if (len > sizeof(buf) - 1)
1732 len = sizeof(buf) - 1;
1733 if (copy_from_user(buf, s, len))
1737 if (*p == '-' && left > 1) {
1741 if (*p < '0' || *p > '9')
1744 lval = simple_strtoul(p, &p, 0);
1747 if ((len < left) && *p && !isspace(*p))
1754 if (conv(&neg, &lval, i, 1, data))
1761 if (conv(&neg, &lval, i, 0, data))
1764 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1768 if(copy_to_user(s, buf, len))
1775 if (!write && !first && left) {
1776 if(put_user('\n', s))
1783 if (get_user(c, s++))
1799 * proc_dointvec - read a vector of integers
1800 * @table: the sysctl table
1801 * @write: %TRUE if this is a write to the sysctl file
1802 * @filp: the file structure
1803 * @buffer: the user buffer
1804 * @lenp: the size of the user buffer
1805 * @ppos: file position
1807 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1808 * values from/to the user buffer, treated as an ASCII string.
1810 * Returns 0 on success.
1812 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1813 void __user *buffer, size_t *lenp, loff_t *ppos)
1815 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1825 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1827 int write, void *data)
1829 int op = *(int *)data;
1831 int val = *negp ? -*lvalp : *lvalp;
1833 case OP_SET: *valp = val; break;
1834 case OP_AND: *valp &= val; break;
1835 case OP_OR: *valp |= val; break;
1836 case OP_MAX: if(*valp < val)
1839 case OP_MIN: if(*valp > val)
1847 *lvalp = (unsigned long)-val;
1850 *lvalp = (unsigned long)val;
1857 * init may raise the set.
1860 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1861 void __user *buffer, size_t *lenp, loff_t *ppos)
1865 if (!capable(CAP_SYS_MODULE)) {
1869 op = (current->pid == 1) ? OP_SET : OP_AND;
1870 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1871 do_proc_dointvec_bset_conv,&op);
1874 struct do_proc_dointvec_minmax_conv_param {
1879 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1881 int write, void *data)
1883 struct do_proc_dointvec_minmax_conv_param *param = data;
1885 int val = *negp ? -*lvalp : *lvalp;
1886 if ((param->min && *param->min > val) ||
1887 (param->max && *param->max < val))
1894 *lvalp = (unsigned long)-val;
1897 *lvalp = (unsigned long)val;
1904 * proc_dointvec_minmax - read a vector of integers with min/max values
1905 * @table: the sysctl table
1906 * @write: %TRUE if this is a write to the sysctl file
1907 * @filp: the file structure
1908 * @buffer: the user buffer
1909 * @lenp: the size of the user buffer
1910 * @ppos: file position
1912 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1913 * values from/to the user buffer, treated as an ASCII string.
1915 * This routine will ensure the values are within the range specified by
1916 * table->extra1 (min) and table->extra2 (max).
1918 * Returns 0 on success.
1920 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1921 void __user *buffer, size_t *lenp, loff_t *ppos)
1923 struct do_proc_dointvec_minmax_conv_param param = {
1924 .min = (int *) table->extra1,
1925 .max = (int *) table->extra2,
1927 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1928 do_proc_dointvec_minmax_conv, ¶m);
1931 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1933 void __user *buffer,
1934 size_t *lenp, loff_t *ppos,
1935 unsigned long convmul,
1936 unsigned long convdiv)
1938 #define TMPBUFLEN 21
1939 unsigned long *i, *min, *max, val;
1940 int vleft, first=1, neg;
1942 char buf[TMPBUFLEN], *p;
1943 char __user *s = buffer;
1945 if (!table->data || !table->maxlen || !*lenp ||
1946 (*ppos && !write)) {
1951 i = (unsigned long *) table->data;
1952 min = (unsigned long *) table->extra1;
1953 max = (unsigned long *) table->extra2;
1954 vleft = table->maxlen / sizeof(unsigned long);
1957 for (; left && vleft--; i++, min++, max++, first=0) {
1972 if (len > TMPBUFLEN-1)
1974 if (copy_from_user(buf, s, len))
1978 if (*p == '-' && left > 1) {
1982 if (*p < '0' || *p > '9')
1984 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1986 if ((len < left) && *p && !isspace(*p))
1995 if ((min && val < *min) || (max && val > *max))
2002 sprintf(p, "%lu", convdiv * (*i) / convmul);
2006 if(copy_to_user(s, buf, len))
2013 if (!write && !first && left) {
2014 if(put_user('\n', s))
2021 if (get_user(c, s++))
2037 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2038 * @table: the sysctl table
2039 * @write: %TRUE if this is a write to the sysctl file
2040 * @filp: the file structure
2041 * @buffer: the user buffer
2042 * @lenp: the size of the user buffer
2043 * @ppos: file position
2045 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2046 * values from/to the user buffer, treated as an ASCII string.
2048 * This routine will ensure the values are within the range specified by
2049 * table->extra1 (min) and table->extra2 (max).
2051 * Returns 0 on success.
2053 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2054 void __user *buffer, size_t *lenp, loff_t *ppos)
2056 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2060 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2061 * @table: the sysctl table
2062 * @write: %TRUE if this is a write to the sysctl file
2063 * @filp: the file structure
2064 * @buffer: the user buffer
2065 * @lenp: the size of the user buffer
2066 * @ppos: file position
2068 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2069 * values from/to the user buffer, treated as an ASCII string. The values
2070 * are treated as milliseconds, and converted to jiffies when they are stored.
2072 * This routine will ensure the values are within the range specified by
2073 * table->extra1 (min) and table->extra2 (max).
2075 * Returns 0 on success.
2077 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2079 void __user *buffer,
2080 size_t *lenp, loff_t *ppos)
2082 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2083 lenp, ppos, HZ, 1000l);
2087 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2089 int write, void *data)
2092 if (*lvalp > LONG_MAX / HZ)
2094 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2100 lval = (unsigned long)-val;
2103 lval = (unsigned long)val;
2110 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2112 int write, void *data)
2115 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2117 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2123 lval = (unsigned long)-val;
2126 lval = (unsigned long)val;
2128 *lvalp = jiffies_to_clock_t(lval);
2133 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2135 int write, void *data)
2138 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2144 lval = (unsigned long)-val;
2147 lval = (unsigned long)val;
2149 *lvalp = jiffies_to_msecs(lval);
2155 * proc_dointvec_jiffies - read a vector of integers as seconds
2156 * @table: the sysctl table
2157 * @write: %TRUE if this is a write to the sysctl file
2158 * @filp: the file structure
2159 * @buffer: the user buffer
2160 * @lenp: the size of the user buffer
2161 * @ppos: file position
2163 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2164 * values from/to the user buffer, treated as an ASCII string.
2165 * The values read are assumed to be in seconds, and are converted into
2168 * Returns 0 on success.
2170 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2171 void __user *buffer, size_t *lenp, loff_t *ppos)
2173 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2174 do_proc_dointvec_jiffies_conv,NULL);
2178 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2179 * @table: the sysctl table
2180 * @write: %TRUE if this is a write to the sysctl file
2181 * @filp: the file structure
2182 * @buffer: the user buffer
2183 * @lenp: the size of the user buffer
2184 * @ppos: pointer to the file position
2186 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2187 * values from/to the user buffer, treated as an ASCII string.
2188 * The values read are assumed to be in 1/USER_HZ seconds, and
2189 * are converted into jiffies.
2191 * Returns 0 on success.
2193 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2194 void __user *buffer, size_t *lenp, loff_t *ppos)
2196 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2197 do_proc_dointvec_userhz_jiffies_conv,NULL);
2201 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2202 * @table: the sysctl table
2203 * @write: %TRUE if this is a write to the sysctl file
2204 * @filp: the file structure
2205 * @buffer: the user buffer
2206 * @lenp: the size of the user buffer
2207 * @ppos: file position
2208 * @ppos: the current position in the file
2210 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2211 * values from/to the user buffer, treated as an ASCII string.
2212 * The values read are assumed to be in 1/1000 seconds, and
2213 * are converted into jiffies.
2215 * Returns 0 on success.
2217 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2218 void __user *buffer, size_t *lenp, loff_t *ppos)
2220 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2221 do_proc_dointvec_ms_jiffies_conv, NULL);
2224 #else /* CONFIG_PROC_FS */
2226 int proc_dostring(ctl_table *table, int write, struct file *filp,
2227 void __user *buffer, size_t *lenp, loff_t *ppos)
2232 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2233 void __user *buffer, size_t *lenp, loff_t *ppos)
2238 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2239 void __user *buffer, size_t *lenp, loff_t *ppos)
2244 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2245 void __user *buffer, size_t *lenp, loff_t *ppos)
2250 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2251 void __user *buffer, size_t *lenp, loff_t *ppos)
2256 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2257 void __user *buffer, size_t *lenp, loff_t *ppos)
2262 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2263 void __user *buffer, size_t *lenp, loff_t *ppos)
2268 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2269 void __user *buffer, size_t *lenp, loff_t *ppos)
2274 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2275 void __user *buffer, size_t *lenp, loff_t *ppos)
2280 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2282 void __user *buffer,
2283 size_t *lenp, loff_t *ppos)
2289 #endif /* CONFIG_PROC_FS */
2293 * General sysctl support routines
2296 /* The generic string strategy routine: */
2297 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2298 void __user *oldval, size_t __user *oldlenp,
2299 void __user *newval, size_t newlen, void **context)
2301 if (!table->data || !table->maxlen)
2304 if (oldval && oldlenp) {
2306 if (get_user(bufsize, oldlenp))
2309 size_t len = strlen(table->data), copied;
2311 /* This shouldn't trigger for a well-formed sysctl */
2312 if (len > table->maxlen)
2313 len = table->maxlen;
2315 /* Copy up to a max of bufsize-1 bytes of the string */
2316 copied = (len >= bufsize) ? bufsize - 1 : len;
2318 if (copy_to_user(oldval, table->data, copied) ||
2319 put_user(0, (char __user *)(oldval + copied)))
2321 if (put_user(len, oldlenp))
2325 if (newval && newlen) {
2326 size_t len = newlen;
2327 if (len > table->maxlen)
2328 len = table->maxlen;
2329 if(copy_from_user(table->data, newval, len))
2331 if (len == table->maxlen)
2333 ((char *) table->data)[len] = 0;
2339 * This function makes sure that all of the integers in the vector
2340 * are between the minimum and maximum values given in the arrays
2341 * table->extra1 and table->extra2, respectively.
2343 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2344 void __user *oldval, size_t __user *oldlenp,
2345 void __user *newval, size_t newlen, void **context)
2348 if (newval && newlen) {
2349 int __user *vec = (int __user *) newval;
2350 int *min = (int *) table->extra1;
2351 int *max = (int *) table->extra2;
2355 if (newlen % sizeof(int) != 0)
2358 if (!table->extra1 && !table->extra2)
2361 if (newlen > table->maxlen)
2362 newlen = table->maxlen;
2363 length = newlen / sizeof(int);
2365 for (i = 0; i < length; i++) {
2367 if (get_user(value, vec + i))
2369 if (min && value < min[i])
2371 if (max && value > max[i])
2378 /* Strategy function to convert jiffies to seconds */
2379 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2380 void __user *oldval, size_t __user *oldlenp,
2381 void __user *newval, size_t newlen, void **context)
2386 if (get_user(olen, oldlenp))
2388 if (olen!=sizeof(int))
2391 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2392 (oldlenp && put_user(sizeof(int),oldlenp)))
2395 if (newval && newlen) {
2397 if (newlen != sizeof(int))
2399 if (get_user(new, (int __user *)newval))
2401 *(int *)(table->data) = new*HZ;
2406 /* Strategy function to convert jiffies to seconds */
2407 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2408 void __user *oldval, size_t __user *oldlenp,
2409 void __user *newval, size_t newlen, void **context)
2414 if (get_user(olen, oldlenp))
2416 if (olen!=sizeof(int))
2419 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2420 (oldlenp && put_user(sizeof(int),oldlenp)))
2423 if (newval && newlen) {
2425 if (newlen != sizeof(int))
2427 if (get_user(new, (int __user *)newval))
2429 *(int *)(table->data) = msecs_to_jiffies(new);
2434 #else /* CONFIG_SYSCTL */
2437 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2442 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2443 void __user *oldval, size_t __user *oldlenp,
2444 void __user *newval, size_t newlen, void **context)
2449 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2450 void __user *oldval, size_t __user *oldlenp,
2451 void __user *newval, size_t newlen, void **context)
2456 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2457 void __user *oldval, size_t __user *oldlenp,
2458 void __user *newval, size_t newlen, void **context)
2463 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2464 void __user *oldval, size_t __user *oldlenp,
2465 void __user *newval, size_t newlen, void **context)
2470 int proc_dostring(ctl_table *table, int write, struct file *filp,
2471 void __user *buffer, size_t *lenp, loff_t *ppos)
2476 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2477 void __user *buffer, size_t *lenp, loff_t *ppos)
2482 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2483 void __user *buffer, size_t *lenp, loff_t *ppos)
2488 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2489 void __user *buffer, size_t *lenp, loff_t *ppos)
2494 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2495 void __user *buffer, size_t *lenp, loff_t *ppos)
2500 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2501 void __user *buffer, size_t *lenp, loff_t *ppos)
2506 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2507 void __user *buffer, size_t *lenp, loff_t *ppos)
2512 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2513 void __user *buffer, size_t *lenp, loff_t *ppos)
2518 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2520 void __user *buffer,
2521 size_t *lenp, loff_t *ppos)
2526 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2532 void unregister_sysctl_table(struct ctl_table_header * table)
2536 #endif /* CONFIG_SYSCTL */
2539 * No sense putting this after each symbol definition, twice,
2540 * exception granted :-)
2542 EXPORT_SYMBOL(proc_dointvec);
2543 EXPORT_SYMBOL(proc_dointvec_jiffies);
2544 EXPORT_SYMBOL(proc_dointvec_minmax);
2545 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2546 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2547 EXPORT_SYMBOL(proc_dostring);
2548 EXPORT_SYMBOL(proc_doulongvec_minmax);
2549 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2550 EXPORT_SYMBOL(register_sysctl_table);
2551 EXPORT_SYMBOL(sysctl_intvec);
2552 EXPORT_SYMBOL(sysctl_jiffies);
2553 EXPORT_SYMBOL(sysctl_ms_jiffies);
2554 EXPORT_SYMBOL(sysctl_string);
2555 EXPORT_SYMBOL(unregister_sysctl_table);