2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/config.h>
22 #include <linux/module.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/capability.h>
29 #include <linux/ctype.h>
30 #include <linux/utsname.h>
31 #include <linux/capability.h>
32 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/security.h>
42 #include <linux/initrd.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
53 extern int proc_nr_files(ctl_table
*table
, int write
, struct file
*filp
,
54 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
56 #if defined(CONFIG_SYSCTL)
58 /* External variables not in a header file. */
60 extern int sysctl_overcommit_memory
;
61 extern int sysctl_overcommit_ratio
;
62 extern int sysctl_panic_on_oom
;
63 extern int max_threads
;
64 extern int sysrq_enabled
;
65 extern int core_uses_pid
;
66 extern int suid_dumpable
;
67 extern char core_pattern
[];
70 extern int min_free_kbytes
;
71 extern int printk_ratelimit_jiffies
;
72 extern int printk_ratelimit_burst
;
73 extern int pid_max_min
, pid_max_max
;
74 extern int sysctl_drop_caches
;
75 extern int percpu_pagelist_fraction
;
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 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
136 ctl_table
*, void **);
137 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
138 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
140 static ctl_table root_table
[];
141 static struct ctl_table_header root_table_header
=
142 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
144 static ctl_table kern_table
[];
145 static ctl_table vm_table
[];
146 static ctl_table fs_table
[];
147 static ctl_table debug_table
[];
148 static ctl_table dev_table
[];
149 extern ctl_table random_table
[];
150 #ifdef CONFIG_UNIX98_PTYS
151 extern ctl_table pty_table
[];
153 #ifdef CONFIG_INOTIFY_USER
154 extern ctl_table inotify_table
[];
157 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
158 int sysctl_legacy_va_layout
;
161 /* /proc declarations: */
163 #ifdef CONFIG_PROC_FS
165 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
166 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
167 static int proc_opensys(struct inode
*, struct file
*);
169 struct file_operations proc_sys_file_operations
= {
170 .open
= proc_opensys
,
171 .read
= proc_readsys
,
172 .write
= proc_writesys
,
175 extern struct proc_dir_entry
*proc_sys_root
;
177 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*, void *);
178 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
181 /* The default sysctl tables: */
183 static ctl_table root_table
[] = {
185 .ctl_name
= CTL_KERN
,
186 .procname
= "kernel",
211 .ctl_name
= CTL_DEBUG
,
214 .child
= debug_table
,
226 static ctl_table kern_table
[] = {
228 .ctl_name
= KERN_OSTYPE
,
229 .procname
= "ostype",
230 .data
= system_utsname
.sysname
,
231 .maxlen
= sizeof(system_utsname
.sysname
),
233 .proc_handler
= &proc_doutsstring
,
234 .strategy
= &sysctl_string
,
237 .ctl_name
= KERN_OSRELEASE
,
238 .procname
= "osrelease",
239 .data
= system_utsname
.release
,
240 .maxlen
= sizeof(system_utsname
.release
),
242 .proc_handler
= &proc_doutsstring
,
243 .strategy
= &sysctl_string
,
246 .ctl_name
= KERN_VERSION
,
247 .procname
= "version",
248 .data
= system_utsname
.version
,
249 .maxlen
= sizeof(system_utsname
.version
),
251 .proc_handler
= &proc_doutsstring
,
252 .strategy
= &sysctl_string
,
255 .ctl_name
= KERN_NODENAME
,
256 .procname
= "hostname",
257 .data
= system_utsname
.nodename
,
258 .maxlen
= sizeof(system_utsname
.nodename
),
260 .proc_handler
= &proc_doutsstring
,
261 .strategy
= &sysctl_string
,
264 .ctl_name
= KERN_DOMAINNAME
,
265 .procname
= "domainname",
266 .data
= system_utsname
.domainname
,
267 .maxlen
= sizeof(system_utsname
.domainname
),
269 .proc_handler
= &proc_doutsstring
,
270 .strategy
= &sysctl_string
,
273 .ctl_name
= KERN_PANIC
,
275 .data
= &panic_timeout
,
276 .maxlen
= sizeof(int),
278 .proc_handler
= &proc_dointvec
,
281 .ctl_name
= KERN_CORE_USES_PID
,
282 .procname
= "core_uses_pid",
283 .data
= &core_uses_pid
,
284 .maxlen
= sizeof(int),
286 .proc_handler
= &proc_dointvec
,
289 .ctl_name
= KERN_CORE_PATTERN
,
290 .procname
= "core_pattern",
291 .data
= core_pattern
,
294 .proc_handler
= &proc_dostring
,
295 .strategy
= &sysctl_string
,
298 .ctl_name
= KERN_TAINTED
,
299 .procname
= "tainted",
301 .maxlen
= sizeof(int),
303 .proc_handler
= &proc_dointvec
,
306 .ctl_name
= KERN_CAP_BSET
,
307 .procname
= "cap-bound",
309 .maxlen
= sizeof(kernel_cap_t
),
311 .proc_handler
= &proc_dointvec_bset
,
313 #ifdef CONFIG_BLK_DEV_INITRD
315 .ctl_name
= KERN_REALROOTDEV
,
316 .procname
= "real-root-dev",
317 .data
= &real_root_dev
,
318 .maxlen
= sizeof(int),
320 .proc_handler
= &proc_dointvec
,
325 .ctl_name
= KERN_SPARC_REBOOT
,
326 .procname
= "reboot-cmd",
327 .data
= reboot_command
,
330 .proc_handler
= &proc_dostring
,
331 .strategy
= &sysctl_string
,
334 .ctl_name
= KERN_SPARC_STOP_A
,
335 .procname
= "stop-a",
336 .data
= &stop_a_enabled
,
337 .maxlen
= sizeof (int),
339 .proc_handler
= &proc_dointvec
,
342 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
343 .procname
= "scons-poweroff",
344 .data
= &scons_pwroff
,
345 .maxlen
= sizeof (int),
347 .proc_handler
= &proc_dointvec
,
352 .ctl_name
= KERN_HPPA_PWRSW
,
353 .procname
= "soft-power",
354 .data
= &pwrsw_enabled
,
355 .maxlen
= sizeof (int),
357 .proc_handler
= &proc_dointvec
,
360 .ctl_name
= KERN_HPPA_UNALIGNED
,
361 .procname
= "unaligned-trap",
362 .data
= &unaligned_enabled
,
363 .maxlen
= sizeof (int),
365 .proc_handler
= &proc_dointvec
,
369 .ctl_name
= KERN_CTLALTDEL
,
370 .procname
= "ctrl-alt-del",
372 .maxlen
= sizeof(int),
374 .proc_handler
= &proc_dointvec
,
377 .ctl_name
= KERN_PRINTK
,
378 .procname
= "printk",
379 .data
= &console_loglevel
,
380 .maxlen
= 4*sizeof(int),
382 .proc_handler
= &proc_dointvec
,
386 .ctl_name
= KERN_MODPROBE
,
387 .procname
= "modprobe",
388 .data
= &modprobe_path
,
389 .maxlen
= KMOD_PATH_LEN
,
391 .proc_handler
= &proc_dostring
,
392 .strategy
= &sysctl_string
,
395 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
397 .ctl_name
= KERN_HOTPLUG
,
398 .procname
= "hotplug",
399 .data
= &uevent_helper
,
400 .maxlen
= UEVENT_HELPER_PATH_LEN
,
402 .proc_handler
= &proc_dostring
,
403 .strategy
= &sysctl_string
,
406 #ifdef CONFIG_CHR_DEV_SG
408 .ctl_name
= KERN_SG_BIG_BUFF
,
409 .procname
= "sg-big-buff",
410 .data
= &sg_big_buff
,
411 .maxlen
= sizeof (int),
413 .proc_handler
= &proc_dointvec
,
416 #ifdef CONFIG_BSD_PROCESS_ACCT
418 .ctl_name
= KERN_ACCT
,
421 .maxlen
= 3*sizeof(int),
423 .proc_handler
= &proc_dointvec
,
426 #ifdef CONFIG_SYSVIPC
428 .ctl_name
= KERN_SHMMAX
,
429 .procname
= "shmmax",
431 .maxlen
= sizeof (size_t),
433 .proc_handler
= &proc_doulongvec_minmax
,
436 .ctl_name
= KERN_SHMALL
,
437 .procname
= "shmall",
439 .maxlen
= sizeof (size_t),
441 .proc_handler
= &proc_doulongvec_minmax
,
444 .ctl_name
= KERN_SHMMNI
,
445 .procname
= "shmmni",
447 .maxlen
= sizeof (int),
449 .proc_handler
= &proc_dointvec
,
452 .ctl_name
= KERN_MSGMAX
,
453 .procname
= "msgmax",
455 .maxlen
= sizeof (int),
457 .proc_handler
= &proc_dointvec
,
460 .ctl_name
= KERN_MSGMNI
,
461 .procname
= "msgmni",
463 .maxlen
= sizeof (int),
465 .proc_handler
= &proc_dointvec
,
468 .ctl_name
= KERN_MSGMNB
,
469 .procname
= "msgmnb",
471 .maxlen
= sizeof (int),
473 .proc_handler
= &proc_dointvec
,
476 .ctl_name
= KERN_SEM
,
479 .maxlen
= 4*sizeof (int),
481 .proc_handler
= &proc_dointvec
,
484 #ifdef CONFIG_MAGIC_SYSRQ
486 .ctl_name
= KERN_SYSRQ
,
488 .data
= &sysrq_enabled
,
489 .maxlen
= sizeof (int),
491 .proc_handler
= &proc_dointvec
,
495 .ctl_name
= KERN_CADPID
,
496 .procname
= "cad_pid",
498 .maxlen
= sizeof (int),
500 .proc_handler
= &proc_dointvec
,
503 .ctl_name
= KERN_MAX_THREADS
,
504 .procname
= "threads-max",
505 .data
= &max_threads
,
506 .maxlen
= sizeof(int),
508 .proc_handler
= &proc_dointvec
,
511 .ctl_name
= KERN_RANDOM
,
512 .procname
= "random",
514 .child
= random_table
,
516 #ifdef CONFIG_UNIX98_PTYS
518 .ctl_name
= KERN_PTY
,
525 .ctl_name
= KERN_OVERFLOWUID
,
526 .procname
= "overflowuid",
527 .data
= &overflowuid
,
528 .maxlen
= sizeof(int),
530 .proc_handler
= &proc_dointvec_minmax
,
531 .strategy
= &sysctl_intvec
,
532 .extra1
= &minolduid
,
533 .extra2
= &maxolduid
,
536 .ctl_name
= KERN_OVERFLOWGID
,
537 .procname
= "overflowgid",
538 .data
= &overflowgid
,
539 .maxlen
= sizeof(int),
541 .proc_handler
= &proc_dointvec_minmax
,
542 .strategy
= &sysctl_intvec
,
543 .extra1
= &minolduid
,
544 .extra2
= &maxolduid
,
547 #ifdef CONFIG_MATHEMU
549 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
550 .procname
= "ieee_emulation_warnings",
551 .data
= &sysctl_ieee_emulation_warnings
,
552 .maxlen
= sizeof(int),
554 .proc_handler
= &proc_dointvec
,
557 #ifdef CONFIG_NO_IDLE_HZ
559 .ctl_name
= KERN_HZ_TIMER
,
560 .procname
= "hz_timer",
561 .data
= &sysctl_hz_timer
,
562 .maxlen
= sizeof(int),
564 .proc_handler
= &proc_dointvec
,
568 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
569 .procname
= "userprocess_debug",
570 .data
= &sysctl_userprocess_debug
,
571 .maxlen
= sizeof(int),
573 .proc_handler
= &proc_dointvec
,
577 .ctl_name
= KERN_PIDMAX
,
578 .procname
= "pid_max",
580 .maxlen
= sizeof (int),
582 .proc_handler
= &proc_dointvec_minmax
,
583 .strategy
= sysctl_intvec
,
584 .extra1
= &pid_max_min
,
585 .extra2
= &pid_max_max
,
588 .ctl_name
= KERN_PANIC_ON_OOPS
,
589 .procname
= "panic_on_oops",
590 .data
= &panic_on_oops
,
591 .maxlen
= sizeof(int),
593 .proc_handler
= &proc_dointvec
,
596 .ctl_name
= KERN_PRINTK_RATELIMIT
,
597 .procname
= "printk_ratelimit",
598 .data
= &printk_ratelimit_jiffies
,
599 .maxlen
= sizeof(int),
601 .proc_handler
= &proc_dointvec_jiffies
,
602 .strategy
= &sysctl_jiffies
,
605 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
606 .procname
= "printk_ratelimit_burst",
607 .data
= &printk_ratelimit_burst
,
608 .maxlen
= sizeof(int),
610 .proc_handler
= &proc_dointvec
,
613 .ctl_name
= KERN_NGROUPS_MAX
,
614 .procname
= "ngroups_max",
615 .data
= &ngroups_max
,
616 .maxlen
= sizeof (int),
618 .proc_handler
= &proc_dointvec
,
620 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
622 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
623 .procname
= "unknown_nmi_panic",
624 .data
= &unknown_nmi_panic
,
625 .maxlen
= sizeof (int),
627 .proc_handler
= &proc_unknown_nmi_panic
,
630 #if defined(CONFIG_X86)
632 .ctl_name
= KERN_BOOTLOADER_TYPE
,
633 .procname
= "bootloader_type",
634 .data
= &bootloader_type
,
635 .maxlen
= sizeof (int),
637 .proc_handler
= &proc_dointvec
,
640 #if defined(CONFIG_MMU)
642 .ctl_name
= KERN_RANDOMIZE
,
643 .procname
= "randomize_va_space",
644 .data
= &randomize_va_space
,
645 .maxlen
= sizeof(int),
647 .proc_handler
= &proc_dointvec
,
650 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
652 .ctl_name
= KERN_SPIN_RETRY
,
653 .procname
= "spin_retry",
655 .maxlen
= sizeof (int),
657 .proc_handler
= &proc_dointvec
,
660 #ifdef CONFIG_ACPI_SLEEP
662 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
663 .procname
= "acpi_video_flags",
664 .data
= &acpi_video_flags
,
665 .maxlen
= sizeof (unsigned long),
667 .proc_handler
= &proc_doulongvec_minmax
,
672 .ctl_name
= KERN_IA64_UNALIGNED
,
673 .procname
= "ignore-unaligned-usertrap",
674 .data
= &no_unaligned_warning
,
675 .maxlen
= sizeof (int),
677 .proc_handler
= &proc_dointvec
,
683 /* Constants for minimum and maximum testing in vm_table.
684 We use these as one-element integer vectors. */
686 static int one_hundred
= 100;
689 static ctl_table vm_table
[] = {
691 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
692 .procname
= "overcommit_memory",
693 .data
= &sysctl_overcommit_memory
,
694 .maxlen
= sizeof(sysctl_overcommit_memory
),
696 .proc_handler
= &proc_dointvec
,
699 .ctl_name
= VM_PANIC_ON_OOM
,
700 .procname
= "panic_on_oom",
701 .data
= &sysctl_panic_on_oom
,
702 .maxlen
= sizeof(sysctl_panic_on_oom
),
704 .proc_handler
= &proc_dointvec
,
707 .ctl_name
= VM_OVERCOMMIT_RATIO
,
708 .procname
= "overcommit_ratio",
709 .data
= &sysctl_overcommit_ratio
,
710 .maxlen
= sizeof(sysctl_overcommit_ratio
),
712 .proc_handler
= &proc_dointvec
,
715 .ctl_name
= VM_PAGE_CLUSTER
,
716 .procname
= "page-cluster",
717 .data
= &page_cluster
,
718 .maxlen
= sizeof(int),
720 .proc_handler
= &proc_dointvec
,
723 .ctl_name
= VM_DIRTY_BACKGROUND
,
724 .procname
= "dirty_background_ratio",
725 .data
= &dirty_background_ratio
,
726 .maxlen
= sizeof(dirty_background_ratio
),
728 .proc_handler
= &proc_dointvec_minmax
,
729 .strategy
= &sysctl_intvec
,
731 .extra2
= &one_hundred
,
734 .ctl_name
= VM_DIRTY_RATIO
,
735 .procname
= "dirty_ratio",
736 .data
= &vm_dirty_ratio
,
737 .maxlen
= sizeof(vm_dirty_ratio
),
739 .proc_handler
= &proc_dointvec_minmax
,
740 .strategy
= &sysctl_intvec
,
742 .extra2
= &one_hundred
,
745 .ctl_name
= VM_DIRTY_WB_CS
,
746 .procname
= "dirty_writeback_centisecs",
747 .data
= &dirty_writeback_interval
,
748 .maxlen
= sizeof(dirty_writeback_interval
),
750 .proc_handler
= &dirty_writeback_centisecs_handler
,
753 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
754 .procname
= "dirty_expire_centisecs",
755 .data
= &dirty_expire_interval
,
756 .maxlen
= sizeof(dirty_expire_interval
),
758 .proc_handler
= &proc_dointvec_userhz_jiffies
,
761 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
762 .procname
= "nr_pdflush_threads",
763 .data
= &nr_pdflush_threads
,
764 .maxlen
= sizeof nr_pdflush_threads
,
765 .mode
= 0444 /* read-only*/,
766 .proc_handler
= &proc_dointvec
,
769 .ctl_name
= VM_SWAPPINESS
,
770 .procname
= "swappiness",
771 .data
= &vm_swappiness
,
772 .maxlen
= sizeof(vm_swappiness
),
774 .proc_handler
= &proc_dointvec_minmax
,
775 .strategy
= &sysctl_intvec
,
777 .extra2
= &one_hundred
,
779 #ifdef CONFIG_HUGETLB_PAGE
781 .ctl_name
= VM_HUGETLB_PAGES
,
782 .procname
= "nr_hugepages",
783 .data
= &max_huge_pages
,
784 .maxlen
= sizeof(unsigned long),
786 .proc_handler
= &hugetlb_sysctl_handler
,
787 .extra1
= (void *)&hugetlb_zero
,
788 .extra2
= (void *)&hugetlb_infinity
,
791 .ctl_name
= VM_HUGETLB_GROUP
,
792 .procname
= "hugetlb_shm_group",
793 .data
= &sysctl_hugetlb_shm_group
,
794 .maxlen
= sizeof(gid_t
),
796 .proc_handler
= &proc_dointvec
,
800 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
801 .procname
= "lowmem_reserve_ratio",
802 .data
= &sysctl_lowmem_reserve_ratio
,
803 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
805 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
806 .strategy
= &sysctl_intvec
,
809 .ctl_name
= VM_DROP_PAGECACHE
,
810 .procname
= "drop_caches",
811 .data
= &sysctl_drop_caches
,
812 .maxlen
= sizeof(int),
814 .proc_handler
= drop_caches_sysctl_handler
,
815 .strategy
= &sysctl_intvec
,
818 .ctl_name
= VM_MIN_FREE_KBYTES
,
819 .procname
= "min_free_kbytes",
820 .data
= &min_free_kbytes
,
821 .maxlen
= sizeof(min_free_kbytes
),
823 .proc_handler
= &min_free_kbytes_sysctl_handler
,
824 .strategy
= &sysctl_intvec
,
828 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
829 .procname
= "percpu_pagelist_fraction",
830 .data
= &percpu_pagelist_fraction
,
831 .maxlen
= sizeof(percpu_pagelist_fraction
),
833 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
834 .strategy
= &sysctl_intvec
,
835 .extra1
= &min_percpu_pagelist_fract
,
839 .ctl_name
= VM_MAX_MAP_COUNT
,
840 .procname
= "max_map_count",
841 .data
= &sysctl_max_map_count
,
842 .maxlen
= sizeof(sysctl_max_map_count
),
844 .proc_handler
= &proc_dointvec
848 .ctl_name
= VM_LAPTOP_MODE
,
849 .procname
= "laptop_mode",
850 .data
= &laptop_mode
,
851 .maxlen
= sizeof(laptop_mode
),
853 .proc_handler
= &proc_dointvec_jiffies
,
854 .strategy
= &sysctl_jiffies
,
857 .ctl_name
= VM_BLOCK_DUMP
,
858 .procname
= "block_dump",
860 .maxlen
= sizeof(block_dump
),
862 .proc_handler
= &proc_dointvec
,
863 .strategy
= &sysctl_intvec
,
867 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
868 .procname
= "vfs_cache_pressure",
869 .data
= &sysctl_vfs_cache_pressure
,
870 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
872 .proc_handler
= &proc_dointvec
,
873 .strategy
= &sysctl_intvec
,
876 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
878 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
879 .procname
= "legacy_va_layout",
880 .data
= &sysctl_legacy_va_layout
,
881 .maxlen
= sizeof(sysctl_legacy_va_layout
),
883 .proc_handler
= &proc_dointvec
,
884 .strategy
= &sysctl_intvec
,
890 .ctl_name
= VM_SWAP_TOKEN_TIMEOUT
,
891 .procname
= "swap_token_timeout",
892 .data
= &swap_token_default_timeout
,
893 .maxlen
= sizeof(swap_token_default_timeout
),
895 .proc_handler
= &proc_dointvec_jiffies
,
896 .strategy
= &sysctl_jiffies
,
901 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
902 .procname
= "zone_reclaim_mode",
903 .data
= &zone_reclaim_mode
,
904 .maxlen
= sizeof(zone_reclaim_mode
),
906 .proc_handler
= &proc_dointvec
,
907 .strategy
= &sysctl_intvec
,
911 .ctl_name
= VM_ZONE_RECLAIM_INTERVAL
,
912 .procname
= "zone_reclaim_interval",
913 .data
= &zone_reclaim_interval
,
914 .maxlen
= sizeof(zone_reclaim_interval
),
916 .proc_handler
= &proc_dointvec_jiffies
,
917 .strategy
= &sysctl_jiffies
,
923 static ctl_table fs_table
[] = {
925 .ctl_name
= FS_NRINODE
,
926 .procname
= "inode-nr",
927 .data
= &inodes_stat
,
928 .maxlen
= 2*sizeof(int),
930 .proc_handler
= &proc_dointvec
,
933 .ctl_name
= FS_STATINODE
,
934 .procname
= "inode-state",
935 .data
= &inodes_stat
,
936 .maxlen
= 7*sizeof(int),
938 .proc_handler
= &proc_dointvec
,
941 .ctl_name
= FS_NRFILE
,
942 .procname
= "file-nr",
944 .maxlen
= 3*sizeof(int),
946 .proc_handler
= &proc_nr_files
,
949 .ctl_name
= FS_MAXFILE
,
950 .procname
= "file-max",
951 .data
= &files_stat
.max_files
,
952 .maxlen
= sizeof(int),
954 .proc_handler
= &proc_dointvec
,
957 .ctl_name
= FS_DENTRY
,
958 .procname
= "dentry-state",
959 .data
= &dentry_stat
,
960 .maxlen
= 6*sizeof(int),
962 .proc_handler
= &proc_dointvec
,
965 .ctl_name
= FS_OVERFLOWUID
,
966 .procname
= "overflowuid",
967 .data
= &fs_overflowuid
,
968 .maxlen
= sizeof(int),
970 .proc_handler
= &proc_dointvec_minmax
,
971 .strategy
= &sysctl_intvec
,
972 .extra1
= &minolduid
,
973 .extra2
= &maxolduid
,
976 .ctl_name
= FS_OVERFLOWGID
,
977 .procname
= "overflowgid",
978 .data
= &fs_overflowgid
,
979 .maxlen
= sizeof(int),
981 .proc_handler
= &proc_dointvec_minmax
,
982 .strategy
= &sysctl_intvec
,
983 .extra1
= &minolduid
,
984 .extra2
= &maxolduid
,
987 .ctl_name
= FS_LEASES
,
988 .procname
= "leases-enable",
989 .data
= &leases_enable
,
990 .maxlen
= sizeof(int),
992 .proc_handler
= &proc_dointvec
,
994 #ifdef CONFIG_DNOTIFY
996 .ctl_name
= FS_DIR_NOTIFY
,
997 .procname
= "dir-notify-enable",
998 .data
= &dir_notify_enable
,
999 .maxlen
= sizeof(int),
1001 .proc_handler
= &proc_dointvec
,
1006 .ctl_name
= FS_LEASE_TIME
,
1007 .procname
= "lease-break-time",
1008 .data
= &lease_break_time
,
1009 .maxlen
= sizeof(int),
1011 .proc_handler
= &proc_dointvec
,
1014 .ctl_name
= FS_AIO_NR
,
1015 .procname
= "aio-nr",
1017 .maxlen
= sizeof(aio_nr
),
1019 .proc_handler
= &proc_doulongvec_minmax
,
1022 .ctl_name
= FS_AIO_MAX_NR
,
1023 .procname
= "aio-max-nr",
1024 .data
= &aio_max_nr
,
1025 .maxlen
= sizeof(aio_max_nr
),
1027 .proc_handler
= &proc_doulongvec_minmax
,
1029 #ifdef CONFIG_INOTIFY_USER
1031 .ctl_name
= FS_INOTIFY
,
1032 .procname
= "inotify",
1034 .child
= inotify_table
,
1039 .ctl_name
= KERN_SETUID_DUMPABLE
,
1040 .procname
= "suid_dumpable",
1041 .data
= &suid_dumpable
,
1042 .maxlen
= sizeof(int),
1044 .proc_handler
= &proc_dointvec
,
1049 static ctl_table debug_table
[] = {
1053 static ctl_table dev_table
[] = {
1057 extern void init_irq_proc (void);
1059 static DEFINE_SPINLOCK(sysctl_lock
);
1061 /* called under sysctl_lock */
1062 static int use_table(struct ctl_table_header
*p
)
1064 if (unlikely(p
->unregistering
))
1070 /* called under sysctl_lock */
1071 static void unuse_table(struct ctl_table_header
*p
)
1074 if (unlikely(p
->unregistering
))
1075 complete(p
->unregistering
);
1078 /* called under sysctl_lock, will reacquire if has to wait */
1079 static void start_unregistering(struct ctl_table_header
*p
)
1082 * if p->used is 0, nobody will ever touch that entry again;
1083 * we'll eliminate all paths to it before dropping sysctl_lock
1085 if (unlikely(p
->used
)) {
1086 struct completion wait
;
1087 init_completion(&wait
);
1088 p
->unregistering
= &wait
;
1089 spin_unlock(&sysctl_lock
);
1090 wait_for_completion(&wait
);
1091 spin_lock(&sysctl_lock
);
1094 * do not remove from the list until nobody holds it; walking the
1095 * list in do_sysctl() relies on that.
1097 list_del_init(&p
->ctl_entry
);
1100 void __init
sysctl_init(void)
1102 #ifdef CONFIG_PROC_FS
1103 register_proc_table(root_table
, proc_sys_root
, &root_table_header
);
1108 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1109 void __user
*newval
, size_t newlen
)
1111 struct list_head
*tmp
;
1112 int error
= -ENOTDIR
;
1114 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1118 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1121 spin_lock(&sysctl_lock
);
1122 tmp
= &root_table_header
.ctl_entry
;
1124 struct ctl_table_header
*head
=
1125 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1126 void *context
= NULL
;
1128 if (!use_table(head
))
1131 spin_unlock(&sysctl_lock
);
1133 error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1134 newval
, newlen
, head
->ctl_table
,
1138 spin_lock(&sysctl_lock
);
1140 if (error
!= -ENOTDIR
)
1142 } while ((tmp
= tmp
->next
) != &root_table_header
.ctl_entry
);
1143 spin_unlock(&sysctl_lock
);
1147 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1149 struct __sysctl_args tmp
;
1152 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1156 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1157 tmp
.newval
, tmp
.newlen
);
1163 * ctl_perm does NOT grant the superuser all rights automatically, because
1164 * some sysctl variables are readonly even to root.
1167 static int test_perm(int mode
, int op
)
1171 else if (in_egroup_p(0))
1173 if ((mode
& op
& 0007) == op
)
1178 static inline int ctl_perm(ctl_table
*table
, int op
)
1181 error
= security_sysctl(table
, op
);
1184 return test_perm(table
->mode
, op
);
1187 static int parse_table(int __user
*name
, int nlen
,
1188 void __user
*oldval
, size_t __user
*oldlenp
,
1189 void __user
*newval
, size_t newlen
,
1190 ctl_table
*table
, void **context
)
1196 if (get_user(n
, name
))
1198 for ( ; table
->ctl_name
; table
++) {
1199 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1202 if (ctl_perm(table
, 001))
1204 if (table
->strategy
) {
1205 error
= table
->strategy(
1208 newval
, newlen
, context
);
1214 table
= table
->child
;
1217 error
= do_sysctl_strategy(table
, name
, nlen
,
1219 newval
, newlen
, context
);
1226 /* Perform the actual read/write of a sysctl table entry. */
1227 int do_sysctl_strategy (ctl_table
*table
,
1228 int __user
*name
, int nlen
,
1229 void __user
*oldval
, size_t __user
*oldlenp
,
1230 void __user
*newval
, size_t newlen
, void **context
)
1239 if (ctl_perm(table
, op
))
1242 if (table
->strategy
) {
1243 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1244 newval
, newlen
, context
);
1251 /* If there is no strategy routine, or if the strategy returns
1252 * zero, proceed with automatic r/w */
1253 if (table
->data
&& table
->maxlen
) {
1254 if (oldval
&& oldlenp
) {
1255 if (get_user(len
, oldlenp
))
1258 if (len
> table
->maxlen
)
1259 len
= table
->maxlen
;
1260 if(copy_to_user(oldval
, table
->data
, len
))
1262 if(put_user(len
, oldlenp
))
1266 if (newval
&& newlen
) {
1268 if (len
> table
->maxlen
)
1269 len
= table
->maxlen
;
1270 if(copy_from_user(table
->data
, newval
, len
))
1278 * register_sysctl_table - register a sysctl hierarchy
1279 * @table: the top-level table structure
1280 * @insert_at_head: whether the entry should be inserted in front or at the end
1282 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1283 * array. An entry with a ctl_name of 0 terminates the table.
1285 * The members of the &ctl_table structure are used as follows:
1287 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1288 * must be unique within that level of sysctl
1290 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1291 * enter a sysctl file
1293 * data - a pointer to data for use by proc_handler
1295 * maxlen - the maximum size in bytes of the data
1297 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1299 * child - a pointer to the child sysctl table if this entry is a directory, or
1302 * proc_handler - the text handler routine (described below)
1304 * strategy - the strategy routine (described below)
1306 * de - for internal use by the sysctl routines
1308 * extra1, extra2 - extra pointers usable by the proc handler routines
1310 * Leaf nodes in the sysctl tree will be represented by a single file
1311 * under /proc; non-leaf nodes will be represented by directories.
1313 * sysctl(2) can automatically manage read and write requests through
1314 * the sysctl table. The data and maxlen fields of the ctl_table
1315 * struct enable minimal validation of the values being written to be
1316 * performed, and the mode field allows minimal authentication.
1318 * More sophisticated management can be enabled by the provision of a
1319 * strategy routine with the table entry. This will be called before
1320 * any automatic read or write of the data is performed.
1322 * The strategy routine may return
1324 * < 0 - Error occurred (error is passed to user process)
1326 * 0 - OK - proceed with automatic read or write.
1328 * > 0 - OK - read or write has been done by the strategy routine, so
1329 * return immediately.
1331 * There must be a proc_handler routine for any terminal nodes
1332 * mirrored under /proc/sys (non-terminals are handled by a built-in
1333 * directory handler). Several default handlers are available to
1334 * cover common cases -
1336 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1337 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1338 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1340 * It is the handler's job to read the input buffer from user memory
1341 * and process it. The handler should return 0 on success.
1343 * This routine returns %NULL on a failure to register, and a pointer
1344 * to the table header on success.
1346 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1349 struct ctl_table_header
*tmp
;
1350 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1353 tmp
->ctl_table
= table
;
1354 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1356 tmp
->unregistering
= NULL
;
1357 spin_lock(&sysctl_lock
);
1359 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1361 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1362 spin_unlock(&sysctl_lock
);
1363 #ifdef CONFIG_PROC_FS
1364 register_proc_table(table
, proc_sys_root
, tmp
);
1370 * unregister_sysctl_table - unregister a sysctl table hierarchy
1371 * @header: the header returned from register_sysctl_table
1373 * Unregisters the sysctl table and all children. proc entries may not
1374 * actually be removed until they are no longer used by anyone.
1376 void unregister_sysctl_table(struct ctl_table_header
* header
)
1379 spin_lock(&sysctl_lock
);
1380 start_unregistering(header
);
1381 #ifdef CONFIG_PROC_FS
1382 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1384 spin_unlock(&sysctl_lock
);
1392 #ifdef CONFIG_PROC_FS
1394 /* Scan the sysctl entries in table and add them all into /proc */
1395 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
, void *set
)
1397 struct proc_dir_entry
*de
;
1401 for (; table
->ctl_name
; table
++) {
1402 /* Can't do anything without a proc name. */
1403 if (!table
->procname
)
1405 /* Maybe we can't do anything with it... */
1406 if (!table
->proc_handler
&& !table
->child
) {
1407 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1412 len
= strlen(table
->procname
);
1416 if (table
->proc_handler
)
1420 for (de
= root
->subdir
; de
; de
= de
->next
) {
1421 if (proc_match(len
, table
->procname
, de
))
1424 /* If the subdir exists already, de is non-NULL */
1428 de
= create_proc_entry(table
->procname
, mode
, root
);
1432 de
->data
= (void *) table
;
1433 if (table
->proc_handler
)
1434 de
->proc_fops
= &proc_sys_file_operations
;
1437 if (de
->mode
& S_IFDIR
)
1438 register_proc_table(table
->child
, de
, set
);
1443 * Unregister a /proc sysctl table and any subdirectories.
1445 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1447 struct proc_dir_entry
*de
;
1448 for (; table
->ctl_name
; table
++) {
1449 if (!(de
= table
->de
))
1451 if (de
->mode
& S_IFDIR
) {
1452 if (!table
->child
) {
1453 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1456 unregister_proc_table(table
->child
, de
);
1458 /* Don't unregister directories which still have entries.. */
1464 * In any case, mark the entry as goner; we'll keep it
1465 * around if it's busy, but we'll know to do nothing with
1466 * its fields. We are under sysctl_lock here.
1470 /* Don't unregister proc entries that are still being used.. */
1471 if (atomic_read(&de
->count
))
1475 remove_proc_entry(table
->procname
, root
);
1479 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1480 size_t count
, loff_t
*ppos
)
1483 struct proc_dir_entry
*de
= PDE(file
->f_dentry
->d_inode
);
1484 struct ctl_table
*table
;
1486 ssize_t error
= -ENOTDIR
;
1488 spin_lock(&sysctl_lock
);
1489 if (de
&& de
->data
&& use_table(de
->set
)) {
1491 * at that point we know that sysctl was not unregistered
1492 * and won't be until we finish
1494 spin_unlock(&sysctl_lock
);
1495 table
= (struct ctl_table
*) de
->data
;
1496 if (!table
|| !table
->proc_handler
)
1499 op
= (write
? 002 : 004);
1500 if (ctl_perm(table
, op
))
1503 /* careful: calling conventions are nasty here */
1505 error
= (*table
->proc_handler
)(table
, write
, file
,
1510 spin_lock(&sysctl_lock
);
1511 unuse_table(de
->set
);
1513 spin_unlock(&sysctl_lock
);
1517 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1519 if (file
->f_mode
& FMODE_WRITE
) {
1521 * sysctl entries that are not writable,
1522 * are _NOT_ writable, capabilities or not.
1524 if (!(inode
->i_mode
& S_IWUSR
))
1531 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1532 size_t count
, loff_t
*ppos
)
1534 return do_rw_proc(0, file
, buf
, count
, ppos
);
1537 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1538 size_t count
, loff_t
*ppos
)
1540 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1544 * proc_dostring - read a string sysctl
1545 * @table: the sysctl table
1546 * @write: %TRUE if this is a write to the sysctl file
1547 * @filp: the file structure
1548 * @buffer: the user buffer
1549 * @lenp: the size of the user buffer
1550 * @ppos: file position
1552 * Reads/writes a string from/to the user buffer. If the kernel
1553 * buffer provided is not large enough to hold the string, the
1554 * string is truncated. The copied string is %NULL-terminated.
1555 * If the string is being read by the user process, it is copied
1556 * and a newline '\n' is added. It is truncated if the buffer is
1559 * Returns 0 on success.
1561 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1562 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1568 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1569 (*ppos
&& !write
)) {
1577 while (len
< *lenp
) {
1578 if (get_user(c
, p
++))
1580 if (c
== 0 || c
== '\n')
1584 if (len
>= table
->maxlen
)
1585 len
= table
->maxlen
-1;
1586 if(copy_from_user(table
->data
, buffer
, len
))
1588 ((char *) table
->data
)[len
] = 0;
1591 len
= strlen(table
->data
);
1592 if (len
> table
->maxlen
)
1593 len
= table
->maxlen
;
1597 if(copy_to_user(buffer
, table
->data
, len
))
1600 if(put_user('\n', ((char __user
*) buffer
) + len
))
1611 * Special case of dostring for the UTS structure. This has locks
1612 * to observe. Should this be in kernel/sys.c ????
1615 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1616 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1621 down_read(&uts_sem
);
1622 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1625 down_write(&uts_sem
);
1626 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1632 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1634 int write
, void *data
)
1637 *valp
= *negp
? -*lvalp
: *lvalp
;
1642 *lvalp
= (unsigned long)-val
;
1645 *lvalp
= (unsigned long)val
;
1651 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1652 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1653 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1654 int write
, void *data
),
1657 #define TMPBUFLEN 21
1658 int *i
, vleft
, first
=1, neg
, val
;
1662 char buf
[TMPBUFLEN
], *p
;
1663 char __user
*s
= buffer
;
1665 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1666 (*ppos
&& !write
)) {
1671 i
= (int *) table
->data
;
1672 vleft
= table
->maxlen
/ sizeof(*i
);
1676 conv
= do_proc_dointvec_conv
;
1678 for (; left
&& vleft
--; i
++, first
=0) {
1693 if (len
> sizeof(buf
) - 1)
1694 len
= sizeof(buf
) - 1;
1695 if (copy_from_user(buf
, s
, len
))
1699 if (*p
== '-' && left
> 1) {
1703 if (*p
< '0' || *p
> '9')
1706 lval
= simple_strtoul(p
, &p
, 0);
1709 if ((len
< left
) && *p
&& !isspace(*p
))
1716 if (conv(&neg
, &lval
, i
, 1, data
))
1723 if (conv(&neg
, &lval
, i
, 0, data
))
1726 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1730 if(copy_to_user(s
, buf
, len
))
1737 if (!write
&& !first
&& left
) {
1738 if(put_user('\n', s
))
1745 if (get_user(c
, s
++))
1761 * proc_dointvec - read a vector of integers
1762 * @table: the sysctl table
1763 * @write: %TRUE if this is a write to the sysctl file
1764 * @filp: the file structure
1765 * @buffer: the user buffer
1766 * @lenp: the size of the user buffer
1767 * @ppos: file position
1769 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1770 * values from/to the user buffer, treated as an ASCII string.
1772 * Returns 0 on success.
1774 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1775 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1777 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1787 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1789 int write
, void *data
)
1791 int op
= *(int *)data
;
1793 int val
= *negp
? -*lvalp
: *lvalp
;
1795 case OP_SET
: *valp
= val
; break;
1796 case OP_AND
: *valp
&= val
; break;
1797 case OP_OR
: *valp
|= val
; break;
1798 case OP_MAX
: if(*valp
< val
)
1801 case OP_MIN
: if(*valp
> val
)
1809 *lvalp
= (unsigned long)-val
;
1812 *lvalp
= (unsigned long)val
;
1819 * init may raise the set.
1822 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1823 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1827 if (!capable(CAP_SYS_MODULE
)) {
1831 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1832 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1833 do_proc_dointvec_bset_conv
,&op
);
1836 struct do_proc_dointvec_minmax_conv_param
{
1841 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1843 int write
, void *data
)
1845 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1847 int val
= *negp
? -*lvalp
: *lvalp
;
1848 if ((param
->min
&& *param
->min
> val
) ||
1849 (param
->max
&& *param
->max
< val
))
1856 *lvalp
= (unsigned long)-val
;
1859 *lvalp
= (unsigned long)val
;
1866 * proc_dointvec_minmax - read a vector of integers with min/max values
1867 * @table: the sysctl table
1868 * @write: %TRUE if this is a write to the sysctl file
1869 * @filp: the file structure
1870 * @buffer: the user buffer
1871 * @lenp: the size of the user buffer
1872 * @ppos: file position
1874 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1875 * values from/to the user buffer, treated as an ASCII string.
1877 * This routine will ensure the values are within the range specified by
1878 * table->extra1 (min) and table->extra2 (max).
1880 * Returns 0 on success.
1882 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1883 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1885 struct do_proc_dointvec_minmax_conv_param param
= {
1886 .min
= (int *) table
->extra1
,
1887 .max
= (int *) table
->extra2
,
1889 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1890 do_proc_dointvec_minmax_conv
, ¶m
);
1893 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1895 void __user
*buffer
,
1896 size_t *lenp
, loff_t
*ppos
,
1897 unsigned long convmul
,
1898 unsigned long convdiv
)
1900 #define TMPBUFLEN 21
1901 unsigned long *i
, *min
, *max
, val
;
1902 int vleft
, first
=1, neg
;
1904 char buf
[TMPBUFLEN
], *p
;
1905 char __user
*s
= buffer
;
1907 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1908 (*ppos
&& !write
)) {
1913 i
= (unsigned long *) table
->data
;
1914 min
= (unsigned long *) table
->extra1
;
1915 max
= (unsigned long *) table
->extra2
;
1916 vleft
= table
->maxlen
/ sizeof(unsigned long);
1919 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1934 if (len
> TMPBUFLEN
-1)
1936 if (copy_from_user(buf
, s
, len
))
1940 if (*p
== '-' && left
> 1) {
1944 if (*p
< '0' || *p
> '9')
1946 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1948 if ((len
< left
) && *p
&& !isspace(*p
))
1957 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1964 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1968 if(copy_to_user(s
, buf
, len
))
1975 if (!write
&& !first
&& left
) {
1976 if(put_user('\n', s
))
1983 if (get_user(c
, s
++))
1999 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2000 * @table: the sysctl table
2001 * @write: %TRUE if this is a write to the sysctl file
2002 * @filp: the file structure
2003 * @buffer: the user buffer
2004 * @lenp: the size of the user buffer
2005 * @ppos: file position
2007 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2008 * values from/to the user buffer, treated as an ASCII string.
2010 * This routine will ensure the values are within the range specified by
2011 * table->extra1 (min) and table->extra2 (max).
2013 * Returns 0 on success.
2015 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2016 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2018 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
2022 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2023 * @table: the sysctl table
2024 * @write: %TRUE if this is a write to the sysctl file
2025 * @filp: the file structure
2026 * @buffer: the user buffer
2027 * @lenp: the size of the user buffer
2028 * @ppos: file position
2030 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2031 * values from/to the user buffer, treated as an ASCII string. The values
2032 * are treated as milliseconds, and converted to jiffies when they are stored.
2034 * This routine will ensure the values are within the range specified by
2035 * table->extra1 (min) and table->extra2 (max).
2037 * Returns 0 on success.
2039 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2041 void __user
*buffer
,
2042 size_t *lenp
, loff_t
*ppos
)
2044 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
2045 lenp
, ppos
, HZ
, 1000l);
2049 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
2051 int write
, void *data
)
2054 if (*lvalp
> LONG_MAX
/ HZ
)
2056 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2062 lval
= (unsigned long)-val
;
2065 lval
= (unsigned long)val
;
2072 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2074 int write
, void *data
)
2077 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2079 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2085 lval
= (unsigned long)-val
;
2088 lval
= (unsigned long)val
;
2090 *lvalp
= jiffies_to_clock_t(lval
);
2095 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2097 int write
, void *data
)
2100 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2106 lval
= (unsigned long)-val
;
2109 lval
= (unsigned long)val
;
2111 *lvalp
= jiffies_to_msecs(lval
);
2117 * proc_dointvec_jiffies - read a vector of integers as seconds
2118 * @table: the sysctl table
2119 * @write: %TRUE if this is a write to the sysctl file
2120 * @filp: the file structure
2121 * @buffer: the user buffer
2122 * @lenp: the size of the user buffer
2123 * @ppos: file position
2125 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2126 * values from/to the user buffer, treated as an ASCII string.
2127 * The values read are assumed to be in seconds, and are converted into
2130 * Returns 0 on success.
2132 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2133 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2135 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2136 do_proc_dointvec_jiffies_conv
,NULL
);
2140 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2141 * @table: the sysctl table
2142 * @write: %TRUE if this is a write to the sysctl file
2143 * @filp: the file structure
2144 * @buffer: the user buffer
2145 * @lenp: the size of the user buffer
2146 * @ppos: pointer to the file position
2148 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2149 * values from/to the user buffer, treated as an ASCII string.
2150 * The values read are assumed to be in 1/USER_HZ seconds, and
2151 * are converted into jiffies.
2153 * Returns 0 on success.
2155 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2156 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2158 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2159 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2163 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2164 * @table: the sysctl table
2165 * @write: %TRUE if this is a write to the sysctl file
2166 * @filp: the file structure
2167 * @buffer: the user buffer
2168 * @lenp: the size of the user buffer
2169 * @ppos: file position
2170 * @ppos: the current position in the file
2172 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2173 * values from/to the user buffer, treated as an ASCII string.
2174 * The values read are assumed to be in 1/1000 seconds, and
2175 * are converted into jiffies.
2177 * Returns 0 on success.
2179 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2180 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2182 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2183 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2186 #else /* CONFIG_PROC_FS */
2188 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2189 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2194 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2195 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2200 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2201 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2206 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2207 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2212 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2213 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2218 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2219 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2224 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2225 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2230 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2231 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2236 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2237 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2242 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2244 void __user
*buffer
,
2245 size_t *lenp
, loff_t
*ppos
)
2251 #endif /* CONFIG_PROC_FS */
2255 * General sysctl support routines
2258 /* The generic string strategy routine: */
2259 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2260 void __user
*oldval
, size_t __user
*oldlenp
,
2261 void __user
*newval
, size_t newlen
, void **context
)
2263 if (!table
->data
|| !table
->maxlen
)
2266 if (oldval
&& oldlenp
) {
2268 if (get_user(bufsize
, oldlenp
))
2271 size_t len
= strlen(table
->data
), copied
;
2273 /* This shouldn't trigger for a well-formed sysctl */
2274 if (len
> table
->maxlen
)
2275 len
= table
->maxlen
;
2277 /* Copy up to a max of bufsize-1 bytes of the string */
2278 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2280 if (copy_to_user(oldval
, table
->data
, copied
) ||
2281 put_user(0, (char __user
*)(oldval
+ copied
)))
2283 if (put_user(len
, oldlenp
))
2287 if (newval
&& newlen
) {
2288 size_t len
= newlen
;
2289 if (len
> table
->maxlen
)
2290 len
= table
->maxlen
;
2291 if(copy_from_user(table
->data
, newval
, len
))
2293 if (len
== table
->maxlen
)
2295 ((char *) table
->data
)[len
] = 0;
2301 * This function makes sure that all of the integers in the vector
2302 * are between the minimum and maximum values given in the arrays
2303 * table->extra1 and table->extra2, respectively.
2305 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2306 void __user
*oldval
, size_t __user
*oldlenp
,
2307 void __user
*newval
, size_t newlen
, void **context
)
2310 if (newval
&& newlen
) {
2311 int __user
*vec
= (int __user
*) newval
;
2312 int *min
= (int *) table
->extra1
;
2313 int *max
= (int *) table
->extra2
;
2317 if (newlen
% sizeof(int) != 0)
2320 if (!table
->extra1
&& !table
->extra2
)
2323 if (newlen
> table
->maxlen
)
2324 newlen
= table
->maxlen
;
2325 length
= newlen
/ sizeof(int);
2327 for (i
= 0; i
< length
; i
++) {
2329 if (get_user(value
, vec
+ i
))
2331 if (min
&& value
< min
[i
])
2333 if (max
&& value
> max
[i
])
2340 /* Strategy function to convert jiffies to seconds */
2341 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2342 void __user
*oldval
, size_t __user
*oldlenp
,
2343 void __user
*newval
, size_t newlen
, void **context
)
2348 if (get_user(olen
, oldlenp
))
2350 if (olen
!=sizeof(int))
2353 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2354 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2357 if (newval
&& newlen
) {
2359 if (newlen
!= sizeof(int))
2361 if (get_user(new, (int __user
*)newval
))
2363 *(int *)(table
->data
) = new*HZ
;
2368 /* Strategy function to convert jiffies to seconds */
2369 int sysctl_ms_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(jiffies_to_msecs(*(int *)(table
->data
)), (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
) = msecs_to_jiffies(new);
2396 #else /* CONFIG_SYSCTL */
2399 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2404 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2405 void __user
*oldval
, size_t __user
*oldlenp
,
2406 void __user
*newval
, size_t newlen
, void **context
)
2411 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2412 void __user
*oldval
, size_t __user
*oldlenp
,
2413 void __user
*newval
, size_t newlen
, void **context
)
2418 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2419 void __user
*oldval
, size_t __user
*oldlenp
,
2420 void __user
*newval
, size_t newlen
, void **context
)
2425 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2426 void __user
*oldval
, size_t __user
*oldlenp
,
2427 void __user
*newval
, size_t newlen
, void **context
)
2432 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2433 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2438 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2439 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2444 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2445 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2450 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2451 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2456 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2457 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2462 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2463 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2468 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2469 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2474 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2475 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2480 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2482 void __user
*buffer
,
2483 size_t *lenp
, loff_t
*ppos
)
2488 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2494 void unregister_sysctl_table(struct ctl_table_header
* table
)
2498 #endif /* CONFIG_SYSCTL */
2501 * No sense putting this after each symbol definition, twice,
2502 * exception granted :-)
2504 EXPORT_SYMBOL(proc_dointvec
);
2505 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2506 EXPORT_SYMBOL(proc_dointvec_minmax
);
2507 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2508 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2509 EXPORT_SYMBOL(proc_dostring
);
2510 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2511 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2512 EXPORT_SYMBOL(register_sysctl_table
);
2513 EXPORT_SYMBOL(sysctl_intvec
);
2514 EXPORT_SYMBOL(sysctl_jiffies
);
2515 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2516 EXPORT_SYMBOL(sysctl_string
);
2517 EXPORT_SYMBOL(unregister_sysctl_table
);