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
;
79 int nmi_watchdog_enabled
;
80 extern int proc_nmi_enabled(struct ctl_table
*, int , struct file
*,
81 void __user
*, size_t *, loff_t
*);
84 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
85 static int maxolduid
= 65535;
87 static int min_percpu_pagelist_fract
= 8;
89 static int ngroups_max
= NGROUPS_MAX
;
92 extern char modprobe_path
[];
94 #ifdef CONFIG_CHR_DEV_SG
95 extern int sg_big_buff
;
98 extern size_t shm_ctlmax
;
99 extern size_t shm_ctlall
;
100 extern int shm_ctlmni
;
101 extern int msg_ctlmax
;
102 extern int msg_ctlmnb
;
103 extern int msg_ctlmni
;
104 extern int sem_ctls
[];
108 extern char reboot_command
[];
109 extern int stop_a_enabled
;
110 extern int scons_pwroff
;
114 extern int pwrsw_enabled
;
115 extern int unaligned_enabled
;
119 #ifdef CONFIG_MATHEMU
120 extern int sysctl_ieee_emulation_warnings
;
122 extern int sysctl_userprocess_debug
;
123 extern int spin_retry
;
126 extern int sysctl_hz_timer
;
128 #ifdef CONFIG_BSD_PROCESS_ACCT
129 extern int acct_parm
[];
133 extern int no_unaligned_warning
;
136 #ifdef CONFIG_RT_MUTEXES
137 extern int max_lock_depth
;
140 #ifdef CONFIG_SYSCTL_SYSCALL
141 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
142 void __user
*, size_t, ctl_table
*, void **);
145 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
146 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
148 static ctl_table root_table
[];
149 static struct ctl_table_header root_table_header
=
150 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
152 static ctl_table kern_table
[];
153 static ctl_table vm_table
[];
154 static ctl_table fs_table
[];
155 static ctl_table debug_table
[];
156 static ctl_table dev_table
[];
157 extern ctl_table random_table
[];
158 #ifdef CONFIG_UNIX98_PTYS
159 extern ctl_table pty_table
[];
161 #ifdef CONFIG_INOTIFY_USER
162 extern ctl_table inotify_table
[];
165 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
166 int sysctl_legacy_va_layout
;
169 /* /proc declarations: */
171 #ifdef CONFIG_PROC_SYSCTL
173 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
174 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
175 static int proc_opensys(struct inode
*, struct file
*);
177 struct file_operations proc_sys_file_operations
= {
178 .open
= proc_opensys
,
179 .read
= proc_readsys
,
180 .write
= proc_writesys
,
183 extern struct proc_dir_entry
*proc_sys_root
;
185 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*, void *);
186 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
189 /* The default sysctl tables: */
191 static ctl_table root_table
[] = {
193 .ctl_name
= CTL_KERN
,
194 .procname
= "kernel",
219 .ctl_name
= CTL_DEBUG
,
222 .child
= debug_table
,
234 static ctl_table kern_table
[] = {
236 .ctl_name
= KERN_OSTYPE
,
237 .procname
= "ostype",
238 .data
= system_utsname
.sysname
,
239 .maxlen
= sizeof(system_utsname
.sysname
),
241 .proc_handler
= &proc_doutsstring
,
242 .strategy
= &sysctl_string
,
245 .ctl_name
= KERN_OSRELEASE
,
246 .procname
= "osrelease",
247 .data
= system_utsname
.release
,
248 .maxlen
= sizeof(system_utsname
.release
),
250 .proc_handler
= &proc_doutsstring
,
251 .strategy
= &sysctl_string
,
254 .ctl_name
= KERN_VERSION
,
255 .procname
= "version",
256 .data
= system_utsname
.version
,
257 .maxlen
= sizeof(system_utsname
.version
),
259 .proc_handler
= &proc_doutsstring
,
260 .strategy
= &sysctl_string
,
263 .ctl_name
= KERN_NODENAME
,
264 .procname
= "hostname",
265 .data
= system_utsname
.nodename
,
266 .maxlen
= sizeof(system_utsname
.nodename
),
268 .proc_handler
= &proc_doutsstring
,
269 .strategy
= &sysctl_string
,
272 .ctl_name
= KERN_DOMAINNAME
,
273 .procname
= "domainname",
274 .data
= system_utsname
.domainname
,
275 .maxlen
= sizeof(system_utsname
.domainname
),
277 .proc_handler
= &proc_doutsstring
,
278 .strategy
= &sysctl_string
,
281 .ctl_name
= KERN_PANIC
,
283 .data
= &panic_timeout
,
284 .maxlen
= sizeof(int),
286 .proc_handler
= &proc_dointvec
,
289 .ctl_name
= KERN_CORE_USES_PID
,
290 .procname
= "core_uses_pid",
291 .data
= &core_uses_pid
,
292 .maxlen
= sizeof(int),
294 .proc_handler
= &proc_dointvec
,
297 .ctl_name
= KERN_CORE_PATTERN
,
298 .procname
= "core_pattern",
299 .data
= core_pattern
,
302 .proc_handler
= &proc_dostring
,
303 .strategy
= &sysctl_string
,
306 .ctl_name
= KERN_TAINTED
,
307 .procname
= "tainted",
309 .maxlen
= sizeof(int),
311 .proc_handler
= &proc_dointvec
,
314 .ctl_name
= KERN_CAP_BSET
,
315 .procname
= "cap-bound",
317 .maxlen
= sizeof(kernel_cap_t
),
319 .proc_handler
= &proc_dointvec_bset
,
321 #ifdef CONFIG_BLK_DEV_INITRD
323 .ctl_name
= KERN_REALROOTDEV
,
324 .procname
= "real-root-dev",
325 .data
= &real_root_dev
,
326 .maxlen
= sizeof(int),
328 .proc_handler
= &proc_dointvec
,
333 .ctl_name
= KERN_SPARC_REBOOT
,
334 .procname
= "reboot-cmd",
335 .data
= reboot_command
,
338 .proc_handler
= &proc_dostring
,
339 .strategy
= &sysctl_string
,
342 .ctl_name
= KERN_SPARC_STOP_A
,
343 .procname
= "stop-a",
344 .data
= &stop_a_enabled
,
345 .maxlen
= sizeof (int),
347 .proc_handler
= &proc_dointvec
,
350 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
351 .procname
= "scons-poweroff",
352 .data
= &scons_pwroff
,
353 .maxlen
= sizeof (int),
355 .proc_handler
= &proc_dointvec
,
360 .ctl_name
= KERN_HPPA_PWRSW
,
361 .procname
= "soft-power",
362 .data
= &pwrsw_enabled
,
363 .maxlen
= sizeof (int),
365 .proc_handler
= &proc_dointvec
,
368 .ctl_name
= KERN_HPPA_UNALIGNED
,
369 .procname
= "unaligned-trap",
370 .data
= &unaligned_enabled
,
371 .maxlen
= sizeof (int),
373 .proc_handler
= &proc_dointvec
,
377 .ctl_name
= KERN_CTLALTDEL
,
378 .procname
= "ctrl-alt-del",
380 .maxlen
= sizeof(int),
382 .proc_handler
= &proc_dointvec
,
385 .ctl_name
= KERN_PRINTK
,
386 .procname
= "printk",
387 .data
= &console_loglevel
,
388 .maxlen
= 4*sizeof(int),
390 .proc_handler
= &proc_dointvec
,
394 .ctl_name
= KERN_MODPROBE
,
395 .procname
= "modprobe",
396 .data
= &modprobe_path
,
397 .maxlen
= KMOD_PATH_LEN
,
399 .proc_handler
= &proc_dostring
,
400 .strategy
= &sysctl_string
,
403 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
405 .ctl_name
= KERN_HOTPLUG
,
406 .procname
= "hotplug",
407 .data
= &uevent_helper
,
408 .maxlen
= UEVENT_HELPER_PATH_LEN
,
410 .proc_handler
= &proc_dostring
,
411 .strategy
= &sysctl_string
,
414 #ifdef CONFIG_CHR_DEV_SG
416 .ctl_name
= KERN_SG_BIG_BUFF
,
417 .procname
= "sg-big-buff",
418 .data
= &sg_big_buff
,
419 .maxlen
= sizeof (int),
421 .proc_handler
= &proc_dointvec
,
424 #ifdef CONFIG_BSD_PROCESS_ACCT
426 .ctl_name
= KERN_ACCT
,
429 .maxlen
= 3*sizeof(int),
431 .proc_handler
= &proc_dointvec
,
434 #ifdef CONFIG_SYSVIPC
436 .ctl_name
= KERN_SHMMAX
,
437 .procname
= "shmmax",
439 .maxlen
= sizeof (size_t),
441 .proc_handler
= &proc_doulongvec_minmax
,
444 .ctl_name
= KERN_SHMALL
,
445 .procname
= "shmall",
447 .maxlen
= sizeof (size_t),
449 .proc_handler
= &proc_doulongvec_minmax
,
452 .ctl_name
= KERN_SHMMNI
,
453 .procname
= "shmmni",
455 .maxlen
= sizeof (int),
457 .proc_handler
= &proc_dointvec
,
460 .ctl_name
= KERN_MSGMAX
,
461 .procname
= "msgmax",
463 .maxlen
= sizeof (int),
465 .proc_handler
= &proc_dointvec
,
468 .ctl_name
= KERN_MSGMNI
,
469 .procname
= "msgmni",
471 .maxlen
= sizeof (int),
473 .proc_handler
= &proc_dointvec
,
476 .ctl_name
= KERN_MSGMNB
,
477 .procname
= "msgmnb",
479 .maxlen
= sizeof (int),
481 .proc_handler
= &proc_dointvec
,
484 .ctl_name
= KERN_SEM
,
487 .maxlen
= 4*sizeof (int),
489 .proc_handler
= &proc_dointvec
,
492 #ifdef CONFIG_MAGIC_SYSRQ
494 .ctl_name
= KERN_SYSRQ
,
496 .data
= &sysrq_enabled
,
497 .maxlen
= sizeof (int),
499 .proc_handler
= &proc_dointvec
,
503 .ctl_name
= KERN_CADPID
,
504 .procname
= "cad_pid",
506 .maxlen
= sizeof (int),
508 .proc_handler
= &proc_dointvec
,
511 .ctl_name
= KERN_MAX_THREADS
,
512 .procname
= "threads-max",
513 .data
= &max_threads
,
514 .maxlen
= sizeof(int),
516 .proc_handler
= &proc_dointvec
,
519 .ctl_name
= KERN_RANDOM
,
520 .procname
= "random",
522 .child
= random_table
,
524 #ifdef CONFIG_UNIX98_PTYS
526 .ctl_name
= KERN_PTY
,
533 .ctl_name
= KERN_OVERFLOWUID
,
534 .procname
= "overflowuid",
535 .data
= &overflowuid
,
536 .maxlen
= sizeof(int),
538 .proc_handler
= &proc_dointvec_minmax
,
539 .strategy
= &sysctl_intvec
,
540 .extra1
= &minolduid
,
541 .extra2
= &maxolduid
,
544 .ctl_name
= KERN_OVERFLOWGID
,
545 .procname
= "overflowgid",
546 .data
= &overflowgid
,
547 .maxlen
= sizeof(int),
549 .proc_handler
= &proc_dointvec_minmax
,
550 .strategy
= &sysctl_intvec
,
551 .extra1
= &minolduid
,
552 .extra2
= &maxolduid
,
555 #ifdef CONFIG_MATHEMU
557 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
558 .procname
= "ieee_emulation_warnings",
559 .data
= &sysctl_ieee_emulation_warnings
,
560 .maxlen
= sizeof(int),
562 .proc_handler
= &proc_dointvec
,
565 #ifdef CONFIG_NO_IDLE_HZ
567 .ctl_name
= KERN_HZ_TIMER
,
568 .procname
= "hz_timer",
569 .data
= &sysctl_hz_timer
,
570 .maxlen
= sizeof(int),
572 .proc_handler
= &proc_dointvec
,
576 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
577 .procname
= "userprocess_debug",
578 .data
= &sysctl_userprocess_debug
,
579 .maxlen
= sizeof(int),
581 .proc_handler
= &proc_dointvec
,
585 .ctl_name
= KERN_PIDMAX
,
586 .procname
= "pid_max",
588 .maxlen
= sizeof (int),
590 .proc_handler
= &proc_dointvec_minmax
,
591 .strategy
= sysctl_intvec
,
592 .extra1
= &pid_max_min
,
593 .extra2
= &pid_max_max
,
596 .ctl_name
= KERN_PANIC_ON_OOPS
,
597 .procname
= "panic_on_oops",
598 .data
= &panic_on_oops
,
599 .maxlen
= sizeof(int),
601 .proc_handler
= &proc_dointvec
,
604 .ctl_name
= KERN_PRINTK_RATELIMIT
,
605 .procname
= "printk_ratelimit",
606 .data
= &printk_ratelimit_jiffies
,
607 .maxlen
= sizeof(int),
609 .proc_handler
= &proc_dointvec_jiffies
,
610 .strategy
= &sysctl_jiffies
,
613 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
614 .procname
= "printk_ratelimit_burst",
615 .data
= &printk_ratelimit_burst
,
616 .maxlen
= sizeof(int),
618 .proc_handler
= &proc_dointvec
,
621 .ctl_name
= KERN_NGROUPS_MAX
,
622 .procname
= "ngroups_max",
623 .data
= &ngroups_max
,
624 .maxlen
= sizeof (int),
626 .proc_handler
= &proc_dointvec
,
628 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
630 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
631 .procname
= "unknown_nmi_panic",
632 .data
= &unknown_nmi_panic
,
633 .maxlen
= sizeof (int),
635 .proc_handler
= &proc_dointvec
,
638 .ctl_name
= KERN_NMI_WATCHDOG
,
639 .procname
= "nmi_watchdog",
640 .data
= &nmi_watchdog_enabled
,
641 .maxlen
= sizeof (int),
643 .proc_handler
= &proc_nmi_enabled
,
646 #if defined(CONFIG_X86)
648 .ctl_name
= KERN_PANIC_ON_NMI
,
649 .procname
= "panic_on_unrecovered_nmi",
650 .data
= &panic_on_unrecovered_nmi
,
651 .maxlen
= sizeof(int),
653 .proc_handler
= &proc_dointvec
,
656 .ctl_name
= KERN_BOOTLOADER_TYPE
,
657 .procname
= "bootloader_type",
658 .data
= &bootloader_type
,
659 .maxlen
= sizeof (int),
661 .proc_handler
= &proc_dointvec
,
664 #if defined(CONFIG_MMU)
666 .ctl_name
= KERN_RANDOMIZE
,
667 .procname
= "randomize_va_space",
668 .data
= &randomize_va_space
,
669 .maxlen
= sizeof(int),
671 .proc_handler
= &proc_dointvec
,
674 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
676 .ctl_name
= KERN_SPIN_RETRY
,
677 .procname
= "spin_retry",
679 .maxlen
= sizeof (int),
681 .proc_handler
= &proc_dointvec
,
684 #ifdef CONFIG_ACPI_SLEEP
686 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
687 .procname
= "acpi_video_flags",
688 .data
= &acpi_video_flags
,
689 .maxlen
= sizeof (unsigned long),
691 .proc_handler
= &proc_doulongvec_minmax
,
696 .ctl_name
= KERN_IA64_UNALIGNED
,
697 .procname
= "ignore-unaligned-usertrap",
698 .data
= &no_unaligned_warning
,
699 .maxlen
= sizeof (int),
701 .proc_handler
= &proc_dointvec
,
706 .ctl_name
= KERN_COMPAT_LOG
,
707 .procname
= "compat-log",
709 .maxlen
= sizeof (int),
711 .proc_handler
= &proc_dointvec
,
714 #ifdef CONFIG_RT_MUTEXES
716 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
717 .procname
= "max_lock_depth",
718 .data
= &max_lock_depth
,
719 .maxlen
= sizeof(int),
721 .proc_handler
= &proc_dointvec
,
728 /* Constants for minimum and maximum testing in vm_table.
729 We use these as one-element integer vectors. */
731 static int one_hundred
= 100;
734 static ctl_table vm_table
[] = {
736 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
737 .procname
= "overcommit_memory",
738 .data
= &sysctl_overcommit_memory
,
739 .maxlen
= sizeof(sysctl_overcommit_memory
),
741 .proc_handler
= &proc_dointvec
,
744 .ctl_name
= VM_PANIC_ON_OOM
,
745 .procname
= "panic_on_oom",
746 .data
= &sysctl_panic_on_oom
,
747 .maxlen
= sizeof(sysctl_panic_on_oom
),
749 .proc_handler
= &proc_dointvec
,
752 .ctl_name
= VM_OVERCOMMIT_RATIO
,
753 .procname
= "overcommit_ratio",
754 .data
= &sysctl_overcommit_ratio
,
755 .maxlen
= sizeof(sysctl_overcommit_ratio
),
757 .proc_handler
= &proc_dointvec
,
760 .ctl_name
= VM_PAGE_CLUSTER
,
761 .procname
= "page-cluster",
762 .data
= &page_cluster
,
763 .maxlen
= sizeof(int),
765 .proc_handler
= &proc_dointvec
,
768 .ctl_name
= VM_DIRTY_BACKGROUND
,
769 .procname
= "dirty_background_ratio",
770 .data
= &dirty_background_ratio
,
771 .maxlen
= sizeof(dirty_background_ratio
),
773 .proc_handler
= &proc_dointvec_minmax
,
774 .strategy
= &sysctl_intvec
,
776 .extra2
= &one_hundred
,
779 .ctl_name
= VM_DIRTY_RATIO
,
780 .procname
= "dirty_ratio",
781 .data
= &vm_dirty_ratio
,
782 .maxlen
= sizeof(vm_dirty_ratio
),
784 .proc_handler
= &proc_dointvec_minmax
,
785 .strategy
= &sysctl_intvec
,
787 .extra2
= &one_hundred
,
790 .ctl_name
= VM_DIRTY_WB_CS
,
791 .procname
= "dirty_writeback_centisecs",
792 .data
= &dirty_writeback_interval
,
793 .maxlen
= sizeof(dirty_writeback_interval
),
795 .proc_handler
= &dirty_writeback_centisecs_handler
,
798 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
799 .procname
= "dirty_expire_centisecs",
800 .data
= &dirty_expire_interval
,
801 .maxlen
= sizeof(dirty_expire_interval
),
803 .proc_handler
= &proc_dointvec_userhz_jiffies
,
806 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
807 .procname
= "nr_pdflush_threads",
808 .data
= &nr_pdflush_threads
,
809 .maxlen
= sizeof nr_pdflush_threads
,
810 .mode
= 0444 /* read-only*/,
811 .proc_handler
= &proc_dointvec
,
814 .ctl_name
= VM_SWAPPINESS
,
815 .procname
= "swappiness",
816 .data
= &vm_swappiness
,
817 .maxlen
= sizeof(vm_swappiness
),
819 .proc_handler
= &proc_dointvec_minmax
,
820 .strategy
= &sysctl_intvec
,
822 .extra2
= &one_hundred
,
824 #ifdef CONFIG_HUGETLB_PAGE
826 .ctl_name
= VM_HUGETLB_PAGES
,
827 .procname
= "nr_hugepages",
828 .data
= &max_huge_pages
,
829 .maxlen
= sizeof(unsigned long),
831 .proc_handler
= &hugetlb_sysctl_handler
,
832 .extra1
= (void *)&hugetlb_zero
,
833 .extra2
= (void *)&hugetlb_infinity
,
836 .ctl_name
= VM_HUGETLB_GROUP
,
837 .procname
= "hugetlb_shm_group",
838 .data
= &sysctl_hugetlb_shm_group
,
839 .maxlen
= sizeof(gid_t
),
841 .proc_handler
= &proc_dointvec
,
845 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
846 .procname
= "lowmem_reserve_ratio",
847 .data
= &sysctl_lowmem_reserve_ratio
,
848 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
850 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
851 .strategy
= &sysctl_intvec
,
854 .ctl_name
= VM_DROP_PAGECACHE
,
855 .procname
= "drop_caches",
856 .data
= &sysctl_drop_caches
,
857 .maxlen
= sizeof(int),
859 .proc_handler
= drop_caches_sysctl_handler
,
860 .strategy
= &sysctl_intvec
,
863 .ctl_name
= VM_MIN_FREE_KBYTES
,
864 .procname
= "min_free_kbytes",
865 .data
= &min_free_kbytes
,
866 .maxlen
= sizeof(min_free_kbytes
),
868 .proc_handler
= &min_free_kbytes_sysctl_handler
,
869 .strategy
= &sysctl_intvec
,
873 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
874 .procname
= "percpu_pagelist_fraction",
875 .data
= &percpu_pagelist_fraction
,
876 .maxlen
= sizeof(percpu_pagelist_fraction
),
878 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
879 .strategy
= &sysctl_intvec
,
880 .extra1
= &min_percpu_pagelist_fract
,
884 .ctl_name
= VM_MAX_MAP_COUNT
,
885 .procname
= "max_map_count",
886 .data
= &sysctl_max_map_count
,
887 .maxlen
= sizeof(sysctl_max_map_count
),
889 .proc_handler
= &proc_dointvec
893 .ctl_name
= VM_LAPTOP_MODE
,
894 .procname
= "laptop_mode",
895 .data
= &laptop_mode
,
896 .maxlen
= sizeof(laptop_mode
),
898 .proc_handler
= &proc_dointvec_jiffies
,
899 .strategy
= &sysctl_jiffies
,
902 .ctl_name
= VM_BLOCK_DUMP
,
903 .procname
= "block_dump",
905 .maxlen
= sizeof(block_dump
),
907 .proc_handler
= &proc_dointvec
,
908 .strategy
= &sysctl_intvec
,
912 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
913 .procname
= "vfs_cache_pressure",
914 .data
= &sysctl_vfs_cache_pressure
,
915 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
917 .proc_handler
= &proc_dointvec
,
918 .strategy
= &sysctl_intvec
,
921 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
923 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
924 .procname
= "legacy_va_layout",
925 .data
= &sysctl_legacy_va_layout
,
926 .maxlen
= sizeof(sysctl_legacy_va_layout
),
928 .proc_handler
= &proc_dointvec
,
929 .strategy
= &sysctl_intvec
,
935 .ctl_name
= VM_SWAP_TOKEN_TIMEOUT
,
936 .procname
= "swap_token_timeout",
937 .data
= &swap_token_default_timeout
,
938 .maxlen
= sizeof(swap_token_default_timeout
),
940 .proc_handler
= &proc_dointvec_jiffies
,
941 .strategy
= &sysctl_jiffies
,
946 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
947 .procname
= "zone_reclaim_mode",
948 .data
= &zone_reclaim_mode
,
949 .maxlen
= sizeof(zone_reclaim_mode
),
951 .proc_handler
= &proc_dointvec
,
952 .strategy
= &sysctl_intvec
,
956 .ctl_name
= VM_MIN_UNMAPPED
,
957 .procname
= "min_unmapped_ratio",
958 .data
= &sysctl_min_unmapped_ratio
,
959 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
961 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
962 .strategy
= &sysctl_intvec
,
964 .extra2
= &one_hundred
,
967 .ctl_name
= VM_MIN_SLAB
,
968 .procname
= "min_slab_ratio",
969 .data
= &sysctl_min_slab_ratio
,
970 .maxlen
= sizeof(sysctl_min_slab_ratio
),
972 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
973 .strategy
= &sysctl_intvec
,
975 .extra2
= &one_hundred
,
980 .ctl_name
= VM_VDSO_ENABLED
,
981 .procname
= "vdso_enabled",
982 .data
= &vdso_enabled
,
983 .maxlen
= sizeof(vdso_enabled
),
985 .proc_handler
= &proc_dointvec
,
986 .strategy
= &sysctl_intvec
,
993 static ctl_table fs_table
[] = {
995 .ctl_name
= FS_NRINODE
,
996 .procname
= "inode-nr",
997 .data
= &inodes_stat
,
998 .maxlen
= 2*sizeof(int),
1000 .proc_handler
= &proc_dointvec
,
1003 .ctl_name
= FS_STATINODE
,
1004 .procname
= "inode-state",
1005 .data
= &inodes_stat
,
1006 .maxlen
= 7*sizeof(int),
1008 .proc_handler
= &proc_dointvec
,
1011 .ctl_name
= FS_NRFILE
,
1012 .procname
= "file-nr",
1013 .data
= &files_stat
,
1014 .maxlen
= 3*sizeof(int),
1016 .proc_handler
= &proc_nr_files
,
1019 .ctl_name
= FS_MAXFILE
,
1020 .procname
= "file-max",
1021 .data
= &files_stat
.max_files
,
1022 .maxlen
= sizeof(int),
1024 .proc_handler
= &proc_dointvec
,
1027 .ctl_name
= FS_DENTRY
,
1028 .procname
= "dentry-state",
1029 .data
= &dentry_stat
,
1030 .maxlen
= 6*sizeof(int),
1032 .proc_handler
= &proc_dointvec
,
1035 .ctl_name
= FS_OVERFLOWUID
,
1036 .procname
= "overflowuid",
1037 .data
= &fs_overflowuid
,
1038 .maxlen
= sizeof(int),
1040 .proc_handler
= &proc_dointvec_minmax
,
1041 .strategy
= &sysctl_intvec
,
1042 .extra1
= &minolduid
,
1043 .extra2
= &maxolduid
,
1046 .ctl_name
= FS_OVERFLOWGID
,
1047 .procname
= "overflowgid",
1048 .data
= &fs_overflowgid
,
1049 .maxlen
= sizeof(int),
1051 .proc_handler
= &proc_dointvec_minmax
,
1052 .strategy
= &sysctl_intvec
,
1053 .extra1
= &minolduid
,
1054 .extra2
= &maxolduid
,
1057 .ctl_name
= FS_LEASES
,
1058 .procname
= "leases-enable",
1059 .data
= &leases_enable
,
1060 .maxlen
= sizeof(int),
1062 .proc_handler
= &proc_dointvec
,
1064 #ifdef CONFIG_DNOTIFY
1066 .ctl_name
= FS_DIR_NOTIFY
,
1067 .procname
= "dir-notify-enable",
1068 .data
= &dir_notify_enable
,
1069 .maxlen
= sizeof(int),
1071 .proc_handler
= &proc_dointvec
,
1076 .ctl_name
= FS_LEASE_TIME
,
1077 .procname
= "lease-break-time",
1078 .data
= &lease_break_time
,
1079 .maxlen
= sizeof(int),
1081 .proc_handler
= &proc_dointvec
,
1084 .ctl_name
= FS_AIO_NR
,
1085 .procname
= "aio-nr",
1087 .maxlen
= sizeof(aio_nr
),
1089 .proc_handler
= &proc_doulongvec_minmax
,
1092 .ctl_name
= FS_AIO_MAX_NR
,
1093 .procname
= "aio-max-nr",
1094 .data
= &aio_max_nr
,
1095 .maxlen
= sizeof(aio_max_nr
),
1097 .proc_handler
= &proc_doulongvec_minmax
,
1099 #ifdef CONFIG_INOTIFY_USER
1101 .ctl_name
= FS_INOTIFY
,
1102 .procname
= "inotify",
1104 .child
= inotify_table
,
1109 .ctl_name
= KERN_SETUID_DUMPABLE
,
1110 .procname
= "suid_dumpable",
1111 .data
= &suid_dumpable
,
1112 .maxlen
= sizeof(int),
1114 .proc_handler
= &proc_dointvec
,
1119 static ctl_table debug_table
[] = {
1123 static ctl_table dev_table
[] = {
1127 extern void init_irq_proc (void);
1129 static DEFINE_SPINLOCK(sysctl_lock
);
1131 /* called under sysctl_lock */
1132 static int use_table(struct ctl_table_header
*p
)
1134 if (unlikely(p
->unregistering
))
1140 /* called under sysctl_lock */
1141 static void unuse_table(struct ctl_table_header
*p
)
1144 if (unlikely(p
->unregistering
))
1145 complete(p
->unregistering
);
1148 /* called under sysctl_lock, will reacquire if has to wait */
1149 static void start_unregistering(struct ctl_table_header
*p
)
1152 * if p->used is 0, nobody will ever touch that entry again;
1153 * we'll eliminate all paths to it before dropping sysctl_lock
1155 if (unlikely(p
->used
)) {
1156 struct completion wait
;
1157 init_completion(&wait
);
1158 p
->unregistering
= &wait
;
1159 spin_unlock(&sysctl_lock
);
1160 wait_for_completion(&wait
);
1161 spin_lock(&sysctl_lock
);
1164 * do not remove from the list until nobody holds it; walking the
1165 * list in do_sysctl() relies on that.
1167 list_del_init(&p
->ctl_entry
);
1170 void __init
sysctl_init(void)
1172 #ifdef CONFIG_PROC_SYSCTL
1173 register_proc_table(root_table
, proc_sys_root
, &root_table_header
);
1178 #ifdef CONFIG_SYSCTL_SYSCALL
1179 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1180 void __user
*newval
, size_t newlen
)
1182 struct list_head
*tmp
;
1183 int error
= -ENOTDIR
;
1185 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1189 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1192 spin_lock(&sysctl_lock
);
1193 tmp
= &root_table_header
.ctl_entry
;
1195 struct ctl_table_header
*head
=
1196 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1197 void *context
= NULL
;
1199 if (!use_table(head
))
1202 spin_unlock(&sysctl_lock
);
1204 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1205 newval
, newlen
, head
->ctl_table
,
1209 spin_lock(&sysctl_lock
);
1211 if (error
!= -ENOTDIR
)
1213 } while ((tmp
= tmp
->next
) != &root_table_header
.ctl_entry
);
1214 spin_unlock(&sysctl_lock
);
1218 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1220 struct __sysctl_args tmp
;
1223 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1227 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1228 tmp
.newval
, tmp
.newlen
);
1232 #endif /* CONFIG_SYSCTL_SYSCALL */
1235 * ctl_perm does NOT grant the superuser all rights automatically, because
1236 * some sysctl variables are readonly even to root.
1239 static int test_perm(int mode
, int op
)
1243 else if (in_egroup_p(0))
1245 if ((mode
& op
& 0007) == op
)
1250 static inline int ctl_perm(ctl_table
*table
, int op
)
1253 error
= security_sysctl(table
, op
);
1256 return test_perm(table
->mode
, op
);
1259 #ifdef CONFIG_SYSCTL_SYSCALL
1260 static int parse_table(int __user
*name
, int nlen
,
1261 void __user
*oldval
, size_t __user
*oldlenp
,
1262 void __user
*newval
, size_t newlen
,
1263 ctl_table
*table
, void **context
)
1269 if (get_user(n
, name
))
1271 for ( ; table
->ctl_name
; table
++) {
1272 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1275 if (ctl_perm(table
, 001))
1277 if (table
->strategy
) {
1278 error
= table
->strategy(
1281 newval
, newlen
, context
);
1287 table
= table
->child
;
1290 error
= do_sysctl_strategy(table
, name
, nlen
,
1292 newval
, newlen
, context
);
1299 /* Perform the actual read/write of a sysctl table entry. */
1300 int do_sysctl_strategy (ctl_table
*table
,
1301 int __user
*name
, int nlen
,
1302 void __user
*oldval
, size_t __user
*oldlenp
,
1303 void __user
*newval
, size_t newlen
, void **context
)
1312 if (ctl_perm(table
, op
))
1315 if (table
->strategy
) {
1316 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1317 newval
, newlen
, context
);
1324 /* If there is no strategy routine, or if the strategy returns
1325 * zero, proceed with automatic r/w */
1326 if (table
->data
&& table
->maxlen
) {
1327 if (oldval
&& oldlenp
) {
1328 if (get_user(len
, oldlenp
))
1331 if (len
> table
->maxlen
)
1332 len
= table
->maxlen
;
1333 if(copy_to_user(oldval
, table
->data
, len
))
1335 if(put_user(len
, oldlenp
))
1339 if (newval
&& newlen
) {
1341 if (len
> table
->maxlen
)
1342 len
= table
->maxlen
;
1343 if(copy_from_user(table
->data
, newval
, len
))
1349 #endif /* CONFIG_SYSCTL_SYSCALL */
1352 * register_sysctl_table - register a sysctl hierarchy
1353 * @table: the top-level table structure
1354 * @insert_at_head: whether the entry should be inserted in front or at the end
1356 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1357 * array. An entry with a ctl_name of 0 terminates the table.
1359 * The members of the &ctl_table structure are used as follows:
1361 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1362 * must be unique within that level of sysctl
1364 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1365 * enter a sysctl file
1367 * data - a pointer to data for use by proc_handler
1369 * maxlen - the maximum size in bytes of the data
1371 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1373 * child - a pointer to the child sysctl table if this entry is a directory, or
1376 * proc_handler - the text handler routine (described below)
1378 * strategy - the strategy routine (described below)
1380 * de - for internal use by the sysctl routines
1382 * extra1, extra2 - extra pointers usable by the proc handler routines
1384 * Leaf nodes in the sysctl tree will be represented by a single file
1385 * under /proc; non-leaf nodes will be represented by directories.
1387 * sysctl(2) can automatically manage read and write requests through
1388 * the sysctl table. The data and maxlen fields of the ctl_table
1389 * struct enable minimal validation of the values being written to be
1390 * performed, and the mode field allows minimal authentication.
1392 * More sophisticated management can be enabled by the provision of a
1393 * strategy routine with the table entry. This will be called before
1394 * any automatic read or write of the data is performed.
1396 * The strategy routine may return
1398 * < 0 - Error occurred (error is passed to user process)
1400 * 0 - OK - proceed with automatic read or write.
1402 * > 0 - OK - read or write has been done by the strategy routine, so
1403 * return immediately.
1405 * There must be a proc_handler routine for any terminal nodes
1406 * mirrored under /proc/sys (non-terminals are handled by a built-in
1407 * directory handler). Several default handlers are available to
1408 * cover common cases -
1410 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1411 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1412 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1414 * It is the handler's job to read the input buffer from user memory
1415 * and process it. The handler should return 0 on success.
1417 * This routine returns %NULL on a failure to register, and a pointer
1418 * to the table header on success.
1420 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1423 struct ctl_table_header
*tmp
;
1424 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1427 tmp
->ctl_table
= table
;
1428 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1430 tmp
->unregistering
= NULL
;
1431 spin_lock(&sysctl_lock
);
1433 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1435 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1436 spin_unlock(&sysctl_lock
);
1437 #ifdef CONFIG_PROC_SYSCTL
1438 register_proc_table(table
, proc_sys_root
, tmp
);
1444 * unregister_sysctl_table - unregister a sysctl table hierarchy
1445 * @header: the header returned from register_sysctl_table
1447 * Unregisters the sysctl table and all children. proc entries may not
1448 * actually be removed until they are no longer used by anyone.
1450 void unregister_sysctl_table(struct ctl_table_header
* header
)
1453 spin_lock(&sysctl_lock
);
1454 start_unregistering(header
);
1455 #ifdef CONFIG_PROC_SYSCTL
1456 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1458 spin_unlock(&sysctl_lock
);
1462 #else /* !CONFIG_SYSCTL */
1463 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
1469 void unregister_sysctl_table(struct ctl_table_header
* table
)
1473 #endif /* CONFIG_SYSCTL */
1479 #ifdef CONFIG_PROC_SYSCTL
1481 /* Scan the sysctl entries in table and add them all into /proc */
1482 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
, void *set
)
1484 struct proc_dir_entry
*de
;
1488 for (; table
->ctl_name
; table
++) {
1489 /* Can't do anything without a proc name. */
1490 if (!table
->procname
)
1492 /* Maybe we can't do anything with it... */
1493 if (!table
->proc_handler
&& !table
->child
) {
1494 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1499 len
= strlen(table
->procname
);
1503 if (table
->proc_handler
)
1507 for (de
= root
->subdir
; de
; de
= de
->next
) {
1508 if (proc_match(len
, table
->procname
, de
))
1511 /* If the subdir exists already, de is non-NULL */
1515 de
= create_proc_entry(table
->procname
, mode
, root
);
1519 de
->data
= (void *) table
;
1520 if (table
->proc_handler
)
1521 de
->proc_fops
= &proc_sys_file_operations
;
1524 if (de
->mode
& S_IFDIR
)
1525 register_proc_table(table
->child
, de
, set
);
1530 * Unregister a /proc sysctl table and any subdirectories.
1532 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1534 struct proc_dir_entry
*de
;
1535 for (; table
->ctl_name
; table
++) {
1536 if (!(de
= table
->de
))
1538 if (de
->mode
& S_IFDIR
) {
1539 if (!table
->child
) {
1540 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1543 unregister_proc_table(table
->child
, de
);
1545 /* Don't unregister directories which still have entries.. */
1551 * In any case, mark the entry as goner; we'll keep it
1552 * around if it's busy, but we'll know to do nothing with
1553 * its fields. We are under sysctl_lock here.
1557 /* Don't unregister proc entries that are still being used.. */
1558 if (atomic_read(&de
->count
))
1562 remove_proc_entry(table
->procname
, root
);
1566 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1567 size_t count
, loff_t
*ppos
)
1570 struct proc_dir_entry
*de
= PDE(file
->f_dentry
->d_inode
);
1571 struct ctl_table
*table
;
1573 ssize_t error
= -ENOTDIR
;
1575 spin_lock(&sysctl_lock
);
1576 if (de
&& de
->data
&& use_table(de
->set
)) {
1578 * at that point we know that sysctl was not unregistered
1579 * and won't be until we finish
1581 spin_unlock(&sysctl_lock
);
1582 table
= (struct ctl_table
*) de
->data
;
1583 if (!table
|| !table
->proc_handler
)
1586 op
= (write
? 002 : 004);
1587 if (ctl_perm(table
, op
))
1590 /* careful: calling conventions are nasty here */
1592 error
= (*table
->proc_handler
)(table
, write
, file
,
1597 spin_lock(&sysctl_lock
);
1598 unuse_table(de
->set
);
1600 spin_unlock(&sysctl_lock
);
1604 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1606 if (file
->f_mode
& FMODE_WRITE
) {
1608 * sysctl entries that are not writable,
1609 * are _NOT_ writable, capabilities or not.
1611 if (!(inode
->i_mode
& S_IWUSR
))
1618 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1619 size_t count
, loff_t
*ppos
)
1621 return do_rw_proc(0, file
, buf
, count
, ppos
);
1624 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1625 size_t count
, loff_t
*ppos
)
1627 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1631 * proc_dostring - read a string sysctl
1632 * @table: the sysctl table
1633 * @write: %TRUE if this is a write to the sysctl file
1634 * @filp: the file structure
1635 * @buffer: the user buffer
1636 * @lenp: the size of the user buffer
1637 * @ppos: file position
1639 * Reads/writes a string from/to the user buffer. If the kernel
1640 * buffer provided is not large enough to hold the string, the
1641 * string is truncated. The copied string is %NULL-terminated.
1642 * If the string is being read by the user process, it is copied
1643 * and a newline '\n' is added. It is truncated if the buffer is
1646 * Returns 0 on success.
1648 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1649 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1655 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1656 (*ppos
&& !write
)) {
1664 while (len
< *lenp
) {
1665 if (get_user(c
, p
++))
1667 if (c
== 0 || c
== '\n')
1671 if (len
>= table
->maxlen
)
1672 len
= table
->maxlen
-1;
1673 if(copy_from_user(table
->data
, buffer
, len
))
1675 ((char *) table
->data
)[len
] = 0;
1678 len
= strlen(table
->data
);
1679 if (len
> table
->maxlen
)
1680 len
= table
->maxlen
;
1684 if(copy_to_user(buffer
, table
->data
, len
))
1687 if(put_user('\n', ((char __user
*) buffer
) + len
))
1698 * Special case of dostring for the UTS structure. This has locks
1699 * to observe. Should this be in kernel/sys.c ????
1702 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1703 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1708 down_read(&uts_sem
);
1709 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1712 down_write(&uts_sem
);
1713 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1719 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1721 int write
, void *data
)
1724 *valp
= *negp
? -*lvalp
: *lvalp
;
1729 *lvalp
= (unsigned long)-val
;
1732 *lvalp
= (unsigned long)val
;
1738 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1739 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1740 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1741 int write
, void *data
),
1744 #define TMPBUFLEN 21
1745 int *i
, vleft
, first
=1, neg
, val
;
1749 char buf
[TMPBUFLEN
], *p
;
1750 char __user
*s
= buffer
;
1752 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1753 (*ppos
&& !write
)) {
1758 i
= (int *) table
->data
;
1759 vleft
= table
->maxlen
/ sizeof(*i
);
1763 conv
= do_proc_dointvec_conv
;
1765 for (; left
&& vleft
--; i
++, first
=0) {
1780 if (len
> sizeof(buf
) - 1)
1781 len
= sizeof(buf
) - 1;
1782 if (copy_from_user(buf
, s
, len
))
1786 if (*p
== '-' && left
> 1) {
1790 if (*p
< '0' || *p
> '9')
1793 lval
= simple_strtoul(p
, &p
, 0);
1796 if ((len
< left
) && *p
&& !isspace(*p
))
1803 if (conv(&neg
, &lval
, i
, 1, data
))
1810 if (conv(&neg
, &lval
, i
, 0, data
))
1813 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1817 if(copy_to_user(s
, buf
, len
))
1824 if (!write
&& !first
&& left
) {
1825 if(put_user('\n', s
))
1832 if (get_user(c
, s
++))
1848 * proc_dointvec - read a vector of integers
1849 * @table: the sysctl table
1850 * @write: %TRUE if this is a write to the sysctl file
1851 * @filp: the file structure
1852 * @buffer: the user buffer
1853 * @lenp: the size of the user buffer
1854 * @ppos: file position
1856 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1857 * values from/to the user buffer, treated as an ASCII string.
1859 * Returns 0 on success.
1861 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1862 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1864 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1874 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1876 int write
, void *data
)
1878 int op
= *(int *)data
;
1880 int val
= *negp
? -*lvalp
: *lvalp
;
1882 case OP_SET
: *valp
= val
; break;
1883 case OP_AND
: *valp
&= val
; break;
1884 case OP_OR
: *valp
|= val
; break;
1885 case OP_MAX
: if(*valp
< val
)
1888 case OP_MIN
: if(*valp
> val
)
1896 *lvalp
= (unsigned long)-val
;
1899 *lvalp
= (unsigned long)val
;
1906 * init may raise the set.
1909 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1910 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1914 if (!capable(CAP_SYS_MODULE
)) {
1918 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1919 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1920 do_proc_dointvec_bset_conv
,&op
);
1923 struct do_proc_dointvec_minmax_conv_param
{
1928 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1930 int write
, void *data
)
1932 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1934 int val
= *negp
? -*lvalp
: *lvalp
;
1935 if ((param
->min
&& *param
->min
> val
) ||
1936 (param
->max
&& *param
->max
< val
))
1943 *lvalp
= (unsigned long)-val
;
1946 *lvalp
= (unsigned long)val
;
1953 * proc_dointvec_minmax - read a vector of integers with min/max values
1954 * @table: the sysctl table
1955 * @write: %TRUE if this is a write to the sysctl file
1956 * @filp: the file structure
1957 * @buffer: the user buffer
1958 * @lenp: the size of the user buffer
1959 * @ppos: file position
1961 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1962 * values from/to the user buffer, treated as an ASCII string.
1964 * This routine will ensure the values are within the range specified by
1965 * table->extra1 (min) and table->extra2 (max).
1967 * Returns 0 on success.
1969 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1970 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1972 struct do_proc_dointvec_minmax_conv_param param
= {
1973 .min
= (int *) table
->extra1
,
1974 .max
= (int *) table
->extra2
,
1976 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1977 do_proc_dointvec_minmax_conv
, ¶m
);
1980 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1982 void __user
*buffer
,
1983 size_t *lenp
, loff_t
*ppos
,
1984 unsigned long convmul
,
1985 unsigned long convdiv
)
1987 #define TMPBUFLEN 21
1988 unsigned long *i
, *min
, *max
, val
;
1989 int vleft
, first
=1, neg
;
1991 char buf
[TMPBUFLEN
], *p
;
1992 char __user
*s
= buffer
;
1994 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1995 (*ppos
&& !write
)) {
2000 i
= (unsigned long *) table
->data
;
2001 min
= (unsigned long *) table
->extra1
;
2002 max
= (unsigned long *) table
->extra2
;
2003 vleft
= table
->maxlen
/ sizeof(unsigned long);
2006 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2021 if (len
> TMPBUFLEN
-1)
2023 if (copy_from_user(buf
, s
, len
))
2027 if (*p
== '-' && left
> 1) {
2031 if (*p
< '0' || *p
> '9')
2033 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2035 if ((len
< left
) && *p
&& !isspace(*p
))
2044 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2051 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2055 if(copy_to_user(s
, buf
, len
))
2062 if (!write
&& !first
&& left
) {
2063 if(put_user('\n', s
))
2070 if (get_user(c
, s
++))
2086 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2087 * @table: the sysctl table
2088 * @write: %TRUE if this is a write to the sysctl file
2089 * @filp: the file structure
2090 * @buffer: the user buffer
2091 * @lenp: the size of the user buffer
2092 * @ppos: file position
2094 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2095 * values from/to the user buffer, treated as an ASCII string.
2097 * This routine will ensure the values are within the range specified by
2098 * table->extra1 (min) and table->extra2 (max).
2100 * Returns 0 on success.
2102 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2103 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2105 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2109 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2110 * @table: the sysctl table
2111 * @write: %TRUE if this is a write to the sysctl file
2112 * @filp: the file structure
2113 * @buffer: the user buffer
2114 * @lenp: the size of the user buffer
2115 * @ppos: file position
2117 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2118 * values from/to the user buffer, treated as an ASCII string. The values
2119 * are treated as milliseconds, and converted to jiffies when they are stored.
2121 * This routine will ensure the values are within the range specified by
2122 * table->extra1 (min) and table->extra2 (max).
2124 * Returns 0 on success.
2126 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2128 void __user
*buffer
,
2129 size_t *lenp
, loff_t
*ppos
)
2131 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2132 lenp
, ppos
, HZ
, 1000l);
2136 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2138 int write
, void *data
)
2141 if (*lvalp
> LONG_MAX
/ HZ
)
2143 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2149 lval
= (unsigned long)-val
;
2152 lval
= (unsigned long)val
;
2159 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2161 int write
, void *data
)
2164 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2166 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2172 lval
= (unsigned long)-val
;
2175 lval
= (unsigned long)val
;
2177 *lvalp
= jiffies_to_clock_t(lval
);
2182 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2184 int write
, void *data
)
2187 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2193 lval
= (unsigned long)-val
;
2196 lval
= (unsigned long)val
;
2198 *lvalp
= jiffies_to_msecs(lval
);
2204 * proc_dointvec_jiffies - read a vector of integers as seconds
2205 * @table: the sysctl table
2206 * @write: %TRUE if this is a write to the sysctl file
2207 * @filp: the file structure
2208 * @buffer: the user buffer
2209 * @lenp: the size of the user buffer
2210 * @ppos: file position
2212 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2213 * values from/to the user buffer, treated as an ASCII string.
2214 * The values read are assumed to be in seconds, and are converted into
2217 * Returns 0 on success.
2219 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2220 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2222 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2223 do_proc_dointvec_jiffies_conv
,NULL
);
2227 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2228 * @table: the sysctl table
2229 * @write: %TRUE if this is a write to the sysctl file
2230 * @filp: the file structure
2231 * @buffer: the user buffer
2232 * @lenp: the size of the user buffer
2233 * @ppos: pointer to the file position
2235 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2236 * values from/to the user buffer, treated as an ASCII string.
2237 * The values read are assumed to be in 1/USER_HZ seconds, and
2238 * are converted into jiffies.
2240 * Returns 0 on success.
2242 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2243 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2245 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2246 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2250 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2251 * @table: the sysctl table
2252 * @write: %TRUE if this is a write to the sysctl file
2253 * @filp: the file structure
2254 * @buffer: the user buffer
2255 * @lenp: the size of the user buffer
2256 * @ppos: file position
2257 * @ppos: the current position in the file
2259 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2260 * values from/to the user buffer, treated as an ASCII string.
2261 * The values read are assumed to be in 1/1000 seconds, and
2262 * are converted into jiffies.
2264 * Returns 0 on success.
2266 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2267 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2269 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2270 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2273 #else /* CONFIG_PROC_FS */
2275 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2276 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2281 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2282 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2287 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2288 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2293 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2294 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2299 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2300 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2305 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2306 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2311 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2312 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2317 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2318 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2323 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2324 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2329 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2331 void __user
*buffer
,
2332 size_t *lenp
, loff_t
*ppos
)
2338 #endif /* CONFIG_PROC_FS */
2341 #ifdef CONFIG_SYSCTL_SYSCALL
2343 * General sysctl support routines
2346 /* The generic string strategy routine: */
2347 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2348 void __user
*oldval
, size_t __user
*oldlenp
,
2349 void __user
*newval
, size_t newlen
, void **context
)
2351 if (!table
->data
|| !table
->maxlen
)
2354 if (oldval
&& oldlenp
) {
2356 if (get_user(bufsize
, oldlenp
))
2359 size_t len
= strlen(table
->data
), copied
;
2361 /* This shouldn't trigger for a well-formed sysctl */
2362 if (len
> table
->maxlen
)
2363 len
= table
->maxlen
;
2365 /* Copy up to a max of bufsize-1 bytes of the string */
2366 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2368 if (copy_to_user(oldval
, table
->data
, copied
) ||
2369 put_user(0, (char __user
*)(oldval
+ copied
)))
2371 if (put_user(len
, oldlenp
))
2375 if (newval
&& newlen
) {
2376 size_t len
= newlen
;
2377 if (len
> table
->maxlen
)
2378 len
= table
->maxlen
;
2379 if(copy_from_user(table
->data
, newval
, len
))
2381 if (len
== table
->maxlen
)
2383 ((char *) table
->data
)[len
] = 0;
2389 * This function makes sure that all of the integers in the vector
2390 * are between the minimum and maximum values given in the arrays
2391 * table->extra1 and table->extra2, respectively.
2393 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2394 void __user
*oldval
, size_t __user
*oldlenp
,
2395 void __user
*newval
, size_t newlen
, void **context
)
2398 if (newval
&& newlen
) {
2399 int __user
*vec
= (int __user
*) newval
;
2400 int *min
= (int *) table
->extra1
;
2401 int *max
= (int *) table
->extra2
;
2405 if (newlen
% sizeof(int) != 0)
2408 if (!table
->extra1
&& !table
->extra2
)
2411 if (newlen
> table
->maxlen
)
2412 newlen
= table
->maxlen
;
2413 length
= newlen
/ sizeof(int);
2415 for (i
= 0; i
< length
; i
++) {
2417 if (get_user(value
, vec
+ i
))
2419 if (min
&& value
< min
[i
])
2421 if (max
&& value
> max
[i
])
2428 /* Strategy function to convert jiffies to seconds */
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 if (get_user(olen
, oldlenp
))
2438 if (olen
!=sizeof(int))
2441 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2442 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2445 if (newval
&& newlen
) {
2447 if (newlen
!= sizeof(int))
2449 if (get_user(new, (int __user
*)newval
))
2451 *(int *)(table
->data
) = new*HZ
;
2456 /* Strategy function to convert jiffies to seconds */
2457 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2458 void __user
*oldval
, size_t __user
*oldlenp
,
2459 void __user
*newval
, size_t newlen
, void **context
)
2464 if (get_user(olen
, oldlenp
))
2466 if (olen
!=sizeof(int))
2469 if (put_user(jiffies_to_msecs(*(int *)(table
->data
)), (int __user
*)oldval
) ||
2470 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2473 if (newval
&& newlen
) {
2475 if (newlen
!= sizeof(int))
2477 if (get_user(new, (int __user
*)newval
))
2479 *(int *)(table
->data
) = msecs_to_jiffies(new);
2484 #else /* CONFIG_SYSCTL_SYSCALL */
2487 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2489 static int msg_count
;
2491 if (msg_count
< 5) {
2494 "warning: process `%s' used the removed sysctl "
2495 "system call\n", current
->comm
);
2500 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2501 void __user
*oldval
, size_t __user
*oldlenp
,
2502 void __user
*newval
, size_t newlen
, void **context
)
2507 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2508 void __user
*oldval
, size_t __user
*oldlenp
,
2509 void __user
*newval
, size_t newlen
, void **context
)
2514 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2515 void __user
*oldval
, size_t __user
*oldlenp
,
2516 void __user
*newval
, size_t newlen
, void **context
)
2521 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2522 void __user
*oldval
, size_t __user
*oldlenp
,
2523 void __user
*newval
, size_t newlen
, void **context
)
2528 #endif /* CONFIG_SYSCTL_SYSCALL */
2531 * No sense putting this after each symbol definition, twice,
2532 * exception granted :-)
2534 EXPORT_SYMBOL(proc_dointvec
);
2535 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2536 EXPORT_SYMBOL(proc_dointvec_minmax
);
2537 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2538 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2539 EXPORT_SYMBOL(proc_dostring
);
2540 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2541 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2542 EXPORT_SYMBOL(register_sysctl_table
);
2543 EXPORT_SYMBOL(sysctl_intvec
);
2544 EXPORT_SYMBOL(sysctl_jiffies
);
2545 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2546 EXPORT_SYMBOL(sysctl_string
);
2547 EXPORT_SYMBOL(unregister_sysctl_table
);