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/capability.h>
29 #include <linux/ctype.h>
30 #include <linux/utsname.h>
31 #include <linux/capability.h>
32 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/security.h>
42 #include <linux/initrd.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
48 #include <asm/uaccess.h>
49 #include <asm/processor.h>
51 #ifdef CONFIG_ROOT_NFS
52 #include <linux/nfs_fs.h>
55 #if defined(CONFIG_SYSCTL)
57 /* External variables not in a header file. */
59 extern int sysctl_overcommit_memory;
60 extern int sysctl_overcommit_ratio;
61 extern int max_threads;
62 extern int sysrq_enabled;
63 extern int core_uses_pid;
64 extern int suid_dumpable;
65 extern char core_pattern[];
68 extern int min_free_kbytes;
69 extern int printk_ratelimit_jiffies;
70 extern int printk_ratelimit_burst;
71 extern int pid_max_min, pid_max_max;
72 extern int sysctl_drop_caches;
73 extern int percpu_pagelist_fraction;
75 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
76 int unknown_nmi_panic;
77 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
78 void __user *, size_t *, loff_t *);
81 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
82 static int maxolduid = 65535;
84 static int min_percpu_pagelist_fract = 8;
86 static int ngroups_max = NGROUPS_MAX;
89 extern char modprobe_path[];
91 #ifdef CONFIG_CHR_DEV_SG
92 extern int sg_big_buff;
95 extern size_t shm_ctlmax;
96 extern size_t shm_ctlall;
97 extern int shm_ctlmni;
98 extern int msg_ctlmax;
99 extern int msg_ctlmnb;
100 extern int msg_ctlmni;
101 extern int sem_ctls[];
105 extern char reboot_command [];
106 extern int stop_a_enabled;
107 extern int scons_pwroff;
111 extern int pwrsw_enabled;
112 extern int unaligned_enabled;
116 #ifdef CONFIG_MATHEMU
117 extern int sysctl_ieee_emulation_warnings;
119 extern int sysctl_userprocess_debug;
120 extern int spin_retry;
123 extern int sysctl_hz_timer;
125 #ifdef CONFIG_BSD_PROCESS_ACCT
126 extern int acct_parm[];
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 = &uevent_helper,
401 .maxlen = UEVENT_HELPER_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,
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_S390) && defined(CONFIG_SMP)
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_DROP_PAGECACHE,
781 .procname = "drop_caches",
782 .data = &sysctl_drop_caches,
783 .maxlen = sizeof(int),
785 .proc_handler = drop_caches_sysctl_handler,
786 .strategy = &sysctl_intvec,
789 .ctl_name = VM_MIN_FREE_KBYTES,
790 .procname = "min_free_kbytes",
791 .data = &min_free_kbytes,
792 .maxlen = sizeof(min_free_kbytes),
794 .proc_handler = &min_free_kbytes_sysctl_handler,
795 .strategy = &sysctl_intvec,
799 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
800 .procname = "percpu_pagelist_fraction",
801 .data = &percpu_pagelist_fraction,
802 .maxlen = sizeof(percpu_pagelist_fraction),
804 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
805 .strategy = &sysctl_intvec,
806 .extra1 = &min_percpu_pagelist_fract,
810 .ctl_name = VM_MAX_MAP_COUNT,
811 .procname = "max_map_count",
812 .data = &sysctl_max_map_count,
813 .maxlen = sizeof(sysctl_max_map_count),
815 .proc_handler = &proc_dointvec
819 .ctl_name = VM_LAPTOP_MODE,
820 .procname = "laptop_mode",
821 .data = &laptop_mode,
822 .maxlen = sizeof(laptop_mode),
824 .proc_handler = &proc_dointvec,
825 .strategy = &sysctl_intvec,
829 .ctl_name = VM_BLOCK_DUMP,
830 .procname = "block_dump",
832 .maxlen = sizeof(block_dump),
834 .proc_handler = &proc_dointvec,
835 .strategy = &sysctl_intvec,
839 .ctl_name = VM_VFS_CACHE_PRESSURE,
840 .procname = "vfs_cache_pressure",
841 .data = &sysctl_vfs_cache_pressure,
842 .maxlen = sizeof(sysctl_vfs_cache_pressure),
844 .proc_handler = &proc_dointvec,
845 .strategy = &sysctl_intvec,
848 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
850 .ctl_name = VM_LEGACY_VA_LAYOUT,
851 .procname = "legacy_va_layout",
852 .data = &sysctl_legacy_va_layout,
853 .maxlen = sizeof(sysctl_legacy_va_layout),
855 .proc_handler = &proc_dointvec,
856 .strategy = &sysctl_intvec,
862 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
863 .procname = "swap_token_timeout",
864 .data = &swap_token_default_timeout,
865 .maxlen = sizeof(swap_token_default_timeout),
867 .proc_handler = &proc_dointvec_jiffies,
868 .strategy = &sysctl_jiffies,
873 .ctl_name = VM_ZONE_RECLAIM_MODE,
874 .procname = "zone_reclaim_mode",
875 .data = &zone_reclaim_mode,
876 .maxlen = sizeof(zone_reclaim_mode),
878 .proc_handler = &proc_dointvec,
879 .strategy = &sysctl_intvec,
883 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
884 .procname = "zone_reclaim_interval",
885 .data = &zone_reclaim_interval,
886 .maxlen = sizeof(zone_reclaim_interval),
888 .proc_handler = &proc_dointvec_jiffies,
889 .strategy = &sysctl_jiffies,
895 static ctl_table proc_table[] = {
899 static ctl_table fs_table[] = {
901 .ctl_name = FS_NRINODE,
902 .procname = "inode-nr",
903 .data = &inodes_stat,
904 .maxlen = 2*sizeof(int),
906 .proc_handler = &proc_dointvec,
909 .ctl_name = FS_STATINODE,
910 .procname = "inode-state",
911 .data = &inodes_stat,
912 .maxlen = 7*sizeof(int),
914 .proc_handler = &proc_dointvec,
917 .ctl_name = FS_NRFILE,
918 .procname = "file-nr",
920 .maxlen = 3*sizeof(int),
922 .proc_handler = &proc_dointvec,
925 .ctl_name = FS_MAXFILE,
926 .procname = "file-max",
927 .data = &files_stat.max_files,
928 .maxlen = sizeof(int),
930 .proc_handler = &proc_dointvec,
933 .ctl_name = FS_DENTRY,
934 .procname = "dentry-state",
935 .data = &dentry_stat,
936 .maxlen = 6*sizeof(int),
938 .proc_handler = &proc_dointvec,
941 .ctl_name = FS_OVERFLOWUID,
942 .procname = "overflowuid",
943 .data = &fs_overflowuid,
944 .maxlen = sizeof(int),
946 .proc_handler = &proc_dointvec_minmax,
947 .strategy = &sysctl_intvec,
948 .extra1 = &minolduid,
949 .extra2 = &maxolduid,
952 .ctl_name = FS_OVERFLOWGID,
953 .procname = "overflowgid",
954 .data = &fs_overflowgid,
955 .maxlen = sizeof(int),
957 .proc_handler = &proc_dointvec_minmax,
958 .strategy = &sysctl_intvec,
959 .extra1 = &minolduid,
960 .extra2 = &maxolduid,
963 .ctl_name = FS_LEASES,
964 .procname = "leases-enable",
965 .data = &leases_enable,
966 .maxlen = sizeof(int),
968 .proc_handler = &proc_dointvec,
970 #ifdef CONFIG_DNOTIFY
972 .ctl_name = FS_DIR_NOTIFY,
973 .procname = "dir-notify-enable",
974 .data = &dir_notify_enable,
975 .maxlen = sizeof(int),
977 .proc_handler = &proc_dointvec,
982 .ctl_name = FS_LEASE_TIME,
983 .procname = "lease-break-time",
984 .data = &lease_break_time,
985 .maxlen = sizeof(int),
987 .proc_handler = &proc_dointvec,
990 .ctl_name = FS_AIO_NR,
991 .procname = "aio-nr",
993 .maxlen = sizeof(aio_nr),
995 .proc_handler = &proc_doulongvec_minmax,
998 .ctl_name = FS_AIO_MAX_NR,
999 .procname = "aio-max-nr",
1000 .data = &aio_max_nr,
1001 .maxlen = sizeof(aio_max_nr),
1003 .proc_handler = &proc_doulongvec_minmax,
1005 #ifdef CONFIG_INOTIFY
1007 .ctl_name = FS_INOTIFY,
1008 .procname = "inotify",
1010 .child = inotify_table,
1015 .ctl_name = KERN_SETUID_DUMPABLE,
1016 .procname = "suid_dumpable",
1017 .data = &suid_dumpable,
1018 .maxlen = sizeof(int),
1020 .proc_handler = &proc_dointvec,
1025 static ctl_table debug_table[] = {
1029 static ctl_table dev_table[] = {
1033 extern void init_irq_proc (void);
1035 static DEFINE_SPINLOCK(sysctl_lock);
1037 /* called under sysctl_lock */
1038 static int use_table(struct ctl_table_header *p)
1040 if (unlikely(p->unregistering))
1046 /* called under sysctl_lock */
1047 static void unuse_table(struct ctl_table_header *p)
1050 if (unlikely(p->unregistering))
1051 complete(p->unregistering);
1054 /* called under sysctl_lock, will reacquire if has to wait */
1055 static void start_unregistering(struct ctl_table_header *p)
1058 * if p->used is 0, nobody will ever touch that entry again;
1059 * we'll eliminate all paths to it before dropping sysctl_lock
1061 if (unlikely(p->used)) {
1062 struct completion wait;
1063 init_completion(&wait);
1064 p->unregistering = &wait;
1065 spin_unlock(&sysctl_lock);
1066 wait_for_completion(&wait);
1067 spin_lock(&sysctl_lock);
1070 * do not remove from the list until nobody holds it; walking the
1071 * list in do_sysctl() relies on that.
1073 list_del_init(&p->ctl_entry);
1076 void __init sysctl_init(void)
1078 #ifdef CONFIG_PROC_FS
1079 register_proc_table(root_table, proc_sys_root, &root_table_header);
1084 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1085 void __user *newval, size_t newlen)
1087 struct list_head *tmp;
1088 int error = -ENOTDIR;
1090 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1094 if (!oldlenp || get_user(old_len, oldlenp))
1097 spin_lock(&sysctl_lock);
1098 tmp = &root_table_header.ctl_entry;
1100 struct ctl_table_header *head =
1101 list_entry(tmp, struct ctl_table_header, ctl_entry);
1102 void *context = NULL;
1104 if (!use_table(head))
1107 spin_unlock(&sysctl_lock);
1109 error = parse_table(name, nlen, oldval, oldlenp,
1110 newval, newlen, head->ctl_table,
1114 spin_lock(&sysctl_lock);
1116 if (error != -ENOTDIR)
1118 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1119 spin_unlock(&sysctl_lock);
1123 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1125 struct __sysctl_args tmp;
1128 if (copy_from_user(&tmp, args, sizeof(tmp)))
1132 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1133 tmp.newval, tmp.newlen);
1139 * ctl_perm does NOT grant the superuser all rights automatically, because
1140 * some sysctl variables are readonly even to root.
1143 static int test_perm(int mode, int op)
1147 else if (in_egroup_p(0))
1149 if ((mode & op & 0007) == op)
1154 static inline int ctl_perm(ctl_table *table, int op)
1157 error = security_sysctl(table, op);
1160 return test_perm(table->mode, op);
1163 static int parse_table(int __user *name, int nlen,
1164 void __user *oldval, size_t __user *oldlenp,
1165 void __user *newval, size_t newlen,
1166 ctl_table *table, void **context)
1172 if (get_user(n, name))
1174 for ( ; table->ctl_name; table++) {
1175 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1178 if (ctl_perm(table, 001))
1180 if (table->strategy) {
1181 error = table->strategy(
1184 newval, newlen, context);
1190 table = table->child;
1193 error = do_sysctl_strategy(table, name, nlen,
1195 newval, newlen, context);
1202 /* Perform the actual read/write of a sysctl table entry. */
1203 int do_sysctl_strategy (ctl_table *table,
1204 int __user *name, int nlen,
1205 void __user *oldval, size_t __user *oldlenp,
1206 void __user *newval, size_t newlen, void **context)
1215 if (ctl_perm(table, op))
1218 if (table->strategy) {
1219 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1220 newval, newlen, context);
1227 /* If there is no strategy routine, or if the strategy returns
1228 * zero, proceed with automatic r/w */
1229 if (table->data && table->maxlen) {
1230 if (oldval && oldlenp) {
1231 if (get_user(len, oldlenp))
1234 if (len > table->maxlen)
1235 len = table->maxlen;
1236 if(copy_to_user(oldval, table->data, len))
1238 if(put_user(len, oldlenp))
1242 if (newval && newlen) {
1244 if (len > table->maxlen)
1245 len = table->maxlen;
1246 if(copy_from_user(table->data, newval, len))
1254 * register_sysctl_table - register a sysctl hierarchy
1255 * @table: the top-level table structure
1256 * @insert_at_head: whether the entry should be inserted in front or at the end
1258 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1259 * array. An entry with a ctl_name of 0 terminates the table.
1261 * The members of the &ctl_table structure are used as follows:
1263 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1264 * must be unique within that level of sysctl
1266 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1267 * enter a sysctl file
1269 * data - a pointer to data for use by proc_handler
1271 * maxlen - the maximum size in bytes of the data
1273 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1275 * child - a pointer to the child sysctl table if this entry is a directory, or
1278 * proc_handler - the text handler routine (described below)
1280 * strategy - the strategy routine (described below)
1282 * de - for internal use by the sysctl routines
1284 * extra1, extra2 - extra pointers usable by the proc handler routines
1286 * Leaf nodes in the sysctl tree will be represented by a single file
1287 * under /proc; non-leaf nodes will be represented by directories.
1289 * sysctl(2) can automatically manage read and write requests through
1290 * the sysctl table. The data and maxlen fields of the ctl_table
1291 * struct enable minimal validation of the values being written to be
1292 * performed, and the mode field allows minimal authentication.
1294 * More sophisticated management can be enabled by the provision of a
1295 * strategy routine with the table entry. This will be called before
1296 * any automatic read or write of the data is performed.
1298 * The strategy routine may return
1300 * < 0 - Error occurred (error is passed to user process)
1302 * 0 - OK - proceed with automatic read or write.
1304 * > 0 - OK - read or write has been done by the strategy routine, so
1305 * return immediately.
1307 * There must be a proc_handler routine for any terminal nodes
1308 * mirrored under /proc/sys (non-terminals are handled by a built-in
1309 * directory handler). Several default handlers are available to
1310 * cover common cases -
1312 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1313 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1314 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1316 * It is the handler's job to read the input buffer from user memory
1317 * and process it. The handler should return 0 on success.
1319 * This routine returns %NULL on a failure to register, and a pointer
1320 * to the table header on success.
1322 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1325 struct ctl_table_header *tmp;
1326 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1329 tmp->ctl_table = table;
1330 INIT_LIST_HEAD(&tmp->ctl_entry);
1332 tmp->unregistering = NULL;
1333 spin_lock(&sysctl_lock);
1335 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1337 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1338 spin_unlock(&sysctl_lock);
1339 #ifdef CONFIG_PROC_FS
1340 register_proc_table(table, proc_sys_root, tmp);
1346 * unregister_sysctl_table - unregister a sysctl table hierarchy
1347 * @header: the header returned from register_sysctl_table
1349 * Unregisters the sysctl table and all children. proc entries may not
1350 * actually be removed until they are no longer used by anyone.
1352 void unregister_sysctl_table(struct ctl_table_header * header)
1355 spin_lock(&sysctl_lock);
1356 start_unregistering(header);
1357 #ifdef CONFIG_PROC_FS
1358 unregister_proc_table(header->ctl_table, proc_sys_root);
1360 spin_unlock(&sysctl_lock);
1368 #ifdef CONFIG_PROC_FS
1370 /* Scan the sysctl entries in table and add them all into /proc */
1371 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1373 struct proc_dir_entry *de;
1377 for (; table->ctl_name; table++) {
1378 /* Can't do anything without a proc name. */
1379 if (!table->procname)
1381 /* Maybe we can't do anything with it... */
1382 if (!table->proc_handler && !table->child) {
1383 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1388 len = strlen(table->procname);
1392 if (table->proc_handler)
1396 for (de = root->subdir; de; de = de->next) {
1397 if (proc_match(len, table->procname, de))
1400 /* If the subdir exists already, de is non-NULL */
1404 de = create_proc_entry(table->procname, mode, root);
1408 de->data = (void *) table;
1409 if (table->proc_handler)
1410 de->proc_fops = &proc_sys_file_operations;
1413 if (de->mode & S_IFDIR)
1414 register_proc_table(table->child, de, set);
1419 * Unregister a /proc sysctl table and any subdirectories.
1421 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1423 struct proc_dir_entry *de;
1424 for (; table->ctl_name; table++) {
1425 if (!(de = table->de))
1427 if (de->mode & S_IFDIR) {
1428 if (!table->child) {
1429 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1432 unregister_proc_table(table->child, de);
1434 /* Don't unregister directories which still have entries.. */
1440 * In any case, mark the entry as goner; we'll keep it
1441 * around if it's busy, but we'll know to do nothing with
1442 * its fields. We are under sysctl_lock here.
1446 /* Don't unregister proc entries that are still being used.. */
1447 if (atomic_read(&de->count))
1451 remove_proc_entry(table->procname, root);
1455 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1456 size_t count, loff_t *ppos)
1459 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1460 struct ctl_table *table;
1462 ssize_t error = -ENOTDIR;
1464 spin_lock(&sysctl_lock);
1465 if (de && de->data && use_table(de->set)) {
1467 * at that point we know that sysctl was not unregistered
1468 * and won't be until we finish
1470 spin_unlock(&sysctl_lock);
1471 table = (struct ctl_table *) de->data;
1472 if (!table || !table->proc_handler)
1475 op = (write ? 002 : 004);
1476 if (ctl_perm(table, op))
1479 /* careful: calling conventions are nasty here */
1481 error = (*table->proc_handler)(table, write, file,
1486 spin_lock(&sysctl_lock);
1487 unuse_table(de->set);
1489 spin_unlock(&sysctl_lock);
1493 static int proc_opensys(struct inode *inode, struct file *file)
1495 if (file->f_mode & FMODE_WRITE) {
1497 * sysctl entries that are not writable,
1498 * are _NOT_ writable, capabilities or not.
1500 if (!(inode->i_mode & S_IWUSR))
1507 static ssize_t proc_readsys(struct file * file, char __user * buf,
1508 size_t count, loff_t *ppos)
1510 return do_rw_proc(0, file, buf, count, ppos);
1513 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1514 size_t count, loff_t *ppos)
1516 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1520 * proc_dostring - read a string sysctl
1521 * @table: the sysctl table
1522 * @write: %TRUE if this is a write to the sysctl file
1523 * @filp: the file structure
1524 * @buffer: the user buffer
1525 * @lenp: the size of the user buffer
1526 * @ppos: file position
1528 * Reads/writes a string from/to the user buffer. If the kernel
1529 * buffer provided is not large enough to hold the string, the
1530 * string is truncated. The copied string is %NULL-terminated.
1531 * If the string is being read by the user process, it is copied
1532 * and a newline '\n' is added. It is truncated if the buffer is
1535 * Returns 0 on success.
1537 int proc_dostring(ctl_table *table, int write, struct file *filp,
1538 void __user *buffer, size_t *lenp, loff_t *ppos)
1544 if (!table->data || !table->maxlen || !*lenp ||
1545 (*ppos && !write)) {
1553 while (len < *lenp) {
1554 if (get_user(c, p++))
1556 if (c == 0 || c == '\n')
1560 if (len >= table->maxlen)
1561 len = table->maxlen-1;
1562 if(copy_from_user(table->data, buffer, len))
1564 ((char *) table->data)[len] = 0;
1567 len = strlen(table->data);
1568 if (len > table->maxlen)
1569 len = table->maxlen;
1573 if(copy_to_user(buffer, table->data, len))
1576 if(put_user('\n', ((char __user *) buffer) + len))
1587 * Special case of dostring for the UTS structure. This has locks
1588 * to observe. Should this be in kernel/sys.c ????
1591 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1592 void __user *buffer, size_t *lenp, loff_t *ppos)
1597 down_read(&uts_sem);
1598 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1601 down_write(&uts_sem);
1602 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1608 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1610 int write, void *data)
1613 *valp = *negp ? -*lvalp : *lvalp;
1618 *lvalp = (unsigned long)-val;
1621 *lvalp = (unsigned long)val;
1627 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1628 void __user *buffer, size_t *lenp, loff_t *ppos,
1629 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1630 int write, void *data),
1633 #define TMPBUFLEN 21
1634 int *i, vleft, first=1, neg, val;
1638 char buf[TMPBUFLEN], *p;
1639 char __user *s = buffer;
1641 if (!table->data || !table->maxlen || !*lenp ||
1642 (*ppos && !write)) {
1647 i = (int *) table->data;
1648 vleft = table->maxlen / sizeof(*i);
1652 conv = do_proc_dointvec_conv;
1654 for (; left && vleft--; i++, first=0) {
1669 if (len > sizeof(buf) - 1)
1670 len = sizeof(buf) - 1;
1671 if (copy_from_user(buf, s, len))
1675 if (*p == '-' && left > 1) {
1679 if (*p < '0' || *p > '9')
1682 lval = simple_strtoul(p, &p, 0);
1685 if ((len < left) && *p && !isspace(*p))
1692 if (conv(&neg, &lval, i, 1, data))
1699 if (conv(&neg, &lval, i, 0, data))
1702 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1706 if(copy_to_user(s, buf, len))
1713 if (!write && !first && left) {
1714 if(put_user('\n', s))
1721 if (get_user(c, s++))
1737 * proc_dointvec - read a vector of integers
1738 * @table: the sysctl table
1739 * @write: %TRUE if this is a write to the sysctl file
1740 * @filp: the file structure
1741 * @buffer: the user buffer
1742 * @lenp: the size of the user buffer
1743 * @ppos: file position
1745 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1746 * values from/to the user buffer, treated as an ASCII string.
1748 * Returns 0 on success.
1750 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1751 void __user *buffer, size_t *lenp, loff_t *ppos)
1753 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1763 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1765 int write, void *data)
1767 int op = *(int *)data;
1769 int val = *negp ? -*lvalp : *lvalp;
1771 case OP_SET: *valp = val; break;
1772 case OP_AND: *valp &= val; break;
1773 case OP_OR: *valp |= val; break;
1774 case OP_MAX: if(*valp < val)
1777 case OP_MIN: if(*valp > val)
1785 *lvalp = (unsigned long)-val;
1788 *lvalp = (unsigned long)val;
1795 * init may raise the set.
1798 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1799 void __user *buffer, size_t *lenp, loff_t *ppos)
1803 if (!capable(CAP_SYS_MODULE)) {
1807 op = (current->pid == 1) ? OP_SET : OP_AND;
1808 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1809 do_proc_dointvec_bset_conv,&op);
1812 struct do_proc_dointvec_minmax_conv_param {
1817 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1819 int write, void *data)
1821 struct do_proc_dointvec_minmax_conv_param *param = data;
1823 int val = *negp ? -*lvalp : *lvalp;
1824 if ((param->min && *param->min > val) ||
1825 (param->max && *param->max < val))
1832 *lvalp = (unsigned long)-val;
1835 *lvalp = (unsigned long)val;
1842 * proc_dointvec_minmax - read a vector of integers with min/max values
1843 * @table: the sysctl table
1844 * @write: %TRUE if this is a write to the sysctl file
1845 * @filp: the file structure
1846 * @buffer: the user buffer
1847 * @lenp: the size of the user buffer
1848 * @ppos: file position
1850 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1851 * values from/to the user buffer, treated as an ASCII string.
1853 * This routine will ensure the values are within the range specified by
1854 * table->extra1 (min) and table->extra2 (max).
1856 * Returns 0 on success.
1858 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1859 void __user *buffer, size_t *lenp, loff_t *ppos)
1861 struct do_proc_dointvec_minmax_conv_param param = {
1862 .min = (int *) table->extra1,
1863 .max = (int *) table->extra2,
1865 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1866 do_proc_dointvec_minmax_conv, ¶m);
1869 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1871 void __user *buffer,
1872 size_t *lenp, loff_t *ppos,
1873 unsigned long convmul,
1874 unsigned long convdiv)
1876 #define TMPBUFLEN 21
1877 unsigned long *i, *min, *max, val;
1878 int vleft, first=1, neg;
1880 char buf[TMPBUFLEN], *p;
1881 char __user *s = buffer;
1883 if (!table->data || !table->maxlen || !*lenp ||
1884 (*ppos && !write)) {
1889 i = (unsigned long *) table->data;
1890 min = (unsigned long *) table->extra1;
1891 max = (unsigned long *) table->extra2;
1892 vleft = table->maxlen / sizeof(unsigned long);
1895 for (; left && vleft--; i++, min++, max++, first=0) {
1910 if (len > TMPBUFLEN-1)
1912 if (copy_from_user(buf, s, len))
1916 if (*p == '-' && left > 1) {
1920 if (*p < '0' || *p > '9')
1922 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1924 if ((len < left) && *p && !isspace(*p))
1933 if ((min && val < *min) || (max && val > *max))
1940 sprintf(p, "%lu", convdiv * (*i) / convmul);
1944 if(copy_to_user(s, buf, len))
1951 if (!write && !first && left) {
1952 if(put_user('\n', s))
1959 if (get_user(c, s++))
1975 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1976 * @table: the sysctl table
1977 * @write: %TRUE if this is a write to the sysctl file
1978 * @filp: the file structure
1979 * @buffer: the user buffer
1980 * @lenp: the size of the user buffer
1981 * @ppos: file position
1983 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1984 * values from/to the user buffer, treated as an ASCII string.
1986 * This routine will ensure the values are within the range specified by
1987 * table->extra1 (min) and table->extra2 (max).
1989 * Returns 0 on success.
1991 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1992 void __user *buffer, size_t *lenp, loff_t *ppos)
1994 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1998 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1999 * @table: the sysctl table
2000 * @write: %TRUE if this is a write to the sysctl file
2001 * @filp: the file structure
2002 * @buffer: the user buffer
2003 * @lenp: the size of the user buffer
2004 * @ppos: file position
2006 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2007 * values from/to the user buffer, treated as an ASCII string. The values
2008 * are treated as milliseconds, and converted to jiffies when they are stored.
2010 * This routine will ensure the values are within the range specified by
2011 * table->extra1 (min) and table->extra2 (max).
2013 * Returns 0 on success.
2015 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2017 void __user *buffer,
2018 size_t *lenp, loff_t *ppos)
2020 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2021 lenp, ppos, HZ, 1000l);
2025 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2027 int write, void *data)
2030 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2036 lval = (unsigned long)-val;
2039 lval = (unsigned long)val;
2046 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2048 int write, void *data)
2051 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2057 lval = (unsigned long)-val;
2060 lval = (unsigned long)val;
2062 *lvalp = jiffies_to_clock_t(lval);
2067 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2069 int write, void *data)
2072 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2078 lval = (unsigned long)-val;
2081 lval = (unsigned long)val;
2083 *lvalp = jiffies_to_msecs(lval);
2089 * proc_dointvec_jiffies - read a vector of integers as seconds
2090 * @table: the sysctl table
2091 * @write: %TRUE if this is a write to the sysctl file
2092 * @filp: the file structure
2093 * @buffer: the user buffer
2094 * @lenp: the size of the user buffer
2095 * @ppos: file position
2097 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2098 * values from/to the user buffer, treated as an ASCII string.
2099 * The values read are assumed to be in seconds, and are converted into
2102 * Returns 0 on success.
2104 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2105 void __user *buffer, size_t *lenp, loff_t *ppos)
2107 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2108 do_proc_dointvec_jiffies_conv,NULL);
2112 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2113 * @table: the sysctl table
2114 * @write: %TRUE if this is a write to the sysctl file
2115 * @filp: the file structure
2116 * @buffer: the user buffer
2117 * @lenp: the size of the user buffer
2118 * @ppos: pointer to the file position
2120 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2121 * values from/to the user buffer, treated as an ASCII string.
2122 * The values read are assumed to be in 1/USER_HZ seconds, and
2123 * are converted into jiffies.
2125 * Returns 0 on success.
2127 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2128 void __user *buffer, size_t *lenp, loff_t *ppos)
2130 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2131 do_proc_dointvec_userhz_jiffies_conv,NULL);
2135 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2136 * @table: the sysctl table
2137 * @write: %TRUE if this is a write to the sysctl file
2138 * @filp: the file structure
2139 * @buffer: the user buffer
2140 * @lenp: the size of the user buffer
2141 * @ppos: file position
2142 * @ppos: the current position in the file
2144 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2145 * values from/to the user buffer, treated as an ASCII string.
2146 * The values read are assumed to be in 1/1000 seconds, and
2147 * are converted into jiffies.
2149 * Returns 0 on success.
2151 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2152 void __user *buffer, size_t *lenp, loff_t *ppos)
2154 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2155 do_proc_dointvec_ms_jiffies_conv, NULL);
2158 #else /* CONFIG_PROC_FS */
2160 int proc_dostring(ctl_table *table, int write, struct file *filp,
2161 void __user *buffer, size_t *lenp, loff_t *ppos)
2166 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2167 void __user *buffer, size_t *lenp, loff_t *ppos)
2172 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2173 void __user *buffer, size_t *lenp, loff_t *ppos)
2178 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2179 void __user *buffer, size_t *lenp, loff_t *ppos)
2184 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2185 void __user *buffer, size_t *lenp, loff_t *ppos)
2190 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2191 void __user *buffer, size_t *lenp, loff_t *ppos)
2196 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2197 void __user *buffer, size_t *lenp, loff_t *ppos)
2202 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2203 void __user *buffer, size_t *lenp, loff_t *ppos)
2208 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2209 void __user *buffer, size_t *lenp, loff_t *ppos)
2214 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2216 void __user *buffer,
2217 size_t *lenp, loff_t *ppos)
2223 #endif /* CONFIG_PROC_FS */
2227 * General sysctl support routines
2230 /* The generic string strategy routine: */
2231 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2232 void __user *oldval, size_t __user *oldlenp,
2233 void __user *newval, size_t newlen, void **context)
2235 if (!table->data || !table->maxlen)
2238 if (oldval && oldlenp) {
2240 if (get_user(bufsize, oldlenp))
2243 size_t len = strlen(table->data), copied;
2245 /* This shouldn't trigger for a well-formed sysctl */
2246 if (len > table->maxlen)
2247 len = table->maxlen;
2249 /* Copy up to a max of bufsize-1 bytes of the string */
2250 copied = (len >= bufsize) ? bufsize - 1 : len;
2252 if (copy_to_user(oldval, table->data, copied) ||
2253 put_user(0, (char __user *)(oldval + copied)))
2255 if (put_user(len, oldlenp))
2259 if (newval && newlen) {
2260 size_t len = newlen;
2261 if (len > table->maxlen)
2262 len = table->maxlen;
2263 if(copy_from_user(table->data, newval, len))
2265 if (len == table->maxlen)
2267 ((char *) table->data)[len] = 0;
2273 * This function makes sure that all of the integers in the vector
2274 * are between the minimum and maximum values given in the arrays
2275 * table->extra1 and table->extra2, respectively.
2277 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2278 void __user *oldval, size_t __user *oldlenp,
2279 void __user *newval, size_t newlen, void **context)
2282 if (newval && newlen) {
2283 int __user *vec = (int __user *) newval;
2284 int *min = (int *) table->extra1;
2285 int *max = (int *) table->extra2;
2289 if (newlen % sizeof(int) != 0)
2292 if (!table->extra1 && !table->extra2)
2295 if (newlen > table->maxlen)
2296 newlen = table->maxlen;
2297 length = newlen / sizeof(int);
2299 for (i = 0; i < length; i++) {
2301 if (get_user(value, vec + i))
2303 if (min && value < min[i])
2305 if (max && value > max[i])
2312 /* Strategy function to convert jiffies to seconds */
2313 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2314 void __user *oldval, size_t __user *oldlenp,
2315 void __user *newval, size_t newlen, void **context)
2320 if (get_user(olen, oldlenp))
2322 if (olen!=sizeof(int))
2325 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2326 (oldlenp && put_user(sizeof(int),oldlenp)))
2329 if (newval && newlen) {
2331 if (newlen != sizeof(int))
2333 if (get_user(new, (int __user *)newval))
2335 *(int *)(table->data) = new*HZ;
2340 /* Strategy function to convert jiffies to seconds */
2341 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2342 void __user *oldval, size_t __user *oldlenp,
2343 void __user *newval, size_t newlen, void **context)
2348 if (get_user(olen, oldlenp))
2350 if (olen!=sizeof(int))
2353 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2354 (oldlenp && put_user(sizeof(int),oldlenp)))
2357 if (newval && newlen) {
2359 if (newlen != sizeof(int))
2361 if (get_user(new, (int __user *)newval))
2363 *(int *)(table->data) = msecs_to_jiffies(new);
2368 #else /* CONFIG_SYSCTL */
2371 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2376 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2377 void __user *oldval, size_t __user *oldlenp,
2378 void __user *newval, size_t newlen, void **context)
2383 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2384 void __user *oldval, size_t __user *oldlenp,
2385 void __user *newval, size_t newlen, void **context)
2390 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2391 void __user *oldval, size_t __user *oldlenp,
2392 void __user *newval, size_t newlen, void **context)
2397 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2398 void __user *oldval, size_t __user *oldlenp,
2399 void __user *newval, size_t newlen, void **context)
2404 int proc_dostring(ctl_table *table, int write, struct file *filp,
2405 void __user *buffer, size_t *lenp, loff_t *ppos)
2410 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2411 void __user *buffer, size_t *lenp, loff_t *ppos)
2416 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2417 void __user *buffer, size_t *lenp, loff_t *ppos)
2422 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2423 void __user *buffer, size_t *lenp, loff_t *ppos)
2428 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2429 void __user *buffer, size_t *lenp, loff_t *ppos)
2434 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2435 void __user *buffer, size_t *lenp, loff_t *ppos)
2440 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2441 void __user *buffer, size_t *lenp, loff_t *ppos)
2446 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2447 void __user *buffer, size_t *lenp, loff_t *ppos)
2452 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2454 void __user *buffer,
2455 size_t *lenp, loff_t *ppos)
2460 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2466 void unregister_sysctl_table(struct ctl_table_header * table)
2470 #endif /* CONFIG_SYSCTL */
2473 * No sense putting this after each symbol definition, twice,
2474 * exception granted :-)
2476 EXPORT_SYMBOL(proc_dointvec);
2477 EXPORT_SYMBOL(proc_dointvec_jiffies);
2478 EXPORT_SYMBOL(proc_dointvec_minmax);
2479 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2480 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2481 EXPORT_SYMBOL(proc_dostring);
2482 EXPORT_SYMBOL(proc_doulongvec_minmax);
2483 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2484 EXPORT_SYMBOL(register_sysctl_table);
2485 EXPORT_SYMBOL(sysctl_intvec);
2486 EXPORT_SYMBOL(sysctl_jiffies);
2487 EXPORT_SYMBOL(sysctl_ms_jiffies);
2488 EXPORT_SYMBOL(sysctl_string);
2489 EXPORT_SYMBOL(unregister_sysctl_table);