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 extern int proc_unknown_nmi_panic(ctl_table
*, int, struct file
*,
80 void __user
*, size_t *, loff_t
*);
83 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
84 static int maxolduid
= 65535;
86 static int min_percpu_pagelist_fract
= 8;
88 static int ngroups_max
= NGROUPS_MAX
;
91 extern char modprobe_path
[];
93 #ifdef CONFIG_CHR_DEV_SG
94 extern int sg_big_buff
;
97 extern size_t shm_ctlmax
;
98 extern size_t shm_ctlall
;
99 extern int shm_ctlmni
;
100 extern int msg_ctlmax
;
101 extern int msg_ctlmnb
;
102 extern int msg_ctlmni
;
103 extern int sem_ctls
[];
107 extern char reboot_command
[];
108 extern int stop_a_enabled
;
109 extern int scons_pwroff
;
113 extern int pwrsw_enabled
;
114 extern int unaligned_enabled
;
118 #ifdef CONFIG_MATHEMU
119 extern int sysctl_ieee_emulation_warnings
;
121 extern int sysctl_userprocess_debug
;
122 extern int spin_retry
;
125 extern int sysctl_hz_timer
;
127 #ifdef CONFIG_BSD_PROCESS_ACCT
128 extern int acct_parm
[];
132 extern int no_unaligned_warning
;
135 #ifdef CONFIG_RT_MUTEXES
136 extern int max_lock_depth
;
139 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
140 ctl_table
*, void **);
141 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
142 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
144 static ctl_table root_table
[];
145 static struct ctl_table_header root_table_header
=
146 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
148 static ctl_table kern_table
[];
149 static ctl_table vm_table
[];
150 static ctl_table fs_table
[];
151 static ctl_table debug_table
[];
152 static ctl_table dev_table
[];
153 extern ctl_table random_table
[];
154 #ifdef CONFIG_UNIX98_PTYS
155 extern ctl_table pty_table
[];
157 #ifdef CONFIG_INOTIFY_USER
158 extern ctl_table inotify_table
[];
161 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
162 int sysctl_legacy_va_layout
;
165 /* /proc declarations: */
167 #ifdef CONFIG_PROC_FS
169 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
170 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
171 static int proc_opensys(struct inode
*, struct file
*);
173 struct file_operations proc_sys_file_operations
= {
174 .open
= proc_opensys
,
175 .read
= proc_readsys
,
176 .write
= proc_writesys
,
179 extern struct proc_dir_entry
*proc_sys_root
;
181 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*, void *);
182 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
185 /* The default sysctl tables: */
187 static ctl_table root_table
[] = {
189 .ctl_name
= CTL_KERN
,
190 .procname
= "kernel",
215 .ctl_name
= CTL_DEBUG
,
218 .child
= debug_table
,
230 static ctl_table kern_table
[] = {
232 .ctl_name
= KERN_OSTYPE
,
233 .procname
= "ostype",
234 .data
= system_utsname
.sysname
,
235 .maxlen
= sizeof(system_utsname
.sysname
),
237 .proc_handler
= &proc_doutsstring
,
238 .strategy
= &sysctl_string
,
241 .ctl_name
= KERN_OSRELEASE
,
242 .procname
= "osrelease",
243 .data
= system_utsname
.release
,
244 .maxlen
= sizeof(system_utsname
.release
),
246 .proc_handler
= &proc_doutsstring
,
247 .strategy
= &sysctl_string
,
250 .ctl_name
= KERN_VERSION
,
251 .procname
= "version",
252 .data
= system_utsname
.version
,
253 .maxlen
= sizeof(system_utsname
.version
),
255 .proc_handler
= &proc_doutsstring
,
256 .strategy
= &sysctl_string
,
259 .ctl_name
= KERN_NODENAME
,
260 .procname
= "hostname",
261 .data
= system_utsname
.nodename
,
262 .maxlen
= sizeof(system_utsname
.nodename
),
264 .proc_handler
= &proc_doutsstring
,
265 .strategy
= &sysctl_string
,
268 .ctl_name
= KERN_DOMAINNAME
,
269 .procname
= "domainname",
270 .data
= system_utsname
.domainname
,
271 .maxlen
= sizeof(system_utsname
.domainname
),
273 .proc_handler
= &proc_doutsstring
,
274 .strategy
= &sysctl_string
,
277 .ctl_name
= KERN_PANIC
,
279 .data
= &panic_timeout
,
280 .maxlen
= sizeof(int),
282 .proc_handler
= &proc_dointvec
,
285 .ctl_name
= KERN_CORE_USES_PID
,
286 .procname
= "core_uses_pid",
287 .data
= &core_uses_pid
,
288 .maxlen
= sizeof(int),
290 .proc_handler
= &proc_dointvec
,
293 .ctl_name
= KERN_CORE_PATTERN
,
294 .procname
= "core_pattern",
295 .data
= core_pattern
,
298 .proc_handler
= &proc_dostring
,
299 .strategy
= &sysctl_string
,
302 .ctl_name
= KERN_TAINTED
,
303 .procname
= "tainted",
305 .maxlen
= sizeof(int),
307 .proc_handler
= &proc_dointvec
,
310 .ctl_name
= KERN_CAP_BSET
,
311 .procname
= "cap-bound",
313 .maxlen
= sizeof(kernel_cap_t
),
315 .proc_handler
= &proc_dointvec_bset
,
317 #ifdef CONFIG_BLK_DEV_INITRD
319 .ctl_name
= KERN_REALROOTDEV
,
320 .procname
= "real-root-dev",
321 .data
= &real_root_dev
,
322 .maxlen
= sizeof(int),
324 .proc_handler
= &proc_dointvec
,
329 .ctl_name
= KERN_SPARC_REBOOT
,
330 .procname
= "reboot-cmd",
331 .data
= reboot_command
,
334 .proc_handler
= &proc_dostring
,
335 .strategy
= &sysctl_string
,
338 .ctl_name
= KERN_SPARC_STOP_A
,
339 .procname
= "stop-a",
340 .data
= &stop_a_enabled
,
341 .maxlen
= sizeof (int),
343 .proc_handler
= &proc_dointvec
,
346 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
347 .procname
= "scons-poweroff",
348 .data
= &scons_pwroff
,
349 .maxlen
= sizeof (int),
351 .proc_handler
= &proc_dointvec
,
356 .ctl_name
= KERN_HPPA_PWRSW
,
357 .procname
= "soft-power",
358 .data
= &pwrsw_enabled
,
359 .maxlen
= sizeof (int),
361 .proc_handler
= &proc_dointvec
,
364 .ctl_name
= KERN_HPPA_UNALIGNED
,
365 .procname
= "unaligned-trap",
366 .data
= &unaligned_enabled
,
367 .maxlen
= sizeof (int),
369 .proc_handler
= &proc_dointvec
,
373 .ctl_name
= KERN_CTLALTDEL
,
374 .procname
= "ctrl-alt-del",
376 .maxlen
= sizeof(int),
378 .proc_handler
= &proc_dointvec
,
381 .ctl_name
= KERN_PRINTK
,
382 .procname
= "printk",
383 .data
= &console_loglevel
,
384 .maxlen
= 4*sizeof(int),
386 .proc_handler
= &proc_dointvec
,
390 .ctl_name
= KERN_MODPROBE
,
391 .procname
= "modprobe",
392 .data
= &modprobe_path
,
393 .maxlen
= KMOD_PATH_LEN
,
395 .proc_handler
= &proc_dostring
,
396 .strategy
= &sysctl_string
,
399 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
401 .ctl_name
= KERN_HOTPLUG
,
402 .procname
= "hotplug",
403 .data
= &uevent_helper
,
404 .maxlen
= UEVENT_HELPER_PATH_LEN
,
406 .proc_handler
= &proc_dostring
,
407 .strategy
= &sysctl_string
,
410 #ifdef CONFIG_CHR_DEV_SG
412 .ctl_name
= KERN_SG_BIG_BUFF
,
413 .procname
= "sg-big-buff",
414 .data
= &sg_big_buff
,
415 .maxlen
= sizeof (int),
417 .proc_handler
= &proc_dointvec
,
420 #ifdef CONFIG_BSD_PROCESS_ACCT
422 .ctl_name
= KERN_ACCT
,
425 .maxlen
= 3*sizeof(int),
427 .proc_handler
= &proc_dointvec
,
430 #ifdef CONFIG_SYSVIPC
432 .ctl_name
= KERN_SHMMAX
,
433 .procname
= "shmmax",
435 .maxlen
= sizeof (size_t),
437 .proc_handler
= &proc_doulongvec_minmax
,
440 .ctl_name
= KERN_SHMALL
,
441 .procname
= "shmall",
443 .maxlen
= sizeof (size_t),
445 .proc_handler
= &proc_doulongvec_minmax
,
448 .ctl_name
= KERN_SHMMNI
,
449 .procname
= "shmmni",
451 .maxlen
= sizeof (int),
453 .proc_handler
= &proc_dointvec
,
456 .ctl_name
= KERN_MSGMAX
,
457 .procname
= "msgmax",
459 .maxlen
= sizeof (int),
461 .proc_handler
= &proc_dointvec
,
464 .ctl_name
= KERN_MSGMNI
,
465 .procname
= "msgmni",
467 .maxlen
= sizeof (int),
469 .proc_handler
= &proc_dointvec
,
472 .ctl_name
= KERN_MSGMNB
,
473 .procname
= "msgmnb",
475 .maxlen
= sizeof (int),
477 .proc_handler
= &proc_dointvec
,
480 .ctl_name
= KERN_SEM
,
483 .maxlen
= 4*sizeof (int),
485 .proc_handler
= &proc_dointvec
,
488 #ifdef CONFIG_MAGIC_SYSRQ
490 .ctl_name
= KERN_SYSRQ
,
492 .data
= &sysrq_enabled
,
493 .maxlen
= sizeof (int),
495 .proc_handler
= &proc_dointvec
,
499 .ctl_name
= KERN_CADPID
,
500 .procname
= "cad_pid",
502 .maxlen
= sizeof (int),
504 .proc_handler
= &proc_dointvec
,
507 .ctl_name
= KERN_MAX_THREADS
,
508 .procname
= "threads-max",
509 .data
= &max_threads
,
510 .maxlen
= sizeof(int),
512 .proc_handler
= &proc_dointvec
,
515 .ctl_name
= KERN_RANDOM
,
516 .procname
= "random",
518 .child
= random_table
,
520 #ifdef CONFIG_UNIX98_PTYS
522 .ctl_name
= KERN_PTY
,
529 .ctl_name
= KERN_OVERFLOWUID
,
530 .procname
= "overflowuid",
531 .data
= &overflowuid
,
532 .maxlen
= sizeof(int),
534 .proc_handler
= &proc_dointvec_minmax
,
535 .strategy
= &sysctl_intvec
,
536 .extra1
= &minolduid
,
537 .extra2
= &maxolduid
,
540 .ctl_name
= KERN_OVERFLOWGID
,
541 .procname
= "overflowgid",
542 .data
= &overflowgid
,
543 .maxlen
= sizeof(int),
545 .proc_handler
= &proc_dointvec_minmax
,
546 .strategy
= &sysctl_intvec
,
547 .extra1
= &minolduid
,
548 .extra2
= &maxolduid
,
551 #ifdef CONFIG_MATHEMU
553 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
554 .procname
= "ieee_emulation_warnings",
555 .data
= &sysctl_ieee_emulation_warnings
,
556 .maxlen
= sizeof(int),
558 .proc_handler
= &proc_dointvec
,
561 #ifdef CONFIG_NO_IDLE_HZ
563 .ctl_name
= KERN_HZ_TIMER
,
564 .procname
= "hz_timer",
565 .data
= &sysctl_hz_timer
,
566 .maxlen
= sizeof(int),
568 .proc_handler
= &proc_dointvec
,
572 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
573 .procname
= "userprocess_debug",
574 .data
= &sysctl_userprocess_debug
,
575 .maxlen
= sizeof(int),
577 .proc_handler
= &proc_dointvec
,
581 .ctl_name
= KERN_PIDMAX
,
582 .procname
= "pid_max",
584 .maxlen
= sizeof (int),
586 .proc_handler
= &proc_dointvec_minmax
,
587 .strategy
= sysctl_intvec
,
588 .extra1
= &pid_max_min
,
589 .extra2
= &pid_max_max
,
592 .ctl_name
= KERN_PANIC_ON_OOPS
,
593 .procname
= "panic_on_oops",
594 .data
= &panic_on_oops
,
595 .maxlen
= sizeof(int),
597 .proc_handler
= &proc_dointvec
,
600 .ctl_name
= KERN_PRINTK_RATELIMIT
,
601 .procname
= "printk_ratelimit",
602 .data
= &printk_ratelimit_jiffies
,
603 .maxlen
= sizeof(int),
605 .proc_handler
= &proc_dointvec_jiffies
,
606 .strategy
= &sysctl_jiffies
,
609 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
610 .procname
= "printk_ratelimit_burst",
611 .data
= &printk_ratelimit_burst
,
612 .maxlen
= sizeof(int),
614 .proc_handler
= &proc_dointvec
,
617 .ctl_name
= KERN_NGROUPS_MAX
,
618 .procname
= "ngroups_max",
619 .data
= &ngroups_max
,
620 .maxlen
= sizeof (int),
622 .proc_handler
= &proc_dointvec
,
624 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
626 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
627 .procname
= "unknown_nmi_panic",
628 .data
= &unknown_nmi_panic
,
629 .maxlen
= sizeof (int),
631 .proc_handler
= &proc_unknown_nmi_panic
,
634 #if defined(CONFIG_X86)
636 .ctl_name
= KERN_BOOTLOADER_TYPE
,
637 .procname
= "bootloader_type",
638 .data
= &bootloader_type
,
639 .maxlen
= sizeof (int),
641 .proc_handler
= &proc_dointvec
,
644 #if defined(CONFIG_MMU)
646 .ctl_name
= KERN_RANDOMIZE
,
647 .procname
= "randomize_va_space",
648 .data
= &randomize_va_space
,
649 .maxlen
= sizeof(int),
651 .proc_handler
= &proc_dointvec
,
654 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
656 .ctl_name
= KERN_SPIN_RETRY
,
657 .procname
= "spin_retry",
659 .maxlen
= sizeof (int),
661 .proc_handler
= &proc_dointvec
,
664 #ifdef CONFIG_ACPI_SLEEP
666 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
667 .procname
= "acpi_video_flags",
668 .data
= &acpi_video_flags
,
669 .maxlen
= sizeof (unsigned long),
671 .proc_handler
= &proc_doulongvec_minmax
,
676 .ctl_name
= KERN_IA64_UNALIGNED
,
677 .procname
= "ignore-unaligned-usertrap",
678 .data
= &no_unaligned_warning
,
679 .maxlen
= sizeof (int),
681 .proc_handler
= &proc_dointvec
,
686 .ctl_name
= KERN_COMPAT_LOG
,
687 .procname
= "compat-log",
689 .maxlen
= sizeof (int),
691 .proc_handler
= &proc_dointvec
,
694 #ifdef CONFIG_RT_MUTEXES
696 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
697 .procname
= "max_lock_depth",
698 .data
= &max_lock_depth
,
699 .maxlen
= sizeof(int),
701 .proc_handler
= &proc_dointvec
,
708 /* Constants for minimum and maximum testing in vm_table.
709 We use these as one-element integer vectors. */
711 static int one_hundred
= 100;
714 static ctl_table vm_table
[] = {
716 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
717 .procname
= "overcommit_memory",
718 .data
= &sysctl_overcommit_memory
,
719 .maxlen
= sizeof(sysctl_overcommit_memory
),
721 .proc_handler
= &proc_dointvec
,
724 .ctl_name
= VM_PANIC_ON_OOM
,
725 .procname
= "panic_on_oom",
726 .data
= &sysctl_panic_on_oom
,
727 .maxlen
= sizeof(sysctl_panic_on_oom
),
729 .proc_handler
= &proc_dointvec
,
732 .ctl_name
= VM_OVERCOMMIT_RATIO
,
733 .procname
= "overcommit_ratio",
734 .data
= &sysctl_overcommit_ratio
,
735 .maxlen
= sizeof(sysctl_overcommit_ratio
),
737 .proc_handler
= &proc_dointvec
,
740 .ctl_name
= VM_PAGE_CLUSTER
,
741 .procname
= "page-cluster",
742 .data
= &page_cluster
,
743 .maxlen
= sizeof(int),
745 .proc_handler
= &proc_dointvec
,
748 .ctl_name
= VM_DIRTY_BACKGROUND
,
749 .procname
= "dirty_background_ratio",
750 .data
= &dirty_background_ratio
,
751 .maxlen
= sizeof(dirty_background_ratio
),
753 .proc_handler
= &proc_dointvec_minmax
,
754 .strategy
= &sysctl_intvec
,
756 .extra2
= &one_hundred
,
759 .ctl_name
= VM_DIRTY_RATIO
,
760 .procname
= "dirty_ratio",
761 .data
= &vm_dirty_ratio
,
762 .maxlen
= sizeof(vm_dirty_ratio
),
764 .proc_handler
= &proc_dointvec_minmax
,
765 .strategy
= &sysctl_intvec
,
767 .extra2
= &one_hundred
,
770 .ctl_name
= VM_DIRTY_WB_CS
,
771 .procname
= "dirty_writeback_centisecs",
772 .data
= &dirty_writeback_interval
,
773 .maxlen
= sizeof(dirty_writeback_interval
),
775 .proc_handler
= &dirty_writeback_centisecs_handler
,
778 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
779 .procname
= "dirty_expire_centisecs",
780 .data
= &dirty_expire_interval
,
781 .maxlen
= sizeof(dirty_expire_interval
),
783 .proc_handler
= &proc_dointvec_userhz_jiffies
,
786 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
787 .procname
= "nr_pdflush_threads",
788 .data
= &nr_pdflush_threads
,
789 .maxlen
= sizeof nr_pdflush_threads
,
790 .mode
= 0444 /* read-only*/,
791 .proc_handler
= &proc_dointvec
,
794 .ctl_name
= VM_SWAPPINESS
,
795 .procname
= "swappiness",
796 .data
= &vm_swappiness
,
797 .maxlen
= sizeof(vm_swappiness
),
799 .proc_handler
= &proc_dointvec_minmax
,
800 .strategy
= &sysctl_intvec
,
802 .extra2
= &one_hundred
,
804 #ifdef CONFIG_HUGETLB_PAGE
806 .ctl_name
= VM_HUGETLB_PAGES
,
807 .procname
= "nr_hugepages",
808 .data
= &max_huge_pages
,
809 .maxlen
= sizeof(unsigned long),
811 .proc_handler
= &hugetlb_sysctl_handler
,
812 .extra1
= (void *)&hugetlb_zero
,
813 .extra2
= (void *)&hugetlb_infinity
,
816 .ctl_name
= VM_HUGETLB_GROUP
,
817 .procname
= "hugetlb_shm_group",
818 .data
= &sysctl_hugetlb_shm_group
,
819 .maxlen
= sizeof(gid_t
),
821 .proc_handler
= &proc_dointvec
,
825 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
826 .procname
= "lowmem_reserve_ratio",
827 .data
= &sysctl_lowmem_reserve_ratio
,
828 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
830 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
831 .strategy
= &sysctl_intvec
,
834 .ctl_name
= VM_DROP_PAGECACHE
,
835 .procname
= "drop_caches",
836 .data
= &sysctl_drop_caches
,
837 .maxlen
= sizeof(int),
839 .proc_handler
= drop_caches_sysctl_handler
,
840 .strategy
= &sysctl_intvec
,
843 .ctl_name
= VM_MIN_FREE_KBYTES
,
844 .procname
= "min_free_kbytes",
845 .data
= &min_free_kbytes
,
846 .maxlen
= sizeof(min_free_kbytes
),
848 .proc_handler
= &min_free_kbytes_sysctl_handler
,
849 .strategy
= &sysctl_intvec
,
853 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
854 .procname
= "percpu_pagelist_fraction",
855 .data
= &percpu_pagelist_fraction
,
856 .maxlen
= sizeof(percpu_pagelist_fraction
),
858 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
859 .strategy
= &sysctl_intvec
,
860 .extra1
= &min_percpu_pagelist_fract
,
864 .ctl_name
= VM_MAX_MAP_COUNT
,
865 .procname
= "max_map_count",
866 .data
= &sysctl_max_map_count
,
867 .maxlen
= sizeof(sysctl_max_map_count
),
869 .proc_handler
= &proc_dointvec
873 .ctl_name
= VM_LAPTOP_MODE
,
874 .procname
= "laptop_mode",
875 .data
= &laptop_mode
,
876 .maxlen
= sizeof(laptop_mode
),
878 .proc_handler
= &proc_dointvec_jiffies
,
879 .strategy
= &sysctl_jiffies
,
882 .ctl_name
= VM_BLOCK_DUMP
,
883 .procname
= "block_dump",
885 .maxlen
= sizeof(block_dump
),
887 .proc_handler
= &proc_dointvec
,
888 .strategy
= &sysctl_intvec
,
892 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
893 .procname
= "vfs_cache_pressure",
894 .data
= &sysctl_vfs_cache_pressure
,
895 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
897 .proc_handler
= &proc_dointvec
,
898 .strategy
= &sysctl_intvec
,
901 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
903 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
904 .procname
= "legacy_va_layout",
905 .data
= &sysctl_legacy_va_layout
,
906 .maxlen
= sizeof(sysctl_legacy_va_layout
),
908 .proc_handler
= &proc_dointvec
,
909 .strategy
= &sysctl_intvec
,
915 .ctl_name
= VM_SWAP_TOKEN_TIMEOUT
,
916 .procname
= "swap_token_timeout",
917 .data
= &swap_token_default_timeout
,
918 .maxlen
= sizeof(swap_token_default_timeout
),
920 .proc_handler
= &proc_dointvec_jiffies
,
921 .strategy
= &sysctl_jiffies
,
926 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
927 .procname
= "zone_reclaim_mode",
928 .data
= &zone_reclaim_mode
,
929 .maxlen
= sizeof(zone_reclaim_mode
),
931 .proc_handler
= &proc_dointvec
,
932 .strategy
= &sysctl_intvec
,
938 .ctl_name
= VM_VDSO_ENABLED
,
939 .procname
= "vdso_enabled",
940 .data
= &vdso_enabled
,
941 .maxlen
= sizeof(vdso_enabled
),
943 .proc_handler
= &proc_dointvec
,
944 .strategy
= &sysctl_intvec
,
951 static ctl_table fs_table
[] = {
953 .ctl_name
= FS_NRINODE
,
954 .procname
= "inode-nr",
955 .data
= &inodes_stat
,
956 .maxlen
= 2*sizeof(int),
958 .proc_handler
= &proc_dointvec
,
961 .ctl_name
= FS_STATINODE
,
962 .procname
= "inode-state",
963 .data
= &inodes_stat
,
964 .maxlen
= 7*sizeof(int),
966 .proc_handler
= &proc_dointvec
,
969 .ctl_name
= FS_NRFILE
,
970 .procname
= "file-nr",
972 .maxlen
= 3*sizeof(int),
974 .proc_handler
= &proc_nr_files
,
977 .ctl_name
= FS_MAXFILE
,
978 .procname
= "file-max",
979 .data
= &files_stat
.max_files
,
980 .maxlen
= sizeof(int),
982 .proc_handler
= &proc_dointvec
,
985 .ctl_name
= FS_DENTRY
,
986 .procname
= "dentry-state",
987 .data
= &dentry_stat
,
988 .maxlen
= 6*sizeof(int),
990 .proc_handler
= &proc_dointvec
,
993 .ctl_name
= FS_OVERFLOWUID
,
994 .procname
= "overflowuid",
995 .data
= &fs_overflowuid
,
996 .maxlen
= sizeof(int),
998 .proc_handler
= &proc_dointvec_minmax
,
999 .strategy
= &sysctl_intvec
,
1000 .extra1
= &minolduid
,
1001 .extra2
= &maxolduid
,
1004 .ctl_name
= FS_OVERFLOWGID
,
1005 .procname
= "overflowgid",
1006 .data
= &fs_overflowgid
,
1007 .maxlen
= sizeof(int),
1009 .proc_handler
= &proc_dointvec_minmax
,
1010 .strategy
= &sysctl_intvec
,
1011 .extra1
= &minolduid
,
1012 .extra2
= &maxolduid
,
1015 .ctl_name
= FS_LEASES
,
1016 .procname
= "leases-enable",
1017 .data
= &leases_enable
,
1018 .maxlen
= sizeof(int),
1020 .proc_handler
= &proc_dointvec
,
1022 #ifdef CONFIG_DNOTIFY
1024 .ctl_name
= FS_DIR_NOTIFY
,
1025 .procname
= "dir-notify-enable",
1026 .data
= &dir_notify_enable
,
1027 .maxlen
= sizeof(int),
1029 .proc_handler
= &proc_dointvec
,
1034 .ctl_name
= FS_LEASE_TIME
,
1035 .procname
= "lease-break-time",
1036 .data
= &lease_break_time
,
1037 .maxlen
= sizeof(int),
1039 .proc_handler
= &proc_dointvec
,
1042 .ctl_name
= FS_AIO_NR
,
1043 .procname
= "aio-nr",
1045 .maxlen
= sizeof(aio_nr
),
1047 .proc_handler
= &proc_doulongvec_minmax
,
1050 .ctl_name
= FS_AIO_MAX_NR
,
1051 .procname
= "aio-max-nr",
1052 .data
= &aio_max_nr
,
1053 .maxlen
= sizeof(aio_max_nr
),
1055 .proc_handler
= &proc_doulongvec_minmax
,
1057 #ifdef CONFIG_INOTIFY_USER
1059 .ctl_name
= FS_INOTIFY
,
1060 .procname
= "inotify",
1062 .child
= inotify_table
,
1067 .ctl_name
= KERN_SETUID_DUMPABLE
,
1068 .procname
= "suid_dumpable",
1069 .data
= &suid_dumpable
,
1070 .maxlen
= sizeof(int),
1072 .proc_handler
= &proc_dointvec
,
1077 static ctl_table debug_table
[] = {
1081 static ctl_table dev_table
[] = {
1085 extern void init_irq_proc (void);
1087 static DEFINE_SPINLOCK(sysctl_lock
);
1089 /* called under sysctl_lock */
1090 static int use_table(struct ctl_table_header
*p
)
1092 if (unlikely(p
->unregistering
))
1098 /* called under sysctl_lock */
1099 static void unuse_table(struct ctl_table_header
*p
)
1102 if (unlikely(p
->unregistering
))
1103 complete(p
->unregistering
);
1106 /* called under sysctl_lock, will reacquire if has to wait */
1107 static void start_unregistering(struct ctl_table_header
*p
)
1110 * if p->used is 0, nobody will ever touch that entry again;
1111 * we'll eliminate all paths to it before dropping sysctl_lock
1113 if (unlikely(p
->used
)) {
1114 struct completion wait
;
1115 init_completion(&wait
);
1116 p
->unregistering
= &wait
;
1117 spin_unlock(&sysctl_lock
);
1118 wait_for_completion(&wait
);
1119 spin_lock(&sysctl_lock
);
1122 * do not remove from the list until nobody holds it; walking the
1123 * list in do_sysctl() relies on that.
1125 list_del_init(&p
->ctl_entry
);
1128 void __init
sysctl_init(void)
1130 #ifdef CONFIG_PROC_FS
1131 register_proc_table(root_table
, proc_sys_root
, &root_table_header
);
1136 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1137 void __user
*newval
, size_t newlen
)
1139 struct list_head
*tmp
;
1140 int error
= -ENOTDIR
;
1142 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1146 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1149 spin_lock(&sysctl_lock
);
1150 tmp
= &root_table_header
.ctl_entry
;
1152 struct ctl_table_header
*head
=
1153 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1154 void *context
= NULL
;
1156 if (!use_table(head
))
1159 spin_unlock(&sysctl_lock
);
1161 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1162 newval
, newlen
, head
->ctl_table
,
1166 spin_lock(&sysctl_lock
);
1168 if (error
!= -ENOTDIR
)
1170 } while ((tmp
= tmp
->next
) != &root_table_header
.ctl_entry
);
1171 spin_unlock(&sysctl_lock
);
1175 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1177 struct __sysctl_args tmp
;
1180 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1184 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1185 tmp
.newval
, tmp
.newlen
);
1191 * ctl_perm does NOT grant the superuser all rights automatically, because
1192 * some sysctl variables are readonly even to root.
1195 static int test_perm(int mode
, int op
)
1199 else if (in_egroup_p(0))
1201 if ((mode
& op
& 0007) == op
)
1206 static inline int ctl_perm(ctl_table
*table
, int op
)
1209 error
= security_sysctl(table
, op
);
1212 return test_perm(table
->mode
, op
);
1215 static int parse_table(int __user
*name
, int nlen
,
1216 void __user
*oldval
, size_t __user
*oldlenp
,
1217 void __user
*newval
, size_t newlen
,
1218 ctl_table
*table
, void **context
)
1224 if (get_user(n
, name
))
1226 for ( ; table
->ctl_name
; table
++) {
1227 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1230 if (ctl_perm(table
, 001))
1232 if (table
->strategy
) {
1233 error
= table
->strategy(
1236 newval
, newlen
, context
);
1242 table
= table
->child
;
1245 error
= do_sysctl_strategy(table
, name
, nlen
,
1247 newval
, newlen
, context
);
1254 /* Perform the actual read/write of a sysctl table entry. */
1255 int do_sysctl_strategy (ctl_table
*table
,
1256 int __user
*name
, int nlen
,
1257 void __user
*oldval
, size_t __user
*oldlenp
,
1258 void __user
*newval
, size_t newlen
, void **context
)
1267 if (ctl_perm(table
, op
))
1270 if (table
->strategy
) {
1271 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1272 newval
, newlen
, context
);
1279 /* If there is no strategy routine, or if the strategy returns
1280 * zero, proceed with automatic r/w */
1281 if (table
->data
&& table
->maxlen
) {
1282 if (oldval
&& oldlenp
) {
1283 if (get_user(len
, oldlenp
))
1286 if (len
> table
->maxlen
)
1287 len
= table
->maxlen
;
1288 if(copy_to_user(oldval
, table
->data
, len
))
1290 if(put_user(len
, oldlenp
))
1294 if (newval
&& newlen
) {
1296 if (len
> table
->maxlen
)
1297 len
= table
->maxlen
;
1298 if(copy_from_user(table
->data
, newval
, len
))
1306 * register_sysctl_table - register a sysctl hierarchy
1307 * @table: the top-level table structure
1308 * @insert_at_head: whether the entry should be inserted in front or at the end
1310 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1311 * array. An entry with a ctl_name of 0 terminates the table.
1313 * The members of the &ctl_table structure are used as follows:
1315 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1316 * must be unique within that level of sysctl
1318 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1319 * enter a sysctl file
1321 * data - a pointer to data for use by proc_handler
1323 * maxlen - the maximum size in bytes of the data
1325 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1327 * child - a pointer to the child sysctl table if this entry is a directory, or
1330 * proc_handler - the text handler routine (described below)
1332 * strategy - the strategy routine (described below)
1334 * de - for internal use by the sysctl routines
1336 * extra1, extra2 - extra pointers usable by the proc handler routines
1338 * Leaf nodes in the sysctl tree will be represented by a single file
1339 * under /proc; non-leaf nodes will be represented by directories.
1341 * sysctl(2) can automatically manage read and write requests through
1342 * the sysctl table. The data and maxlen fields of the ctl_table
1343 * struct enable minimal validation of the values being written to be
1344 * performed, and the mode field allows minimal authentication.
1346 * More sophisticated management can be enabled by the provision of a
1347 * strategy routine with the table entry. This will be called before
1348 * any automatic read or write of the data is performed.
1350 * The strategy routine may return
1352 * < 0 - Error occurred (error is passed to user process)
1354 * 0 - OK - proceed with automatic read or write.
1356 * > 0 - OK - read or write has been done by the strategy routine, so
1357 * return immediately.
1359 * There must be a proc_handler routine for any terminal nodes
1360 * mirrored under /proc/sys (non-terminals are handled by a built-in
1361 * directory handler). Several default handlers are available to
1362 * cover common cases -
1364 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1365 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1366 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1368 * It is the handler's job to read the input buffer from user memory
1369 * and process it. The handler should return 0 on success.
1371 * This routine returns %NULL on a failure to register, and a pointer
1372 * to the table header on success.
1374 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1377 struct ctl_table_header
*tmp
;
1378 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1381 tmp
->ctl_table
= table
;
1382 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1384 tmp
->unregistering
= NULL
;
1385 spin_lock(&sysctl_lock
);
1387 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1389 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1390 spin_unlock(&sysctl_lock
);
1391 #ifdef CONFIG_PROC_FS
1392 register_proc_table(table
, proc_sys_root
, tmp
);
1398 * unregister_sysctl_table - unregister a sysctl table hierarchy
1399 * @header: the header returned from register_sysctl_table
1401 * Unregisters the sysctl table and all children. proc entries may not
1402 * actually be removed until they are no longer used by anyone.
1404 void unregister_sysctl_table(struct ctl_table_header
* header
)
1407 spin_lock(&sysctl_lock
);
1408 start_unregistering(header
);
1409 #ifdef CONFIG_PROC_FS
1410 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1412 spin_unlock(&sysctl_lock
);
1420 #ifdef CONFIG_PROC_FS
1422 /* Scan the sysctl entries in table and add them all into /proc */
1423 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
, void *set
)
1425 struct proc_dir_entry
*de
;
1429 for (; table
->ctl_name
; table
++) {
1430 /* Can't do anything without a proc name. */
1431 if (!table
->procname
)
1433 /* Maybe we can't do anything with it... */
1434 if (!table
->proc_handler
&& !table
->child
) {
1435 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1440 len
= strlen(table
->procname
);
1444 if (table
->proc_handler
)
1448 for (de
= root
->subdir
; de
; de
= de
->next
) {
1449 if (proc_match(len
, table
->procname
, de
))
1452 /* If the subdir exists already, de is non-NULL */
1456 de
= create_proc_entry(table
->procname
, mode
, root
);
1460 de
->data
= (void *) table
;
1461 if (table
->proc_handler
)
1462 de
->proc_fops
= &proc_sys_file_operations
;
1465 if (de
->mode
& S_IFDIR
)
1466 register_proc_table(table
->child
, de
, set
);
1471 * Unregister a /proc sysctl table and any subdirectories.
1473 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1475 struct proc_dir_entry
*de
;
1476 for (; table
->ctl_name
; table
++) {
1477 if (!(de
= table
->de
))
1479 if (de
->mode
& S_IFDIR
) {
1480 if (!table
->child
) {
1481 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1484 unregister_proc_table(table
->child
, de
);
1486 /* Don't unregister directories which still have entries.. */
1492 * In any case, mark the entry as goner; we'll keep it
1493 * around if it's busy, but we'll know to do nothing with
1494 * its fields. We are under sysctl_lock here.
1498 /* Don't unregister proc entries that are still being used.. */
1499 if (atomic_read(&de
->count
))
1503 remove_proc_entry(table
->procname
, root
);
1507 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1508 size_t count
, loff_t
*ppos
)
1511 struct proc_dir_entry
*de
= PDE(file
->f_dentry
->d_inode
);
1512 struct ctl_table
*table
;
1514 ssize_t error
= -ENOTDIR
;
1516 spin_lock(&sysctl_lock
);
1517 if (de
&& de
->data
&& use_table(de
->set
)) {
1519 * at that point we know that sysctl was not unregistered
1520 * and won't be until we finish
1522 spin_unlock(&sysctl_lock
);
1523 table
= (struct ctl_table
*) de
->data
;
1524 if (!table
|| !table
->proc_handler
)
1527 op
= (write
? 002 : 004);
1528 if (ctl_perm(table
, op
))
1531 /* careful: calling conventions are nasty here */
1533 error
= (*table
->proc_handler
)(table
, write
, file
,
1538 spin_lock(&sysctl_lock
);
1539 unuse_table(de
->set
);
1541 spin_unlock(&sysctl_lock
);
1545 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1547 if (file
->f_mode
& FMODE_WRITE
) {
1549 * sysctl entries that are not writable,
1550 * are _NOT_ writable, capabilities or not.
1552 if (!(inode
->i_mode
& S_IWUSR
))
1559 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1560 size_t count
, loff_t
*ppos
)
1562 return do_rw_proc(0, file
, buf
, count
, ppos
);
1565 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1566 size_t count
, loff_t
*ppos
)
1568 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1572 * proc_dostring - read a string sysctl
1573 * @table: the sysctl table
1574 * @write: %TRUE if this is a write to the sysctl file
1575 * @filp: the file structure
1576 * @buffer: the user buffer
1577 * @lenp: the size of the user buffer
1578 * @ppos: file position
1580 * Reads/writes a string from/to the user buffer. If the kernel
1581 * buffer provided is not large enough to hold the string, the
1582 * string is truncated. The copied string is %NULL-terminated.
1583 * If the string is being read by the user process, it is copied
1584 * and a newline '\n' is added. It is truncated if the buffer is
1587 * Returns 0 on success.
1589 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1590 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1596 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1597 (*ppos
&& !write
)) {
1605 while (len
< *lenp
) {
1606 if (get_user(c
, p
++))
1608 if (c
== 0 || c
== '\n')
1612 if (len
>= table
->maxlen
)
1613 len
= table
->maxlen
-1;
1614 if(copy_from_user(table
->data
, buffer
, len
))
1616 ((char *) table
->data
)[len
] = 0;
1619 len
= strlen(table
->data
);
1620 if (len
> table
->maxlen
)
1621 len
= table
->maxlen
;
1625 if(copy_to_user(buffer
, table
->data
, len
))
1628 if(put_user('\n', ((char __user
*) buffer
) + len
))
1639 * Special case of dostring for the UTS structure. This has locks
1640 * to observe. Should this be in kernel/sys.c ????
1643 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1644 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1649 down_read(&uts_sem
);
1650 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1653 down_write(&uts_sem
);
1654 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1660 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1662 int write
, void *data
)
1665 *valp
= *negp
? -*lvalp
: *lvalp
;
1670 *lvalp
= (unsigned long)-val
;
1673 *lvalp
= (unsigned long)val
;
1679 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1680 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1681 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1682 int write
, void *data
),
1685 #define TMPBUFLEN 21
1686 int *i
, vleft
, first
=1, neg
, val
;
1690 char buf
[TMPBUFLEN
], *p
;
1691 char __user
*s
= buffer
;
1693 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1694 (*ppos
&& !write
)) {
1699 i
= (int *) table
->data
;
1700 vleft
= table
->maxlen
/ sizeof(*i
);
1704 conv
= do_proc_dointvec_conv
;
1706 for (; left
&& vleft
--; i
++, first
=0) {
1721 if (len
> sizeof(buf
) - 1)
1722 len
= sizeof(buf
) - 1;
1723 if (copy_from_user(buf
, s
, len
))
1727 if (*p
== '-' && left
> 1) {
1731 if (*p
< '0' || *p
> '9')
1734 lval
= simple_strtoul(p
, &p
, 0);
1737 if ((len
< left
) && *p
&& !isspace(*p
))
1744 if (conv(&neg
, &lval
, i
, 1, data
))
1751 if (conv(&neg
, &lval
, i
, 0, data
))
1754 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1758 if(copy_to_user(s
, buf
, len
))
1765 if (!write
&& !first
&& left
) {
1766 if(put_user('\n', s
))
1773 if (get_user(c
, s
++))
1789 * proc_dointvec - read a vector of integers
1790 * @table: the sysctl table
1791 * @write: %TRUE if this is a write to the sysctl file
1792 * @filp: the file structure
1793 * @buffer: the user buffer
1794 * @lenp: the size of the user buffer
1795 * @ppos: file position
1797 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1798 * values from/to the user buffer, treated as an ASCII string.
1800 * Returns 0 on success.
1802 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1803 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1805 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1815 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1817 int write
, void *data
)
1819 int op
= *(int *)data
;
1821 int val
= *negp
? -*lvalp
: *lvalp
;
1823 case OP_SET
: *valp
= val
; break;
1824 case OP_AND
: *valp
&= val
; break;
1825 case OP_OR
: *valp
|= val
; break;
1826 case OP_MAX
: if(*valp
< val
)
1829 case OP_MIN
: if(*valp
> val
)
1837 *lvalp
= (unsigned long)-val
;
1840 *lvalp
= (unsigned long)val
;
1847 * init may raise the set.
1850 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1851 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1855 if (!capable(CAP_SYS_MODULE
)) {
1859 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1860 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1861 do_proc_dointvec_bset_conv
,&op
);
1864 struct do_proc_dointvec_minmax_conv_param
{
1869 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1871 int write
, void *data
)
1873 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1875 int val
= *negp
? -*lvalp
: *lvalp
;
1876 if ((param
->min
&& *param
->min
> val
) ||
1877 (param
->max
&& *param
->max
< val
))
1884 *lvalp
= (unsigned long)-val
;
1887 *lvalp
= (unsigned long)val
;
1894 * proc_dointvec_minmax - read a vector of integers with min/max values
1895 * @table: the sysctl table
1896 * @write: %TRUE if this is a write to the sysctl file
1897 * @filp: the file structure
1898 * @buffer: the user buffer
1899 * @lenp: the size of the user buffer
1900 * @ppos: file position
1902 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1903 * values from/to the user buffer, treated as an ASCII string.
1905 * This routine will ensure the values are within the range specified by
1906 * table->extra1 (min) and table->extra2 (max).
1908 * Returns 0 on success.
1910 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1911 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1913 struct do_proc_dointvec_minmax_conv_param param
= {
1914 .min
= (int *) table
->extra1
,
1915 .max
= (int *) table
->extra2
,
1917 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1918 do_proc_dointvec_minmax_conv
, ¶m
);
1921 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1923 void __user
*buffer
,
1924 size_t *lenp
, loff_t
*ppos
,
1925 unsigned long convmul
,
1926 unsigned long convdiv
)
1928 #define TMPBUFLEN 21
1929 unsigned long *i
, *min
, *max
, val
;
1930 int vleft
, first
=1, neg
;
1932 char buf
[TMPBUFLEN
], *p
;
1933 char __user
*s
= buffer
;
1935 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1936 (*ppos
&& !write
)) {
1941 i
= (unsigned long *) table
->data
;
1942 min
= (unsigned long *) table
->extra1
;
1943 max
= (unsigned long *) table
->extra2
;
1944 vleft
= table
->maxlen
/ sizeof(unsigned long);
1947 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1962 if (len
> TMPBUFLEN
-1)
1964 if (copy_from_user(buf
, s
, len
))
1968 if (*p
== '-' && left
> 1) {
1972 if (*p
< '0' || *p
> '9')
1974 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1976 if ((len
< left
) && *p
&& !isspace(*p
))
1985 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1992 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1996 if(copy_to_user(s
, buf
, len
))
2003 if (!write
&& !first
&& left
) {
2004 if(put_user('\n', s
))
2011 if (get_user(c
, s
++))
2027 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2028 * @table: the sysctl table
2029 * @write: %TRUE if this is a write to the sysctl file
2030 * @filp: the file structure
2031 * @buffer: the user buffer
2032 * @lenp: the size of the user buffer
2033 * @ppos: file position
2035 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2036 * values from/to the user buffer, treated as an ASCII string.
2038 * This routine will ensure the values are within the range specified by
2039 * table->extra1 (min) and table->extra2 (max).
2041 * Returns 0 on success.
2043 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2044 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2046 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2050 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2051 * @table: the sysctl table
2052 * @write: %TRUE if this is a write to the sysctl file
2053 * @filp: the file structure
2054 * @buffer: the user buffer
2055 * @lenp: the size of the user buffer
2056 * @ppos: file position
2058 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2059 * values from/to the user buffer, treated as an ASCII string. The values
2060 * are treated as milliseconds, and converted to jiffies when they are stored.
2062 * This routine will ensure the values are within the range specified by
2063 * table->extra1 (min) and table->extra2 (max).
2065 * Returns 0 on success.
2067 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2069 void __user
*buffer
,
2070 size_t *lenp
, loff_t
*ppos
)
2072 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2073 lenp
, ppos
, HZ
, 1000l);
2077 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2079 int write
, void *data
)
2082 if (*lvalp
> LONG_MAX
/ HZ
)
2084 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2090 lval
= (unsigned long)-val
;
2093 lval
= (unsigned long)val
;
2100 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2102 int write
, void *data
)
2105 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2107 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2113 lval
= (unsigned long)-val
;
2116 lval
= (unsigned long)val
;
2118 *lvalp
= jiffies_to_clock_t(lval
);
2123 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2125 int write
, void *data
)
2128 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2134 lval
= (unsigned long)-val
;
2137 lval
= (unsigned long)val
;
2139 *lvalp
= jiffies_to_msecs(lval
);
2145 * proc_dointvec_jiffies - read a vector of integers as seconds
2146 * @table: the sysctl table
2147 * @write: %TRUE if this is a write to the sysctl file
2148 * @filp: the file structure
2149 * @buffer: the user buffer
2150 * @lenp: the size of the user buffer
2151 * @ppos: file position
2153 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2154 * values from/to the user buffer, treated as an ASCII string.
2155 * The values read are assumed to be in seconds, and are converted into
2158 * Returns 0 on success.
2160 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2161 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2163 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2164 do_proc_dointvec_jiffies_conv
,NULL
);
2168 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2169 * @table: the sysctl table
2170 * @write: %TRUE if this is a write to the sysctl file
2171 * @filp: the file structure
2172 * @buffer: the user buffer
2173 * @lenp: the size of the user buffer
2174 * @ppos: pointer to the file position
2176 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2177 * values from/to the user buffer, treated as an ASCII string.
2178 * The values read are assumed to be in 1/USER_HZ seconds, and
2179 * are converted into jiffies.
2181 * Returns 0 on success.
2183 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2184 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2186 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2187 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2191 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2192 * @table: the sysctl table
2193 * @write: %TRUE if this is a write to the sysctl file
2194 * @filp: the file structure
2195 * @buffer: the user buffer
2196 * @lenp: the size of the user buffer
2197 * @ppos: file position
2198 * @ppos: the current position in the file
2200 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2201 * values from/to the user buffer, treated as an ASCII string.
2202 * The values read are assumed to be in 1/1000 seconds, and
2203 * are converted into jiffies.
2205 * Returns 0 on success.
2207 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2208 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2210 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2211 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2214 #else /* CONFIG_PROC_FS */
2216 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2217 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2222 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2223 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2228 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2229 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2234 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2235 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2240 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2241 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2246 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2247 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2252 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2253 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2258 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2259 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2264 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2265 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2270 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2272 void __user
*buffer
,
2273 size_t *lenp
, loff_t
*ppos
)
2279 #endif /* CONFIG_PROC_FS */
2283 * General sysctl support routines
2286 /* The generic string strategy routine: */
2287 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2288 void __user
*oldval
, size_t __user
*oldlenp
,
2289 void __user
*newval
, size_t newlen
, void **context
)
2291 if (!table
->data
|| !table
->maxlen
)
2294 if (oldval
&& oldlenp
) {
2296 if (get_user(bufsize
, oldlenp
))
2299 size_t len
= strlen(table
->data
), copied
;
2301 /* This shouldn't trigger for a well-formed sysctl */
2302 if (len
> table
->maxlen
)
2303 len
= table
->maxlen
;
2305 /* Copy up to a max of bufsize-1 bytes of the string */
2306 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2308 if (copy_to_user(oldval
, table
->data
, copied
) ||
2309 put_user(0, (char __user
*)(oldval
+ copied
)))
2311 if (put_user(len
, oldlenp
))
2315 if (newval
&& newlen
) {
2316 size_t len
= newlen
;
2317 if (len
> table
->maxlen
)
2318 len
= table
->maxlen
;
2319 if(copy_from_user(table
->data
, newval
, len
))
2321 if (len
== table
->maxlen
)
2323 ((char *) table
->data
)[len
] = 0;
2329 * This function makes sure that all of the integers in the vector
2330 * are between the minimum and maximum values given in the arrays
2331 * table->extra1 and table->extra2, respectively.
2333 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2334 void __user
*oldval
, size_t __user
*oldlenp
,
2335 void __user
*newval
, size_t newlen
, void **context
)
2338 if (newval
&& newlen
) {
2339 int __user
*vec
= (int __user
*) newval
;
2340 int *min
= (int *) table
->extra1
;
2341 int *max
= (int *) table
->extra2
;
2345 if (newlen
% sizeof(int) != 0)
2348 if (!table
->extra1
&& !table
->extra2
)
2351 if (newlen
> table
->maxlen
)
2352 newlen
= table
->maxlen
;
2353 length
= newlen
/ sizeof(int);
2355 for (i
= 0; i
< length
; i
++) {
2357 if (get_user(value
, vec
+ i
))
2359 if (min
&& value
< min
[i
])
2361 if (max
&& value
> max
[i
])
2368 /* Strategy function to convert jiffies to seconds */
2369 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2370 void __user
*oldval
, size_t __user
*oldlenp
,
2371 void __user
*newval
, size_t newlen
, void **context
)
2376 if (get_user(olen
, oldlenp
))
2378 if (olen
!=sizeof(int))
2381 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2382 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2385 if (newval
&& newlen
) {
2387 if (newlen
!= sizeof(int))
2389 if (get_user(new, (int __user
*)newval
))
2391 *(int *)(table
->data
) = new*HZ
;
2396 /* Strategy function to convert jiffies to seconds */
2397 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2398 void __user
*oldval
, size_t __user
*oldlenp
,
2399 void __user
*newval
, size_t newlen
, void **context
)
2404 if (get_user(olen
, oldlenp
))
2406 if (olen
!=sizeof(int))
2409 if (put_user(jiffies_to_msecs(*(int *)(table
->data
)), (int __user
*)oldval
) ||
2410 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2413 if (newval
&& newlen
) {
2415 if (newlen
!= sizeof(int))
2417 if (get_user(new, (int __user
*)newval
))
2419 *(int *)(table
->data
) = msecs_to_jiffies(new);
2424 #else /* CONFIG_SYSCTL */
2427 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2432 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2433 void __user
*oldval
, size_t __user
*oldlenp
,
2434 void __user
*newval
, size_t newlen
, void **context
)
2439 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2440 void __user
*oldval
, size_t __user
*oldlenp
,
2441 void __user
*newval
, size_t newlen
, void **context
)
2446 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2447 void __user
*oldval
, size_t __user
*oldlenp
,
2448 void __user
*newval
, size_t newlen
, void **context
)
2453 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2454 void __user
*oldval
, size_t __user
*oldlenp
,
2455 void __user
*newval
, size_t newlen
, void **context
)
2460 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2461 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2466 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2467 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2472 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2473 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2478 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2479 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2484 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2485 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2490 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2491 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2496 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2497 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2502 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2503 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2508 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2510 void __user
*buffer
,
2511 size_t *lenp
, loff_t
*ppos
)
2516 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2522 void unregister_sysctl_table(struct ctl_table_header
* table
)
2526 #endif /* CONFIG_SYSCTL */
2529 * No sense putting this after each symbol definition, twice,
2530 * exception granted :-)
2532 EXPORT_SYMBOL(proc_dointvec
);
2533 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2534 EXPORT_SYMBOL(proc_dointvec_minmax
);
2535 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2536 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2537 EXPORT_SYMBOL(proc_dostring
);
2538 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2539 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2540 EXPORT_SYMBOL(register_sysctl_table
);
2541 EXPORT_SYMBOL(sysctl_intvec
);
2542 EXPORT_SYMBOL(sysctl_jiffies
);
2543 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2544 EXPORT_SYMBOL(sysctl_string
);
2545 EXPORT_SYMBOL(unregister_sysctl_table
);