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 #if defined(CONFIG_SYSCTL)
55 /* External variables not in a header file. */
57 extern int sysctl_overcommit_memory
;
58 extern int sysctl_overcommit_ratio
;
59 extern int max_threads
;
60 extern int sysrq_enabled
;
61 extern int core_uses_pid
;
62 extern int suid_dumpable
;
63 extern char core_pattern
[];
66 extern int min_free_kbytes
;
67 extern int printk_ratelimit_jiffies
;
68 extern int printk_ratelimit_burst
;
69 extern int pid_max_min
, pid_max_max
;
70 extern int sysctl_drop_caches
;
71 extern int percpu_pagelist_fraction
;
73 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
74 int unknown_nmi_panic
;
75 extern int proc_unknown_nmi_panic(ctl_table
*, int, struct file
*,
76 void __user
*, size_t *, loff_t
*);
79 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
80 static int maxolduid
= 65535;
82 static int min_percpu_pagelist_fract
= 8;
84 static int ngroups_max
= NGROUPS_MAX
;
87 extern char modprobe_path
[];
89 #ifdef CONFIG_CHR_DEV_SG
90 extern int sg_big_buff
;
93 extern size_t shm_ctlmax
;
94 extern size_t shm_ctlall
;
95 extern int shm_ctlmni
;
96 extern int msg_ctlmax
;
97 extern int msg_ctlmnb
;
98 extern int msg_ctlmni
;
99 extern int sem_ctls
[];
103 extern char reboot_command
[];
104 extern int stop_a_enabled
;
105 extern int scons_pwroff
;
109 extern int pwrsw_enabled
;
110 extern int unaligned_enabled
;
114 #ifdef CONFIG_MATHEMU
115 extern int sysctl_ieee_emulation_warnings
;
117 extern int sysctl_userprocess_debug
;
118 extern int spin_retry
;
121 extern int sysctl_hz_timer
;
123 #ifdef CONFIG_BSD_PROCESS_ACCT
124 extern int acct_parm
[];
128 extern int no_unaligned_warning
;
131 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
132 ctl_table
*, void **);
133 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
134 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
136 static ctl_table root_table
[];
137 static struct ctl_table_header root_table_header
=
138 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
140 static ctl_table kern_table
[];
141 static ctl_table vm_table
[];
142 static ctl_table proc_table
[];
143 static ctl_table fs_table
[];
144 static ctl_table debug_table
[];
145 static ctl_table dev_table
[];
146 extern ctl_table random_table
[];
147 #ifdef CONFIG_UNIX98_PTYS
148 extern ctl_table pty_table
[];
150 #ifdef CONFIG_INOTIFY
151 extern ctl_table inotify_table
[];
154 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
155 int sysctl_legacy_va_layout
;
158 /* /proc declarations: */
160 #ifdef CONFIG_PROC_FS
162 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
163 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
164 static int proc_opensys(struct inode
*, struct file
*);
166 struct file_operations proc_sys_file_operations
= {
167 .open
= proc_opensys
,
168 .read
= proc_readsys
,
169 .write
= proc_writesys
,
172 extern struct proc_dir_entry
*proc_sys_root
;
174 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*, void *);
175 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
178 /* The default sysctl tables: */
180 static ctl_table root_table
[] = {
182 .ctl_name
= CTL_KERN
,
183 .procname
= "kernel",
202 .ctl_name
= CTL_PROC
,
214 .ctl_name
= CTL_DEBUG
,
217 .child
= debug_table
,
229 static ctl_table kern_table
[] = {
231 .ctl_name
= KERN_OSTYPE
,
232 .procname
= "ostype",
233 .data
= system_utsname
.sysname
,
234 .maxlen
= sizeof(system_utsname
.sysname
),
236 .proc_handler
= &proc_doutsstring
,
237 .strategy
= &sysctl_string
,
240 .ctl_name
= KERN_OSRELEASE
,
241 .procname
= "osrelease",
242 .data
= system_utsname
.release
,
243 .maxlen
= sizeof(system_utsname
.release
),
245 .proc_handler
= &proc_doutsstring
,
246 .strategy
= &sysctl_string
,
249 .ctl_name
= KERN_VERSION
,
250 .procname
= "version",
251 .data
= system_utsname
.version
,
252 .maxlen
= sizeof(system_utsname
.version
),
254 .proc_handler
= &proc_doutsstring
,
255 .strategy
= &sysctl_string
,
258 .ctl_name
= KERN_NODENAME
,
259 .procname
= "hostname",
260 .data
= system_utsname
.nodename
,
261 .maxlen
= sizeof(system_utsname
.nodename
),
263 .proc_handler
= &proc_doutsstring
,
264 .strategy
= &sysctl_string
,
267 .ctl_name
= KERN_DOMAINNAME
,
268 .procname
= "domainname",
269 .data
= system_utsname
.domainname
,
270 .maxlen
= sizeof(system_utsname
.domainname
),
272 .proc_handler
= &proc_doutsstring
,
273 .strategy
= &sysctl_string
,
276 .ctl_name
= KERN_PANIC
,
278 .data
= &panic_timeout
,
279 .maxlen
= sizeof(int),
281 .proc_handler
= &proc_dointvec
,
284 .ctl_name
= KERN_CORE_USES_PID
,
285 .procname
= "core_uses_pid",
286 .data
= &core_uses_pid
,
287 .maxlen
= sizeof(int),
289 .proc_handler
= &proc_dointvec
,
292 .ctl_name
= KERN_CORE_PATTERN
,
293 .procname
= "core_pattern",
294 .data
= core_pattern
,
297 .proc_handler
= &proc_dostring
,
298 .strategy
= &sysctl_string
,
301 .ctl_name
= KERN_TAINTED
,
302 .procname
= "tainted",
304 .maxlen
= sizeof(int),
306 .proc_handler
= &proc_dointvec
,
309 .ctl_name
= KERN_CAP_BSET
,
310 .procname
= "cap-bound",
312 .maxlen
= sizeof(kernel_cap_t
),
314 .proc_handler
= &proc_dointvec_bset
,
316 #ifdef CONFIG_BLK_DEV_INITRD
318 .ctl_name
= KERN_REALROOTDEV
,
319 .procname
= "real-root-dev",
320 .data
= &real_root_dev
,
321 .maxlen
= sizeof(int),
323 .proc_handler
= &proc_dointvec
,
328 .ctl_name
= KERN_SPARC_REBOOT
,
329 .procname
= "reboot-cmd",
330 .data
= reboot_command
,
333 .proc_handler
= &proc_dostring
,
334 .strategy
= &sysctl_string
,
337 .ctl_name
= KERN_SPARC_STOP_A
,
338 .procname
= "stop-a",
339 .data
= &stop_a_enabled
,
340 .maxlen
= sizeof (int),
342 .proc_handler
= &proc_dointvec
,
345 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
346 .procname
= "scons-poweroff",
347 .data
= &scons_pwroff
,
348 .maxlen
= sizeof (int),
350 .proc_handler
= &proc_dointvec
,
355 .ctl_name
= KERN_HPPA_PWRSW
,
356 .procname
= "soft-power",
357 .data
= &pwrsw_enabled
,
358 .maxlen
= sizeof (int),
360 .proc_handler
= &proc_dointvec
,
363 .ctl_name
= KERN_HPPA_UNALIGNED
,
364 .procname
= "unaligned-trap",
365 .data
= &unaligned_enabled
,
366 .maxlen
= sizeof (int),
368 .proc_handler
= &proc_dointvec
,
372 .ctl_name
= KERN_CTLALTDEL
,
373 .procname
= "ctrl-alt-del",
375 .maxlen
= sizeof(int),
377 .proc_handler
= &proc_dointvec
,
380 .ctl_name
= KERN_PRINTK
,
381 .procname
= "printk",
382 .data
= &console_loglevel
,
383 .maxlen
= 4*sizeof(int),
385 .proc_handler
= &proc_dointvec
,
389 .ctl_name
= KERN_MODPROBE
,
390 .procname
= "modprobe",
391 .data
= &modprobe_path
,
392 .maxlen
= KMOD_PATH_LEN
,
394 .proc_handler
= &proc_dostring
,
395 .strategy
= &sysctl_string
,
398 #ifdef CONFIG_HOTPLUG
400 .ctl_name
= KERN_HOTPLUG
,
401 .procname
= "hotplug",
402 .data
= &uevent_helper
,
403 .maxlen
= UEVENT_HELPER_PATH_LEN
,
405 .proc_handler
= &proc_dostring
,
406 .strategy
= &sysctl_string
,
409 #ifdef CONFIG_CHR_DEV_SG
411 .ctl_name
= KERN_SG_BIG_BUFF
,
412 .procname
= "sg-big-buff",
413 .data
= &sg_big_buff
,
414 .maxlen
= sizeof (int),
416 .proc_handler
= &proc_dointvec
,
419 #ifdef CONFIG_BSD_PROCESS_ACCT
421 .ctl_name
= KERN_ACCT
,
424 .maxlen
= 3*sizeof(int),
426 .proc_handler
= &proc_dointvec
,
429 #ifdef CONFIG_SYSVIPC
431 .ctl_name
= KERN_SHMMAX
,
432 .procname
= "shmmax",
434 .maxlen
= sizeof (size_t),
436 .proc_handler
= &proc_doulongvec_minmax
,
439 .ctl_name
= KERN_SHMALL
,
440 .procname
= "shmall",
442 .maxlen
= sizeof (size_t),
444 .proc_handler
= &proc_doulongvec_minmax
,
447 .ctl_name
= KERN_SHMMNI
,
448 .procname
= "shmmni",
450 .maxlen
= sizeof (int),
452 .proc_handler
= &proc_dointvec
,
455 .ctl_name
= KERN_MSGMAX
,
456 .procname
= "msgmax",
458 .maxlen
= sizeof (int),
460 .proc_handler
= &proc_dointvec
,
463 .ctl_name
= KERN_MSGMNI
,
464 .procname
= "msgmni",
466 .maxlen
= sizeof (int),
468 .proc_handler
= &proc_dointvec
,
471 .ctl_name
= KERN_MSGMNB
,
472 .procname
= "msgmnb",
474 .maxlen
= sizeof (int),
476 .proc_handler
= &proc_dointvec
,
479 .ctl_name
= KERN_SEM
,
482 .maxlen
= 4*sizeof (int),
484 .proc_handler
= &proc_dointvec
,
487 #ifdef CONFIG_MAGIC_SYSRQ
489 .ctl_name
= KERN_SYSRQ
,
491 .data
= &sysrq_enabled
,
492 .maxlen
= sizeof (int),
494 .proc_handler
= &proc_dointvec
,
498 .ctl_name
= KERN_CADPID
,
499 .procname
= "cad_pid",
501 .maxlen
= sizeof (int),
503 .proc_handler
= &proc_dointvec
,
506 .ctl_name
= KERN_MAX_THREADS
,
507 .procname
= "threads-max",
508 .data
= &max_threads
,
509 .maxlen
= sizeof(int),
511 .proc_handler
= &proc_dointvec
,
514 .ctl_name
= KERN_RANDOM
,
515 .procname
= "random",
517 .child
= random_table
,
519 #ifdef CONFIG_UNIX98_PTYS
521 .ctl_name
= KERN_PTY
,
528 .ctl_name
= KERN_OVERFLOWUID
,
529 .procname
= "overflowuid",
530 .data
= &overflowuid
,
531 .maxlen
= sizeof(int),
533 .proc_handler
= &proc_dointvec_minmax
,
534 .strategy
= &sysctl_intvec
,
535 .extra1
= &minolduid
,
536 .extra2
= &maxolduid
,
539 .ctl_name
= KERN_OVERFLOWGID
,
540 .procname
= "overflowgid",
541 .data
= &overflowgid
,
542 .maxlen
= sizeof(int),
544 .proc_handler
= &proc_dointvec_minmax
,
545 .strategy
= &sysctl_intvec
,
546 .extra1
= &minolduid
,
547 .extra2
= &maxolduid
,
550 #ifdef CONFIG_MATHEMU
552 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
553 .procname
= "ieee_emulation_warnings",
554 .data
= &sysctl_ieee_emulation_warnings
,
555 .maxlen
= sizeof(int),
557 .proc_handler
= &proc_dointvec
,
560 #ifdef CONFIG_NO_IDLE_HZ
562 .ctl_name
= KERN_HZ_TIMER
,
563 .procname
= "hz_timer",
564 .data
= &sysctl_hz_timer
,
565 .maxlen
= sizeof(int),
567 .proc_handler
= &proc_dointvec
,
571 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
572 .procname
= "userprocess_debug",
573 .data
= &sysctl_userprocess_debug
,
574 .maxlen
= sizeof(int),
576 .proc_handler
= &proc_dointvec
,
580 .ctl_name
= KERN_PIDMAX
,
581 .procname
= "pid_max",
583 .maxlen
= sizeof (int),
585 .proc_handler
= &proc_dointvec_minmax
,
586 .strategy
= sysctl_intvec
,
587 .extra1
= &pid_max_min
,
588 .extra2
= &pid_max_max
,
591 .ctl_name
= KERN_PANIC_ON_OOPS
,
592 .procname
= "panic_on_oops",
593 .data
= &panic_on_oops
,
594 .maxlen
= sizeof(int),
596 .proc_handler
= &proc_dointvec
,
599 .ctl_name
= KERN_PRINTK_RATELIMIT
,
600 .procname
= "printk_ratelimit",
601 .data
= &printk_ratelimit_jiffies
,
602 .maxlen
= sizeof(int),
604 .proc_handler
= &proc_dointvec_jiffies
,
605 .strategy
= &sysctl_jiffies
,
608 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
609 .procname
= "printk_ratelimit_burst",
610 .data
= &printk_ratelimit_burst
,
611 .maxlen
= sizeof(int),
613 .proc_handler
= &proc_dointvec
,
616 .ctl_name
= KERN_NGROUPS_MAX
,
617 .procname
= "ngroups_max",
618 .data
= &ngroups_max
,
619 .maxlen
= sizeof (int),
621 .proc_handler
= &proc_dointvec
,
623 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
625 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
626 .procname
= "unknown_nmi_panic",
627 .data
= &unknown_nmi_panic
,
628 .maxlen
= sizeof (int),
630 .proc_handler
= &proc_unknown_nmi_panic
,
633 #if defined(CONFIG_X86)
635 .ctl_name
= KERN_BOOTLOADER_TYPE
,
636 .procname
= "bootloader_type",
637 .data
= &bootloader_type
,
638 .maxlen
= sizeof (int),
640 .proc_handler
= &proc_dointvec
,
643 #if defined(CONFIG_MMU)
645 .ctl_name
= KERN_RANDOMIZE
,
646 .procname
= "randomize_va_space",
647 .data
= &randomize_va_space
,
648 .maxlen
= sizeof(int),
650 .proc_handler
= &proc_dointvec
,
653 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
655 .ctl_name
= KERN_SPIN_RETRY
,
656 .procname
= "spin_retry",
658 .maxlen
= sizeof (int),
660 .proc_handler
= &proc_dointvec
,
663 #ifdef CONFIG_ACPI_SLEEP
665 .ctl_name
= KERN_ACPI_VIDEO_FLAGS
,
666 .procname
= "acpi_video_flags",
667 .data
= &acpi_video_flags
,
668 .maxlen
= sizeof (unsigned long),
670 .proc_handler
= &proc_doulongvec_minmax
,
675 .ctl_name
= KERN_IA64_UNALIGNED
,
676 .procname
= "ignore-unaligned-usertrap",
677 .data
= &no_unaligned_warning
,
678 .maxlen
= sizeof (int),
680 .proc_handler
= &proc_dointvec
,
686 /* Constants for minimum and maximum testing in vm_table.
687 We use these as one-element integer vectors. */
689 static int one_hundred
= 100;
692 static ctl_table vm_table
[] = {
694 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
695 .procname
= "overcommit_memory",
696 .data
= &sysctl_overcommit_memory
,
697 .maxlen
= sizeof(sysctl_overcommit_memory
),
699 .proc_handler
= &proc_dointvec
,
702 .ctl_name
= VM_OVERCOMMIT_RATIO
,
703 .procname
= "overcommit_ratio",
704 .data
= &sysctl_overcommit_ratio
,
705 .maxlen
= sizeof(sysctl_overcommit_ratio
),
707 .proc_handler
= &proc_dointvec
,
710 .ctl_name
= VM_PAGE_CLUSTER
,
711 .procname
= "page-cluster",
712 .data
= &page_cluster
,
713 .maxlen
= sizeof(int),
715 .proc_handler
= &proc_dointvec
,
718 .ctl_name
= VM_DIRTY_BACKGROUND
,
719 .procname
= "dirty_background_ratio",
720 .data
= &dirty_background_ratio
,
721 .maxlen
= sizeof(dirty_background_ratio
),
723 .proc_handler
= &proc_dointvec_minmax
,
724 .strategy
= &sysctl_intvec
,
726 .extra2
= &one_hundred
,
729 .ctl_name
= VM_DIRTY_RATIO
,
730 .procname
= "dirty_ratio",
731 .data
= &vm_dirty_ratio
,
732 .maxlen
= sizeof(vm_dirty_ratio
),
734 .proc_handler
= &proc_dointvec_minmax
,
735 .strategy
= &sysctl_intvec
,
737 .extra2
= &one_hundred
,
740 .ctl_name
= VM_DIRTY_WB_CS
,
741 .procname
= "dirty_writeback_centisecs",
742 .data
= &dirty_writeback_centisecs
,
743 .maxlen
= sizeof(dirty_writeback_centisecs
),
745 .proc_handler
= &dirty_writeback_centisecs_handler
,
748 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
749 .procname
= "dirty_expire_centisecs",
750 .data
= &dirty_expire_centisecs
,
751 .maxlen
= sizeof(dirty_expire_centisecs
),
753 .proc_handler
= &proc_dointvec
,
756 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
757 .procname
= "nr_pdflush_threads",
758 .data
= &nr_pdflush_threads
,
759 .maxlen
= sizeof nr_pdflush_threads
,
760 .mode
= 0444 /* read-only*/,
761 .proc_handler
= &proc_dointvec
,
764 .ctl_name
= VM_SWAPPINESS
,
765 .procname
= "swappiness",
766 .data
= &vm_swappiness
,
767 .maxlen
= sizeof(vm_swappiness
),
769 .proc_handler
= &proc_dointvec_minmax
,
770 .strategy
= &sysctl_intvec
,
772 .extra2
= &one_hundred
,
774 #ifdef CONFIG_HUGETLB_PAGE
776 .ctl_name
= VM_HUGETLB_PAGES
,
777 .procname
= "nr_hugepages",
778 .data
= &max_huge_pages
,
779 .maxlen
= sizeof(unsigned long),
781 .proc_handler
= &hugetlb_sysctl_handler
,
782 .extra1
= (void *)&hugetlb_zero
,
783 .extra2
= (void *)&hugetlb_infinity
,
786 .ctl_name
= VM_HUGETLB_GROUP
,
787 .procname
= "hugetlb_shm_group",
788 .data
= &sysctl_hugetlb_shm_group
,
789 .maxlen
= sizeof(gid_t
),
791 .proc_handler
= &proc_dointvec
,
795 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
796 .procname
= "lowmem_reserve_ratio",
797 .data
= &sysctl_lowmem_reserve_ratio
,
798 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
800 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
801 .strategy
= &sysctl_intvec
,
804 .ctl_name
= VM_DROP_PAGECACHE
,
805 .procname
= "drop_caches",
806 .data
= &sysctl_drop_caches
,
807 .maxlen
= sizeof(int),
809 .proc_handler
= drop_caches_sysctl_handler
,
810 .strategy
= &sysctl_intvec
,
813 .ctl_name
= VM_MIN_FREE_KBYTES
,
814 .procname
= "min_free_kbytes",
815 .data
= &min_free_kbytes
,
816 .maxlen
= sizeof(min_free_kbytes
),
818 .proc_handler
= &min_free_kbytes_sysctl_handler
,
819 .strategy
= &sysctl_intvec
,
823 .ctl_name
= VM_PERCPU_PAGELIST_FRACTION
,
824 .procname
= "percpu_pagelist_fraction",
825 .data
= &percpu_pagelist_fraction
,
826 .maxlen
= sizeof(percpu_pagelist_fraction
),
828 .proc_handler
= &percpu_pagelist_fraction_sysctl_handler
,
829 .strategy
= &sysctl_intvec
,
830 .extra1
= &min_percpu_pagelist_fract
,
834 .ctl_name
= VM_MAX_MAP_COUNT
,
835 .procname
= "max_map_count",
836 .data
= &sysctl_max_map_count
,
837 .maxlen
= sizeof(sysctl_max_map_count
),
839 .proc_handler
= &proc_dointvec
843 .ctl_name
= VM_LAPTOP_MODE
,
844 .procname
= "laptop_mode",
845 .data
= &laptop_mode
,
846 .maxlen
= sizeof(laptop_mode
),
848 .proc_handler
= &proc_dointvec
,
849 .strategy
= &sysctl_intvec
,
853 .ctl_name
= VM_BLOCK_DUMP
,
854 .procname
= "block_dump",
856 .maxlen
= sizeof(block_dump
),
858 .proc_handler
= &proc_dointvec
,
859 .strategy
= &sysctl_intvec
,
863 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
864 .procname
= "vfs_cache_pressure",
865 .data
= &sysctl_vfs_cache_pressure
,
866 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
868 .proc_handler
= &proc_dointvec
,
869 .strategy
= &sysctl_intvec
,
872 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
874 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
875 .procname
= "legacy_va_layout",
876 .data
= &sysctl_legacy_va_layout
,
877 .maxlen
= sizeof(sysctl_legacy_va_layout
),
879 .proc_handler
= &proc_dointvec
,
880 .strategy
= &sysctl_intvec
,
886 .ctl_name
= VM_SWAP_TOKEN_TIMEOUT
,
887 .procname
= "swap_token_timeout",
888 .data
= &swap_token_default_timeout
,
889 .maxlen
= sizeof(swap_token_default_timeout
),
891 .proc_handler
= &proc_dointvec_jiffies
,
892 .strategy
= &sysctl_jiffies
,
897 .ctl_name
= VM_ZONE_RECLAIM_MODE
,
898 .procname
= "zone_reclaim_mode",
899 .data
= &zone_reclaim_mode
,
900 .maxlen
= sizeof(zone_reclaim_mode
),
902 .proc_handler
= &proc_dointvec
,
903 .strategy
= &sysctl_intvec
,
907 .ctl_name
= VM_ZONE_RECLAIM_INTERVAL
,
908 .procname
= "zone_reclaim_interval",
909 .data
= &zone_reclaim_interval
,
910 .maxlen
= sizeof(zone_reclaim_interval
),
912 .proc_handler
= &proc_dointvec_jiffies
,
913 .strategy
= &sysctl_jiffies
,
919 static ctl_table proc_table
[] = {
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_dointvec
,
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
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 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2060 lval
= (unsigned long)-val
;
2063 lval
= (unsigned long)val
;
2070 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
2072 int write
, void *data
)
2075 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2081 lval
= (unsigned long)-val
;
2084 lval
= (unsigned long)val
;
2086 *lvalp
= jiffies_to_clock_t(lval
);
2091 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
2093 int write
, void *data
)
2096 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2102 lval
= (unsigned long)-val
;
2105 lval
= (unsigned long)val
;
2107 *lvalp
= jiffies_to_msecs(lval
);
2113 * proc_dointvec_jiffies - read a vector of integers as seconds
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 int) integer
2122 * values from/to the user buffer, treated as an ASCII string.
2123 * The values read are assumed to be in seconds, and are converted into
2126 * Returns 0 on success.
2128 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2129 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2131 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2132 do_proc_dointvec_jiffies_conv
,NULL
);
2136 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2137 * @table: the sysctl table
2138 * @write: %TRUE if this is a write to the sysctl file
2139 * @filp: the file structure
2140 * @buffer: the user buffer
2141 * @lenp: the size of the user buffer
2142 * @ppos: pointer to the file position
2144 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2145 * values from/to the user buffer, treated as an ASCII string.
2146 * The values read are assumed to be in 1/USER_HZ seconds, and
2147 * are converted into jiffies.
2149 * Returns 0 on success.
2151 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2152 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2154 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2155 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2159 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2160 * @table: the sysctl table
2161 * @write: %TRUE if this is a write to the sysctl file
2162 * @filp: the file structure
2163 * @buffer: the user buffer
2164 * @lenp: the size of the user buffer
2165 * @ppos: file position
2166 * @ppos: the current position in the file
2168 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2169 * values from/to the user buffer, treated as an ASCII string.
2170 * The values read are assumed to be in 1/1000 seconds, and
2171 * are converted into jiffies.
2173 * Returns 0 on success.
2175 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2176 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2178 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2179 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2182 #else /* CONFIG_PROC_FS */
2184 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2185 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2190 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2191 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2196 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2197 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2202 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2203 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2208 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2209 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2214 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2215 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2220 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2221 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2226 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2227 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2232 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2233 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2238 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2240 void __user
*buffer
,
2241 size_t *lenp
, loff_t
*ppos
)
2247 #endif /* CONFIG_PROC_FS */
2251 * General sysctl support routines
2254 /* The generic string strategy routine: */
2255 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2256 void __user
*oldval
, size_t __user
*oldlenp
,
2257 void __user
*newval
, size_t newlen
, void **context
)
2259 if (!table
->data
|| !table
->maxlen
)
2262 if (oldval
&& oldlenp
) {
2264 if (get_user(bufsize
, oldlenp
))
2267 size_t len
= strlen(table
->data
), copied
;
2269 /* This shouldn't trigger for a well-formed sysctl */
2270 if (len
> table
->maxlen
)
2271 len
= table
->maxlen
;
2273 /* Copy up to a max of bufsize-1 bytes of the string */
2274 copied
= (len
>= bufsize
) ? bufsize
- 1 : len
;
2276 if (copy_to_user(oldval
, table
->data
, copied
) ||
2277 put_user(0, (char __user
*)(oldval
+ copied
)))
2279 if (put_user(len
, oldlenp
))
2283 if (newval
&& newlen
) {
2284 size_t len
= newlen
;
2285 if (len
> table
->maxlen
)
2286 len
= table
->maxlen
;
2287 if(copy_from_user(table
->data
, newval
, len
))
2289 if (len
== table
->maxlen
)
2291 ((char *) table
->data
)[len
] = 0;
2297 * This function makes sure that all of the integers in the vector
2298 * are between the minimum and maximum values given in the arrays
2299 * table->extra1 and table->extra2, respectively.
2301 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2302 void __user
*oldval
, size_t __user
*oldlenp
,
2303 void __user
*newval
, size_t newlen
, void **context
)
2306 if (newval
&& newlen
) {
2307 int __user
*vec
= (int __user
*) newval
;
2308 int *min
= (int *) table
->extra1
;
2309 int *max
= (int *) table
->extra2
;
2313 if (newlen
% sizeof(int) != 0)
2316 if (!table
->extra1
&& !table
->extra2
)
2319 if (newlen
> table
->maxlen
)
2320 newlen
= table
->maxlen
;
2321 length
= newlen
/ sizeof(int);
2323 for (i
= 0; i
< length
; i
++) {
2325 if (get_user(value
, vec
+ i
))
2327 if (min
&& value
< min
[i
])
2329 if (max
&& value
> max
[i
])
2336 /* Strategy function to convert jiffies to seconds */
2337 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2338 void __user
*oldval
, size_t __user
*oldlenp
,
2339 void __user
*newval
, size_t newlen
, void **context
)
2344 if (get_user(olen
, oldlenp
))
2346 if (olen
!=sizeof(int))
2349 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2350 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2353 if (newval
&& newlen
) {
2355 if (newlen
!= sizeof(int))
2357 if (get_user(new, (int __user
*)newval
))
2359 *(int *)(table
->data
) = new*HZ
;
2364 /* Strategy function to convert jiffies to seconds */
2365 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2366 void __user
*oldval
, size_t __user
*oldlenp
,
2367 void __user
*newval
, size_t newlen
, void **context
)
2372 if (get_user(olen
, oldlenp
))
2374 if (olen
!=sizeof(int))
2377 if (put_user(jiffies_to_msecs(*(int *)(table
->data
)), (int __user
*)oldval
) ||
2378 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2381 if (newval
&& newlen
) {
2383 if (newlen
!= sizeof(int))
2385 if (get_user(new, (int __user
*)newval
))
2387 *(int *)(table
->data
) = msecs_to_jiffies(new);
2392 #else /* CONFIG_SYSCTL */
2395 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2400 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2401 void __user
*oldval
, size_t __user
*oldlenp
,
2402 void __user
*newval
, size_t newlen
, void **context
)
2407 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2408 void __user
*oldval
, size_t __user
*oldlenp
,
2409 void __user
*newval
, size_t newlen
, void **context
)
2414 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2415 void __user
*oldval
, size_t __user
*oldlenp
,
2416 void __user
*newval
, size_t newlen
, void **context
)
2421 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2422 void __user
*oldval
, size_t __user
*oldlenp
,
2423 void __user
*newval
, size_t newlen
, void **context
)
2428 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2429 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2434 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2435 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2440 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2441 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2446 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2447 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2452 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2453 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2458 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2459 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2464 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2465 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2470 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2471 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2476 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2478 void __user
*buffer
,
2479 size_t *lenp
, loff_t
*ppos
)
2484 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2490 void unregister_sysctl_table(struct ctl_table_header
* table
)
2494 #endif /* CONFIG_SYSCTL */
2497 * No sense putting this after each symbol definition, twice,
2498 * exception granted :-)
2500 EXPORT_SYMBOL(proc_dointvec
);
2501 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2502 EXPORT_SYMBOL(proc_dointvec_minmax
);
2503 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2504 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2505 EXPORT_SYMBOL(proc_dostring
);
2506 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2507 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2508 EXPORT_SYMBOL(register_sysctl_table
);
2509 EXPORT_SYMBOL(sysctl_intvec
);
2510 EXPORT_SYMBOL(sysctl_jiffies
);
2511 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2512 EXPORT_SYMBOL(sysctl_string
);
2513 EXPORT_SYMBOL(unregister_sysctl_table
);