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
);
59 #if defined(CONFIG_SYSCTL)
61 /* External variables not in a header file. */
63 extern int sysctl_overcommit_memory
;
64 extern int sysctl_overcommit_ratio
;
65 extern int sysctl_panic_on_oom
;
66 extern int max_threads
;
67 extern int sysrq_enabled
;
68 extern int core_uses_pid
;
69 extern int suid_dumpable
;
70 extern char core_pattern
[];
73 extern int min_free_kbytes
;
74 extern int printk_ratelimit_jiffies
;
75 extern int printk_ratelimit_burst
;
76 extern int pid_max_min
, pid_max_max
;
77 extern int sysctl_drop_caches
;
78 extern int percpu_pagelist_fraction
;
79 extern int compat_log
;
81 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
82 static int maxolduid
= 65535;
84 static int min_percpu_pagelist_fract
= 8;
86 static int ngroups_max
= NGROUPS_MAX
;
89 extern char modprobe_path
[];
91 #ifdef CONFIG_CHR_DEV_SG
92 extern int sg_big_buff
;
95 extern size_t shm_ctlmax
;
96 extern size_t shm_ctlall
;
97 extern int shm_ctlmni
;
98 extern int msg_ctlmax
;
99 extern int msg_ctlmnb
;
100 extern int msg_ctlmni
;
101 extern int sem_ctls
[];
105 extern char reboot_command
[];
106 extern int stop_a_enabled
;
107 extern int scons_pwroff
;
111 extern int pwrsw_enabled
;
112 extern int unaligned_enabled
;
116 #ifdef CONFIG_MATHEMU
117 extern int sysctl_ieee_emulation_warnings
;
119 extern int sysctl_userprocess_debug
;
120 extern int spin_retry
;
123 extern int sysctl_hz_timer
;
125 #ifdef CONFIG_BSD_PROCESS_ACCT
126 extern int acct_parm
[];
130 extern int no_unaligned_warning
;
133 #ifdef CONFIG_RT_MUTEXES
134 extern int max_lock_depth
;
137 #ifdef CONFIG_SYSCTL_SYSCALL
138 static int parse_table(int __user
*, int, void __user
*, size_t __user
*,
139 void __user
*, size_t, ctl_table
*, void **);
142 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
143 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
145 static ctl_table root_table
[];
146 static struct ctl_table_header root_table_header
=
147 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
149 static ctl_table kern_table
[];
150 static ctl_table vm_table
[];
151 static ctl_table fs_table
[];
152 static ctl_table debug_table
[];
153 static ctl_table dev_table
[];
154 extern ctl_table random_table
[];
155 #ifdef CONFIG_UNIX98_PTYS
156 extern ctl_table pty_table
[];
158 #ifdef CONFIG_INOTIFY_USER
159 extern ctl_table inotify_table
[];
162 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
163 int sysctl_legacy_va_layout
;
166 /* /proc declarations: */
168 #ifdef CONFIG_PROC_SYSCTL
170 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
171 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
172 static int proc_opensys(struct inode
*, struct file
*);
174 struct file_operations proc_sys_file_operations
= {
175 .open
= proc_opensys
,
176 .read
= proc_readsys
,
177 .write
= proc_writesys
,
180 extern struct proc_dir_entry
*proc_sys_root
;
182 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*, void *);
183 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
186 /* The default sysctl tables: */
188 static ctl_table root_table
[] = {
190 .ctl_name
= CTL_KERN
,
191 .procname
= "kernel",
216 .ctl_name
= CTL_DEBUG
,
219 .child
= debug_table
,
231 static ctl_table kern_table
[] = {
233 .ctl_name
= KERN_OSTYPE
,
234 .procname
= "ostype",
235 .data
= system_utsname
.sysname
,
236 .maxlen
= sizeof(system_utsname
.sysname
),
238 .proc_handler
= &proc_doutsstring
,
239 .strategy
= &sysctl_string
,
242 .ctl_name
= KERN_OSRELEASE
,
243 .procname
= "osrelease",
244 .data
= system_utsname
.release
,
245 .maxlen
= sizeof(system_utsname
.release
),
247 .proc_handler
= &proc_doutsstring
,
248 .strategy
= &sysctl_string
,
251 .ctl_name
= KERN_VERSION
,
252 .procname
= "version",
253 .data
= system_utsname
.version
,
254 .maxlen
= sizeof(system_utsname
.version
),
256 .proc_handler
= &proc_doutsstring
,
257 .strategy
= &sysctl_string
,
260 .ctl_name
= KERN_NODENAME
,
261 .procname
= "hostname",
262 .data
= system_utsname
.nodename
,
263 .maxlen
= sizeof(system_utsname
.nodename
),
265 .proc_handler
= &proc_doutsstring
,
266 .strategy
= &sysctl_string
,
269 .ctl_name
= KERN_DOMAINNAME
,
270 .procname
= "domainname",
271 .data
= system_utsname
.domainname
,
272 .maxlen
= sizeof(system_utsname
.domainname
),
274 .proc_handler
= &proc_doutsstring
,
275 .strategy
= &sysctl_string
,
278 .ctl_name
= KERN_PANIC
,
280 .data
= &panic_timeout
,
281 .maxlen
= sizeof(int),
283 .proc_handler
= &proc_dointvec
,
286 .ctl_name
= KERN_CORE_USES_PID
,
287 .procname
= "core_uses_pid",
288 .data
= &core_uses_pid
,
289 .maxlen
= sizeof(int),
291 .proc_handler
= &proc_dointvec
,
294 .ctl_name
= KERN_CORE_PATTERN
,
295 .procname
= "core_pattern",
296 .data
= core_pattern
,
299 .proc_handler
= &proc_dostring
,
300 .strategy
= &sysctl_string
,
303 .ctl_name
= KERN_TAINTED
,
304 .procname
= "tainted",
306 .maxlen
= sizeof(int),
308 .proc_handler
= &proc_dointvec
,
311 .ctl_name
= KERN_CAP_BSET
,
312 .procname
= "cap-bound",
314 .maxlen
= sizeof(kernel_cap_t
),
316 .proc_handler
= &proc_dointvec_bset
,
318 #ifdef CONFIG_BLK_DEV_INITRD
320 .ctl_name
= KERN_REALROOTDEV
,
321 .procname
= "real-root-dev",
322 .data
= &real_root_dev
,
323 .maxlen
= sizeof(int),
325 .proc_handler
= &proc_dointvec
,
330 .ctl_name
= KERN_SPARC_REBOOT
,
331 .procname
= "reboot-cmd",
332 .data
= reboot_command
,
335 .proc_handler
= &proc_dostring
,
336 .strategy
= &sysctl_string
,
339 .ctl_name
= KERN_SPARC_STOP_A
,
340 .procname
= "stop-a",
341 .data
= &stop_a_enabled
,
342 .maxlen
= sizeof (int),
344 .proc_handler
= &proc_dointvec
,
347 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
348 .procname
= "scons-poweroff",
349 .data
= &scons_pwroff
,
350 .maxlen
= sizeof (int),
352 .proc_handler
= &proc_dointvec
,
357 .ctl_name
= KERN_HPPA_PWRSW
,
358 .procname
= "soft-power",
359 .data
= &pwrsw_enabled
,
360 .maxlen
= sizeof (int),
362 .proc_handler
= &proc_dointvec
,
365 .ctl_name
= KERN_HPPA_UNALIGNED
,
366 .procname
= "unaligned-trap",
367 .data
= &unaligned_enabled
,
368 .maxlen
= sizeof (int),
370 .proc_handler
= &proc_dointvec
,
374 .ctl_name
= KERN_CTLALTDEL
,
375 .procname
= "ctrl-alt-del",
377 .maxlen
= sizeof(int),
379 .proc_handler
= &proc_dointvec
,
382 .ctl_name
= KERN_PRINTK
,
383 .procname
= "printk",
384 .data
= &console_loglevel
,
385 .maxlen
= 4*sizeof(int),
387 .proc_handler
= &proc_dointvec
,
391 .ctl_name
= KERN_MODPROBE
,
392 .procname
= "modprobe",
393 .data
= &modprobe_path
,
394 .maxlen
= KMOD_PATH_LEN
,
396 .proc_handler
= &proc_dostring
,
397 .strategy
= &sysctl_string
,
400 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
402 .ctl_name
= KERN_HOTPLUG
,
403 .procname
= "hotplug",
404 .data
= &uevent_helper
,
405 .maxlen
= UEVENT_HELPER_PATH_LEN
,
407 .proc_handler
= &proc_dostring
,
408 .strategy
= &sysctl_string
,
411 #ifdef CONFIG_CHR_DEV_SG
413 .ctl_name
= KERN_SG_BIG_BUFF
,
414 .procname
= "sg-big-buff",
415 .data
= &sg_big_buff
,
416 .maxlen
= sizeof (int),
418 .proc_handler
= &proc_dointvec
,
421 #ifdef CONFIG_BSD_PROCESS_ACCT
423 .ctl_name
= KERN_ACCT
,
426 .maxlen
= 3*sizeof(int),
428 .proc_handler
= &proc_dointvec
,
431 #ifdef CONFIG_SYSVIPC
433 .ctl_name
= KERN_SHMMAX
,
434 .procname
= "shmmax",
436 .maxlen
= sizeof (size_t),
438 .proc_handler
= &proc_doulongvec_minmax
,
441 .ctl_name
= KERN_SHMALL
,
442 .procname
= "shmall",
444 .maxlen
= sizeof (size_t),
446 .proc_handler
= &proc_doulongvec_minmax
,
449 .ctl_name
= KERN_SHMMNI
,
450 .procname
= "shmmni",
452 .maxlen
= sizeof (int),
454 .proc_handler
= &proc_dointvec
,
457 .ctl_name
= KERN_MSGMAX
,
458 .procname
= "msgmax",
460 .maxlen
= sizeof (int),
462 .proc_handler
= &proc_dointvec
,
465 .ctl_name
= KERN_MSGMNI
,
466 .procname
= "msgmni",
468 .maxlen
= sizeof (int),
470 .proc_handler
= &proc_dointvec
,
473 .ctl_name
= KERN_MSGMNB
,
474 .procname
= "msgmnb",
476 .maxlen
= sizeof (int),
478 .proc_handler
= &proc_dointvec
,
481 .ctl_name
= KERN_SEM
,
484 .maxlen
= 4*sizeof (int),
486 .proc_handler
= &proc_dointvec
,
489 #ifdef CONFIG_MAGIC_SYSRQ
491 .ctl_name
= KERN_SYSRQ
,
493 .data
= &sysrq_enabled
,
494 .maxlen
= sizeof (int),
496 .proc_handler
= &proc_dointvec
,
500 .ctl_name
= KERN_CADPID
,
501 .procname
= "cad_pid",
503 .maxlen
= sizeof (int),
505 .proc_handler
= &proc_dointvec
,
508 .ctl_name
= KERN_MAX_THREADS
,
509 .procname
= "threads-max",
510 .data
= &max_threads
,
511 .maxlen
= sizeof(int),
513 .proc_handler
= &proc_dointvec
,
516 .ctl_name
= KERN_RANDOM
,
517 .procname
= "random",
519 .child
= random_table
,
521 #ifdef CONFIG_UNIX98_PTYS
523 .ctl_name
= KERN_PTY
,
530 .ctl_name
= KERN_OVERFLOWUID
,
531 .procname
= "overflowuid",
532 .data
= &overflowuid
,
533 .maxlen
= sizeof(int),
535 .proc_handler
= &proc_dointvec_minmax
,
536 .strategy
= &sysctl_intvec
,
537 .extra1
= &minolduid
,
538 .extra2
= &maxolduid
,
541 .ctl_name
= KERN_OVERFLOWGID
,
542 .procname
= "overflowgid",
543 .data
= &overflowgid
,
544 .maxlen
= sizeof(int),
546 .proc_handler
= &proc_dointvec_minmax
,
547 .strategy
= &sysctl_intvec
,
548 .extra1
= &minolduid
,
549 .extra2
= &maxolduid
,
552 #ifdef CONFIG_MATHEMU
554 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
555 .procname
= "ieee_emulation_warnings",
556 .data
= &sysctl_ieee_emulation_warnings
,
557 .maxlen
= sizeof(int),
559 .proc_handler
= &proc_dointvec
,
562 #ifdef CONFIG_NO_IDLE_HZ
564 .ctl_name
= KERN_HZ_TIMER
,
565 .procname
= "hz_timer",
566 .data
= &sysctl_hz_timer
,
567 .maxlen
= sizeof(int),
569 .proc_handler
= &proc_dointvec
,
573 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
574 .procname
= "userprocess_debug",
575 .data
= &sysctl_userprocess_debug
,
576 .maxlen
= sizeof(int),
578 .proc_handler
= &proc_dointvec
,
582 .ctl_name
= KERN_PIDMAX
,
583 .procname
= "pid_max",
585 .maxlen
= sizeof (int),
587 .proc_handler
= &proc_dointvec_minmax
,
588 .strategy
= sysctl_intvec
,
589 .extra1
= &pid_max_min
,
590 .extra2
= &pid_max_max
,
593 .ctl_name
= KERN_PANIC_ON_OOPS
,
594 .procname
= "panic_on_oops",
595 .data
= &panic_on_oops
,
596 .maxlen
= sizeof(int),
598 .proc_handler
= &proc_dointvec
,
601 .ctl_name
= KERN_PRINTK_RATELIMIT
,
602 .procname
= "printk_ratelimit",
603 .data
= &printk_ratelimit_jiffies
,
604 .maxlen
= sizeof(int),
606 .proc_handler
= &proc_dointvec_jiffies
,
607 .strategy
= &sysctl_jiffies
,
610 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
611 .procname
= "printk_ratelimit_burst",
612 .data
= &printk_ratelimit_burst
,
613 .maxlen
= sizeof(int),
615 .proc_handler
= &proc_dointvec
,
618 .ctl_name
= KERN_NGROUPS_MAX
,
619 .procname
= "ngroups_max",
620 .data
= &ngroups_max
,
621 .maxlen
= sizeof (int),
623 .proc_handler
= &proc_dointvec
,
625 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
627 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
628 .procname
= "unknown_nmi_panic",
629 .data
= &unknown_nmi_panic
,
630 .maxlen
= sizeof (int),
632 .proc_handler
= &proc_dointvec
,
635 .ctl_name
= KERN_NMI_WATCHDOG
,
636 .procname
= "nmi_watchdog",
637 .data
= &nmi_watchdog_enabled
,
638 .maxlen
= sizeof (int),
640 .proc_handler
= &proc_nmi_enabled
,
643 #if defined(CONFIG_X86)
645 .ctl_name
= KERN_PANIC_ON_NMI
,
646 .procname
= "panic_on_unrecovered_nmi",
647 .data
= &panic_on_unrecovered_nmi
,
648 .maxlen
= sizeof(int),
650 .proc_handler
= &proc_dointvec
,
653 .ctl_name
= KERN_BOOTLOADER_TYPE
,
654 .procname
= "bootloader_type",
655 .data
= &bootloader_type
,
656 .maxlen
= sizeof (int),
658 .proc_handler
= &proc_dointvec
,
661 #if defined(CONFIG_MMU)
663 .ctl_name
= KERN_RANDOMIZE
,
664 .procname
= "randomize_va_space",
665 .data
= &randomize_va_space
,
666 .maxlen
= sizeof(int),
668 .proc_handler
= &proc_dointvec
,
671 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
673 .ctl_name
= KERN_SPIN_RETRY
,
674 .procname
= "spin_retry",
676 .maxlen
= sizeof (int),
678 .proc_handler
= &proc_dointvec
,
681 #ifdef CONFIG_ACPI_SLEEP
683 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
684 .procname
= "acpi_video_flags",
685 .data
= &acpi_video_flags
,
686 .maxlen
= sizeof (unsigned long),
688 .proc_handler
= &proc_doulongvec_minmax
,
693 .ctl_name
= KERN_IA64_UNALIGNED
,
694 .procname
= "ignore-unaligned-usertrap",
695 .data
= &no_unaligned_warning
,
696 .maxlen
= sizeof (int),
698 .proc_handler
= &proc_dointvec
,
703 .ctl_name
= KERN_COMPAT_LOG
,
704 .procname
= "compat-log",
706 .maxlen
= sizeof (int),
708 .proc_handler
= &proc_dointvec
,
711 #ifdef CONFIG_RT_MUTEXES
713 .ctl_name
= KERN_MAX_LOCK_DEPTH
,
714 .procname
= "max_lock_depth",
715 .data
= &max_lock_depth
,
716 .maxlen
= sizeof(int),
718 .proc_handler
= &proc_dointvec
,
725 /* Constants for minimum and maximum testing in vm_table.
726 We use these as one-element integer vectors. */
728 static int one_hundred
= 100;
731 static ctl_table vm_table
[] = {
733 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
734 .procname
= "overcommit_memory",
735 .data
= &sysctl_overcommit_memory
,
736 .maxlen
= sizeof(sysctl_overcommit_memory
),
738 .proc_handler
= &proc_dointvec
,
741 .ctl_name
= VM_PANIC_ON_OOM
,
742 .procname
= "panic_on_oom",
743 .data
= &sysctl_panic_on_oom
,
744 .maxlen
= sizeof(sysctl_panic_on_oom
),
746 .proc_handler
= &proc_dointvec
,
749 .ctl_name
= VM_OVERCOMMIT_RATIO
,
750 .procname
= "overcommit_ratio",
751 .data
= &sysctl_overcommit_ratio
,
752 .maxlen
= sizeof(sysctl_overcommit_ratio
),
754 .proc_handler
= &proc_dointvec
,
757 .ctl_name
= VM_PAGE_CLUSTER
,
758 .procname
= "page-cluster",
759 .data
= &page_cluster
,
760 .maxlen
= sizeof(int),
762 .proc_handler
= &proc_dointvec
,
765 .ctl_name
= VM_DIRTY_BACKGROUND
,
766 .procname
= "dirty_background_ratio",
767 .data
= &dirty_background_ratio
,
768 .maxlen
= sizeof(dirty_background_ratio
),
770 .proc_handler
= &proc_dointvec_minmax
,
771 .strategy
= &sysctl_intvec
,
773 .extra2
= &one_hundred
,
776 .ctl_name
= VM_DIRTY_RATIO
,
777 .procname
= "dirty_ratio",
778 .data
= &vm_dirty_ratio
,
779 .maxlen
= sizeof(vm_dirty_ratio
),
781 .proc_handler
= &proc_dointvec_minmax
,
782 .strategy
= &sysctl_intvec
,
784 .extra2
= &one_hundred
,
787 .ctl_name
= VM_DIRTY_WB_CS
,
788 .procname
= "dirty_writeback_centisecs",
789 .data
= &dirty_writeback_interval
,
790 .maxlen
= sizeof(dirty_writeback_interval
),
792 .proc_handler
= &dirty_writeback_centisecs_handler
,
795 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
796 .procname
= "dirty_expire_centisecs",
797 .data
= &dirty_expire_interval
,
798 .maxlen
= sizeof(dirty_expire_interval
),
800 .proc_handler
= &proc_dointvec_userhz_jiffies
,
803 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
804 .procname
= "nr_pdflush_threads",
805 .data
= &nr_pdflush_threads
,
806 .maxlen
= sizeof nr_pdflush_threads
,
807 .mode
= 0444 /* read-only*/,
808 .proc_handler
= &proc_dointvec
,
811 .ctl_name
= VM_SWAPPINESS
,
812 .procname
= "swappiness",
813 .data
= &vm_swappiness
,
814 .maxlen
= sizeof(vm_swappiness
),
816 .proc_handler
= &proc_dointvec_minmax
,
817 .strategy
= &sysctl_intvec
,
819 .extra2
= &one_hundred
,
821 #ifdef CONFIG_HUGETLB_PAGE
823 .ctl_name
= VM_HUGETLB_PAGES
,
824 .procname
= "nr_hugepages",
825 .data
= &max_huge_pages
,
826 .maxlen
= sizeof(unsigned long),
828 .proc_handler
= &hugetlb_sysctl_handler
,
829 .extra1
= (void *)&hugetlb_zero
,
830 .extra2
= (void *)&hugetlb_infinity
,
833 .ctl_name
= VM_HUGETLB_GROUP
,
834 .procname
= "hugetlb_shm_group",
835 .data
= &sysctl_hugetlb_shm_group
,
836 .maxlen
= sizeof(gid_t
),
838 .proc_handler
= &proc_dointvec
,
842 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
843 .procname
= "lowmem_reserve_ratio",
844 .data
= &sysctl_lowmem_reserve_ratio
,
845 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
847 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
848 .strategy
= &sysctl_intvec
,
851 .ctl_name
= VM_DROP_PAGECACHE
,
852 .procname
= "drop_caches",
853 .data
= &sysctl_drop_caches
,
854 .maxlen
= sizeof(int),
856 .proc_handler
= drop_caches_sysctl_handler
,
857 .strategy
= &sysctl_intvec
,
860 .ctl_name
= VM_MIN_FREE_KBYTES
,
861 .procname
= "min_free_kbytes",
862 .data
= &min_free_kbytes
,
863 .maxlen
= sizeof(min_free_kbytes
),
865 .proc_handler
= &min_free_kbytes_sysctl_handler
,
866 .strategy
= &sysctl_intvec
,
870 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
871 .procname
= "percpu_pagelist_fraction",
872 .data
= &percpu_pagelist_fraction
,
873 .maxlen
= sizeof(percpu_pagelist_fraction
),
875 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
876 .strategy
= &sysctl_intvec
,
877 .extra1
= &min_percpu_pagelist_fract
,
881 .ctl_name
= VM_MAX_MAP_COUNT
,
882 .procname
= "max_map_count",
883 .data
= &sysctl_max_map_count
,
884 .maxlen
= sizeof(sysctl_max_map_count
),
886 .proc_handler
= &proc_dointvec
890 .ctl_name
= VM_LAPTOP_MODE
,
891 .procname
= "laptop_mode",
892 .data
= &laptop_mode
,
893 .maxlen
= sizeof(laptop_mode
),
895 .proc_handler
= &proc_dointvec_jiffies
,
896 .strategy
= &sysctl_jiffies
,
899 .ctl_name
= VM_BLOCK_DUMP
,
900 .procname
= "block_dump",
902 .maxlen
= sizeof(block_dump
),
904 .proc_handler
= &proc_dointvec
,
905 .strategy
= &sysctl_intvec
,
909 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
910 .procname
= "vfs_cache_pressure",
911 .data
= &sysctl_vfs_cache_pressure
,
912 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
914 .proc_handler
= &proc_dointvec
,
915 .strategy
= &sysctl_intvec
,
918 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
920 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
921 .procname
= "legacy_va_layout",
922 .data
= &sysctl_legacy_va_layout
,
923 .maxlen
= sizeof(sysctl_legacy_va_layout
),
925 .proc_handler
= &proc_dointvec
,
926 .strategy
= &sysctl_intvec
,
932 .ctl_name
= VM_SWAP_TOKEN_TIMEOUT
,
933 .procname
= "swap_token_timeout",
934 .data
= &swap_token_default_timeout
,
935 .maxlen
= sizeof(swap_token_default_timeout
),
937 .proc_handler
= &proc_dointvec_jiffies
,
938 .strategy
= &sysctl_jiffies
,
943 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
944 .procname
= "zone_reclaim_mode",
945 .data
= &zone_reclaim_mode
,
946 .maxlen
= sizeof(zone_reclaim_mode
),
948 .proc_handler
= &proc_dointvec
,
949 .strategy
= &sysctl_intvec
,
953 .ctl_name
= VM_MIN_UNMAPPED
,
954 .procname
= "min_unmapped_ratio",
955 .data
= &sysctl_min_unmapped_ratio
,
956 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
958 .proc_handler
= &sysctl_min_unmapped_ratio_sysctl_handler
,
959 .strategy
= &sysctl_intvec
,
961 .extra2
= &one_hundred
,
964 .ctl_name
= VM_MIN_SLAB
,
965 .procname
= "min_slab_ratio",
966 .data
= &sysctl_min_slab_ratio
,
967 .maxlen
= sizeof(sysctl_min_slab_ratio
),
969 .proc_handler
= &sysctl_min_slab_ratio_sysctl_handler
,
970 .strategy
= &sysctl_intvec
,
972 .extra2
= &one_hundred
,
977 .ctl_name
= VM_VDSO_ENABLED
,
978 .procname
= "vdso_enabled",
979 .data
= &vdso_enabled
,
980 .maxlen
= sizeof(vdso_enabled
),
982 .proc_handler
= &proc_dointvec
,
983 .strategy
= &sysctl_intvec
,
990 static ctl_table fs_table
[] = {
992 .ctl_name
= FS_NRINODE
,
993 .procname
= "inode-nr",
994 .data
= &inodes_stat
,
995 .maxlen
= 2*sizeof(int),
997 .proc_handler
= &proc_dointvec
,
1000 .ctl_name
= FS_STATINODE
,
1001 .procname
= "inode-state",
1002 .data
= &inodes_stat
,
1003 .maxlen
= 7*sizeof(int),
1005 .proc_handler
= &proc_dointvec
,
1008 .ctl_name
= FS_NRFILE
,
1009 .procname
= "file-nr",
1010 .data
= &files_stat
,
1011 .maxlen
= 3*sizeof(int),
1013 .proc_handler
= &proc_nr_files
,
1016 .ctl_name
= FS_MAXFILE
,
1017 .procname
= "file-max",
1018 .data
= &files_stat
.max_files
,
1019 .maxlen
= sizeof(int),
1021 .proc_handler
= &proc_dointvec
,
1024 .ctl_name
= FS_DENTRY
,
1025 .procname
= "dentry-state",
1026 .data
= &dentry_stat
,
1027 .maxlen
= 6*sizeof(int),
1029 .proc_handler
= &proc_dointvec
,
1032 .ctl_name
= FS_OVERFLOWUID
,
1033 .procname
= "overflowuid",
1034 .data
= &fs_overflowuid
,
1035 .maxlen
= sizeof(int),
1037 .proc_handler
= &proc_dointvec_minmax
,
1038 .strategy
= &sysctl_intvec
,
1039 .extra1
= &minolduid
,
1040 .extra2
= &maxolduid
,
1043 .ctl_name
= FS_OVERFLOWGID
,
1044 .procname
= "overflowgid",
1045 .data
= &fs_overflowgid
,
1046 .maxlen
= sizeof(int),
1048 .proc_handler
= &proc_dointvec_minmax
,
1049 .strategy
= &sysctl_intvec
,
1050 .extra1
= &minolduid
,
1051 .extra2
= &maxolduid
,
1054 .ctl_name
= FS_LEASES
,
1055 .procname
= "leases-enable",
1056 .data
= &leases_enable
,
1057 .maxlen
= sizeof(int),
1059 .proc_handler
= &proc_dointvec
,
1061 #ifdef CONFIG_DNOTIFY
1063 .ctl_name
= FS_DIR_NOTIFY
,
1064 .procname
= "dir-notify-enable",
1065 .data
= &dir_notify_enable
,
1066 .maxlen
= sizeof(int),
1068 .proc_handler
= &proc_dointvec
,
1073 .ctl_name
= FS_LEASE_TIME
,
1074 .procname
= "lease-break-time",
1075 .data
= &lease_break_time
,
1076 .maxlen
= sizeof(int),
1078 .proc_handler
= &proc_dointvec
,
1081 .ctl_name
= FS_AIO_NR
,
1082 .procname
= "aio-nr",
1084 .maxlen
= sizeof(aio_nr
),
1086 .proc_handler
= &proc_doulongvec_minmax
,
1089 .ctl_name
= FS_AIO_MAX_NR
,
1090 .procname
= "aio-max-nr",
1091 .data
= &aio_max_nr
,
1092 .maxlen
= sizeof(aio_max_nr
),
1094 .proc_handler
= &proc_doulongvec_minmax
,
1096 #ifdef CONFIG_INOTIFY_USER
1098 .ctl_name
= FS_INOTIFY
,
1099 .procname
= "inotify",
1101 .child
= inotify_table
,
1106 .ctl_name
= KERN_SETUID_DUMPABLE
,
1107 .procname
= "suid_dumpable",
1108 .data
= &suid_dumpable
,
1109 .maxlen
= sizeof(int),
1111 .proc_handler
= &proc_dointvec
,
1116 static ctl_table debug_table
[] = {
1120 static ctl_table dev_table
[] = {
1124 extern void init_irq_proc (void);
1126 static DEFINE_SPINLOCK(sysctl_lock
);
1128 /* called under sysctl_lock */
1129 static int use_table(struct ctl_table_header
*p
)
1131 if (unlikely(p
->unregistering
))
1137 /* called under sysctl_lock */
1138 static void unuse_table(struct ctl_table_header
*p
)
1141 if (unlikely(p
->unregistering
))
1142 complete(p
->unregistering
);
1145 /* called under sysctl_lock, will reacquire if has to wait */
1146 static void start_unregistering(struct ctl_table_header
*p
)
1149 * if p->used is 0, nobody will ever touch that entry again;
1150 * we'll eliminate all paths to it before dropping sysctl_lock
1152 if (unlikely(p
->used
)) {
1153 struct completion wait
;
1154 init_completion(&wait
);
1155 p
->unregistering
= &wait
;
1156 spin_unlock(&sysctl_lock
);
1157 wait_for_completion(&wait
);
1158 spin_lock(&sysctl_lock
);
1161 * do not remove from the list until nobody holds it; walking the
1162 * list in do_sysctl() relies on that.
1164 list_del_init(&p
->ctl_entry
);
1167 void __init
sysctl_init(void)
1169 #ifdef CONFIG_PROC_SYSCTL
1170 register_proc_table(root_table
, proc_sys_root
, &root_table_header
);
1175 #ifdef CONFIG_SYSCTL_SYSCALL
1176 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1177 void __user
*newval
, size_t newlen
)
1179 struct list_head
*tmp
;
1180 int error
= -ENOTDIR
;
1182 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1186 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1189 spin_lock(&sysctl_lock
);
1190 tmp
= &root_table_header
.ctl_entry
;
1192 struct ctl_table_header
*head
=
1193 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1194 void *context
= NULL
;
1196 if (!use_table(head
))
1199 spin_unlock(&sysctl_lock
);
1201 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1202 newval
, newlen
, head
->ctl_table
,
1206 spin_lock(&sysctl_lock
);
1208 if (error
!= -ENOTDIR
)
1210 } while ((tmp
= tmp
->next
) != &root_table_header
.ctl_entry
);
1211 spin_unlock(&sysctl_lock
);
1215 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1217 struct __sysctl_args tmp
;
1220 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1224 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1225 tmp
.newval
, tmp
.newlen
);
1229 #endif /* CONFIG_SYSCTL_SYSCALL */
1232 * ctl_perm does NOT grant the superuser all rights automatically, because
1233 * some sysctl variables are readonly even to root.
1236 static int test_perm(int mode
, int op
)
1240 else if (in_egroup_p(0))
1242 if ((mode
& op
& 0007) == op
)
1247 static inline int ctl_perm(ctl_table
*table
, int op
)
1250 error
= security_sysctl(table
, op
);
1253 return test_perm(table
->mode
, op
);
1256 #ifdef CONFIG_SYSCTL_SYSCALL
1257 static int parse_table(int __user
*name
, int nlen
,
1258 void __user
*oldval
, size_t __user
*oldlenp
,
1259 void __user
*newval
, size_t newlen
,
1260 ctl_table
*table
, void **context
)
1266 if (get_user(n
, name
))
1268 for ( ; table
->ctl_name
; table
++) {
1269 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1272 if (ctl_perm(table
, 001))
1274 if (table
->strategy
) {
1275 error
= table
->strategy(
1278 newval
, newlen
, context
);
1284 table
= table
->child
;
1287 error
= do_sysctl_strategy(table
, name
, nlen
,
1289 newval
, newlen
, context
);
1296 /* Perform the actual read/write of a sysctl table entry. */
1297 int do_sysctl_strategy (ctl_table
*table
,
1298 int __user
*name
, int nlen
,
1299 void __user
*oldval
, size_t __user
*oldlenp
,
1300 void __user
*newval
, size_t newlen
, void **context
)
1309 if (ctl_perm(table
, op
))
1312 if (table
->strategy
) {
1313 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1314 newval
, newlen
, context
);
1321 /* If there is no strategy routine, or if the strategy returns
1322 * zero, proceed with automatic r/w */
1323 if (table
->data
&& table
->maxlen
) {
1324 if (oldval
&& oldlenp
) {
1325 if (get_user(len
, oldlenp
))
1328 if (len
> table
->maxlen
)
1329 len
= table
->maxlen
;
1330 if(copy_to_user(oldval
, table
->data
, len
))
1332 if(put_user(len
, oldlenp
))
1336 if (newval
&& newlen
) {
1338 if (len
> table
->maxlen
)
1339 len
= table
->maxlen
;
1340 if(copy_from_user(table
->data
, newval
, len
))
1346 #endif /* CONFIG_SYSCTL_SYSCALL */
1349 * register_sysctl_table - register a sysctl hierarchy
1350 * @table: the top-level table structure
1351 * @insert_at_head: whether the entry should be inserted in front or at the end
1353 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1354 * array. An entry with a ctl_name of 0 terminates the table.
1356 * The members of the &ctl_table structure are used as follows:
1358 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1359 * must be unique within that level of sysctl
1361 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1362 * enter a sysctl file
1364 * data - a pointer to data for use by proc_handler
1366 * maxlen - the maximum size in bytes of the data
1368 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1370 * child - a pointer to the child sysctl table if this entry is a directory, or
1373 * proc_handler - the text handler routine (described below)
1375 * strategy - the strategy routine (described below)
1377 * de - for internal use by the sysctl routines
1379 * extra1, extra2 - extra pointers usable by the proc handler routines
1381 * Leaf nodes in the sysctl tree will be represented by a single file
1382 * under /proc; non-leaf nodes will be represented by directories.
1384 * sysctl(2) can automatically manage read and write requests through
1385 * the sysctl table. The data and maxlen fields of the ctl_table
1386 * struct enable minimal validation of the values being written to be
1387 * performed, and the mode field allows minimal authentication.
1389 * More sophisticated management can be enabled by the provision of a
1390 * strategy routine with the table entry. This will be called before
1391 * any automatic read or write of the data is performed.
1393 * The strategy routine may return
1395 * < 0 - Error occurred (error is passed to user process)
1397 * 0 - OK - proceed with automatic read or write.
1399 * > 0 - OK - read or write has been done by the strategy routine, so
1400 * return immediately.
1402 * There must be a proc_handler routine for any terminal nodes
1403 * mirrored under /proc/sys (non-terminals are handled by a built-in
1404 * directory handler). Several default handlers are available to
1405 * cover common cases -
1407 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1408 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1409 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1411 * It is the handler's job to read the input buffer from user memory
1412 * and process it. The handler should return 0 on success.
1414 * This routine returns %NULL on a failure to register, and a pointer
1415 * to the table header on success.
1417 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1420 struct ctl_table_header
*tmp
;
1421 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1424 tmp
->ctl_table
= table
;
1425 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1427 tmp
->unregistering
= NULL
;
1428 spin_lock(&sysctl_lock
);
1430 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1432 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1433 spin_unlock(&sysctl_lock
);
1434 #ifdef CONFIG_PROC_SYSCTL
1435 register_proc_table(table
, proc_sys_root
, tmp
);
1441 * unregister_sysctl_table - unregister a sysctl table hierarchy
1442 * @header: the header returned from register_sysctl_table
1444 * Unregisters the sysctl table and all children. proc entries may not
1445 * actually be removed until they are no longer used by anyone.
1447 void unregister_sysctl_table(struct ctl_table_header
* header
)
1450 spin_lock(&sysctl_lock
);
1451 start_unregistering(header
);
1452 #ifdef CONFIG_PROC_SYSCTL
1453 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1455 spin_unlock(&sysctl_lock
);
1459 #else /* !CONFIG_SYSCTL */
1460 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
1466 void unregister_sysctl_table(struct ctl_table_header
* table
)
1470 #endif /* CONFIG_SYSCTL */
1476 #ifdef CONFIG_PROC_SYSCTL
1478 /* Scan the sysctl entries in table and add them all into /proc */
1479 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
, void *set
)
1481 struct proc_dir_entry
*de
;
1485 for (; table
->ctl_name
; table
++) {
1486 /* Can't do anything without a proc name. */
1487 if (!table
->procname
)
1489 /* Maybe we can't do anything with it... */
1490 if (!table
->proc_handler
&& !table
->child
) {
1491 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1496 len
= strlen(table
->procname
);
1500 if (table
->proc_handler
)
1504 for (de
= root
->subdir
; de
; de
= de
->next
) {
1505 if (proc_match(len
, table
->procname
, de
))
1508 /* If the subdir exists already, de is non-NULL */
1512 de
= create_proc_entry(table
->procname
, mode
, root
);
1516 de
->data
= (void *) table
;
1517 if (table
->proc_handler
)
1518 de
->proc_fops
= &proc_sys_file_operations
;
1521 if (de
->mode
& S_IFDIR
)
1522 register_proc_table(table
->child
, de
, set
);
1527 * Unregister a /proc sysctl table and any subdirectories.
1529 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1531 struct proc_dir_entry
*de
;
1532 for (; table
->ctl_name
; table
++) {
1533 if (!(de
= table
->de
))
1535 if (de
->mode
& S_IFDIR
) {
1536 if (!table
->child
) {
1537 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1540 unregister_proc_table(table
->child
, de
);
1542 /* Don't unregister directories which still have entries.. */
1548 * In any case, mark the entry as goner; we'll keep it
1549 * around if it's busy, but we'll know to do nothing with
1550 * its fields. We are under sysctl_lock here.
1554 /* Don't unregister proc entries that are still being used.. */
1555 if (atomic_read(&de
->count
))
1559 remove_proc_entry(table
->procname
, root
);
1563 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1564 size_t count
, loff_t
*ppos
)
1567 struct proc_dir_entry
*de
= PDE(file
->f_dentry
->d_inode
);
1568 struct ctl_table
*table
;
1570 ssize_t error
= -ENOTDIR
;
1572 spin_lock(&sysctl_lock
);
1573 if (de
&& de
->data
&& use_table(de
->set
)) {
1575 * at that point we know that sysctl was not unregistered
1576 * and won't be until we finish
1578 spin_unlock(&sysctl_lock
);
1579 table
= (struct ctl_table
*) de
->data
;
1580 if (!table
|| !table
->proc_handler
)
1583 op
= (write
? 002 : 004);
1584 if (ctl_perm(table
, op
))
1587 /* careful: calling conventions are nasty here */
1589 error
= (*table
->proc_handler
)(table
, write
, file
,
1594 spin_lock(&sysctl_lock
);
1595 unuse_table(de
->set
);
1597 spin_unlock(&sysctl_lock
);
1601 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1603 if (file
->f_mode
& FMODE_WRITE
) {
1605 * sysctl entries that are not writable,
1606 * are _NOT_ writable, capabilities or not.
1608 if (!(inode
->i_mode
& S_IWUSR
))
1615 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1616 size_t count
, loff_t
*ppos
)
1618 return do_rw_proc(0, file
, buf
, count
, ppos
);
1621 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1622 size_t count
, loff_t
*ppos
)
1624 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1627 int _proc_do_string(void* data
, int maxlen
, int write
, struct file
*filp
,
1628 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1634 if (!data
|| !maxlen
|| !*lenp
||
1635 (*ppos
&& !write
)) {
1643 while (len
< *lenp
) {
1644 if (get_user(c
, p
++))
1646 if (c
== 0 || c
== '\n')
1652 if(copy_from_user(data
, buffer
, len
))
1654 ((char *) data
)[len
] = 0;
1663 if(copy_to_user(buffer
, data
, len
))
1666 if(put_user('\n', ((char __user
*) buffer
) + len
))
1677 * proc_dostring - read a string sysctl
1678 * @table: the sysctl table
1679 * @write: %TRUE if this is a write to the sysctl file
1680 * @filp: the file structure
1681 * @buffer: the user buffer
1682 * @lenp: the size of the user buffer
1683 * @ppos: file position
1685 * Reads/writes a string from/to the user buffer. If the kernel
1686 * buffer provided is not large enough to hold the string, the
1687 * string is truncated. The copied string is %NULL-terminated.
1688 * If the string is being read by the user process, it is copied
1689 * and a newline '\n' is added. It is truncated if the buffer is
1692 * Returns 0 on success.
1694 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1695 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1697 return _proc_do_string(table
->data
, table
->maxlen
, write
, filp
,
1698 buffer
, lenp
, ppos
);
1702 * Special case of dostring for the UTS structure. This has locks
1703 * to observe. Should this be in kernel/sys.c ????
1706 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1707 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1712 down_read(&uts_sem
);
1713 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1716 down_write(&uts_sem
);
1717 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1723 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1725 int write
, void *data
)
1728 *valp
= *negp
? -*lvalp
: *lvalp
;
1733 *lvalp
= (unsigned long)-val
;
1736 *lvalp
= (unsigned long)val
;
1742 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1743 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1744 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1745 int write
, void *data
),
1748 #define TMPBUFLEN 21
1749 int *i
, vleft
, first
=1, neg
, val
;
1753 char buf
[TMPBUFLEN
], *p
;
1754 char __user
*s
= buffer
;
1756 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1757 (*ppos
&& !write
)) {
1762 i
= (int *) table
->data
;
1763 vleft
= table
->maxlen
/ sizeof(*i
);
1767 conv
= do_proc_dointvec_conv
;
1769 for (; left
&& vleft
--; i
++, first
=0) {
1784 if (len
> sizeof(buf
) - 1)
1785 len
= sizeof(buf
) - 1;
1786 if (copy_from_user(buf
, s
, len
))
1790 if (*p
== '-' && left
> 1) {
1794 if (*p
< '0' || *p
> '9')
1797 lval
= simple_strtoul(p
, &p
, 0);
1800 if ((len
< left
) && *p
&& !isspace(*p
))
1807 if (conv(&neg
, &lval
, i
, 1, data
))
1814 if (conv(&neg
, &lval
, i
, 0, data
))
1817 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1821 if(copy_to_user(s
, buf
, len
))
1828 if (!write
&& !first
&& left
) {
1829 if(put_user('\n', s
))
1836 if (get_user(c
, s
++))
1852 * proc_dointvec - read a vector of integers
1853 * @table: the sysctl table
1854 * @write: %TRUE if this is a write to the sysctl file
1855 * @filp: the file structure
1856 * @buffer: the user buffer
1857 * @lenp: the size of the user buffer
1858 * @ppos: file position
1860 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1861 * values from/to the user buffer, treated as an ASCII string.
1863 * Returns 0 on success.
1865 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1866 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1868 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1878 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1880 int write
, void *data
)
1882 int op
= *(int *)data
;
1884 int val
= *negp
? -*lvalp
: *lvalp
;
1886 case OP_SET
: *valp
= val
; break;
1887 case OP_AND
: *valp
&= val
; break;
1888 case OP_OR
: *valp
|= val
; break;
1889 case OP_MAX
: if(*valp
< val
)
1892 case OP_MIN
: if(*valp
> val
)
1900 *lvalp
= (unsigned long)-val
;
1903 *lvalp
= (unsigned long)val
;
1910 * init may raise the set.
1913 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1914 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1918 if (!capable(CAP_SYS_MODULE
)) {
1922 op
= is_init(current
) ? OP_SET
: OP_AND
;
1923 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1924 do_proc_dointvec_bset_conv
,&op
);
1927 struct do_proc_dointvec_minmax_conv_param
{
1932 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1934 int write
, void *data
)
1936 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1938 int val
= *negp
? -*lvalp
: *lvalp
;
1939 if ((param
->min
&& *param
->min
> val
) ||
1940 (param
->max
&& *param
->max
< val
))
1947 *lvalp
= (unsigned long)-val
;
1950 *lvalp
= (unsigned long)val
;
1957 * proc_dointvec_minmax - read a vector of integers with min/max values
1958 * @table: the sysctl table
1959 * @write: %TRUE if this is a write to the sysctl file
1960 * @filp: the file structure
1961 * @buffer: the user buffer
1962 * @lenp: the size of the user buffer
1963 * @ppos: file position
1965 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1966 * values from/to the user buffer, treated as an ASCII string.
1968 * This routine will ensure the values are within the range specified by
1969 * table->extra1 (min) and table->extra2 (max).
1971 * Returns 0 on success.
1973 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1974 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1976 struct do_proc_dointvec_minmax_conv_param param
= {
1977 .min
= (int *) table
->extra1
,
1978 .max
= (int *) table
->extra2
,
1980 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1981 do_proc_dointvec_minmax_conv
, ¶m
);
1984 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1986 void __user
*buffer
,
1987 size_t *lenp
, loff_t
*ppos
,
1988 unsigned long convmul
,
1989 unsigned long convdiv
)
1991 #define TMPBUFLEN 21
1992 unsigned long *i
, *min
, *max
, val
;
1993 int vleft
, first
=1, neg
;
1995 char buf
[TMPBUFLEN
], *p
;
1996 char __user
*s
= buffer
;
1998 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1999 (*ppos
&& !write
)) {
2004 i
= (unsigned long *) table
->data
;
2005 min
= (unsigned long *) table
->extra1
;
2006 max
= (unsigned long *) table
->extra2
;
2007 vleft
= table
->maxlen
/ sizeof(unsigned long);
2010 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
2025 if (len
> TMPBUFLEN
-1)
2027 if (copy_from_user(buf
, s
, len
))
2031 if (*p
== '-' && left
> 1) {
2035 if (*p
< '0' || *p
> '9')
2037 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
2039 if ((len
< left
) && *p
&& !isspace(*p
))
2048 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2055 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
2059 if(copy_to_user(s
, buf
, len
))
2066 if (!write
&& !first
&& left
) {
2067 if(put_user('\n', s
))
2074 if (get_user(c
, s
++))
2090 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2091 * @table: the sysctl table
2092 * @write: %TRUE if this is a write to the sysctl file
2093 * @filp: the file structure
2094 * @buffer: the user buffer
2095 * @lenp: the size of the user buffer
2096 * @ppos: file position
2098 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2099 * values from/to the user buffer, treated as an ASCII string.
2101 * This routine will ensure the values are within the range specified by
2102 * table->extra1 (min) and table->extra2 (max).
2104 * Returns 0 on success.
2106 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2107 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2109 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2113 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2114 * @table: the sysctl table
2115 * @write: %TRUE if this is a write to the sysctl file
2116 * @filp: the file structure
2117 * @buffer: the user buffer
2118 * @lenp: the size of the user buffer
2119 * @ppos: file position
2121 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2122 * values from/to the user buffer, treated as an ASCII string. The values
2123 * are treated as milliseconds, and converted to jiffies when they are stored.
2125 * This routine will ensure the values are within the range specified by
2126 * table->extra1 (min) and table->extra2 (max).
2128 * Returns 0 on success.
2130 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2132 void __user
*buffer
,
2133 size_t *lenp
, loff_t
*ppos
)
2135 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2136 lenp
, ppos
, HZ
, 1000l);
2140 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2142 int write
, void *data
)
2145 if (*lvalp
> LONG_MAX
/ HZ
)
2147 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2153 lval
= (unsigned long)-val
;
2156 lval
= (unsigned long)val
;
2163 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2165 int write
, void *data
)
2168 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2170 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2176 lval
= (unsigned long)-val
;
2179 lval
= (unsigned long)val
;
2181 *lvalp
= jiffies_to_clock_t(lval
);
2186 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2188 int write
, void *data
)
2191 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2197 lval
= (unsigned long)-val
;
2200 lval
= (unsigned long)val
;
2202 *lvalp
= jiffies_to_msecs(lval
);
2208 * proc_dointvec_jiffies - read a vector of integers as seconds
2209 * @table: the sysctl table
2210 * @write: %TRUE if this is a write to the sysctl file
2211 * @filp: the file structure
2212 * @buffer: the user buffer
2213 * @lenp: the size of the user buffer
2214 * @ppos: file position
2216 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2217 * values from/to the user buffer, treated as an ASCII string.
2218 * The values read are assumed to be in seconds, and are converted into
2221 * Returns 0 on success.
2223 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2224 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2226 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2227 do_proc_dointvec_jiffies_conv
,NULL
);
2231 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2232 * @table: the sysctl table
2233 * @write: %TRUE if this is a write to the sysctl file
2234 * @filp: the file structure
2235 * @buffer: the user buffer
2236 * @lenp: the size of the user buffer
2237 * @ppos: pointer to the file position
2239 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2240 * values from/to the user buffer, treated as an ASCII string.
2241 * The values read are assumed to be in 1/USER_HZ seconds, and
2242 * are converted into jiffies.
2244 * Returns 0 on success.
2246 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2247 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2249 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2250 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2254 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2255 * @table: the sysctl table
2256 * @write: %TRUE if this is a write to the sysctl file
2257 * @filp: the file structure
2258 * @buffer: the user buffer
2259 * @lenp: the size of the user buffer
2260 * @ppos: file position
2261 * @ppos: the current position in the file
2263 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2264 * values from/to the user buffer, treated as an ASCII string.
2265 * The values read are assumed to be in 1/1000 seconds, and
2266 * are converted into jiffies.
2268 * Returns 0 on success.
2270 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2271 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2273 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2274 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2277 #else /* CONFIG_PROC_FS */
2279 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2280 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2285 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2286 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2291 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2292 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2297 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2298 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2303 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2304 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2309 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2310 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2315 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2316 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2321 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2322 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2327 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2328 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2333 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2335 void __user
*buffer
,
2336 size_t *lenp
, loff_t
*ppos
)
2342 #endif /* CONFIG_PROC_FS */
2345 #ifdef CONFIG_SYSCTL_SYSCALL
2347 * General sysctl support routines
2350 /* The generic string strategy routine: */
2351 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2352 void __user
*oldval
, size_t __user
*oldlenp
,
2353 void __user
*newval
, size_t newlen
, void **context
)
2355 if (!table
->data
|| !table
->maxlen
)
2358 if (oldval
&& oldlenp
) {
2360 if (get_user(bufsize
, oldlenp
))
2363 size_t len
= strlen(table
->data
), copied
;
2365 /* This shouldn't trigger for a well-formed sysctl */
2366 if (len
> table
->maxlen
)
2367 len
= table
->maxlen
;
2369 /* Copy up to a max of bufsize-1 bytes of the string */
2370 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2372 if (copy_to_user(oldval
, table
->data
, copied
) ||
2373 put_user(0, (char __user
*)(oldval
+ copied
)))
2375 if (put_user(len
, oldlenp
))
2379 if (newval
&& newlen
) {
2380 size_t len
= newlen
;
2381 if (len
> table
->maxlen
)
2382 len
= table
->maxlen
;
2383 if(copy_from_user(table
->data
, newval
, len
))
2385 if (len
== table
->maxlen
)
2387 ((char *) table
->data
)[len
] = 0;
2393 * This function makes sure that all of the integers in the vector
2394 * are between the minimum and maximum values given in the arrays
2395 * table->extra1 and table->extra2, respectively.
2397 int sysctl_intvec(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
)
2402 if (newval
&& newlen
) {
2403 int __user
*vec
= (int __user
*) newval
;
2404 int *min
= (int *) table
->extra1
;
2405 int *max
= (int *) table
->extra2
;
2409 if (newlen
% sizeof(int) != 0)
2412 if (!table
->extra1
&& !table
->extra2
)
2415 if (newlen
> table
->maxlen
)
2416 newlen
= table
->maxlen
;
2417 length
= newlen
/ sizeof(int);
2419 for (i
= 0; i
< length
; i
++) {
2421 if (get_user(value
, vec
+ i
))
2423 if (min
&& value
< min
[i
])
2425 if (max
&& value
> max
[i
])
2432 /* Strategy function to convert jiffies to seconds */
2433 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2434 void __user
*oldval
, size_t __user
*oldlenp
,
2435 void __user
*newval
, size_t newlen
, void **context
)
2440 if (get_user(olen
, oldlenp
))
2442 if (olen
!=sizeof(int))
2445 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2446 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2449 if (newval
&& newlen
) {
2451 if (newlen
!= sizeof(int))
2453 if (get_user(new, (int __user
*)newval
))
2455 *(int *)(table
->data
) = new*HZ
;
2460 /* Strategy function to convert jiffies to seconds */
2461 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2462 void __user
*oldval
, size_t __user
*oldlenp
,
2463 void __user
*newval
, size_t newlen
, void **context
)
2468 if (get_user(olen
, oldlenp
))
2470 if (olen
!=sizeof(int))
2473 if (put_user(jiffies_to_msecs(*(int *)(table
->data
)), (int __user
*)oldval
) ||
2474 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2477 if (newval
&& newlen
) {
2479 if (newlen
!= sizeof(int))
2481 if (get_user(new, (int __user
*)newval
))
2483 *(int *)(table
->data
) = msecs_to_jiffies(new);
2488 #else /* CONFIG_SYSCTL_SYSCALL */
2491 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2493 static int msg_count
;
2495 if (msg_count
< 5) {
2498 "warning: process `%s' used the removed sysctl "
2499 "system call\n", current
->comm
);
2504 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2505 void __user
*oldval
, size_t __user
*oldlenp
,
2506 void __user
*newval
, size_t newlen
, void **context
)
2511 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2512 void __user
*oldval
, size_t __user
*oldlenp
,
2513 void __user
*newval
, size_t newlen
, void **context
)
2518 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2519 void __user
*oldval
, size_t __user
*oldlenp
,
2520 void __user
*newval
, size_t newlen
, void **context
)
2525 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2526 void __user
*oldval
, size_t __user
*oldlenp
,
2527 void __user
*newval
, size_t newlen
, void **context
)
2532 #endif /* CONFIG_SYSCTL_SYSCALL */
2535 * No sense putting this after each symbol definition, twice,
2536 * exception granted :-)
2538 EXPORT_SYMBOL(proc_dointvec
);
2539 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2540 EXPORT_SYMBOL(proc_dointvec_minmax
);
2541 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2542 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2543 EXPORT_SYMBOL(proc_dostring
);
2544 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2545 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2546 EXPORT_SYMBOL(register_sysctl_table
);
2547 EXPORT_SYMBOL(sysctl_intvec
);
2548 EXPORT_SYMBOL(sysctl_jiffies
);
2549 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2550 EXPORT_SYMBOL(sysctl_string
);
2551 EXPORT_SYMBOL(unregister_sysctl_table
);