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. */
55 extern int panic_timeout
;
57 extern int sysctl_overcommit_memory
;
58 extern int sysctl_overcommit_ratio
;
59 extern int max_threads
;
60 extern int sysrq_enabled
;
61 extern int core_uses_pid
;
62 extern char core_pattern
[];
65 extern int sysctl_lower_zone_protection
;
66 extern int min_free_kbytes
;
67 extern int printk_ratelimit_jiffies
;
68 extern int printk_ratelimit_burst
;
69 extern int pid_max_min
, pid_max_max
;
71 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
72 int unknown_nmi_panic
;
73 extern int proc_unknown_nmi_panic(ctl_table
*, int, struct file
*,
74 void __user
*, size_t *, loff_t
*);
77 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
78 static int maxolduid
= 65535;
81 static int ngroups_max
= NGROUPS_MAX
;
84 extern char modprobe_path
[];
87 extern char hotplug_path
[];
89 #ifdef CONFIG_CHR_DEV_SG
90 extern int sg_big_buff
;
93 extern size_t shm_ctlmax
;
94 extern size_t shm_ctlall
;
95 extern int shm_ctlmni
;
96 extern int msg_ctlmax
;
97 extern int msg_ctlmnb
;
98 extern int msg_ctlmni
;
99 extern int sem_ctls
[];
103 extern char reboot_command
[];
104 extern int stop_a_enabled
;
105 extern int scons_pwroff
;
109 extern int pwrsw_enabled
;
110 extern int unaligned_enabled
;
113 #ifdef CONFIG_ARCH_S390
114 #ifdef CONFIG_MATHEMU
115 extern int sysctl_ieee_emulation_warnings
;
117 extern int sysctl_userprocess_debug
;
120 extern int sysctl_hz_timer
;
122 #ifdef CONFIG_BSD_PROCESS_ACCT
123 extern int acct_parm
[];
126 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
127 ctl_table
*, void **);
128 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
129 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
131 static ctl_table root_table
[];
132 static struct ctl_table_header root_table_header
=
133 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
135 static ctl_table kern_table
[];
136 static ctl_table vm_table
[];
138 extern ctl_table net_table
[];
140 static ctl_table proc_table
[];
141 static ctl_table fs_table
[];
142 static ctl_table debug_table
[];
143 static ctl_table dev_table
[];
144 extern ctl_table random_table
[];
145 #ifdef CONFIG_UNIX98_PTYS
146 extern ctl_table pty_table
[];
149 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
150 int sysctl_legacy_va_layout
;
153 /* /proc declarations: */
155 #ifdef CONFIG_PROC_FS
157 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
158 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
159 static int proc_opensys(struct inode
*, struct file
*);
161 struct file_operations proc_sys_file_operations
= {
162 .open
= proc_opensys
,
163 .read
= proc_readsys
,
164 .write
= proc_writesys
,
167 extern struct proc_dir_entry
*proc_sys_root
;
169 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*);
170 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
173 /* The default sysctl tables: */
175 static ctl_table root_table
[] = {
177 .ctl_name
= CTL_KERN
,
178 .procname
= "kernel",
197 .ctl_name
= CTL_PROC
,
209 .ctl_name
= CTL_DEBUG
,
212 .child
= debug_table
,
223 static ctl_table kern_table
[] = {
225 .ctl_name
= KERN_OSTYPE
,
226 .procname
= "ostype",
227 .data
= system_utsname
.sysname
,
228 .maxlen
= sizeof(system_utsname
.sysname
),
230 .proc_handler
= &proc_doutsstring
,
231 .strategy
= &sysctl_string
,
234 .ctl_name
= KERN_OSRELEASE
,
235 .procname
= "osrelease",
236 .data
= system_utsname
.release
,
237 .maxlen
= sizeof(system_utsname
.release
),
239 .proc_handler
= &proc_doutsstring
,
240 .strategy
= &sysctl_string
,
243 .ctl_name
= KERN_VERSION
,
244 .procname
= "version",
245 .data
= system_utsname
.version
,
246 .maxlen
= sizeof(system_utsname
.version
),
248 .proc_handler
= &proc_doutsstring
,
249 .strategy
= &sysctl_string
,
252 .ctl_name
= KERN_NODENAME
,
253 .procname
= "hostname",
254 .data
= system_utsname
.nodename
,
255 .maxlen
= sizeof(system_utsname
.nodename
),
257 .proc_handler
= &proc_doutsstring
,
258 .strategy
= &sysctl_string
,
261 .ctl_name
= KERN_DOMAINNAME
,
262 .procname
= "domainname",
263 .data
= system_utsname
.domainname
,
264 .maxlen
= sizeof(system_utsname
.domainname
),
266 .proc_handler
= &proc_doutsstring
,
267 .strategy
= &sysctl_string
,
270 .ctl_name
= KERN_PANIC
,
272 .data
= &panic_timeout
,
273 .maxlen
= sizeof(int),
275 .proc_handler
= &proc_dointvec
,
278 .ctl_name
= KERN_CORE_USES_PID
,
279 .procname
= "core_uses_pid",
280 .data
= &core_uses_pid
,
281 .maxlen
= sizeof(int),
283 .proc_handler
= &proc_dointvec
,
286 .ctl_name
= KERN_CORE_PATTERN
,
287 .procname
= "core_pattern",
288 .data
= core_pattern
,
291 .proc_handler
= &proc_dostring
,
292 .strategy
= &sysctl_string
,
295 .ctl_name
= KERN_TAINTED
,
296 .procname
= "tainted",
298 .maxlen
= sizeof(int),
300 .proc_handler
= &proc_dointvec
,
303 .ctl_name
= KERN_CAP_BSET
,
304 .procname
= "cap-bound",
306 .maxlen
= sizeof(kernel_cap_t
),
308 .proc_handler
= &proc_dointvec_bset
,
310 #ifdef CONFIG_BLK_DEV_INITRD
312 .ctl_name
= KERN_REALROOTDEV
,
313 .procname
= "real-root-dev",
314 .data
= &real_root_dev
,
315 .maxlen
= sizeof(int),
317 .proc_handler
= &proc_dointvec
,
322 .ctl_name
= KERN_SPARC_REBOOT
,
323 .procname
= "reboot-cmd",
324 .data
= reboot_command
,
327 .proc_handler
= &proc_dostring
,
328 .strategy
= &sysctl_string
,
331 .ctl_name
= KERN_SPARC_STOP_A
,
332 .procname
= "stop-a",
333 .data
= &stop_a_enabled
,
334 .maxlen
= sizeof (int),
336 .proc_handler
= &proc_dointvec
,
339 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
340 .procname
= "scons-poweroff",
341 .data
= &scons_pwroff
,
342 .maxlen
= sizeof (int),
344 .proc_handler
= &proc_dointvec
,
349 .ctl_name
= KERN_HPPA_PWRSW
,
350 .procname
= "soft-power",
351 .data
= &pwrsw_enabled
,
352 .maxlen
= sizeof (int),
354 .proc_handler
= &proc_dointvec
,
357 .ctl_name
= KERN_HPPA_UNALIGNED
,
358 .procname
= "unaligned-trap",
359 .data
= &unaligned_enabled
,
360 .maxlen
= sizeof (int),
362 .proc_handler
= &proc_dointvec
,
366 .ctl_name
= KERN_CTLALTDEL
,
367 .procname
= "ctrl-alt-del",
369 .maxlen
= sizeof(int),
371 .proc_handler
= &proc_dointvec
,
374 .ctl_name
= KERN_PRINTK
,
375 .procname
= "printk",
376 .data
= &console_loglevel
,
377 .maxlen
= 4*sizeof(int),
379 .proc_handler
= &proc_dointvec
,
383 .ctl_name
= KERN_MODPROBE
,
384 .procname
= "modprobe",
385 .data
= &modprobe_path
,
386 .maxlen
= KMOD_PATH_LEN
,
388 .proc_handler
= &proc_dostring
,
389 .strategy
= &sysctl_string
,
392 #ifdef CONFIG_HOTPLUG
394 .ctl_name
= KERN_HOTPLUG
,
395 .procname
= "hotplug",
396 .data
= &hotplug_path
,
397 .maxlen
= KMOD_PATH_LEN
,
399 .proc_handler
= &proc_dostring
,
400 .strategy
= &sysctl_string
,
403 #ifdef CONFIG_CHR_DEV_SG
405 .ctl_name
= KERN_SG_BIG_BUFF
,
406 .procname
= "sg-big-buff",
407 .data
= &sg_big_buff
,
408 .maxlen
= sizeof (int),
410 .proc_handler
= &proc_dointvec
,
413 #ifdef CONFIG_BSD_PROCESS_ACCT
415 .ctl_name
= KERN_ACCT
,
418 .maxlen
= 3*sizeof(int),
420 .proc_handler
= &proc_dointvec
,
423 #ifdef CONFIG_SYSVIPC
425 .ctl_name
= KERN_SHMMAX
,
426 .procname
= "shmmax",
428 .maxlen
= sizeof (size_t),
430 .proc_handler
= &proc_doulongvec_minmax
,
433 .ctl_name
= KERN_SHMALL
,
434 .procname
= "shmall",
436 .maxlen
= sizeof (size_t),
438 .proc_handler
= &proc_doulongvec_minmax
,
441 .ctl_name
= KERN_SHMMNI
,
442 .procname
= "shmmni",
444 .maxlen
= sizeof (int),
446 .proc_handler
= &proc_dointvec
,
449 .ctl_name
= KERN_MSGMAX
,
450 .procname
= "msgmax",
452 .maxlen
= sizeof (int),
454 .proc_handler
= &proc_dointvec
,
457 .ctl_name
= KERN_MSGMNI
,
458 .procname
= "msgmni",
460 .maxlen
= sizeof (int),
462 .proc_handler
= &proc_dointvec
,
465 .ctl_name
= KERN_MSGMNB
,
466 .procname
= "msgmnb",
468 .maxlen
= sizeof (int),
470 .proc_handler
= &proc_dointvec
,
473 .ctl_name
= KERN_SEM
,
476 .maxlen
= 4*sizeof (int),
478 .proc_handler
= &proc_dointvec
,
481 #ifdef CONFIG_MAGIC_SYSRQ
483 .ctl_name
= KERN_SYSRQ
,
485 .data
= &sysrq_enabled
,
486 .maxlen
= sizeof (int),
488 .proc_handler
= &proc_dointvec
,
492 .ctl_name
= KERN_CADPID
,
493 .procname
= "cad_pid",
495 .maxlen
= sizeof (int),
497 .proc_handler
= &proc_dointvec
,
500 .ctl_name
= KERN_MAX_THREADS
,
501 .procname
= "threads-max",
502 .data
= &max_threads
,
503 .maxlen
= sizeof(int),
505 .proc_handler
= &proc_dointvec
,
508 .ctl_name
= KERN_RANDOM
,
509 .procname
= "random",
511 .child
= random_table
,
513 #ifdef CONFIG_UNIX98_PTYS
515 .ctl_name
= KERN_PTY
,
522 .ctl_name
= KERN_OVERFLOWUID
,
523 .procname
= "overflowuid",
524 .data
= &overflowuid
,
525 .maxlen
= sizeof(int),
527 .proc_handler
= &proc_dointvec_minmax
,
528 .strategy
= &sysctl_intvec
,
529 .extra1
= &minolduid
,
530 .extra2
= &maxolduid
,
533 .ctl_name
= KERN_OVERFLOWGID
,
534 .procname
= "overflowgid",
535 .data
= &overflowgid
,
536 .maxlen
= sizeof(int),
538 .proc_handler
= &proc_dointvec_minmax
,
539 .strategy
= &sysctl_intvec
,
540 .extra1
= &minolduid
,
541 .extra2
= &maxolduid
,
543 #ifdef CONFIG_ARCH_S390
544 #ifdef CONFIG_MATHEMU
546 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
547 .procname
= "ieee_emulation_warnings",
548 .data
= &sysctl_ieee_emulation_warnings
,
549 .maxlen
= sizeof(int),
551 .proc_handler
= &proc_dointvec
,
554 #ifdef CONFIG_NO_IDLE_HZ
556 .ctl_name
= KERN_HZ_TIMER
,
557 .procname
= "hz_timer",
558 .data
= &sysctl_hz_timer
,
559 .maxlen
= sizeof(int),
561 .proc_handler
= &proc_dointvec
,
565 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
566 .procname
= "userprocess_debug",
567 .data
= &sysctl_userprocess_debug
,
568 .maxlen
= sizeof(int),
570 .proc_handler
= &proc_dointvec
,
574 .ctl_name
= KERN_PIDMAX
,
575 .procname
= "pid_max",
577 .maxlen
= sizeof (int),
579 .proc_handler
= &proc_dointvec_minmax
,
580 .strategy
= sysctl_intvec
,
581 .extra1
= &pid_max_min
,
582 .extra2
= &pid_max_max
,
585 .ctl_name
= KERN_PANIC_ON_OOPS
,
586 .procname
= "panic_on_oops",
587 .data
= &panic_on_oops
,
588 .maxlen
= sizeof(int),
590 .proc_handler
= &proc_dointvec
,
593 .ctl_name
= KERN_PRINTK_RATELIMIT
,
594 .procname
= "printk_ratelimit",
595 .data
= &printk_ratelimit_jiffies
,
596 .maxlen
= sizeof(int),
598 .proc_handler
= &proc_dointvec_jiffies
,
599 .strategy
= &sysctl_jiffies
,
602 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
603 .procname
= "printk_ratelimit_burst",
604 .data
= &printk_ratelimit_burst
,
605 .maxlen
= sizeof(int),
607 .proc_handler
= &proc_dointvec
,
610 .ctl_name
= KERN_NGROUPS_MAX
,
611 .procname
= "ngroups_max",
612 .data
= &ngroups_max
,
613 .maxlen
= sizeof (int),
615 .proc_handler
= &proc_dointvec
,
617 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
619 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
620 .procname
= "unknown_nmi_panic",
621 .data
= &unknown_nmi_panic
,
622 .maxlen
= sizeof (int),
624 .proc_handler
= &proc_unknown_nmi_panic
,
630 /* Constants for minimum and maximum testing in vm_table.
631 We use these as one-element integer vectors. */
633 static int one_hundred
= 100;
636 static ctl_table vm_table
[] = {
638 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
639 .procname
= "overcommit_memory",
640 .data
= &sysctl_overcommit_memory
,
641 .maxlen
= sizeof(sysctl_overcommit_memory
),
643 .proc_handler
= &proc_dointvec
,
646 .ctl_name
= VM_OVERCOMMIT_RATIO
,
647 .procname
= "overcommit_ratio",
648 .data
= &sysctl_overcommit_ratio
,
649 .maxlen
= sizeof(sysctl_overcommit_ratio
),
651 .proc_handler
= &proc_dointvec
,
654 .ctl_name
= VM_PAGE_CLUSTER
,
655 .procname
= "page-cluster",
656 .data
= &page_cluster
,
657 .maxlen
= sizeof(int),
659 .proc_handler
= &proc_dointvec
,
662 .ctl_name
= VM_DIRTY_BACKGROUND
,
663 .procname
= "dirty_background_ratio",
664 .data
= &dirty_background_ratio
,
665 .maxlen
= sizeof(dirty_background_ratio
),
667 .proc_handler
= &proc_dointvec_minmax
,
668 .strategy
= &sysctl_intvec
,
670 .extra2
= &one_hundred
,
673 .ctl_name
= VM_DIRTY_RATIO
,
674 .procname
= "dirty_ratio",
675 .data
= &vm_dirty_ratio
,
676 .maxlen
= sizeof(vm_dirty_ratio
),
678 .proc_handler
= &proc_dointvec_minmax
,
679 .strategy
= &sysctl_intvec
,
681 .extra2
= &one_hundred
,
684 .ctl_name
= VM_DIRTY_WB_CS
,
685 .procname
= "dirty_writeback_centisecs",
686 .data
= &dirty_writeback_centisecs
,
687 .maxlen
= sizeof(dirty_writeback_centisecs
),
689 .proc_handler
= &dirty_writeback_centisecs_handler
,
692 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
693 .procname
= "dirty_expire_centisecs",
694 .data
= &dirty_expire_centisecs
,
695 .maxlen
= sizeof(dirty_expire_centisecs
),
697 .proc_handler
= &proc_dointvec
,
700 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
701 .procname
= "nr_pdflush_threads",
702 .data
= &nr_pdflush_threads
,
703 .maxlen
= sizeof nr_pdflush_threads
,
704 .mode
= 0444 /* read-only*/,
705 .proc_handler
= &proc_dointvec
,
708 .ctl_name
= VM_SWAPPINESS
,
709 .procname
= "swappiness",
710 .data
= &vm_swappiness
,
711 .maxlen
= sizeof(vm_swappiness
),
713 .proc_handler
= &proc_dointvec_minmax
,
714 .strategy
= &sysctl_intvec
,
716 .extra2
= &one_hundred
,
718 #ifdef CONFIG_HUGETLB_PAGE
720 .ctl_name
= VM_HUGETLB_PAGES
,
721 .procname
= "nr_hugepages",
722 .data
= &max_huge_pages
,
723 .maxlen
= sizeof(unsigned long),
725 .proc_handler
= &hugetlb_sysctl_handler
,
726 .extra1
= (void *)&hugetlb_zero
,
727 .extra2
= (void *)&hugetlb_infinity
,
730 .ctl_name
= VM_HUGETLB_GROUP
,
731 .procname
= "hugetlb_shm_group",
732 .data
= &sysctl_hugetlb_shm_group
,
733 .maxlen
= sizeof(gid_t
),
735 .proc_handler
= &proc_dointvec
,
739 .ctl_name
= VM_LOWER_ZONE_PROTECTION
,
740 .procname
= "lower_zone_protection",
741 .data
= &sysctl_lower_zone_protection
,
742 .maxlen
= sizeof(sysctl_lower_zone_protection
),
744 .proc_handler
= &lower_zone_protection_sysctl_handler
,
745 .strategy
= &sysctl_intvec
,
749 .ctl_name
= VM_MIN_FREE_KBYTES
,
750 .procname
= "min_free_kbytes",
751 .data
= &min_free_kbytes
,
752 .maxlen
= sizeof(min_free_kbytes
),
754 .proc_handler
= &min_free_kbytes_sysctl_handler
,
755 .strategy
= &sysctl_intvec
,
759 .ctl_name
= VM_MAX_MAP_COUNT
,
760 .procname
= "max_map_count",
761 .data
= &sysctl_max_map_count
,
762 .maxlen
= sizeof(sysctl_max_map_count
),
764 .proc_handler
= &proc_dointvec
767 .ctl_name
= VM_LAPTOP_MODE
,
768 .procname
= "laptop_mode",
769 .data
= &laptop_mode
,
770 .maxlen
= sizeof(laptop_mode
),
772 .proc_handler
= &proc_dointvec
,
773 .strategy
= &sysctl_intvec
,
777 .ctl_name
= VM_BLOCK_DUMP
,
778 .procname
= "block_dump",
780 .maxlen
= sizeof(block_dump
),
782 .proc_handler
= &proc_dointvec
,
783 .strategy
= &sysctl_intvec
,
787 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
788 .procname
= "vfs_cache_pressure",
789 .data
= &sysctl_vfs_cache_pressure
,
790 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
792 .proc_handler
= &proc_dointvec
,
793 .strategy
= &sysctl_intvec
,
796 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
798 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
799 .procname
= "legacy_va_layout",
800 .data
= &sysctl_legacy_va_layout
,
801 .maxlen
= sizeof(sysctl_legacy_va_layout
),
803 .proc_handler
= &proc_dointvec
,
804 .strategy
= &sysctl_intvec
,
811 static ctl_table proc_table
[] = {
815 static ctl_table fs_table
[] = {
817 .ctl_name
= FS_NRINODE
,
818 .procname
= "inode-nr",
819 .data
= &inodes_stat
,
820 .maxlen
= 2*sizeof(int),
822 .proc_handler
= &proc_dointvec
,
825 .ctl_name
= FS_STATINODE
,
826 .procname
= "inode-state",
827 .data
= &inodes_stat
,
828 .maxlen
= 7*sizeof(int),
830 .proc_handler
= &proc_dointvec
,
833 .ctl_name
= FS_NRFILE
,
834 .procname
= "file-nr",
836 .maxlen
= 3*sizeof(int),
838 .proc_handler
= &proc_dointvec
,
841 .ctl_name
= FS_MAXFILE
,
842 .procname
= "file-max",
843 .data
= &files_stat
.max_files
,
844 .maxlen
= sizeof(int),
846 .proc_handler
= &proc_dointvec
,
849 .ctl_name
= FS_DENTRY
,
850 .procname
= "dentry-state",
851 .data
= &dentry_stat
,
852 .maxlen
= 6*sizeof(int),
854 .proc_handler
= &proc_dointvec
,
857 .ctl_name
= FS_OVERFLOWUID
,
858 .procname
= "overflowuid",
859 .data
= &fs_overflowuid
,
860 .maxlen
= sizeof(int),
862 .proc_handler
= &proc_dointvec_minmax
,
863 .strategy
= &sysctl_intvec
,
864 .extra1
= &minolduid
,
865 .extra2
= &maxolduid
,
868 .ctl_name
= FS_OVERFLOWGID
,
869 .procname
= "overflowgid",
870 .data
= &fs_overflowgid
,
871 .maxlen
= sizeof(int),
873 .proc_handler
= &proc_dointvec_minmax
,
874 .strategy
= &sysctl_intvec
,
875 .extra1
= &minolduid
,
876 .extra2
= &maxolduid
,
879 .ctl_name
= FS_LEASES
,
880 .procname
= "leases-enable",
881 .data
= &leases_enable
,
882 .maxlen
= sizeof(int),
884 .proc_handler
= &proc_dointvec
,
887 .ctl_name
= FS_DIR_NOTIFY
,
888 .procname
= "dir-notify-enable",
889 .data
= &dir_notify_enable
,
890 .maxlen
= sizeof(int),
892 .proc_handler
= &proc_dointvec
,
895 .ctl_name
= FS_LEASE_TIME
,
896 .procname
= "lease-break-time",
897 .data
= &lease_break_time
,
898 .maxlen
= sizeof(int),
900 .proc_handler
= &proc_dointvec
,
903 .ctl_name
= FS_AIO_NR
,
904 .procname
= "aio-nr",
906 .maxlen
= sizeof(aio_nr
),
908 .proc_handler
= &proc_dointvec
,
911 .ctl_name
= FS_AIO_MAX_NR
,
912 .procname
= "aio-max-nr",
914 .maxlen
= sizeof(aio_max_nr
),
916 .proc_handler
= &proc_dointvec
,
921 static ctl_table debug_table
[] = {
925 static ctl_table dev_table
[] = {
929 extern void init_irq_proc (void);
931 void __init
sysctl_init(void)
933 #ifdef CONFIG_PROC_FS
934 register_proc_table(root_table
, proc_sys_root
);
939 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
940 void __user
*newval
, size_t newlen
)
942 struct list_head
*tmp
;
944 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
948 if (!oldlenp
|| get_user(old_len
, oldlenp
))
951 tmp
= &root_table_header
.ctl_entry
;
953 struct ctl_table_header
*head
=
954 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
955 void *context
= NULL
;
956 int error
= parse_table(name
, nlen
, oldval
, oldlenp
,
957 newval
, newlen
, head
->ctl_table
,
961 if (error
!= -ENOTDIR
)
964 } while (tmp
!= &root_table_header
.ctl_entry
);
968 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
970 struct __sysctl_args tmp
;
973 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
977 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
978 tmp
.newval
, tmp
.newlen
);
984 * ctl_perm does NOT grant the superuser all rights automatically, because
985 * some sysctl variables are readonly even to root.
988 static int test_perm(int mode
, int op
)
992 else if (in_egroup_p(0))
994 if ((mode
& op
& 0007) == op
)
999 static inline int ctl_perm(ctl_table
*table
, int op
)
1002 error
= security_sysctl(table
, op
);
1005 return test_perm(table
->mode
, op
);
1008 static int parse_table(int __user
*name
, int nlen
,
1009 void __user
*oldval
, size_t __user
*oldlenp
,
1010 void __user
*newval
, size_t newlen
,
1011 ctl_table
*table
, void **context
)
1017 if (get_user(n
, name
))
1019 for ( ; table
->ctl_name
; table
++) {
1020 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1023 if (ctl_perm(table
, 001))
1025 if (table
->strategy
) {
1026 error
= table
->strategy(
1029 newval
, newlen
, context
);
1035 table
= table
->child
;
1038 error
= do_sysctl_strategy(table
, name
, nlen
,
1040 newval
, newlen
, context
);
1047 /* Perform the actual read/write of a sysctl table entry. */
1048 int do_sysctl_strategy (ctl_table
*table
,
1049 int __user
*name
, int nlen
,
1050 void __user
*oldval
, size_t __user
*oldlenp
,
1051 void __user
*newval
, size_t newlen
, void **context
)
1060 if (ctl_perm(table
, op
))
1063 if (table
->strategy
) {
1064 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1065 newval
, newlen
, context
);
1072 /* If there is no strategy routine, or if the strategy returns
1073 * zero, proceed with automatic r/w */
1074 if (table
->data
&& table
->maxlen
) {
1075 if (oldval
&& oldlenp
) {
1076 if (get_user(len
, oldlenp
))
1079 if (len
> table
->maxlen
)
1080 len
= table
->maxlen
;
1081 if(copy_to_user(oldval
, table
->data
, len
))
1083 if(put_user(len
, oldlenp
))
1087 if (newval
&& newlen
) {
1089 if (len
> table
->maxlen
)
1090 len
= table
->maxlen
;
1091 if(copy_from_user(table
->data
, newval
, len
))
1099 * register_sysctl_table - register a sysctl hierarchy
1100 * @table: the top-level table structure
1101 * @insert_at_head: whether the entry should be inserted in front or at the end
1103 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1104 * array. An entry with a ctl_name of 0 terminates the table.
1106 * The members of the &ctl_table structure are used as follows:
1108 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1109 * must be unique within that level of sysctl
1111 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1112 * enter a sysctl file
1114 * data - a pointer to data for use by proc_handler
1116 * maxlen - the maximum size in bytes of the data
1118 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1120 * child - a pointer to the child sysctl table if this entry is a directory, or
1123 * proc_handler - the text handler routine (described below)
1125 * strategy - the strategy routine (described below)
1127 * de - for internal use by the sysctl routines
1129 * extra1, extra2 - extra pointers usable by the proc handler routines
1131 * Leaf nodes in the sysctl tree will be represented by a single file
1132 * under /proc; non-leaf nodes will be represented by directories.
1134 * sysctl(2) can automatically manage read and write requests through
1135 * the sysctl table. The data and maxlen fields of the ctl_table
1136 * struct enable minimal validation of the values being written to be
1137 * performed, and the mode field allows minimal authentication.
1139 * More sophisticated management can be enabled by the provision of a
1140 * strategy routine with the table entry. This will be called before
1141 * any automatic read or write of the data is performed.
1143 * The strategy routine may return
1145 * < 0 - Error occurred (error is passed to user process)
1147 * 0 - OK - proceed with automatic read or write.
1149 * > 0 - OK - read or write has been done by the strategy routine, so
1150 * return immediately.
1152 * There must be a proc_handler routine for any terminal nodes
1153 * mirrored under /proc/sys (non-terminals are handled by a built-in
1154 * directory handler). Several default handlers are available to
1155 * cover common cases -
1157 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1158 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1159 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1161 * It is the handler's job to read the input buffer from user memory
1162 * and process it. The handler should return 0 on success.
1164 * This routine returns %NULL on a failure to register, and a pointer
1165 * to the table header on success.
1167 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1170 struct ctl_table_header
*tmp
;
1171 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1174 tmp
->ctl_table
= table
;
1175 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1177 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1179 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1180 #ifdef CONFIG_PROC_FS
1181 register_proc_table(table
, proc_sys_root
);
1187 * unregister_sysctl_table - unregister a sysctl table hierarchy
1188 * @header: the header returned from register_sysctl_table
1190 * Unregisters the sysctl table and all children. proc entries may not
1191 * actually be removed until they are no longer used by anyone.
1193 void unregister_sysctl_table(struct ctl_table_header
* header
)
1195 list_del(&header
->ctl_entry
);
1196 #ifdef CONFIG_PROC_FS
1197 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1206 #ifdef CONFIG_PROC_FS
1208 /* Scan the sysctl entries in table and add them all into /proc */
1209 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1211 struct proc_dir_entry
*de
;
1215 for (; table
->ctl_name
; table
++) {
1216 /* Can't do anything without a proc name. */
1217 if (!table
->procname
)
1219 /* Maybe we can't do anything with it... */
1220 if (!table
->proc_handler
&& !table
->child
) {
1221 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1226 len
= strlen(table
->procname
);
1230 if (table
->proc_handler
)
1234 for (de
= root
->subdir
; de
; de
= de
->next
) {
1235 if (proc_match(len
, table
->procname
, de
))
1238 /* If the subdir exists already, de is non-NULL */
1242 de
= create_proc_entry(table
->procname
, mode
, root
);
1245 de
->data
= (void *) table
;
1246 if (table
->proc_handler
)
1247 de
->proc_fops
= &proc_sys_file_operations
;
1250 if (de
->mode
& S_IFDIR
)
1251 register_proc_table(table
->child
, de
);
1256 * Unregister a /proc sysctl table and any subdirectories.
1258 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1260 struct proc_dir_entry
*de
;
1261 for (; table
->ctl_name
; table
++) {
1262 if (!(de
= table
->de
))
1264 if (de
->mode
& S_IFDIR
) {
1265 if (!table
->child
) {
1266 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1269 unregister_proc_table(table
->child
, de
);
1271 /* Don't unregister directories which still have entries.. */
1276 /* Don't unregister proc entries that are still being used.. */
1277 if (atomic_read(&de
->count
))
1281 remove_proc_entry(table
->procname
, root
);
1285 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1286 size_t count
, loff_t
*ppos
)
1289 struct proc_dir_entry
*de
;
1290 struct ctl_table
*table
;
1294 de
= PDE(file
->f_dentry
->d_inode
);
1295 if (!de
|| !de
->data
)
1297 table
= (struct ctl_table
*) de
->data
;
1298 if (!table
|| !table
->proc_handler
)
1300 op
= (write
? 002 : 004);
1301 if (ctl_perm(table
, op
))
1306 error
= (*table
->proc_handler
) (table
, write
, file
, buf
, &res
, ppos
);
1312 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1314 if (file
->f_mode
& FMODE_WRITE
) {
1316 * sysctl entries that are not writable,
1317 * are _NOT_ writable, capabilities or not.
1319 if (!(inode
->i_mode
& S_IWUSR
))
1326 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1327 size_t count
, loff_t
*ppos
)
1329 return do_rw_proc(0, file
, buf
, count
, ppos
);
1332 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1333 size_t count
, loff_t
*ppos
)
1335 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1339 * proc_dostring - read a string sysctl
1340 * @table: the sysctl table
1341 * @write: %TRUE if this is a write to the sysctl file
1342 * @filp: the file structure
1343 * @buffer: the user buffer
1344 * @lenp: the size of the user buffer
1346 * Reads/writes a string from/to the user buffer. If the kernel
1347 * buffer provided is not large enough to hold the string, the
1348 * string is truncated. The copied string is %NULL-terminated.
1349 * If the string is being read by the user process, it is copied
1350 * and a newline '\n' is added. It is truncated if the buffer is
1353 * Returns 0 on success.
1355 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1356 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1362 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1363 (*ppos
&& !write
)) {
1371 while (len
< *lenp
) {
1372 if (get_user(c
, p
++))
1374 if (c
== 0 || c
== '\n')
1378 if (len
>= table
->maxlen
)
1379 len
= table
->maxlen
-1;
1380 if(copy_from_user(table
->data
, buffer
, len
))
1382 ((char *) table
->data
)[len
] = 0;
1385 len
= strlen(table
->data
);
1386 if (len
> table
->maxlen
)
1387 len
= table
->maxlen
;
1391 if(copy_to_user(buffer
, table
->data
, len
))
1394 if(put_user('\n', ((char __user
*) buffer
) + len
))
1405 * Special case of dostring for the UTS structure. This has locks
1406 * to observe. Should this be in kernel/sys.c ????
1409 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1410 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1415 down_read(&uts_sem
);
1416 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1419 down_write(&uts_sem
);
1420 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1426 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1428 int write
, void *data
)
1431 *valp
= *negp
? -*lvalp
: *lvalp
;
1436 *lvalp
= (unsigned long)-val
;
1439 *lvalp
= (unsigned long)val
;
1445 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1446 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1447 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1448 int write
, void *data
),
1451 #define TMPBUFLEN 21
1452 int *i
, vleft
, first
=1, neg
, val
;
1456 char buf
[TMPBUFLEN
], *p
;
1457 char __user
*s
= buffer
;
1459 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1460 (*ppos
&& !write
)) {
1465 i
= (int *) table
->data
;
1466 vleft
= table
->maxlen
/ sizeof(*i
);
1470 conv
= do_proc_dointvec_conv
;
1472 for (; left
&& vleft
--; i
++, first
=0) {
1487 if (len
> sizeof(buf
) - 1)
1488 len
= sizeof(buf
) - 1;
1489 if (copy_from_user(buf
, s
, len
))
1493 if (*p
== '-' && left
> 1) {
1497 if (*p
< '0' || *p
> '9')
1500 lval
= simple_strtoul(p
, &p
, 0);
1503 if ((len
< left
) && *p
&& !isspace(*p
))
1510 if (conv(&neg
, &lval
, i
, 1, data
))
1517 if (conv(&neg
, &lval
, i
, 0, data
))
1520 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1524 if(copy_to_user(s
, buf
, len
))
1531 if (!write
&& !first
&& left
) {
1532 if(put_user('\n', s
))
1539 if (get_user(c
, s
++))
1555 * proc_dointvec - read a vector of integers
1556 * @table: the sysctl table
1557 * @write: %TRUE if this is a write to the sysctl file
1558 * @filp: the file structure
1559 * @buffer: the user buffer
1560 * @lenp: the size of the user buffer
1562 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1563 * values from/to the user buffer, treated as an ASCII string.
1565 * Returns 0 on success.
1567 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1568 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1570 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1580 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1582 int write
, void *data
)
1584 int op
= *(int *)data
;
1586 int val
= *negp
? -*lvalp
: *lvalp
;
1588 case OP_SET
: *valp
= val
; break;
1589 case OP_AND
: *valp
&= val
; break;
1590 case OP_OR
: *valp
|= val
; break;
1591 case OP_MAX
: if(*valp
< val
)
1594 case OP_MIN
: if(*valp
> val
)
1602 *lvalp
= (unsigned long)-val
;
1605 *lvalp
= (unsigned long)val
;
1612 * init may raise the set.
1615 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1616 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1620 if (!capable(CAP_SYS_MODULE
)) {
1624 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1625 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1626 do_proc_dointvec_bset_conv
,&op
);
1629 struct do_proc_dointvec_minmax_conv_param
{
1634 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1636 int write
, void *data
)
1638 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1640 int val
= *negp
? -*lvalp
: *lvalp
;
1641 if ((param
->min
&& *param
->min
> val
) ||
1642 (param
->max
&& *param
->max
< val
))
1649 *lvalp
= (unsigned long)-val
;
1652 *lvalp
= (unsigned long)val
;
1659 * proc_dointvec_minmax - read a vector of integers with min/max values
1660 * @table: the sysctl table
1661 * @write: %TRUE if this is a write to the sysctl file
1662 * @filp: the file structure
1663 * @buffer: the user buffer
1664 * @lenp: the size of the user buffer
1666 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1667 * values from/to the user buffer, treated as an ASCII string.
1669 * This routine will ensure the values are within the range specified by
1670 * table->extra1 (min) and table->extra2 (max).
1672 * Returns 0 on success.
1674 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1675 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1677 struct do_proc_dointvec_minmax_conv_param param
= {
1678 .min
= (int *) table
->extra1
,
1679 .max
= (int *) table
->extra2
,
1681 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1682 do_proc_dointvec_minmax_conv
, ¶m
);
1685 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1687 void __user
*buffer
,
1688 size_t *lenp
, loff_t
*ppos
,
1689 unsigned long convmul
,
1690 unsigned long convdiv
)
1692 #define TMPBUFLEN 21
1693 unsigned long *i
, *min
, *max
, val
;
1694 int vleft
, first
=1, neg
;
1696 char buf
[TMPBUFLEN
], *p
;
1697 char __user
*s
= buffer
;
1699 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1700 (*ppos
&& !write
)) {
1705 i
= (unsigned long *) table
->data
;
1706 min
= (unsigned long *) table
->extra1
;
1707 max
= (unsigned long *) table
->extra2
;
1708 vleft
= table
->maxlen
/ sizeof(unsigned long);
1711 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1726 if (len
> TMPBUFLEN
-1)
1728 if (copy_from_user(buf
, s
, len
))
1732 if (*p
== '-' && left
> 1) {
1736 if (*p
< '0' || *p
> '9')
1738 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1740 if ((len
< left
) && *p
&& !isspace(*p
))
1749 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1756 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1760 if(copy_to_user(s
, buf
, len
))
1767 if (!write
&& !first
&& left
) {
1768 if(put_user('\n', s
))
1775 if (get_user(c
, s
++))
1791 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1792 * @table: the sysctl table
1793 * @write: %TRUE if this is a write to the sysctl file
1794 * @filp: the file structure
1795 * @buffer: the user buffer
1796 * @lenp: the size of the user buffer
1798 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1799 * values from/to the user buffer, treated as an ASCII string.
1801 * This routine will ensure the values are within the range specified by
1802 * table->extra1 (min) and table->extra2 (max).
1804 * Returns 0 on success.
1806 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1807 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1809 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
1813 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1814 * @table: the sysctl table
1815 * @write: %TRUE if this is a write to the sysctl file
1816 * @filp: the file structure
1817 * @buffer: the user buffer
1818 * @lenp: the size of the user buffer
1820 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1821 * values from/to the user buffer, treated as an ASCII string. The values
1822 * are treated as milliseconds, and converted to jiffies when they are stored.
1824 * This routine will ensure the values are within the range specified by
1825 * table->extra1 (min) and table->extra2 (max).
1827 * Returns 0 on success.
1829 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1831 void __user
*buffer
,
1832 size_t *lenp
, loff_t
*ppos
)
1834 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1835 lenp
, ppos
, HZ
, 1000l);
1839 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
1841 int write
, void *data
)
1844 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
1850 lval
= (unsigned long)-val
;
1853 lval
= (unsigned long)val
;
1860 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
1862 int write
, void *data
)
1865 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1871 lval
= (unsigned long)-val
;
1874 lval
= (unsigned long)val
;
1876 *lvalp
= jiffies_to_clock_t(lval
);
1882 * proc_dointvec_jiffies - read a vector of integers as seconds
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
1889 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1890 * values from/to the user buffer, treated as an ASCII string.
1891 * The values read are assumed to be in seconds, and are converted into
1894 * Returns 0 on success.
1896 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1897 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1899 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1900 do_proc_dointvec_jiffies_conv
,NULL
);
1904 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1905 * @table: the sysctl table
1906 * @write: %TRUE if this is a write to the sysctl file
1907 * @filp: the file structure
1908 * @buffer: the user buffer
1909 * @lenp: the size of the user buffer
1911 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1912 * values from/to the user buffer, treated as an ASCII string.
1913 * The values read are assumed to be in 1/USER_HZ seconds, and
1914 * are converted into jiffies.
1916 * Returns 0 on success.
1918 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1919 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1921 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1922 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
1925 #else /* CONFIG_PROC_FS */
1927 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1928 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1933 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1934 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1939 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1940 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1945 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1946 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1951 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1952 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1957 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1958 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1963 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1964 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1969 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1970 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1975 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1977 void __user
*buffer
,
1978 size_t *lenp
, loff_t
*ppos
)
1984 #endif /* CONFIG_PROC_FS */
1988 * General sysctl support routines
1991 /* The generic string strategy routine: */
1992 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
1993 void __user
*oldval
, size_t __user
*oldlenp
,
1994 void __user
*newval
, size_t newlen
, void **context
)
1998 if (!table
->data
|| !table
->maxlen
)
2001 if (oldval
&& oldlenp
) {
2002 if (get_user(len
, oldlenp
))
2005 l
= strlen(table
->data
);
2006 if (len
> l
) len
= l
;
2007 if (len
>= table
->maxlen
)
2008 len
= table
->maxlen
;
2009 if(copy_to_user(oldval
, table
->data
, len
))
2011 if(put_user(0, ((char __user
*) oldval
) + len
))
2013 if(put_user(len
, oldlenp
))
2017 if (newval
&& newlen
) {
2019 if (len
> table
->maxlen
)
2020 len
= table
->maxlen
;
2021 if(copy_from_user(table
->data
, newval
, len
))
2023 if (len
== table
->maxlen
)
2025 ((char *) table
->data
)[len
] = 0;
2031 * This function makes sure that all of the integers in the vector
2032 * are between the minimum and maximum values given in the arrays
2033 * table->extra1 and table->extra2, respectively.
2035 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2036 void __user
*oldval
, size_t __user
*oldlenp
,
2037 void __user
*newval
, size_t newlen
, void **context
)
2040 if (newval
&& newlen
) {
2041 int __user
*vec
= (int __user
*) newval
;
2042 int *min
= (int *) table
->extra1
;
2043 int *max
= (int *) table
->extra2
;
2047 if (newlen
% sizeof(int) != 0)
2050 if (!table
->extra1
&& !table
->extra2
)
2053 if (newlen
> table
->maxlen
)
2054 newlen
= table
->maxlen
;
2055 length
= newlen
/ sizeof(int);
2057 for (i
= 0; i
< length
; i
++) {
2059 if (get_user(value
, vec
+ i
))
2061 if (min
&& value
< min
[i
])
2063 if (max
&& value
> max
[i
])
2070 /* Strategy function to convert jiffies to seconds */
2071 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2072 void __user
*oldval
, size_t __user
*oldlenp
,
2073 void __user
*newval
, size_t newlen
, void **context
)
2078 if (get_user(olen
, oldlenp
))
2080 if (olen
!=sizeof(int))
2083 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2084 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2087 if (newval
&& newlen
) {
2089 if (newlen
!= sizeof(int))
2091 if (get_user(new, (int __user
*)newval
))
2093 *(int *)(table
->data
) = new*HZ
;
2099 #else /* CONFIG_SYSCTL */
2102 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2107 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2108 void __user
*oldval
, size_t __user
*oldlenp
,
2109 void __user
*newval
, size_t newlen
, void **context
)
2114 int sysctl_intvec(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
)
2121 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2122 void __user
*oldval
, size_t __user
*oldlenp
,
2123 void __user
*newval
, size_t newlen
, void **context
)
2128 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2129 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2134 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2135 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2140 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2141 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2146 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2147 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2152 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2153 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2158 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2159 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2164 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2165 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2170 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2172 void __user
*buffer
,
2173 size_t *lenp
, loff_t
*ppos
)
2178 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2184 void unregister_sysctl_table(struct ctl_table_header
* table
)
2188 #endif /* CONFIG_SYSCTL */
2191 * No sense putting this after each symbol definition, twice,
2192 * exception granted :-)
2194 EXPORT_SYMBOL(proc_dointvec
);
2195 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2196 EXPORT_SYMBOL(proc_dointvec_minmax
);
2197 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2198 EXPORT_SYMBOL(proc_dostring
);
2199 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2200 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2201 EXPORT_SYMBOL(register_sysctl_table
);
2202 EXPORT_SYMBOL(sysctl_intvec
);
2203 EXPORT_SYMBOL(sysctl_jiffies
);
2204 EXPORT_SYMBOL(sysctl_string
);
2205 EXPORT_SYMBOL(unregister_sysctl_table
);