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
;
119 extern int sysctl_hz_timer
;
121 #ifdef CONFIG_BSD_PROCESS_ACCT
122 extern int acct_parm
[];
125 int randomize_va_space
= 1;
127 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
128 ctl_table
*, void **);
129 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
130 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
132 static ctl_table root_table
[];
133 static struct ctl_table_header root_table_header
=
134 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
136 static ctl_table kern_table
[];
137 static ctl_table vm_table
[];
139 extern ctl_table net_table
[];
141 static ctl_table proc_table
[];
142 static ctl_table fs_table
[];
143 static ctl_table debug_table
[];
144 static ctl_table dev_table
[];
145 extern ctl_table random_table
[];
146 #ifdef CONFIG_UNIX98_PTYS
147 extern ctl_table pty_table
[];
150 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
151 int sysctl_legacy_va_layout
;
154 /* /proc declarations: */
156 #ifdef CONFIG_PROC_FS
158 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
159 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
160 static int proc_opensys(struct inode
*, struct file
*);
162 struct file_operations proc_sys_file_operations
= {
163 .open
= proc_opensys
,
164 .read
= proc_readsys
,
165 .write
= proc_writesys
,
168 extern struct proc_dir_entry
*proc_sys_root
;
170 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*);
171 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
174 /* The default sysctl tables: */
176 static ctl_table root_table
[] = {
178 .ctl_name
= CTL_KERN
,
179 .procname
= "kernel",
198 .ctl_name
= CTL_PROC
,
210 .ctl_name
= CTL_DEBUG
,
213 .child
= debug_table
,
224 static ctl_table kern_table
[] = {
226 .ctl_name
= KERN_OSTYPE
,
227 .procname
= "ostype",
228 .data
= system_utsname
.sysname
,
229 .maxlen
= sizeof(system_utsname
.sysname
),
231 .proc_handler
= &proc_doutsstring
,
232 .strategy
= &sysctl_string
,
235 .ctl_name
= KERN_OSRELEASE
,
236 .procname
= "osrelease",
237 .data
= system_utsname
.release
,
238 .maxlen
= sizeof(system_utsname
.release
),
240 .proc_handler
= &proc_doutsstring
,
241 .strategy
= &sysctl_string
,
244 .ctl_name
= KERN_VERSION
,
245 .procname
= "version",
246 .data
= system_utsname
.version
,
247 .maxlen
= sizeof(system_utsname
.version
),
249 .proc_handler
= &proc_doutsstring
,
250 .strategy
= &sysctl_string
,
253 .ctl_name
= KERN_NODENAME
,
254 .procname
= "hostname",
255 .data
= system_utsname
.nodename
,
256 .maxlen
= sizeof(system_utsname
.nodename
),
258 .proc_handler
= &proc_doutsstring
,
259 .strategy
= &sysctl_string
,
262 .ctl_name
= KERN_DOMAINNAME
,
263 .procname
= "domainname",
264 .data
= system_utsname
.domainname
,
265 .maxlen
= sizeof(system_utsname
.domainname
),
267 .proc_handler
= &proc_doutsstring
,
268 .strategy
= &sysctl_string
,
271 .ctl_name
= KERN_PANIC
,
273 .data
= &panic_timeout
,
274 .maxlen
= sizeof(int),
276 .proc_handler
= &proc_dointvec
,
279 .ctl_name
= KERN_CORE_USES_PID
,
280 .procname
= "core_uses_pid",
281 .data
= &core_uses_pid
,
282 .maxlen
= sizeof(int),
284 .proc_handler
= &proc_dointvec
,
287 .ctl_name
= KERN_CORE_PATTERN
,
288 .procname
= "core_pattern",
289 .data
= core_pattern
,
292 .proc_handler
= &proc_dostring
,
293 .strategy
= &sysctl_string
,
296 .ctl_name
= KERN_TAINTED
,
297 .procname
= "tainted",
299 .maxlen
= sizeof(int),
301 .proc_handler
= &proc_dointvec
,
304 .ctl_name
= KERN_CAP_BSET
,
305 .procname
= "cap-bound",
307 .maxlen
= sizeof(kernel_cap_t
),
309 .proc_handler
= &proc_dointvec_bset
,
311 #ifdef CONFIG_BLK_DEV_INITRD
313 .ctl_name
= KERN_REALROOTDEV
,
314 .procname
= "real-root-dev",
315 .data
= &real_root_dev
,
316 .maxlen
= sizeof(int),
318 .proc_handler
= &proc_dointvec
,
323 .ctl_name
= KERN_SPARC_REBOOT
,
324 .procname
= "reboot-cmd",
325 .data
= reboot_command
,
328 .proc_handler
= &proc_dostring
,
329 .strategy
= &sysctl_string
,
332 .ctl_name
= KERN_SPARC_STOP_A
,
333 .procname
= "stop-a",
334 .data
= &stop_a_enabled
,
335 .maxlen
= sizeof (int),
337 .proc_handler
= &proc_dointvec
,
340 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
341 .procname
= "scons-poweroff",
342 .data
= &scons_pwroff
,
343 .maxlen
= sizeof (int),
345 .proc_handler
= &proc_dointvec
,
350 .ctl_name
= KERN_HPPA_PWRSW
,
351 .procname
= "soft-power",
352 .data
= &pwrsw_enabled
,
353 .maxlen
= sizeof (int),
355 .proc_handler
= &proc_dointvec
,
358 .ctl_name
= KERN_HPPA_UNALIGNED
,
359 .procname
= "unaligned-trap",
360 .data
= &unaligned_enabled
,
361 .maxlen
= sizeof (int),
363 .proc_handler
= &proc_dointvec
,
367 .ctl_name
= KERN_CTLALTDEL
,
368 .procname
= "ctrl-alt-del",
370 .maxlen
= sizeof(int),
372 .proc_handler
= &proc_dointvec
,
375 .ctl_name
= KERN_PRINTK
,
376 .procname
= "printk",
377 .data
= &console_loglevel
,
378 .maxlen
= 4*sizeof(int),
380 .proc_handler
= &proc_dointvec
,
384 .ctl_name
= KERN_MODPROBE
,
385 .procname
= "modprobe",
386 .data
= &modprobe_path
,
387 .maxlen
= KMOD_PATH_LEN
,
389 .proc_handler
= &proc_dostring
,
390 .strategy
= &sysctl_string
,
393 #ifdef CONFIG_HOTPLUG
395 .ctl_name
= KERN_HOTPLUG
,
396 .procname
= "hotplug",
397 .data
= &hotplug_path
,
398 .maxlen
= HOTPLUG_PATH_LEN
,
400 .proc_handler
= &proc_dostring
,
401 .strategy
= &sysctl_string
,
404 #ifdef CONFIG_CHR_DEV_SG
406 .ctl_name
= KERN_SG_BIG_BUFF
,
407 .procname
= "sg-big-buff",
408 .data
= &sg_big_buff
,
409 .maxlen
= sizeof (int),
411 .proc_handler
= &proc_dointvec
,
414 #ifdef CONFIG_BSD_PROCESS_ACCT
416 .ctl_name
= KERN_ACCT
,
419 .maxlen
= 3*sizeof(int),
421 .proc_handler
= &proc_dointvec
,
424 #ifdef CONFIG_SYSVIPC
426 .ctl_name
= KERN_SHMMAX
,
427 .procname
= "shmmax",
429 .maxlen
= sizeof (size_t),
431 .proc_handler
= &proc_doulongvec_minmax
,
434 .ctl_name
= KERN_SHMALL
,
435 .procname
= "shmall",
437 .maxlen
= sizeof (size_t),
439 .proc_handler
= &proc_doulongvec_minmax
,
442 .ctl_name
= KERN_SHMMNI
,
443 .procname
= "shmmni",
445 .maxlen
= sizeof (int),
447 .proc_handler
= &proc_dointvec
,
450 .ctl_name
= KERN_MSGMAX
,
451 .procname
= "msgmax",
453 .maxlen
= sizeof (int),
455 .proc_handler
= &proc_dointvec
,
458 .ctl_name
= KERN_MSGMNI
,
459 .procname
= "msgmni",
461 .maxlen
= sizeof (int),
463 .proc_handler
= &proc_dointvec
,
466 .ctl_name
= KERN_MSGMNB
,
467 .procname
= "msgmnb",
469 .maxlen
= sizeof (int),
471 .proc_handler
= &proc_dointvec
,
474 .ctl_name
= KERN_SEM
,
477 .maxlen
= 4*sizeof (int),
479 .proc_handler
= &proc_dointvec
,
482 #ifdef CONFIG_MAGIC_SYSRQ
484 .ctl_name
= KERN_SYSRQ
,
486 .data
= &sysrq_enabled
,
487 .maxlen
= sizeof (int),
489 .proc_handler
= &proc_dointvec
,
493 .ctl_name
= KERN_CADPID
,
494 .procname
= "cad_pid",
496 .maxlen
= sizeof (int),
498 .proc_handler
= &proc_dointvec
,
501 .ctl_name
= KERN_MAX_THREADS
,
502 .procname
= "threads-max",
503 .data
= &max_threads
,
504 .maxlen
= sizeof(int),
506 .proc_handler
= &proc_dointvec
,
509 .ctl_name
= KERN_RANDOM
,
510 .procname
= "random",
512 .child
= random_table
,
514 #ifdef CONFIG_UNIX98_PTYS
516 .ctl_name
= KERN_PTY
,
523 .ctl_name
= KERN_OVERFLOWUID
,
524 .procname
= "overflowuid",
525 .data
= &overflowuid
,
526 .maxlen
= sizeof(int),
528 .proc_handler
= &proc_dointvec_minmax
,
529 .strategy
= &sysctl_intvec
,
530 .extra1
= &minolduid
,
531 .extra2
= &maxolduid
,
534 .ctl_name
= KERN_OVERFLOWGID
,
535 .procname
= "overflowgid",
536 .data
= &overflowgid
,
537 .maxlen
= sizeof(int),
539 .proc_handler
= &proc_dointvec_minmax
,
540 .strategy
= &sysctl_intvec
,
541 .extra1
= &minolduid
,
542 .extra2
= &maxolduid
,
544 #ifdef CONFIG_ARCH_S390
545 #ifdef CONFIG_MATHEMU
547 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
548 .procname
= "ieee_emulation_warnings",
549 .data
= &sysctl_ieee_emulation_warnings
,
550 .maxlen
= sizeof(int),
552 .proc_handler
= &proc_dointvec
,
555 #ifdef CONFIG_NO_IDLE_HZ
557 .ctl_name
= KERN_HZ_TIMER
,
558 .procname
= "hz_timer",
559 .data
= &sysctl_hz_timer
,
560 .maxlen
= sizeof(int),
562 .proc_handler
= &proc_dointvec
,
566 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
567 .procname
= "userprocess_debug",
568 .data
= &sysctl_userprocess_debug
,
569 .maxlen
= sizeof(int),
571 .proc_handler
= &proc_dointvec
,
575 .ctl_name
= KERN_PIDMAX
,
576 .procname
= "pid_max",
578 .maxlen
= sizeof (int),
580 .proc_handler
= &proc_dointvec_minmax
,
581 .strategy
= sysctl_intvec
,
582 .extra1
= &pid_max_min
,
583 .extra2
= &pid_max_max
,
586 .ctl_name
= KERN_PANIC_ON_OOPS
,
587 .procname
= "panic_on_oops",
588 .data
= &panic_on_oops
,
589 .maxlen
= sizeof(int),
591 .proc_handler
= &proc_dointvec
,
594 .ctl_name
= KERN_PRINTK_RATELIMIT
,
595 .procname
= "printk_ratelimit",
596 .data
= &printk_ratelimit_jiffies
,
597 .maxlen
= sizeof(int),
599 .proc_handler
= &proc_dointvec_jiffies
,
600 .strategy
= &sysctl_jiffies
,
603 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
604 .procname
= "printk_ratelimit_burst",
605 .data
= &printk_ratelimit_burst
,
606 .maxlen
= sizeof(int),
608 .proc_handler
= &proc_dointvec
,
611 .ctl_name
= KERN_NGROUPS_MAX
,
612 .procname
= "ngroups_max",
613 .data
= &ngroups_max
,
614 .maxlen
= sizeof (int),
616 .proc_handler
= &proc_dointvec
,
618 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
620 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
621 .procname
= "unknown_nmi_panic",
622 .data
= &unknown_nmi_panic
,
623 .maxlen
= sizeof (int),
625 .proc_handler
= &proc_unknown_nmi_panic
,
628 #if defined(CONFIG_X86)
630 .ctl_name
= KERN_BOOTLOADER_TYPE
,
631 .procname
= "bootloader_type",
632 .data
= &bootloader_type
,
633 .maxlen
= sizeof (int),
635 .proc_handler
= &proc_dointvec
,
639 .ctl_name
= KERN_RANDOMIZE
,
640 .procname
= "randomize_va_space",
641 .data
= &randomize_va_space
,
642 .maxlen
= sizeof(int),
644 .proc_handler
= &proc_dointvec
,
650 /* Constants for minimum and maximum testing in vm_table.
651 We use these as one-element integer vectors. */
653 static int one_hundred
= 100;
656 static ctl_table vm_table
[] = {
658 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
659 .procname
= "overcommit_memory",
660 .data
= &sysctl_overcommit_memory
,
661 .maxlen
= sizeof(sysctl_overcommit_memory
),
663 .proc_handler
= &proc_dointvec
,
666 .ctl_name
= VM_OVERCOMMIT_RATIO
,
667 .procname
= "overcommit_ratio",
668 .data
= &sysctl_overcommit_ratio
,
669 .maxlen
= sizeof(sysctl_overcommit_ratio
),
671 .proc_handler
= &proc_dointvec
,
674 .ctl_name
= VM_PAGE_CLUSTER
,
675 .procname
= "page-cluster",
676 .data
= &page_cluster
,
677 .maxlen
= sizeof(int),
679 .proc_handler
= &proc_dointvec
,
682 .ctl_name
= VM_DIRTY_BACKGROUND
,
683 .procname
= "dirty_background_ratio",
684 .data
= &dirty_background_ratio
,
685 .maxlen
= sizeof(dirty_background_ratio
),
687 .proc_handler
= &proc_dointvec_minmax
,
688 .strategy
= &sysctl_intvec
,
690 .extra2
= &one_hundred
,
693 .ctl_name
= VM_DIRTY_RATIO
,
694 .procname
= "dirty_ratio",
695 .data
= &vm_dirty_ratio
,
696 .maxlen
= sizeof(vm_dirty_ratio
),
698 .proc_handler
= &proc_dointvec_minmax
,
699 .strategy
= &sysctl_intvec
,
701 .extra2
= &one_hundred
,
704 .ctl_name
= VM_DIRTY_WB_CS
,
705 .procname
= "dirty_writeback_centisecs",
706 .data
= &dirty_writeback_centisecs
,
707 .maxlen
= sizeof(dirty_writeback_centisecs
),
709 .proc_handler
= &dirty_writeback_centisecs_handler
,
712 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
713 .procname
= "dirty_expire_centisecs",
714 .data
= &dirty_expire_centisecs
,
715 .maxlen
= sizeof(dirty_expire_centisecs
),
717 .proc_handler
= &proc_dointvec
,
720 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
721 .procname
= "nr_pdflush_threads",
722 .data
= &nr_pdflush_threads
,
723 .maxlen
= sizeof nr_pdflush_threads
,
724 .mode
= 0444 /* read-only*/,
725 .proc_handler
= &proc_dointvec
,
728 .ctl_name
= VM_SWAPPINESS
,
729 .procname
= "swappiness",
730 .data
= &vm_swappiness
,
731 .maxlen
= sizeof(vm_swappiness
),
733 .proc_handler
= &proc_dointvec_minmax
,
734 .strategy
= &sysctl_intvec
,
736 .extra2
= &one_hundred
,
738 #ifdef CONFIG_HUGETLB_PAGE
740 .ctl_name
= VM_HUGETLB_PAGES
,
741 .procname
= "nr_hugepages",
742 .data
= &max_huge_pages
,
743 .maxlen
= sizeof(unsigned long),
745 .proc_handler
= &hugetlb_sysctl_handler
,
746 .extra1
= (void *)&hugetlb_zero
,
747 .extra2
= (void *)&hugetlb_infinity
,
750 .ctl_name
= VM_HUGETLB_GROUP
,
751 .procname
= "hugetlb_shm_group",
752 .data
= &sysctl_hugetlb_shm_group
,
753 .maxlen
= sizeof(gid_t
),
755 .proc_handler
= &proc_dointvec
,
759 .ctl_name
= VM_LOWMEM_RESERVE_RATIO
,
760 .procname
= "lowmem_reserve_ratio",
761 .data
= &sysctl_lowmem_reserve_ratio
,
762 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
764 .proc_handler
= &lowmem_reserve_ratio_sysctl_handler
,
765 .strategy
= &sysctl_intvec
,
768 .ctl_name
= VM_MIN_FREE_KBYTES
,
769 .procname
= "min_free_kbytes",
770 .data
= &min_free_kbytes
,
771 .maxlen
= sizeof(min_free_kbytes
),
773 .proc_handler
= &min_free_kbytes_sysctl_handler
,
774 .strategy
= &sysctl_intvec
,
779 .ctl_name
= VM_MAX_MAP_COUNT
,
780 .procname
= "max_map_count",
781 .data
= &sysctl_max_map_count
,
782 .maxlen
= sizeof(sysctl_max_map_count
),
784 .proc_handler
= &proc_dointvec
788 .ctl_name
= VM_LAPTOP_MODE
,
789 .procname
= "laptop_mode",
790 .data
= &laptop_mode
,
791 .maxlen
= sizeof(laptop_mode
),
793 .proc_handler
= &proc_dointvec
,
794 .strategy
= &sysctl_intvec
,
798 .ctl_name
= VM_BLOCK_DUMP
,
799 .procname
= "block_dump",
801 .maxlen
= sizeof(block_dump
),
803 .proc_handler
= &proc_dointvec
,
804 .strategy
= &sysctl_intvec
,
808 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
809 .procname
= "vfs_cache_pressure",
810 .data
= &sysctl_vfs_cache_pressure
,
811 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
813 .proc_handler
= &proc_dointvec
,
814 .strategy
= &sysctl_intvec
,
817 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
819 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
820 .procname
= "legacy_va_layout",
821 .data
= &sysctl_legacy_va_layout
,
822 .maxlen
= sizeof(sysctl_legacy_va_layout
),
824 .proc_handler
= &proc_dointvec
,
825 .strategy
= &sysctl_intvec
,
831 .ctl_name
= VM_SWAP_TOKEN_TIMEOUT
,
832 .procname
= "swap_token_timeout",
833 .data
= &swap_token_default_timeout
,
834 .maxlen
= sizeof(swap_token_default_timeout
),
836 .proc_handler
= &proc_dointvec_jiffies
,
837 .strategy
= &sysctl_jiffies
,
843 static ctl_table proc_table
[] = {
847 static ctl_table fs_table
[] = {
849 .ctl_name
= FS_NRINODE
,
850 .procname
= "inode-nr",
851 .data
= &inodes_stat
,
852 .maxlen
= 2*sizeof(int),
854 .proc_handler
= &proc_dointvec
,
857 .ctl_name
= FS_STATINODE
,
858 .procname
= "inode-state",
859 .data
= &inodes_stat
,
860 .maxlen
= 7*sizeof(int),
862 .proc_handler
= &proc_dointvec
,
865 .ctl_name
= FS_NRFILE
,
866 .procname
= "file-nr",
868 .maxlen
= 3*sizeof(int),
870 .proc_handler
= &proc_dointvec
,
873 .ctl_name
= FS_MAXFILE
,
874 .procname
= "file-max",
875 .data
= &files_stat
.max_files
,
876 .maxlen
= sizeof(int),
878 .proc_handler
= &proc_dointvec
,
881 .ctl_name
= FS_DENTRY
,
882 .procname
= "dentry-state",
883 .data
= &dentry_stat
,
884 .maxlen
= 6*sizeof(int),
886 .proc_handler
= &proc_dointvec
,
889 .ctl_name
= FS_OVERFLOWUID
,
890 .procname
= "overflowuid",
891 .data
= &fs_overflowuid
,
892 .maxlen
= sizeof(int),
894 .proc_handler
= &proc_dointvec_minmax
,
895 .strategy
= &sysctl_intvec
,
896 .extra1
= &minolduid
,
897 .extra2
= &maxolduid
,
900 .ctl_name
= FS_OVERFLOWGID
,
901 .procname
= "overflowgid",
902 .data
= &fs_overflowgid
,
903 .maxlen
= sizeof(int),
905 .proc_handler
= &proc_dointvec_minmax
,
906 .strategy
= &sysctl_intvec
,
907 .extra1
= &minolduid
,
908 .extra2
= &maxolduid
,
911 .ctl_name
= FS_LEASES
,
912 .procname
= "leases-enable",
913 .data
= &leases_enable
,
914 .maxlen
= sizeof(int),
916 .proc_handler
= &proc_dointvec
,
918 #ifdef CONFIG_DNOTIFY
920 .ctl_name
= FS_DIR_NOTIFY
,
921 .procname
= "dir-notify-enable",
922 .data
= &dir_notify_enable
,
923 .maxlen
= sizeof(int),
925 .proc_handler
= &proc_dointvec
,
930 .ctl_name
= FS_LEASE_TIME
,
931 .procname
= "lease-break-time",
932 .data
= &lease_break_time
,
933 .maxlen
= sizeof(int),
935 .proc_handler
= &proc_dointvec
,
938 .ctl_name
= FS_AIO_NR
,
939 .procname
= "aio-nr",
941 .maxlen
= sizeof(aio_nr
),
943 .proc_handler
= &proc_dointvec
,
946 .ctl_name
= FS_AIO_MAX_NR
,
947 .procname
= "aio-max-nr",
949 .maxlen
= sizeof(aio_max_nr
),
951 .proc_handler
= &proc_dointvec
,
955 .ctl_name
= KERN_SETUID_DUMPABLE
,
956 .procname
= "suid_dumpable",
957 .data
= &suid_dumpable
,
958 .maxlen
= sizeof(int),
960 .proc_handler
= &proc_dointvec
,
965 static ctl_table debug_table
[] = {
969 static ctl_table dev_table
[] = {
973 extern void init_irq_proc (void);
975 void __init
sysctl_init(void)
977 #ifdef CONFIG_PROC_FS
978 register_proc_table(root_table
, proc_sys_root
);
983 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
984 void __user
*newval
, size_t newlen
)
986 struct list_head
*tmp
;
988 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
992 if (!oldlenp
|| get_user(old_len
, oldlenp
))
995 tmp
= &root_table_header
.ctl_entry
;
997 struct ctl_table_header
*head
=
998 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
999 void *context
= NULL
;
1000 int error
= parse_table(name
, nlen
, oldval
, oldlenp
,
1001 newval
, newlen
, head
->ctl_table
,
1005 if (error
!= -ENOTDIR
)
1008 } while (tmp
!= &root_table_header
.ctl_entry
);
1012 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
1014 struct __sysctl_args tmp
;
1017 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
1021 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
1022 tmp
.newval
, tmp
.newlen
);
1028 * ctl_perm does NOT grant the superuser all rights automatically, because
1029 * some sysctl variables are readonly even to root.
1032 static int test_perm(int mode
, int op
)
1036 else if (in_egroup_p(0))
1038 if ((mode
& op
& 0007) == op
)
1043 static inline int ctl_perm(ctl_table
*table
, int op
)
1046 error
= security_sysctl(table
, op
);
1049 return test_perm(table
->mode
, op
);
1052 static int parse_table(int __user
*name
, int nlen
,
1053 void __user
*oldval
, size_t __user
*oldlenp
,
1054 void __user
*newval
, size_t newlen
,
1055 ctl_table
*table
, void **context
)
1061 if (get_user(n
, name
))
1063 for ( ; table
->ctl_name
; table
++) {
1064 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1067 if (ctl_perm(table
, 001))
1069 if (table
->strategy
) {
1070 error
= table
->strategy(
1073 newval
, newlen
, context
);
1079 table
= table
->child
;
1082 error
= do_sysctl_strategy(table
, name
, nlen
,
1084 newval
, newlen
, context
);
1091 /* Perform the actual read/write of a sysctl table entry. */
1092 int do_sysctl_strategy (ctl_table
*table
,
1093 int __user
*name
, int nlen
,
1094 void __user
*oldval
, size_t __user
*oldlenp
,
1095 void __user
*newval
, size_t newlen
, void **context
)
1104 if (ctl_perm(table
, op
))
1107 if (table
->strategy
) {
1108 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1109 newval
, newlen
, context
);
1116 /* If there is no strategy routine, or if the strategy returns
1117 * zero, proceed with automatic r/w */
1118 if (table
->data
&& table
->maxlen
) {
1119 if (oldval
&& oldlenp
) {
1120 if (get_user(len
, oldlenp
))
1123 if (len
> table
->maxlen
)
1124 len
= table
->maxlen
;
1125 if(copy_to_user(oldval
, table
->data
, len
))
1127 if(put_user(len
, oldlenp
))
1131 if (newval
&& newlen
) {
1133 if (len
> table
->maxlen
)
1134 len
= table
->maxlen
;
1135 if(copy_from_user(table
->data
, newval
, len
))
1143 * register_sysctl_table - register a sysctl hierarchy
1144 * @table: the top-level table structure
1145 * @insert_at_head: whether the entry should be inserted in front or at the end
1147 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1148 * array. An entry with a ctl_name of 0 terminates the table.
1150 * The members of the &ctl_table structure are used as follows:
1152 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1153 * must be unique within that level of sysctl
1155 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1156 * enter a sysctl file
1158 * data - a pointer to data for use by proc_handler
1160 * maxlen - the maximum size in bytes of the data
1162 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1164 * child - a pointer to the child sysctl table if this entry is a directory, or
1167 * proc_handler - the text handler routine (described below)
1169 * strategy - the strategy routine (described below)
1171 * de - for internal use by the sysctl routines
1173 * extra1, extra2 - extra pointers usable by the proc handler routines
1175 * Leaf nodes in the sysctl tree will be represented by a single file
1176 * under /proc; non-leaf nodes will be represented by directories.
1178 * sysctl(2) can automatically manage read and write requests through
1179 * the sysctl table. The data and maxlen fields of the ctl_table
1180 * struct enable minimal validation of the values being written to be
1181 * performed, and the mode field allows minimal authentication.
1183 * More sophisticated management can be enabled by the provision of a
1184 * strategy routine with the table entry. This will be called before
1185 * any automatic read or write of the data is performed.
1187 * The strategy routine may return
1189 * < 0 - Error occurred (error is passed to user process)
1191 * 0 - OK - proceed with automatic read or write.
1193 * > 0 - OK - read or write has been done by the strategy routine, so
1194 * return immediately.
1196 * There must be a proc_handler routine for any terminal nodes
1197 * mirrored under /proc/sys (non-terminals are handled by a built-in
1198 * directory handler). Several default handlers are available to
1199 * cover common cases -
1201 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1202 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1203 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1205 * It is the handler's job to read the input buffer from user memory
1206 * and process it. The handler should return 0 on success.
1208 * This routine returns %NULL on a failure to register, and a pointer
1209 * to the table header on success.
1211 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1214 struct ctl_table_header
*tmp
;
1215 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1218 tmp
->ctl_table
= table
;
1219 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1221 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1223 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1224 #ifdef CONFIG_PROC_FS
1225 register_proc_table(table
, proc_sys_root
);
1231 * unregister_sysctl_table - unregister a sysctl table hierarchy
1232 * @header: the header returned from register_sysctl_table
1234 * Unregisters the sysctl table and all children. proc entries may not
1235 * actually be removed until they are no longer used by anyone.
1237 void unregister_sysctl_table(struct ctl_table_header
* header
)
1239 list_del(&header
->ctl_entry
);
1240 #ifdef CONFIG_PROC_FS
1241 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1250 #ifdef CONFIG_PROC_FS
1252 /* Scan the sysctl entries in table and add them all into /proc */
1253 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1255 struct proc_dir_entry
*de
;
1259 for (; table
->ctl_name
; table
++) {
1260 /* Can't do anything without a proc name. */
1261 if (!table
->procname
)
1263 /* Maybe we can't do anything with it... */
1264 if (!table
->proc_handler
&& !table
->child
) {
1265 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1270 len
= strlen(table
->procname
);
1274 if (table
->proc_handler
)
1278 for (de
= root
->subdir
; de
; de
= de
->next
) {
1279 if (proc_match(len
, table
->procname
, de
))
1282 /* If the subdir exists already, de is non-NULL */
1286 de
= create_proc_entry(table
->procname
, mode
, root
);
1289 de
->data
= (void *) table
;
1290 if (table
->proc_handler
)
1291 de
->proc_fops
= &proc_sys_file_operations
;
1294 if (de
->mode
& S_IFDIR
)
1295 register_proc_table(table
->child
, de
);
1300 * Unregister a /proc sysctl table and any subdirectories.
1302 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1304 struct proc_dir_entry
*de
;
1305 for (; table
->ctl_name
; table
++) {
1306 if (!(de
= table
->de
))
1308 if (de
->mode
& S_IFDIR
) {
1309 if (!table
->child
) {
1310 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1313 unregister_proc_table(table
->child
, de
);
1315 /* Don't unregister directories which still have entries.. */
1320 /* Don't unregister proc entries that are still being used.. */
1321 if (atomic_read(&de
->count
))
1325 remove_proc_entry(table
->procname
, root
);
1329 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1330 size_t count
, loff_t
*ppos
)
1333 struct proc_dir_entry
*de
;
1334 struct ctl_table
*table
;
1338 de
= PDE(file
->f_dentry
->d_inode
);
1339 if (!de
|| !de
->data
)
1341 table
= (struct ctl_table
*) de
->data
;
1342 if (!table
|| !table
->proc_handler
)
1344 op
= (write
? 002 : 004);
1345 if (ctl_perm(table
, op
))
1350 error
= (*table
->proc_handler
) (table
, write
, file
, buf
, &res
, ppos
);
1356 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1358 if (file
->f_mode
& FMODE_WRITE
) {
1360 * sysctl entries that are not writable,
1361 * are _NOT_ writable, capabilities or not.
1363 if (!(inode
->i_mode
& S_IWUSR
))
1370 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1371 size_t count
, loff_t
*ppos
)
1373 return do_rw_proc(0, file
, buf
, count
, ppos
);
1376 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1377 size_t count
, loff_t
*ppos
)
1379 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1383 * proc_dostring - read a string sysctl
1384 * @table: the sysctl table
1385 * @write: %TRUE if this is a write to the sysctl file
1386 * @filp: the file structure
1387 * @buffer: the user buffer
1388 * @lenp: the size of the user buffer
1389 * @ppos: file position
1391 * Reads/writes a string from/to the user buffer. If the kernel
1392 * buffer provided is not large enough to hold the string, the
1393 * string is truncated. The copied string is %NULL-terminated.
1394 * If the string is being read by the user process, it is copied
1395 * and a newline '\n' is added. It is truncated if the buffer is
1398 * Returns 0 on success.
1400 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1401 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1407 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1408 (*ppos
&& !write
)) {
1416 while (len
< *lenp
) {
1417 if (get_user(c
, p
++))
1419 if (c
== 0 || c
== '\n')
1423 if (len
>= table
->maxlen
)
1424 len
= table
->maxlen
-1;
1425 if(copy_from_user(table
->data
, buffer
, len
))
1427 ((char *) table
->data
)[len
] = 0;
1430 len
= strlen(table
->data
);
1431 if (len
> table
->maxlen
)
1432 len
= table
->maxlen
;
1436 if(copy_to_user(buffer
, table
->data
, len
))
1439 if(put_user('\n', ((char __user
*) buffer
) + len
))
1450 * Special case of dostring for the UTS structure. This has locks
1451 * to observe. Should this be in kernel/sys.c ????
1454 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1455 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1460 down_read(&uts_sem
);
1461 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1464 down_write(&uts_sem
);
1465 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1471 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1473 int write
, void *data
)
1476 *valp
= *negp
? -*lvalp
: *lvalp
;
1481 *lvalp
= (unsigned long)-val
;
1484 *lvalp
= (unsigned long)val
;
1490 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1491 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1492 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1493 int write
, void *data
),
1496 #define TMPBUFLEN 21
1497 int *i
, vleft
, first
=1, neg
, val
;
1501 char buf
[TMPBUFLEN
], *p
;
1502 char __user
*s
= buffer
;
1504 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1505 (*ppos
&& !write
)) {
1510 i
= (int *) table
->data
;
1511 vleft
= table
->maxlen
/ sizeof(*i
);
1515 conv
= do_proc_dointvec_conv
;
1517 for (; left
&& vleft
--; i
++, first
=0) {
1532 if (len
> sizeof(buf
) - 1)
1533 len
= sizeof(buf
) - 1;
1534 if (copy_from_user(buf
, s
, len
))
1538 if (*p
== '-' && left
> 1) {
1542 if (*p
< '0' || *p
> '9')
1545 lval
= simple_strtoul(p
, &p
, 0);
1548 if ((len
< left
) && *p
&& !isspace(*p
))
1555 if (conv(&neg
, &lval
, i
, 1, data
))
1562 if (conv(&neg
, &lval
, i
, 0, data
))
1565 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1569 if(copy_to_user(s
, buf
, len
))
1576 if (!write
&& !first
&& left
) {
1577 if(put_user('\n', s
))
1584 if (get_user(c
, s
++))
1600 * proc_dointvec - read a vector of integers
1601 * @table: the sysctl table
1602 * @write: %TRUE if this is a write to the sysctl file
1603 * @filp: the file structure
1604 * @buffer: the user buffer
1605 * @lenp: the size of the user buffer
1606 * @ppos: file position
1608 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1609 * values from/to the user buffer, treated as an ASCII string.
1611 * Returns 0 on success.
1613 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1614 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1616 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1626 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1628 int write
, void *data
)
1630 int op
= *(int *)data
;
1632 int val
= *negp
? -*lvalp
: *lvalp
;
1634 case OP_SET
: *valp
= val
; break;
1635 case OP_AND
: *valp
&= val
; break;
1636 case OP_OR
: *valp
|= val
; break;
1637 case OP_MAX
: if(*valp
< val
)
1640 case OP_MIN
: if(*valp
> val
)
1648 *lvalp
= (unsigned long)-val
;
1651 *lvalp
= (unsigned long)val
;
1658 * init may raise the set.
1661 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1662 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1666 if (!capable(CAP_SYS_MODULE
)) {
1670 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1671 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1672 do_proc_dointvec_bset_conv
,&op
);
1675 struct do_proc_dointvec_minmax_conv_param
{
1680 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1682 int write
, void *data
)
1684 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1686 int val
= *negp
? -*lvalp
: *lvalp
;
1687 if ((param
->min
&& *param
->min
> val
) ||
1688 (param
->max
&& *param
->max
< val
))
1695 *lvalp
= (unsigned long)-val
;
1698 *lvalp
= (unsigned long)val
;
1705 * proc_dointvec_minmax - read a vector of integers with min/max values
1706 * @table: the sysctl table
1707 * @write: %TRUE if this is a write to the sysctl file
1708 * @filp: the file structure
1709 * @buffer: the user buffer
1710 * @lenp: the size of the user buffer
1711 * @ppos: file position
1713 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1714 * values from/to the user buffer, treated as an ASCII string.
1716 * This routine will ensure the values are within the range specified by
1717 * table->extra1 (min) and table->extra2 (max).
1719 * Returns 0 on success.
1721 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1722 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1724 struct do_proc_dointvec_minmax_conv_param param
= {
1725 .min
= (int *) table
->extra1
,
1726 .max
= (int *) table
->extra2
,
1728 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1729 do_proc_dointvec_minmax_conv
, ¶m
);
1732 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1734 void __user
*buffer
,
1735 size_t *lenp
, loff_t
*ppos
,
1736 unsigned long convmul
,
1737 unsigned long convdiv
)
1739 #define TMPBUFLEN 21
1740 unsigned long *i
, *min
, *max
, val
;
1741 int vleft
, first
=1, neg
;
1743 char buf
[TMPBUFLEN
], *p
;
1744 char __user
*s
= buffer
;
1746 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1747 (*ppos
&& !write
)) {
1752 i
= (unsigned long *) table
->data
;
1753 min
= (unsigned long *) table
->extra1
;
1754 max
= (unsigned long *) table
->extra2
;
1755 vleft
= table
->maxlen
/ sizeof(unsigned long);
1758 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1773 if (len
> TMPBUFLEN
-1)
1775 if (copy_from_user(buf
, s
, len
))
1779 if (*p
== '-' && left
> 1) {
1783 if (*p
< '0' || *p
> '9')
1785 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1787 if ((len
< left
) && *p
&& !isspace(*p
))
1796 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1803 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1807 if(copy_to_user(s
, buf
, len
))
1814 if (!write
&& !first
&& left
) {
1815 if(put_user('\n', s
))
1822 if (get_user(c
, s
++))
1838 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1839 * @table: the sysctl table
1840 * @write: %TRUE if this is a write to the sysctl file
1841 * @filp: the file structure
1842 * @buffer: the user buffer
1843 * @lenp: the size of the user buffer
1844 * @ppos: file position
1846 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1847 * values from/to the user buffer, treated as an ASCII string.
1849 * This routine will ensure the values are within the range specified by
1850 * table->extra1 (min) and table->extra2 (max).
1852 * Returns 0 on success.
1854 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1855 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1857 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
1861 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1862 * @table: the sysctl table
1863 * @write: %TRUE if this is a write to the sysctl file
1864 * @filp: the file structure
1865 * @buffer: the user buffer
1866 * @lenp: the size of the user buffer
1867 * @ppos: file position
1869 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1870 * values from/to the user buffer, treated as an ASCII string. The values
1871 * are treated as milliseconds, and converted to jiffies when they are stored.
1873 * This routine will ensure the values are within the range specified by
1874 * table->extra1 (min) and table->extra2 (max).
1876 * Returns 0 on success.
1878 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1880 void __user
*buffer
,
1881 size_t *lenp
, loff_t
*ppos
)
1883 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1884 lenp
, ppos
, HZ
, 1000l);
1888 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
1890 int write
, void *data
)
1893 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
1899 lval
= (unsigned long)-val
;
1902 lval
= (unsigned long)val
;
1909 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
1911 int write
, void *data
)
1914 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1920 lval
= (unsigned long)-val
;
1923 lval
= (unsigned long)val
;
1925 *lvalp
= jiffies_to_clock_t(lval
);
1930 static int do_proc_dointvec_ms_jiffies_conv(int *negp
, unsigned long *lvalp
,
1932 int write
, void *data
)
1935 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1941 lval
= (unsigned long)-val
;
1944 lval
= (unsigned long)val
;
1946 *lvalp
= jiffies_to_msecs(lval
);
1952 * proc_dointvec_jiffies - read a vector of integers as seconds
1953 * @table: the sysctl table
1954 * @write: %TRUE if this is a write to the sysctl file
1955 * @filp: the file structure
1956 * @buffer: the user buffer
1957 * @lenp: the size of the user buffer
1958 * @ppos: file position
1960 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1961 * values from/to the user buffer, treated as an ASCII string.
1962 * The values read are assumed to be in seconds, and are converted into
1965 * Returns 0 on success.
1967 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1968 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1970 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1971 do_proc_dointvec_jiffies_conv
,NULL
);
1975 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1976 * @table: the sysctl table
1977 * @write: %TRUE if this is a write to the sysctl file
1978 * @filp: the file structure
1979 * @buffer: the user buffer
1980 * @lenp: the size of the user buffer
1982 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1983 * values from/to the user buffer, treated as an ASCII string.
1984 * The values read are assumed to be in 1/USER_HZ seconds, and
1985 * are converted into jiffies.
1987 * Returns 0 on success.
1989 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1990 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1992 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1993 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
1997 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1998 * @table: the sysctl table
1999 * @write: %TRUE if this is a write to the sysctl file
2000 * @filp: the file structure
2001 * @buffer: the user buffer
2002 * @lenp: the size of the user buffer
2003 * @ppos: file position
2004 * @ppos: the current position in the file
2006 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2007 * values from/to the user buffer, treated as an ASCII string.
2008 * The values read are assumed to be in 1/1000 seconds, and
2009 * are converted into jiffies.
2011 * Returns 0 on success.
2013 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2014 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2016 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
2017 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2020 #else /* CONFIG_PROC_FS */
2022 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2023 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2028 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
2029 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2034 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2035 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2040 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2041 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2046 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2047 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2052 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2053 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2058 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2059 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2064 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2065 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2070 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2071 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2076 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2078 void __user
*buffer
,
2079 size_t *lenp
, loff_t
*ppos
)
2085 #endif /* CONFIG_PROC_FS */
2089 * General sysctl support routines
2092 /* The generic string strategy routine: */
2093 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2094 void __user
*oldval
, size_t __user
*oldlenp
,
2095 void __user
*newval
, size_t newlen
, void **context
)
2099 if (!table
->data
|| !table
->maxlen
)
2102 if (oldval
&& oldlenp
) {
2103 if (get_user(len
, oldlenp
))
2106 l
= strlen(table
->data
);
2107 if (len
> l
) len
= l
;
2108 if (len
>= table
->maxlen
)
2109 len
= table
->maxlen
;
2110 if(copy_to_user(oldval
, table
->data
, len
))
2112 if(put_user(0, ((char __user
*) oldval
) + len
))
2114 if(put_user(len
, oldlenp
))
2118 if (newval
&& newlen
) {
2120 if (len
> table
->maxlen
)
2121 len
= table
->maxlen
;
2122 if(copy_from_user(table
->data
, newval
, len
))
2124 if (len
== table
->maxlen
)
2126 ((char *) table
->data
)[len
] = 0;
2132 * This function makes sure that all of the integers in the vector
2133 * are between the minimum and maximum values given in the arrays
2134 * table->extra1 and table->extra2, respectively.
2136 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2137 void __user
*oldval
, size_t __user
*oldlenp
,
2138 void __user
*newval
, size_t newlen
, void **context
)
2141 if (newval
&& newlen
) {
2142 int __user
*vec
= (int __user
*) newval
;
2143 int *min
= (int *) table
->extra1
;
2144 int *max
= (int *) table
->extra2
;
2148 if (newlen
% sizeof(int) != 0)
2151 if (!table
->extra1
&& !table
->extra2
)
2154 if (newlen
> table
->maxlen
)
2155 newlen
= table
->maxlen
;
2156 length
= newlen
/ sizeof(int);
2158 for (i
= 0; i
< length
; i
++) {
2160 if (get_user(value
, vec
+ i
))
2162 if (min
&& value
< min
[i
])
2164 if (max
&& value
> max
[i
])
2171 /* Strategy function to convert jiffies to seconds */
2172 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2173 void __user
*oldval
, size_t __user
*oldlenp
,
2174 void __user
*newval
, size_t newlen
, void **context
)
2179 if (get_user(olen
, oldlenp
))
2181 if (olen
!=sizeof(int))
2184 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2185 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2188 if (newval
&& newlen
) {
2190 if (newlen
!= sizeof(int))
2192 if (get_user(new, (int __user
*)newval
))
2194 *(int *)(table
->data
) = new*HZ
;
2199 /* Strategy function to convert jiffies to seconds */
2200 int sysctl_ms_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2201 void __user
*oldval
, size_t __user
*oldlenp
,
2202 void __user
*newval
, size_t newlen
, void **context
)
2207 if (get_user(olen
, oldlenp
))
2209 if (olen
!=sizeof(int))
2212 if (put_user(jiffies_to_msecs(*(int *)(table
->data
)), (int __user
*)oldval
) ||
2213 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2216 if (newval
&& newlen
) {
2218 if (newlen
!= sizeof(int))
2220 if (get_user(new, (int __user
*)newval
))
2222 *(int *)(table
->data
) = msecs_to_jiffies(new);
2227 #else /* CONFIG_SYSCTL */
2230 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2235 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2236 void __user
*oldval
, size_t __user
*oldlenp
,
2237 void __user
*newval
, size_t newlen
, void **context
)
2242 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2243 void __user
*oldval
, size_t __user
*oldlenp
,
2244 void __user
*newval
, size_t newlen
, void **context
)
2249 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2250 void __user
*oldval
, size_t __user
*oldlenp
,
2251 void __user
*newval
, size_t newlen
, void **context
)
2256 int sysctl_ms_jiffies(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 proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2264 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2269 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2270 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2275 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2276 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2281 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2282 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2287 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2288 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2293 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2294 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2299 int proc_dointvec_ms_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2300 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2305 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2306 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2311 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2313 void __user
*buffer
,
2314 size_t *lenp
, loff_t
*ppos
)
2319 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2325 void unregister_sysctl_table(struct ctl_table_header
* table
)
2329 #endif /* CONFIG_SYSCTL */
2332 * No sense putting this after each symbol definition, twice,
2333 * exception granted :-)
2335 EXPORT_SYMBOL(proc_dointvec
);
2336 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2337 EXPORT_SYMBOL(proc_dointvec_minmax
);
2338 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2339 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2340 EXPORT_SYMBOL(proc_dostring
);
2341 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2342 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2343 EXPORT_SYMBOL(register_sysctl_table
);
2344 EXPORT_SYMBOL(sysctl_intvec
);
2345 EXPORT_SYMBOL(sysctl_jiffies
);
2346 EXPORT_SYMBOL(sysctl_ms_jiffies
);
2347 EXPORT_SYMBOL(sysctl_string
);
2348 EXPORT_SYMBOL(unregister_sysctl_table
);