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>
46 #ifdef CONFIG_ROOT_NFS
47 #include <linux/nfs_fs.h>
50 #if defined(CONFIG_SYSCTL)
52 /* External variables not in a header file. */
53 extern int panic_timeout
;
55 extern int sysctl_overcommit_memory
;
56 extern int sysctl_overcommit_ratio
;
57 extern int max_threads
;
58 extern int sysrq_enabled
;
59 extern int core_uses_pid
;
60 extern char core_pattern
[];
63 extern int sysctl_lower_zone_protection
;
64 extern int min_free_kbytes
;
65 extern int printk_ratelimit_jiffies
;
66 extern int printk_ratelimit_burst
;
68 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
69 static int maxolduid
= 65535;
72 static int ngroups_max
= NGROUPS_MAX
;
75 extern char modprobe_path
[];
78 extern char hotplug_path
[];
80 #ifdef CONFIG_CHR_DEV_SG
81 extern int sg_big_buff
;
84 extern size_t shm_ctlmax
;
85 extern size_t shm_ctlall
;
86 extern int shm_ctlmni
;
87 extern int msg_ctlmax
;
88 extern int msg_ctlmnb
;
89 extern int msg_ctlmni
;
90 extern int sem_ctls
[];
94 extern char reboot_command
[];
95 extern int stop_a_enabled
;
96 extern int scons_pwroff
;
100 extern int pwrsw_enabled
;
101 extern int unaligned_enabled
;
104 #ifdef CONFIG_ARCH_S390
105 #ifdef CONFIG_MATHEMU
106 extern int sysctl_ieee_emulation_warnings
;
108 extern int sysctl_userprocess_debug
;
111 extern int sysctl_hz_timer
;
113 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
114 extern unsigned long powersave_nap
;
115 int proc_dol2crvec(ctl_table
*table
, int write
, struct file
*filp
,
116 void *buffer
, size_t *lenp
);
119 #ifdef CONFIG_BSD_PROCESS_ACCT
120 extern int acct_parm
[];
123 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
124 ctl_table
*, void **);
125 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
126 void __user
*buffer
, size_t *lenp
);
128 static ctl_table root_table
[];
129 static struct ctl_table_header root_table_header
=
130 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
132 static ctl_table kern_table
[];
133 static ctl_table vm_table
[];
135 extern ctl_table net_table
[];
137 static ctl_table proc_table
[];
138 static ctl_table fs_table
[];
139 static ctl_table debug_table
[];
140 static ctl_table dev_table
[];
141 extern ctl_table random_table
[];
142 #ifdef CONFIG_UNIX98_PTYS
143 extern ctl_table pty_table
[];
146 /* /proc declarations: */
148 #ifdef CONFIG_PROC_FS
150 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
151 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
152 static int proc_opensys(struct inode
*, struct file
*);
154 struct file_operations proc_sys_file_operations
= {
155 .open
= proc_opensys
,
156 .read
= proc_readsys
,
157 .write
= proc_writesys
,
160 extern struct proc_dir_entry
*proc_sys_root
;
162 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*);
163 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
166 /* The default sysctl tables: */
168 static ctl_table root_table
[] = {
170 .ctl_name
= CTL_KERN
,
171 .procname
= "kernel",
190 .ctl_name
= CTL_PROC
,
202 .ctl_name
= CTL_DEBUG
,
205 .child
= debug_table
,
216 static ctl_table kern_table
[] = {
218 .ctl_name
= KERN_OSTYPE
,
219 .procname
= "ostype",
220 .data
= system_utsname
.sysname
,
221 .maxlen
= sizeof(system_utsname
.sysname
),
223 .proc_handler
= &proc_doutsstring
,
224 .strategy
= &sysctl_string
,
227 .ctl_name
= KERN_OSRELEASE
,
228 .procname
= "osrelease",
229 .data
= system_utsname
.release
,
230 .maxlen
= sizeof(system_utsname
.release
),
232 .proc_handler
= &proc_doutsstring
,
233 .strategy
= &sysctl_string
,
236 .ctl_name
= KERN_VERSION
,
237 .procname
= "version",
238 .data
= system_utsname
.version
,
239 .maxlen
= sizeof(system_utsname
.version
),
241 .proc_handler
= &proc_doutsstring
,
242 .strategy
= &sysctl_string
,
245 .ctl_name
= KERN_NODENAME
,
246 .procname
= "hostname",
247 .data
= system_utsname
.nodename
,
248 .maxlen
= sizeof(system_utsname
.nodename
),
250 .proc_handler
= &proc_doutsstring
,
251 .strategy
= &sysctl_string
,
254 .ctl_name
= KERN_DOMAINNAME
,
255 .procname
= "domainname",
256 .data
= system_utsname
.domainname
,
257 .maxlen
= sizeof(system_utsname
.domainname
),
259 .proc_handler
= &proc_doutsstring
,
260 .strategy
= &sysctl_string
,
263 .ctl_name
= KERN_PANIC
,
265 .data
= &panic_timeout
,
266 .maxlen
= sizeof(int),
268 .proc_handler
= &proc_dointvec
,
271 .ctl_name
= KERN_CORE_USES_PID
,
272 .procname
= "core_uses_pid",
273 .data
= &core_uses_pid
,
274 .maxlen
= sizeof(int),
276 .proc_handler
= &proc_dointvec
,
279 .ctl_name
= KERN_CORE_PATTERN
,
280 .procname
= "core_pattern",
281 .data
= core_pattern
,
284 .proc_handler
= &proc_dostring
,
285 .strategy
= &sysctl_string
,
288 .ctl_name
= KERN_TAINTED
,
289 .procname
= "tainted",
291 .maxlen
= sizeof(int),
293 .proc_handler
= &proc_dointvec
,
296 .ctl_name
= KERN_CAP_BSET
,
297 .procname
= "cap-bound",
299 .maxlen
= sizeof(kernel_cap_t
),
301 .proc_handler
= &proc_dointvec_bset
,
303 #ifdef CONFIG_BLK_DEV_INITRD
305 .ctl_name
= KERN_REALROOTDEV
,
306 .procname
= "real-root-dev",
307 .data
= &real_root_dev
,
308 .maxlen
= sizeof(int),
310 .proc_handler
= &proc_dointvec
,
315 .ctl_name
= KERN_SPARC_REBOOT
,
316 .procname
= "reboot-cmd",
317 .data
= reboot_command
,
320 .proc_handler
= &proc_dostring
,
321 .strategy
= &sysctl_string
,
324 .ctl_name
= KERN_SPARC_STOP_A
,
325 .procname
= "stop-a",
326 .data
= &stop_a_enabled
,
327 .maxlen
= sizeof (int),
329 .proc_handler
= &proc_dointvec
,
332 .ctl_name
= KERN_SPARC_SCONS_PWROFF
,
333 .procname
= "scons-poweroff",
334 .data
= &scons_pwroff
,
335 .maxlen
= sizeof (int),
337 .proc_handler
= &proc_dointvec
,
342 .ctl_name
= KERN_HPPA_PWRSW
,
343 .procname
= "soft-power",
344 .data
= &pwrsw_enabled
,
345 .maxlen
= sizeof (int),
347 .proc_handler
= &proc_dointvec
,
350 .ctl_name
= KERN_HPPA_UNALIGNED
,
351 .procname
= "unaligned-trap",
352 .data
= &unaligned_enabled
,
353 .maxlen
= sizeof (int),
355 .proc_handler
= &proc_dointvec
,
358 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
360 .ctl_name
= KERN_PPC_POWERSAVE_NAP
,
361 .procname
= "powersave-nap",
362 .data
= &powersave_nap
,
363 .maxlen
= sizeof(int),
365 .proc_handler
= &proc_dointvec
,
368 .ctl_name
= KERN_PPC_L2CR
,
371 .proc_handler
= &proc_dol2crvec
,
375 .ctl_name
= KERN_CTLALTDEL
,
376 .procname
= "ctrl-alt-del",
378 .maxlen
= sizeof(int),
380 .proc_handler
= &proc_dointvec
,
383 .ctl_name
= KERN_PRINTK
,
384 .procname
= "printk",
385 .data
= &console_loglevel
,
386 .maxlen
= 4*sizeof(int),
388 .proc_handler
= &proc_dointvec
,
392 .ctl_name
= KERN_MODPROBE
,
393 .procname
= "modprobe",
394 .data
= &modprobe_path
,
395 .maxlen
= KMOD_PATH_LEN
,
397 .proc_handler
= &proc_dostring
,
398 .strategy
= &sysctl_string
,
401 #ifdef CONFIG_HOTPLUG
403 .ctl_name
= KERN_HOTPLUG
,
404 .procname
= "hotplug",
405 .data
= &hotplug_path
,
406 .maxlen
= KMOD_PATH_LEN
,
408 .proc_handler
= &proc_dostring
,
409 .strategy
= &sysctl_string
,
412 #ifdef CONFIG_CHR_DEV_SG
414 .ctl_name
= KERN_SG_BIG_BUFF
,
415 .procname
= "sg-big-buff",
416 .data
= &sg_big_buff
,
417 .maxlen
= sizeof (int),
419 .proc_handler
= &proc_dointvec
,
422 #ifdef CONFIG_BSD_PROCESS_ACCT
424 .ctl_name
= KERN_ACCT
,
427 .maxlen
= 3*sizeof(int),
429 .proc_handler
= &proc_dointvec
,
432 #ifdef CONFIG_SYSVIPC
434 .ctl_name
= KERN_SHMMAX
,
435 .procname
= "shmmax",
437 .maxlen
= sizeof (size_t),
439 .proc_handler
= &proc_doulongvec_minmax
,
442 .ctl_name
= KERN_SHMALL
,
443 .procname
= "shmall",
445 .maxlen
= sizeof (size_t),
447 .proc_handler
= &proc_doulongvec_minmax
,
450 .ctl_name
= KERN_SHMMNI
,
451 .procname
= "shmmni",
453 .maxlen
= sizeof (int),
455 .proc_handler
= &proc_dointvec
,
458 .ctl_name
= KERN_MSGMAX
,
459 .procname
= "msgmax",
461 .maxlen
= sizeof (int),
463 .proc_handler
= &proc_dointvec
,
466 .ctl_name
= KERN_MSGMNI
,
467 .procname
= "msgmni",
469 .maxlen
= sizeof (int),
471 .proc_handler
= &proc_dointvec
,
474 .ctl_name
= KERN_MSGMNB
,
475 .procname
= "msgmnb",
477 .maxlen
= sizeof (int),
479 .proc_handler
= &proc_dointvec
,
482 .ctl_name
= KERN_SEM
,
485 .maxlen
= 4*sizeof (int),
487 .proc_handler
= &proc_dointvec
,
490 #ifdef CONFIG_MAGIC_SYSRQ
492 .ctl_name
= KERN_SYSRQ
,
494 .data
= &sysrq_enabled
,
495 .maxlen
= sizeof (int),
497 .proc_handler
= &proc_dointvec
,
501 .ctl_name
= KERN_CADPID
,
502 .procname
= "cad_pid",
504 .maxlen
= sizeof (int),
506 .proc_handler
= &proc_dointvec
,
509 .ctl_name
= KERN_MAX_THREADS
,
510 .procname
= "threads-max",
511 .data
= &max_threads
,
512 .maxlen
= sizeof(int),
514 .proc_handler
= &proc_dointvec
,
517 .ctl_name
= KERN_RANDOM
,
518 .procname
= "random",
520 .child
= random_table
,
522 #ifdef CONFIG_UNIX98_PTYS
524 .ctl_name
= KERN_PTY
,
531 .ctl_name
= KERN_OVERFLOWUID
,
532 .procname
= "overflowuid",
533 .data
= &overflowuid
,
534 .maxlen
= sizeof(int),
536 .proc_handler
= &proc_dointvec_minmax
,
537 .strategy
= &sysctl_intvec
,
538 .extra1
= &minolduid
,
539 .extra2
= &maxolduid
,
542 .ctl_name
= KERN_OVERFLOWGID
,
543 .procname
= "overflowgid",
544 .data
= &overflowgid
,
545 .maxlen
= sizeof(int),
547 .proc_handler
= &proc_dointvec_minmax
,
548 .strategy
= &sysctl_intvec
,
549 .extra1
= &minolduid
,
550 .extra2
= &maxolduid
,
552 #ifdef CONFIG_ARCH_S390
553 #ifdef CONFIG_MATHEMU
555 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
556 .procname
= "ieee_emulation_warnings",
557 .data
= &sysctl_ieee_emulation_warnings
,
558 .maxlen
= sizeof(int),
560 .proc_handler
= &proc_dointvec
,
563 #ifdef CONFIG_NO_IDLE_HZ
565 .ctl_name
= KERN_HZ_TIMER
,
566 .procname
= "hz_timer",
567 .data
= &sysctl_hz_timer
,
568 .maxlen
= sizeof(int),
570 .proc_handler
= &proc_dointvec
,
574 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
575 .procname
= "userprocess_debug",
576 .data
= &sysctl_userprocess_debug
,
577 .maxlen
= sizeof(int),
579 .proc_handler
= &proc_dointvec
,
583 .ctl_name
= KERN_PIDMAX
,
584 .procname
= "pid_max",
586 .maxlen
= sizeof (int),
588 .proc_handler
= &proc_dointvec
,
591 .ctl_name
= KERN_PANIC_ON_OOPS
,
592 .procname
= "panic_on_oops",
593 .data
= &panic_on_oops
,
594 .maxlen
= sizeof(int),
596 .proc_handler
= &proc_dointvec
,
599 .ctl_name
= KERN_PRINTK_RATELIMIT
,
600 .procname
= "printk_ratelimit",
601 .data
= &printk_ratelimit_jiffies
,
602 .maxlen
= sizeof(int),
604 .proc_handler
= &proc_dointvec_jiffies
,
605 .strategy
= &sysctl_jiffies
,
608 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
609 .procname
= "printk_ratelimit_burst",
610 .data
= &printk_ratelimit_burst
,
611 .maxlen
= sizeof(int),
613 .proc_handler
= &proc_dointvec
,
616 .ctl_name
= KERN_NGROUPS_MAX
,
617 .procname
= "ngroups_max",
618 .data
= &ngroups_max
,
619 .maxlen
= sizeof (int),
621 .proc_handler
= &proc_dointvec
,
626 /* Constants for minimum and maximum testing in vm_table.
627 We use these as one-element integer vectors. */
629 static int one_hundred
= 100;
632 static ctl_table vm_table
[] = {
634 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
635 .procname
= "overcommit_memory",
636 .data
= &sysctl_overcommit_memory
,
637 .maxlen
= sizeof(sysctl_overcommit_memory
),
639 .proc_handler
= &proc_dointvec
,
642 .ctl_name
= VM_OVERCOMMIT_RATIO
,
643 .procname
= "overcommit_ratio",
644 .data
= &sysctl_overcommit_ratio
,
645 .maxlen
= sizeof(sysctl_overcommit_ratio
),
647 .proc_handler
= &proc_dointvec
,
650 .ctl_name
= VM_PAGE_CLUSTER
,
651 .procname
= "page-cluster",
652 .data
= &page_cluster
,
653 .maxlen
= sizeof(int),
655 .proc_handler
= &proc_dointvec
,
658 .ctl_name
= VM_DIRTY_BACKGROUND
,
659 .procname
= "dirty_background_ratio",
660 .data
= &dirty_background_ratio
,
661 .maxlen
= sizeof(dirty_background_ratio
),
663 .proc_handler
= &proc_dointvec_minmax
,
664 .strategy
= &sysctl_intvec
,
666 .extra2
= &one_hundred
,
669 .ctl_name
= VM_DIRTY_RATIO
,
670 .procname
= "dirty_ratio",
671 .data
= &vm_dirty_ratio
,
672 .maxlen
= sizeof(vm_dirty_ratio
),
674 .proc_handler
= &proc_dointvec_minmax
,
675 .strategy
= &sysctl_intvec
,
677 .extra2
= &one_hundred
,
680 .ctl_name
= VM_DIRTY_WB_CS
,
681 .procname
= "dirty_writeback_centisecs",
682 .data
= &dirty_writeback_centisecs
,
683 .maxlen
= sizeof(dirty_writeback_centisecs
),
685 .proc_handler
= &dirty_writeback_centisecs_handler
,
688 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
689 .procname
= "dirty_expire_centisecs",
690 .data
= &dirty_expire_centisecs
,
691 .maxlen
= sizeof(dirty_expire_centisecs
),
693 .proc_handler
= &proc_dointvec
,
696 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
697 .procname
= "nr_pdflush_threads",
698 .data
= &nr_pdflush_threads
,
699 .maxlen
= sizeof nr_pdflush_threads
,
700 .mode
= 0444 /* read-only*/,
701 .proc_handler
= &proc_dointvec
,
704 .ctl_name
= VM_SWAPPINESS
,
705 .procname
= "swappiness",
706 .data
= &vm_swappiness
,
707 .maxlen
= sizeof(vm_swappiness
),
709 .proc_handler
= &proc_dointvec_minmax
,
710 .strategy
= &sysctl_intvec
,
712 .extra2
= &one_hundred
,
714 #ifdef CONFIG_HUGETLB_PAGE
716 .ctl_name
= VM_HUGETLB_PAGES
,
717 .procname
= "nr_hugepages",
718 .data
= &max_huge_pages
,
719 .maxlen
= sizeof(unsigned long),
721 .proc_handler
= &hugetlb_sysctl_handler
,
722 .extra1
= (void *)&hugetlb_zero
,
723 .extra2
= (void *)&hugetlb_infinity
,
726 .ctl_name
= VM_HUGETLB_GROUP
,
727 .procname
= "hugetlb_shm_group",
728 .data
= &sysctl_hugetlb_shm_group
,
729 .maxlen
= sizeof(gid_t
),
731 .proc_handler
= &proc_dointvec
,
735 .ctl_name
= VM_LOWER_ZONE_PROTECTION
,
736 .procname
= "lower_zone_protection",
737 .data
= &sysctl_lower_zone_protection
,
738 .maxlen
= sizeof(sysctl_lower_zone_protection
),
740 .proc_handler
= &lower_zone_protection_sysctl_handler
,
741 .strategy
= &sysctl_intvec
,
745 .ctl_name
= VM_MIN_FREE_KBYTES
,
746 .procname
= "min_free_kbytes",
747 .data
= &min_free_kbytes
,
748 .maxlen
= sizeof(min_free_kbytes
),
750 .proc_handler
= &min_free_kbytes_sysctl_handler
,
751 .strategy
= &sysctl_intvec
,
755 .ctl_name
= VM_MAX_MAP_COUNT
,
756 .procname
= "max_map_count",
757 .data
= &sysctl_max_map_count
,
758 .maxlen
= sizeof(sysctl_max_map_count
),
760 .proc_handler
= &proc_dointvec
763 .ctl_name
= VM_LAPTOP_MODE
,
764 .procname
= "laptop_mode",
765 .data
= &laptop_mode
,
766 .maxlen
= sizeof(laptop_mode
),
768 .proc_handler
= &proc_dointvec
,
769 .strategy
= &sysctl_intvec
,
773 .ctl_name
= VM_BLOCK_DUMP
,
774 .procname
= "block_dump",
776 .maxlen
= sizeof(block_dump
),
778 .proc_handler
= &proc_dointvec
,
779 .strategy
= &sysctl_intvec
,
783 .ctl_name
= VM_VFS_CACHE_PRESSURE
,
784 .procname
= "vfs_cache_pressure",
785 .data
= &sysctl_vfs_cache_pressure
,
786 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
788 .proc_handler
= &proc_dointvec
,
789 .strategy
= &sysctl_intvec
,
795 static ctl_table proc_table
[] = {
799 static ctl_table fs_table
[] = {
801 .ctl_name
= FS_NRINODE
,
802 .procname
= "inode-nr",
803 .data
= &inodes_stat
,
804 .maxlen
= 2*sizeof(int),
806 .proc_handler
= &proc_dointvec
,
809 .ctl_name
= FS_STATINODE
,
810 .procname
= "inode-state",
811 .data
= &inodes_stat
,
812 .maxlen
= 7*sizeof(int),
814 .proc_handler
= &proc_dointvec
,
817 .ctl_name
= FS_NRFILE
,
818 .procname
= "file-nr",
820 .maxlen
= 3*sizeof(int),
822 .proc_handler
= &proc_dointvec
,
825 .ctl_name
= FS_MAXFILE
,
826 .procname
= "file-max",
827 .data
= &files_stat
.max_files
,
828 .maxlen
= sizeof(int),
830 .proc_handler
= &proc_dointvec
,
833 .ctl_name
= FS_DENTRY
,
834 .procname
= "dentry-state",
835 .data
= &dentry_stat
,
836 .maxlen
= 6*sizeof(int),
838 .proc_handler
= &proc_dointvec
,
841 .ctl_name
= FS_OVERFLOWUID
,
842 .procname
= "overflowuid",
843 .data
= &fs_overflowuid
,
844 .maxlen
= sizeof(int),
846 .proc_handler
= &proc_dointvec_minmax
,
847 .strategy
= &sysctl_intvec
,
848 .extra1
= &minolduid
,
849 .extra2
= &maxolduid
,
852 .ctl_name
= FS_OVERFLOWGID
,
853 .procname
= "overflowgid",
854 .data
= &fs_overflowgid
,
855 .maxlen
= sizeof(int),
857 .proc_handler
= &proc_dointvec_minmax
,
858 .strategy
= &sysctl_intvec
,
859 .extra1
= &minolduid
,
860 .extra2
= &maxolduid
,
863 .ctl_name
= FS_LEASES
,
864 .procname
= "leases-enable",
865 .data
= &leases_enable
,
866 .maxlen
= sizeof(int),
868 .proc_handler
= &proc_dointvec
,
871 .ctl_name
= FS_DIR_NOTIFY
,
872 .procname
= "dir-notify-enable",
873 .data
= &dir_notify_enable
,
874 .maxlen
= sizeof(int),
876 .proc_handler
= &proc_dointvec
,
879 .ctl_name
= FS_LEASE_TIME
,
880 .procname
= "lease-break-time",
881 .data
= &lease_break_time
,
882 .maxlen
= sizeof(int),
884 .proc_handler
= &proc_dointvec
,
887 .ctl_name
= FS_AIO_NR
,
888 .procname
= "aio-nr",
890 .maxlen
= sizeof(aio_nr
),
892 .proc_handler
= &proc_dointvec
,
895 .ctl_name
= FS_AIO_MAX_NR
,
896 .procname
= "aio-max-nr",
898 .maxlen
= sizeof(aio_max_nr
),
900 .proc_handler
= &proc_dointvec
,
905 static ctl_table debug_table
[] = {
909 static ctl_table dev_table
[] = {
913 extern void init_irq_proc (void);
915 void __init
sysctl_init(void)
917 #ifdef CONFIG_PROC_FS
918 register_proc_table(root_table
, proc_sys_root
);
923 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
924 void __user
*newval
, size_t newlen
)
926 struct list_head
*tmp
;
928 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
932 if (!oldlenp
|| get_user(old_len
, oldlenp
))
935 tmp
= &root_table_header
.ctl_entry
;
937 struct ctl_table_header
*head
=
938 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
939 void *context
= NULL
;
940 int error
= parse_table(name
, nlen
, oldval
, oldlenp
,
941 newval
, newlen
, head
->ctl_table
,
945 if (error
!= -ENOTDIR
)
948 } while (tmp
!= &root_table_header
.ctl_entry
);
952 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
954 struct __sysctl_args tmp
;
957 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
961 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
962 tmp
.newval
, tmp
.newlen
);
968 * ctl_perm does NOT grant the superuser all rights automatically, because
969 * some sysctl variables are readonly even to root.
972 static int test_perm(int mode
, int op
)
976 else if (in_egroup_p(0))
978 if ((mode
& op
& 0007) == op
)
983 static inline int ctl_perm(ctl_table
*table
, int op
)
986 error
= security_sysctl(table
, op
);
989 return test_perm(table
->mode
, op
);
992 static int parse_table(int __user
*name
, int nlen
,
993 void __user
*oldval
, size_t __user
*oldlenp
,
994 void __user
*newval
, size_t newlen
,
995 ctl_table
*table
, void **context
)
1001 if (get_user(n
, name
))
1003 for ( ; table
->ctl_name
; table
++) {
1004 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
1007 if (ctl_perm(table
, 001))
1009 if (table
->strategy
) {
1010 error
= table
->strategy(
1013 newval
, newlen
, context
);
1019 table
= table
->child
;
1022 error
= do_sysctl_strategy(table
, name
, nlen
,
1024 newval
, newlen
, context
);
1031 /* Perform the actual read/write of a sysctl table entry. */
1032 int do_sysctl_strategy (ctl_table
*table
,
1033 int __user
*name
, int nlen
,
1034 void __user
*oldval
, size_t __user
*oldlenp
,
1035 void __user
*newval
, size_t newlen
, void **context
)
1044 if (ctl_perm(table
, op
))
1047 if (table
->strategy
) {
1048 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
1049 newval
, newlen
, context
);
1056 /* If there is no strategy routine, or if the strategy returns
1057 * zero, proceed with automatic r/w */
1058 if (table
->data
&& table
->maxlen
) {
1059 if (oldval
&& oldlenp
) {
1060 if (get_user(len
, oldlenp
))
1063 if (len
> table
->maxlen
)
1064 len
= table
->maxlen
;
1065 if(copy_to_user(oldval
, table
->data
, len
))
1067 if(put_user(len
, oldlenp
))
1071 if (newval
&& newlen
) {
1073 if (len
> table
->maxlen
)
1074 len
= table
->maxlen
;
1075 if(copy_from_user(table
->data
, newval
, len
))
1083 * register_sysctl_table - register a sysctl hierarchy
1084 * @table: the top-level table structure
1085 * @insert_at_head: whether the entry should be inserted in front or at the end
1087 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1088 * array. An entry with a ctl_name of 0 terminates the table.
1090 * The members of the &ctl_table structure are used as follows:
1092 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1093 * must be unique within that level of sysctl
1095 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1096 * enter a sysctl file
1098 * data - a pointer to data for use by proc_handler
1100 * maxlen - the maximum size in bytes of the data
1102 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1104 * child - a pointer to the child sysctl table if this entry is a directory, or
1107 * proc_handler - the text handler routine (described below)
1109 * strategy - the strategy routine (described below)
1111 * de - for internal use by the sysctl routines
1113 * extra1, extra2 - extra pointers usable by the proc handler routines
1115 * Leaf nodes in the sysctl tree will be represented by a single file
1116 * under /proc; non-leaf nodes will be represented by directories.
1118 * sysctl(2) can automatically manage read and write requests through
1119 * the sysctl table. The data and maxlen fields of the ctl_table
1120 * struct enable minimal validation of the values being written to be
1121 * performed, and the mode field allows minimal authentication.
1123 * More sophisticated management can be enabled by the provision of a
1124 * strategy routine with the table entry. This will be called before
1125 * any automatic read or write of the data is performed.
1127 * The strategy routine may return
1129 * < 0 - Error occurred (error is passed to user process)
1131 * 0 - OK - proceed with automatic read or write.
1133 * > 0 - OK - read or write has been done by the strategy routine, so
1134 * return immediately.
1136 * There must be a proc_handler routine for any terminal nodes
1137 * mirrored under /proc/sys (non-terminals are handled by a built-in
1138 * directory handler). Several default handlers are available to
1139 * cover common cases -
1141 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1142 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1143 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1145 * It is the handler's job to read the input buffer from user memory
1146 * and process it. The handler should return 0 on success.
1148 * This routine returns %NULL on a failure to register, and a pointer
1149 * to the table header on success.
1151 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1154 struct ctl_table_header
*tmp
;
1155 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1158 tmp
->ctl_table
= table
;
1159 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1161 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1163 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1164 #ifdef CONFIG_PROC_FS
1165 register_proc_table(table
, proc_sys_root
);
1171 * unregister_sysctl_table - unregister a sysctl table hierarchy
1172 * @header: the header returned from register_sysctl_table
1174 * Unregisters the sysctl table and all children. proc entries may not
1175 * actually be removed until they are no longer used by anyone.
1177 void unregister_sysctl_table(struct ctl_table_header
* header
)
1179 list_del(&header
->ctl_entry
);
1180 #ifdef CONFIG_PROC_FS
1181 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1190 #ifdef CONFIG_PROC_FS
1192 /* Scan the sysctl entries in table and add them all into /proc */
1193 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1195 struct proc_dir_entry
*de
;
1199 for (; table
->ctl_name
; table
++) {
1200 /* Can't do anything without a proc name. */
1201 if (!table
->procname
)
1203 /* Maybe we can't do anything with it... */
1204 if (!table
->proc_handler
&& !table
->child
) {
1205 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1210 len
= strlen(table
->procname
);
1214 if (table
->proc_handler
)
1218 for (de
= root
->subdir
; de
; de
= de
->next
) {
1219 if (proc_match(len
, table
->procname
, de
))
1222 /* If the subdir exists already, de is non-NULL */
1226 de
= create_proc_entry(table
->procname
, mode
, root
);
1229 de
->data
= (void *) table
;
1230 if (table
->proc_handler
)
1231 de
->proc_fops
= &proc_sys_file_operations
;
1234 if (de
->mode
& S_IFDIR
)
1235 register_proc_table(table
->child
, de
);
1240 * Unregister a /proc sysctl table and any subdirectories.
1242 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1244 struct proc_dir_entry
*de
;
1245 for (; table
->ctl_name
; table
++) {
1246 if (!(de
= table
->de
))
1248 if (de
->mode
& S_IFDIR
) {
1249 if (!table
->child
) {
1250 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1253 unregister_proc_table(table
->child
, de
);
1255 /* Don't unregister directories which still have entries.. */
1260 /* Don't unregister proc entries that are still being used.. */
1261 if (atomic_read(&de
->count
))
1265 remove_proc_entry(table
->procname
, root
);
1269 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1270 size_t count
, loff_t
*ppos
)
1273 struct proc_dir_entry
*de
;
1274 struct ctl_table
*table
;
1278 de
= PDE(file
->f_dentry
->d_inode
);
1279 if (!de
|| !de
->data
)
1281 table
= (struct ctl_table
*) de
->data
;
1282 if (!table
|| !table
->proc_handler
)
1284 op
= (write
? 002 : 004);
1285 if (ctl_perm(table
, op
))
1291 * FIXME: we need to pass on ppos to the handler.
1294 error
= (*table
->proc_handler
) (table
, write
, file
, buf
, &res
);
1300 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1302 if (file
->f_mode
& FMODE_WRITE
) {
1304 * sysctl entries that are not writable,
1305 * are _NOT_ writable, capabilities or not.
1307 if (!(inode
->i_mode
& S_IWUSR
))
1314 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1315 size_t count
, loff_t
*ppos
)
1317 return do_rw_proc(0, file
, buf
, count
, ppos
);
1320 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1321 size_t count
, loff_t
*ppos
)
1323 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1327 * proc_dostring - read a string sysctl
1328 * @table: the sysctl table
1329 * @write: %TRUE if this is a write to the sysctl file
1330 * @filp: the file structure
1331 * @buffer: the user buffer
1332 * @lenp: the size of the user buffer
1334 * Reads/writes a string from/to the user buffer. If the kernel
1335 * buffer provided is not large enough to hold the string, the
1336 * string is truncated. The copied string is %NULL-terminated.
1337 * If the string is being read by the user process, it is copied
1338 * and a newline '\n' is added. It is truncated if the buffer is
1341 * Returns 0 on success.
1343 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1344 void __user
*buffer
, size_t *lenp
)
1350 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1351 (filp
->f_pos
&& !write
)) {
1359 while (len
< *lenp
) {
1360 if (get_user(c
, p
++))
1362 if (c
== 0 || c
== '\n')
1366 if (len
>= table
->maxlen
)
1367 len
= table
->maxlen
-1;
1368 if(copy_from_user(table
->data
, buffer
, len
))
1370 ((char *) table
->data
)[len
] = 0;
1371 filp
->f_pos
+= *lenp
;
1373 len
= strlen(table
->data
);
1374 if (len
> table
->maxlen
)
1375 len
= table
->maxlen
;
1379 if(copy_to_user(buffer
, table
->data
, len
))
1382 if(put_user('\n', ((char __user
*) buffer
) + len
))
1393 * Special case of dostring for the UTS structure. This has locks
1394 * to observe. Should this be in kernel/sys.c ????
1397 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1398 void __user
*buffer
, size_t *lenp
)
1403 down_read(&uts_sem
);
1404 r
=proc_dostring(table
,0,filp
,buffer
,lenp
);
1407 down_write(&uts_sem
);
1408 r
=proc_dostring(table
,1,filp
,buffer
,lenp
);
1414 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1416 int write
, void *data
)
1419 *valp
= *negp
? -*lvalp
: *lvalp
;
1424 *lvalp
= (unsigned long)-val
;
1427 *lvalp
= (unsigned long)val
;
1433 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1434 void __user
*buffer
, size_t *lenp
,
1435 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1436 int write
, void *data
),
1439 #define TMPBUFLEN 20
1440 int *i
, vleft
, first
=1, neg
, val
;
1444 char buf
[TMPBUFLEN
], *p
;
1445 char __user
*s
= buffer
;
1447 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1448 (filp
->f_pos
&& !write
)) {
1453 i
= (int *) table
->data
;
1454 vleft
= table
->maxlen
/ sizeof(*i
);
1458 conv
= do_proc_dointvec_conv
;
1460 for (; left
&& vleft
--; i
++, first
=0) {
1475 if (len
> sizeof(buf
) - 1)
1476 len
= sizeof(buf
) - 1;
1477 if (copy_from_user(buf
, s
, len
))
1481 if (*p
== '-' && left
> 1) {
1485 if (*p
< '0' || *p
> '9')
1488 lval
= simple_strtoul(p
, &p
, 0);
1491 if ((len
< left
) && *p
&& !isspace(*p
))
1498 if (conv(&neg
, &lval
, i
, 1, data
))
1505 if (conv(&neg
, &lval
, i
, 0, data
))
1508 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1512 if(copy_to_user(s
, buf
, len
))
1519 if (!write
&& !first
&& left
) {
1520 if(put_user('\n', s
))
1527 if (get_user(c
, s
++))
1537 filp
->f_pos
+= *lenp
;
1543 * proc_dointvec - read a vector of integers
1544 * @table: the sysctl table
1545 * @write: %TRUE if this is a write to the sysctl file
1546 * @filp: the file structure
1547 * @buffer: the user buffer
1548 * @lenp: the size of the user buffer
1550 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1551 * values from/to the user buffer, treated as an ASCII string.
1553 * Returns 0 on success.
1555 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1556 void __user
*buffer
, size_t *lenp
)
1558 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,
1568 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1570 int write
, void *data
)
1572 int op
= *(int *)data
;
1574 int val
= *negp
? -*lvalp
: *lvalp
;
1576 case OP_SET
: *valp
= val
; break;
1577 case OP_AND
: *valp
&= val
; break;
1578 case OP_OR
: *valp
|= val
; break;
1579 case OP_MAX
: if(*valp
< val
)
1582 case OP_MIN
: if(*valp
> val
)
1590 *lvalp
= (unsigned long)-val
;
1593 *lvalp
= (unsigned long)val
;
1600 * init may raise the set.
1603 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1604 void __user
*buffer
, size_t *lenp
)
1608 if (!capable(CAP_SYS_MODULE
)) {
1612 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1613 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,
1614 do_proc_dointvec_bset_conv
,&op
);
1617 struct do_proc_dointvec_minmax_conv_param
{
1622 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1624 int write
, void *data
)
1626 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1628 int val
= *negp
? -*lvalp
: *lvalp
;
1629 if ((param
->min
&& *param
->min
> val
) ||
1630 (param
->max
&& *param
->max
< val
))
1637 *lvalp
= (unsigned long)-val
;
1640 *lvalp
= (unsigned long)val
;
1647 * proc_dointvec_minmax - read a vector of integers with min/max values
1648 * @table: the sysctl table
1649 * @write: %TRUE if this is a write to the sysctl file
1650 * @filp: the file structure
1651 * @buffer: the user buffer
1652 * @lenp: the size of the user buffer
1654 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1655 * values from/to the user buffer, treated as an ASCII string.
1657 * This routine will ensure the values are within the range specified by
1658 * table->extra1 (min) and table->extra2 (max).
1660 * Returns 0 on success.
1662 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1663 void __user
*buffer
, size_t *lenp
)
1665 struct do_proc_dointvec_minmax_conv_param param
= {
1666 .min
= (int *) table
->extra1
,
1667 .max
= (int *) table
->extra2
,
1669 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
,
1670 do_proc_dointvec_minmax_conv
, ¶m
);
1673 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1675 void __user
*buffer
, size_t *lenp
,
1676 unsigned long convmul
,
1677 unsigned long convdiv
)
1679 #define TMPBUFLEN 20
1680 unsigned long *i
, *min
, *max
, val
;
1681 int vleft
, first
=1, neg
;
1683 char buf
[TMPBUFLEN
], *p
;
1684 char __user
*s
= buffer
;
1686 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1687 (filp
->f_pos
&& !write
)) {
1692 i
= (unsigned long *) table
->data
;
1693 min
= (unsigned long *) table
->extra1
;
1694 max
= (unsigned long *) table
->extra2
;
1695 vleft
= table
->maxlen
/ sizeof(unsigned long);
1698 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1713 if (len
> TMPBUFLEN
-1)
1715 if (copy_from_user(buf
, s
, len
))
1719 if (*p
== '-' && left
> 1) {
1723 if (*p
< '0' || *p
> '9')
1725 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1727 if ((len
< left
) && *p
&& !isspace(*p
))
1736 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1743 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1747 if(copy_to_user(s
, buf
, len
))
1754 if (!write
&& !first
&& left
) {
1755 if(put_user('\n', s
))
1762 if (get_user(c
, s
++))
1772 filp
->f_pos
+= *lenp
;
1778 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1779 * @table: the sysctl table
1780 * @write: %TRUE if this is a write to the sysctl file
1781 * @filp: the file structure
1782 * @buffer: the user buffer
1783 * @lenp: the size of the user buffer
1785 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1786 * values from/to the user buffer, treated as an ASCII string.
1788 * This routine will ensure the values are within the range specified by
1789 * table->extra1 (min) and table->extra2 (max).
1791 * Returns 0 on success.
1793 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1794 void __user
*buffer
, size_t *lenp
)
1796 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, 1l, 1l);
1800 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1801 * @table: the sysctl table
1802 * @write: %TRUE if this is a write to the sysctl file
1803 * @filp: the file structure
1804 * @buffer: the user buffer
1805 * @lenp: the size of the user buffer
1807 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1808 * values from/to the user buffer, treated as an ASCII string. The values
1809 * are treated as milliseconds, and converted to jiffies when they are stored.
1811 * This routine will ensure the values are within the range specified by
1812 * table->extra1 (min) and table->extra2 (max).
1814 * Returns 0 on success.
1816 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1818 void __user
*buffer
, size_t *lenp
)
1820 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1825 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
1827 int write
, void *data
)
1830 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
1836 lval
= (unsigned long)-val
;
1839 lval
= (unsigned long)val
;
1846 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
1848 int write
, void *data
)
1851 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1857 lval
= (unsigned long)-val
;
1860 lval
= (unsigned long)val
;
1862 *lvalp
= jiffies_to_clock_t(lval
);
1868 * proc_dointvec_jiffies - read a vector of integers as seconds
1869 * @table: the sysctl table
1870 * @write: %TRUE if this is a write to the sysctl file
1871 * @filp: the file structure
1872 * @buffer: the user buffer
1873 * @lenp: the size of the user buffer
1875 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1876 * values from/to the user buffer, treated as an ASCII string.
1877 * The values read are assumed to be in seconds, and are converted into
1880 * Returns 0 on success.
1882 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1883 void __user
*buffer
, size_t *lenp
)
1885 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,
1886 do_proc_dointvec_jiffies_conv
,NULL
);
1890 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1891 * @table: the sysctl table
1892 * @write: %TRUE if this is a write to the sysctl file
1893 * @filp: the file structure
1894 * @buffer: the user buffer
1895 * @lenp: the size of the user buffer
1897 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1898 * values from/to the user buffer, treated as an ASCII string.
1899 * The values read are assumed to be in 1/USER_HZ seconds, and
1900 * are converted into jiffies.
1902 * Returns 0 on success.
1904 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1905 void __user
*buffer
, size_t *lenp
)
1907 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,
1908 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
1911 #else /* CONFIG_PROC_FS */
1913 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1914 void __user
*buffer
, size_t *lenp
)
1919 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1920 void __user
*buffer
, size_t *lenp
)
1925 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1926 void __user
*buffer
, size_t *lenp
)
1931 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1932 void __user
*buffer
, size_t *lenp
)
1937 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1938 void __user
*buffer
, size_t *lenp
)
1943 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1944 void __user
*buffer
, size_t *lenp
)
1949 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1950 void __user
*buffer
, size_t *lenp
)
1955 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1956 void __user
*buffer
, size_t *lenp
)
1961 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1963 void __user
*buffer
, size_t *lenp
)
1969 #endif /* CONFIG_PROC_FS */
1973 * General sysctl support routines
1976 /* The generic string strategy routine: */
1977 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
1978 void __user
*oldval
, size_t __user
*oldlenp
,
1979 void __user
*newval
, size_t newlen
, void **context
)
1983 if (!table
->data
|| !table
->maxlen
)
1986 if (oldval
&& oldlenp
) {
1987 if (get_user(len
, oldlenp
))
1990 l
= strlen(table
->data
);
1991 if (len
> l
) len
= l
;
1992 if (len
>= table
->maxlen
)
1993 len
= table
->maxlen
;
1994 if(copy_to_user(oldval
, table
->data
, len
))
1996 if(put_user(0, ((char __user
*) oldval
) + len
))
1998 if(put_user(len
, oldlenp
))
2002 if (newval
&& newlen
) {
2004 if (len
> table
->maxlen
)
2005 len
= table
->maxlen
;
2006 if(copy_from_user(table
->data
, newval
, len
))
2008 if (len
== table
->maxlen
)
2010 ((char *) table
->data
)[len
] = 0;
2016 * This function makes sure that all of the integers in the vector
2017 * are between the minimum and maximum values given in the arrays
2018 * table->extra1 and table->extra2, respectively.
2020 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2021 void __user
*oldval
, size_t __user
*oldlenp
,
2022 void __user
*newval
, size_t newlen
, void **context
)
2025 if (newval
&& newlen
) {
2026 int __user
*vec
= (int __user
*) newval
;
2027 int *min
= (int *) table
->extra1
;
2028 int *max
= (int *) table
->extra2
;
2032 if (newlen
% sizeof(int) != 0)
2035 if (!table
->extra1
&& !table
->extra2
)
2038 if (newlen
> table
->maxlen
)
2039 newlen
= table
->maxlen
;
2040 length
= newlen
/ sizeof(int);
2042 for (i
= 0; i
< length
; i
++) {
2044 if (get_user(value
, vec
+ i
))
2046 if (min
&& value
< min
[i
])
2048 if (max
&& value
> max
[i
])
2055 /* Strategy function to convert jiffies to seconds */
2056 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2057 void __user
*oldval
, size_t __user
*oldlenp
,
2058 void __user
*newval
, size_t newlen
, void **context
)
2063 if (get_user(olen
, oldlenp
))
2065 if (olen
!=sizeof(int))
2068 if (put_user(*(int *)(table
->data
)/HZ
, (int __user
*)oldval
) ||
2069 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2072 if (newval
&& newlen
) {
2074 if (newlen
!= sizeof(int))
2076 if (get_user(new, (int __user
*)newval
))
2078 *(int *)(table
->data
) = new*HZ
;
2084 #else /* CONFIG_SYSCTL */
2087 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2092 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2093 void __user
*oldval
, size_t __user
*oldlenp
,
2094 void __user
*newval
, size_t newlen
, void **context
)
2099 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2100 void __user
*oldval
, size_t __user
*oldlenp
,
2101 void __user
*newval
, size_t newlen
, void **context
)
2106 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2107 void __user
*oldval
, size_t __user
*oldlenp
,
2108 void __user
*newval
, size_t newlen
, void **context
)
2113 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2114 void __user
*buffer
, size_t *lenp
)
2119 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2120 void __user
*buffer
, size_t *lenp
)
2125 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2126 void __user
*buffer
, size_t *lenp
)
2131 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2132 void __user
*buffer
, size_t *lenp
)
2137 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2138 void __user
*buffer
, size_t *lenp
)
2143 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2144 void __user
*buffer
, size_t *lenp
)
2149 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2150 void __user
*buffer
, size_t *lenp
)
2155 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2157 void __user
*buffer
, size_t *lenp
)
2162 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2168 void unregister_sysctl_table(struct ctl_table_header
* table
)
2172 #endif /* CONFIG_SYSCTL */
2175 * No sense putting this after each symbol definition, twice,
2176 * exception granted :-)
2178 EXPORT_SYMBOL(proc_dointvec
);
2179 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2180 EXPORT_SYMBOL(proc_dointvec_minmax
);
2181 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2182 EXPORT_SYMBOL(proc_dostring
);
2183 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2184 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2185 EXPORT_SYMBOL(register_sysctl_table
);
2186 EXPORT_SYMBOL(sysctl_intvec
);
2187 EXPORT_SYMBOL(sysctl_jiffies
);
2188 EXPORT_SYMBOL(sysctl_string
);
2189 EXPORT_SYMBOL(unregister_sysctl_table
);