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
,
939 .ctl_name
= VM_VDSO_ENABLED
,
940 .procname
= "vdso_enabled",
941 .data
= &vdso_enabled
,
942 .maxlen
= sizeof(vdso_enabled
),
944 .proc_handler
= &proc_dointvec
,
945 .strategy
= &sysctl_intvec
,
952 static ctl_table fs_table
[] = {
954 .ctl_name
= FS_NRINODE
,
955 .procname
= "inode-nr",
956 .data
= &inodes_stat
,
957 .maxlen
= 2*sizeof(int),
959 .proc_handler
= &proc_dointvec
,
962 .ctl_name
= FS_STATINODE
,
963 .procname
= "inode-state",
964 .data
= &inodes_stat
,
965 .maxlen
= 7*sizeof(int),
967 .proc_handler
= &proc_dointvec
,
970 .ctl_name
= FS_NRFILE
,
971 .procname
= "file-nr",
973 .maxlen
= 3*sizeof(int),
975 .proc_handler
= &proc_nr_files
,
978 .ctl_name
= FS_MAXFILE
,
979 .procname
= "file-max",
980 .data
= &files_stat
.max_files
,
981 .maxlen
= sizeof(int),
983 .proc_handler
= &proc_dointvec
,
986 .ctl_name
= FS_DENTRY
,
987 .procname
= "dentry-state",
988 .data
= &dentry_stat
,
989 .maxlen
= 6*sizeof(int),
991 .proc_handler
= &proc_dointvec
,
994 .ctl_name
= FS_OVERFLOWUID
,
995 .procname
= "overflowuid",
996 .data
= &fs_overflowuid
,
997 .maxlen
= sizeof(int),
999 .proc_handler
= &proc_dointvec_minmax
,
1000 .strategy
= &sysctl_intvec
,
1001 .extra1
= &minolduid
,
1002 .extra2
= &maxolduid
,
1005 .ctl_name
= FS_OVERFLOWGID
,
1006 .procname
= "overflowgid",
1007 .data
= &fs_overflowgid
,
1008 .maxlen
= sizeof(int),
1010 .proc_handler
= &proc_dointvec_minmax
,
1011 .strategy
= &sysctl_intvec
,
1012 .extra1
= &minolduid
,
1013 .extra2
= &maxolduid
,
1016 .ctl_name
= FS_LEASES
,
1017 .procname
= "leases-enable",
1018 .data
= &leases_enable
,
1019 .maxlen
= sizeof(int),
1021 .proc_handler
= &proc_dointvec
,
1023 #ifdef CONFIG_DNOTIFY
1025 .ctl_name
= FS_DIR_NOTIFY
,
1026 .procname
= "dir-notify-enable",
1027 .data
= &dir_notify_enable
,
1028 .maxlen
= sizeof(int),
1030 .proc_handler
= &proc_dointvec
,
1035 .ctl_name
= FS_LEASE_TIME
,
1036 .procname
= "lease-break-time",
1037 .data
= &lease_break_time
,
1038 .maxlen
= sizeof(int),
1040 .proc_handler
= &proc_dointvec
,
1043 .ctl_name
= FS_AIO_NR
,
1044 .procname
= "aio-nr",
1046 .maxlen
= sizeof(aio_nr
),
1048 .proc_handler
= &proc_doulongvec_minmax
,
1051 .ctl_name
= FS_AIO_MAX_NR
,
1052 .procname
= "aio-max-nr",
1053 .data
= &aio_max_nr
,
1054 .maxlen
= sizeof(aio_max_nr
),
1056 .proc_handler
= &proc_doulongvec_minmax
,
1058 #ifdef CONFIG_INOTIFY_USER
1060 .ctl_name
= FS_INOTIFY
,
1061 .procname
= "inotify",
1063 .child
= inotify_table
,
1068 .ctl_name
= KERN_SETUID_DUMPABLE
,
1069 .procname
= "suid_dumpable",
1070 .data
= &suid_dumpable
,
1071 .maxlen
= sizeof(int),
1073 .proc_handler
= &proc_dointvec
,
1078 static ctl_table debug_table
[] = {
1082 static ctl_table dev_table
[] = {
1086 extern void init_irq_proc (void);
1088 static DEFINE_SPINLOCK(sysctl_lock
);
1090 /* called under sysctl_lock */
1091 static int use_table(struct ctl_table_header
*p
)
1093 if (unlikely(p
->unregistering
))
1099 /* called under sysctl_lock */
1100 static void unuse_table(struct ctl_table_header
*p
)
1103 if (unlikely(p
->unregistering
))
1104 complete(p
->unregistering
);
1107 /* called under sysctl_lock, will reacquire if has to wait */
1108 static void start_unregistering(struct ctl_table_header
*p
)
1111 * if p->used is 0, nobody will ever touch that entry again;
1112 * we'll eliminate all paths to it before dropping sysctl_lock
1114 if (unlikely(p
->used
)) {
1115 struct completion wait
;
1116 init_completion(&wait
);
1117 p
->unregistering
= &wait
;
1118 spin_unlock(&sysctl_lock
);
1119 wait_for_completion(&wait
);
1120 spin_lock(&sysctl_lock
);
1123 * do not remove from the list until nobody holds it; walking the
1124 * list in do_sysctl() relies on that.
1126 list_del_init(&p
->ctl_entry
);
1129 void __init
sysctl_init(void)
1131 #ifdef CONFIG_PROC_FS
1132 register_proc_table(root_table
, proc_sys_root
, &root_table_header
);
1137 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1138 void __user
*newval
, size_t newlen
)
1140 struct list_head
*tmp
;
1141 int error
= -ENOTDIR
;
1143 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1147 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1150 spin_lock(&sysctl_lock
);
1151 tmp
= &root_table_header
.ctl_entry
;
1153 struct ctl_table_header
*head
=
1154 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1155 void *context
= NULL
;
1157 if (!use_table(head
))
1160 spin_unlock(&sysctl_lock
);
1162 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1163 newval
, newlen
, head
->ctl_table
,
1167 spin_lock(&sysctl_lock
);
1169 if (error
!= -ENOTDIR
)
1171 } while ((tmp
= tmp
->next
) != &root_table_header
.ctl_entry
);
1172 spin_unlock(&sysctl_lock
);
1176 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1178 struct __sysctl_args tmp
;
1181 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1185 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1186 tmp
.newval
, tmp
.newlen
);
1192 * ctl_perm does NOT grant the superuser all rights automatically, because
1193 * some sysctl variables are readonly even to root.
1196 static int test_perm(int mode
, int op
)
1200 else if (in_egroup_p(0))
1202 if ((mode
& op
& 0007) == op
)
1207 static inline int ctl_perm(ctl_table
*table
, int op
)
1210 error
= security_sysctl(table
, op
);
1213 return test_perm(table
->mode
, op
);
1216 static int parse_table(int __user
*name
, int nlen
,
1217 void __user
*oldval
, size_t __user
*oldlenp
,
1218 void __user
*newval
, size_t newlen
,
1219 ctl_table
*table
, void **context
)
1225 if (get_user(n
, name
))
1227 for ( ; table
->ctl_name
; table
++) {
1228 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1231 if (ctl_perm(table
, 001))
1233 if (table
->strategy
) {
1234 error
= table
->strategy(
1237 newval
, newlen
, context
);
1243 table
= table
->child
;
1246 error
= do_sysctl_strategy(table
, name
, nlen
,
1248 newval
, newlen
, context
);
1255 /* Perform the actual read/write of a sysctl table entry. */
1256 int do_sysctl_strategy (ctl_table
*table
,
1257 int __user
*name
, int nlen
,
1258 void __user
*oldval
, size_t __user
*oldlenp
,
1259 void __user
*newval
, size_t newlen
, void **context
)
1268 if (ctl_perm(table
, op
))
1271 if (table
->strategy
) {
1272 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1273 newval
, newlen
, context
);
1280 /* If there is no strategy routine, or if the strategy returns
1281 * zero, proceed with automatic r/w */
1282 if (table
->data
&& table
->maxlen
) {
1283 if (oldval
&& oldlenp
) {
1284 if (get_user(len
, oldlenp
))
1287 if (len
> table
->maxlen
)
1288 len
= table
->maxlen
;
1289 if(copy_to_user(oldval
, table
->data
, len
))
1291 if(put_user(len
, oldlenp
))
1295 if (newval
&& newlen
) {
1297 if (len
> table
->maxlen
)
1298 len
= table
->maxlen
;
1299 if(copy_from_user(table
->data
, newval
, len
))
1307 * register_sysctl_table - register a sysctl hierarchy
1308 * @table: the top-level table structure
1309 * @insert_at_head: whether the entry should be inserted in front or at the end
1311 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1312 * array. An entry with a ctl_name of 0 terminates the table.
1314 * The members of the &ctl_table structure are used as follows:
1316 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1317 * must be unique within that level of sysctl
1319 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1320 * enter a sysctl file
1322 * data - a pointer to data for use by proc_handler
1324 * maxlen - the maximum size in bytes of the data
1326 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1328 * child - a pointer to the child sysctl table if this entry is a directory, or
1331 * proc_handler - the text handler routine (described below)
1333 * strategy - the strategy routine (described below)
1335 * de - for internal use by the sysctl routines
1337 * extra1, extra2 - extra pointers usable by the proc handler routines
1339 * Leaf nodes in the sysctl tree will be represented by a single file
1340 * under /proc; non-leaf nodes will be represented by directories.
1342 * sysctl(2) can automatically manage read and write requests through
1343 * the sysctl table. The data and maxlen fields of the ctl_table
1344 * struct enable minimal validation of the values being written to be
1345 * performed, and the mode field allows minimal authentication.
1347 * More sophisticated management can be enabled by the provision of a
1348 * strategy routine with the table entry. This will be called before
1349 * any automatic read or write of the data is performed.
1351 * The strategy routine may return
1353 * < 0 - Error occurred (error is passed to user process)
1355 * 0 - OK - proceed with automatic read or write.
1357 * > 0 - OK - read or write has been done by the strategy routine, so
1358 * return immediately.
1360 * There must be a proc_handler routine for any terminal nodes
1361 * mirrored under /proc/sys (non-terminals are handled by a built-in
1362 * directory handler). Several default handlers are available to
1363 * cover common cases -
1365 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1366 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1367 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1369 * It is the handler's job to read the input buffer from user memory
1370 * and process it. The handler should return 0 on success.
1372 * This routine returns %NULL on a failure to register, and a pointer
1373 * to the table header on success.
1375 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1378 struct ctl_table_header
*tmp
;
1379 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1382 tmp
->ctl_table
= table
;
1383 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1385 tmp
->unregistering
= NULL
;
1386 spin_lock(&sysctl_lock
);
1388 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1390 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1391 spin_unlock(&sysctl_lock
);
1392 #ifdef CONFIG_PROC_FS
1393 register_proc_table(table
, proc_sys_root
, tmp
);
1399 * unregister_sysctl_table - unregister a sysctl table hierarchy
1400 * @header: the header returned from register_sysctl_table
1402 * Unregisters the sysctl table and all children. proc entries may not
1403 * actually be removed until they are no longer used by anyone.
1405 void unregister_sysctl_table(struct ctl_table_header
* header
)
1408 spin_lock(&sysctl_lock
);
1409 start_unregistering(header
);
1410 #ifdef CONFIG_PROC_FS
1411 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1413 spin_unlock(&sysctl_lock
);
1421 #ifdef CONFIG_PROC_FS
1423 /* Scan the sysctl entries in table and add them all into /proc */
1424 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
, void *set
)
1426 struct proc_dir_entry
*de
;
1430 for (; table
->ctl_name
; table
++) {
1431 /* Can't do anything without a proc name. */
1432 if (!table
->procname
)
1434 /* Maybe we can't do anything with it... */
1435 if (!table
->proc_handler
&& !table
->child
) {
1436 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1441 len
= strlen(table
->procname
);
1445 if (table
->proc_handler
)
1449 for (de
= root
->subdir
; de
; de
= de
->next
) {
1450 if (proc_match(len
, table
->procname
, de
))
1453 /* If the subdir exists already, de is non-NULL */
1457 de
= create_proc_entry(table
->procname
, mode
, root
);
1461 de
->data
= (void *) table
;
1462 if (table
->proc_handler
)
1463 de
->proc_fops
= &proc_sys_file_operations
;
1466 if (de
->mode
& S_IFDIR
)
1467 register_proc_table(table
->child
, de
, set
);
1472 * Unregister a /proc sysctl table and any subdirectories.
1474 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1476 struct proc_dir_entry
*de
;
1477 for (; table
->ctl_name
; table
++) {
1478 if (!(de
= table
->de
))
1480 if (de
->mode
& S_IFDIR
) {
1481 if (!table
->child
) {
1482 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1485 unregister_proc_table(table
->child
, de
);
1487 /* Don't unregister directories which still have entries.. */
1493 * In any case, mark the entry as goner; we'll keep it
1494 * around if it's busy, but we'll know to do nothing with
1495 * its fields. We are under sysctl_lock here.
1499 /* Don't unregister proc entries that are still being used.. */
1500 if (atomic_read(&de
->count
))
1504 remove_proc_entry(table
->procname
, root
);
1508 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1509 size_t count
, loff_t
*ppos
)
1512 struct proc_dir_entry
*de
= PDE(file
->f_dentry
->d_inode
);
1513 struct ctl_table
*table
;
1515 ssize_t error
= -ENOTDIR
;
1517 spin_lock(&sysctl_lock
);
1518 if (de
&& de
->data
&& use_table(de
->set
)) {
1520 * at that point we know that sysctl was not unregistered
1521 * and won't be until we finish
1523 spin_unlock(&sysctl_lock
);
1524 table
= (struct ctl_table
*) de
->data
;
1525 if (!table
|| !table
->proc_handler
)
1528 op
= (write
? 002 : 004);
1529 if (ctl_perm(table
, op
))
1532 /* careful: calling conventions are nasty here */
1534 error
= (*table
->proc_handler
)(table
, write
, file
,
1539 spin_lock(&sysctl_lock
);
1540 unuse_table(de
->set
);
1542 spin_unlock(&sysctl_lock
);
1546 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1548 if (file
->f_mode
& FMODE_WRITE
) {
1550 * sysctl entries that are not writable,
1551 * are _NOT_ writable, capabilities or not.
1553 if (!(inode
->i_mode
& S_IWUSR
))
1560 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1561 size_t count
, loff_t
*ppos
)
1563 return do_rw_proc(0, file
, buf
, count
, ppos
);
1566 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1567 size_t count
, loff_t
*ppos
)
1569 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1573 * proc_dostring - read a string sysctl
1574 * @table: the sysctl table
1575 * @write: %TRUE if this is a write to the sysctl file
1576 * @filp: the file structure
1577 * @buffer: the user buffer
1578 * @lenp: the size of the user buffer
1579 * @ppos: file position
1581 * Reads/writes a string from/to the user buffer. If the kernel
1582 * buffer provided is not large enough to hold the string, the
1583 * string is truncated. The copied string is %NULL-terminated.
1584 * If the string is being read by the user process, it is copied
1585 * and a newline '\n' is added. It is truncated if the buffer is
1588 * Returns 0 on success.
1590 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1591 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1597 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1598 (*ppos
&& !write
)) {
1606 while (len
< *lenp
) {
1607 if (get_user(c
, p
++))
1609 if (c
== 0 || c
== '\n')
1613 if (len
>= table
->maxlen
)
1614 len
= table
->maxlen
-1;
1615 if(copy_from_user(table
->data
, buffer
, len
))
1617 ((char *) table
->data
)[len
] = 0;
1620 len
= strlen(table
->data
);
1621 if (len
> table
->maxlen
)
1622 len
= table
->maxlen
;
1626 if(copy_to_user(buffer
, table
->data
, len
))
1629 if(put_user('\n', ((char __user
*) buffer
) + len
))
1640 * Special case of dostring for the UTS structure. This has locks
1641 * to observe. Should this be in kernel/sys.c ????
1644 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1645 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1650 down_read(&uts_sem
);
1651 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1654 down_write(&uts_sem
);
1655 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1661 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1663 int write
, void *data
)
1666 *valp
= *negp
? -*lvalp
: *lvalp
;
1671 *lvalp
= (unsigned long)-val
;
1674 *lvalp
= (unsigned long)val
;
1680 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1681 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1682 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1683 int write
, void *data
),
1686 #define TMPBUFLEN 21
1687 int *i
, vleft
, first
=1, neg
, val
;
1691 char buf
[TMPBUFLEN
], *p
;
1692 char __user
*s
= buffer
;
1694 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1695 (*ppos
&& !write
)) {
1700 i
= (int *) table
->data
;
1701 vleft
= table
->maxlen
/ sizeof(*i
);
1705 conv
= do_proc_dointvec_conv
;
1707 for (; left
&& vleft
--; i
++, first
=0) {
1722 if (len
> sizeof(buf
) - 1)
1723 len
= sizeof(buf
) - 1;
1724 if (copy_from_user(buf
, s
, len
))
1728 if (*p
== '-' && left
> 1) {
1732 if (*p
< '0' || *p
> '9')
1735 lval
= simple_strtoul(p
, &p
, 0);
1738 if ((len
< left
) && *p
&& !isspace(*p
))
1745 if (conv(&neg
, &lval
, i
, 1, data
))
1752 if (conv(&neg
, &lval
, i
, 0, data
))
1755 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1759 if(copy_to_user(s
, buf
, len
))
1766 if (!write
&& !first
&& left
) {
1767 if(put_user('\n', s
))
1774 if (get_user(c
, s
++))
1790 * proc_dointvec - read a vector of integers
1791 * @table: the sysctl table
1792 * @write: %TRUE if this is a write to the sysctl file
1793 * @filp: the file structure
1794 * @buffer: the user buffer
1795 * @lenp: the size of the user buffer
1796 * @ppos: file position
1798 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1799 * values from/to the user buffer, treated as an ASCII string.
1801 * Returns 0 on success.
1803 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1804 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1806 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1816 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1818 int write
, void *data
)
1820 int op
= *(int *)data
;
1822 int val
= *negp
? -*lvalp
: *lvalp
;
1824 case OP_SET
: *valp
= val
; break;
1825 case OP_AND
: *valp
&= val
; break;
1826 case OP_OR
: *valp
|= val
; break;
1827 case OP_MAX
: if(*valp
< val
)
1830 case OP_MIN
: if(*valp
> val
)
1838 *lvalp
= (unsigned long)-val
;
1841 *lvalp
= (unsigned long)val
;
1848 * init may raise the set.
1851 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1852 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1856 if (!capable(CAP_SYS_MODULE
)) {
1860 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1861 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1862 do_proc_dointvec_bset_conv
,&op
);
1865 struct do_proc_dointvec_minmax_conv_param
{
1870 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1872 int write
, void *data
)
1874 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1876 int val
= *negp
? -*lvalp
: *lvalp
;
1877 if ((param
->min
&& *param
->min
> val
) ||
1878 (param
->max
&& *param
->max
< val
))
1885 *lvalp
= (unsigned long)-val
;
1888 *lvalp
= (unsigned long)val
;
1895 * proc_dointvec_minmax - read a vector of integers with min/max values
1896 * @table: the sysctl table
1897 * @write: %TRUE if this is a write to the sysctl file
1898 * @filp: the file structure
1899 * @buffer: the user buffer
1900 * @lenp: the size of the user buffer
1901 * @ppos: file position
1903 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1904 * values from/to the user buffer, treated as an ASCII string.
1906 * This routine will ensure the values are within the range specified by
1907 * table->extra1 (min) and table->extra2 (max).
1909 * Returns 0 on success.
1911 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1912 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1914 struct do_proc_dointvec_minmax_conv_param param
= {
1915 .min
= (int *) table
->extra1
,
1916 .max
= (int *) table
->extra2
,
1918 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1919 do_proc_dointvec_minmax_conv
, ¶m
);
1922 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1924 void __user
*buffer
,
1925 size_t *lenp
, loff_t
*ppos
,
1926 unsigned long convmul
,
1927 unsigned long convdiv
)
1929 #define TMPBUFLEN 21
1930 unsigned long *i
, *min
, *max
, val
;
1931 int vleft
, first
=1, neg
;
1933 char buf
[TMPBUFLEN
], *p
;
1934 char __user
*s
= buffer
;
1936 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1937 (*ppos
&& !write
)) {
1942 i
= (unsigned long *) table
->data
;
1943 min
= (unsigned long *) table
->extra1
;
1944 max
= (unsigned long *) table
->extra2
;
1945 vleft
= table
->maxlen
/ sizeof(unsigned long);
1948 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1963 if (len
> TMPBUFLEN
-1)
1965 if (copy_from_user(buf
, s
, len
))
1969 if (*p
== '-' && left
> 1) {
1973 if (*p
< '0' || *p
> '9')
1975 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1977 if ((len
< left
) && *p
&& !isspace(*p
))
1986 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1993 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1997 if(copy_to_user(s
, buf
, len
))
2004 if (!write
&& !first
&& left
) {
2005 if(put_user('\n', s
))
2012 if (get_user(c
, s
++))
2028 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2029 * @table: the sysctl table
2030 * @write: %TRUE if this is a write to the sysctl file
2031 * @filp: the file structure
2032 * @buffer: the user buffer
2033 * @lenp: the size of the user buffer
2034 * @ppos: file position
2036 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2037 * values from/to the user buffer, treated as an ASCII string.
2039 * This routine will ensure the values are within the range specified by
2040 * table->extra1 (min) and table->extra2 (max).
2042 * Returns 0 on success.
2044 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2045 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2047 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2051 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2052 * @table: the sysctl table
2053 * @write: %TRUE if this is a write to the sysctl file
2054 * @filp: the file structure
2055 * @buffer: the user buffer
2056 * @lenp: the size of the user buffer
2057 * @ppos: file position
2059 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2060 * values from/to the user buffer, treated as an ASCII string. The values
2061 * are treated as milliseconds, and converted to jiffies when they are stored.
2063 * This routine will ensure the values are within the range specified by
2064 * table->extra1 (min) and table->extra2 (max).
2066 * Returns 0 on success.
2068 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2070 void __user
*buffer
,
2071 size_t *lenp
, loff_t
*ppos
)
2073 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2074 lenp
, ppos
, HZ
, 1000l);
2078 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2080 int write
, void *data
)
2083 if (*lvalp
> LONG_MAX
/ HZ
)
2085 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2091 lval
= (unsigned long)-val
;
2094 lval
= (unsigned long)val
;
2101 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2103 int write
, void *data
)
2106 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2108 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2114 lval
= (unsigned long)-val
;
2117 lval
= (unsigned long)val
;
2119 *lvalp
= jiffies_to_clock_t(lval
);
2124 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2126 int write
, void *data
)
2129 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2135 lval
= (unsigned long)-val
;
2138 lval
= (unsigned long)val
;
2140 *lvalp
= jiffies_to_msecs(lval
);
2146 * proc_dointvec_jiffies - read a vector of integers as seconds
2147 * @table: the sysctl table
2148 * @write: %TRUE if this is a write to the sysctl file
2149 * @filp: the file structure
2150 * @buffer: the user buffer
2151 * @lenp: the size of the user buffer
2152 * @ppos: file position
2154 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2155 * values from/to the user buffer, treated as an ASCII string.
2156 * The values read are assumed to be in seconds, and are converted into
2159 * Returns 0 on success.
2161 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2162 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2164 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2165 do_proc_dointvec_jiffies_conv
,NULL
);
2169 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2170 * @table: the sysctl table
2171 * @write: %TRUE if this is a write to the sysctl file
2172 * @filp: the file structure
2173 * @buffer: the user buffer
2174 * @lenp: the size of the user buffer
2175 * @ppos: pointer to the file position
2177 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2178 * values from/to the user buffer, treated as an ASCII string.
2179 * The values read are assumed to be in 1/USER_HZ seconds, and
2180 * are converted into jiffies.
2182 * Returns 0 on success.
2184 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2185 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2187 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2188 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2192 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2193 * @table: the sysctl table
2194 * @write: %TRUE if this is a write to the sysctl file
2195 * @filp: the file structure
2196 * @buffer: the user buffer
2197 * @lenp: the size of the user buffer
2198 * @ppos: file position
2199 * @ppos: the current position in the file
2201 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2202 * values from/to the user buffer, treated as an ASCII string.
2203 * The values read are assumed to be in 1/1000 seconds, and
2204 * are converted into jiffies.
2206 * Returns 0 on success.
2208 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2209 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2211 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2212 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2215 #else /* CONFIG_PROC_FS */
2217 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2218 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2223 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2229 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2230 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2235 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2236 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2241 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2242 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2247 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2248 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2253 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2254 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2259 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2260 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2265 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2266 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2271 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2273 void __user
*buffer
,
2274 size_t *lenp
, loff_t
*ppos
)
2280 #endif /* CONFIG_PROC_FS */
2284 * General sysctl support routines
2287 /* The generic string strategy routine: */
2288 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2289 void __user
*oldval
, size_t __user
*oldlenp
,
2290 void __user
*newval
, size_t newlen
, void **context
)
2292 if (!table
->data
|| !table
->maxlen
)
2295 if (oldval
&& oldlenp
) {
2297 if (get_user(bufsize
, oldlenp
))
2300 size_t len
= strlen(table
->data
), copied
;
2302 /* This shouldn't trigger for a well-formed sysctl */
2303 if (len
> table
->maxlen
)
2304 len
= table
->maxlen
;
2306 /* Copy up to a max of bufsize-1 bytes of the string */
2307 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2309 if (copy_to_user(oldval
, table
->data
, copied
) ||
2310 put_user(0, (char __user
*)(oldval
+ copied
)))
2312 if (put_user(len
, oldlenp
))
2316 if (newval
&& newlen
) {
2317 size_t len
= newlen
;
2318 if (len
> table
->maxlen
)
2319 len
= table
->maxlen
;
2320 if(copy_from_user(table
->data
, newval
, len
))
2322 if (len
== table
->maxlen
)
2324 ((char *) table
->data
)[len
] = 0;
2330 * This function makes sure that all of the integers in the vector
2331 * are between the minimum and maximum values given in the arrays
2332 * table->extra1 and table->extra2, respectively.
2334 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2335 void __user
*oldval
, size_t __user
*oldlenp
,
2336 void __user
*newval
, size_t newlen
, void **context
)
2339 if (newval
&& newlen
) {
2340 int __user
*vec
= (int __user
*) newval
;
2341 int *min
= (int *) table
->extra1
;
2342 int *max
= (int *) table
->extra2
;
2346 if (newlen
% sizeof(int) != 0)
2349 if (!table
->extra1
&& !table
->extra2
)
2352 if (newlen
> table
->maxlen
)
2353 newlen
= table
->maxlen
;
2354 length
= newlen
/ sizeof(int);
2356 for (i
= 0; i
< length
; i
++) {
2358 if (get_user(value
, vec
+ i
))
2360 if (min
&& value
< min
[i
])
2362 if (max
&& value
> max
[i
])
2369 /* Strategy function to convert jiffies to seconds */
2370 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2371 void __user
*oldval
, size_t __user
*oldlenp
,
2372 void __user
*newval
, size_t newlen
, void **context
)
2377 if (get_user(olen
, oldlenp
))
2379 if (olen
!=sizeof(int))
2382 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2383 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2386 if (newval
&& newlen
) {
2388 if (newlen
!= sizeof(int))
2390 if (get_user(new, (int __user
*)newval
))
2392 *(int *)(table
->data
) = new*HZ
;
2397 /* Strategy function to convert jiffies to seconds */
2398 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2399 void __user
*oldval
, size_t __user
*oldlenp
,
2400 void __user
*newval
, size_t newlen
, void **context
)
2405 if (get_user(olen
, oldlenp
))
2407 if (olen
!=sizeof(int))
2410 if (put_user(jiffies_to_msecs(*(int *)(table
->data
)), (int __user
*)oldval
) ||
2411 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2414 if (newval
&& newlen
) {
2416 if (newlen
!= sizeof(int))
2418 if (get_user(new, (int __user
*)newval
))
2420 *(int *)(table
->data
) = msecs_to_jiffies(new);
2425 #else /* CONFIG_SYSCTL */
2428 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2433 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2434 void __user
*oldval
, size_t __user
*oldlenp
,
2435 void __user
*newval
, size_t newlen
, void **context
)
2440 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2441 void __user
*oldval
, size_t __user
*oldlenp
,
2442 void __user
*newval
, size_t newlen
, void **context
)
2447 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2448 void __user
*oldval
, size_t __user
*oldlenp
,
2449 void __user
*newval
, size_t newlen
, void **context
)
2454 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2455 void __user
*oldval
, size_t __user
*oldlenp
,
2456 void __user
*newval
, size_t newlen
, void **context
)
2461 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2462 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2467 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2468 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2473 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2474 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2479 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2480 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2485 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2486 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2491 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2492 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2497 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2498 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2503 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2504 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2509 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2511 void __user
*buffer
,
2512 size_t *lenp
, loff_t
*ppos
)
2517 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2523 void unregister_sysctl_table(struct ctl_table_header
* table
)
2527 #endif /* CONFIG_SYSCTL */
2530 * No sense putting this after each symbol definition, twice,
2531 * exception granted :-)
2533 EXPORT_SYMBOL(proc_dointvec
);
2534 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2535 EXPORT_SYMBOL(proc_dointvec_minmax
);
2536 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2537 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2538 EXPORT_SYMBOL(proc_dostring
);
2539 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2540 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2541 EXPORT_SYMBOL(register_sysctl_table
);
2542 EXPORT_SYMBOL(sysctl_intvec
);
2543 EXPORT_SYMBOL(sysctl_jiffies
);
2544 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2545 EXPORT_SYMBOL(sysctl_string
);
2546 EXPORT_SYMBOL(unregister_sysctl_table
);