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 *, void *);
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_doulongvec_minmax,
958 .ctl_name = FS_AIO_MAX_NR,
959 .procname = "aio-max-nr",
961 .maxlen = sizeof(aio_max_nr),
963 .proc_handler = &proc_doulongvec_minmax,
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 static DEFINE_SPINLOCK(sysctl_lock);
997 /* called under sysctl_lock */
998 static int use_table(struct ctl_table_header *p)
1000 if (unlikely(p->unregistering))
1006 /* called under sysctl_lock */
1007 static void unuse_table(struct ctl_table_header *p)
1010 if (unlikely(p->unregistering))
1011 complete(p->unregistering);
1014 /* called under sysctl_lock, will reacquire if has to wait */
1015 static void start_unregistering(struct ctl_table_header *p)
1018 * if p->used is 0, nobody will ever touch that entry again;
1019 * we'll eliminate all paths to it before dropping sysctl_lock
1021 if (unlikely(p->used)) {
1022 struct completion wait;
1023 init_completion(&wait);
1024 p->unregistering = &wait;
1025 spin_unlock(&sysctl_lock);
1026 wait_for_completion(&wait);
1027 spin_lock(&sysctl_lock);
1030 * do not remove from the list until nobody holds it; walking the
1031 * list in do_sysctl() relies on that.
1033 list_del_init(&p->ctl_entry);
1036 void __init sysctl_init(void)
1038 #ifdef CONFIG_PROC_FS
1039 register_proc_table(root_table, proc_sys_root, &root_table_header);
1044 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1045 void __user *newval, size_t newlen)
1047 struct list_head *tmp;
1048 int error = -ENOTDIR;
1050 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1054 if (!oldlenp || get_user(old_len, oldlenp))
1057 spin_lock(&sysctl_lock);
1058 tmp = &root_table_header.ctl_entry;
1060 struct ctl_table_header *head =
1061 list_entry(tmp, struct ctl_table_header, ctl_entry);
1062 void *context = NULL;
1064 if (!use_table(head))
1067 spin_unlock(&sysctl_lock);
1069 error = parse_table(name, nlen, oldval, oldlenp,
1070 newval, newlen, head->ctl_table,
1074 spin_lock(&sysctl_lock);
1076 if (error != -ENOTDIR)
1078 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1079 spin_unlock(&sysctl_lock);
1083 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1085 struct __sysctl_args tmp;
1088 if (copy_from_user(&tmp, args, sizeof(tmp)))
1092 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1093 tmp.newval, tmp.newlen);
1099 * ctl_perm does NOT grant the superuser all rights automatically, because
1100 * some sysctl variables are readonly even to root.
1103 static int test_perm(int mode, int op)
1107 else if (in_egroup_p(0))
1109 if ((mode & op & 0007) == op)
1114 static inline int ctl_perm(ctl_table *table, int op)
1117 error = security_sysctl(table, op);
1120 return test_perm(table->mode, op);
1123 static int parse_table(int __user *name, int nlen,
1124 void __user *oldval, size_t __user *oldlenp,
1125 void __user *newval, size_t newlen,
1126 ctl_table *table, void **context)
1132 if (get_user(n, name))
1134 for ( ; table->ctl_name; table++) {
1135 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1138 if (ctl_perm(table, 001))
1140 if (table->strategy) {
1141 error = table->strategy(
1144 newval, newlen, context);
1150 table = table->child;
1153 error = do_sysctl_strategy(table, name, nlen,
1155 newval, newlen, context);
1162 /* Perform the actual read/write of a sysctl table entry. */
1163 int do_sysctl_strategy (ctl_table *table,
1164 int __user *name, int nlen,
1165 void __user *oldval, size_t __user *oldlenp,
1166 void __user *newval, size_t newlen, void **context)
1175 if (ctl_perm(table, op))
1178 if (table->strategy) {
1179 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1180 newval, newlen, context);
1187 /* If there is no strategy routine, or if the strategy returns
1188 * zero, proceed with automatic r/w */
1189 if (table->data && table->maxlen) {
1190 if (oldval && oldlenp) {
1191 if (get_user(len, oldlenp))
1194 if (len > table->maxlen)
1195 len = table->maxlen;
1196 if(copy_to_user(oldval, table->data, len))
1198 if(put_user(len, oldlenp))
1202 if (newval && newlen) {
1204 if (len > table->maxlen)
1205 len = table->maxlen;
1206 if(copy_from_user(table->data, newval, len))
1214 * register_sysctl_table - register a sysctl hierarchy
1215 * @table: the top-level table structure
1216 * @insert_at_head: whether the entry should be inserted in front or at the end
1218 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1219 * array. An entry with a ctl_name of 0 terminates the table.
1221 * The members of the &ctl_table structure are used as follows:
1223 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1224 * must be unique within that level of sysctl
1226 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1227 * enter a sysctl file
1229 * data - a pointer to data for use by proc_handler
1231 * maxlen - the maximum size in bytes of the data
1233 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1235 * child - a pointer to the child sysctl table if this entry is a directory, or
1238 * proc_handler - the text handler routine (described below)
1240 * strategy - the strategy routine (described below)
1242 * de - for internal use by the sysctl routines
1244 * extra1, extra2 - extra pointers usable by the proc handler routines
1246 * Leaf nodes in the sysctl tree will be represented by a single file
1247 * under /proc; non-leaf nodes will be represented by directories.
1249 * sysctl(2) can automatically manage read and write requests through
1250 * the sysctl table. The data and maxlen fields of the ctl_table
1251 * struct enable minimal validation of the values being written to be
1252 * performed, and the mode field allows minimal authentication.
1254 * More sophisticated management can be enabled by the provision of a
1255 * strategy routine with the table entry. This will be called before
1256 * any automatic read or write of the data is performed.
1258 * The strategy routine may return
1260 * < 0 - Error occurred (error is passed to user process)
1262 * 0 - OK - proceed with automatic read or write.
1264 * > 0 - OK - read or write has been done by the strategy routine, so
1265 * return immediately.
1267 * There must be a proc_handler routine for any terminal nodes
1268 * mirrored under /proc/sys (non-terminals are handled by a built-in
1269 * directory handler). Several default handlers are available to
1270 * cover common cases -
1272 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1273 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1274 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1276 * It is the handler's job to read the input buffer from user memory
1277 * and process it. The handler should return 0 on success.
1279 * This routine returns %NULL on a failure to register, and a pointer
1280 * to the table header on success.
1282 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1285 struct ctl_table_header *tmp;
1286 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1289 tmp->ctl_table = table;
1290 INIT_LIST_HEAD(&tmp->ctl_entry);
1292 tmp->unregistering = NULL;
1293 spin_lock(&sysctl_lock);
1295 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1297 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1298 spin_unlock(&sysctl_lock);
1299 #ifdef CONFIG_PROC_FS
1300 register_proc_table(table, proc_sys_root, tmp);
1306 * unregister_sysctl_table - unregister a sysctl table hierarchy
1307 * @header: the header returned from register_sysctl_table
1309 * Unregisters the sysctl table and all children. proc entries may not
1310 * actually be removed until they are no longer used by anyone.
1312 void unregister_sysctl_table(struct ctl_table_header * header)
1315 spin_lock(&sysctl_lock);
1316 start_unregistering(header);
1317 #ifdef CONFIG_PROC_FS
1318 unregister_proc_table(header->ctl_table, proc_sys_root);
1320 spin_unlock(&sysctl_lock);
1328 #ifdef CONFIG_PROC_FS
1330 /* Scan the sysctl entries in table and add them all into /proc */
1331 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1333 struct proc_dir_entry *de;
1337 for (; table->ctl_name; table++) {
1338 /* Can't do anything without a proc name. */
1339 if (!table->procname)
1341 /* Maybe we can't do anything with it... */
1342 if (!table->proc_handler && !table->child) {
1343 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1348 len = strlen(table->procname);
1352 if (table->proc_handler)
1356 for (de = root->subdir; de; de = de->next) {
1357 if (proc_match(len, table->procname, de))
1360 /* If the subdir exists already, de is non-NULL */
1364 de = create_proc_entry(table->procname, mode, root);
1368 de->data = (void *) table;
1369 if (table->proc_handler)
1370 de->proc_fops = &proc_sys_file_operations;
1373 if (de->mode & S_IFDIR)
1374 register_proc_table(table->child, de, set);
1379 * Unregister a /proc sysctl table and any subdirectories.
1381 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1383 struct proc_dir_entry *de;
1384 for (; table->ctl_name; table++) {
1385 if (!(de = table->de))
1387 if (de->mode & S_IFDIR) {
1388 if (!table->child) {
1389 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1392 unregister_proc_table(table->child, de);
1394 /* Don't unregister directories which still have entries.. */
1400 * In any case, mark the entry as goner; we'll keep it
1401 * around if it's busy, but we'll know to do nothing with
1402 * its fields. We are under sysctl_lock here.
1406 /* Don't unregister proc entries that are still being used.. */
1407 if (atomic_read(&de->count))
1411 remove_proc_entry(table->procname, root);
1415 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1416 size_t count, loff_t *ppos)
1419 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1420 struct ctl_table *table;
1422 ssize_t error = -ENOTDIR;
1424 spin_lock(&sysctl_lock);
1425 if (de && de->data && use_table(de->set)) {
1427 * at that point we know that sysctl was not unregistered
1428 * and won't be until we finish
1430 spin_unlock(&sysctl_lock);
1431 table = (struct ctl_table *) de->data;
1432 if (!table || !table->proc_handler)
1435 op = (write ? 002 : 004);
1436 if (ctl_perm(table, op))
1439 /* careful: calling conventions are nasty here */
1441 error = (*table->proc_handler)(table, write, file,
1446 spin_lock(&sysctl_lock);
1447 unuse_table(de->set);
1449 spin_unlock(&sysctl_lock);
1453 static int proc_opensys(struct inode *inode, struct file *file)
1455 if (file->f_mode & FMODE_WRITE) {
1457 * sysctl entries that are not writable,
1458 * are _NOT_ writable, capabilities or not.
1460 if (!(inode->i_mode & S_IWUSR))
1467 static ssize_t proc_readsys(struct file * file, char __user * buf,
1468 size_t count, loff_t *ppos)
1470 return do_rw_proc(0, file, buf, count, ppos);
1473 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1474 size_t count, loff_t *ppos)
1476 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1480 * proc_dostring - read a string sysctl
1481 * @table: the sysctl table
1482 * @write: %TRUE if this is a write to the sysctl file
1483 * @filp: the file structure
1484 * @buffer: the user buffer
1485 * @lenp: the size of the user buffer
1486 * @ppos: file position
1488 * Reads/writes a string from/to the user buffer. If the kernel
1489 * buffer provided is not large enough to hold the string, the
1490 * string is truncated. The copied string is %NULL-terminated.
1491 * If the string is being read by the user process, it is copied
1492 * and a newline '\n' is added. It is truncated if the buffer is
1495 * Returns 0 on success.
1497 int proc_dostring(ctl_table *table, int write, struct file *filp,
1498 void __user *buffer, size_t *lenp, loff_t *ppos)
1504 if (!table->data || !table->maxlen || !*lenp ||
1505 (*ppos && !write)) {
1513 while (len < *lenp) {
1514 if (get_user(c, p++))
1516 if (c == 0 || c == '\n')
1520 if (len >= table->maxlen)
1521 len = table->maxlen-1;
1522 if(copy_from_user(table->data, buffer, len))
1524 ((char *) table->data)[len] = 0;
1527 len = strlen(table->data);
1528 if (len > table->maxlen)
1529 len = table->maxlen;
1533 if(copy_to_user(buffer, table->data, len))
1536 if(put_user('\n', ((char __user *) buffer) + len))
1547 * Special case of dostring for the UTS structure. This has locks
1548 * to observe. Should this be in kernel/sys.c ????
1551 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1552 void __user *buffer, size_t *lenp, loff_t *ppos)
1557 down_read(&uts_sem);
1558 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1561 down_write(&uts_sem);
1562 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1568 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1570 int write, void *data)
1573 *valp = *negp ? -*lvalp : *lvalp;
1578 *lvalp = (unsigned long)-val;
1581 *lvalp = (unsigned long)val;
1587 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1588 void __user *buffer, size_t *lenp, loff_t *ppos,
1589 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1590 int write, void *data),
1593 #define TMPBUFLEN 21
1594 int *i, vleft, first=1, neg, val;
1598 char buf[TMPBUFLEN], *p;
1599 char __user *s = buffer;
1601 if (!table->data || !table->maxlen || !*lenp ||
1602 (*ppos && !write)) {
1607 i = (int *) table->data;
1608 vleft = table->maxlen / sizeof(*i);
1612 conv = do_proc_dointvec_conv;
1614 for (; left && vleft--; i++, first=0) {
1629 if (len > sizeof(buf) - 1)
1630 len = sizeof(buf) - 1;
1631 if (copy_from_user(buf, s, len))
1635 if (*p == '-' && left > 1) {
1639 if (*p < '0' || *p > '9')
1642 lval = simple_strtoul(p, &p, 0);
1645 if ((len < left) && *p && !isspace(*p))
1652 if (conv(&neg, &lval, i, 1, data))
1659 if (conv(&neg, &lval, i, 0, data))
1662 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1666 if(copy_to_user(s, buf, len))
1673 if (!write && !first && left) {
1674 if(put_user('\n', s))
1681 if (get_user(c, s++))
1697 * proc_dointvec - read a vector of integers
1698 * @table: the sysctl table
1699 * @write: %TRUE if this is a write to the sysctl file
1700 * @filp: the file structure
1701 * @buffer: the user buffer
1702 * @lenp: the size of the user buffer
1703 * @ppos: file position
1705 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1706 * values from/to the user buffer, treated as an ASCII string.
1708 * Returns 0 on success.
1710 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1711 void __user *buffer, size_t *lenp, loff_t *ppos)
1713 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1723 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1725 int write, void *data)
1727 int op = *(int *)data;
1729 int val = *negp ? -*lvalp : *lvalp;
1731 case OP_SET: *valp = val; break;
1732 case OP_AND: *valp &= val; break;
1733 case OP_OR: *valp |= val; break;
1734 case OP_MAX: if(*valp < val)
1737 case OP_MIN: if(*valp > val)
1745 *lvalp = (unsigned long)-val;
1748 *lvalp = (unsigned long)val;
1755 * init may raise the set.
1758 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1759 void __user *buffer, size_t *lenp, loff_t *ppos)
1763 if (!capable(CAP_SYS_MODULE)) {
1767 op = (current->pid == 1) ? OP_SET : OP_AND;
1768 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1769 do_proc_dointvec_bset_conv,&op);
1772 struct do_proc_dointvec_minmax_conv_param {
1777 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1779 int write, void *data)
1781 struct do_proc_dointvec_minmax_conv_param *param = data;
1783 int val = *negp ? -*lvalp : *lvalp;
1784 if ((param->min && *param->min > val) ||
1785 (param->max && *param->max < val))
1792 *lvalp = (unsigned long)-val;
1795 *lvalp = (unsigned long)val;
1802 * proc_dointvec_minmax - read a vector of integers with min/max values
1803 * @table: the sysctl table
1804 * @write: %TRUE if this is a write to the sysctl file
1805 * @filp: the file structure
1806 * @buffer: the user buffer
1807 * @lenp: the size of the user buffer
1808 * @ppos: file position
1810 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1811 * values from/to the user buffer, treated as an ASCII string.
1813 * This routine will ensure the values are within the range specified by
1814 * table->extra1 (min) and table->extra2 (max).
1816 * Returns 0 on success.
1818 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1819 void __user *buffer, size_t *lenp, loff_t *ppos)
1821 struct do_proc_dointvec_minmax_conv_param param = {
1822 .min = (int *) table->extra1,
1823 .max = (int *) table->extra2,
1825 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1826 do_proc_dointvec_minmax_conv, ¶m);
1829 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1831 void __user *buffer,
1832 size_t *lenp, loff_t *ppos,
1833 unsigned long convmul,
1834 unsigned long convdiv)
1836 #define TMPBUFLEN 21
1837 unsigned long *i, *min, *max, val;
1838 int vleft, first=1, neg;
1840 char buf[TMPBUFLEN], *p;
1841 char __user *s = buffer;
1843 if (!table->data || !table->maxlen || !*lenp ||
1844 (*ppos && !write)) {
1849 i = (unsigned long *) table->data;
1850 min = (unsigned long *) table->extra1;
1851 max = (unsigned long *) table->extra2;
1852 vleft = table->maxlen / sizeof(unsigned long);
1855 for (; left && vleft--; i++, min++, max++, first=0) {
1870 if (len > TMPBUFLEN-1)
1872 if (copy_from_user(buf, s, len))
1876 if (*p == '-' && left > 1) {
1880 if (*p < '0' || *p > '9')
1882 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1884 if ((len < left) && *p && !isspace(*p))
1893 if ((min && val < *min) || (max && val > *max))
1900 sprintf(p, "%lu", convdiv * (*i) / convmul);
1904 if(copy_to_user(s, buf, len))
1911 if (!write && !first && left) {
1912 if(put_user('\n', s))
1919 if (get_user(c, s++))
1935 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1936 * @table: the sysctl table
1937 * @write: %TRUE if this is a write to the sysctl file
1938 * @filp: the file structure
1939 * @buffer: the user buffer
1940 * @lenp: the size of the user buffer
1941 * @ppos: file position
1943 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1944 * values from/to the user buffer, treated as an ASCII string.
1946 * This routine will ensure the values are within the range specified by
1947 * table->extra1 (min) and table->extra2 (max).
1949 * Returns 0 on success.
1951 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1952 void __user *buffer, size_t *lenp, loff_t *ppos)
1954 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1958 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1959 * @table: the sysctl table
1960 * @write: %TRUE if this is a write to the sysctl file
1961 * @filp: the file structure
1962 * @buffer: the user buffer
1963 * @lenp: the size of the user buffer
1964 * @ppos: file position
1966 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1967 * values from/to the user buffer, treated as an ASCII string. The values
1968 * are treated as milliseconds, and converted to jiffies when they are stored.
1970 * This routine will ensure the values are within the range specified by
1971 * table->extra1 (min) and table->extra2 (max).
1973 * Returns 0 on success.
1975 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1977 void __user *buffer,
1978 size_t *lenp, loff_t *ppos)
1980 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1981 lenp, ppos, HZ, 1000l);
1985 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1987 int write, void *data)
1990 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1996 lval = (unsigned long)-val;
1999 lval = (unsigned long)val;
2006 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2008 int write, void *data)
2011 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2017 lval = (unsigned long)-val;
2020 lval = (unsigned long)val;
2022 *lvalp = jiffies_to_clock_t(lval);
2027 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2029 int write, void *data)
2032 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2038 lval = (unsigned long)-val;
2041 lval = (unsigned long)val;
2043 *lvalp = jiffies_to_msecs(lval);
2049 * proc_dointvec_jiffies - read a vector of integers as seconds
2050 * @table: the sysctl table
2051 * @write: %TRUE if this is a write to the sysctl file
2052 * @filp: the file structure
2053 * @buffer: the user buffer
2054 * @lenp: the size of the user buffer
2055 * @ppos: file position
2057 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2058 * values from/to the user buffer, treated as an ASCII string.
2059 * The values read are assumed to be in seconds, and are converted into
2062 * Returns 0 on success.
2064 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2065 void __user *buffer, size_t *lenp, loff_t *ppos)
2067 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2068 do_proc_dointvec_jiffies_conv,NULL);
2072 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2073 * @table: the sysctl table
2074 * @write: %TRUE if this is a write to the sysctl file
2075 * @filp: the file structure
2076 * @buffer: the user buffer
2077 * @lenp: the size of the user buffer
2078 * @ppos: pointer to the file position
2080 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2081 * values from/to the user buffer, treated as an ASCII string.
2082 * The values read are assumed to be in 1/USER_HZ seconds, and
2083 * are converted into jiffies.
2085 * Returns 0 on success.
2087 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2088 void __user *buffer, size_t *lenp, loff_t *ppos)
2090 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2091 do_proc_dointvec_userhz_jiffies_conv,NULL);
2095 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2096 * @table: the sysctl table
2097 * @write: %TRUE if this is a write to the sysctl file
2098 * @filp: the file structure
2099 * @buffer: the user buffer
2100 * @lenp: the size of the user buffer
2101 * @ppos: file position
2102 * @ppos: the current position in the file
2104 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2105 * values from/to the user buffer, treated as an ASCII string.
2106 * The values read are assumed to be in 1/1000 seconds, and
2107 * are converted into jiffies.
2109 * Returns 0 on success.
2111 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2112 void __user *buffer, size_t *lenp, loff_t *ppos)
2114 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2115 do_proc_dointvec_ms_jiffies_conv, NULL);
2118 #else /* CONFIG_PROC_FS */
2120 int proc_dostring(ctl_table *table, int write, struct file *filp,
2121 void __user *buffer, size_t *lenp, loff_t *ppos)
2126 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2127 void __user *buffer, size_t *lenp, loff_t *ppos)
2132 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2133 void __user *buffer, size_t *lenp, loff_t *ppos)
2138 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2139 void __user *buffer, size_t *lenp, loff_t *ppos)
2144 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2145 void __user *buffer, size_t *lenp, loff_t *ppos)
2150 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2151 void __user *buffer, size_t *lenp, loff_t *ppos)
2156 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2157 void __user *buffer, size_t *lenp, loff_t *ppos)
2162 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2163 void __user *buffer, size_t *lenp, loff_t *ppos)
2168 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2169 void __user *buffer, size_t *lenp, loff_t *ppos)
2174 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2176 void __user *buffer,
2177 size_t *lenp, loff_t *ppos)
2183 #endif /* CONFIG_PROC_FS */
2187 * General sysctl support routines
2190 /* The generic string strategy routine: */
2191 int sysctl_string(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)
2195 if (!table->data || !table->maxlen)
2198 if (oldval && oldlenp) {
2200 if (get_user(bufsize, oldlenp))
2203 size_t len = strlen(table->data), copied;
2205 /* This shouldn't trigger for a well-formed sysctl */
2206 if (len > table->maxlen)
2207 len = table->maxlen;
2209 /* Copy up to a max of bufsize-1 bytes of the string */
2210 copied = (len >= bufsize) ? bufsize - 1 : len;
2212 if (copy_to_user(oldval, table->data, copied) ||
2213 put_user(0, (char __user *)(oldval + copied)))
2215 if (put_user(len, oldlenp))
2219 if (newval && newlen) {
2220 size_t len = newlen;
2221 if (len > table->maxlen)
2222 len = table->maxlen;
2223 if(copy_from_user(table->data, newval, len))
2225 if (len == table->maxlen)
2227 ((char *) table->data)[len] = 0;
2233 * This function makes sure that all of the integers in the vector
2234 * are between the minimum and maximum values given in the arrays
2235 * table->extra1 and table->extra2, respectively.
2237 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2238 void __user *oldval, size_t __user *oldlenp,
2239 void __user *newval, size_t newlen, void **context)
2242 if (newval && newlen) {
2243 int __user *vec = (int __user *) newval;
2244 int *min = (int *) table->extra1;
2245 int *max = (int *) table->extra2;
2249 if (newlen % sizeof(int) != 0)
2252 if (!table->extra1 && !table->extra2)
2255 if (newlen > table->maxlen)
2256 newlen = table->maxlen;
2257 length = newlen / sizeof(int);
2259 for (i = 0; i < length; i++) {
2261 if (get_user(value, vec + i))
2263 if (min && value < min[i])
2265 if (max && value > max[i])
2272 /* Strategy function to convert jiffies to seconds */
2273 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2274 void __user *oldval, size_t __user *oldlenp,
2275 void __user *newval, size_t newlen, void **context)
2280 if (get_user(olen, oldlenp))
2282 if (olen!=sizeof(int))
2285 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2286 (oldlenp && put_user(sizeof(int),oldlenp)))
2289 if (newval && newlen) {
2291 if (newlen != sizeof(int))
2293 if (get_user(new, (int __user *)newval))
2295 *(int *)(table->data) = new*HZ;
2300 /* Strategy function to convert jiffies to seconds */
2301 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2302 void __user *oldval, size_t __user *oldlenp,
2303 void __user *newval, size_t newlen, void **context)
2308 if (get_user(olen, oldlenp))
2310 if (olen!=sizeof(int))
2313 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2314 (oldlenp && put_user(sizeof(int),oldlenp)))
2317 if (newval && newlen) {
2319 if (newlen != sizeof(int))
2321 if (get_user(new, (int __user *)newval))
2323 *(int *)(table->data) = msecs_to_jiffies(new);
2328 #else /* CONFIG_SYSCTL */
2331 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2336 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2337 void __user *oldval, size_t __user *oldlenp,
2338 void __user *newval, size_t newlen, void **context)
2343 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2344 void __user *oldval, size_t __user *oldlenp,
2345 void __user *newval, size_t newlen, void **context)
2350 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2351 void __user *oldval, size_t __user *oldlenp,
2352 void __user *newval, size_t newlen, void **context)
2357 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2358 void __user *oldval, size_t __user *oldlenp,
2359 void __user *newval, size_t newlen, void **context)
2364 int proc_dostring(ctl_table *table, int write, struct file *filp,
2365 void __user *buffer, size_t *lenp, loff_t *ppos)
2370 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2371 void __user *buffer, size_t *lenp, loff_t *ppos)
2376 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2377 void __user *buffer, size_t *lenp, loff_t *ppos)
2382 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2383 void __user *buffer, size_t *lenp, loff_t *ppos)
2388 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2389 void __user *buffer, size_t *lenp, loff_t *ppos)
2394 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2395 void __user *buffer, size_t *lenp, loff_t *ppos)
2400 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2401 void __user *buffer, size_t *lenp, loff_t *ppos)
2406 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2407 void __user *buffer, size_t *lenp, loff_t *ppos)
2412 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2414 void __user *buffer,
2415 size_t *lenp, loff_t *ppos)
2420 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2426 void unregister_sysctl_table(struct ctl_table_header * table)
2430 #endif /* CONFIG_SYSCTL */
2433 * No sense putting this after each symbol definition, twice,
2434 * exception granted :-)
2436 EXPORT_SYMBOL(proc_dointvec);
2437 EXPORT_SYMBOL(proc_dointvec_jiffies);
2438 EXPORT_SYMBOL(proc_dointvec_minmax);
2439 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2440 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2441 EXPORT_SYMBOL(proc_dostring);
2442 EXPORT_SYMBOL(proc_doulongvec_minmax);
2443 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2444 EXPORT_SYMBOL(register_sysctl_table);
2445 EXPORT_SYMBOL(sysctl_intvec);
2446 EXPORT_SYMBOL(sysctl_jiffies);
2447 EXPORT_SYMBOL(sysctl_ms_jiffies);
2448 EXPORT_SYMBOL(sysctl_string);
2449 EXPORT_SYMBOL(unregister_sysctl_table);