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/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/sysrq.h>
35 #include <linux/highuid.h>
36 #include <linux/writeback.h>
37 #include <linux/hugetlb.h>
38 #include <linux/security.h>
39 #include <linux/initrd.h>
40 #include <linux/times.h>
41 #include <linux/limits.h>
42 #include <linux/dcache.h>
43 #include <linux/syscalls.h>
45 #include <asm/uaccess.h>
46 #include <asm/processor.h>
48 #ifdef CONFIG_ROOT_NFS
49 #include <linux/nfs_fs.h>
52 #if defined(CONFIG_SYSCTL)
54 /* External variables not in a header file. */
56 extern int sysctl_overcommit_memory
;
57 extern int sysctl_overcommit_ratio
;
58 extern int max_threads
;
59 extern int sysrq_enabled
;
60 extern int core_uses_pid
;
61 extern int suid_dumpable
;
62 extern char core_pattern
[];
65 extern int min_free_kbytes
;
66 extern int printk_ratelimit_jiffies
;
67 extern int printk_ratelimit_burst
;
68 extern int pid_max_min
, pid_max_max
;
70 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
71 int unknown_nmi_panic
;
72 extern int proc_unknown_nmi_panic(ctl_table
*, int, struct file
*,
73 void __user
*, size_t *, loff_t
*);
76 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
77 static int maxolduid
= 65535;
80 static int ngroups_max
= NGROUPS_MAX
;
83 extern char modprobe_path
[];
86 extern char hotplug_path
[];
88 #ifdef CONFIG_CHR_DEV_SG
89 extern int sg_big_buff
;
92 extern size_t shm_ctlmax
;
93 extern size_t shm_ctlall
;
94 extern int shm_ctlmni
;
95 extern int msg_ctlmax
;
96 extern int msg_ctlmnb
;
97 extern int msg_ctlmni
;
98 extern int sem_ctls
[];
102 extern char reboot_command
[];
103 extern int stop_a_enabled
;
104 extern int scons_pwroff
;
108 extern int pwrsw_enabled
;
109 extern int unaligned_enabled
;
112 #ifdef CONFIG_ARCH_S390
113 #ifdef CONFIG_MATHEMU
114 extern int sysctl_ieee_emulation_warnings
;
116 extern int sysctl_userprocess_debug
;
117 extern int spin_retry
;
120 extern int sysctl_hz_timer
;
122 #ifdef CONFIG_BSD_PROCESS_ACCT
123 extern int acct_parm
[];
126 int randomize_va_space
= 1;
128 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
129 ctl_table
*, void **);
130 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
131 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
133 static ctl_table root_table
[];
134 static struct ctl_table_header root_table_header
=
135 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
137 static ctl_table kern_table
[];
138 static ctl_table vm_table
[];
140 extern ctl_table net_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
*);
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
= &hotplug_path
,
403 .maxlen
= HOTPLUG_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
,
549 #ifdef CONFIG_ARCH_S390
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
,
644 .ctl_name
= KERN_RANDOMIZE
,
645 .procname
= "randomize_va_space",
646 .data
= &randomize_va_space
,
647 .maxlen
= sizeof(int),
649 .proc_handler
= &proc_dointvec
,
651 #if defined(CONFIG_ARCH_S390)
653 .ctl_name
= KERN_SPIN_RETRY
,
654 .procname
= "spin_retry",
656 .maxlen
= sizeof (int),
658 .proc_handler
= &proc_dointvec
,
664 /* Constants for minimum and maximum testing in vm_table.
665 We use these as one-element integer vectors. */
667 static int one_hundred
= 100;
670 static ctl_table vm_table
[] = {
672 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
673 .procname
= "overcommit_memory",
674 .data
= &sysctl_overcommit_memory
,
675 .maxlen
= sizeof(sysctl_overcommit_memory
),
677 .proc_handler
= &proc_dointvec
,
680 .ctl_name
= VM_OVERCOMMIT_RATIO
,
681 .procname
= "overcommit_ratio",
682 .data
= &sysctl_overcommit_ratio
,
683 .maxlen
= sizeof(sysctl_overcommit_ratio
),
685 .proc_handler
= &proc_dointvec
,
688 .ctl_name
= VM_PAGE_CLUSTER
,
689 .procname
= "page-cluster",
690 .data
= &page_cluster
,
691 .maxlen
= sizeof(int),
693 .proc_handler
= &proc_dointvec
,
696 .ctl_name
= VM_DIRTY_BACKGROUND
,
697 .procname
= "dirty_background_ratio",
698 .data
= &dirty_background_ratio
,
699 .maxlen
= sizeof(dirty_background_ratio
),
701 .proc_handler
= &proc_dointvec_minmax
,
702 .strategy
= &sysctl_intvec
,
704 .extra2
= &one_hundred
,
707 .ctl_name
= VM_DIRTY_RATIO
,
708 .procname
= "dirty_ratio",
709 .data
= &vm_dirty_ratio
,
710 .maxlen
= sizeof(vm_dirty_ratio
),
712 .proc_handler
= &proc_dointvec_minmax
,
713 .strategy
= &sysctl_intvec
,
715 .extra2
= &one_hundred
,
718 .ctl_name
= VM_DIRTY_WB_CS
,
719 .procname
= "dirty_writeback_centisecs",
720 .data
= &dirty_writeback_centisecs
,
721 .maxlen
= sizeof(dirty_writeback_centisecs
),
723 .proc_handler
= &dirty_writeback_centisecs_handler
,
726 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
727 .procname
= "dirty_expire_centisecs",
728 .data
= &dirty_expire_centisecs
,
729 .maxlen
= sizeof(dirty_expire_centisecs
),
731 .proc_handler
= &proc_dointvec
,
734 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
735 .procname
= "nr_pdflush_threads",
736 .data
= &nr_pdflush_threads
,
737 .maxlen
= sizeof nr_pdflush_threads
,
738 .mode
= 0444 /* read-only*/,
739 .proc_handler
= &proc_dointvec
,
742 .ctl_name
= VM_SWAPPINESS
,
743 .procname
= "swappiness",
744 .data
= &vm_swappiness
,
745 .maxlen
= sizeof(vm_swappiness
),
747 .proc_handler
= &proc_dointvec_minmax
,
748 .strategy
= &sysctl_intvec
,
750 .extra2
= &one_hundred
,
752 #ifdef CONFIG_HUGETLB_PAGE
754 .ctl_name
= VM_HUGETLB_PAGES
,
755 .procname
= "nr_hugepages",
756 .data
= &max_huge_pages
,
757 .maxlen
= sizeof(unsigned long),
759 .proc_handler
= &hugetlb_sysctl_handler
,
760 .extra1
= (void *)&hugetlb_zero
,
761 .extra2
= (void *)&hugetlb_infinity
,
764 .ctl_name
= VM_HUGETLB_GROUP
,
765 .procname
= "hugetlb_shm_group",
766 .data
= &sysctl_hugetlb_shm_group
,
767 .maxlen
= sizeof(gid_t
),
769 .proc_handler
= &proc_dointvec
,
773 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
774 .procname
= "lowmem_reserve_ratio",
775 .data
= &sysctl_lowmem_reserve_ratio
,
776 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
778 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
779 .strategy
= &sysctl_intvec
,
782 .ctl_name
= VM_MIN_FREE_KBYTES
,
783 .procname
= "min_free_kbytes",
784 .data
= &min_free_kbytes
,
785 .maxlen
= sizeof(min_free_kbytes
),
787 .proc_handler
= &min_free_kbytes_sysctl_handler
,
788 .strategy
= &sysctl_intvec
,
793 .ctl_name
= VM_MAX_MAP_COUNT
,
794 .procname
= "max_map_count",
795 .data
= &sysctl_max_map_count
,
796 .maxlen
= sizeof(sysctl_max_map_count
),
798 .proc_handler
= &proc_dointvec
802 .ctl_name
= VM_LAPTOP_MODE
,
803 .procname
= "laptop_mode",
804 .data
= &laptop_mode
,
805 .maxlen
= sizeof(laptop_mode
),
807 .proc_handler
= &proc_dointvec
,
808 .strategy
= &sysctl_intvec
,
812 .ctl_name
= VM_BLOCK_DUMP
,
813 .procname
= "block_dump",
815 .maxlen
= sizeof(block_dump
),
817 .proc_handler
= &proc_dointvec
,
818 .strategy
= &sysctl_intvec
,
822 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
823 .procname
= "vfs_cache_pressure",
824 .data
= &sysctl_vfs_cache_pressure
,
825 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
827 .proc_handler
= &proc_dointvec
,
828 .strategy
= &sysctl_intvec
,
831 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
833 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
834 .procname
= "legacy_va_layout",
835 .data
= &sysctl_legacy_va_layout
,
836 .maxlen
= sizeof(sysctl_legacy_va_layout
),
838 .proc_handler
= &proc_dointvec
,
839 .strategy
= &sysctl_intvec
,
845 .ctl_name
= VM_SWAP_TOKEN_TIMEOUT
,
846 .procname
= "swap_token_timeout",
847 .data
= &swap_token_default_timeout
,
848 .maxlen
= sizeof(swap_token_default_timeout
),
850 .proc_handler
= &proc_dointvec_jiffies
,
851 .strategy
= &sysctl_jiffies
,
857 static ctl_table proc_table
[] = {
861 static ctl_table fs_table
[] = {
863 .ctl_name
= FS_NRINODE
,
864 .procname
= "inode-nr",
865 .data
= &inodes_stat
,
866 .maxlen
= 2*sizeof(int),
868 .proc_handler
= &proc_dointvec
,
871 .ctl_name
= FS_STATINODE
,
872 .procname
= "inode-state",
873 .data
= &inodes_stat
,
874 .maxlen
= 7*sizeof(int),
876 .proc_handler
= &proc_dointvec
,
879 .ctl_name
= FS_NRFILE
,
880 .procname
= "file-nr",
882 .maxlen
= 3*sizeof(int),
884 .proc_handler
= &proc_dointvec
,
887 .ctl_name
= FS_MAXFILE
,
888 .procname
= "file-max",
889 .data
= &files_stat
.max_files
,
890 .maxlen
= sizeof(int),
892 .proc_handler
= &proc_dointvec
,
895 .ctl_name
= FS_DENTRY
,
896 .procname
= "dentry-state",
897 .data
= &dentry_stat
,
898 .maxlen
= 6*sizeof(int),
900 .proc_handler
= &proc_dointvec
,
903 .ctl_name
= FS_OVERFLOWUID
,
904 .procname
= "overflowuid",
905 .data
= &fs_overflowuid
,
906 .maxlen
= sizeof(int),
908 .proc_handler
= &proc_dointvec_minmax
,
909 .strategy
= &sysctl_intvec
,
910 .extra1
= &minolduid
,
911 .extra2
= &maxolduid
,
914 .ctl_name
= FS_OVERFLOWGID
,
915 .procname
= "overflowgid",
916 .data
= &fs_overflowgid
,
917 .maxlen
= sizeof(int),
919 .proc_handler
= &proc_dointvec_minmax
,
920 .strategy
= &sysctl_intvec
,
921 .extra1
= &minolduid
,
922 .extra2
= &maxolduid
,
925 .ctl_name
= FS_LEASES
,
926 .procname
= "leases-enable",
927 .data
= &leases_enable
,
928 .maxlen
= sizeof(int),
930 .proc_handler
= &proc_dointvec
,
932 #ifdef CONFIG_DNOTIFY
934 .ctl_name
= FS_DIR_NOTIFY
,
935 .procname
= "dir-notify-enable",
936 .data
= &dir_notify_enable
,
937 .maxlen
= sizeof(int),
939 .proc_handler
= &proc_dointvec
,
944 .ctl_name
= FS_LEASE_TIME
,
945 .procname
= "lease-break-time",
946 .data
= &lease_break_time
,
947 .maxlen
= sizeof(int),
949 .proc_handler
= &proc_dointvec
,
952 .ctl_name
= FS_AIO_NR
,
953 .procname
= "aio-nr",
955 .maxlen
= sizeof(aio_nr
),
957 .proc_handler
= &proc_dointvec
,
960 .ctl_name
= FS_AIO_MAX_NR
,
961 .procname
= "aio-max-nr",
963 .maxlen
= sizeof(aio_max_nr
),
965 .proc_handler
= &proc_dointvec
,
967 #ifdef CONFIG_INOTIFY
969 .ctl_name
= FS_INOTIFY
,
970 .procname
= "inotify",
972 .child
= inotify_table
,
977 .ctl_name
= KERN_SETUID_DUMPABLE
,
978 .procname
= "suid_dumpable",
979 .data
= &suid_dumpable
,
980 .maxlen
= sizeof(int),
982 .proc_handler
= &proc_dointvec
,
987 static ctl_table debug_table
[] = {
991 static ctl_table dev_table
[] = {
995 extern void init_irq_proc (void);
997 void __init
sysctl_init(void)
999 #ifdef CONFIG_PROC_FS
1000 register_proc_table(root_table
, proc_sys_root
);
1005 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
1006 void __user
*newval
, size_t newlen
)
1008 struct list_head
*tmp
;
1010 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
1014 if (!oldlenp
|| get_user(old_len
, oldlenp
))
1017 tmp
= &root_table_header
.ctl_entry
;
1019 struct ctl_table_header
*head
=
1020 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1021 void *context
= NULL
;
1022 int error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1023 newval
, newlen
, head
->ctl_table
,
1026 if (error
!= -ENOTDIR
)
1029 } while (tmp
!= &root_table_header
.ctl_entry
);
1033 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1035 struct __sysctl_args tmp
;
1038 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1042 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1043 tmp
.newval
, tmp
.newlen
);
1049 * ctl_perm does NOT grant the superuser all rights automatically, because
1050 * some sysctl variables are readonly even to root.
1053 static int test_perm(int mode
, int op
)
1057 else if (in_egroup_p(0))
1059 if ((mode
& op
& 0007) == op
)
1064 static inline int ctl_perm(ctl_table
*table
, int op
)
1067 error
= security_sysctl(table
, op
);
1070 return test_perm(table
->mode
, op
);
1073 static int parse_table(int __user
*name
, int nlen
,
1074 void __user
*oldval
, size_t __user
*oldlenp
,
1075 void __user
*newval
, size_t newlen
,
1076 ctl_table
*table
, void **context
)
1082 if (get_user(n
, name
))
1084 for ( ; table
->ctl_name
; table
++) {
1085 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1088 if (ctl_perm(table
, 001))
1090 if (table
->strategy
) {
1091 error
= table
->strategy(
1094 newval
, newlen
, context
);
1100 table
= table
->child
;
1103 error
= do_sysctl_strategy(table
, name
, nlen
,
1105 newval
, newlen
, context
);
1112 /* Perform the actual read/write of a sysctl table entry. */
1113 int do_sysctl_strategy (ctl_table
*table
,
1114 int __user
*name
, int nlen
,
1115 void __user
*oldval
, size_t __user
*oldlenp
,
1116 void __user
*newval
, size_t newlen
, void **context
)
1125 if (ctl_perm(table
, op
))
1128 if (table
->strategy
) {
1129 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1130 newval
, newlen
, context
);
1137 /* If there is no strategy routine, or if the strategy returns
1138 * zero, proceed with automatic r/w */
1139 if (table
->data
&& table
->maxlen
) {
1140 if (oldval
&& oldlenp
) {
1141 if (get_user(len
, oldlenp
))
1144 if (len
> table
->maxlen
)
1145 len
= table
->maxlen
;
1146 if(copy_to_user(oldval
, table
->data
, len
))
1148 if(put_user(len
, oldlenp
))
1152 if (newval
&& newlen
) {
1154 if (len
> table
->maxlen
)
1155 len
= table
->maxlen
;
1156 if(copy_from_user(table
->data
, newval
, len
))
1164 * register_sysctl_table - register a sysctl hierarchy
1165 * @table: the top-level table structure
1166 * @insert_at_head: whether the entry should be inserted in front or at the end
1168 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1169 * array. An entry with a ctl_name of 0 terminates the table.
1171 * The members of the &ctl_table structure are used as follows:
1173 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1174 * must be unique within that level of sysctl
1176 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1177 * enter a sysctl file
1179 * data - a pointer to data for use by proc_handler
1181 * maxlen - the maximum size in bytes of the data
1183 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1185 * child - a pointer to the child sysctl table if this entry is a directory, or
1188 * proc_handler - the text handler routine (described below)
1190 * strategy - the strategy routine (described below)
1192 * de - for internal use by the sysctl routines
1194 * extra1, extra2 - extra pointers usable by the proc handler routines
1196 * Leaf nodes in the sysctl tree will be represented by a single file
1197 * under /proc; non-leaf nodes will be represented by directories.
1199 * sysctl(2) can automatically manage read and write requests through
1200 * the sysctl table. The data and maxlen fields of the ctl_table
1201 * struct enable minimal validation of the values being written to be
1202 * performed, and the mode field allows minimal authentication.
1204 * More sophisticated management can be enabled by the provision of a
1205 * strategy routine with the table entry. This will be called before
1206 * any automatic read or write of the data is performed.
1208 * The strategy routine may return
1210 * < 0 - Error occurred (error is passed to user process)
1212 * 0 - OK - proceed with automatic read or write.
1214 * > 0 - OK - read or write has been done by the strategy routine, so
1215 * return immediately.
1217 * There must be a proc_handler routine for any terminal nodes
1218 * mirrored under /proc/sys (non-terminals are handled by a built-in
1219 * directory handler). Several default handlers are available to
1220 * cover common cases -
1222 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1223 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1224 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1226 * It is the handler's job to read the input buffer from user memory
1227 * and process it. The handler should return 0 on success.
1229 * This routine returns %NULL on a failure to register, and a pointer
1230 * to the table header on success.
1232 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1235 struct ctl_table_header
*tmp
;
1236 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1239 tmp
->ctl_table
= table
;
1240 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1242 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1244 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1245 #ifdef CONFIG_PROC_FS
1246 register_proc_table(table
, proc_sys_root
);
1252 * unregister_sysctl_table - unregister a sysctl table hierarchy
1253 * @header: the header returned from register_sysctl_table
1255 * Unregisters the sysctl table and all children. proc entries may not
1256 * actually be removed until they are no longer used by anyone.
1258 void unregister_sysctl_table(struct ctl_table_header
* header
)
1260 list_del(&header
->ctl_entry
);
1261 #ifdef CONFIG_PROC_FS
1262 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1271 #ifdef CONFIG_PROC_FS
1273 /* Scan the sysctl entries in table and add them all into /proc */
1274 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1276 struct proc_dir_entry
*de
;
1280 for (; table
->ctl_name
; table
++) {
1281 /* Can't do anything without a proc name. */
1282 if (!table
->procname
)
1284 /* Maybe we can't do anything with it... */
1285 if (!table
->proc_handler
&& !table
->child
) {
1286 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1291 len
= strlen(table
->procname
);
1295 if (table
->proc_handler
)
1299 for (de
= root
->subdir
; de
; de
= de
->next
) {
1300 if (proc_match(len
, table
->procname
, de
))
1303 /* If the subdir exists already, de is non-NULL */
1307 de
= create_proc_entry(table
->procname
, mode
, root
);
1310 de
->data
= (void *) table
;
1311 if (table
->proc_handler
)
1312 de
->proc_fops
= &proc_sys_file_operations
;
1315 if (de
->mode
& S_IFDIR
)
1316 register_proc_table(table
->child
, de
);
1321 * Unregister a /proc sysctl table and any subdirectories.
1323 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1325 struct proc_dir_entry
*de
;
1326 for (; table
->ctl_name
; table
++) {
1327 if (!(de
= table
->de
))
1329 if (de
->mode
& S_IFDIR
) {
1330 if (!table
->child
) {
1331 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1334 unregister_proc_table(table
->child
, de
);
1336 /* Don't unregister directories which still have entries.. */
1341 /* Don't unregister proc entries that are still being used.. */
1342 if (atomic_read(&de
->count
))
1346 remove_proc_entry(table
->procname
, root
);
1350 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1351 size_t count
, loff_t
*ppos
)
1354 struct proc_dir_entry
*de
;
1355 struct ctl_table
*table
;
1359 de
= PDE(file
->f_dentry
->d_inode
);
1360 if (!de
|| !de
->data
)
1362 table
= (struct ctl_table
*) de
->data
;
1363 if (!table
|| !table
->proc_handler
)
1365 op
= (write
? 002 : 004);
1366 if (ctl_perm(table
, op
))
1371 error
= (*table
->proc_handler
) (table
, write
, file
, buf
, &res
, ppos
);
1377 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1379 if (file
->f_mode
& FMODE_WRITE
) {
1381 * sysctl entries that are not writable,
1382 * are _NOT_ writable, capabilities or not.
1384 if (!(inode
->i_mode
& S_IWUSR
))
1391 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1392 size_t count
, loff_t
*ppos
)
1394 return do_rw_proc(0, file
, buf
, count
, ppos
);
1397 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1398 size_t count
, loff_t
*ppos
)
1400 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1404 * proc_dostring - read a string sysctl
1405 * @table: the sysctl table
1406 * @write: %TRUE if this is a write to the sysctl file
1407 * @filp: the file structure
1408 * @buffer: the user buffer
1409 * @lenp: the size of the user buffer
1410 * @ppos: file position
1412 * Reads/writes a string from/to the user buffer. If the kernel
1413 * buffer provided is not large enough to hold the string, the
1414 * string is truncated. The copied string is %NULL-terminated.
1415 * If the string is being read by the user process, it is copied
1416 * and a newline '\n' is added. It is truncated if the buffer is
1419 * Returns 0 on success.
1421 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1422 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1428 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1429 (*ppos
&& !write
)) {
1437 while (len
< *lenp
) {
1438 if (get_user(c
, p
++))
1440 if (c
== 0 || c
== '\n')
1444 if (len
>= table
->maxlen
)
1445 len
= table
->maxlen
-1;
1446 if(copy_from_user(table
->data
, buffer
, len
))
1448 ((char *) table
->data
)[len
] = 0;
1451 len
= strlen(table
->data
);
1452 if (len
> table
->maxlen
)
1453 len
= table
->maxlen
;
1457 if(copy_to_user(buffer
, table
->data
, len
))
1460 if(put_user('\n', ((char __user
*) buffer
) + len
))
1471 * Special case of dostring for the UTS structure. This has locks
1472 * to observe. Should this be in kernel/sys.c ????
1475 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1476 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1481 down_read(&uts_sem
);
1482 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1485 down_write(&uts_sem
);
1486 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1492 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1494 int write
, void *data
)
1497 *valp
= *negp
? -*lvalp
: *lvalp
;
1502 *lvalp
= (unsigned long)-val
;
1505 *lvalp
= (unsigned long)val
;
1511 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1512 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1513 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1514 int write
, void *data
),
1517 #define TMPBUFLEN 21
1518 int *i
, vleft
, first
=1, neg
, val
;
1522 char buf
[TMPBUFLEN
], *p
;
1523 char __user
*s
= buffer
;
1525 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1526 (*ppos
&& !write
)) {
1531 i
= (int *) table
->data
;
1532 vleft
= table
->maxlen
/ sizeof(*i
);
1536 conv
= do_proc_dointvec_conv
;
1538 for (; left
&& vleft
--; i
++, first
=0) {
1553 if (len
> sizeof(buf
) - 1)
1554 len
= sizeof(buf
) - 1;
1555 if (copy_from_user(buf
, s
, len
))
1559 if (*p
== '-' && left
> 1) {
1563 if (*p
< '0' || *p
> '9')
1566 lval
= simple_strtoul(p
, &p
, 0);
1569 if ((len
< left
) && *p
&& !isspace(*p
))
1576 if (conv(&neg
, &lval
, i
, 1, data
))
1583 if (conv(&neg
, &lval
, i
, 0, data
))
1586 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1590 if(copy_to_user(s
, buf
, len
))
1597 if (!write
&& !first
&& left
) {
1598 if(put_user('\n', s
))
1605 if (get_user(c
, s
++))
1621 * proc_dointvec - read a vector of integers
1622 * @table: the sysctl table
1623 * @write: %TRUE if this is a write to the sysctl file
1624 * @filp: the file structure
1625 * @buffer: the user buffer
1626 * @lenp: the size of the user buffer
1627 * @ppos: file position
1629 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1630 * values from/to the user buffer, treated as an ASCII string.
1632 * Returns 0 on success.
1634 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1635 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1637 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1647 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1649 int write
, void *data
)
1651 int op
= *(int *)data
;
1653 int val
= *negp
? -*lvalp
: *lvalp
;
1655 case OP_SET
: *valp
= val
; break;
1656 case OP_AND
: *valp
&= val
; break;
1657 case OP_OR
: *valp
|= val
; break;
1658 case OP_MAX
: if(*valp
< val
)
1661 case OP_MIN
: if(*valp
> val
)
1669 *lvalp
= (unsigned long)-val
;
1672 *lvalp
= (unsigned long)val
;
1679 * init may raise the set.
1682 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1683 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1687 if (!capable(CAP_SYS_MODULE
)) {
1691 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1692 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1693 do_proc_dointvec_bset_conv
,&op
);
1696 struct do_proc_dointvec_minmax_conv_param
{
1701 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1703 int write
, void *data
)
1705 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1707 int val
= *negp
? -*lvalp
: *lvalp
;
1708 if ((param
->min
&& *param
->min
> val
) ||
1709 (param
->max
&& *param
->max
< val
))
1716 *lvalp
= (unsigned long)-val
;
1719 *lvalp
= (unsigned long)val
;
1726 * proc_dointvec_minmax - read a vector of integers with min/max values
1727 * @table: the sysctl table
1728 * @write: %TRUE if this is a write to the sysctl file
1729 * @filp: the file structure
1730 * @buffer: the user buffer
1731 * @lenp: the size of the user buffer
1732 * @ppos: file position
1734 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1735 * values from/to the user buffer, treated as an ASCII string.
1737 * This routine will ensure the values are within the range specified by
1738 * table->extra1 (min) and table->extra2 (max).
1740 * Returns 0 on success.
1742 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1743 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1745 struct do_proc_dointvec_minmax_conv_param param
= {
1746 .min
= (int *) table
->extra1
,
1747 .max
= (int *) table
->extra2
,
1749 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1750 do_proc_dointvec_minmax_conv
, ¶m
);
1753 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1755 void __user
*buffer
,
1756 size_t *lenp
, loff_t
*ppos
,
1757 unsigned long convmul
,
1758 unsigned long convdiv
)
1760 #define TMPBUFLEN 21
1761 unsigned long *i
, *min
, *max
, val
;
1762 int vleft
, first
=1, neg
;
1764 char buf
[TMPBUFLEN
], *p
;
1765 char __user
*s
= buffer
;
1767 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1768 (*ppos
&& !write
)) {
1773 i
= (unsigned long *) table
->data
;
1774 min
= (unsigned long *) table
->extra1
;
1775 max
= (unsigned long *) table
->extra2
;
1776 vleft
= table
->maxlen
/ sizeof(unsigned long);
1779 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1794 if (len
> TMPBUFLEN
-1)
1796 if (copy_from_user(buf
, s
, len
))
1800 if (*p
== '-' && left
> 1) {
1804 if (*p
< '0' || *p
> '9')
1806 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1808 if ((len
< left
) && *p
&& !isspace(*p
))
1817 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1824 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1828 if(copy_to_user(s
, buf
, len
))
1835 if (!write
&& !first
&& left
) {
1836 if(put_user('\n', s
))
1843 if (get_user(c
, s
++))
1859 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1860 * @table: the sysctl table
1861 * @write: %TRUE if this is a write to the sysctl file
1862 * @filp: the file structure
1863 * @buffer: the user buffer
1864 * @lenp: the size of the user buffer
1865 * @ppos: file position
1867 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1868 * values from/to the user buffer, treated as an ASCII string.
1870 * This routine will ensure the values are within the range specified by
1871 * table->extra1 (min) and table->extra2 (max).
1873 * Returns 0 on success.
1875 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1876 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1878 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
1882 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1883 * @table: the sysctl table
1884 * @write: %TRUE if this is a write to the sysctl file
1885 * @filp: the file structure
1886 * @buffer: the user buffer
1887 * @lenp: the size of the user buffer
1888 * @ppos: file position
1890 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1891 * values from/to the user buffer, treated as an ASCII string. The values
1892 * are treated as milliseconds, and converted to jiffies when they are stored.
1894 * This routine will ensure the values are within the range specified by
1895 * table->extra1 (min) and table->extra2 (max).
1897 * Returns 0 on success.
1899 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1901 void __user
*buffer
,
1902 size_t *lenp
, loff_t
*ppos
)
1904 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1905 lenp
, ppos
, HZ
, 1000l);
1909 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
1911 int write
, void *data
)
1914 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
1920 lval
= (unsigned long)-val
;
1923 lval
= (unsigned long)val
;
1930 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
1932 int write
, void *data
)
1935 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1941 lval
= (unsigned long)-val
;
1944 lval
= (unsigned long)val
;
1946 *lvalp
= jiffies_to_clock_t(lval
);
1951 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
1953 int write
, void *data
)
1956 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1962 lval
= (unsigned long)-val
;
1965 lval
= (unsigned long)val
;
1967 *lvalp
= jiffies_to_msecs(lval
);
1973 * proc_dointvec_jiffies - read a vector of integers as seconds
1974 * @table: the sysctl table
1975 * @write: %TRUE if this is a write to the sysctl file
1976 * @filp: the file structure
1977 * @buffer: the user buffer
1978 * @lenp: the size of the user buffer
1979 * @ppos: file position
1981 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1982 * values from/to the user buffer, treated as an ASCII string.
1983 * The values read are assumed to be in seconds, and are converted into
1986 * Returns 0 on success.
1988 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1989 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1991 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1992 do_proc_dointvec_jiffies_conv
,NULL
);
1996 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1997 * @table: the sysctl table
1998 * @write: %TRUE if this is a write to the sysctl file
1999 * @filp: the file structure
2000 * @buffer: the user buffer
2001 * @lenp: the size of the user buffer
2003 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2004 * values from/to the user buffer, treated as an ASCII string.
2005 * The values read are assumed to be in 1/USER_HZ seconds, and
2006 * are converted into jiffies.
2008 * Returns 0 on success.
2010 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2011 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2013 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
2014 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2018 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2019 * @table: the sysctl table
2020 * @write: %TRUE if this is a write to the sysctl file
2021 * @filp: the file structure
2022 * @buffer: the user buffer
2023 * @lenp: the size of the user buffer
2024 * @ppos: file position
2025 * @ppos: the current position in the file
2027 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2028 * values from/to the user buffer, treated as an ASCII string.
2029 * The values read are assumed to be in 1/1000 seconds, and
2030 * are converted into jiffies.
2032 * Returns 0 on success.
2034 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2035 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2037 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2038 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2041 #else /* CONFIG_PROC_FS */
2043 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2044 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2049 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2050 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2055 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2056 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2061 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2062 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2067 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2068 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2073 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2074 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2079 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2080 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2085 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2086 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2091 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2092 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2097 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2099 void __user
*buffer
,
2100 size_t *lenp
, loff_t
*ppos
)
2106 #endif /* CONFIG_PROC_FS */
2110 * General sysctl support routines
2113 /* The generic string strategy routine: */
2114 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2115 void __user
*oldval
, size_t __user
*oldlenp
,
2116 void __user
*newval
, size_t newlen
, void **context
)
2120 if (!table
->data
|| !table
->maxlen
)
2123 if (oldval
&& oldlenp
) {
2124 if (get_user(len
, oldlenp
))
2127 l
= strlen(table
->data
);
2128 if (len
> l
) len
= l
;
2129 if (len
>= table
->maxlen
)
2130 len
= table
->maxlen
;
2131 if(copy_to_user(oldval
, table
->data
, len
))
2133 if(put_user(0, ((char __user
*) oldval
) + len
))
2135 if(put_user(len
, oldlenp
))
2139 if (newval
&& newlen
) {
2141 if (len
> table
->maxlen
)
2142 len
= table
->maxlen
;
2143 if(copy_from_user(table
->data
, newval
, len
))
2145 if (len
== table
->maxlen
)
2147 ((char *) table
->data
)[len
] = 0;
2153 * This function makes sure that all of the integers in the vector
2154 * are between the minimum and maximum values given in the arrays
2155 * table->extra1 and table->extra2, respectively.
2157 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2158 void __user
*oldval
, size_t __user
*oldlenp
,
2159 void __user
*newval
, size_t newlen
, void **context
)
2162 if (newval
&& newlen
) {
2163 int __user
*vec
= (int __user
*) newval
;
2164 int *min
= (int *) table
->extra1
;
2165 int *max
= (int *) table
->extra2
;
2169 if (newlen
% sizeof(int) != 0)
2172 if (!table
->extra1
&& !table
->extra2
)
2175 if (newlen
> table
->maxlen
)
2176 newlen
= table
->maxlen
;
2177 length
= newlen
/ sizeof(int);
2179 for (i
= 0; i
< length
; i
++) {
2181 if (get_user(value
, vec
+ i
))
2183 if (min
&& value
< min
[i
])
2185 if (max
&& value
> max
[i
])
2192 /* Strategy function to convert jiffies to seconds */
2193 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2194 void __user
*oldval
, size_t __user
*oldlenp
,
2195 void __user
*newval
, size_t newlen
, void **context
)
2200 if (get_user(olen
, oldlenp
))
2202 if (olen
!=sizeof(int))
2205 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2206 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2209 if (newval
&& newlen
) {
2211 if (newlen
!= sizeof(int))
2213 if (get_user(new, (int __user
*)newval
))
2215 *(int *)(table
->data
) = new*HZ
;
2220 /* Strategy function to convert jiffies to seconds */
2221 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2222 void __user
*oldval
, size_t __user
*oldlenp
,
2223 void __user
*newval
, size_t newlen
, void **context
)
2228 if (get_user(olen
, oldlenp
))
2230 if (olen
!=sizeof(int))
2233 if (put_user(jiffies_to_msecs(*(int *)(table
->data
)), (int __user
*)oldval
) ||
2234 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2237 if (newval
&& newlen
) {
2239 if (newlen
!= sizeof(int))
2241 if (get_user(new, (int __user
*)newval
))
2243 *(int *)(table
->data
) = msecs_to_jiffies(new);
2248 #else /* CONFIG_SYSCTL */
2251 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2256 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2257 void __user
*oldval
, size_t __user
*oldlenp
,
2258 void __user
*newval
, size_t newlen
, void **context
)
2263 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2264 void __user
*oldval
, size_t __user
*oldlenp
,
2265 void __user
*newval
, size_t newlen
, void **context
)
2270 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2271 void __user
*oldval
, size_t __user
*oldlenp
,
2272 void __user
*newval
, size_t newlen
, void **context
)
2277 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2278 void __user
*oldval
, size_t __user
*oldlenp
,
2279 void __user
*newval
, size_t newlen
, void **context
)
2284 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2285 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2290 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2291 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2296 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2297 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2302 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2303 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2308 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2309 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2314 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2315 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2320 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2321 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2326 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2327 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2332 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2334 void __user
*buffer
,
2335 size_t *lenp
, loff_t
*ppos
)
2340 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2346 void unregister_sysctl_table(struct ctl_table_header
* table
)
2350 #endif /* CONFIG_SYSCTL */
2353 * No sense putting this after each symbol definition, twice,
2354 * exception granted :-)
2356 EXPORT_SYMBOL(proc_dointvec
);
2357 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2358 EXPORT_SYMBOL(proc_dointvec_minmax
);
2359 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2360 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2361 EXPORT_SYMBOL(proc_dostring
);
2362 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2363 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2364 EXPORT_SYMBOL(register_sysctl_table
);
2365 EXPORT_SYMBOL(sysctl_intvec
);
2366 EXPORT_SYMBOL(sysctl_jiffies
);
2367 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2368 EXPORT_SYMBOL(sysctl_string
);
2369 EXPORT_SYMBOL(unregister_sysctl_table
);