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/net.h>
35 #include <linux/sysrq.h>
36 #include <linux/highuid.h>
37 #include <linux/writeback.h>
38 #include <linux/hugetlb.h>
39 #include <linux/security.h>
40 #include <linux/initrd.h>
41 #include <linux/times.h>
42 #include <linux/limits.h>
43 #include <linux/dcache.h>
44 #include <linux/syscalls.h>
46 #include <asm/uaccess.h>
47 #include <asm/processor.h>
49 #ifdef CONFIG_ROOT_NFS
50 #include <linux/nfs_fs.h>
53 #if defined(CONFIG_SYSCTL)
55 /* External variables not in a header file. */
57 extern int sysctl_overcommit_memory;
58 extern int sysctl_overcommit_ratio;
59 extern int max_threads;
60 extern int sysrq_enabled;
61 extern int core_uses_pid;
62 extern int suid_dumpable;
63 extern char core_pattern[];
66 extern int min_free_kbytes;
67 extern int printk_ratelimit_jiffies;
68 extern int printk_ratelimit_burst;
69 extern int pid_max_min, pid_max_max;
71 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
72 int unknown_nmi_panic;
73 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
74 void __user *, size_t *, loff_t *);
77 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
78 static int maxolduid = 65535;
81 static int ngroups_max = NGROUPS_MAX;
84 extern char modprobe_path[];
87 extern char hotplug_path[];
89 #ifdef CONFIG_CHR_DEV_SG
90 extern int sg_big_buff;
93 extern size_t shm_ctlmax;
94 extern size_t shm_ctlall;
95 extern int shm_ctlmni;
96 extern int msg_ctlmax;
97 extern int msg_ctlmnb;
98 extern int msg_ctlmni;
99 extern int sem_ctls[];
103 extern char reboot_command [];
104 extern int stop_a_enabled;
105 extern int scons_pwroff;
109 extern int pwrsw_enabled;
110 extern int unaligned_enabled;
113 #ifdef CONFIG_ARCH_S390
114 #ifdef CONFIG_MATHEMU
115 extern int sysctl_ieee_emulation_warnings;
117 extern int sysctl_userprocess_debug;
118 extern int spin_retry;
121 extern int sysctl_hz_timer;
123 #ifdef CONFIG_BSD_PROCESS_ACCT
124 extern int acct_parm[];
127 int randomize_va_space = 1;
129 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
130 ctl_table *, void **);
131 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
132 void __user *buffer, size_t *lenp, loff_t *ppos);
134 static ctl_table root_table[];
135 static struct ctl_table_header root_table_header =
136 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
138 static ctl_table kern_table[];
139 static ctl_table vm_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[];
148 #ifdef CONFIG_INOTIFY
149 extern ctl_table inotify_table[];
152 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
153 int sysctl_legacy_va_layout;
156 /* /proc declarations: */
158 #ifdef CONFIG_PROC_FS
160 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
161 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
162 static int proc_opensys(struct inode *, struct file *);
164 struct file_operations proc_sys_file_operations = {
165 .open = proc_opensys,
166 .read = proc_readsys,
167 .write = proc_writesys,
170 extern struct proc_dir_entry *proc_sys_root;
172 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
173 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
176 /* The default sysctl tables: */
178 static ctl_table root_table[] = {
180 .ctl_name = CTL_KERN,
181 .procname = "kernel",
200 .ctl_name = CTL_PROC,
212 .ctl_name = CTL_DEBUG,
215 .child = debug_table,
227 static ctl_table kern_table[] = {
229 .ctl_name = KERN_OSTYPE,
230 .procname = "ostype",
231 .data = system_utsname.sysname,
232 .maxlen = sizeof(system_utsname.sysname),
234 .proc_handler = &proc_doutsstring,
235 .strategy = &sysctl_string,
238 .ctl_name = KERN_OSRELEASE,
239 .procname = "osrelease",
240 .data = system_utsname.release,
241 .maxlen = sizeof(system_utsname.release),
243 .proc_handler = &proc_doutsstring,
244 .strategy = &sysctl_string,
247 .ctl_name = KERN_VERSION,
248 .procname = "version",
249 .data = system_utsname.version,
250 .maxlen = sizeof(system_utsname.version),
252 .proc_handler = &proc_doutsstring,
253 .strategy = &sysctl_string,
256 .ctl_name = KERN_NODENAME,
257 .procname = "hostname",
258 .data = system_utsname.nodename,
259 .maxlen = sizeof(system_utsname.nodename),
261 .proc_handler = &proc_doutsstring,
262 .strategy = &sysctl_string,
265 .ctl_name = KERN_DOMAINNAME,
266 .procname = "domainname",
267 .data = system_utsname.domainname,
268 .maxlen = sizeof(system_utsname.domainname),
270 .proc_handler = &proc_doutsstring,
271 .strategy = &sysctl_string,
274 .ctl_name = KERN_PANIC,
276 .data = &panic_timeout,
277 .maxlen = sizeof(int),
279 .proc_handler = &proc_dointvec,
282 .ctl_name = KERN_CORE_USES_PID,
283 .procname = "core_uses_pid",
284 .data = &core_uses_pid,
285 .maxlen = sizeof(int),
287 .proc_handler = &proc_dointvec,
290 .ctl_name = KERN_CORE_PATTERN,
291 .procname = "core_pattern",
292 .data = core_pattern,
295 .proc_handler = &proc_dostring,
296 .strategy = &sysctl_string,
299 .ctl_name = KERN_TAINTED,
300 .procname = "tainted",
302 .maxlen = sizeof(int),
304 .proc_handler = &proc_dointvec,
307 .ctl_name = KERN_CAP_BSET,
308 .procname = "cap-bound",
310 .maxlen = sizeof(kernel_cap_t),
312 .proc_handler = &proc_dointvec_bset,
314 #ifdef CONFIG_BLK_DEV_INITRD
316 .ctl_name = KERN_REALROOTDEV,
317 .procname = "real-root-dev",
318 .data = &real_root_dev,
319 .maxlen = sizeof(int),
321 .proc_handler = &proc_dointvec,
326 .ctl_name = KERN_SPARC_REBOOT,
327 .procname = "reboot-cmd",
328 .data = reboot_command,
331 .proc_handler = &proc_dostring,
332 .strategy = &sysctl_string,
335 .ctl_name = KERN_SPARC_STOP_A,
336 .procname = "stop-a",
337 .data = &stop_a_enabled,
338 .maxlen = sizeof (int),
340 .proc_handler = &proc_dointvec,
343 .ctl_name = KERN_SPARC_SCONS_PWROFF,
344 .procname = "scons-poweroff",
345 .data = &scons_pwroff,
346 .maxlen = sizeof (int),
348 .proc_handler = &proc_dointvec,
353 .ctl_name = KERN_HPPA_PWRSW,
354 .procname = "soft-power",
355 .data = &pwrsw_enabled,
356 .maxlen = sizeof (int),
358 .proc_handler = &proc_dointvec,
361 .ctl_name = KERN_HPPA_UNALIGNED,
362 .procname = "unaligned-trap",
363 .data = &unaligned_enabled,
364 .maxlen = sizeof (int),
366 .proc_handler = &proc_dointvec,
370 .ctl_name = KERN_CTLALTDEL,
371 .procname = "ctrl-alt-del",
373 .maxlen = sizeof(int),
375 .proc_handler = &proc_dointvec,
378 .ctl_name = KERN_PRINTK,
379 .procname = "printk",
380 .data = &console_loglevel,
381 .maxlen = 4*sizeof(int),
383 .proc_handler = &proc_dointvec,
387 .ctl_name = KERN_MODPROBE,
388 .procname = "modprobe",
389 .data = &modprobe_path,
390 .maxlen = KMOD_PATH_LEN,
392 .proc_handler = &proc_dostring,
393 .strategy = &sysctl_string,
396 #ifdef CONFIG_HOTPLUG
398 .ctl_name = KERN_HOTPLUG,
399 .procname = "hotplug",
400 .data = &hotplug_path,
401 .maxlen = HOTPLUG_PATH_LEN,
403 .proc_handler = &proc_dostring,
404 .strategy = &sysctl_string,
407 #ifdef CONFIG_CHR_DEV_SG
409 .ctl_name = KERN_SG_BIG_BUFF,
410 .procname = "sg-big-buff",
411 .data = &sg_big_buff,
412 .maxlen = sizeof (int),
414 .proc_handler = &proc_dointvec,
417 #ifdef CONFIG_BSD_PROCESS_ACCT
419 .ctl_name = KERN_ACCT,
422 .maxlen = 3*sizeof(int),
424 .proc_handler = &proc_dointvec,
427 #ifdef CONFIG_SYSVIPC
429 .ctl_name = KERN_SHMMAX,
430 .procname = "shmmax",
432 .maxlen = sizeof (size_t),
434 .proc_handler = &proc_doulongvec_minmax,
437 .ctl_name = KERN_SHMALL,
438 .procname = "shmall",
440 .maxlen = sizeof (size_t),
442 .proc_handler = &proc_doulongvec_minmax,
445 .ctl_name = KERN_SHMMNI,
446 .procname = "shmmni",
448 .maxlen = sizeof (int),
450 .proc_handler = &proc_dointvec,
453 .ctl_name = KERN_MSGMAX,
454 .procname = "msgmax",
456 .maxlen = sizeof (int),
458 .proc_handler = &proc_dointvec,
461 .ctl_name = KERN_MSGMNI,
462 .procname = "msgmni",
464 .maxlen = sizeof (int),
466 .proc_handler = &proc_dointvec,
469 .ctl_name = KERN_MSGMNB,
470 .procname = "msgmnb",
472 .maxlen = sizeof (int),
474 .proc_handler = &proc_dointvec,
477 .ctl_name = KERN_SEM,
480 .maxlen = 4*sizeof (int),
482 .proc_handler = &proc_dointvec,
485 #ifdef CONFIG_MAGIC_SYSRQ
487 .ctl_name = KERN_SYSRQ,
489 .data = &sysrq_enabled,
490 .maxlen = sizeof (int),
492 .proc_handler = &proc_dointvec,
496 .ctl_name = KERN_CADPID,
497 .procname = "cad_pid",
499 .maxlen = sizeof (int),
501 .proc_handler = &proc_dointvec,
504 .ctl_name = KERN_MAX_THREADS,
505 .procname = "threads-max",
506 .data = &max_threads,
507 .maxlen = sizeof(int),
509 .proc_handler = &proc_dointvec,
512 .ctl_name = KERN_RANDOM,
513 .procname = "random",
515 .child = random_table,
517 #ifdef CONFIG_UNIX98_PTYS
519 .ctl_name = KERN_PTY,
526 .ctl_name = KERN_OVERFLOWUID,
527 .procname = "overflowuid",
528 .data = &overflowuid,
529 .maxlen = sizeof(int),
531 .proc_handler = &proc_dointvec_minmax,
532 .strategy = &sysctl_intvec,
533 .extra1 = &minolduid,
534 .extra2 = &maxolduid,
537 .ctl_name = KERN_OVERFLOWGID,
538 .procname = "overflowgid",
539 .data = &overflowgid,
540 .maxlen = sizeof(int),
542 .proc_handler = &proc_dointvec_minmax,
543 .strategy = &sysctl_intvec,
544 .extra1 = &minolduid,
545 .extra2 = &maxolduid,
547 #ifdef CONFIG_ARCH_S390
548 #ifdef CONFIG_MATHEMU
550 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
551 .procname = "ieee_emulation_warnings",
552 .data = &sysctl_ieee_emulation_warnings,
553 .maxlen = sizeof(int),
555 .proc_handler = &proc_dointvec,
558 #ifdef CONFIG_NO_IDLE_HZ
560 .ctl_name = KERN_HZ_TIMER,
561 .procname = "hz_timer",
562 .data = &sysctl_hz_timer,
563 .maxlen = sizeof(int),
565 .proc_handler = &proc_dointvec,
569 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
570 .procname = "userprocess_debug",
571 .data = &sysctl_userprocess_debug,
572 .maxlen = sizeof(int),
574 .proc_handler = &proc_dointvec,
578 .ctl_name = KERN_PIDMAX,
579 .procname = "pid_max",
581 .maxlen = sizeof (int),
583 .proc_handler = &proc_dointvec_minmax,
584 .strategy = sysctl_intvec,
585 .extra1 = &pid_max_min,
586 .extra2 = &pid_max_max,
589 .ctl_name = KERN_PANIC_ON_OOPS,
590 .procname = "panic_on_oops",
591 .data = &panic_on_oops,
592 .maxlen = sizeof(int),
594 .proc_handler = &proc_dointvec,
597 .ctl_name = KERN_PRINTK_RATELIMIT,
598 .procname = "printk_ratelimit",
599 .data = &printk_ratelimit_jiffies,
600 .maxlen = sizeof(int),
602 .proc_handler = &proc_dointvec_jiffies,
603 .strategy = &sysctl_jiffies,
606 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
607 .procname = "printk_ratelimit_burst",
608 .data = &printk_ratelimit_burst,
609 .maxlen = sizeof(int),
611 .proc_handler = &proc_dointvec,
614 .ctl_name = KERN_NGROUPS_MAX,
615 .procname = "ngroups_max",
616 .data = &ngroups_max,
617 .maxlen = sizeof (int),
619 .proc_handler = &proc_dointvec,
621 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
623 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
624 .procname = "unknown_nmi_panic",
625 .data = &unknown_nmi_panic,
626 .maxlen = sizeof (int),
628 .proc_handler = &proc_unknown_nmi_panic,
631 #if defined(CONFIG_X86)
633 .ctl_name = KERN_BOOTLOADER_TYPE,
634 .procname = "bootloader_type",
635 .data = &bootloader_type,
636 .maxlen = sizeof (int),
638 .proc_handler = &proc_dointvec,
642 .ctl_name = KERN_RANDOMIZE,
643 .procname = "randomize_va_space",
644 .data = &randomize_va_space,
645 .maxlen = sizeof(int),
647 .proc_handler = &proc_dointvec,
649 #if defined(CONFIG_ARCH_S390)
651 .ctl_name = KERN_SPIN_RETRY,
652 .procname = "spin_retry",
654 .maxlen = sizeof (int),
656 .proc_handler = &proc_dointvec,
662 /* Constants for minimum and maximum testing in vm_table.
663 We use these as one-element integer vectors. */
665 static int one_hundred = 100;
668 static ctl_table vm_table[] = {
670 .ctl_name = VM_OVERCOMMIT_MEMORY,
671 .procname = "overcommit_memory",
672 .data = &sysctl_overcommit_memory,
673 .maxlen = sizeof(sysctl_overcommit_memory),
675 .proc_handler = &proc_dointvec,
678 .ctl_name = VM_OVERCOMMIT_RATIO,
679 .procname = "overcommit_ratio",
680 .data = &sysctl_overcommit_ratio,
681 .maxlen = sizeof(sysctl_overcommit_ratio),
683 .proc_handler = &proc_dointvec,
686 .ctl_name = VM_PAGE_CLUSTER,
687 .procname = "page-cluster",
688 .data = &page_cluster,
689 .maxlen = sizeof(int),
691 .proc_handler = &proc_dointvec,
694 .ctl_name = VM_DIRTY_BACKGROUND,
695 .procname = "dirty_background_ratio",
696 .data = &dirty_background_ratio,
697 .maxlen = sizeof(dirty_background_ratio),
699 .proc_handler = &proc_dointvec_minmax,
700 .strategy = &sysctl_intvec,
702 .extra2 = &one_hundred,
705 .ctl_name = VM_DIRTY_RATIO,
706 .procname = "dirty_ratio",
707 .data = &vm_dirty_ratio,
708 .maxlen = sizeof(vm_dirty_ratio),
710 .proc_handler = &proc_dointvec_minmax,
711 .strategy = &sysctl_intvec,
713 .extra2 = &one_hundred,
716 .ctl_name = VM_DIRTY_WB_CS,
717 .procname = "dirty_writeback_centisecs",
718 .data = &dirty_writeback_centisecs,
719 .maxlen = sizeof(dirty_writeback_centisecs),
721 .proc_handler = &dirty_writeback_centisecs_handler,
724 .ctl_name = VM_DIRTY_EXPIRE_CS,
725 .procname = "dirty_expire_centisecs",
726 .data = &dirty_expire_centisecs,
727 .maxlen = sizeof(dirty_expire_centisecs),
729 .proc_handler = &proc_dointvec,
732 .ctl_name = VM_NR_PDFLUSH_THREADS,
733 .procname = "nr_pdflush_threads",
734 .data = &nr_pdflush_threads,
735 .maxlen = sizeof nr_pdflush_threads,
736 .mode = 0444 /* read-only*/,
737 .proc_handler = &proc_dointvec,
740 .ctl_name = VM_SWAPPINESS,
741 .procname = "swappiness",
742 .data = &vm_swappiness,
743 .maxlen = sizeof(vm_swappiness),
745 .proc_handler = &proc_dointvec_minmax,
746 .strategy = &sysctl_intvec,
748 .extra2 = &one_hundred,
750 #ifdef CONFIG_HUGETLB_PAGE
752 .ctl_name = VM_HUGETLB_PAGES,
753 .procname = "nr_hugepages",
754 .data = &max_huge_pages,
755 .maxlen = sizeof(unsigned long),
757 .proc_handler = &hugetlb_sysctl_handler,
758 .extra1 = (void *)&hugetlb_zero,
759 .extra2 = (void *)&hugetlb_infinity,
762 .ctl_name = VM_HUGETLB_GROUP,
763 .procname = "hugetlb_shm_group",
764 .data = &sysctl_hugetlb_shm_group,
765 .maxlen = sizeof(gid_t),
767 .proc_handler = &proc_dointvec,
771 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
772 .procname = "lowmem_reserve_ratio",
773 .data = &sysctl_lowmem_reserve_ratio,
774 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
776 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
777 .strategy = &sysctl_intvec,
780 .ctl_name = VM_MIN_FREE_KBYTES,
781 .procname = "min_free_kbytes",
782 .data = &min_free_kbytes,
783 .maxlen = sizeof(min_free_kbytes),
785 .proc_handler = &min_free_kbytes_sysctl_handler,
786 .strategy = &sysctl_intvec,
791 .ctl_name = VM_MAX_MAP_COUNT,
792 .procname = "max_map_count",
793 .data = &sysctl_max_map_count,
794 .maxlen = sizeof(sysctl_max_map_count),
796 .proc_handler = &proc_dointvec
800 .ctl_name = VM_LAPTOP_MODE,
801 .procname = "laptop_mode",
802 .data = &laptop_mode,
803 .maxlen = sizeof(laptop_mode),
805 .proc_handler = &proc_dointvec,
806 .strategy = &sysctl_intvec,
810 .ctl_name = VM_BLOCK_DUMP,
811 .procname = "block_dump",
813 .maxlen = sizeof(block_dump),
815 .proc_handler = &proc_dointvec,
816 .strategy = &sysctl_intvec,
820 .ctl_name = VM_VFS_CACHE_PRESSURE,
821 .procname = "vfs_cache_pressure",
822 .data = &sysctl_vfs_cache_pressure,
823 .maxlen = sizeof(sysctl_vfs_cache_pressure),
825 .proc_handler = &proc_dointvec,
826 .strategy = &sysctl_intvec,
829 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
831 .ctl_name = VM_LEGACY_VA_LAYOUT,
832 .procname = "legacy_va_layout",
833 .data = &sysctl_legacy_va_layout,
834 .maxlen = sizeof(sysctl_legacy_va_layout),
836 .proc_handler = &proc_dointvec,
837 .strategy = &sysctl_intvec,
843 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
844 .procname = "swap_token_timeout",
845 .data = &swap_token_default_timeout,
846 .maxlen = sizeof(swap_token_default_timeout),
848 .proc_handler = &proc_dointvec_jiffies,
849 .strategy = &sysctl_jiffies,
855 static ctl_table proc_table[] = {
859 static ctl_table fs_table[] = {
861 .ctl_name = FS_NRINODE,
862 .procname = "inode-nr",
863 .data = &inodes_stat,
864 .maxlen = 2*sizeof(int),
866 .proc_handler = &proc_dointvec,
869 .ctl_name = FS_STATINODE,
870 .procname = "inode-state",
871 .data = &inodes_stat,
872 .maxlen = 7*sizeof(int),
874 .proc_handler = &proc_dointvec,
877 .ctl_name = FS_NRFILE,
878 .procname = "file-nr",
880 .maxlen = 3*sizeof(int),
882 .proc_handler = &proc_dointvec,
885 .ctl_name = FS_MAXFILE,
886 .procname = "file-max",
887 .data = &files_stat.max_files,
888 .maxlen = sizeof(int),
890 .proc_handler = &proc_dointvec,
893 .ctl_name = FS_DENTRY,
894 .procname = "dentry-state",
895 .data = &dentry_stat,
896 .maxlen = 6*sizeof(int),
898 .proc_handler = &proc_dointvec,
901 .ctl_name = FS_OVERFLOWUID,
902 .procname = "overflowuid",
903 .data = &fs_overflowuid,
904 .maxlen = sizeof(int),
906 .proc_handler = &proc_dointvec_minmax,
907 .strategy = &sysctl_intvec,
908 .extra1 = &minolduid,
909 .extra2 = &maxolduid,
912 .ctl_name = FS_OVERFLOWGID,
913 .procname = "overflowgid",
914 .data = &fs_overflowgid,
915 .maxlen = sizeof(int),
917 .proc_handler = &proc_dointvec_minmax,
918 .strategy = &sysctl_intvec,
919 .extra1 = &minolduid,
920 .extra2 = &maxolduid,
923 .ctl_name = FS_LEASES,
924 .procname = "leases-enable",
925 .data = &leases_enable,
926 .maxlen = sizeof(int),
928 .proc_handler = &proc_dointvec,
930 #ifdef CONFIG_DNOTIFY
932 .ctl_name = FS_DIR_NOTIFY,
933 .procname = "dir-notify-enable",
934 .data = &dir_notify_enable,
935 .maxlen = sizeof(int),
937 .proc_handler = &proc_dointvec,
942 .ctl_name = FS_LEASE_TIME,
943 .procname = "lease-break-time",
944 .data = &lease_break_time,
945 .maxlen = sizeof(int),
947 .proc_handler = &proc_dointvec,
950 .ctl_name = FS_AIO_NR,
951 .procname = "aio-nr",
953 .maxlen = sizeof(aio_nr),
955 .proc_handler = &proc_dointvec,
958 .ctl_name = FS_AIO_MAX_NR,
959 .procname = "aio-max-nr",
961 .maxlen = sizeof(aio_max_nr),
963 .proc_handler = &proc_dointvec,
965 #ifdef CONFIG_INOTIFY
967 .ctl_name = FS_INOTIFY,
968 .procname = "inotify",
970 .child = inotify_table,
975 .ctl_name = KERN_SETUID_DUMPABLE,
976 .procname = "suid_dumpable",
977 .data = &suid_dumpable,
978 .maxlen = sizeof(int),
980 .proc_handler = &proc_dointvec,
985 static ctl_table debug_table[] = {
989 static ctl_table dev_table[] = {
993 extern void init_irq_proc (void);
995 void __init sysctl_init(void)
997 #ifdef CONFIG_PROC_FS
998 register_proc_table(root_table, proc_sys_root);
1003 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1004 void __user *newval, size_t newlen)
1006 struct list_head *tmp;
1008 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1012 if (!oldlenp || get_user(old_len, oldlenp))
1015 tmp = &root_table_header.ctl_entry;
1017 struct ctl_table_header *head =
1018 list_entry(tmp, struct ctl_table_header, ctl_entry);
1019 void *context = NULL;
1020 int error = parse_table(name, nlen, oldval, oldlenp,
1021 newval, newlen, head->ctl_table,
1024 if (error != -ENOTDIR)
1027 } while (tmp != &root_table_header.ctl_entry);
1031 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1033 struct __sysctl_args tmp;
1036 if (copy_from_user(&tmp, args, sizeof(tmp)))
1040 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1041 tmp.newval, tmp.newlen);
1047 * ctl_perm does NOT grant the superuser all rights automatically, because
1048 * some sysctl variables are readonly even to root.
1051 static int test_perm(int mode, int op)
1055 else if (in_egroup_p(0))
1057 if ((mode & op & 0007) == op)
1062 static inline int ctl_perm(ctl_table *table, int op)
1065 error = security_sysctl(table, op);
1068 return test_perm(table->mode, op);
1071 static int parse_table(int __user *name, int nlen,
1072 void __user *oldval, size_t __user *oldlenp,
1073 void __user *newval, size_t newlen,
1074 ctl_table *table, void **context)
1080 if (get_user(n, name))
1082 for ( ; table->ctl_name; table++) {
1083 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1086 if (ctl_perm(table, 001))
1088 if (table->strategy) {
1089 error = table->strategy(
1092 newval, newlen, context);
1098 table = table->child;
1101 error = do_sysctl_strategy(table, name, nlen,
1103 newval, newlen, context);
1110 /* Perform the actual read/write of a sysctl table entry. */
1111 int do_sysctl_strategy (ctl_table *table,
1112 int __user *name, int nlen,
1113 void __user *oldval, size_t __user *oldlenp,
1114 void __user *newval, size_t newlen, void **context)
1123 if (ctl_perm(table, op))
1126 if (table->strategy) {
1127 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1128 newval, newlen, context);
1135 /* If there is no strategy routine, or if the strategy returns
1136 * zero, proceed with automatic r/w */
1137 if (table->data && table->maxlen) {
1138 if (oldval && oldlenp) {
1139 if (get_user(len, oldlenp))
1142 if (len > table->maxlen)
1143 len = table->maxlen;
1144 if(copy_to_user(oldval, table->data, len))
1146 if(put_user(len, oldlenp))
1150 if (newval && newlen) {
1152 if (len > table->maxlen)
1153 len = table->maxlen;
1154 if(copy_from_user(table->data, newval, len))
1162 * register_sysctl_table - register a sysctl hierarchy
1163 * @table: the top-level table structure
1164 * @insert_at_head: whether the entry should be inserted in front or at the end
1166 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1167 * array. An entry with a ctl_name of 0 terminates the table.
1169 * The members of the &ctl_table structure are used as follows:
1171 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1172 * must be unique within that level of sysctl
1174 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1175 * enter a sysctl file
1177 * data - a pointer to data for use by proc_handler
1179 * maxlen - the maximum size in bytes of the data
1181 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1183 * child - a pointer to the child sysctl table if this entry is a directory, or
1186 * proc_handler - the text handler routine (described below)
1188 * strategy - the strategy routine (described below)
1190 * de - for internal use by the sysctl routines
1192 * extra1, extra2 - extra pointers usable by the proc handler routines
1194 * Leaf nodes in the sysctl tree will be represented by a single file
1195 * under /proc; non-leaf nodes will be represented by directories.
1197 * sysctl(2) can automatically manage read and write requests through
1198 * the sysctl table. The data and maxlen fields of the ctl_table
1199 * struct enable minimal validation of the values being written to be
1200 * performed, and the mode field allows minimal authentication.
1202 * More sophisticated management can be enabled by the provision of a
1203 * strategy routine with the table entry. This will be called before
1204 * any automatic read or write of the data is performed.
1206 * The strategy routine may return
1208 * < 0 - Error occurred (error is passed to user process)
1210 * 0 - OK - proceed with automatic read or write.
1212 * > 0 - OK - read or write has been done by the strategy routine, so
1213 * return immediately.
1215 * There must be a proc_handler routine for any terminal nodes
1216 * mirrored under /proc/sys (non-terminals are handled by a built-in
1217 * directory handler). Several default handlers are available to
1218 * cover common cases -
1220 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1221 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1222 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1224 * It is the handler's job to read the input buffer from user memory
1225 * and process it. The handler should return 0 on success.
1227 * This routine returns %NULL on a failure to register, and a pointer
1228 * to the table header on success.
1230 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1233 struct ctl_table_header *tmp;
1234 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1237 tmp->ctl_table = table;
1238 INIT_LIST_HEAD(&tmp->ctl_entry);
1240 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1242 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1243 #ifdef CONFIG_PROC_FS
1244 register_proc_table(table, proc_sys_root);
1250 * unregister_sysctl_table - unregister a sysctl table hierarchy
1251 * @header: the header returned from register_sysctl_table
1253 * Unregisters the sysctl table and all children. proc entries may not
1254 * actually be removed until they are no longer used by anyone.
1256 void unregister_sysctl_table(struct ctl_table_header * header)
1258 list_del(&header->ctl_entry);
1259 #ifdef CONFIG_PROC_FS
1260 unregister_proc_table(header->ctl_table, proc_sys_root);
1269 #ifdef CONFIG_PROC_FS
1271 /* Scan the sysctl entries in table and add them all into /proc */
1272 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1274 struct proc_dir_entry *de;
1278 for (; table->ctl_name; table++) {
1279 /* Can't do anything without a proc name. */
1280 if (!table->procname)
1282 /* Maybe we can't do anything with it... */
1283 if (!table->proc_handler && !table->child) {
1284 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1289 len = strlen(table->procname);
1293 if (table->proc_handler)
1297 for (de = root->subdir; de; de = de->next) {
1298 if (proc_match(len, table->procname, de))
1301 /* If the subdir exists already, de is non-NULL */
1305 de = create_proc_entry(table->procname, mode, root);
1308 de->data = (void *) table;
1309 if (table->proc_handler)
1310 de->proc_fops = &proc_sys_file_operations;
1313 if (de->mode & S_IFDIR)
1314 register_proc_table(table->child, de);
1319 * Unregister a /proc sysctl table and any subdirectories.
1321 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1323 struct proc_dir_entry *de;
1324 for (; table->ctl_name; table++) {
1325 if (!(de = table->de))
1327 if (de->mode & S_IFDIR) {
1328 if (!table->child) {
1329 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1332 unregister_proc_table(table->child, de);
1334 /* Don't unregister directories which still have entries.. */
1339 /* Don't unregister proc entries that are still being used.. */
1340 if (atomic_read(&de->count))
1344 remove_proc_entry(table->procname, root);
1348 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1349 size_t count, loff_t *ppos)
1352 struct proc_dir_entry *de;
1353 struct ctl_table *table;
1357 de = PDE(file->f_dentry->d_inode);
1358 if (!de || !de->data)
1360 table = (struct ctl_table *) de->data;
1361 if (!table || !table->proc_handler)
1363 op = (write ? 002 : 004);
1364 if (ctl_perm(table, op))
1369 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1375 static int proc_opensys(struct inode *inode, struct file *file)
1377 if (file->f_mode & FMODE_WRITE) {
1379 * sysctl entries that are not writable,
1380 * are _NOT_ writable, capabilities or not.
1382 if (!(inode->i_mode & S_IWUSR))
1389 static ssize_t proc_readsys(struct file * file, char __user * buf,
1390 size_t count, loff_t *ppos)
1392 return do_rw_proc(0, file, buf, count, ppos);
1395 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1396 size_t count, loff_t *ppos)
1398 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1402 * proc_dostring - read a string sysctl
1403 * @table: the sysctl table
1404 * @write: %TRUE if this is a write to the sysctl file
1405 * @filp: the file structure
1406 * @buffer: the user buffer
1407 * @lenp: the size of the user buffer
1408 * @ppos: file position
1410 * Reads/writes a string from/to the user buffer. If the kernel
1411 * buffer provided is not large enough to hold the string, the
1412 * string is truncated. The copied string is %NULL-terminated.
1413 * If the string is being read by the user process, it is copied
1414 * and a newline '\n' is added. It is truncated if the buffer is
1417 * Returns 0 on success.
1419 int proc_dostring(ctl_table *table, int write, struct file *filp,
1420 void __user *buffer, size_t *lenp, loff_t *ppos)
1426 if (!table->data || !table->maxlen || !*lenp ||
1427 (*ppos && !write)) {
1435 while (len < *lenp) {
1436 if (get_user(c, p++))
1438 if (c == 0 || c == '\n')
1442 if (len >= table->maxlen)
1443 len = table->maxlen-1;
1444 if(copy_from_user(table->data, buffer, len))
1446 ((char *) table->data)[len] = 0;
1449 len = strlen(table->data);
1450 if (len > table->maxlen)
1451 len = table->maxlen;
1455 if(copy_to_user(buffer, table->data, len))
1458 if(put_user('\n', ((char __user *) buffer) + len))
1469 * Special case of dostring for the UTS structure. This has locks
1470 * to observe. Should this be in kernel/sys.c ????
1473 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1474 void __user *buffer, size_t *lenp, loff_t *ppos)
1479 down_read(&uts_sem);
1480 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1483 down_write(&uts_sem);
1484 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1490 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1492 int write, void *data)
1495 *valp = *negp ? -*lvalp : *lvalp;
1500 *lvalp = (unsigned long)-val;
1503 *lvalp = (unsigned long)val;
1509 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1510 void __user *buffer, size_t *lenp, loff_t *ppos,
1511 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1512 int write, void *data),
1515 #define TMPBUFLEN 21
1516 int *i, vleft, first=1, neg, val;
1520 char buf[TMPBUFLEN], *p;
1521 char __user *s = buffer;
1523 if (!table->data || !table->maxlen || !*lenp ||
1524 (*ppos && !write)) {
1529 i = (int *) table->data;
1530 vleft = table->maxlen / sizeof(*i);
1534 conv = do_proc_dointvec_conv;
1536 for (; left && vleft--; i++, first=0) {
1551 if (len > sizeof(buf) - 1)
1552 len = sizeof(buf) - 1;
1553 if (copy_from_user(buf, s, len))
1557 if (*p == '-' && left > 1) {
1561 if (*p < '0' || *p > '9')
1564 lval = simple_strtoul(p, &p, 0);
1567 if ((len < left) && *p && !isspace(*p))
1574 if (conv(&neg, &lval, i, 1, data))
1581 if (conv(&neg, &lval, i, 0, data))
1584 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1588 if(copy_to_user(s, buf, len))
1595 if (!write && !first && left) {
1596 if(put_user('\n', s))
1603 if (get_user(c, s++))
1619 * proc_dointvec - read a vector of integers
1620 * @table: the sysctl table
1621 * @write: %TRUE if this is a write to the sysctl file
1622 * @filp: the file structure
1623 * @buffer: the user buffer
1624 * @lenp: the size of the user buffer
1625 * @ppos: file position
1627 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1628 * values from/to the user buffer, treated as an ASCII string.
1630 * Returns 0 on success.
1632 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1633 void __user *buffer, size_t *lenp, loff_t *ppos)
1635 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1645 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1647 int write, void *data)
1649 int op = *(int *)data;
1651 int val = *negp ? -*lvalp : *lvalp;
1653 case OP_SET: *valp = val; break;
1654 case OP_AND: *valp &= val; break;
1655 case OP_OR: *valp |= val; break;
1656 case OP_MAX: if(*valp < val)
1659 case OP_MIN: if(*valp > val)
1667 *lvalp = (unsigned long)-val;
1670 *lvalp = (unsigned long)val;
1677 * init may raise the set.
1680 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1681 void __user *buffer, size_t *lenp, loff_t *ppos)
1685 if (!capable(CAP_SYS_MODULE)) {
1689 op = (current->pid == 1) ? OP_SET : OP_AND;
1690 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1691 do_proc_dointvec_bset_conv,&op);
1694 struct do_proc_dointvec_minmax_conv_param {
1699 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1701 int write, void *data)
1703 struct do_proc_dointvec_minmax_conv_param *param = data;
1705 int val = *negp ? -*lvalp : *lvalp;
1706 if ((param->min && *param->min > val) ||
1707 (param->max && *param->max < val))
1714 *lvalp = (unsigned long)-val;
1717 *lvalp = (unsigned long)val;
1724 * proc_dointvec_minmax - read a vector of integers with min/max values
1725 * @table: the sysctl table
1726 * @write: %TRUE if this is a write to the sysctl file
1727 * @filp: the file structure
1728 * @buffer: the user buffer
1729 * @lenp: the size of the user buffer
1730 * @ppos: file position
1732 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1733 * values from/to the user buffer, treated as an ASCII string.
1735 * This routine will ensure the values are within the range specified by
1736 * table->extra1 (min) and table->extra2 (max).
1738 * Returns 0 on success.
1740 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1741 void __user *buffer, size_t *lenp, loff_t *ppos)
1743 struct do_proc_dointvec_minmax_conv_param param = {
1744 .min = (int *) table->extra1,
1745 .max = (int *) table->extra2,
1747 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1748 do_proc_dointvec_minmax_conv, ¶m);
1751 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1753 void __user *buffer,
1754 size_t *lenp, loff_t *ppos,
1755 unsigned long convmul,
1756 unsigned long convdiv)
1758 #define TMPBUFLEN 21
1759 unsigned long *i, *min, *max, val;
1760 int vleft, first=1, neg;
1762 char buf[TMPBUFLEN], *p;
1763 char __user *s = buffer;
1765 if (!table->data || !table->maxlen || !*lenp ||
1766 (*ppos && !write)) {
1771 i = (unsigned long *) table->data;
1772 min = (unsigned long *) table->extra1;
1773 max = (unsigned long *) table->extra2;
1774 vleft = table->maxlen / sizeof(unsigned long);
1777 for (; left && vleft--; i++, min++, max++, first=0) {
1792 if (len > TMPBUFLEN-1)
1794 if (copy_from_user(buf, s, len))
1798 if (*p == '-' && left > 1) {
1802 if (*p < '0' || *p > '9')
1804 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1806 if ((len < left) && *p && !isspace(*p))
1815 if ((min && val < *min) || (max && val > *max))
1822 sprintf(p, "%lu", convdiv * (*i) / convmul);
1826 if(copy_to_user(s, buf, len))
1833 if (!write && !first && left) {
1834 if(put_user('\n', s))
1841 if (get_user(c, s++))
1857 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1858 * @table: the sysctl table
1859 * @write: %TRUE if this is a write to the sysctl file
1860 * @filp: the file structure
1861 * @buffer: the user buffer
1862 * @lenp: the size of the user buffer
1863 * @ppos: file position
1865 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1866 * values from/to the user buffer, treated as an ASCII string.
1868 * This routine will ensure the values are within the range specified by
1869 * table->extra1 (min) and table->extra2 (max).
1871 * Returns 0 on success.
1873 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1874 void __user *buffer, size_t *lenp, loff_t *ppos)
1876 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1880 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1881 * @table: the sysctl table
1882 * @write: %TRUE if this is a write to the sysctl file
1883 * @filp: the file structure
1884 * @buffer: the user buffer
1885 * @lenp: the size of the user buffer
1886 * @ppos: file position
1888 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1889 * values from/to the user buffer, treated as an ASCII string. The values
1890 * are treated as milliseconds, and converted to jiffies when they are stored.
1892 * This routine will ensure the values are within the range specified by
1893 * table->extra1 (min) and table->extra2 (max).
1895 * Returns 0 on success.
1897 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1899 void __user *buffer,
1900 size_t *lenp, loff_t *ppos)
1902 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1903 lenp, ppos, HZ, 1000l);
1907 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1909 int write, void *data)
1912 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1918 lval = (unsigned long)-val;
1921 lval = (unsigned long)val;
1928 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1930 int write, void *data)
1933 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1939 lval = (unsigned long)-val;
1942 lval = (unsigned long)val;
1944 *lvalp = jiffies_to_clock_t(lval);
1949 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1951 int write, void *data)
1954 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1960 lval = (unsigned long)-val;
1963 lval = (unsigned long)val;
1965 *lvalp = jiffies_to_msecs(lval);
1971 * proc_dointvec_jiffies - read a vector of integers as seconds
1972 * @table: the sysctl table
1973 * @write: %TRUE if this is a write to the sysctl file
1974 * @filp: the file structure
1975 * @buffer: the user buffer
1976 * @lenp: the size of the user buffer
1977 * @ppos: file position
1979 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1980 * values from/to the user buffer, treated as an ASCII string.
1981 * The values read are assumed to be in seconds, and are converted into
1984 * Returns 0 on success.
1986 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1987 void __user *buffer, size_t *lenp, loff_t *ppos)
1989 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1990 do_proc_dointvec_jiffies_conv,NULL);
1994 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1995 * @table: the sysctl table
1996 * @write: %TRUE if this is a write to the sysctl file
1997 * @filp: the file structure
1998 * @buffer: the user buffer
1999 * @lenp: the size of the user buffer
2001 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2002 * values from/to the user buffer, treated as an ASCII string.
2003 * The values read are assumed to be in 1/USER_HZ seconds, and
2004 * are converted into jiffies.
2006 * Returns 0 on success.
2008 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2009 void __user *buffer, size_t *lenp, loff_t *ppos)
2011 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2012 do_proc_dointvec_userhz_jiffies_conv,NULL);
2016 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2017 * @table: the sysctl table
2018 * @write: %TRUE if this is a write to the sysctl file
2019 * @filp: the file structure
2020 * @buffer: the user buffer
2021 * @lenp: the size of the user buffer
2022 * @ppos: file position
2023 * @ppos: the current position in the file
2025 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2026 * values from/to the user buffer, treated as an ASCII string.
2027 * The values read are assumed to be in 1/1000 seconds, and
2028 * are converted into jiffies.
2030 * Returns 0 on success.
2032 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2033 void __user *buffer, size_t *lenp, loff_t *ppos)
2035 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2036 do_proc_dointvec_ms_jiffies_conv, NULL);
2039 #else /* CONFIG_PROC_FS */
2041 int proc_dostring(ctl_table *table, int write, struct file *filp,
2042 void __user *buffer, size_t *lenp, loff_t *ppos)
2047 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2048 void __user *buffer, size_t *lenp, loff_t *ppos)
2053 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2054 void __user *buffer, size_t *lenp, loff_t *ppos)
2059 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2060 void __user *buffer, size_t *lenp, loff_t *ppos)
2065 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2066 void __user *buffer, size_t *lenp, loff_t *ppos)
2071 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2072 void __user *buffer, size_t *lenp, loff_t *ppos)
2077 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2078 void __user *buffer, size_t *lenp, loff_t *ppos)
2083 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2084 void __user *buffer, size_t *lenp, loff_t *ppos)
2089 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2090 void __user *buffer, size_t *lenp, loff_t *ppos)
2095 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2097 void __user *buffer,
2098 size_t *lenp, loff_t *ppos)
2104 #endif /* CONFIG_PROC_FS */
2108 * General sysctl support routines
2111 /* The generic string strategy routine: */
2112 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2113 void __user *oldval, size_t __user *oldlenp,
2114 void __user *newval, size_t newlen, void **context)
2118 if (!table->data || !table->maxlen)
2121 if (oldval && oldlenp) {
2122 if (get_user(len, oldlenp))
2125 l = strlen(table->data);
2126 if (len > l) len = l;
2127 if (len >= table->maxlen)
2128 len = table->maxlen;
2129 if(copy_to_user(oldval, table->data, len))
2131 if(put_user(0, ((char __user *) oldval) + len))
2133 if(put_user(len, oldlenp))
2137 if (newval && newlen) {
2139 if (len > table->maxlen)
2140 len = table->maxlen;
2141 if(copy_from_user(table->data, newval, len))
2143 if (len == table->maxlen)
2145 ((char *) table->data)[len] = 0;
2151 * This function makes sure that all of the integers in the vector
2152 * are between the minimum and maximum values given in the arrays
2153 * table->extra1 and table->extra2, respectively.
2155 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2156 void __user *oldval, size_t __user *oldlenp,
2157 void __user *newval, size_t newlen, void **context)
2160 if (newval && newlen) {
2161 int __user *vec = (int __user *) newval;
2162 int *min = (int *) table->extra1;
2163 int *max = (int *) table->extra2;
2167 if (newlen % sizeof(int) != 0)
2170 if (!table->extra1 && !table->extra2)
2173 if (newlen > table->maxlen)
2174 newlen = table->maxlen;
2175 length = newlen / sizeof(int);
2177 for (i = 0; i < length; i++) {
2179 if (get_user(value, vec + i))
2181 if (min && value < min[i])
2183 if (max && value > max[i])
2190 /* Strategy function to convert jiffies to seconds */
2191 int sysctl_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(*(int *)(table->data)/HZ, (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) = new*HZ;
2218 /* Strategy function to convert jiffies to seconds */
2219 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2220 void __user *oldval, size_t __user *oldlenp,
2221 void __user *newval, size_t newlen, void **context)
2226 if (get_user(olen, oldlenp))
2228 if (olen!=sizeof(int))
2231 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2232 (oldlenp && put_user(sizeof(int),oldlenp)))
2235 if (newval && newlen) {
2237 if (newlen != sizeof(int))
2239 if (get_user(new, (int __user *)newval))
2241 *(int *)(table->data) = msecs_to_jiffies(new);
2246 #else /* CONFIG_SYSCTL */
2249 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2254 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2255 void __user *oldval, size_t __user *oldlenp,
2256 void __user *newval, size_t newlen, void **context)
2261 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2262 void __user *oldval, size_t __user *oldlenp,
2263 void __user *newval, size_t newlen, void **context)
2268 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2269 void __user *oldval, size_t __user *oldlenp,
2270 void __user *newval, size_t newlen, void **context)
2275 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2276 void __user *oldval, size_t __user *oldlenp,
2277 void __user *newval, size_t newlen, void **context)
2282 int proc_dostring(ctl_table *table, int write, struct file *filp,
2283 void __user *buffer, size_t *lenp, loff_t *ppos)
2288 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2289 void __user *buffer, size_t *lenp, loff_t *ppos)
2294 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2295 void __user *buffer, size_t *lenp, loff_t *ppos)
2300 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2301 void __user *buffer, size_t *lenp, loff_t *ppos)
2306 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2307 void __user *buffer, size_t *lenp, loff_t *ppos)
2312 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2313 void __user *buffer, size_t *lenp, loff_t *ppos)
2318 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2319 void __user *buffer, size_t *lenp, loff_t *ppos)
2324 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2325 void __user *buffer, size_t *lenp, loff_t *ppos)
2330 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2332 void __user *buffer,
2333 size_t *lenp, loff_t *ppos)
2338 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2344 void unregister_sysctl_table(struct ctl_table_header * table)
2348 #endif /* CONFIG_SYSCTL */
2351 * No sense putting this after each symbol definition, twice,
2352 * exception granted :-)
2354 EXPORT_SYMBOL(proc_dointvec);
2355 EXPORT_SYMBOL(proc_dointvec_jiffies);
2356 EXPORT_SYMBOL(proc_dointvec_minmax);
2357 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2358 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2359 EXPORT_SYMBOL(proc_dostring);
2360 EXPORT_SYMBOL(proc_doulongvec_minmax);
2361 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2362 EXPORT_SYMBOL(register_sysctl_table);
2363 EXPORT_SYMBOL(sysctl_intvec);
2364 EXPORT_SYMBOL(sysctl_jiffies);
2365 EXPORT_SYMBOL(sysctl_ms_jiffies);
2366 EXPORT_SYMBOL(sysctl_string);
2367 EXPORT_SYMBOL(unregister_sysctl_table);