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 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
137 ctl_table
*, void **);
138 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
139 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
141 static ctl_table root_table
[];
142 static struct ctl_table_header root_table_header
=
143 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
145 static ctl_table kern_table
[];
146 static ctl_table vm_table
[];
147 static ctl_table fs_table
[];
148 static ctl_table debug_table
[];
149 static ctl_table dev_table
[];
150 extern ctl_table random_table
[];
151 #ifdef CONFIG_UNIX98_PTYS
152 extern ctl_table pty_table
[];
154 #ifdef CONFIG_INOTIFY_USER
155 extern ctl_table inotify_table
[];
158 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
159 int sysctl_legacy_va_layout
;
162 /* /proc declarations: */
164 #ifdef CONFIG_PROC_FS
166 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
167 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
168 static int proc_opensys(struct inode
*, struct file
*);
170 struct file_operations proc_sys_file_operations
= {
171 .open
= proc_opensys
,
172 .read
= proc_readsys
,
173 .write
= proc_writesys
,
176 extern struct proc_dir_entry
*proc_sys_root
;
178 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*, void *);
179 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
182 /* The default sysctl tables: */
184 static ctl_table root_table
[] = {
186 .ctl_name
= CTL_KERN
,
187 .procname
= "kernel",
212 .ctl_name
= CTL_DEBUG
,
215 .child
= debug_table
,
227 static ctl_table kern_table
[] = {
229 .ctl_name
= KERN_OSTYPE
,
230 .procname
= "ostype",
231 .data
= system_utsname
.sysname
,
232 .maxlen
= sizeof(system_utsname
.sysname
),
234 .proc_handler
= &proc_doutsstring
,
235 .strategy
= &sysctl_string
,
238 .ctl_name
= KERN_OSRELEASE
,
239 .procname
= "osrelease",
240 .data
= system_utsname
.release
,
241 .maxlen
= sizeof(system_utsname
.release
),
243 .proc_handler
= &proc_doutsstring
,
244 .strategy
= &sysctl_string
,
247 .ctl_name
= KERN_VERSION
,
248 .procname
= "version",
249 .data
= system_utsname
.version
,
250 .maxlen
= sizeof(system_utsname
.version
),
252 .proc_handler
= &proc_doutsstring
,
253 .strategy
= &sysctl_string
,
256 .ctl_name
= KERN_NODENAME
,
257 .procname
= "hostname",
258 .data
= system_utsname
.nodename
,
259 .maxlen
= sizeof(system_utsname
.nodename
),
261 .proc_handler
= &proc_doutsstring
,
262 .strategy
= &sysctl_string
,
265 .ctl_name
= KERN_DOMAINNAME
,
266 .procname
= "domainname",
267 .data
= system_utsname
.domainname
,
268 .maxlen
= sizeof(system_utsname
.domainname
),
270 .proc_handler
= &proc_doutsstring
,
271 .strategy
= &sysctl_string
,
274 .ctl_name
= KERN_PANIC
,
276 .data
= &panic_timeout
,
277 .maxlen
= sizeof(int),
279 .proc_handler
= &proc_dointvec
,
282 .ctl_name
= KERN_CORE_USES_PID
,
283 .procname
= "core_uses_pid",
284 .data
= &core_uses_pid
,
285 .maxlen
= sizeof(int),
287 .proc_handler
= &proc_dointvec
,
290 .ctl_name
= KERN_CORE_PATTERN
,
291 .procname
= "core_pattern",
292 .data
= core_pattern
,
295 .proc_handler
= &proc_dostring
,
296 .strategy
= &sysctl_string
,
299 .ctl_name
= KERN_TAINTED
,
300 .procname
= "tainted",
302 .maxlen
= sizeof(int),
304 .proc_handler
= &proc_dointvec
,
307 .ctl_name
= KERN_CAP_BSET
,
308 .procname
= "cap-bound",
310 .maxlen
= sizeof(kernel_cap_t
),
312 .proc_handler
= &proc_dointvec_bset
,
314 #ifdef CONFIG_BLK_DEV_INITRD
316 .ctl_name
= KERN_REALROOTDEV
,
317 .procname
= "real-root-dev",
318 .data
= &real_root_dev
,
319 .maxlen
= sizeof(int),
321 .proc_handler
= &proc_dointvec
,
326 .ctl_name
= KERN_SPARC_REBOOT
,
327 .procname
= "reboot-cmd",
328 .data
= reboot_command
,
331 .proc_handler
= &proc_dostring
,
332 .strategy
= &sysctl_string
,
335 .ctl_name
= KERN_SPARC_STOP_A
,
336 .procname
= "stop-a",
337 .data
= &stop_a_enabled
,
338 .maxlen
= sizeof (int),
340 .proc_handler
= &proc_dointvec
,
343 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
344 .procname
= "scons-poweroff",
345 .data
= &scons_pwroff
,
346 .maxlen
= sizeof (int),
348 .proc_handler
= &proc_dointvec
,
353 .ctl_name
= KERN_HPPA_PWRSW
,
354 .procname
= "soft-power",
355 .data
= &pwrsw_enabled
,
356 .maxlen
= sizeof (int),
358 .proc_handler
= &proc_dointvec
,
361 .ctl_name
= KERN_HPPA_UNALIGNED
,
362 .procname
= "unaligned-trap",
363 .data
= &unaligned_enabled
,
364 .maxlen
= sizeof (int),
366 .proc_handler
= &proc_dointvec
,
370 .ctl_name
= KERN_CTLALTDEL
,
371 .procname
= "ctrl-alt-del",
373 .maxlen
= sizeof(int),
375 .proc_handler
= &proc_dointvec
,
378 .ctl_name
= KERN_PRINTK
,
379 .procname
= "printk",
380 .data
= &console_loglevel
,
381 .maxlen
= 4*sizeof(int),
383 .proc_handler
= &proc_dointvec
,
387 .ctl_name
= KERN_MODPROBE
,
388 .procname
= "modprobe",
389 .data
= &modprobe_path
,
390 .maxlen
= KMOD_PATH_LEN
,
392 .proc_handler
= &proc_dostring
,
393 .strategy
= &sysctl_string
,
396 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
398 .ctl_name
= KERN_HOTPLUG
,
399 .procname
= "hotplug",
400 .data
= &uevent_helper
,
401 .maxlen
= UEVENT_HELPER_PATH_LEN
,
403 .proc_handler
= &proc_dostring
,
404 .strategy
= &sysctl_string
,
407 #ifdef CONFIG_CHR_DEV_SG
409 .ctl_name
= KERN_SG_BIG_BUFF
,
410 .procname
= "sg-big-buff",
411 .data
= &sg_big_buff
,
412 .maxlen
= sizeof (int),
414 .proc_handler
= &proc_dointvec
,
417 #ifdef CONFIG_BSD_PROCESS_ACCT
419 .ctl_name
= KERN_ACCT
,
422 .maxlen
= 3*sizeof(int),
424 .proc_handler
= &proc_dointvec
,
427 #ifdef CONFIG_SYSVIPC
429 .ctl_name
= KERN_SHMMAX
,
430 .procname
= "shmmax",
432 .maxlen
= sizeof (size_t),
434 .proc_handler
= &proc_doulongvec_minmax
,
437 .ctl_name
= KERN_SHMALL
,
438 .procname
= "shmall",
440 .maxlen
= sizeof (size_t),
442 .proc_handler
= &proc_doulongvec_minmax
,
445 .ctl_name
= KERN_SHMMNI
,
446 .procname
= "shmmni",
448 .maxlen
= sizeof (int),
450 .proc_handler
= &proc_dointvec
,
453 .ctl_name
= KERN_MSGMAX
,
454 .procname
= "msgmax",
456 .maxlen
= sizeof (int),
458 .proc_handler
= &proc_dointvec
,
461 .ctl_name
= KERN_MSGMNI
,
462 .procname
= "msgmni",
464 .maxlen
= sizeof (int),
466 .proc_handler
= &proc_dointvec
,
469 .ctl_name
= KERN_MSGMNB
,
470 .procname
= "msgmnb",
472 .maxlen
= sizeof (int),
474 .proc_handler
= &proc_dointvec
,
477 .ctl_name
= KERN_SEM
,
480 .maxlen
= 4*sizeof (int),
482 .proc_handler
= &proc_dointvec
,
485 #ifdef CONFIG_MAGIC_SYSRQ
487 .ctl_name
= KERN_SYSRQ
,
489 .data
= &sysrq_enabled
,
490 .maxlen
= sizeof (int),
492 .proc_handler
= &proc_dointvec
,
496 .ctl_name
= KERN_CADPID
,
497 .procname
= "cad_pid",
499 .maxlen
= sizeof (int),
501 .proc_handler
= &proc_dointvec
,
504 .ctl_name
= KERN_MAX_THREADS
,
505 .procname
= "threads-max",
506 .data
= &max_threads
,
507 .maxlen
= sizeof(int),
509 .proc_handler
= &proc_dointvec
,
512 .ctl_name
= KERN_RANDOM
,
513 .procname
= "random",
515 .child
= random_table
,
517 #ifdef CONFIG_UNIX98_PTYS
519 .ctl_name
= KERN_PTY
,
526 .ctl_name
= KERN_OVERFLOWUID
,
527 .procname
= "overflowuid",
528 .data
= &overflowuid
,
529 .maxlen
= sizeof(int),
531 .proc_handler
= &proc_dointvec_minmax
,
532 .strategy
= &sysctl_intvec
,
533 .extra1
= &minolduid
,
534 .extra2
= &maxolduid
,
537 .ctl_name
= KERN_OVERFLOWGID
,
538 .procname
= "overflowgid",
539 .data
= &overflowgid
,
540 .maxlen
= sizeof(int),
542 .proc_handler
= &proc_dointvec_minmax
,
543 .strategy
= &sysctl_intvec
,
544 .extra1
= &minolduid
,
545 .extra2
= &maxolduid
,
548 #ifdef CONFIG_MATHEMU
550 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
551 .procname
= "ieee_emulation_warnings",
552 .data
= &sysctl_ieee_emulation_warnings
,
553 .maxlen
= sizeof(int),
555 .proc_handler
= &proc_dointvec
,
558 #ifdef CONFIG_NO_IDLE_HZ
560 .ctl_name
= KERN_HZ_TIMER
,
561 .procname
= "hz_timer",
562 .data
= &sysctl_hz_timer
,
563 .maxlen
= sizeof(int),
565 .proc_handler
= &proc_dointvec
,
569 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
570 .procname
= "userprocess_debug",
571 .data
= &sysctl_userprocess_debug
,
572 .maxlen
= sizeof(int),
574 .proc_handler
= &proc_dointvec
,
578 .ctl_name
= KERN_PIDMAX
,
579 .procname
= "pid_max",
581 .maxlen
= sizeof (int),
583 .proc_handler
= &proc_dointvec_minmax
,
584 .strategy
= sysctl_intvec
,
585 .extra1
= &pid_max_min
,
586 .extra2
= &pid_max_max
,
589 .ctl_name
= KERN_PANIC_ON_OOPS
,
590 .procname
= "panic_on_oops",
591 .data
= &panic_on_oops
,
592 .maxlen
= sizeof(int),
594 .proc_handler
= &proc_dointvec
,
597 .ctl_name
= KERN_PRINTK_RATELIMIT
,
598 .procname
= "printk_ratelimit",
599 .data
= &printk_ratelimit_jiffies
,
600 .maxlen
= sizeof(int),
602 .proc_handler
= &proc_dointvec_jiffies
,
603 .strategy
= &sysctl_jiffies
,
606 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
607 .procname
= "printk_ratelimit_burst",
608 .data
= &printk_ratelimit_burst
,
609 .maxlen
= sizeof(int),
611 .proc_handler
= &proc_dointvec
,
614 .ctl_name
= KERN_NGROUPS_MAX
,
615 .procname
= "ngroups_max",
616 .data
= &ngroups_max
,
617 .maxlen
= sizeof (int),
619 .proc_handler
= &proc_dointvec
,
621 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
623 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
624 .procname
= "unknown_nmi_panic",
625 .data
= &unknown_nmi_panic
,
626 .maxlen
= sizeof (int),
628 .proc_handler
= &proc_unknown_nmi_panic
,
631 #if defined(CONFIG_X86)
633 .ctl_name
= KERN_BOOTLOADER_TYPE
,
634 .procname
= "bootloader_type",
635 .data
= &bootloader_type
,
636 .maxlen
= sizeof (int),
638 .proc_handler
= &proc_dointvec
,
641 #if defined(CONFIG_MMU)
643 .ctl_name
= KERN_RANDOMIZE
,
644 .procname
= "randomize_va_space",
645 .data
= &randomize_va_space
,
646 .maxlen
= sizeof(int),
648 .proc_handler
= &proc_dointvec
,
651 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
653 .ctl_name
= KERN_SPIN_RETRY
,
654 .procname
= "spin_retry",
656 .maxlen
= sizeof (int),
658 .proc_handler
= &proc_dointvec
,
661 #ifdef CONFIG_ACPI_SLEEP
663 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
664 .procname
= "acpi_video_flags",
665 .data
= &acpi_video_flags
,
666 .maxlen
= sizeof (unsigned long),
668 .proc_handler
= &proc_doulongvec_minmax
,
673 .ctl_name
= KERN_IA64_UNALIGNED
,
674 .procname
= "ignore-unaligned-usertrap",
675 .data
= &no_unaligned_warning
,
676 .maxlen
= sizeof (int),
678 .proc_handler
= &proc_dointvec
,
683 .ctl_name
= KERN_COMPAT_LOG
,
684 .procname
= "compat-log",
686 .maxlen
= sizeof (int),
688 .proc_handler
= &proc_dointvec
,
694 /* Constants for minimum and maximum testing in vm_table.
695 We use these as one-element integer vectors. */
697 static int one_hundred
= 100;
700 static ctl_table vm_table
[] = {
702 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
703 .procname
= "overcommit_memory",
704 .data
= &sysctl_overcommit_memory
,
705 .maxlen
= sizeof(sysctl_overcommit_memory
),
707 .proc_handler
= &proc_dointvec
,
710 .ctl_name
= VM_PANIC_ON_OOM
,
711 .procname
= "panic_on_oom",
712 .data
= &sysctl_panic_on_oom
,
713 .maxlen
= sizeof(sysctl_panic_on_oom
),
715 .proc_handler
= &proc_dointvec
,
718 .ctl_name
= VM_OVERCOMMIT_RATIO
,
719 .procname
= "overcommit_ratio",
720 .data
= &sysctl_overcommit_ratio
,
721 .maxlen
= sizeof(sysctl_overcommit_ratio
),
723 .proc_handler
= &proc_dointvec
,
726 .ctl_name
= VM_PAGE_CLUSTER
,
727 .procname
= "page-cluster",
728 .data
= &page_cluster
,
729 .maxlen
= sizeof(int),
731 .proc_handler
= &proc_dointvec
,
734 .ctl_name
= VM_DIRTY_BACKGROUND
,
735 .procname
= "dirty_background_ratio",
736 .data
= &dirty_background_ratio
,
737 .maxlen
= sizeof(dirty_background_ratio
),
739 .proc_handler
= &proc_dointvec_minmax
,
740 .strategy
= &sysctl_intvec
,
742 .extra2
= &one_hundred
,
745 .ctl_name
= VM_DIRTY_RATIO
,
746 .procname
= "dirty_ratio",
747 .data
= &vm_dirty_ratio
,
748 .maxlen
= sizeof(vm_dirty_ratio
),
750 .proc_handler
= &proc_dointvec_minmax
,
751 .strategy
= &sysctl_intvec
,
753 .extra2
= &one_hundred
,
756 .ctl_name
= VM_DIRTY_WB_CS
,
757 .procname
= "dirty_writeback_centisecs",
758 .data
= &dirty_writeback_interval
,
759 .maxlen
= sizeof(dirty_writeback_interval
),
761 .proc_handler
= &dirty_writeback_centisecs_handler
,
764 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
765 .procname
= "dirty_expire_centisecs",
766 .data
= &dirty_expire_interval
,
767 .maxlen
= sizeof(dirty_expire_interval
),
769 .proc_handler
= &proc_dointvec_userhz_jiffies
,
772 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
773 .procname
= "nr_pdflush_threads",
774 .data
= &nr_pdflush_threads
,
775 .maxlen
= sizeof nr_pdflush_threads
,
776 .mode
= 0444 /* read-only*/,
777 .proc_handler
= &proc_dointvec
,
780 .ctl_name
= VM_SWAPPINESS
,
781 .procname
= "swappiness",
782 .data
= &vm_swappiness
,
783 .maxlen
= sizeof(vm_swappiness
),
785 .proc_handler
= &proc_dointvec_minmax
,
786 .strategy
= &sysctl_intvec
,
788 .extra2
= &one_hundred
,
790 #ifdef CONFIG_HUGETLB_PAGE
792 .ctl_name
= VM_HUGETLB_PAGES
,
793 .procname
= "nr_hugepages",
794 .data
= &max_huge_pages
,
795 .maxlen
= sizeof(unsigned long),
797 .proc_handler
= &hugetlb_sysctl_handler
,
798 .extra1
= (void *)&hugetlb_zero
,
799 .extra2
= (void *)&hugetlb_infinity
,
802 .ctl_name
= VM_HUGETLB_GROUP
,
803 .procname
= "hugetlb_shm_group",
804 .data
= &sysctl_hugetlb_shm_group
,
805 .maxlen
= sizeof(gid_t
),
807 .proc_handler
= &proc_dointvec
,
811 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
812 .procname
= "lowmem_reserve_ratio",
813 .data
= &sysctl_lowmem_reserve_ratio
,
814 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
816 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
817 .strategy
= &sysctl_intvec
,
820 .ctl_name
= VM_DROP_PAGECACHE
,
821 .procname
= "drop_caches",
822 .data
= &sysctl_drop_caches
,
823 .maxlen
= sizeof(int),
825 .proc_handler
= drop_caches_sysctl_handler
,
826 .strategy
= &sysctl_intvec
,
829 .ctl_name
= VM_MIN_FREE_KBYTES
,
830 .procname
= "min_free_kbytes",
831 .data
= &min_free_kbytes
,
832 .maxlen
= sizeof(min_free_kbytes
),
834 .proc_handler
= &min_free_kbytes_sysctl_handler
,
835 .strategy
= &sysctl_intvec
,
839 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
840 .procname
= "percpu_pagelist_fraction",
841 .data
= &percpu_pagelist_fraction
,
842 .maxlen
= sizeof(percpu_pagelist_fraction
),
844 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
845 .strategy
= &sysctl_intvec
,
846 .extra1
= &min_percpu_pagelist_fract
,
850 .ctl_name
= VM_MAX_MAP_COUNT
,
851 .procname
= "max_map_count",
852 .data
= &sysctl_max_map_count
,
853 .maxlen
= sizeof(sysctl_max_map_count
),
855 .proc_handler
= &proc_dointvec
859 .ctl_name
= VM_LAPTOP_MODE
,
860 .procname
= "laptop_mode",
861 .data
= &laptop_mode
,
862 .maxlen
= sizeof(laptop_mode
),
864 .proc_handler
= &proc_dointvec_jiffies
,
865 .strategy
= &sysctl_jiffies
,
868 .ctl_name
= VM_BLOCK_DUMP
,
869 .procname
= "block_dump",
871 .maxlen
= sizeof(block_dump
),
873 .proc_handler
= &proc_dointvec
,
874 .strategy
= &sysctl_intvec
,
878 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
879 .procname
= "vfs_cache_pressure",
880 .data
= &sysctl_vfs_cache_pressure
,
881 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
883 .proc_handler
= &proc_dointvec
,
884 .strategy
= &sysctl_intvec
,
887 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
889 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
890 .procname
= "legacy_va_layout",
891 .data
= &sysctl_legacy_va_layout
,
892 .maxlen
= sizeof(sysctl_legacy_va_layout
),
894 .proc_handler
= &proc_dointvec
,
895 .strategy
= &sysctl_intvec
,
901 .ctl_name
= VM_SWAP_TOKEN_TIMEOUT
,
902 .procname
= "swap_token_timeout",
903 .data
= &swap_token_default_timeout
,
904 .maxlen
= sizeof(swap_token_default_timeout
),
906 .proc_handler
= &proc_dointvec_jiffies
,
907 .strategy
= &sysctl_jiffies
,
912 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
913 .procname
= "zone_reclaim_mode",
914 .data
= &zone_reclaim_mode
,
915 .maxlen
= sizeof(zone_reclaim_mode
),
917 .proc_handler
= &proc_dointvec
,
918 .strategy
= &sysctl_intvec
,
922 .ctl_name
= VM_ZONE_RECLAIM_INTERVAL
,
923 .procname
= "zone_reclaim_interval",
924 .data
= &zone_reclaim_interval
,
925 .maxlen
= sizeof(zone_reclaim_interval
),
927 .proc_handler
= &proc_dointvec_jiffies
,
928 .strategy
= &sysctl_jiffies
,
934 static ctl_table fs_table
[] = {
936 .ctl_name
= FS_NRINODE
,
937 .procname
= "inode-nr",
938 .data
= &inodes_stat
,
939 .maxlen
= 2*sizeof(int),
941 .proc_handler
= &proc_dointvec
,
944 .ctl_name
= FS_STATINODE
,
945 .procname
= "inode-state",
946 .data
= &inodes_stat
,
947 .maxlen
= 7*sizeof(int),
949 .proc_handler
= &proc_dointvec
,
952 .ctl_name
= FS_NRFILE
,
953 .procname
= "file-nr",
955 .maxlen
= 3*sizeof(int),
957 .proc_handler
= &proc_nr_files
,
960 .ctl_name
= FS_MAXFILE
,
961 .procname
= "file-max",
962 .data
= &files_stat
.max_files
,
963 .maxlen
= sizeof(int),
965 .proc_handler
= &proc_dointvec
,
968 .ctl_name
= FS_DENTRY
,
969 .procname
= "dentry-state",
970 .data
= &dentry_stat
,
971 .maxlen
= 6*sizeof(int),
973 .proc_handler
= &proc_dointvec
,
976 .ctl_name
= FS_OVERFLOWUID
,
977 .procname
= "overflowuid",
978 .data
= &fs_overflowuid
,
979 .maxlen
= sizeof(int),
981 .proc_handler
= &proc_dointvec_minmax
,
982 .strategy
= &sysctl_intvec
,
983 .extra1
= &minolduid
,
984 .extra2
= &maxolduid
,
987 .ctl_name
= FS_OVERFLOWGID
,
988 .procname
= "overflowgid",
989 .data
= &fs_overflowgid
,
990 .maxlen
= sizeof(int),
992 .proc_handler
= &proc_dointvec_minmax
,
993 .strategy
= &sysctl_intvec
,
994 .extra1
= &minolduid
,
995 .extra2
= &maxolduid
,
998 .ctl_name
= FS_LEASES
,
999 .procname
= "leases-enable",
1000 .data
= &leases_enable
,
1001 .maxlen
= sizeof(int),
1003 .proc_handler
= &proc_dointvec
,
1005 #ifdef CONFIG_DNOTIFY
1007 .ctl_name
= FS_DIR_NOTIFY
,
1008 .procname
= "dir-notify-enable",
1009 .data
= &dir_notify_enable
,
1010 .maxlen
= sizeof(int),
1012 .proc_handler
= &proc_dointvec
,
1017 .ctl_name
= FS_LEASE_TIME
,
1018 .procname
= "lease-break-time",
1019 .data
= &lease_break_time
,
1020 .maxlen
= sizeof(int),
1022 .proc_handler
= &proc_dointvec
,
1025 .ctl_name
= FS_AIO_NR
,
1026 .procname
= "aio-nr",
1028 .maxlen
= sizeof(aio_nr
),
1030 .proc_handler
= &proc_doulongvec_minmax
,
1033 .ctl_name
= FS_AIO_MAX_NR
,
1034 .procname
= "aio-max-nr",
1035 .data
= &aio_max_nr
,
1036 .maxlen
= sizeof(aio_max_nr
),
1038 .proc_handler
= &proc_doulongvec_minmax
,
1040 #ifdef CONFIG_INOTIFY_USER
1042 .ctl_name
= FS_INOTIFY
,
1043 .procname
= "inotify",
1045 .child
= inotify_table
,
1050 .ctl_name
= KERN_SETUID_DUMPABLE
,
1051 .procname
= "suid_dumpable",
1052 .data
= &suid_dumpable
,
1053 .maxlen
= sizeof(int),
1055 .proc_handler
= &proc_dointvec
,
1060 static ctl_table debug_table
[] = {
1064 static ctl_table dev_table
[] = {
1068 extern void init_irq_proc (void);
1070 static DEFINE_SPINLOCK(sysctl_lock
);
1072 /* called under sysctl_lock */
1073 static int use_table(struct ctl_table_header
*p
)
1075 if (unlikely(p
->unregistering
))
1081 /* called under sysctl_lock */
1082 static void unuse_table(struct ctl_table_header
*p
)
1085 if (unlikely(p
->unregistering
))
1086 complete(p
->unregistering
);
1089 /* called under sysctl_lock, will reacquire if has to wait */
1090 static void start_unregistering(struct ctl_table_header
*p
)
1093 * if p->used is 0, nobody will ever touch that entry again;
1094 * we'll eliminate all paths to it before dropping sysctl_lock
1096 if (unlikely(p
->used
)) {
1097 struct completion wait
;
1098 init_completion(&wait
);
1099 p
->unregistering
= &wait
;
1100 spin_unlock(&sysctl_lock
);
1101 wait_for_completion(&wait
);
1102 spin_lock(&sysctl_lock
);
1105 * do not remove from the list until nobody holds it; walking the
1106 * list in do_sysctl() relies on that.
1108 list_del_init(&p
->ctl_entry
);
1111 void __init
sysctl_init(void)
1113 #ifdef CONFIG_PROC_FS
1114 register_proc_table(root_table
, proc_sys_root
, &root_table_header
);
1119 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1120 void __user
*newval
, size_t newlen
)
1122 struct list_head
*tmp
;
1123 int error
= -ENOTDIR
;
1125 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1129 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1132 spin_lock(&sysctl_lock
);
1133 tmp
= &root_table_header
.ctl_entry
;
1135 struct ctl_table_header
*head
=
1136 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1137 void *context
= NULL
;
1139 if (!use_table(head
))
1142 spin_unlock(&sysctl_lock
);
1144 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1145 newval
, newlen
, head
->ctl_table
,
1149 spin_lock(&sysctl_lock
);
1151 if (error
!= -ENOTDIR
)
1153 } while ((tmp
= tmp
->next
) != &root_table_header
.ctl_entry
);
1154 spin_unlock(&sysctl_lock
);
1158 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1160 struct __sysctl_args tmp
;
1163 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1167 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1168 tmp
.newval
, tmp
.newlen
);
1174 * ctl_perm does NOT grant the superuser all rights automatically, because
1175 * some sysctl variables are readonly even to root.
1178 static int test_perm(int mode
, int op
)
1182 else if (in_egroup_p(0))
1184 if ((mode
& op
& 0007) == op
)
1189 static inline int ctl_perm(ctl_table
*table
, int op
)
1192 error
= security_sysctl(table
, op
);
1195 return test_perm(table
->mode
, op
);
1198 static int parse_table(int __user
*name
, int nlen
,
1199 void __user
*oldval
, size_t __user
*oldlenp
,
1200 void __user
*newval
, size_t newlen
,
1201 ctl_table
*table
, void **context
)
1207 if (get_user(n
, name
))
1209 for ( ; table
->ctl_name
; table
++) {
1210 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1213 if (ctl_perm(table
, 001))
1215 if (table
->strategy
) {
1216 error
= table
->strategy(
1219 newval
, newlen
, context
);
1225 table
= table
->child
;
1228 error
= do_sysctl_strategy(table
, name
, nlen
,
1230 newval
, newlen
, context
);
1237 /* Perform the actual read/write of a sysctl table entry. */
1238 int do_sysctl_strategy (ctl_table
*table
,
1239 int __user
*name
, int nlen
,
1240 void __user
*oldval
, size_t __user
*oldlenp
,
1241 void __user
*newval
, size_t newlen
, void **context
)
1250 if (ctl_perm(table
, op
))
1253 if (table
->strategy
) {
1254 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1255 newval
, newlen
, context
);
1262 /* If there is no strategy routine, or if the strategy returns
1263 * zero, proceed with automatic r/w */
1264 if (table
->data
&& table
->maxlen
) {
1265 if (oldval
&& oldlenp
) {
1266 if (get_user(len
, oldlenp
))
1269 if (len
> table
->maxlen
)
1270 len
= table
->maxlen
;
1271 if(copy_to_user(oldval
, table
->data
, len
))
1273 if(put_user(len
, oldlenp
))
1277 if (newval
&& newlen
) {
1279 if (len
> table
->maxlen
)
1280 len
= table
->maxlen
;
1281 if(copy_from_user(table
->data
, newval
, len
))
1289 * register_sysctl_table - register a sysctl hierarchy
1290 * @table: the top-level table structure
1291 * @insert_at_head: whether the entry should be inserted in front or at the end
1293 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1294 * array. An entry with a ctl_name of 0 terminates the table.
1296 * The members of the &ctl_table structure are used as follows:
1298 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1299 * must be unique within that level of sysctl
1301 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1302 * enter a sysctl file
1304 * data - a pointer to data for use by proc_handler
1306 * maxlen - the maximum size in bytes of the data
1308 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1310 * child - a pointer to the child sysctl table if this entry is a directory, or
1313 * proc_handler - the text handler routine (described below)
1315 * strategy - the strategy routine (described below)
1317 * de - for internal use by the sysctl routines
1319 * extra1, extra2 - extra pointers usable by the proc handler routines
1321 * Leaf nodes in the sysctl tree will be represented by a single file
1322 * under /proc; non-leaf nodes will be represented by directories.
1324 * sysctl(2) can automatically manage read and write requests through
1325 * the sysctl table. The data and maxlen fields of the ctl_table
1326 * struct enable minimal validation of the values being written to be
1327 * performed, and the mode field allows minimal authentication.
1329 * More sophisticated management can be enabled by the provision of a
1330 * strategy routine with the table entry. This will be called before
1331 * any automatic read or write of the data is performed.
1333 * The strategy routine may return
1335 * < 0 - Error occurred (error is passed to user process)
1337 * 0 - OK - proceed with automatic read or write.
1339 * > 0 - OK - read or write has been done by the strategy routine, so
1340 * return immediately.
1342 * There must be a proc_handler routine for any terminal nodes
1343 * mirrored under /proc/sys (non-terminals are handled by a built-in
1344 * directory handler). Several default handlers are available to
1345 * cover common cases -
1347 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1348 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1349 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1351 * It is the handler's job to read the input buffer from user memory
1352 * and process it. The handler should return 0 on success.
1354 * This routine returns %NULL on a failure to register, and a pointer
1355 * to the table header on success.
1357 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1360 struct ctl_table_header
*tmp
;
1361 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1364 tmp
->ctl_table
= table
;
1365 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1367 tmp
->unregistering
= NULL
;
1368 spin_lock(&sysctl_lock
);
1370 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1372 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1373 spin_unlock(&sysctl_lock
);
1374 #ifdef CONFIG_PROC_FS
1375 register_proc_table(table
, proc_sys_root
, tmp
);
1381 * unregister_sysctl_table - unregister a sysctl table hierarchy
1382 * @header: the header returned from register_sysctl_table
1384 * Unregisters the sysctl table and all children. proc entries may not
1385 * actually be removed until they are no longer used by anyone.
1387 void unregister_sysctl_table(struct ctl_table_header
* header
)
1390 spin_lock(&sysctl_lock
);
1391 start_unregistering(header
);
1392 #ifdef CONFIG_PROC_FS
1393 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1395 spin_unlock(&sysctl_lock
);
1403 #ifdef CONFIG_PROC_FS
1405 /* Scan the sysctl entries in table and add them all into /proc */
1406 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
, void *set
)
1408 struct proc_dir_entry
*de
;
1412 for (; table
->ctl_name
; table
++) {
1413 /* Can't do anything without a proc name. */
1414 if (!table
->procname
)
1416 /* Maybe we can't do anything with it... */
1417 if (!table
->proc_handler
&& !table
->child
) {
1418 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1423 len
= strlen(table
->procname
);
1427 if (table
->proc_handler
)
1431 for (de
= root
->subdir
; de
; de
= de
->next
) {
1432 if (proc_match(len
, table
->procname
, de
))
1435 /* If the subdir exists already, de is non-NULL */
1439 de
= create_proc_entry(table
->procname
, mode
, root
);
1443 de
->data
= (void *) table
;
1444 if (table
->proc_handler
)
1445 de
->proc_fops
= &proc_sys_file_operations
;
1448 if (de
->mode
& S_IFDIR
)
1449 register_proc_table(table
->child
, de
, set
);
1454 * Unregister a /proc sysctl table and any subdirectories.
1456 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1458 struct proc_dir_entry
*de
;
1459 for (; table
->ctl_name
; table
++) {
1460 if (!(de
= table
->de
))
1462 if (de
->mode
& S_IFDIR
) {
1463 if (!table
->child
) {
1464 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1467 unregister_proc_table(table
->child
, de
);
1469 /* Don't unregister directories which still have entries.. */
1475 * In any case, mark the entry as goner; we'll keep it
1476 * around if it's busy, but we'll know to do nothing with
1477 * its fields. We are under sysctl_lock here.
1481 /* Don't unregister proc entries that are still being used.. */
1482 if (atomic_read(&de
->count
))
1486 remove_proc_entry(table
->procname
, root
);
1490 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1491 size_t count
, loff_t
*ppos
)
1494 struct proc_dir_entry
*de
= PDE(file
->f_dentry
->d_inode
);
1495 struct ctl_table
*table
;
1497 ssize_t error
= -ENOTDIR
;
1499 spin_lock(&sysctl_lock
);
1500 if (de
&& de
->data
&& use_table(de
->set
)) {
1502 * at that point we know that sysctl was not unregistered
1503 * and won't be until we finish
1505 spin_unlock(&sysctl_lock
);
1506 table
= (struct ctl_table
*) de
->data
;
1507 if (!table
|| !table
->proc_handler
)
1510 op
= (write
? 002 : 004);
1511 if (ctl_perm(table
, op
))
1514 /* careful: calling conventions are nasty here */
1516 error
= (*table
->proc_handler
)(table
, write
, file
,
1521 spin_lock(&sysctl_lock
);
1522 unuse_table(de
->set
);
1524 spin_unlock(&sysctl_lock
);
1528 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1530 if (file
->f_mode
& FMODE_WRITE
) {
1532 * sysctl entries that are not writable,
1533 * are _NOT_ writable, capabilities or not.
1535 if (!(inode
->i_mode
& S_IWUSR
))
1542 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1543 size_t count
, loff_t
*ppos
)
1545 return do_rw_proc(0, file
, buf
, count
, ppos
);
1548 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1549 size_t count
, loff_t
*ppos
)
1551 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1555 * proc_dostring - read a string sysctl
1556 * @table: the sysctl table
1557 * @write: %TRUE if this is a write to the sysctl file
1558 * @filp: the file structure
1559 * @buffer: the user buffer
1560 * @lenp: the size of the user buffer
1561 * @ppos: file position
1563 * Reads/writes a string from/to the user buffer. If the kernel
1564 * buffer provided is not large enough to hold the string, the
1565 * string is truncated. The copied string is %NULL-terminated.
1566 * If the string is being read by the user process, it is copied
1567 * and a newline '\n' is added. It is truncated if the buffer is
1570 * Returns 0 on success.
1572 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1573 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1579 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1580 (*ppos
&& !write
)) {
1588 while (len
< *lenp
) {
1589 if (get_user(c
, p
++))
1591 if (c
== 0 || c
== '\n')
1595 if (len
>= table
->maxlen
)
1596 len
= table
->maxlen
-1;
1597 if(copy_from_user(table
->data
, buffer
, len
))
1599 ((char *) table
->data
)[len
] = 0;
1602 len
= strlen(table
->data
);
1603 if (len
> table
->maxlen
)
1604 len
= table
->maxlen
;
1608 if(copy_to_user(buffer
, table
->data
, len
))
1611 if(put_user('\n', ((char __user
*) buffer
) + len
))
1622 * Special case of dostring for the UTS structure. This has locks
1623 * to observe. Should this be in kernel/sys.c ????
1626 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1627 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1632 down_read(&uts_sem
);
1633 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1636 down_write(&uts_sem
);
1637 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1643 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1645 int write
, void *data
)
1648 *valp
= *negp
? -*lvalp
: *lvalp
;
1653 *lvalp
= (unsigned long)-val
;
1656 *lvalp
= (unsigned long)val
;
1662 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1663 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1664 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1665 int write
, void *data
),
1668 #define TMPBUFLEN 21
1669 int *i
, vleft
, first
=1, neg
, val
;
1673 char buf
[TMPBUFLEN
], *p
;
1674 char __user
*s
= buffer
;
1676 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1677 (*ppos
&& !write
)) {
1682 i
= (int *) table
->data
;
1683 vleft
= table
->maxlen
/ sizeof(*i
);
1687 conv
= do_proc_dointvec_conv
;
1689 for (; left
&& vleft
--; i
++, first
=0) {
1704 if (len
> sizeof(buf
) - 1)
1705 len
= sizeof(buf
) - 1;
1706 if (copy_from_user(buf
, s
, len
))
1710 if (*p
== '-' && left
> 1) {
1714 if (*p
< '0' || *p
> '9')
1717 lval
= simple_strtoul(p
, &p
, 0);
1720 if ((len
< left
) && *p
&& !isspace(*p
))
1727 if (conv(&neg
, &lval
, i
, 1, data
))
1734 if (conv(&neg
, &lval
, i
, 0, data
))
1737 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1741 if(copy_to_user(s
, buf
, len
))
1748 if (!write
&& !first
&& left
) {
1749 if(put_user('\n', s
))
1756 if (get_user(c
, s
++))
1772 * proc_dointvec - read a vector of integers
1773 * @table: the sysctl table
1774 * @write: %TRUE if this is a write to the sysctl file
1775 * @filp: the file structure
1776 * @buffer: the user buffer
1777 * @lenp: the size of the user buffer
1778 * @ppos: file position
1780 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1781 * values from/to the user buffer, treated as an ASCII string.
1783 * Returns 0 on success.
1785 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1786 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1788 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1798 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1800 int write
, void *data
)
1802 int op
= *(int *)data
;
1804 int val
= *negp
? -*lvalp
: *lvalp
;
1806 case OP_SET
: *valp
= val
; break;
1807 case OP_AND
: *valp
&= val
; break;
1808 case OP_OR
: *valp
|= val
; break;
1809 case OP_MAX
: if(*valp
< val
)
1812 case OP_MIN
: if(*valp
> val
)
1820 *lvalp
= (unsigned long)-val
;
1823 *lvalp
= (unsigned long)val
;
1830 * init may raise the set.
1833 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1834 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1838 if (!capable(CAP_SYS_MODULE
)) {
1842 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1843 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1844 do_proc_dointvec_bset_conv
,&op
);
1847 struct do_proc_dointvec_minmax_conv_param
{
1852 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1854 int write
, void *data
)
1856 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1858 int val
= *negp
? -*lvalp
: *lvalp
;
1859 if ((param
->min
&& *param
->min
> val
) ||
1860 (param
->max
&& *param
->max
< val
))
1867 *lvalp
= (unsigned long)-val
;
1870 *lvalp
= (unsigned long)val
;
1877 * proc_dointvec_minmax - read a vector of integers with min/max values
1878 * @table: the sysctl table
1879 * @write: %TRUE if this is a write to the sysctl file
1880 * @filp: the file structure
1881 * @buffer: the user buffer
1882 * @lenp: the size of the user buffer
1883 * @ppos: file position
1885 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1886 * values from/to the user buffer, treated as an ASCII string.
1888 * This routine will ensure the values are within the range specified by
1889 * table->extra1 (min) and table->extra2 (max).
1891 * Returns 0 on success.
1893 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1894 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1896 struct do_proc_dointvec_minmax_conv_param param
= {
1897 .min
= (int *) table
->extra1
,
1898 .max
= (int *) table
->extra2
,
1900 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1901 do_proc_dointvec_minmax_conv
, ¶m
);
1904 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1906 void __user
*buffer
,
1907 size_t *lenp
, loff_t
*ppos
,
1908 unsigned long convmul
,
1909 unsigned long convdiv
)
1911 #define TMPBUFLEN 21
1912 unsigned long *i
, *min
, *max
, val
;
1913 int vleft
, first
=1, neg
;
1915 char buf
[TMPBUFLEN
], *p
;
1916 char __user
*s
= buffer
;
1918 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1919 (*ppos
&& !write
)) {
1924 i
= (unsigned long *) table
->data
;
1925 min
= (unsigned long *) table
->extra1
;
1926 max
= (unsigned long *) table
->extra2
;
1927 vleft
= table
->maxlen
/ sizeof(unsigned long);
1930 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1945 if (len
> TMPBUFLEN
-1)
1947 if (copy_from_user(buf
, s
, len
))
1951 if (*p
== '-' && left
> 1) {
1955 if (*p
< '0' || *p
> '9')
1957 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1959 if ((len
< left
) && *p
&& !isspace(*p
))
1968 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1975 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1979 if(copy_to_user(s
, buf
, len
))
1986 if (!write
&& !first
&& left
) {
1987 if(put_user('\n', s
))
1994 if (get_user(c
, s
++))
2010 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2011 * @table: the sysctl table
2012 * @write: %TRUE if this is a write to the sysctl file
2013 * @filp: the file structure
2014 * @buffer: the user buffer
2015 * @lenp: the size of the user buffer
2016 * @ppos: file position
2018 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2019 * values from/to the user buffer, treated as an ASCII string.
2021 * This routine will ensure the values are within the range specified by
2022 * table->extra1 (min) and table->extra2 (max).
2024 * Returns 0 on success.
2026 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2027 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2029 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2033 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2034 * @table: the sysctl table
2035 * @write: %TRUE if this is a write to the sysctl file
2036 * @filp: the file structure
2037 * @buffer: the user buffer
2038 * @lenp: the size of the user buffer
2039 * @ppos: file position
2041 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2042 * values from/to the user buffer, treated as an ASCII string. The values
2043 * are treated as milliseconds, and converted to jiffies when they are stored.
2045 * This routine will ensure the values are within the range specified by
2046 * table->extra1 (min) and table->extra2 (max).
2048 * Returns 0 on success.
2050 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2052 void __user
*buffer
,
2053 size_t *lenp
, loff_t
*ppos
)
2055 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2056 lenp
, ppos
, HZ
, 1000l);
2060 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2062 int write
, void *data
)
2065 if (*lvalp
> LONG_MAX
/ HZ
)
2067 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2073 lval
= (unsigned long)-val
;
2076 lval
= (unsigned long)val
;
2083 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2085 int write
, void *data
)
2088 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2090 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2096 lval
= (unsigned long)-val
;
2099 lval
= (unsigned long)val
;
2101 *lvalp
= jiffies_to_clock_t(lval
);
2106 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2108 int write
, void *data
)
2111 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2117 lval
= (unsigned long)-val
;
2120 lval
= (unsigned long)val
;
2122 *lvalp
= jiffies_to_msecs(lval
);
2128 * proc_dointvec_jiffies - read a vector of integers as seconds
2129 * @table: the sysctl table
2130 * @write: %TRUE if this is a write to the sysctl file
2131 * @filp: the file structure
2132 * @buffer: the user buffer
2133 * @lenp: the size of the user buffer
2134 * @ppos: file position
2136 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2137 * values from/to the user buffer, treated as an ASCII string.
2138 * The values read are assumed to be in seconds, and are converted into
2141 * Returns 0 on success.
2143 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2144 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2146 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2147 do_proc_dointvec_jiffies_conv
,NULL
);
2151 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2152 * @table: the sysctl table
2153 * @write: %TRUE if this is a write to the sysctl file
2154 * @filp: the file structure
2155 * @buffer: the user buffer
2156 * @lenp: the size of the user buffer
2157 * @ppos: pointer to the file position
2159 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2160 * values from/to the user buffer, treated as an ASCII string.
2161 * The values read are assumed to be in 1/USER_HZ seconds, and
2162 * are converted into jiffies.
2164 * Returns 0 on success.
2166 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2167 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2169 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2170 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2174 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2175 * @table: the sysctl table
2176 * @write: %TRUE if this is a write to the sysctl file
2177 * @filp: the file structure
2178 * @buffer: the user buffer
2179 * @lenp: the size of the user buffer
2180 * @ppos: file position
2181 * @ppos: the current position in the file
2183 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2184 * values from/to the user buffer, treated as an ASCII string.
2185 * The values read are assumed to be in 1/1000 seconds, and
2186 * are converted into jiffies.
2188 * Returns 0 on success.
2190 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2191 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2193 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2194 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2197 #else /* CONFIG_PROC_FS */
2199 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2200 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2205 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2206 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2211 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2212 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2217 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2218 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2223 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2229 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2230 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2235 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2236 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2241 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2242 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2247 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2248 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2253 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2255 void __user
*buffer
,
2256 size_t *lenp
, loff_t
*ppos
)
2262 #endif /* CONFIG_PROC_FS */
2266 * General sysctl support routines
2269 /* The generic string strategy routine: */
2270 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2271 void __user
*oldval
, size_t __user
*oldlenp
,
2272 void __user
*newval
, size_t newlen
, void **context
)
2274 if (!table
->data
|| !table
->maxlen
)
2277 if (oldval
&& oldlenp
) {
2279 if (get_user(bufsize
, oldlenp
))
2282 size_t len
= strlen(table
->data
), copied
;
2284 /* This shouldn't trigger for a well-formed sysctl */
2285 if (len
> table
->maxlen
)
2286 len
= table
->maxlen
;
2288 /* Copy up to a max of bufsize-1 bytes of the string */
2289 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2291 if (copy_to_user(oldval
, table
->data
, copied
) ||
2292 put_user(0, (char __user
*)(oldval
+ copied
)))
2294 if (put_user(len
, oldlenp
))
2298 if (newval
&& newlen
) {
2299 size_t len
= newlen
;
2300 if (len
> table
->maxlen
)
2301 len
= table
->maxlen
;
2302 if(copy_from_user(table
->data
, newval
, len
))
2304 if (len
== table
->maxlen
)
2306 ((char *) table
->data
)[len
] = 0;
2312 * This function makes sure that all of the integers in the vector
2313 * are between the minimum and maximum values given in the arrays
2314 * table->extra1 and table->extra2, respectively.
2316 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2317 void __user
*oldval
, size_t __user
*oldlenp
,
2318 void __user
*newval
, size_t newlen
, void **context
)
2321 if (newval
&& newlen
) {
2322 int __user
*vec
= (int __user
*) newval
;
2323 int *min
= (int *) table
->extra1
;
2324 int *max
= (int *) table
->extra2
;
2328 if (newlen
% sizeof(int) != 0)
2331 if (!table
->extra1
&& !table
->extra2
)
2334 if (newlen
> table
->maxlen
)
2335 newlen
= table
->maxlen
;
2336 length
= newlen
/ sizeof(int);
2338 for (i
= 0; i
< length
; i
++) {
2340 if (get_user(value
, vec
+ i
))
2342 if (min
&& value
< min
[i
])
2344 if (max
&& value
> max
[i
])
2351 /* Strategy function to convert jiffies to seconds */
2352 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2353 void __user
*oldval
, size_t __user
*oldlenp
,
2354 void __user
*newval
, size_t newlen
, void **context
)
2359 if (get_user(olen
, oldlenp
))
2361 if (olen
!=sizeof(int))
2364 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2365 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2368 if (newval
&& newlen
) {
2370 if (newlen
!= sizeof(int))
2372 if (get_user(new, (int __user
*)newval
))
2374 *(int *)(table
->data
) = new*HZ
;
2379 /* Strategy function to convert jiffies to seconds */
2380 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2381 void __user
*oldval
, size_t __user
*oldlenp
,
2382 void __user
*newval
, size_t newlen
, void **context
)
2387 if (get_user(olen
, oldlenp
))
2389 if (olen
!=sizeof(int))
2392 if (put_user(jiffies_to_msecs(*(int *)(table
->data
)), (int __user
*)oldval
) ||
2393 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2396 if (newval
&& newlen
) {
2398 if (newlen
!= sizeof(int))
2400 if (get_user(new, (int __user
*)newval
))
2402 *(int *)(table
->data
) = msecs_to_jiffies(new);
2407 #else /* CONFIG_SYSCTL */
2410 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2415 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2416 void __user
*oldval
, size_t __user
*oldlenp
,
2417 void __user
*newval
, size_t newlen
, void **context
)
2422 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2423 void __user
*oldval
, size_t __user
*oldlenp
,
2424 void __user
*newval
, size_t newlen
, void **context
)
2429 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2430 void __user
*oldval
, size_t __user
*oldlenp
,
2431 void __user
*newval
, size_t newlen
, void **context
)
2436 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2437 void __user
*oldval
, size_t __user
*oldlenp
,
2438 void __user
*newval
, size_t newlen
, void **context
)
2443 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2444 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2449 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2450 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2455 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2456 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2461 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2462 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2467 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2468 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2473 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2474 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2479 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2480 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2485 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2486 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2491 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2493 void __user
*buffer
,
2494 size_t *lenp
, loff_t
*ppos
)
2499 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2505 void unregister_sysctl_table(struct ctl_table_header
* table
)
2509 #endif /* CONFIG_SYSCTL */
2512 * No sense putting this after each symbol definition, twice,
2513 * exception granted :-)
2515 EXPORT_SYMBOL(proc_dointvec
);
2516 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2517 EXPORT_SYMBOL(proc_dointvec_minmax
);
2518 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2519 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2520 EXPORT_SYMBOL(proc_dostring
);
2521 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2522 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2523 EXPORT_SYMBOL(register_sysctl_table
);
2524 EXPORT_SYMBOL(sysctl_intvec
);
2525 EXPORT_SYMBOL(sysctl_jiffies
);
2526 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2527 EXPORT_SYMBOL(sysctl_string
);
2528 EXPORT_SYMBOL(unregister_sysctl_table
);