2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/capability.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
52 extern int proc_nr_files(ctl_table
*table
, int write
, struct file
*filp
,
53 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
55 #if defined(CONFIG_SYSCTL)
57 /* External variables not in a header file. */
59 extern int sysctl_overcommit_memory
;
60 extern int sysctl_overcommit_ratio
;
61 extern int sysctl_panic_on_oom
;
62 extern int max_threads
;
63 extern int sysrq_enabled
;
64 extern int core_uses_pid
;
65 extern int suid_dumpable
;
66 extern char core_pattern
[];
69 extern int min_free_kbytes
;
70 extern int printk_ratelimit_jiffies
;
71 extern int printk_ratelimit_burst
;
72 extern int pid_max_min
, pid_max_max
;
73 extern int sysctl_drop_caches
;
74 extern int percpu_pagelist_fraction
;
75 extern int compat_log
;
77 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
78 int unknown_nmi_panic
;
81 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
82 static int maxolduid
= 65535;
84 static int min_percpu_pagelist_fract
= 8;
86 static int ngroups_max
= NGROUPS_MAX
;
89 extern char modprobe_path
[];
91 #ifdef CONFIG_CHR_DEV_SG
92 extern int sg_big_buff
;
95 extern size_t shm_ctlmax
;
96 extern size_t shm_ctlall
;
97 extern int shm_ctlmni
;
98 extern int msg_ctlmax
;
99 extern int msg_ctlmnb
;
100 extern int msg_ctlmni
;
101 extern int sem_ctls
[];
105 extern char reboot_command
[];
106 extern int stop_a_enabled
;
107 extern int scons_pwroff
;
111 extern int pwrsw_enabled
;
112 extern int unaligned_enabled
;
116 #ifdef CONFIG_MATHEMU
117 extern int sysctl_ieee_emulation_warnings
;
119 extern int sysctl_userprocess_debug
;
120 extern int spin_retry
;
123 extern int sysctl_hz_timer
;
125 #ifdef CONFIG_BSD_PROCESS_ACCT
126 extern int acct_parm
[];
130 extern int no_unaligned_warning
;
133 #ifdef CONFIG_RT_MUTEXES
134 extern int max_lock_depth
;
137 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
138 ctl_table
*, void **);
139 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
140 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
142 static ctl_table root_table
[];
143 static struct ctl_table_header root_table_header
=
144 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
146 static ctl_table kern_table
[];
147 static ctl_table vm_table
[];
148 static ctl_table fs_table
[];
149 static ctl_table debug_table
[];
150 static ctl_table dev_table
[];
151 extern ctl_table random_table
[];
152 #ifdef CONFIG_UNIX98_PTYS
153 extern ctl_table pty_table
[];
155 #ifdef CONFIG_INOTIFY_USER
156 extern ctl_table inotify_table
[];
159 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
160 int sysctl_legacy_va_layout
;
163 /* /proc declarations: */
165 #ifdef CONFIG_PROC_FS
167 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
168 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
169 static int proc_opensys(struct inode
*, struct file
*);
171 struct file_operations proc_sys_file_operations
= {
172 .open
= proc_opensys
,
173 .read
= proc_readsys
,
174 .write
= proc_writesys
,
177 extern struct proc_dir_entry
*proc_sys_root
;
179 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*, void *);
180 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
183 /* The default sysctl tables: */
185 static ctl_table root_table
[] = {
187 .ctl_name
= CTL_KERN
,
188 .procname
= "kernel",
213 .ctl_name
= CTL_DEBUG
,
216 .child
= debug_table
,
228 static ctl_table kern_table
[] = {
230 .ctl_name
= KERN_OSTYPE
,
231 .procname
= "ostype",
232 .data
= system_utsname
.sysname
,
233 .maxlen
= sizeof(system_utsname
.sysname
),
235 .proc_handler
= &proc_doutsstring
,
236 .strategy
= &sysctl_string
,
239 .ctl_name
= KERN_OSRELEASE
,
240 .procname
= "osrelease",
241 .data
= system_utsname
.release
,
242 .maxlen
= sizeof(system_utsname
.release
),
244 .proc_handler
= &proc_doutsstring
,
245 .strategy
= &sysctl_string
,
248 .ctl_name
= KERN_VERSION
,
249 .procname
= "version",
250 .data
= system_utsname
.version
,
251 .maxlen
= sizeof(system_utsname
.version
),
253 .proc_handler
= &proc_doutsstring
,
254 .strategy
= &sysctl_string
,
257 .ctl_name
= KERN_NODENAME
,
258 .procname
= "hostname",
259 .data
= system_utsname
.nodename
,
260 .maxlen
= sizeof(system_utsname
.nodename
),
262 .proc_handler
= &proc_doutsstring
,
263 .strategy
= &sysctl_string
,
266 .ctl_name
= KERN_DOMAINNAME
,
267 .procname
= "domainname",
268 .data
= system_utsname
.domainname
,
269 .maxlen
= sizeof(system_utsname
.domainname
),
271 .proc_handler
= &proc_doutsstring
,
272 .strategy
= &sysctl_string
,
275 .ctl_name
= KERN_PANIC
,
277 .data
= &panic_timeout
,
278 .maxlen
= sizeof(int),
280 .proc_handler
= &proc_dointvec
,
283 .ctl_name
= KERN_CORE_USES_PID
,
284 .procname
= "core_uses_pid",
285 .data
= &core_uses_pid
,
286 .maxlen
= sizeof(int),
288 .proc_handler
= &proc_dointvec
,
291 .ctl_name
= KERN_CORE_PATTERN
,
292 .procname
= "core_pattern",
293 .data
= core_pattern
,
296 .proc_handler
= &proc_dostring
,
297 .strategy
= &sysctl_string
,
300 .ctl_name
= KERN_TAINTED
,
301 .procname
= "tainted",
303 .maxlen
= sizeof(int),
305 .proc_handler
= &proc_dointvec
,
308 .ctl_name
= KERN_CAP_BSET
,
309 .procname
= "cap-bound",
311 .maxlen
= sizeof(kernel_cap_t
),
313 .proc_handler
= &proc_dointvec_bset
,
315 #ifdef CONFIG_BLK_DEV_INITRD
317 .ctl_name
= KERN_REALROOTDEV
,
318 .procname
= "real-root-dev",
319 .data
= &real_root_dev
,
320 .maxlen
= sizeof(int),
322 .proc_handler
= &proc_dointvec
,
327 .ctl_name
= KERN_SPARC_REBOOT
,
328 .procname
= "reboot-cmd",
329 .data
= reboot_command
,
332 .proc_handler
= &proc_dostring
,
333 .strategy
= &sysctl_string
,
336 .ctl_name
= KERN_SPARC_STOP_A
,
337 .procname
= "stop-a",
338 .data
= &stop_a_enabled
,
339 .maxlen
= sizeof (int),
341 .proc_handler
= &proc_dointvec
,
344 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
345 .procname
= "scons-poweroff",
346 .data
= &scons_pwroff
,
347 .maxlen
= sizeof (int),
349 .proc_handler
= &proc_dointvec
,
354 .ctl_name
= KERN_HPPA_PWRSW
,
355 .procname
= "soft-power",
356 .data
= &pwrsw_enabled
,
357 .maxlen
= sizeof (int),
359 .proc_handler
= &proc_dointvec
,
362 .ctl_name
= KERN_HPPA_UNALIGNED
,
363 .procname
= "unaligned-trap",
364 .data
= &unaligned_enabled
,
365 .maxlen
= sizeof (int),
367 .proc_handler
= &proc_dointvec
,
371 .ctl_name
= KERN_CTLALTDEL
,
372 .procname
= "ctrl-alt-del",
374 .maxlen
= sizeof(int),
376 .proc_handler
= &proc_dointvec
,
379 .ctl_name
= KERN_PRINTK
,
380 .procname
= "printk",
381 .data
= &console_loglevel
,
382 .maxlen
= 4*sizeof(int),
384 .proc_handler
= &proc_dointvec
,
388 .ctl_name
= KERN_MODPROBE
,
389 .procname
= "modprobe",
390 .data
= &modprobe_path
,
391 .maxlen
= KMOD_PATH_LEN
,
393 .proc_handler
= &proc_dostring
,
394 .strategy
= &sysctl_string
,
397 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
399 .ctl_name
= KERN_HOTPLUG
,
400 .procname
= "hotplug",
401 .data
= &uevent_helper
,
402 .maxlen
= UEVENT_HELPER_PATH_LEN
,
404 .proc_handler
= &proc_dostring
,
405 .strategy
= &sysctl_string
,
408 #ifdef CONFIG_CHR_DEV_SG
410 .ctl_name
= KERN_SG_BIG_BUFF
,
411 .procname
= "sg-big-buff",
412 .data
= &sg_big_buff
,
413 .maxlen
= sizeof (int),
415 .proc_handler
= &proc_dointvec
,
418 #ifdef CONFIG_BSD_PROCESS_ACCT
420 .ctl_name
= KERN_ACCT
,
423 .maxlen
= 3*sizeof(int),
425 .proc_handler
= &proc_dointvec
,
428 #ifdef CONFIG_SYSVIPC
430 .ctl_name
= KERN_SHMMAX
,
431 .procname
= "shmmax",
433 .maxlen
= sizeof (size_t),
435 .proc_handler
= &proc_doulongvec_minmax
,
438 .ctl_name
= KERN_SHMALL
,
439 .procname
= "shmall",
441 .maxlen
= sizeof (size_t),
443 .proc_handler
= &proc_doulongvec_minmax
,
446 .ctl_name
= KERN_SHMMNI
,
447 .procname
= "shmmni",
449 .maxlen
= sizeof (int),
451 .proc_handler
= &proc_dointvec
,
454 .ctl_name
= KERN_MSGMAX
,
455 .procname
= "msgmax",
457 .maxlen
= sizeof (int),
459 .proc_handler
= &proc_dointvec
,
462 .ctl_name
= KERN_MSGMNI
,
463 .procname
= "msgmni",
465 .maxlen
= sizeof (int),
467 .proc_handler
= &proc_dointvec
,
470 .ctl_name
= KERN_MSGMNB
,
471 .procname
= "msgmnb",
473 .maxlen
= sizeof (int),
475 .proc_handler
= &proc_dointvec
,
478 .ctl_name
= KERN_SEM
,
481 .maxlen
= 4*sizeof (int),
483 .proc_handler
= &proc_dointvec
,
486 #ifdef CONFIG_MAGIC_SYSRQ
488 .ctl_name
= KERN_SYSRQ
,
490 .data
= &sysrq_enabled
,
491 .maxlen
= sizeof (int),
493 .proc_handler
= &proc_dointvec
,
497 .ctl_name
= KERN_CADPID
,
498 .procname
= "cad_pid",
500 .maxlen
= sizeof (int),
502 .proc_handler
= &proc_dointvec
,
505 .ctl_name
= KERN_MAX_THREADS
,
506 .procname
= "threads-max",
507 .data
= &max_threads
,
508 .maxlen
= sizeof(int),
510 .proc_handler
= &proc_dointvec
,
513 .ctl_name
= KERN_RANDOM
,
514 .procname
= "random",
516 .child
= random_table
,
518 #ifdef CONFIG_UNIX98_PTYS
520 .ctl_name
= KERN_PTY
,
527 .ctl_name
= KERN_OVERFLOWUID
,
528 .procname
= "overflowuid",
529 .data
= &overflowuid
,
530 .maxlen
= sizeof(int),
532 .proc_handler
= &proc_dointvec_minmax
,
533 .strategy
= &sysctl_intvec
,
534 .extra1
= &minolduid
,
535 .extra2
= &maxolduid
,
538 .ctl_name
= KERN_OVERFLOWGID
,
539 .procname
= "overflowgid",
540 .data
= &overflowgid
,
541 .maxlen
= sizeof(int),
543 .proc_handler
= &proc_dointvec_minmax
,
544 .strategy
= &sysctl_intvec
,
545 .extra1
= &minolduid
,
546 .extra2
= &maxolduid
,
549 #ifdef CONFIG_MATHEMU
551 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
552 .procname
= "ieee_emulation_warnings",
553 .data
= &sysctl_ieee_emulation_warnings
,
554 .maxlen
= sizeof(int),
556 .proc_handler
= &proc_dointvec
,
559 #ifdef CONFIG_NO_IDLE_HZ
561 .ctl_name
= KERN_HZ_TIMER
,
562 .procname
= "hz_timer",
563 .data
= &sysctl_hz_timer
,
564 .maxlen
= sizeof(int),
566 .proc_handler
= &proc_dointvec
,
570 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
571 .procname
= "userprocess_debug",
572 .data
= &sysctl_userprocess_debug
,
573 .maxlen
= sizeof(int),
575 .proc_handler
= &proc_dointvec
,
579 .ctl_name
= KERN_PIDMAX
,
580 .procname
= "pid_max",
582 .maxlen
= sizeof (int),
584 .proc_handler
= &proc_dointvec_minmax
,
585 .strategy
= sysctl_intvec
,
586 .extra1
= &pid_max_min
,
587 .extra2
= &pid_max_max
,
590 .ctl_name
= KERN_PANIC_ON_OOPS
,
591 .procname
= "panic_on_oops",
592 .data
= &panic_on_oops
,
593 .maxlen
= sizeof(int),
595 .proc_handler
= &proc_dointvec
,
598 .ctl_name
= KERN_PRINTK_RATELIMIT
,
599 .procname
= "printk_ratelimit",
600 .data
= &printk_ratelimit_jiffies
,
601 .maxlen
= sizeof(int),
603 .proc_handler
= &proc_dointvec_jiffies
,
604 .strategy
= &sysctl_jiffies
,
607 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
608 .procname
= "printk_ratelimit_burst",
609 .data
= &printk_ratelimit_burst
,
610 .maxlen
= sizeof(int),
612 .proc_handler
= &proc_dointvec
,
615 .ctl_name
= KERN_NGROUPS_MAX
,
616 .procname
= "ngroups_max",
617 .data
= &ngroups_max
,
618 .maxlen
= sizeof (int),
620 .proc_handler
= &proc_dointvec
,
622 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
624 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
625 .procname
= "unknown_nmi_panic",
626 .data
= &unknown_nmi_panic
,
627 .maxlen
= sizeof (int),
629 .proc_handler
= &proc_dointvec
,
632 #if defined(CONFIG_X86)
634 .ctl_name
= KERN_BOOTLOADER_TYPE
,
635 .procname
= "bootloader_type",
636 .data
= &bootloader_type
,
637 .maxlen
= sizeof (int),
639 .proc_handler
= &proc_dointvec
,
642 #if defined(CONFIG_MMU)
644 .ctl_name
= KERN_RANDOMIZE
,
645 .procname
= "randomize_va_space",
646 .data
= &randomize_va_space
,
647 .maxlen
= sizeof(int),
649 .proc_handler
= &proc_dointvec
,
652 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
654 .ctl_name
= KERN_SPIN_RETRY
,
655 .procname
= "spin_retry",
657 .maxlen
= sizeof (int),
659 .proc_handler
= &proc_dointvec
,
662 #ifdef CONFIG_ACPI_SLEEP
664 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
665 .procname
= "acpi_video_flags",
666 .data
= &acpi_video_flags
,
667 .maxlen
= sizeof (unsigned long),
669 .proc_handler
= &proc_doulongvec_minmax
,
674 .ctl_name
= KERN_IA64_UNALIGNED
,
675 .procname
= "ignore-unaligned-usertrap",
676 .data
= &no_unaligned_warning
,
677 .maxlen
= sizeof (int),
679 .proc_handler
= &proc_dointvec
,
684 .ctl_name
= KERN_COMPAT_LOG
,
685 .procname
= "compat-log",
687 .maxlen
= sizeof (int),
689 .proc_handler
= &proc_dointvec
,
692 #ifdef CONFIG_RT_MUTEXES
694 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
695 .procname
= "max_lock_depth",
696 .data
= &max_lock_depth
,
697 .maxlen
= sizeof(int),
699 .proc_handler
= &proc_dointvec
,
706 /* Constants for minimum and maximum testing in vm_table.
707 We use these as one-element integer vectors. */
709 static int one_hundred
= 100;
712 static ctl_table vm_table
[] = {
714 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
715 .procname
= "overcommit_memory",
716 .data
= &sysctl_overcommit_memory
,
717 .maxlen
= sizeof(sysctl_overcommit_memory
),
719 .proc_handler
= &proc_dointvec
,
722 .ctl_name
= VM_PANIC_ON_OOM
,
723 .procname
= "panic_on_oom",
724 .data
= &sysctl_panic_on_oom
,
725 .maxlen
= sizeof(sysctl_panic_on_oom
),
727 .proc_handler
= &proc_dointvec
,
730 .ctl_name
= VM_OVERCOMMIT_RATIO
,
731 .procname
= "overcommit_ratio",
732 .data
= &sysctl_overcommit_ratio
,
733 .maxlen
= sizeof(sysctl_overcommit_ratio
),
735 .proc_handler
= &proc_dointvec
,
738 .ctl_name
= VM_PAGE_CLUSTER
,
739 .procname
= "page-cluster",
740 .data
= &page_cluster
,
741 .maxlen
= sizeof(int),
743 .proc_handler
= &proc_dointvec
,
746 .ctl_name
= VM_DIRTY_BACKGROUND
,
747 .procname
= "dirty_background_ratio",
748 .data
= &dirty_background_ratio
,
749 .maxlen
= sizeof(dirty_background_ratio
),
751 .proc_handler
= &proc_dointvec_minmax
,
752 .strategy
= &sysctl_intvec
,
754 .extra2
= &one_hundred
,
757 .ctl_name
= VM_DIRTY_RATIO
,
758 .procname
= "dirty_ratio",
759 .data
= &vm_dirty_ratio
,
760 .maxlen
= sizeof(vm_dirty_ratio
),
762 .proc_handler
= &proc_dointvec_minmax
,
763 .strategy
= &sysctl_intvec
,
765 .extra2
= &one_hundred
,
768 .ctl_name
= VM_DIRTY_WB_CS
,
769 .procname
= "dirty_writeback_centisecs",
770 .data
= &dirty_writeback_interval
,
771 .maxlen
= sizeof(dirty_writeback_interval
),
773 .proc_handler
= &dirty_writeback_centisecs_handler
,
776 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
777 .procname
= "dirty_expire_centisecs",
778 .data
= &dirty_expire_interval
,
779 .maxlen
= sizeof(dirty_expire_interval
),
781 .proc_handler
= &proc_dointvec_userhz_jiffies
,
784 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
785 .procname
= "nr_pdflush_threads",
786 .data
= &nr_pdflush_threads
,
787 .maxlen
= sizeof nr_pdflush_threads
,
788 .mode
= 0444 /* read-only*/,
789 .proc_handler
= &proc_dointvec
,
792 .ctl_name
= VM_SWAPPINESS
,
793 .procname
= "swappiness",
794 .data
= &vm_swappiness
,
795 .maxlen
= sizeof(vm_swappiness
),
797 .proc_handler
= &proc_dointvec_minmax
,
798 .strategy
= &sysctl_intvec
,
800 .extra2
= &one_hundred
,
802 #ifdef CONFIG_HUGETLB_PAGE
804 .ctl_name
= VM_HUGETLB_PAGES
,
805 .procname
= "nr_hugepages",
806 .data
= &max_huge_pages
,
807 .maxlen
= sizeof(unsigned long),
809 .proc_handler
= &hugetlb_sysctl_handler
,
810 .extra1
= (void *)&hugetlb_zero
,
811 .extra2
= (void *)&hugetlb_infinity
,
814 .ctl_name
= VM_HUGETLB_GROUP
,
815 .procname
= "hugetlb_shm_group",
816 .data
= &sysctl_hugetlb_shm_group
,
817 .maxlen
= sizeof(gid_t
),
819 .proc_handler
= &proc_dointvec
,
823 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
824 .procname
= "lowmem_reserve_ratio",
825 .data
= &sysctl_lowmem_reserve_ratio
,
826 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
828 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
829 .strategy
= &sysctl_intvec
,
832 .ctl_name
= VM_DROP_PAGECACHE
,
833 .procname
= "drop_caches",
834 .data
= &sysctl_drop_caches
,
835 .maxlen
= sizeof(int),
837 .proc_handler
= drop_caches_sysctl_handler
,
838 .strategy
= &sysctl_intvec
,
841 .ctl_name
= VM_MIN_FREE_KBYTES
,
842 .procname
= "min_free_kbytes",
843 .data
= &min_free_kbytes
,
844 .maxlen
= sizeof(min_free_kbytes
),
846 .proc_handler
= &min_free_kbytes_sysctl_handler
,
847 .strategy
= &sysctl_intvec
,
851 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
852 .procname
= "percpu_pagelist_fraction",
853 .data
= &percpu_pagelist_fraction
,
854 .maxlen
= sizeof(percpu_pagelist_fraction
),
856 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
857 .strategy
= &sysctl_intvec
,
858 .extra1
= &min_percpu_pagelist_fract
,
862 .ctl_name
= VM_MAX_MAP_COUNT
,
863 .procname
= "max_map_count",
864 .data
= &sysctl_max_map_count
,
865 .maxlen
= sizeof(sysctl_max_map_count
),
867 .proc_handler
= &proc_dointvec
871 .ctl_name
= VM_LAPTOP_MODE
,
872 .procname
= "laptop_mode",
873 .data
= &laptop_mode
,
874 .maxlen
= sizeof(laptop_mode
),
876 .proc_handler
= &proc_dointvec_jiffies
,
877 .strategy
= &sysctl_jiffies
,
880 .ctl_name
= VM_BLOCK_DUMP
,
881 .procname
= "block_dump",
883 .maxlen
= sizeof(block_dump
),
885 .proc_handler
= &proc_dointvec
,
886 .strategy
= &sysctl_intvec
,
890 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
891 .procname
= "vfs_cache_pressure",
892 .data
= &sysctl_vfs_cache_pressure
,
893 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
895 .proc_handler
= &proc_dointvec
,
896 .strategy
= &sysctl_intvec
,
899 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
901 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
902 .procname
= "legacy_va_layout",
903 .data
= &sysctl_legacy_va_layout
,
904 .maxlen
= sizeof(sysctl_legacy_va_layout
),
906 .proc_handler
= &proc_dointvec
,
907 .strategy
= &sysctl_intvec
,
913 .ctl_name
= VM_SWAP_TOKEN_TIMEOUT
,
914 .procname
= "swap_token_timeout",
915 .data
= &swap_token_default_timeout
,
916 .maxlen
= sizeof(swap_token_default_timeout
),
918 .proc_handler
= &proc_dointvec_jiffies
,
919 .strategy
= &sysctl_jiffies
,
924 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
925 .procname
= "zone_reclaim_mode",
926 .data
= &zone_reclaim_mode
,
927 .maxlen
= sizeof(zone_reclaim_mode
),
929 .proc_handler
= &proc_dointvec
,
930 .strategy
= &sysctl_intvec
,
934 .ctl_name
= VM_MIN_UNMAPPED
,
935 .procname
= "min_unmapped_ratio",
936 .data
= &sysctl_min_unmapped_ratio
,
937 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
939 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
940 .strategy
= &sysctl_intvec
,
942 .extra2
= &one_hundred
,
947 .ctl_name
= VM_VDSO_ENABLED
,
948 .procname
= "vdso_enabled",
949 .data
= &vdso_enabled
,
950 .maxlen
= sizeof(vdso_enabled
),
952 .proc_handler
= &proc_dointvec
,
953 .strategy
= &sysctl_intvec
,
960 static ctl_table fs_table
[] = {
962 .ctl_name
= FS_NRINODE
,
963 .procname
= "inode-nr",
964 .data
= &inodes_stat
,
965 .maxlen
= 2*sizeof(int),
967 .proc_handler
= &proc_dointvec
,
970 .ctl_name
= FS_STATINODE
,
971 .procname
= "inode-state",
972 .data
= &inodes_stat
,
973 .maxlen
= 7*sizeof(int),
975 .proc_handler
= &proc_dointvec
,
978 .ctl_name
= FS_NRFILE
,
979 .procname
= "file-nr",
981 .maxlen
= 3*sizeof(int),
983 .proc_handler
= &proc_nr_files
,
986 .ctl_name
= FS_MAXFILE
,
987 .procname
= "file-max",
988 .data
= &files_stat
.max_files
,
989 .maxlen
= sizeof(int),
991 .proc_handler
= &proc_dointvec
,
994 .ctl_name
= FS_DENTRY
,
995 .procname
= "dentry-state",
996 .data
= &dentry_stat
,
997 .maxlen
= 6*sizeof(int),
999 .proc_handler
= &proc_dointvec
,
1002 .ctl_name
= FS_OVERFLOWUID
,
1003 .procname
= "overflowuid",
1004 .data
= &fs_overflowuid
,
1005 .maxlen
= sizeof(int),
1007 .proc_handler
= &proc_dointvec_minmax
,
1008 .strategy
= &sysctl_intvec
,
1009 .extra1
= &minolduid
,
1010 .extra2
= &maxolduid
,
1013 .ctl_name
= FS_OVERFLOWGID
,
1014 .procname
= "overflowgid",
1015 .data
= &fs_overflowgid
,
1016 .maxlen
= sizeof(int),
1018 .proc_handler
= &proc_dointvec_minmax
,
1019 .strategy
= &sysctl_intvec
,
1020 .extra1
= &minolduid
,
1021 .extra2
= &maxolduid
,
1024 .ctl_name
= FS_LEASES
,
1025 .procname
= "leases-enable",
1026 .data
= &leases_enable
,
1027 .maxlen
= sizeof(int),
1029 .proc_handler
= &proc_dointvec
,
1031 #ifdef CONFIG_DNOTIFY
1033 .ctl_name
= FS_DIR_NOTIFY
,
1034 .procname
= "dir-notify-enable",
1035 .data
= &dir_notify_enable
,
1036 .maxlen
= sizeof(int),
1038 .proc_handler
= &proc_dointvec
,
1043 .ctl_name
= FS_LEASE_TIME
,
1044 .procname
= "lease-break-time",
1045 .data
= &lease_break_time
,
1046 .maxlen
= sizeof(int),
1048 .proc_handler
= &proc_dointvec
,
1051 .ctl_name
= FS_AIO_NR
,
1052 .procname
= "aio-nr",
1054 .maxlen
= sizeof(aio_nr
),
1056 .proc_handler
= &proc_doulongvec_minmax
,
1059 .ctl_name
= FS_AIO_MAX_NR
,
1060 .procname
= "aio-max-nr",
1061 .data
= &aio_max_nr
,
1062 .maxlen
= sizeof(aio_max_nr
),
1064 .proc_handler
= &proc_doulongvec_minmax
,
1066 #ifdef CONFIG_INOTIFY_USER
1068 .ctl_name
= FS_INOTIFY
,
1069 .procname
= "inotify",
1071 .child
= inotify_table
,
1076 .ctl_name
= KERN_SETUID_DUMPABLE
,
1077 .procname
= "suid_dumpable",
1078 .data
= &suid_dumpable
,
1079 .maxlen
= sizeof(int),
1081 .proc_handler
= &proc_dointvec
,
1086 static ctl_table debug_table
[] = {
1090 static ctl_table dev_table
[] = {
1094 extern void init_irq_proc (void);
1096 static DEFINE_SPINLOCK(sysctl_lock
);
1098 /* called under sysctl_lock */
1099 static int use_table(struct ctl_table_header
*p
)
1101 if (unlikely(p
->unregistering
))
1107 /* called under sysctl_lock */
1108 static void unuse_table(struct ctl_table_header
*p
)
1111 if (unlikely(p
->unregistering
))
1112 complete(p
->unregistering
);
1115 /* called under sysctl_lock, will reacquire if has to wait */
1116 static void start_unregistering(struct ctl_table_header
*p
)
1119 * if p->used is 0, nobody will ever touch that entry again;
1120 * we'll eliminate all paths to it before dropping sysctl_lock
1122 if (unlikely(p
->used
)) {
1123 struct completion wait
;
1124 init_completion(&wait
);
1125 p
->unregistering
= &wait
;
1126 spin_unlock(&sysctl_lock
);
1127 wait_for_completion(&wait
);
1128 spin_lock(&sysctl_lock
);
1131 * do not remove from the list until nobody holds it; walking the
1132 * list in do_sysctl() relies on that.
1134 list_del_init(&p
->ctl_entry
);
1137 void __init
sysctl_init(void)
1139 #ifdef CONFIG_PROC_FS
1140 register_proc_table(root_table
, proc_sys_root
, &root_table_header
);
1145 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1146 void __user
*newval
, size_t newlen
)
1148 struct list_head
*tmp
;
1149 int error
= -ENOTDIR
;
1151 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1155 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1158 spin_lock(&sysctl_lock
);
1159 tmp
= &root_table_header
.ctl_entry
;
1161 struct ctl_table_header
*head
=
1162 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1163 void *context
= NULL
;
1165 if (!use_table(head
))
1168 spin_unlock(&sysctl_lock
);
1170 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1171 newval
, newlen
, head
->ctl_table
,
1175 spin_lock(&sysctl_lock
);
1177 if (error
!= -ENOTDIR
)
1179 } while ((tmp
= tmp
->next
) != &root_table_header
.ctl_entry
);
1180 spin_unlock(&sysctl_lock
);
1184 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1186 struct __sysctl_args tmp
;
1189 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1193 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1194 tmp
.newval
, tmp
.newlen
);
1200 * ctl_perm does NOT grant the superuser all rights automatically, because
1201 * some sysctl variables are readonly even to root.
1204 static int test_perm(int mode
, int op
)
1208 else if (in_egroup_p(0))
1210 if ((mode
& op
& 0007) == op
)
1215 static inline int ctl_perm(ctl_table
*table
, int op
)
1218 error
= security_sysctl(table
, op
);
1221 return test_perm(table
->mode
, op
);
1224 static int parse_table(int __user
*name
, int nlen
,
1225 void __user
*oldval
, size_t __user
*oldlenp
,
1226 void __user
*newval
, size_t newlen
,
1227 ctl_table
*table
, void **context
)
1233 if (get_user(n
, name
))
1235 for ( ; table
->ctl_name
; table
++) {
1236 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1239 if (ctl_perm(table
, 001))
1241 if (table
->strategy
) {
1242 error
= table
->strategy(
1245 newval
, newlen
, context
);
1251 table
= table
->child
;
1254 error
= do_sysctl_strategy(table
, name
, nlen
,
1256 newval
, newlen
, context
);
1263 /* Perform the actual read/write of a sysctl table entry. */
1264 int do_sysctl_strategy (ctl_table
*table
,
1265 int __user
*name
, int nlen
,
1266 void __user
*oldval
, size_t __user
*oldlenp
,
1267 void __user
*newval
, size_t newlen
, void **context
)
1276 if (ctl_perm(table
, op
))
1279 if (table
->strategy
) {
1280 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1281 newval
, newlen
, context
);
1288 /* If there is no strategy routine, or if the strategy returns
1289 * zero, proceed with automatic r/w */
1290 if (table
->data
&& table
->maxlen
) {
1291 if (oldval
&& oldlenp
) {
1292 if (get_user(len
, oldlenp
))
1295 if (len
> table
->maxlen
)
1296 len
= table
->maxlen
;
1297 if(copy_to_user(oldval
, table
->data
, len
))
1299 if(put_user(len
, oldlenp
))
1303 if (newval
&& newlen
) {
1305 if (len
> table
->maxlen
)
1306 len
= table
->maxlen
;
1307 if(copy_from_user(table
->data
, newval
, len
))
1315 * register_sysctl_table - register a sysctl hierarchy
1316 * @table: the top-level table structure
1317 * @insert_at_head: whether the entry should be inserted in front or at the end
1319 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1320 * array. An entry with a ctl_name of 0 terminates the table.
1322 * The members of the &ctl_table structure are used as follows:
1324 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1325 * must be unique within that level of sysctl
1327 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1328 * enter a sysctl file
1330 * data - a pointer to data for use by proc_handler
1332 * maxlen - the maximum size in bytes of the data
1334 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1336 * child - a pointer to the child sysctl table if this entry is a directory, or
1339 * proc_handler - the text handler routine (described below)
1341 * strategy - the strategy routine (described below)
1343 * de - for internal use by the sysctl routines
1345 * extra1, extra2 - extra pointers usable by the proc handler routines
1347 * Leaf nodes in the sysctl tree will be represented by a single file
1348 * under /proc; non-leaf nodes will be represented by directories.
1350 * sysctl(2) can automatically manage read and write requests through
1351 * the sysctl table. The data and maxlen fields of the ctl_table
1352 * struct enable minimal validation of the values being written to be
1353 * performed, and the mode field allows minimal authentication.
1355 * More sophisticated management can be enabled by the provision of a
1356 * strategy routine with the table entry. This will be called before
1357 * any automatic read or write of the data is performed.
1359 * The strategy routine may return
1361 * < 0 - Error occurred (error is passed to user process)
1363 * 0 - OK - proceed with automatic read or write.
1365 * > 0 - OK - read or write has been done by the strategy routine, so
1366 * return immediately.
1368 * There must be a proc_handler routine for any terminal nodes
1369 * mirrored under /proc/sys (non-terminals are handled by a built-in
1370 * directory handler). Several default handlers are available to
1371 * cover common cases -
1373 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1374 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1375 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1377 * It is the handler's job to read the input buffer from user memory
1378 * and process it. The handler should return 0 on success.
1380 * This routine returns %NULL on a failure to register, and a pointer
1381 * to the table header on success.
1383 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1386 struct ctl_table_header
*tmp
;
1387 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1390 tmp
->ctl_table
= table
;
1391 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1393 tmp
->unregistering
= NULL
;
1394 spin_lock(&sysctl_lock
);
1396 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1398 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1399 spin_unlock(&sysctl_lock
);
1400 #ifdef CONFIG_PROC_FS
1401 register_proc_table(table
, proc_sys_root
, tmp
);
1407 * unregister_sysctl_table - unregister a sysctl table hierarchy
1408 * @header: the header returned from register_sysctl_table
1410 * Unregisters the sysctl table and all children. proc entries may not
1411 * actually be removed until they are no longer used by anyone.
1413 void unregister_sysctl_table(struct ctl_table_header
* header
)
1416 spin_lock(&sysctl_lock
);
1417 start_unregistering(header
);
1418 #ifdef CONFIG_PROC_FS
1419 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1421 spin_unlock(&sysctl_lock
);
1429 #ifdef CONFIG_PROC_FS
1431 /* Scan the sysctl entries in table and add them all into /proc */
1432 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
, void *set
)
1434 struct proc_dir_entry
*de
;
1438 for (; table
->ctl_name
; table
++) {
1439 /* Can't do anything without a proc name. */
1440 if (!table
->procname
)
1442 /* Maybe we can't do anything with it... */
1443 if (!table
->proc_handler
&& !table
->child
) {
1444 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1449 len
= strlen(table
->procname
);
1453 if (table
->proc_handler
)
1457 for (de
= root
->subdir
; de
; de
= de
->next
) {
1458 if (proc_match(len
, table
->procname
, de
))
1461 /* If the subdir exists already, de is non-NULL */
1465 de
= create_proc_entry(table
->procname
, mode
, root
);
1469 de
->data
= (void *) table
;
1470 if (table
->proc_handler
)
1471 de
->proc_fops
= &proc_sys_file_operations
;
1474 if (de
->mode
& S_IFDIR
)
1475 register_proc_table(table
->child
, de
, set
);
1480 * Unregister a /proc sysctl table and any subdirectories.
1482 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1484 struct proc_dir_entry
*de
;
1485 for (; table
->ctl_name
; table
++) {
1486 if (!(de
= table
->de
))
1488 if (de
->mode
& S_IFDIR
) {
1489 if (!table
->child
) {
1490 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1493 unregister_proc_table(table
->child
, de
);
1495 /* Don't unregister directories which still have entries.. */
1501 * In any case, mark the entry as goner; we'll keep it
1502 * around if it's busy, but we'll know to do nothing with
1503 * its fields. We are under sysctl_lock here.
1507 /* Don't unregister proc entries that are still being used.. */
1508 if (atomic_read(&de
->count
))
1512 remove_proc_entry(table
->procname
, root
);
1516 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1517 size_t count
, loff_t
*ppos
)
1520 struct proc_dir_entry
*de
= PDE(file
->f_dentry
->d_inode
);
1521 struct ctl_table
*table
;
1523 ssize_t error
= -ENOTDIR
;
1525 spin_lock(&sysctl_lock
);
1526 if (de
&& de
->data
&& use_table(de
->set
)) {
1528 * at that point we know that sysctl was not unregistered
1529 * and won't be until we finish
1531 spin_unlock(&sysctl_lock
);
1532 table
= (struct ctl_table
*) de
->data
;
1533 if (!table
|| !table
->proc_handler
)
1536 op
= (write
? 002 : 004);
1537 if (ctl_perm(table
, op
))
1540 /* careful: calling conventions are nasty here */
1542 error
= (*table
->proc_handler
)(table
, write
, file
,
1547 spin_lock(&sysctl_lock
);
1548 unuse_table(de
->set
);
1550 spin_unlock(&sysctl_lock
);
1554 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1556 if (file
->f_mode
& FMODE_WRITE
) {
1558 * sysctl entries that are not writable,
1559 * are _NOT_ writable, capabilities or not.
1561 if (!(inode
->i_mode
& S_IWUSR
))
1568 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1569 size_t count
, loff_t
*ppos
)
1571 return do_rw_proc(0, file
, buf
, count
, ppos
);
1574 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1575 size_t count
, loff_t
*ppos
)
1577 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1581 * proc_dostring - read a string sysctl
1582 * @table: the sysctl table
1583 * @write: %TRUE if this is a write to the sysctl file
1584 * @filp: the file structure
1585 * @buffer: the user buffer
1586 * @lenp: the size of the user buffer
1587 * @ppos: file position
1589 * Reads/writes a string from/to the user buffer. If the kernel
1590 * buffer provided is not large enough to hold the string, the
1591 * string is truncated. The copied string is %NULL-terminated.
1592 * If the string is being read by the user process, it is copied
1593 * and a newline '\n' is added. It is truncated if the buffer is
1596 * Returns 0 on success.
1598 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1599 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1605 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1606 (*ppos
&& !write
)) {
1614 while (len
< *lenp
) {
1615 if (get_user(c
, p
++))
1617 if (c
== 0 || c
== '\n')
1621 if (len
>= table
->maxlen
)
1622 len
= table
->maxlen
-1;
1623 if(copy_from_user(table
->data
, buffer
, len
))
1625 ((char *) table
->data
)[len
] = 0;
1628 len
= strlen(table
->data
);
1629 if (len
> table
->maxlen
)
1630 len
= table
->maxlen
;
1634 if(copy_to_user(buffer
, table
->data
, len
))
1637 if(put_user('\n', ((char __user
*) buffer
) + len
))
1648 * Special case of dostring for the UTS structure. This has locks
1649 * to observe. Should this be in kernel/sys.c ????
1652 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1653 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1658 down_read(&uts_sem
);
1659 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1662 down_write(&uts_sem
);
1663 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1669 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1671 int write
, void *data
)
1674 *valp
= *negp
? -*lvalp
: *lvalp
;
1679 *lvalp
= (unsigned long)-val
;
1682 *lvalp
= (unsigned long)val
;
1688 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1689 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1690 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1691 int write
, void *data
),
1694 #define TMPBUFLEN 21
1695 int *i
, vleft
, first
=1, neg
, val
;
1699 char buf
[TMPBUFLEN
], *p
;
1700 char __user
*s
= buffer
;
1702 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1703 (*ppos
&& !write
)) {
1708 i
= (int *) table
->data
;
1709 vleft
= table
->maxlen
/ sizeof(*i
);
1713 conv
= do_proc_dointvec_conv
;
1715 for (; left
&& vleft
--; i
++, first
=0) {
1730 if (len
> sizeof(buf
) - 1)
1731 len
= sizeof(buf
) - 1;
1732 if (copy_from_user(buf
, s
, len
))
1736 if (*p
== '-' && left
> 1) {
1740 if (*p
< '0' || *p
> '9')
1743 lval
= simple_strtoul(p
, &p
, 0);
1746 if ((len
< left
) && *p
&& !isspace(*p
))
1753 if (conv(&neg
, &lval
, i
, 1, data
))
1760 if (conv(&neg
, &lval
, i
, 0, data
))
1763 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1767 if(copy_to_user(s
, buf
, len
))
1774 if (!write
&& !first
&& left
) {
1775 if(put_user('\n', s
))
1782 if (get_user(c
, s
++))
1798 * proc_dointvec - read a vector of integers
1799 * @table: the sysctl table
1800 * @write: %TRUE if this is a write to the sysctl file
1801 * @filp: the file structure
1802 * @buffer: the user buffer
1803 * @lenp: the size of the user buffer
1804 * @ppos: file position
1806 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1807 * values from/to the user buffer, treated as an ASCII string.
1809 * Returns 0 on success.
1811 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1812 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1814 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1824 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1826 int write
, void *data
)
1828 int op
= *(int *)data
;
1830 int val
= *negp
? -*lvalp
: *lvalp
;
1832 case OP_SET
: *valp
= val
; break;
1833 case OP_AND
: *valp
&= val
; break;
1834 case OP_OR
: *valp
|= val
; break;
1835 case OP_MAX
: if(*valp
< val
)
1838 case OP_MIN
: if(*valp
> val
)
1846 *lvalp
= (unsigned long)-val
;
1849 *lvalp
= (unsigned long)val
;
1856 * init may raise the set.
1859 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1860 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1864 if (!capable(CAP_SYS_MODULE
)) {
1868 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1869 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1870 do_proc_dointvec_bset_conv
,&op
);
1873 struct do_proc_dointvec_minmax_conv_param
{
1878 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1880 int write
, void *data
)
1882 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1884 int val
= *negp
? -*lvalp
: *lvalp
;
1885 if ((param
->min
&& *param
->min
> val
) ||
1886 (param
->max
&& *param
->max
< val
))
1893 *lvalp
= (unsigned long)-val
;
1896 *lvalp
= (unsigned long)val
;
1903 * proc_dointvec_minmax - read a vector of integers with min/max values
1904 * @table: the sysctl table
1905 * @write: %TRUE if this is a write to the sysctl file
1906 * @filp: the file structure
1907 * @buffer: the user buffer
1908 * @lenp: the size of the user buffer
1909 * @ppos: file position
1911 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1912 * values from/to the user buffer, treated as an ASCII string.
1914 * This routine will ensure the values are within the range specified by
1915 * table->extra1 (min) and table->extra2 (max).
1917 * Returns 0 on success.
1919 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1920 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1922 struct do_proc_dointvec_minmax_conv_param param
= {
1923 .min
= (int *) table
->extra1
,
1924 .max
= (int *) table
->extra2
,
1926 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1927 do_proc_dointvec_minmax_conv
, ¶m
);
1930 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1932 void __user
*buffer
,
1933 size_t *lenp
, loff_t
*ppos
,
1934 unsigned long convmul
,
1935 unsigned long convdiv
)
1937 #define TMPBUFLEN 21
1938 unsigned long *i
, *min
, *max
, val
;
1939 int vleft
, first
=1, neg
;
1941 char buf
[TMPBUFLEN
], *p
;
1942 char __user
*s
= buffer
;
1944 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1945 (*ppos
&& !write
)) {
1950 i
= (unsigned long *) table
->data
;
1951 min
= (unsigned long *) table
->extra1
;
1952 max
= (unsigned long *) table
->extra2
;
1953 vleft
= table
->maxlen
/ sizeof(unsigned long);
1956 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1971 if (len
> TMPBUFLEN
-1)
1973 if (copy_from_user(buf
, s
, len
))
1977 if (*p
== '-' && left
> 1) {
1981 if (*p
< '0' || *p
> '9')
1983 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1985 if ((len
< left
) && *p
&& !isspace(*p
))
1994 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2001 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2005 if(copy_to_user(s
, buf
, len
))
2012 if (!write
&& !first
&& left
) {
2013 if(put_user('\n', s
))
2020 if (get_user(c
, s
++))
2036 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2037 * @table: the sysctl table
2038 * @write: %TRUE if this is a write to the sysctl file
2039 * @filp: the file structure
2040 * @buffer: the user buffer
2041 * @lenp: the size of the user buffer
2042 * @ppos: file position
2044 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2045 * values from/to the user buffer, treated as an ASCII string.
2047 * This routine will ensure the values are within the range specified by
2048 * table->extra1 (min) and table->extra2 (max).
2050 * Returns 0 on success.
2052 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2053 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2055 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2059 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2060 * @table: the sysctl table
2061 * @write: %TRUE if this is a write to the sysctl file
2062 * @filp: the file structure
2063 * @buffer: the user buffer
2064 * @lenp: the size of the user buffer
2065 * @ppos: file position
2067 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2068 * values from/to the user buffer, treated as an ASCII string. The values
2069 * are treated as milliseconds, and converted to jiffies when they are stored.
2071 * This routine will ensure the values are within the range specified by
2072 * table->extra1 (min) and table->extra2 (max).
2074 * Returns 0 on success.
2076 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2078 void __user
*buffer
,
2079 size_t *lenp
, loff_t
*ppos
)
2081 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2082 lenp
, ppos
, HZ
, 1000l);
2086 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2088 int write
, void *data
)
2091 if (*lvalp
> LONG_MAX
/ HZ
)
2093 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2099 lval
= (unsigned long)-val
;
2102 lval
= (unsigned long)val
;
2109 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2111 int write
, void *data
)
2114 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2116 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2122 lval
= (unsigned long)-val
;
2125 lval
= (unsigned long)val
;
2127 *lvalp
= jiffies_to_clock_t(lval
);
2132 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2134 int write
, void *data
)
2137 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2143 lval
= (unsigned long)-val
;
2146 lval
= (unsigned long)val
;
2148 *lvalp
= jiffies_to_msecs(lval
);
2154 * proc_dointvec_jiffies - read a vector of integers as seconds
2155 * @table: the sysctl table
2156 * @write: %TRUE if this is a write to the sysctl file
2157 * @filp: the file structure
2158 * @buffer: the user buffer
2159 * @lenp: the size of the user buffer
2160 * @ppos: file position
2162 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2163 * values from/to the user buffer, treated as an ASCII string.
2164 * The values read are assumed to be in seconds, and are converted into
2167 * Returns 0 on success.
2169 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2170 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2172 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2173 do_proc_dointvec_jiffies_conv
,NULL
);
2177 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2178 * @table: the sysctl table
2179 * @write: %TRUE if this is a write to the sysctl file
2180 * @filp: the file structure
2181 * @buffer: the user buffer
2182 * @lenp: the size of the user buffer
2183 * @ppos: pointer to the file position
2185 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2186 * values from/to the user buffer, treated as an ASCII string.
2187 * The values read are assumed to be in 1/USER_HZ seconds, and
2188 * are converted into jiffies.
2190 * Returns 0 on success.
2192 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2193 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2195 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2196 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2200 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2201 * @table: the sysctl table
2202 * @write: %TRUE if this is a write to the sysctl file
2203 * @filp: the file structure
2204 * @buffer: the user buffer
2205 * @lenp: the size of the user buffer
2206 * @ppos: file position
2207 * @ppos: the current position in the file
2209 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2210 * values from/to the user buffer, treated as an ASCII string.
2211 * The values read are assumed to be in 1/1000 seconds, and
2212 * are converted into jiffies.
2214 * Returns 0 on success.
2216 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2217 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2219 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2220 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2223 #else /* CONFIG_PROC_FS */
2225 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2226 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2231 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2232 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2237 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2238 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2243 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2244 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2249 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2250 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2255 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2256 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2261 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2262 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2267 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2268 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2273 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2274 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2279 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2281 void __user
*buffer
,
2282 size_t *lenp
, loff_t
*ppos
)
2288 #endif /* CONFIG_PROC_FS */
2292 * General sysctl support routines
2295 /* The generic string strategy routine: */
2296 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2297 void __user
*oldval
, size_t __user
*oldlenp
,
2298 void __user
*newval
, size_t newlen
, void **context
)
2300 if (!table
->data
|| !table
->maxlen
)
2303 if (oldval
&& oldlenp
) {
2305 if (get_user(bufsize
, oldlenp
))
2308 size_t len
= strlen(table
->data
), copied
;
2310 /* This shouldn't trigger for a well-formed sysctl */
2311 if (len
> table
->maxlen
)
2312 len
= table
->maxlen
;
2314 /* Copy up to a max of bufsize-1 bytes of the string */
2315 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2317 if (copy_to_user(oldval
, table
->data
, copied
) ||
2318 put_user(0, (char __user
*)(oldval
+ copied
)))
2320 if (put_user(len
, oldlenp
))
2324 if (newval
&& newlen
) {
2325 size_t len
= newlen
;
2326 if (len
> table
->maxlen
)
2327 len
= table
->maxlen
;
2328 if(copy_from_user(table
->data
, newval
, len
))
2330 if (len
== table
->maxlen
)
2332 ((char *) table
->data
)[len
] = 0;
2338 * This function makes sure that all of the integers in the vector
2339 * are between the minimum and maximum values given in the arrays
2340 * table->extra1 and table->extra2, respectively.
2342 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2343 void __user
*oldval
, size_t __user
*oldlenp
,
2344 void __user
*newval
, size_t newlen
, void **context
)
2347 if (newval
&& newlen
) {
2348 int __user
*vec
= (int __user
*) newval
;
2349 int *min
= (int *) table
->extra1
;
2350 int *max
= (int *) table
->extra2
;
2354 if (newlen
% sizeof(int) != 0)
2357 if (!table
->extra1
&& !table
->extra2
)
2360 if (newlen
> table
->maxlen
)
2361 newlen
= table
->maxlen
;
2362 length
= newlen
/ sizeof(int);
2364 for (i
= 0; i
< length
; i
++) {
2366 if (get_user(value
, vec
+ i
))
2368 if (min
&& value
< min
[i
])
2370 if (max
&& value
> max
[i
])
2377 /* Strategy function to convert jiffies to seconds */
2378 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2379 void __user
*oldval
, size_t __user
*oldlenp
,
2380 void __user
*newval
, size_t newlen
, void **context
)
2385 if (get_user(olen
, oldlenp
))
2387 if (olen
!=sizeof(int))
2390 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2391 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2394 if (newval
&& newlen
) {
2396 if (newlen
!= sizeof(int))
2398 if (get_user(new, (int __user
*)newval
))
2400 *(int *)(table
->data
) = new*HZ
;
2405 /* Strategy function to convert jiffies to seconds */
2406 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2407 void __user
*oldval
, size_t __user
*oldlenp
,
2408 void __user
*newval
, size_t newlen
, void **context
)
2413 if (get_user(olen
, oldlenp
))
2415 if (olen
!=sizeof(int))
2418 if (put_user(jiffies_to_msecs(*(int *)(table
->data
)), (int __user
*)oldval
) ||
2419 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2422 if (newval
&& newlen
) {
2424 if (newlen
!= sizeof(int))
2426 if (get_user(new, (int __user
*)newval
))
2428 *(int *)(table
->data
) = msecs_to_jiffies(new);
2433 #else /* CONFIG_SYSCTL */
2436 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2441 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2442 void __user
*oldval
, size_t __user
*oldlenp
,
2443 void __user
*newval
, size_t newlen
, void **context
)
2448 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2449 void __user
*oldval
, size_t __user
*oldlenp
,
2450 void __user
*newval
, size_t newlen
, void **context
)
2455 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2456 void __user
*oldval
, size_t __user
*oldlenp
,
2457 void __user
*newval
, size_t newlen
, void **context
)
2462 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2463 void __user
*oldval
, size_t __user
*oldlenp
,
2464 void __user
*newval
, size_t newlen
, void **context
)
2469 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2470 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2475 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2476 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2481 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2482 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2487 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2488 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2493 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2494 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2499 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2500 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2505 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2506 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2511 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2512 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2517 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2519 void __user
*buffer
,
2520 size_t *lenp
, loff_t
*ppos
)
2525 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2531 void unregister_sysctl_table(struct ctl_table_header
* table
)
2535 #endif /* CONFIG_SYSCTL */
2538 * No sense putting this after each symbol definition, twice,
2539 * exception granted :-)
2541 EXPORT_SYMBOL(proc_dointvec
);
2542 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2543 EXPORT_SYMBOL(proc_dointvec_minmax
);
2544 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2545 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2546 EXPORT_SYMBOL(proc_dostring
);
2547 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2548 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2549 EXPORT_SYMBOL(register_sysctl_table
);
2550 EXPORT_SYMBOL(sysctl_intvec
);
2551 EXPORT_SYMBOL(sysctl_jiffies
);
2552 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2553 EXPORT_SYMBOL(sysctl_string
);
2554 EXPORT_SYMBOL(unregister_sysctl_table
);