2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/config.h>
22 #include <linux/module.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/sysrq.h>
35 #include <linux/highuid.h>
36 #include <linux/writeback.h>
37 #include <linux/hugetlb.h>
38 #include <linux/security.h>
39 #include <linux/initrd.h>
40 #include <linux/times.h>
41 #include <linux/limits.h>
42 #include <linux/dcache.h>
43 #include <linux/syscalls.h>
45 #include <asm/uaccess.h>
46 #include <asm/processor.h>
48 #ifdef CONFIG_ROOT_NFS
49 #include <linux/nfs_fs.h>
52 #if defined(CONFIG_SYSCTL)
54 /* External variables not in a header file. */
56 extern int sysctl_overcommit_memory;
57 extern int sysctl_overcommit_ratio;
58 extern int max_threads;
59 extern int sysrq_enabled;
60 extern int core_uses_pid;
61 extern char core_pattern[];
64 extern int min_free_kbytes;
65 extern int printk_ratelimit_jiffies;
66 extern int printk_ratelimit_burst;
67 extern int pid_max_min, pid_max_max;
69 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
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 int randomize_va_space = 1;
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 = HOTPLUG_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(CONFIG_X86)
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,
627 #if defined(CONFIG_X86)
629 .ctl_name = KERN_BOOTLOADER_TYPE,
630 .procname = "bootloader_type",
631 .data = &bootloader_type,
632 .maxlen = sizeof (int),
634 .proc_handler = &proc_dointvec,
638 .ctl_name = KERN_RANDOMIZE,
639 .procname = "randomize_va_space",
640 .data = &randomize_va_space,
641 .maxlen = sizeof(int),
643 .proc_handler = &proc_dointvec,
649 /* Constants for minimum and maximum testing in vm_table.
650 We use these as one-element integer vectors. */
652 static int one_hundred = 100;
655 static ctl_table vm_table[] = {
657 .ctl_name = VM_OVERCOMMIT_MEMORY,
658 .procname = "overcommit_memory",
659 .data = &sysctl_overcommit_memory,
660 .maxlen = sizeof(sysctl_overcommit_memory),
662 .proc_handler = &proc_dointvec,
665 .ctl_name = VM_OVERCOMMIT_RATIO,
666 .procname = "overcommit_ratio",
667 .data = &sysctl_overcommit_ratio,
668 .maxlen = sizeof(sysctl_overcommit_ratio),
670 .proc_handler = &proc_dointvec,
673 .ctl_name = VM_PAGE_CLUSTER,
674 .procname = "page-cluster",
675 .data = &page_cluster,
676 .maxlen = sizeof(int),
678 .proc_handler = &proc_dointvec,
681 .ctl_name = VM_DIRTY_BACKGROUND,
682 .procname = "dirty_background_ratio",
683 .data = &dirty_background_ratio,
684 .maxlen = sizeof(dirty_background_ratio),
686 .proc_handler = &proc_dointvec_minmax,
687 .strategy = &sysctl_intvec,
689 .extra2 = &one_hundred,
692 .ctl_name = VM_DIRTY_RATIO,
693 .procname = "dirty_ratio",
694 .data = &vm_dirty_ratio,
695 .maxlen = sizeof(vm_dirty_ratio),
697 .proc_handler = &proc_dointvec_minmax,
698 .strategy = &sysctl_intvec,
700 .extra2 = &one_hundred,
703 .ctl_name = VM_DIRTY_WB_CS,
704 .procname = "dirty_writeback_centisecs",
705 .data = &dirty_writeback_centisecs,
706 .maxlen = sizeof(dirty_writeback_centisecs),
708 .proc_handler = &dirty_writeback_centisecs_handler,
711 .ctl_name = VM_DIRTY_EXPIRE_CS,
712 .procname = "dirty_expire_centisecs",
713 .data = &dirty_expire_centisecs,
714 .maxlen = sizeof(dirty_expire_centisecs),
716 .proc_handler = &proc_dointvec,
719 .ctl_name = VM_NR_PDFLUSH_THREADS,
720 .procname = "nr_pdflush_threads",
721 .data = &nr_pdflush_threads,
722 .maxlen = sizeof nr_pdflush_threads,
723 .mode = 0444 /* read-only*/,
724 .proc_handler = &proc_dointvec,
727 .ctl_name = VM_SWAPPINESS,
728 .procname = "swappiness",
729 .data = &vm_swappiness,
730 .maxlen = sizeof(vm_swappiness),
732 .proc_handler = &proc_dointvec_minmax,
733 .strategy = &sysctl_intvec,
735 .extra2 = &one_hundred,
737 #ifdef CONFIG_HUGETLB_PAGE
739 .ctl_name = VM_HUGETLB_PAGES,
740 .procname = "nr_hugepages",
741 .data = &max_huge_pages,
742 .maxlen = sizeof(unsigned long),
744 .proc_handler = &hugetlb_sysctl_handler,
745 .extra1 = (void *)&hugetlb_zero,
746 .extra2 = (void *)&hugetlb_infinity,
749 .ctl_name = VM_HUGETLB_GROUP,
750 .procname = "hugetlb_shm_group",
751 .data = &sysctl_hugetlb_shm_group,
752 .maxlen = sizeof(gid_t),
754 .proc_handler = &proc_dointvec,
758 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
759 .procname = "lowmem_reserve_ratio",
760 .data = &sysctl_lowmem_reserve_ratio,
761 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
763 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
764 .strategy = &sysctl_intvec,
767 .ctl_name = VM_MIN_FREE_KBYTES,
768 .procname = "min_free_kbytes",
769 .data = &min_free_kbytes,
770 .maxlen = sizeof(min_free_kbytes),
772 .proc_handler = &min_free_kbytes_sysctl_handler,
773 .strategy = &sysctl_intvec,
778 .ctl_name = VM_MAX_MAP_COUNT,
779 .procname = "max_map_count",
780 .data = &sysctl_max_map_count,
781 .maxlen = sizeof(sysctl_max_map_count),
783 .proc_handler = &proc_dointvec
787 .ctl_name = VM_LAPTOP_MODE,
788 .procname = "laptop_mode",
789 .data = &laptop_mode,
790 .maxlen = sizeof(laptop_mode),
792 .proc_handler = &proc_dointvec,
793 .strategy = &sysctl_intvec,
797 .ctl_name = VM_BLOCK_DUMP,
798 .procname = "block_dump",
800 .maxlen = sizeof(block_dump),
802 .proc_handler = &proc_dointvec,
803 .strategy = &sysctl_intvec,
807 .ctl_name = VM_VFS_CACHE_PRESSURE,
808 .procname = "vfs_cache_pressure",
809 .data = &sysctl_vfs_cache_pressure,
810 .maxlen = sizeof(sysctl_vfs_cache_pressure),
812 .proc_handler = &proc_dointvec,
813 .strategy = &sysctl_intvec,
816 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
818 .ctl_name = VM_LEGACY_VA_LAYOUT,
819 .procname = "legacy_va_layout",
820 .data = &sysctl_legacy_va_layout,
821 .maxlen = sizeof(sysctl_legacy_va_layout),
823 .proc_handler = &proc_dointvec,
824 .strategy = &sysctl_intvec,
830 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
831 .procname = "swap_token_timeout",
832 .data = &swap_token_default_timeout,
833 .maxlen = sizeof(swap_token_default_timeout),
835 .proc_handler = &proc_dointvec_jiffies,
836 .strategy = &sysctl_jiffies,
842 static ctl_table proc_table[] = {
846 static ctl_table fs_table[] = {
848 .ctl_name = FS_NRINODE,
849 .procname = "inode-nr",
850 .data = &inodes_stat,
851 .maxlen = 2*sizeof(int),
853 .proc_handler = &proc_dointvec,
856 .ctl_name = FS_STATINODE,
857 .procname = "inode-state",
858 .data = &inodes_stat,
859 .maxlen = 7*sizeof(int),
861 .proc_handler = &proc_dointvec,
864 .ctl_name = FS_NRFILE,
865 .procname = "file-nr",
867 .maxlen = 3*sizeof(int),
869 .proc_handler = &proc_dointvec,
872 .ctl_name = FS_MAXFILE,
873 .procname = "file-max",
874 .data = &files_stat.max_files,
875 .maxlen = sizeof(int),
877 .proc_handler = &proc_dointvec,
880 .ctl_name = FS_DENTRY,
881 .procname = "dentry-state",
882 .data = &dentry_stat,
883 .maxlen = 6*sizeof(int),
885 .proc_handler = &proc_dointvec,
888 .ctl_name = FS_OVERFLOWUID,
889 .procname = "overflowuid",
890 .data = &fs_overflowuid,
891 .maxlen = sizeof(int),
893 .proc_handler = &proc_dointvec_minmax,
894 .strategy = &sysctl_intvec,
895 .extra1 = &minolduid,
896 .extra2 = &maxolduid,
899 .ctl_name = FS_OVERFLOWGID,
900 .procname = "overflowgid",
901 .data = &fs_overflowgid,
902 .maxlen = sizeof(int),
904 .proc_handler = &proc_dointvec_minmax,
905 .strategy = &sysctl_intvec,
906 .extra1 = &minolduid,
907 .extra2 = &maxolduid,
910 .ctl_name = FS_LEASES,
911 .procname = "leases-enable",
912 .data = &leases_enable,
913 .maxlen = sizeof(int),
915 .proc_handler = &proc_dointvec,
917 #ifdef CONFIG_DNOTIFY
919 .ctl_name = FS_DIR_NOTIFY,
920 .procname = "dir-notify-enable",
921 .data = &dir_notify_enable,
922 .maxlen = sizeof(int),
924 .proc_handler = &proc_dointvec,
929 .ctl_name = FS_LEASE_TIME,
930 .procname = "lease-break-time",
931 .data = &lease_break_time,
932 .maxlen = sizeof(int),
934 .proc_handler = &proc_dointvec,
937 .ctl_name = FS_AIO_NR,
938 .procname = "aio-nr",
940 .maxlen = sizeof(aio_nr),
942 .proc_handler = &proc_dointvec,
945 .ctl_name = FS_AIO_MAX_NR,
946 .procname = "aio-max-nr",
948 .maxlen = sizeof(aio_max_nr),
950 .proc_handler = &proc_dointvec,
956 static ctl_table debug_table[] = {
960 static ctl_table dev_table[] = {
964 extern void init_irq_proc (void);
966 void __init sysctl_init(void)
968 #ifdef CONFIG_PROC_FS
969 register_proc_table(root_table, proc_sys_root);
974 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
975 void __user *newval, size_t newlen)
977 struct list_head *tmp;
979 if (nlen <= 0 || nlen >= CTL_MAXNAME)
983 if (!oldlenp || get_user(old_len, oldlenp))
986 tmp = &root_table_header.ctl_entry;
988 struct ctl_table_header *head =
989 list_entry(tmp, struct ctl_table_header, ctl_entry);
990 void *context = NULL;
991 int error = parse_table(name, nlen, oldval, oldlenp,
992 newval, newlen, head->ctl_table,
996 if (error != -ENOTDIR)
999 } while (tmp != &root_table_header.ctl_entry);
1003 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1005 struct __sysctl_args tmp;
1008 if (copy_from_user(&tmp, args, sizeof(tmp)))
1012 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1013 tmp.newval, tmp.newlen);
1019 * ctl_perm does NOT grant the superuser all rights automatically, because
1020 * some sysctl variables are readonly even to root.
1023 static int test_perm(int mode, int op)
1027 else if (in_egroup_p(0))
1029 if ((mode & op & 0007) == op)
1034 static inline int ctl_perm(ctl_table *table, int op)
1037 error = security_sysctl(table, op);
1040 return test_perm(table->mode, op);
1043 static int parse_table(int __user *name, int nlen,
1044 void __user *oldval, size_t __user *oldlenp,
1045 void __user *newval, size_t newlen,
1046 ctl_table *table, void **context)
1052 if (get_user(n, name))
1054 for ( ; table->ctl_name; table++) {
1055 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1058 if (ctl_perm(table, 001))
1060 if (table->strategy) {
1061 error = table->strategy(
1064 newval, newlen, context);
1070 table = table->child;
1073 error = do_sysctl_strategy(table, name, nlen,
1075 newval, newlen, context);
1082 /* Perform the actual read/write of a sysctl table entry. */
1083 int do_sysctl_strategy (ctl_table *table,
1084 int __user *name, int nlen,
1085 void __user *oldval, size_t __user *oldlenp,
1086 void __user *newval, size_t newlen, void **context)
1095 if (ctl_perm(table, op))
1098 if (table->strategy) {
1099 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1100 newval, newlen, context);
1107 /* If there is no strategy routine, or if the strategy returns
1108 * zero, proceed with automatic r/w */
1109 if (table->data && table->maxlen) {
1110 if (oldval && oldlenp) {
1111 if (get_user(len, oldlenp))
1114 if (len > table->maxlen)
1115 len = table->maxlen;
1116 if(copy_to_user(oldval, table->data, len))
1118 if(put_user(len, oldlenp))
1122 if (newval && newlen) {
1124 if (len > table->maxlen)
1125 len = table->maxlen;
1126 if(copy_from_user(table->data, newval, len))
1134 * register_sysctl_table - register a sysctl hierarchy
1135 * @table: the top-level table structure
1136 * @insert_at_head: whether the entry should be inserted in front or at the end
1138 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1139 * array. An entry with a ctl_name of 0 terminates the table.
1141 * The members of the &ctl_table structure are used as follows:
1143 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1144 * must be unique within that level of sysctl
1146 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1147 * enter a sysctl file
1149 * data - a pointer to data for use by proc_handler
1151 * maxlen - the maximum size in bytes of the data
1153 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1155 * child - a pointer to the child sysctl table if this entry is a directory, or
1158 * proc_handler - the text handler routine (described below)
1160 * strategy - the strategy routine (described below)
1162 * de - for internal use by the sysctl routines
1164 * extra1, extra2 - extra pointers usable by the proc handler routines
1166 * Leaf nodes in the sysctl tree will be represented by a single file
1167 * under /proc; non-leaf nodes will be represented by directories.
1169 * sysctl(2) can automatically manage read and write requests through
1170 * the sysctl table. The data and maxlen fields of the ctl_table
1171 * struct enable minimal validation of the values being written to be
1172 * performed, and the mode field allows minimal authentication.
1174 * More sophisticated management can be enabled by the provision of a
1175 * strategy routine with the table entry. This will be called before
1176 * any automatic read or write of the data is performed.
1178 * The strategy routine may return
1180 * < 0 - Error occurred (error is passed to user process)
1182 * 0 - OK - proceed with automatic read or write.
1184 * > 0 - OK - read or write has been done by the strategy routine, so
1185 * return immediately.
1187 * There must be a proc_handler routine for any terminal nodes
1188 * mirrored under /proc/sys (non-terminals are handled by a built-in
1189 * directory handler). Several default handlers are available to
1190 * cover common cases -
1192 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1193 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1194 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1196 * It is the handler's job to read the input buffer from user memory
1197 * and process it. The handler should return 0 on success.
1199 * This routine returns %NULL on a failure to register, and a pointer
1200 * to the table header on success.
1202 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1205 struct ctl_table_header *tmp;
1206 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1209 tmp->ctl_table = table;
1210 INIT_LIST_HEAD(&tmp->ctl_entry);
1212 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1214 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1215 #ifdef CONFIG_PROC_FS
1216 register_proc_table(table, proc_sys_root);
1222 * unregister_sysctl_table - unregister a sysctl table hierarchy
1223 * @header: the header returned from register_sysctl_table
1225 * Unregisters the sysctl table and all children. proc entries may not
1226 * actually be removed until they are no longer used by anyone.
1228 void unregister_sysctl_table(struct ctl_table_header * header)
1230 list_del(&header->ctl_entry);
1231 #ifdef CONFIG_PROC_FS
1232 unregister_proc_table(header->ctl_table, proc_sys_root);
1241 #ifdef CONFIG_PROC_FS
1243 /* Scan the sysctl entries in table and add them all into /proc */
1244 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1246 struct proc_dir_entry *de;
1250 for (; table->ctl_name; table++) {
1251 /* Can't do anything without a proc name. */
1252 if (!table->procname)
1254 /* Maybe we can't do anything with it... */
1255 if (!table->proc_handler && !table->child) {
1256 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1261 len = strlen(table->procname);
1265 if (table->proc_handler)
1269 for (de = root->subdir; de; de = de->next) {
1270 if (proc_match(len, table->procname, de))
1273 /* If the subdir exists already, de is non-NULL */
1277 de = create_proc_entry(table->procname, mode, root);
1280 de->data = (void *) table;
1281 if (table->proc_handler)
1282 de->proc_fops = &proc_sys_file_operations;
1285 if (de->mode & S_IFDIR)
1286 register_proc_table(table->child, de);
1291 * Unregister a /proc sysctl table and any subdirectories.
1293 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1295 struct proc_dir_entry *de;
1296 for (; table->ctl_name; table++) {
1297 if (!(de = table->de))
1299 if (de->mode & S_IFDIR) {
1300 if (!table->child) {
1301 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1304 unregister_proc_table(table->child, de);
1306 /* Don't unregister directories which still have entries.. */
1311 /* Don't unregister proc entries that are still being used.. */
1312 if (atomic_read(&de->count))
1316 remove_proc_entry(table->procname, root);
1320 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1321 size_t count, loff_t *ppos)
1324 struct proc_dir_entry *de;
1325 struct ctl_table *table;
1329 de = PDE(file->f_dentry->d_inode);
1330 if (!de || !de->data)
1332 table = (struct ctl_table *) de->data;
1333 if (!table || !table->proc_handler)
1335 op = (write ? 002 : 004);
1336 if (ctl_perm(table, op))
1341 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1347 static int proc_opensys(struct inode *inode, struct file *file)
1349 if (file->f_mode & FMODE_WRITE) {
1351 * sysctl entries that are not writable,
1352 * are _NOT_ writable, capabilities or not.
1354 if (!(inode->i_mode & S_IWUSR))
1361 static ssize_t proc_readsys(struct file * file, char __user * buf,
1362 size_t count, loff_t *ppos)
1364 return do_rw_proc(0, file, buf, count, ppos);
1367 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1368 size_t count, loff_t *ppos)
1370 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1374 * proc_dostring - read a string sysctl
1375 * @table: the sysctl table
1376 * @write: %TRUE if this is a write to the sysctl file
1377 * @filp: the file structure
1378 * @buffer: the user buffer
1379 * @lenp: the size of the user buffer
1380 * @ppos: file position
1382 * Reads/writes a string from/to the user buffer. If the kernel
1383 * buffer provided is not large enough to hold the string, the
1384 * string is truncated. The copied string is %NULL-terminated.
1385 * If the string is being read by the user process, it is copied
1386 * and a newline '\n' is added. It is truncated if the buffer is
1389 * Returns 0 on success.
1391 int proc_dostring(ctl_table *table, int write, struct file *filp,
1392 void __user *buffer, size_t *lenp, loff_t *ppos)
1398 if (!table->data || !table->maxlen || !*lenp ||
1399 (*ppos && !write)) {
1407 while (len < *lenp) {
1408 if (get_user(c, p++))
1410 if (c == 0 || c == '\n')
1414 if (len >= table->maxlen)
1415 len = table->maxlen-1;
1416 if(copy_from_user(table->data, buffer, len))
1418 ((char *) table->data)[len] = 0;
1421 len = strlen(table->data);
1422 if (len > table->maxlen)
1423 len = table->maxlen;
1427 if(copy_to_user(buffer, table->data, len))
1430 if(put_user('\n', ((char __user *) buffer) + len))
1441 * Special case of dostring for the UTS structure. This has locks
1442 * to observe. Should this be in kernel/sys.c ????
1445 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1446 void __user *buffer, size_t *lenp, loff_t *ppos)
1451 down_read(&uts_sem);
1452 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1455 down_write(&uts_sem);
1456 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1462 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1464 int write, void *data)
1467 *valp = *negp ? -*lvalp : *lvalp;
1472 *lvalp = (unsigned long)-val;
1475 *lvalp = (unsigned long)val;
1481 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1482 void __user *buffer, size_t *lenp, loff_t *ppos,
1483 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1484 int write, void *data),
1487 #define TMPBUFLEN 21
1488 int *i, vleft, first=1, neg, val;
1492 char buf[TMPBUFLEN], *p;
1493 char __user *s = buffer;
1495 if (!table->data || !table->maxlen || !*lenp ||
1496 (*ppos && !write)) {
1501 i = (int *) table->data;
1502 vleft = table->maxlen / sizeof(*i);
1506 conv = do_proc_dointvec_conv;
1508 for (; left && vleft--; i++, first=0) {
1523 if (len > sizeof(buf) - 1)
1524 len = sizeof(buf) - 1;
1525 if (copy_from_user(buf, s, len))
1529 if (*p == '-' && left > 1) {
1533 if (*p < '0' || *p > '9')
1536 lval = simple_strtoul(p, &p, 0);
1539 if ((len < left) && *p && !isspace(*p))
1546 if (conv(&neg, &lval, i, 1, data))
1553 if (conv(&neg, &lval, i, 0, data))
1556 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1560 if(copy_to_user(s, buf, len))
1567 if (!write && !first && left) {
1568 if(put_user('\n', s))
1575 if (get_user(c, s++))
1591 * proc_dointvec - read a vector of integers
1592 * @table: the sysctl table
1593 * @write: %TRUE if this is a write to the sysctl file
1594 * @filp: the file structure
1595 * @buffer: the user buffer
1596 * @lenp: the size of the user buffer
1597 * @ppos: file position
1599 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1600 * values from/to the user buffer, treated as an ASCII string.
1602 * Returns 0 on success.
1604 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1605 void __user *buffer, size_t *lenp, loff_t *ppos)
1607 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1617 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1619 int write, void *data)
1621 int op = *(int *)data;
1623 int val = *negp ? -*lvalp : *lvalp;
1625 case OP_SET: *valp = val; break;
1626 case OP_AND: *valp &= val; break;
1627 case OP_OR: *valp |= val; break;
1628 case OP_MAX: if(*valp < val)
1631 case OP_MIN: if(*valp > val)
1639 *lvalp = (unsigned long)-val;
1642 *lvalp = (unsigned long)val;
1649 * init may raise the set.
1652 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1653 void __user *buffer, size_t *lenp, loff_t *ppos)
1657 if (!capable(CAP_SYS_MODULE)) {
1661 op = (current->pid == 1) ? OP_SET : OP_AND;
1662 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1663 do_proc_dointvec_bset_conv,&op);
1666 struct do_proc_dointvec_minmax_conv_param {
1671 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1673 int write, void *data)
1675 struct do_proc_dointvec_minmax_conv_param *param = data;
1677 int val = *negp ? -*lvalp : *lvalp;
1678 if ((param->min && *param->min > val) ||
1679 (param->max && *param->max < val))
1686 *lvalp = (unsigned long)-val;
1689 *lvalp = (unsigned long)val;
1696 * proc_dointvec_minmax - read a vector of integers with min/max values
1697 * @table: the sysctl table
1698 * @write: %TRUE if this is a write to the sysctl file
1699 * @filp: the file structure
1700 * @buffer: the user buffer
1701 * @lenp: the size of the user buffer
1702 * @ppos: file position
1704 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1705 * values from/to the user buffer, treated as an ASCII string.
1707 * This routine will ensure the values are within the range specified by
1708 * table->extra1 (min) and table->extra2 (max).
1710 * Returns 0 on success.
1712 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1713 void __user *buffer, size_t *lenp, loff_t *ppos)
1715 struct do_proc_dointvec_minmax_conv_param param = {
1716 .min = (int *) table->extra1,
1717 .max = (int *) table->extra2,
1719 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1720 do_proc_dointvec_minmax_conv, ¶m);
1723 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1725 void __user *buffer,
1726 size_t *lenp, loff_t *ppos,
1727 unsigned long convmul,
1728 unsigned long convdiv)
1730 #define TMPBUFLEN 21
1731 unsigned long *i, *min, *max, val;
1732 int vleft, first=1, neg;
1734 char buf[TMPBUFLEN], *p;
1735 char __user *s = buffer;
1737 if (!table->data || !table->maxlen || !*lenp ||
1738 (*ppos && !write)) {
1743 i = (unsigned long *) table->data;
1744 min = (unsigned long *) table->extra1;
1745 max = (unsigned long *) table->extra2;
1746 vleft = table->maxlen / sizeof(unsigned long);
1749 for (; left && vleft--; i++, min++, max++, first=0) {
1764 if (len > TMPBUFLEN-1)
1766 if (copy_from_user(buf, s, len))
1770 if (*p == '-' && left > 1) {
1774 if (*p < '0' || *p > '9')
1776 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1778 if ((len < left) && *p && !isspace(*p))
1787 if ((min && val < *min) || (max && val > *max))
1794 sprintf(p, "%lu", convdiv * (*i) / convmul);
1798 if(copy_to_user(s, buf, len))
1805 if (!write && !first && left) {
1806 if(put_user('\n', s))
1813 if (get_user(c, s++))
1829 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1830 * @table: the sysctl table
1831 * @write: %TRUE if this is a write to the sysctl file
1832 * @filp: the file structure
1833 * @buffer: the user buffer
1834 * @lenp: the size of the user buffer
1835 * @ppos: file position
1837 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1838 * values from/to the user buffer, treated as an ASCII string.
1840 * This routine will ensure the values are within the range specified by
1841 * table->extra1 (min) and table->extra2 (max).
1843 * Returns 0 on success.
1845 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1846 void __user *buffer, size_t *lenp, loff_t *ppos)
1848 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1852 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1853 * @table: the sysctl table
1854 * @write: %TRUE if this is a write to the sysctl file
1855 * @filp: the file structure
1856 * @buffer: the user buffer
1857 * @lenp: the size of the user buffer
1858 * @ppos: file position
1860 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1861 * values from/to the user buffer, treated as an ASCII string. The values
1862 * are treated as milliseconds, and converted to jiffies when they are stored.
1864 * This routine will ensure the values are within the range specified by
1865 * table->extra1 (min) and table->extra2 (max).
1867 * Returns 0 on success.
1869 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1871 void __user *buffer,
1872 size_t *lenp, loff_t *ppos)
1874 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1875 lenp, ppos, HZ, 1000l);
1879 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1881 int write, void *data)
1884 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1890 lval = (unsigned long)-val;
1893 lval = (unsigned long)val;
1900 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1902 int write, void *data)
1905 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1911 lval = (unsigned long)-val;
1914 lval = (unsigned long)val;
1916 *lvalp = jiffies_to_clock_t(lval);
1921 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1923 int write, void *data)
1926 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1932 lval = (unsigned long)-val;
1935 lval = (unsigned long)val;
1937 *lvalp = jiffies_to_msecs(lval);
1943 * proc_dointvec_jiffies - read a vector of integers as seconds
1944 * @table: the sysctl table
1945 * @write: %TRUE if this is a write to the sysctl file
1946 * @filp: the file structure
1947 * @buffer: the user buffer
1948 * @lenp: the size of the user buffer
1949 * @ppos: file position
1951 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1952 * values from/to the user buffer, treated as an ASCII string.
1953 * The values read are assumed to be in seconds, and are converted into
1956 * Returns 0 on success.
1958 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1959 void __user *buffer, size_t *lenp, loff_t *ppos)
1961 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1962 do_proc_dointvec_jiffies_conv,NULL);
1966 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1967 * @table: the sysctl table
1968 * @write: %TRUE if this is a write to the sysctl file
1969 * @filp: the file structure
1970 * @buffer: the user buffer
1971 * @lenp: the size of the user buffer
1973 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1974 * values from/to the user buffer, treated as an ASCII string.
1975 * The values read are assumed to be in 1/USER_HZ seconds, and
1976 * are converted into jiffies.
1978 * Returns 0 on success.
1980 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1981 void __user *buffer, size_t *lenp, loff_t *ppos)
1983 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1984 do_proc_dointvec_userhz_jiffies_conv,NULL);
1988 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1989 * @table: the sysctl table
1990 * @write: %TRUE if this is a write to the sysctl file
1991 * @filp: the file structure
1992 * @buffer: the user buffer
1993 * @lenp: the size of the user buffer
1994 * @ppos: file position
1995 * @ppos: the current position in the file
1997 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1998 * values from/to the user buffer, treated as an ASCII string.
1999 * The values read are assumed to be in 1/1000 seconds, and
2000 * are converted into jiffies.
2002 * Returns 0 on success.
2004 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2005 void __user *buffer, size_t *lenp, loff_t *ppos)
2007 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2008 do_proc_dointvec_ms_jiffies_conv, NULL);
2011 #else /* CONFIG_PROC_FS */
2013 int proc_dostring(ctl_table *table, int write, struct file *filp,
2014 void __user *buffer, size_t *lenp, loff_t *ppos)
2019 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2020 void __user *buffer, size_t *lenp, loff_t *ppos)
2025 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2026 void __user *buffer, size_t *lenp, loff_t *ppos)
2031 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2032 void __user *buffer, size_t *lenp, loff_t *ppos)
2037 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2038 void __user *buffer, size_t *lenp, loff_t *ppos)
2043 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2044 void __user *buffer, size_t *lenp, loff_t *ppos)
2049 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2050 void __user *buffer, size_t *lenp, loff_t *ppos)
2055 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2056 void __user *buffer, size_t *lenp, loff_t *ppos)
2061 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2062 void __user *buffer, size_t *lenp, loff_t *ppos)
2067 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2069 void __user *buffer,
2070 size_t *lenp, loff_t *ppos)
2076 #endif /* CONFIG_PROC_FS */
2080 * General sysctl support routines
2083 /* The generic string strategy routine: */
2084 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2085 void __user *oldval, size_t __user *oldlenp,
2086 void __user *newval, size_t newlen, void **context)
2090 if (!table->data || !table->maxlen)
2093 if (oldval && oldlenp) {
2094 if (get_user(len, oldlenp))
2097 l = strlen(table->data);
2098 if (len > l) len = l;
2099 if (len >= table->maxlen)
2100 len = table->maxlen;
2101 if(copy_to_user(oldval, table->data, len))
2103 if(put_user(0, ((char __user *) oldval) + len))
2105 if(put_user(len, oldlenp))
2109 if (newval && newlen) {
2111 if (len > table->maxlen)
2112 len = table->maxlen;
2113 if(copy_from_user(table->data, newval, len))
2115 if (len == table->maxlen)
2117 ((char *) table->data)[len] = 0;
2123 * This function makes sure that all of the integers in the vector
2124 * are between the minimum and maximum values given in the arrays
2125 * table->extra1 and table->extra2, respectively.
2127 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2128 void __user *oldval, size_t __user *oldlenp,
2129 void __user *newval, size_t newlen, void **context)
2132 if (newval && newlen) {
2133 int __user *vec = (int __user *) newval;
2134 int *min = (int *) table->extra1;
2135 int *max = (int *) table->extra2;
2139 if (newlen % sizeof(int) != 0)
2142 if (!table->extra1 && !table->extra2)
2145 if (newlen > table->maxlen)
2146 newlen = table->maxlen;
2147 length = newlen / sizeof(int);
2149 for (i = 0; i < length; i++) {
2151 if (get_user(value, vec + i))
2153 if (min && value < min[i])
2155 if (max && value > max[i])
2162 /* Strategy function to convert jiffies to seconds */
2163 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2164 void __user *oldval, size_t __user *oldlenp,
2165 void __user *newval, size_t newlen, void **context)
2170 if (get_user(olen, oldlenp))
2172 if (olen!=sizeof(int))
2175 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2176 (oldlenp && put_user(sizeof(int),oldlenp)))
2179 if (newval && newlen) {
2181 if (newlen != sizeof(int))
2183 if (get_user(new, (int __user *)newval))
2185 *(int *)(table->data) = new*HZ;
2190 /* Strategy function to convert jiffies to seconds */
2191 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2192 void __user *oldval, size_t __user *oldlenp,
2193 void __user *newval, size_t newlen, void **context)
2198 if (get_user(olen, oldlenp))
2200 if (olen!=sizeof(int))
2203 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2204 (oldlenp && put_user(sizeof(int),oldlenp)))
2207 if (newval && newlen) {
2209 if (newlen != sizeof(int))
2211 if (get_user(new, (int __user *)newval))
2213 *(int *)(table->data) = msecs_to_jiffies(new);
2218 #else /* CONFIG_SYSCTL */
2221 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2226 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2227 void __user *oldval, size_t __user *oldlenp,
2228 void __user *newval, size_t newlen, void **context)
2233 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2234 void __user *oldval, size_t __user *oldlenp,
2235 void __user *newval, size_t newlen, void **context)
2240 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2241 void __user *oldval, size_t __user *oldlenp,
2242 void __user *newval, size_t newlen, void **context)
2247 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2248 void __user *oldval, size_t __user *oldlenp,
2249 void __user *newval, size_t newlen, void **context)
2254 int proc_dostring(ctl_table *table, int write, struct file *filp,
2255 void __user *buffer, size_t *lenp, loff_t *ppos)
2260 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2261 void __user *buffer, size_t *lenp, loff_t *ppos)
2266 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2267 void __user *buffer, size_t *lenp, loff_t *ppos)
2272 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2273 void __user *buffer, size_t *lenp, loff_t *ppos)
2278 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2279 void __user *buffer, size_t *lenp, loff_t *ppos)
2284 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2285 void __user *buffer, size_t *lenp, loff_t *ppos)
2290 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2291 void __user *buffer, size_t *lenp, loff_t *ppos)
2296 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2297 void __user *buffer, size_t *lenp, loff_t *ppos)
2302 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2304 void __user *buffer,
2305 size_t *lenp, loff_t *ppos)
2310 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2316 void unregister_sysctl_table(struct ctl_table_header * table)
2320 #endif /* CONFIG_SYSCTL */
2323 * No sense putting this after each symbol definition, twice,
2324 * exception granted :-)
2326 EXPORT_SYMBOL(proc_dointvec);
2327 EXPORT_SYMBOL(proc_dointvec_jiffies);
2328 EXPORT_SYMBOL(proc_dointvec_minmax);
2329 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2330 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2331 EXPORT_SYMBOL(proc_dostring);
2332 EXPORT_SYMBOL(proc_doulongvec_minmax);
2333 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2334 EXPORT_SYMBOL(register_sysctl_table);
2335 EXPORT_SYMBOL(sysctl_intvec);
2336 EXPORT_SYMBOL(sysctl_jiffies);
2337 EXPORT_SYMBOL(sysctl_ms_jiffies);
2338 EXPORT_SYMBOL(sysctl_string);
2339 EXPORT_SYMBOL(unregister_sysctl_table);