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>
44 #include <asm/uaccess.h>
45 #include <asm/processor.h>
47 #ifdef CONFIG_ROOT_NFS
48 #include <linux/nfs_fs.h>
51 #if defined(CONFIG_SYSCTL)
53 /* External variables not in a header file. */
54 extern int panic_timeout
;
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 char core_pattern
[];
64 extern int sysctl_lower_zone_protection
;
65 extern int min_free_kbytes
;
66 extern int printk_ratelimit_jiffies
;
67 extern int printk_ratelimit_burst
;
69 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
70 int unknown_nmi_panic
;
71 extern int proc_unknown_nmi_panic(ctl_table
*, int, struct file
*,
72 void __user
*, size_t *, loff_t
*);
75 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
76 static int maxolduid
= 65535;
79 static int ngroups_max
= NGROUPS_MAX
;
82 extern char modprobe_path
[];
85 extern char hotplug_path
[];
87 #ifdef CONFIG_CHR_DEV_SG
88 extern int sg_big_buff
;
91 extern size_t shm_ctlmax
;
92 extern size_t shm_ctlall
;
93 extern int shm_ctlmni
;
94 extern int msg_ctlmax
;
95 extern int msg_ctlmnb
;
96 extern int msg_ctlmni
;
97 extern int sem_ctls
[];
101 extern char reboot_command
[];
102 extern int stop_a_enabled
;
103 extern int scons_pwroff
;
107 extern int pwrsw_enabled
;
108 extern int unaligned_enabled
;
111 #ifdef CONFIG_ARCH_S390
112 #ifdef CONFIG_MATHEMU
113 extern int sysctl_ieee_emulation_warnings
;
115 extern int sysctl_userprocess_debug
;
118 extern int sysctl_hz_timer
;
120 #ifdef CONFIG_BSD_PROCESS_ACCT
121 extern int acct_parm
[];
124 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
125 ctl_table
*, void **);
126 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
127 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
129 static ctl_table root_table
[];
130 static struct ctl_table_header root_table_header
=
131 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
133 static ctl_table kern_table
[];
134 static ctl_table vm_table
[];
136 extern ctl_table net_table
[];
138 static ctl_table proc_table
[];
139 static ctl_table fs_table
[];
140 static ctl_table debug_table
[];
141 static ctl_table dev_table
[];
142 extern ctl_table random_table
[];
143 #ifdef CONFIG_UNIX98_PTYS
144 extern ctl_table pty_table
[];
147 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
148 int sysctl_legacy_va_layout
;
151 /* /proc declarations: */
153 #ifdef CONFIG_PROC_FS
155 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
156 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
157 static int proc_opensys(struct inode
*, struct file
*);
159 struct file_operations proc_sys_file_operations
= {
160 .open
= proc_opensys
,
161 .read
= proc_readsys
,
162 .write
= proc_writesys
,
165 extern struct proc_dir_entry
*proc_sys_root
;
167 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*);
168 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
171 /* The default sysctl tables: */
173 static ctl_table root_table
[] = {
175 .ctl_name
= CTL_KERN
,
176 .procname
= "kernel",
195 .ctl_name
= CTL_PROC
,
207 .ctl_name
= CTL_DEBUG
,
210 .child
= debug_table
,
221 static ctl_table kern_table
[] = {
223 .ctl_name
= KERN_OSTYPE
,
224 .procname
= "ostype",
225 .data
= system_utsname
.sysname
,
226 .maxlen
= sizeof(system_utsname
.sysname
),
228 .proc_handler
= &proc_doutsstring
,
229 .strategy
= &sysctl_string
,
232 .ctl_name
= KERN_OSRELEASE
,
233 .procname
= "osrelease",
234 .data
= system_utsname
.release
,
235 .maxlen
= sizeof(system_utsname
.release
),
237 .proc_handler
= &proc_doutsstring
,
238 .strategy
= &sysctl_string
,
241 .ctl_name
= KERN_VERSION
,
242 .procname
= "version",
243 .data
= system_utsname
.version
,
244 .maxlen
= sizeof(system_utsname
.version
),
246 .proc_handler
= &proc_doutsstring
,
247 .strategy
= &sysctl_string
,
250 .ctl_name
= KERN_NODENAME
,
251 .procname
= "hostname",
252 .data
= system_utsname
.nodename
,
253 .maxlen
= sizeof(system_utsname
.nodename
),
255 .proc_handler
= &proc_doutsstring
,
256 .strategy
= &sysctl_string
,
259 .ctl_name
= KERN_DOMAINNAME
,
260 .procname
= "domainname",
261 .data
= system_utsname
.domainname
,
262 .maxlen
= sizeof(system_utsname
.domainname
),
264 .proc_handler
= &proc_doutsstring
,
265 .strategy
= &sysctl_string
,
268 .ctl_name
= KERN_PANIC
,
270 .data
= &panic_timeout
,
271 .maxlen
= sizeof(int),
273 .proc_handler
= &proc_dointvec
,
276 .ctl_name
= KERN_CORE_USES_PID
,
277 .procname
= "core_uses_pid",
278 .data
= &core_uses_pid
,
279 .maxlen
= sizeof(int),
281 .proc_handler
= &proc_dointvec
,
284 .ctl_name
= KERN_CORE_PATTERN
,
285 .procname
= "core_pattern",
286 .data
= core_pattern
,
289 .proc_handler
= &proc_dostring
,
290 .strategy
= &sysctl_string
,
293 .ctl_name
= KERN_TAINTED
,
294 .procname
= "tainted",
296 .maxlen
= sizeof(int),
298 .proc_handler
= &proc_dointvec
,
301 .ctl_name
= KERN_CAP_BSET
,
302 .procname
= "cap-bound",
304 .maxlen
= sizeof(kernel_cap_t
),
306 .proc_handler
= &proc_dointvec_bset
,
308 #ifdef CONFIG_BLK_DEV_INITRD
310 .ctl_name
= KERN_REALROOTDEV
,
311 .procname
= "real-root-dev",
312 .data
= &real_root_dev
,
313 .maxlen
= sizeof(int),
315 .proc_handler
= &proc_dointvec
,
320 .ctl_name
= KERN_SPARC_REBOOT
,
321 .procname
= "reboot-cmd",
322 .data
= reboot_command
,
325 .proc_handler
= &proc_dostring
,
326 .strategy
= &sysctl_string
,
329 .ctl_name
= KERN_SPARC_STOP_A
,
330 .procname
= "stop-a",
331 .data
= &stop_a_enabled
,
332 .maxlen
= sizeof (int),
334 .proc_handler
= &proc_dointvec
,
337 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
338 .procname
= "scons-poweroff",
339 .data
= &scons_pwroff
,
340 .maxlen
= sizeof (int),
342 .proc_handler
= &proc_dointvec
,
347 .ctl_name
= KERN_HPPA_PWRSW
,
348 .procname
= "soft-power",
349 .data
= &pwrsw_enabled
,
350 .maxlen
= sizeof (int),
352 .proc_handler
= &proc_dointvec
,
355 .ctl_name
= KERN_HPPA_UNALIGNED
,
356 .procname
= "unaligned-trap",
357 .data
= &unaligned_enabled
,
358 .maxlen
= sizeof (int),
360 .proc_handler
= &proc_dointvec
,
364 .ctl_name
= KERN_CTLALTDEL
,
365 .procname
= "ctrl-alt-del",
367 .maxlen
= sizeof(int),
369 .proc_handler
= &proc_dointvec
,
372 .ctl_name
= KERN_PRINTK
,
373 .procname
= "printk",
374 .data
= &console_loglevel
,
375 .maxlen
= 4*sizeof(int),
377 .proc_handler
= &proc_dointvec
,
381 .ctl_name
= KERN_MODPROBE
,
382 .procname
= "modprobe",
383 .data
= &modprobe_path
,
384 .maxlen
= KMOD_PATH_LEN
,
386 .proc_handler
= &proc_dostring
,
387 .strategy
= &sysctl_string
,
390 #ifdef CONFIG_HOTPLUG
392 .ctl_name
= KERN_HOTPLUG
,
393 .procname
= "hotplug",
394 .data
= &hotplug_path
,
395 .maxlen
= KMOD_PATH_LEN
,
397 .proc_handler
= &proc_dostring
,
398 .strategy
= &sysctl_string
,
401 #ifdef CONFIG_CHR_DEV_SG
403 .ctl_name
= KERN_SG_BIG_BUFF
,
404 .procname
= "sg-big-buff",
405 .data
= &sg_big_buff
,
406 .maxlen
= sizeof (int),
408 .proc_handler
= &proc_dointvec
,
411 #ifdef CONFIG_BSD_PROCESS_ACCT
413 .ctl_name
= KERN_ACCT
,
416 .maxlen
= 3*sizeof(int),
418 .proc_handler
= &proc_dointvec
,
421 #ifdef CONFIG_SYSVIPC
423 .ctl_name
= KERN_SHMMAX
,
424 .procname
= "shmmax",
426 .maxlen
= sizeof (size_t),
428 .proc_handler
= &proc_doulongvec_minmax
,
431 .ctl_name
= KERN_SHMALL
,
432 .procname
= "shmall",
434 .maxlen
= sizeof (size_t),
436 .proc_handler
= &proc_doulongvec_minmax
,
439 .ctl_name
= KERN_SHMMNI
,
440 .procname
= "shmmni",
442 .maxlen
= sizeof (int),
444 .proc_handler
= &proc_dointvec
,
447 .ctl_name
= KERN_MSGMAX
,
448 .procname
= "msgmax",
450 .maxlen
= sizeof (int),
452 .proc_handler
= &proc_dointvec
,
455 .ctl_name
= KERN_MSGMNI
,
456 .procname
= "msgmni",
458 .maxlen
= sizeof (int),
460 .proc_handler
= &proc_dointvec
,
463 .ctl_name
= KERN_MSGMNB
,
464 .procname
= "msgmnb",
466 .maxlen
= sizeof (int),
468 .proc_handler
= &proc_dointvec
,
471 .ctl_name
= KERN_SEM
,
474 .maxlen
= 4*sizeof (int),
476 .proc_handler
= &proc_dointvec
,
479 #ifdef CONFIG_MAGIC_SYSRQ
481 .ctl_name
= KERN_SYSRQ
,
483 .data
= &sysrq_enabled
,
484 .maxlen
= sizeof (int),
486 .proc_handler
= &proc_dointvec
,
490 .ctl_name
= KERN_CADPID
,
491 .procname
= "cad_pid",
493 .maxlen
= sizeof (int),
495 .proc_handler
= &proc_dointvec
,
498 .ctl_name
= KERN_MAX_THREADS
,
499 .procname
= "threads-max",
500 .data
= &max_threads
,
501 .maxlen
= sizeof(int),
503 .proc_handler
= &proc_dointvec
,
506 .ctl_name
= KERN_RANDOM
,
507 .procname
= "random",
509 .child
= random_table
,
511 #ifdef CONFIG_UNIX98_PTYS
513 .ctl_name
= KERN_PTY
,
520 .ctl_name
= KERN_OVERFLOWUID
,
521 .procname
= "overflowuid",
522 .data
= &overflowuid
,
523 .maxlen
= sizeof(int),
525 .proc_handler
= &proc_dointvec_minmax
,
526 .strategy
= &sysctl_intvec
,
527 .extra1
= &minolduid
,
528 .extra2
= &maxolduid
,
531 .ctl_name
= KERN_OVERFLOWGID
,
532 .procname
= "overflowgid",
533 .data
= &overflowgid
,
534 .maxlen
= sizeof(int),
536 .proc_handler
= &proc_dointvec_minmax
,
537 .strategy
= &sysctl_intvec
,
538 .extra1
= &minolduid
,
539 .extra2
= &maxolduid
,
541 #ifdef CONFIG_ARCH_S390
542 #ifdef CONFIG_MATHEMU
544 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
545 .procname
= "ieee_emulation_warnings",
546 .data
= &sysctl_ieee_emulation_warnings
,
547 .maxlen
= sizeof(int),
549 .proc_handler
= &proc_dointvec
,
552 #ifdef CONFIG_NO_IDLE_HZ
554 .ctl_name
= KERN_HZ_TIMER
,
555 .procname
= "hz_timer",
556 .data
= &sysctl_hz_timer
,
557 .maxlen
= sizeof(int),
559 .proc_handler
= &proc_dointvec
,
563 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
564 .procname
= "userprocess_debug",
565 .data
= &sysctl_userprocess_debug
,
566 .maxlen
= sizeof(int),
568 .proc_handler
= &proc_dointvec
,
572 .ctl_name
= KERN_PIDMAX
,
573 .procname
= "pid_max",
575 .maxlen
= sizeof (int),
577 .proc_handler
= &proc_dointvec
,
580 .ctl_name
= KERN_PANIC_ON_OOPS
,
581 .procname
= "panic_on_oops",
582 .data
= &panic_on_oops
,
583 .maxlen
= sizeof(int),
585 .proc_handler
= &proc_dointvec
,
588 .ctl_name
= KERN_PRINTK_RATELIMIT
,
589 .procname
= "printk_ratelimit",
590 .data
= &printk_ratelimit_jiffies
,
591 .maxlen
= sizeof(int),
593 .proc_handler
= &proc_dointvec_jiffies
,
594 .strategy
= &sysctl_jiffies
,
597 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
598 .procname
= "printk_ratelimit_burst",
599 .data
= &printk_ratelimit_burst
,
600 .maxlen
= sizeof(int),
602 .proc_handler
= &proc_dointvec
,
605 .ctl_name
= KERN_NGROUPS_MAX
,
606 .procname
= "ngroups_max",
607 .data
= &ngroups_max
,
608 .maxlen
= sizeof (int),
610 .proc_handler
= &proc_dointvec
,
612 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
614 .ctl_name
= KERN_UNKNOWN_NMI_PANIC
,
615 .procname
= "unknown_nmi_panic",
616 .data
= &unknown_nmi_panic
,
617 .maxlen
= sizeof (int),
619 .proc_handler
= &proc_unknown_nmi_panic
,
625 /* Constants for minimum and maximum testing in vm_table.
626 We use these as one-element integer vectors. */
628 static int one_hundred
= 100;
631 static ctl_table vm_table
[] = {
633 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
634 .procname
= "overcommit_memory",
635 .data
= &sysctl_overcommit_memory
,
636 .maxlen
= sizeof(sysctl_overcommit_memory
),
638 .proc_handler
= &proc_dointvec
,
641 .ctl_name
= VM_OVERCOMMIT_RATIO
,
642 .procname
= "overcommit_ratio",
643 .data
= &sysctl_overcommit_ratio
,
644 .maxlen
= sizeof(sysctl_overcommit_ratio
),
646 .proc_handler
= &proc_dointvec
,
649 .ctl_name
= VM_PAGE_CLUSTER
,
650 .procname
= "page-cluster",
651 .data
= &page_cluster
,
652 .maxlen
= sizeof(int),
654 .proc_handler
= &proc_dointvec
,
657 .ctl_name
= VM_DIRTY_BACKGROUND
,
658 .procname
= "dirty_background_ratio",
659 .data
= &dirty_background_ratio
,
660 .maxlen
= sizeof(dirty_background_ratio
),
662 .proc_handler
= &proc_dointvec_minmax
,
663 .strategy
= &sysctl_intvec
,
665 .extra2
= &one_hundred
,
668 .ctl_name
= VM_DIRTY_RATIO
,
669 .procname
= "dirty_ratio",
670 .data
= &vm_dirty_ratio
,
671 .maxlen
= sizeof(vm_dirty_ratio
),
673 .proc_handler
= &proc_dointvec_minmax
,
674 .strategy
= &sysctl_intvec
,
676 .extra2
= &one_hundred
,
679 .ctl_name
= VM_DIRTY_WB_CS
,
680 .procname
= "dirty_writeback_centisecs",
681 .data
= &dirty_writeback_centisecs
,
682 .maxlen
= sizeof(dirty_writeback_centisecs
),
684 .proc_handler
= &dirty_writeback_centisecs_handler
,
687 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
688 .procname
= "dirty_expire_centisecs",
689 .data
= &dirty_expire_centisecs
,
690 .maxlen
= sizeof(dirty_expire_centisecs
),
692 .proc_handler
= &proc_dointvec
,
695 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
696 .procname
= "nr_pdflush_threads",
697 .data
= &nr_pdflush_threads
,
698 .maxlen
= sizeof nr_pdflush_threads
,
699 .mode
= 0444 /* read-only*/,
700 .proc_handler
= &proc_dointvec
,
703 .ctl_name
= VM_SWAPPINESS
,
704 .procname
= "swappiness",
705 .data
= &vm_swappiness
,
706 .maxlen
= sizeof(vm_swappiness
),
708 .proc_handler
= &proc_dointvec_minmax
,
709 .strategy
= &sysctl_intvec
,
711 .extra2
= &one_hundred
,
713 #ifdef CONFIG_HUGETLB_PAGE
715 .ctl_name
= VM_HUGETLB_PAGES
,
716 .procname
= "nr_hugepages",
717 .data
= &max_huge_pages
,
718 .maxlen
= sizeof(unsigned long),
720 .proc_handler
= &hugetlb_sysctl_handler
,
721 .extra1
= (void *)&hugetlb_zero
,
722 .extra2
= (void *)&hugetlb_infinity
,
725 .ctl_name
= VM_HUGETLB_GROUP
,
726 .procname
= "hugetlb_shm_group",
727 .data
= &sysctl_hugetlb_shm_group
,
728 .maxlen
= sizeof(gid_t
),
730 .proc_handler
= &proc_dointvec
,
734 .ctl_name
= VM_LOWER_ZONE_PROTECTION
,
735 .procname
= "lower_zone_protection",
736 .data
= &sysctl_lower_zone_protection
,
737 .maxlen
= sizeof(sysctl_lower_zone_protection
),
739 .proc_handler
= &lower_zone_protection_sysctl_handler
,
740 .strategy
= &sysctl_intvec
,
744 .ctl_name
= VM_MIN_FREE_KBYTES
,
745 .procname
= "min_free_kbytes",
746 .data
= &min_free_kbytes
,
747 .maxlen
= sizeof(min_free_kbytes
),
749 .proc_handler
= &min_free_kbytes_sysctl_handler
,
750 .strategy
= &sysctl_intvec
,
754 .ctl_name
= VM_MAX_MAP_COUNT
,
755 .procname
= "max_map_count",
756 .data
= &sysctl_max_map_count
,
757 .maxlen
= sizeof(sysctl_max_map_count
),
759 .proc_handler
= &proc_dointvec
762 .ctl_name
= VM_LAPTOP_MODE
,
763 .procname
= "laptop_mode",
764 .data
= &laptop_mode
,
765 .maxlen
= sizeof(laptop_mode
),
767 .proc_handler
= &proc_dointvec
,
768 .strategy
= &sysctl_intvec
,
772 .ctl_name
= VM_BLOCK_DUMP
,
773 .procname
= "block_dump",
775 .maxlen
= sizeof(block_dump
),
777 .proc_handler
= &proc_dointvec
,
778 .strategy
= &sysctl_intvec
,
782 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
783 .procname
= "vfs_cache_pressure",
784 .data
= &sysctl_vfs_cache_pressure
,
785 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
787 .proc_handler
= &proc_dointvec
,
788 .strategy
= &sysctl_intvec
,
791 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
793 .ctl_name
= VM_LEGACY_VA_LAYOUT
,
794 .procname
= "legacy_va_layout",
795 .data
= &sysctl_legacy_va_layout
,
796 .maxlen
= sizeof(sysctl_legacy_va_layout
),
798 .proc_handler
= &proc_dointvec
,
799 .strategy
= &sysctl_intvec
,
806 static ctl_table proc_table
[] = {
810 static ctl_table fs_table
[] = {
812 .ctl_name
= FS_NRINODE
,
813 .procname
= "inode-nr",
814 .data
= &inodes_stat
,
815 .maxlen
= 2*sizeof(int),
817 .proc_handler
= &proc_dointvec
,
820 .ctl_name
= FS_STATINODE
,
821 .procname
= "inode-state",
822 .data
= &inodes_stat
,
823 .maxlen
= 7*sizeof(int),
825 .proc_handler
= &proc_dointvec
,
828 .ctl_name
= FS_NRFILE
,
829 .procname
= "file-nr",
831 .maxlen
= 3*sizeof(int),
833 .proc_handler
= &proc_dointvec
,
836 .ctl_name
= FS_MAXFILE
,
837 .procname
= "file-max",
838 .data
= &files_stat
.max_files
,
839 .maxlen
= sizeof(int),
841 .proc_handler
= &proc_dointvec
,
844 .ctl_name
= FS_DENTRY
,
845 .procname
= "dentry-state",
846 .data
= &dentry_stat
,
847 .maxlen
= 6*sizeof(int),
849 .proc_handler
= &proc_dointvec
,
852 .ctl_name
= FS_OVERFLOWUID
,
853 .procname
= "overflowuid",
854 .data
= &fs_overflowuid
,
855 .maxlen
= sizeof(int),
857 .proc_handler
= &proc_dointvec_minmax
,
858 .strategy
= &sysctl_intvec
,
859 .extra1
= &minolduid
,
860 .extra2
= &maxolduid
,
863 .ctl_name
= FS_OVERFLOWGID
,
864 .procname
= "overflowgid",
865 .data
= &fs_overflowgid
,
866 .maxlen
= sizeof(int),
868 .proc_handler
= &proc_dointvec_minmax
,
869 .strategy
= &sysctl_intvec
,
870 .extra1
= &minolduid
,
871 .extra2
= &maxolduid
,
874 .ctl_name
= FS_LEASES
,
875 .procname
= "leases-enable",
876 .data
= &leases_enable
,
877 .maxlen
= sizeof(int),
879 .proc_handler
= &proc_dointvec
,
882 .ctl_name
= FS_DIR_NOTIFY
,
883 .procname
= "dir-notify-enable",
884 .data
= &dir_notify_enable
,
885 .maxlen
= sizeof(int),
887 .proc_handler
= &proc_dointvec
,
890 .ctl_name
= FS_LEASE_TIME
,
891 .procname
= "lease-break-time",
892 .data
= &lease_break_time
,
893 .maxlen
= sizeof(int),
895 .proc_handler
= &proc_dointvec
,
898 .ctl_name
= FS_AIO_NR
,
899 .procname
= "aio-nr",
901 .maxlen
= sizeof(aio_nr
),
903 .proc_handler
= &proc_dointvec
,
906 .ctl_name
= FS_AIO_MAX_NR
,
907 .procname
= "aio-max-nr",
909 .maxlen
= sizeof(aio_max_nr
),
911 .proc_handler
= &proc_dointvec
,
916 static ctl_table debug_table
[] = {
920 static ctl_table dev_table
[] = {
924 extern void init_irq_proc (void);
926 void __init
sysctl_init(void)
928 #ifdef CONFIG_PROC_FS
929 register_proc_table(root_table
, proc_sys_root
);
934 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
935 void __user
*newval
, size_t newlen
)
937 struct list_head
*tmp
;
939 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
943 if (!oldlenp
|| get_user(old_len
, oldlenp
))
946 tmp
= &root_table_header
.ctl_entry
;
948 struct ctl_table_header
*head
=
949 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
950 void *context
= NULL
;
951 int error
= parse_table(name
, nlen
, oldval
, oldlenp
,
952 newval
, newlen
, head
->ctl_table
,
956 if (error
!= -ENOTDIR
)
959 } while (tmp
!= &root_table_header
.ctl_entry
);
963 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
965 struct __sysctl_args tmp
;
968 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
972 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
973 tmp
.newval
, tmp
.newlen
);
979 * ctl_perm does NOT grant the superuser all rights automatically, because
980 * some sysctl variables are readonly even to root.
983 static int test_perm(int mode
, int op
)
987 else if (in_egroup_p(0))
989 if ((mode
& op
& 0007) == op
)
994 static inline int ctl_perm(ctl_table
*table
, int op
)
997 error
= security_sysctl(table
, op
);
1000 return test_perm(table
->mode
, op
);
1003 static int parse_table(int __user
*name
, int nlen
,
1004 void __user
*oldval
, size_t __user
*oldlenp
,
1005 void __user
*newval
, size_t newlen
,
1006 ctl_table
*table
, void **context
)
1012 if (get_user(n
, name
))
1014 for ( ; table
->ctl_name
; table
++) {
1015 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1018 if (ctl_perm(table
, 001))
1020 if (table
->strategy
) {
1021 error
= table
->strategy(
1024 newval
, newlen
, context
);
1030 table
= table
->child
;
1033 error
= do_sysctl_strategy(table
, name
, nlen
,
1035 newval
, newlen
, context
);
1042 /* Perform the actual read/write of a sysctl table entry. */
1043 int do_sysctl_strategy (ctl_table
*table
,
1044 int __user
*name
, int nlen
,
1045 void __user
*oldval
, size_t __user
*oldlenp
,
1046 void __user
*newval
, size_t newlen
, void **context
)
1055 if (ctl_perm(table
, op
))
1058 if (table
->strategy
) {
1059 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1060 newval
, newlen
, context
);
1067 /* If there is no strategy routine, or if the strategy returns
1068 * zero, proceed with automatic r/w */
1069 if (table
->data
&& table
->maxlen
) {
1070 if (oldval
&& oldlenp
) {
1071 if (get_user(len
, oldlenp
))
1074 if (len
> table
->maxlen
)
1075 len
= table
->maxlen
;
1076 if(copy_to_user(oldval
, table
->data
, len
))
1078 if(put_user(len
, oldlenp
))
1082 if (newval
&& newlen
) {
1084 if (len
> table
->maxlen
)
1085 len
= table
->maxlen
;
1086 if(copy_from_user(table
->data
, newval
, len
))
1094 * register_sysctl_table - register a sysctl hierarchy
1095 * @table: the top-level table structure
1096 * @insert_at_head: whether the entry should be inserted in front or at the end
1098 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1099 * array. An entry with a ctl_name of 0 terminates the table.
1101 * The members of the &ctl_table structure are used as follows:
1103 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1104 * must be unique within that level of sysctl
1106 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1107 * enter a sysctl file
1109 * data - a pointer to data for use by proc_handler
1111 * maxlen - the maximum size in bytes of the data
1113 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1115 * child - a pointer to the child sysctl table if this entry is a directory, or
1118 * proc_handler - the text handler routine (described below)
1120 * strategy - the strategy routine (described below)
1122 * de - for internal use by the sysctl routines
1124 * extra1, extra2 - extra pointers usable by the proc handler routines
1126 * Leaf nodes in the sysctl tree will be represented by a single file
1127 * under /proc; non-leaf nodes will be represented by directories.
1129 * sysctl(2) can automatically manage read and write requests through
1130 * the sysctl table. The data and maxlen fields of the ctl_table
1131 * struct enable minimal validation of the values being written to be
1132 * performed, and the mode field allows minimal authentication.
1134 * More sophisticated management can be enabled by the provision of a
1135 * strategy routine with the table entry. This will be called before
1136 * any automatic read or write of the data is performed.
1138 * The strategy routine may return
1140 * < 0 - Error occurred (error is passed to user process)
1142 * 0 - OK - proceed with automatic read or write.
1144 * > 0 - OK - read or write has been done by the strategy routine, so
1145 * return immediately.
1147 * There must be a proc_handler routine for any terminal nodes
1148 * mirrored under /proc/sys (non-terminals are handled by a built-in
1149 * directory handler). Several default handlers are available to
1150 * cover common cases -
1152 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1153 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1154 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1156 * It is the handler's job to read the input buffer from user memory
1157 * and process it. The handler should return 0 on success.
1159 * This routine returns %NULL on a failure to register, and a pointer
1160 * to the table header on success.
1162 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1165 struct ctl_table_header
*tmp
;
1166 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1169 tmp
->ctl_table
= table
;
1170 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1172 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1174 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1175 #ifdef CONFIG_PROC_FS
1176 register_proc_table(table
, proc_sys_root
);
1182 * unregister_sysctl_table - unregister a sysctl table hierarchy
1183 * @header: the header returned from register_sysctl_table
1185 * Unregisters the sysctl table and all children. proc entries may not
1186 * actually be removed until they are no longer used by anyone.
1188 void unregister_sysctl_table(struct ctl_table_header
* header
)
1190 list_del(&header
->ctl_entry
);
1191 #ifdef CONFIG_PROC_FS
1192 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1201 #ifdef CONFIG_PROC_FS
1203 /* Scan the sysctl entries in table and add them all into /proc */
1204 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1206 struct proc_dir_entry
*de
;
1210 for (; table
->ctl_name
; table
++) {
1211 /* Can't do anything without a proc name. */
1212 if (!table
->procname
)
1214 /* Maybe we can't do anything with it... */
1215 if (!table
->proc_handler
&& !table
->child
) {
1216 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1221 len
= strlen(table
->procname
);
1225 if (table
->proc_handler
)
1229 for (de
= root
->subdir
; de
; de
= de
->next
) {
1230 if (proc_match(len
, table
->procname
, de
))
1233 /* If the subdir exists already, de is non-NULL */
1237 de
= create_proc_entry(table
->procname
, mode
, root
);
1240 de
->data
= (void *) table
;
1241 if (table
->proc_handler
)
1242 de
->proc_fops
= &proc_sys_file_operations
;
1245 if (de
->mode
& S_IFDIR
)
1246 register_proc_table(table
->child
, de
);
1251 * Unregister a /proc sysctl table and any subdirectories.
1253 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1255 struct proc_dir_entry
*de
;
1256 for (; table
->ctl_name
; table
++) {
1257 if (!(de
= table
->de
))
1259 if (de
->mode
& S_IFDIR
) {
1260 if (!table
->child
) {
1261 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1264 unregister_proc_table(table
->child
, de
);
1266 /* Don't unregister directories which still have entries.. */
1271 /* Don't unregister proc entries that are still being used.. */
1272 if (atomic_read(&de
->count
))
1276 remove_proc_entry(table
->procname
, root
);
1280 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1281 size_t count
, loff_t
*ppos
)
1284 struct proc_dir_entry
*de
;
1285 struct ctl_table
*table
;
1289 de
= PDE(file
->f_dentry
->d_inode
);
1290 if (!de
|| !de
->data
)
1292 table
= (struct ctl_table
*) de
->data
;
1293 if (!table
|| !table
->proc_handler
)
1295 op
= (write
? 002 : 004);
1296 if (ctl_perm(table
, op
))
1301 error
= (*table
->proc_handler
) (table
, write
, file
, buf
, &res
, ppos
);
1307 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1309 if (file
->f_mode
& FMODE_WRITE
) {
1311 * sysctl entries that are not writable,
1312 * are _NOT_ writable, capabilities or not.
1314 if (!(inode
->i_mode
& S_IWUSR
))
1321 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1322 size_t count
, loff_t
*ppos
)
1324 return do_rw_proc(0, file
, buf
, count
, ppos
);
1327 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1328 size_t count
, loff_t
*ppos
)
1330 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1334 * proc_dostring - read a string sysctl
1335 * @table: the sysctl table
1336 * @write: %TRUE if this is a write to the sysctl file
1337 * @filp: the file structure
1338 * @buffer: the user buffer
1339 * @lenp: the size of the user buffer
1341 * Reads/writes a string from/to the user buffer. If the kernel
1342 * buffer provided is not large enough to hold the string, the
1343 * string is truncated. The copied string is %NULL-terminated.
1344 * If the string is being read by the user process, it is copied
1345 * and a newline '\n' is added. It is truncated if the buffer is
1348 * Returns 0 on success.
1350 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1351 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1357 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1358 (*ppos
&& !write
)) {
1366 while (len
< *lenp
) {
1367 if (get_user(c
, p
++))
1369 if (c
== 0 || c
== '\n')
1373 if (len
>= table
->maxlen
)
1374 len
= table
->maxlen
-1;
1375 if(copy_from_user(table
->data
, buffer
, len
))
1377 ((char *) table
->data
)[len
] = 0;
1380 len
= strlen(table
->data
);
1381 if (len
> table
->maxlen
)
1382 len
= table
->maxlen
;
1386 if(copy_to_user(buffer
, table
->data
, len
))
1389 if(put_user('\n', ((char __user
*) buffer
) + len
))
1400 * Special case of dostring for the UTS structure. This has locks
1401 * to observe. Should this be in kernel/sys.c ????
1404 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1405 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1410 down_read(&uts_sem
);
1411 r
=proc_dostring(table
,0,filp
,buffer
,lenp
, ppos
);
1414 down_write(&uts_sem
);
1415 r
=proc_dostring(table
,1,filp
,buffer
,lenp
, ppos
);
1421 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1423 int write
, void *data
)
1426 *valp
= *negp
? -*lvalp
: *lvalp
;
1431 *lvalp
= (unsigned long)-val
;
1434 *lvalp
= (unsigned long)val
;
1440 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1441 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
1442 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1443 int write
, void *data
),
1446 #define TMPBUFLEN 21
1447 int *i
, vleft
, first
=1, neg
, val
;
1451 char buf
[TMPBUFLEN
], *p
;
1452 char __user
*s
= buffer
;
1454 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1455 (*ppos
&& !write
)) {
1460 i
= (int *) table
->data
;
1461 vleft
= table
->maxlen
/ sizeof(*i
);
1465 conv
= do_proc_dointvec_conv
;
1467 for (; left
&& vleft
--; i
++, first
=0) {
1482 if (len
> sizeof(buf
) - 1)
1483 len
= sizeof(buf
) - 1;
1484 if (copy_from_user(buf
, s
, len
))
1488 if (*p
== '-' && left
> 1) {
1492 if (*p
< '0' || *p
> '9')
1495 lval
= simple_strtoul(p
, &p
, 0);
1498 if ((len
< left
) && *p
&& !isspace(*p
))
1505 if (conv(&neg
, &lval
, i
, 1, data
))
1512 if (conv(&neg
, &lval
, i
, 0, data
))
1515 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1519 if(copy_to_user(s
, buf
, len
))
1526 if (!write
&& !first
&& left
) {
1527 if(put_user('\n', s
))
1534 if (get_user(c
, s
++))
1550 * proc_dointvec - read a vector of integers
1551 * @table: the sysctl table
1552 * @write: %TRUE if this is a write to the sysctl file
1553 * @filp: the file structure
1554 * @buffer: the user buffer
1555 * @lenp: the size of the user buffer
1557 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1558 * values from/to the user buffer, treated as an ASCII string.
1560 * Returns 0 on success.
1562 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1563 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1565 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1575 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1577 int write
, void *data
)
1579 int op
= *(int *)data
;
1581 int val
= *negp
? -*lvalp
: *lvalp
;
1583 case OP_SET
: *valp
= val
; break;
1584 case OP_AND
: *valp
&= val
; break;
1585 case OP_OR
: *valp
|= val
; break;
1586 case OP_MAX
: if(*valp
< val
)
1589 case OP_MIN
: if(*valp
> val
)
1597 *lvalp
= (unsigned long)-val
;
1600 *lvalp
= (unsigned long)val
;
1607 * init may raise the set.
1610 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1611 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1615 if (!capable(CAP_SYS_MODULE
)) {
1619 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1620 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1621 do_proc_dointvec_bset_conv
,&op
);
1624 struct do_proc_dointvec_minmax_conv_param
{
1629 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1631 int write
, void *data
)
1633 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1635 int val
= *negp
? -*lvalp
: *lvalp
;
1636 if ((param
->min
&& *param
->min
> val
) ||
1637 (param
->max
&& *param
->max
< val
))
1644 *lvalp
= (unsigned long)-val
;
1647 *lvalp
= (unsigned long)val
;
1654 * proc_dointvec_minmax - read a vector of integers with min/max values
1655 * @table: the sysctl table
1656 * @write: %TRUE if this is a write to the sysctl file
1657 * @filp: the file structure
1658 * @buffer: the user buffer
1659 * @lenp: the size of the user buffer
1661 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1662 * values from/to the user buffer, treated as an ASCII string.
1664 * This routine will ensure the values are within the range specified by
1665 * table->extra1 (min) and table->extra2 (max).
1667 * Returns 0 on success.
1669 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1670 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1672 struct do_proc_dointvec_minmax_conv_param param
= {
1673 .min
= (int *) table
->extra1
,
1674 .max
= (int *) table
->extra2
,
1676 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
, ppos
,
1677 do_proc_dointvec_minmax_conv
, ¶m
);
1680 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1682 void __user
*buffer
,
1683 size_t *lenp
, loff_t
*ppos
,
1684 unsigned long convmul
,
1685 unsigned long convdiv
)
1687 #define TMPBUFLEN 21
1688 unsigned long *i
, *min
, *max
, val
;
1689 int vleft
, first
=1, neg
;
1691 char buf
[TMPBUFLEN
], *p
;
1692 char __user
*s
= buffer
;
1694 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1695 (*ppos
&& !write
)) {
1700 i
= (unsigned long *) table
->data
;
1701 min
= (unsigned long *) table
->extra1
;
1702 max
= (unsigned long *) table
->extra2
;
1703 vleft
= table
->maxlen
/ sizeof(unsigned long);
1706 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1721 if (len
> TMPBUFLEN
-1)
1723 if (copy_from_user(buf
, s
, len
))
1727 if (*p
== '-' && left
> 1) {
1731 if (*p
< '0' || *p
> '9')
1733 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1735 if ((len
< left
) && *p
&& !isspace(*p
))
1744 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1751 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1755 if(copy_to_user(s
, buf
, len
))
1762 if (!write
&& !first
&& left
) {
1763 if(put_user('\n', s
))
1770 if (get_user(c
, s
++))
1786 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1787 * @table: the sysctl table
1788 * @write: %TRUE if this is a write to the sysctl file
1789 * @filp: the file structure
1790 * @buffer: the user buffer
1791 * @lenp: the size of the user buffer
1793 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1794 * values from/to the user buffer, treated as an ASCII string.
1796 * This routine will ensure the values are within the range specified by
1797 * table->extra1 (min) and table->extra2 (max).
1799 * Returns 0 on success.
1801 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1802 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1804 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, ppos
, 1l, 1l);
1808 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1809 * @table: the sysctl table
1810 * @write: %TRUE if this is a write to the sysctl file
1811 * @filp: the file structure
1812 * @buffer: the user buffer
1813 * @lenp: the size of the user buffer
1815 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1816 * values from/to the user buffer, treated as an ASCII string. The values
1817 * are treated as milliseconds, and converted to jiffies when they are stored.
1819 * This routine will ensure the values are within the range specified by
1820 * table->extra1 (min) and table->extra2 (max).
1822 * Returns 0 on success.
1824 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1826 void __user
*buffer
,
1827 size_t *lenp
, loff_t
*ppos
)
1829 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1830 lenp
, ppos
, HZ
, 1000l);
1834 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
1836 int write
, void *data
)
1839 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
1845 lval
= (unsigned long)-val
;
1848 lval
= (unsigned long)val
;
1855 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
1857 int write
, void *data
)
1860 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1866 lval
= (unsigned long)-val
;
1869 lval
= (unsigned long)val
;
1871 *lvalp
= jiffies_to_clock_t(lval
);
1877 * proc_dointvec_jiffies - read a vector of integers as seconds
1878 * @table: the sysctl table
1879 * @write: %TRUE if this is a write to the sysctl file
1880 * @filp: the file structure
1881 * @buffer: the user buffer
1882 * @lenp: the size of the user buffer
1884 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1885 * values from/to the user buffer, treated as an ASCII string.
1886 * The values read are assumed to be in seconds, and are converted into
1889 * Returns 0 on success.
1891 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1892 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1894 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1895 do_proc_dointvec_jiffies_conv
,NULL
);
1899 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1900 * @table: the sysctl table
1901 * @write: %TRUE if this is a write to the sysctl file
1902 * @filp: the file structure
1903 * @buffer: the user buffer
1904 * @lenp: the size of the user buffer
1906 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1907 * values from/to the user buffer, treated as an ASCII string.
1908 * The values read are assumed to be in 1/USER_HZ seconds, and
1909 * are converted into jiffies.
1911 * Returns 0 on success.
1913 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1914 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1916 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,ppos
,
1917 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
1920 #else /* CONFIG_PROC_FS */
1922 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1923 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1928 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1929 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1934 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1935 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1940 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1941 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1946 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1947 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1952 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1953 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1958 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1959 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1964 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1965 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
1970 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1972 void __user
*buffer
,
1973 size_t *lenp
, loff_t
*ppos
)
1979 #endif /* CONFIG_PROC_FS */
1983 * General sysctl support routines
1986 /* The generic string strategy routine: */
1987 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
1988 void __user
*oldval
, size_t __user
*oldlenp
,
1989 void __user
*newval
, size_t newlen
, void **context
)
1993 if (!table
->data
|| !table
->maxlen
)
1996 if (oldval
&& oldlenp
) {
1997 if (get_user(len
, oldlenp
))
2000 l
= strlen(table
->data
);
2001 if (len
> l
) len
= l
;
2002 if (len
>= table
->maxlen
)
2003 len
= table
->maxlen
;
2004 if(copy_to_user(oldval
, table
->data
, len
))
2006 if(put_user(0, ((char __user
*) oldval
) + len
))
2008 if(put_user(len
, oldlenp
))
2012 if (newval
&& newlen
) {
2014 if (len
> table
->maxlen
)
2015 len
= table
->maxlen
;
2016 if(copy_from_user(table
->data
, newval
, len
))
2018 if (len
== table
->maxlen
)
2020 ((char *) table
->data
)[len
] = 0;
2026 * This function makes sure that all of the integers in the vector
2027 * are between the minimum and maximum values given in the arrays
2028 * table->extra1 and table->extra2, respectively.
2030 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2031 void __user
*oldval
, size_t __user
*oldlenp
,
2032 void __user
*newval
, size_t newlen
, void **context
)
2035 if (newval
&& newlen
) {
2036 int __user
*vec
= (int __user
*) newval
;
2037 int *min
= (int *) table
->extra1
;
2038 int *max
= (int *) table
->extra2
;
2042 if (newlen
% sizeof(int) != 0)
2045 if (!table
->extra1
&& !table
->extra2
)
2048 if (newlen
> table
->maxlen
)
2049 newlen
= table
->maxlen
;
2050 length
= newlen
/ sizeof(int);
2052 for (i
= 0; i
< length
; i
++) {
2054 if (get_user(value
, vec
+ i
))
2056 if (min
&& value
< min
[i
])
2058 if (max
&& value
> max
[i
])
2065 /* Strategy function to convert jiffies to seconds */
2066 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2067 void __user
*oldval
, size_t __user
*oldlenp
,
2068 void __user
*newval
, size_t newlen
, void **context
)
2073 if (get_user(olen
, oldlenp
))
2075 if (olen
!=sizeof(int))
2078 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2079 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2082 if (newval
&& newlen
) {
2084 if (newlen
!= sizeof(int))
2086 if (get_user(new, (int __user
*)newval
))
2088 *(int *)(table
->data
) = new*HZ
;
2094 #else /* CONFIG_SYSCTL */
2097 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2102 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2103 void __user
*oldval
, size_t __user
*oldlenp
,
2104 void __user
*newval
, size_t newlen
, void **context
)
2109 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2110 void __user
*oldval
, size_t __user
*oldlenp
,
2111 void __user
*newval
, size_t newlen
, void **context
)
2116 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2117 void __user
*oldval
, size_t __user
*oldlenp
,
2118 void __user
*newval
, size_t newlen
, void **context
)
2123 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2124 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2129 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2130 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2135 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2136 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2141 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2142 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2147 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2148 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2153 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2154 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2159 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2160 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2165 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2167 void __user
*buffer
,
2168 size_t *lenp
, loff_t
*ppos
)
2173 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2179 void unregister_sysctl_table(struct ctl_table_header
* table
)
2183 #endif /* CONFIG_SYSCTL */
2186 * No sense putting this after each symbol definition, twice,
2187 * exception granted :-)
2189 EXPORT_SYMBOL(proc_dointvec
);
2190 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2191 EXPORT_SYMBOL(proc_dointvec_minmax
);
2192 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2193 EXPORT_SYMBOL(proc_dostring
);
2194 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2195 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2196 EXPORT_SYMBOL(register_sysctl_table
);
2197 EXPORT_SYMBOL(sysctl_intvec
);
2198 EXPORT_SYMBOL(sysctl_jiffies
);
2199 EXPORT_SYMBOL(sysctl_string
);
2200 EXPORT_SYMBOL(unregister_sysctl_table
);