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>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.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;
70 extern int sysctl_drop_caches;
71 extern int percpu_pagelist_fraction;
73 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
74 int unknown_nmi_panic;
75 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
76 void __user *, size_t *, loff_t *);
79 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
80 static int maxolduid = 65535;
82 static int min_percpu_pagelist_fract = 8;
84 static int ngroups_max = NGROUPS_MAX;
87 extern char modprobe_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;
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 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
128 ctl_table *, void **);
129 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
130 void __user *buffer, size_t *lenp, loff_t *ppos);
132 static ctl_table root_table[];
133 static struct ctl_table_header root_table_header =
134 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
136 static ctl_table kern_table[];
137 static ctl_table vm_table[];
138 static ctl_table proc_table[];
139 static ctl_table fs_table[];
140 static ctl_table debug_table[];
141 static ctl_table dev_table[];
142 extern ctl_table random_table[];
143 #ifdef CONFIG_UNIX98_PTYS
144 extern ctl_table pty_table[];
146 #ifdef CONFIG_INOTIFY
147 extern ctl_table inotify_table[];
150 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
151 int sysctl_legacy_va_layout;
154 /* /proc declarations: */
156 #ifdef CONFIG_PROC_FS
158 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
159 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
160 static int proc_opensys(struct inode *, struct file *);
162 struct file_operations proc_sys_file_operations = {
163 .open = proc_opensys,
164 .read = proc_readsys,
165 .write = proc_writesys,
168 extern struct proc_dir_entry *proc_sys_root;
170 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
171 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
174 /* The default sysctl tables: */
176 static ctl_table root_table[] = {
178 .ctl_name = CTL_KERN,
179 .procname = "kernel",
198 .ctl_name = CTL_PROC,
210 .ctl_name = CTL_DEBUG,
213 .child = debug_table,
225 static ctl_table kern_table[] = {
227 .ctl_name = KERN_OSTYPE,
228 .procname = "ostype",
229 .data = system_utsname.sysname,
230 .maxlen = sizeof(system_utsname.sysname),
232 .proc_handler = &proc_doutsstring,
233 .strategy = &sysctl_string,
236 .ctl_name = KERN_OSRELEASE,
237 .procname = "osrelease",
238 .data = system_utsname.release,
239 .maxlen = sizeof(system_utsname.release),
241 .proc_handler = &proc_doutsstring,
242 .strategy = &sysctl_string,
245 .ctl_name = KERN_VERSION,
246 .procname = "version",
247 .data = system_utsname.version,
248 .maxlen = sizeof(system_utsname.version),
250 .proc_handler = &proc_doutsstring,
251 .strategy = &sysctl_string,
254 .ctl_name = KERN_NODENAME,
255 .procname = "hostname",
256 .data = system_utsname.nodename,
257 .maxlen = sizeof(system_utsname.nodename),
259 .proc_handler = &proc_doutsstring,
260 .strategy = &sysctl_string,
263 .ctl_name = KERN_DOMAINNAME,
264 .procname = "domainname",
265 .data = system_utsname.domainname,
266 .maxlen = sizeof(system_utsname.domainname),
268 .proc_handler = &proc_doutsstring,
269 .strategy = &sysctl_string,
272 .ctl_name = KERN_PANIC,
274 .data = &panic_timeout,
275 .maxlen = sizeof(int),
277 .proc_handler = &proc_dointvec,
280 .ctl_name = KERN_CORE_USES_PID,
281 .procname = "core_uses_pid",
282 .data = &core_uses_pid,
283 .maxlen = sizeof(int),
285 .proc_handler = &proc_dointvec,
288 .ctl_name = KERN_CORE_PATTERN,
289 .procname = "core_pattern",
290 .data = core_pattern,
293 .proc_handler = &proc_dostring,
294 .strategy = &sysctl_string,
297 .ctl_name = KERN_TAINTED,
298 .procname = "tainted",
300 .maxlen = sizeof(int),
302 .proc_handler = &proc_dointvec,
305 .ctl_name = KERN_CAP_BSET,
306 .procname = "cap-bound",
308 .maxlen = sizeof(kernel_cap_t),
310 .proc_handler = &proc_dointvec_bset,
312 #ifdef CONFIG_BLK_DEV_INITRD
314 .ctl_name = KERN_REALROOTDEV,
315 .procname = "real-root-dev",
316 .data = &real_root_dev,
317 .maxlen = sizeof(int),
319 .proc_handler = &proc_dointvec,
324 .ctl_name = KERN_SPARC_REBOOT,
325 .procname = "reboot-cmd",
326 .data = reboot_command,
329 .proc_handler = &proc_dostring,
330 .strategy = &sysctl_string,
333 .ctl_name = KERN_SPARC_STOP_A,
334 .procname = "stop-a",
335 .data = &stop_a_enabled,
336 .maxlen = sizeof (int),
338 .proc_handler = &proc_dointvec,
341 .ctl_name = KERN_SPARC_SCONS_PWROFF,
342 .procname = "scons-poweroff",
343 .data = &scons_pwroff,
344 .maxlen = sizeof (int),
346 .proc_handler = &proc_dointvec,
351 .ctl_name = KERN_HPPA_PWRSW,
352 .procname = "soft-power",
353 .data = &pwrsw_enabled,
354 .maxlen = sizeof (int),
356 .proc_handler = &proc_dointvec,
359 .ctl_name = KERN_HPPA_UNALIGNED,
360 .procname = "unaligned-trap",
361 .data = &unaligned_enabled,
362 .maxlen = sizeof (int),
364 .proc_handler = &proc_dointvec,
368 .ctl_name = KERN_CTLALTDEL,
369 .procname = "ctrl-alt-del",
371 .maxlen = sizeof(int),
373 .proc_handler = &proc_dointvec,
376 .ctl_name = KERN_PRINTK,
377 .procname = "printk",
378 .data = &console_loglevel,
379 .maxlen = 4*sizeof(int),
381 .proc_handler = &proc_dointvec,
385 .ctl_name = KERN_MODPROBE,
386 .procname = "modprobe",
387 .data = &modprobe_path,
388 .maxlen = KMOD_PATH_LEN,
390 .proc_handler = &proc_dostring,
391 .strategy = &sysctl_string,
394 #ifdef CONFIG_HOTPLUG
396 .ctl_name = KERN_HOTPLUG,
397 .procname = "hotplug",
398 .data = &uevent_helper,
399 .maxlen = UEVENT_HELPER_PATH_LEN,
401 .proc_handler = &proc_dostring,
402 .strategy = &sysctl_string,
405 #ifdef CONFIG_CHR_DEV_SG
407 .ctl_name = KERN_SG_BIG_BUFF,
408 .procname = "sg-big-buff",
409 .data = &sg_big_buff,
410 .maxlen = sizeof (int),
412 .proc_handler = &proc_dointvec,
415 #ifdef CONFIG_BSD_PROCESS_ACCT
417 .ctl_name = KERN_ACCT,
420 .maxlen = 3*sizeof(int),
422 .proc_handler = &proc_dointvec,
425 #ifdef CONFIG_SYSVIPC
427 .ctl_name = KERN_SHMMAX,
428 .procname = "shmmax",
430 .maxlen = sizeof (size_t),
432 .proc_handler = &proc_doulongvec_minmax,
435 .ctl_name = KERN_SHMALL,
436 .procname = "shmall",
438 .maxlen = sizeof (size_t),
440 .proc_handler = &proc_doulongvec_minmax,
443 .ctl_name = KERN_SHMMNI,
444 .procname = "shmmni",
446 .maxlen = sizeof (int),
448 .proc_handler = &proc_dointvec,
451 .ctl_name = KERN_MSGMAX,
452 .procname = "msgmax",
454 .maxlen = sizeof (int),
456 .proc_handler = &proc_dointvec,
459 .ctl_name = KERN_MSGMNI,
460 .procname = "msgmni",
462 .maxlen = sizeof (int),
464 .proc_handler = &proc_dointvec,
467 .ctl_name = KERN_MSGMNB,
468 .procname = "msgmnb",
470 .maxlen = sizeof (int),
472 .proc_handler = &proc_dointvec,
475 .ctl_name = KERN_SEM,
478 .maxlen = 4*sizeof (int),
480 .proc_handler = &proc_dointvec,
483 #ifdef CONFIG_MAGIC_SYSRQ
485 .ctl_name = KERN_SYSRQ,
487 .data = &sysrq_enabled,
488 .maxlen = sizeof (int),
490 .proc_handler = &proc_dointvec,
494 .ctl_name = KERN_CADPID,
495 .procname = "cad_pid",
497 .maxlen = sizeof (int),
499 .proc_handler = &proc_dointvec,
502 .ctl_name = KERN_MAX_THREADS,
503 .procname = "threads-max",
504 .data = &max_threads,
505 .maxlen = sizeof(int),
507 .proc_handler = &proc_dointvec,
510 .ctl_name = KERN_RANDOM,
511 .procname = "random",
513 .child = random_table,
515 #ifdef CONFIG_UNIX98_PTYS
517 .ctl_name = KERN_PTY,
524 .ctl_name = KERN_OVERFLOWUID,
525 .procname = "overflowuid",
526 .data = &overflowuid,
527 .maxlen = sizeof(int),
529 .proc_handler = &proc_dointvec_minmax,
530 .strategy = &sysctl_intvec,
531 .extra1 = &minolduid,
532 .extra2 = &maxolduid,
535 .ctl_name = KERN_OVERFLOWGID,
536 .procname = "overflowgid",
537 .data = &overflowgid,
538 .maxlen = sizeof(int),
540 .proc_handler = &proc_dointvec_minmax,
541 .strategy = &sysctl_intvec,
542 .extra1 = &minolduid,
543 .extra2 = &maxolduid,
546 #ifdef CONFIG_MATHEMU
548 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
549 .procname = "ieee_emulation_warnings",
550 .data = &sysctl_ieee_emulation_warnings,
551 .maxlen = sizeof(int),
553 .proc_handler = &proc_dointvec,
556 #ifdef CONFIG_NO_IDLE_HZ
558 .ctl_name = KERN_HZ_TIMER,
559 .procname = "hz_timer",
560 .data = &sysctl_hz_timer,
561 .maxlen = sizeof(int),
563 .proc_handler = &proc_dointvec,
567 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
568 .procname = "userprocess_debug",
569 .data = &sysctl_userprocess_debug,
570 .maxlen = sizeof(int),
572 .proc_handler = &proc_dointvec,
576 .ctl_name = KERN_PIDMAX,
577 .procname = "pid_max",
579 .maxlen = sizeof (int),
581 .proc_handler = &proc_dointvec_minmax,
582 .strategy = sysctl_intvec,
583 .extra1 = &pid_max_min,
584 .extra2 = &pid_max_max,
587 .ctl_name = KERN_PANIC_ON_OOPS,
588 .procname = "panic_on_oops",
589 .data = &panic_on_oops,
590 .maxlen = sizeof(int),
592 .proc_handler = &proc_dointvec,
595 .ctl_name = KERN_PRINTK_RATELIMIT,
596 .procname = "printk_ratelimit",
597 .data = &printk_ratelimit_jiffies,
598 .maxlen = sizeof(int),
600 .proc_handler = &proc_dointvec_jiffies,
601 .strategy = &sysctl_jiffies,
604 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
605 .procname = "printk_ratelimit_burst",
606 .data = &printk_ratelimit_burst,
607 .maxlen = sizeof(int),
609 .proc_handler = &proc_dointvec,
612 .ctl_name = KERN_NGROUPS_MAX,
613 .procname = "ngroups_max",
614 .data = &ngroups_max,
615 .maxlen = sizeof (int),
617 .proc_handler = &proc_dointvec,
619 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
621 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
622 .procname = "unknown_nmi_panic",
623 .data = &unknown_nmi_panic,
624 .maxlen = sizeof (int),
626 .proc_handler = &proc_unknown_nmi_panic,
629 #if defined(CONFIG_X86)
631 .ctl_name = KERN_BOOTLOADER_TYPE,
632 .procname = "bootloader_type",
633 .data = &bootloader_type,
634 .maxlen = sizeof (int),
636 .proc_handler = &proc_dointvec,
640 .ctl_name = KERN_RANDOMIZE,
641 .procname = "randomize_va_space",
642 .data = &randomize_va_space,
643 .maxlen = sizeof(int),
645 .proc_handler = &proc_dointvec,
647 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
649 .ctl_name = KERN_SPIN_RETRY,
650 .procname = "spin_retry",
652 .maxlen = sizeof (int),
654 .proc_handler = &proc_dointvec,
657 #ifdef CONFIG_ACPI_SLEEP
659 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
660 .procname = "acpi_video_flags",
661 .data = &acpi_video_flags,
662 .maxlen = sizeof (unsigned long),
664 .proc_handler = &proc_dointvec,
670 /* Constants for minimum and maximum testing in vm_table.
671 We use these as one-element integer vectors. */
673 static int one_hundred = 100;
676 static ctl_table vm_table[] = {
678 .ctl_name = VM_OVERCOMMIT_MEMORY,
679 .procname = "overcommit_memory",
680 .data = &sysctl_overcommit_memory,
681 .maxlen = sizeof(sysctl_overcommit_memory),
683 .proc_handler = &proc_dointvec,
686 .ctl_name = VM_OVERCOMMIT_RATIO,
687 .procname = "overcommit_ratio",
688 .data = &sysctl_overcommit_ratio,
689 .maxlen = sizeof(sysctl_overcommit_ratio),
691 .proc_handler = &proc_dointvec,
694 .ctl_name = VM_PAGE_CLUSTER,
695 .procname = "page-cluster",
696 .data = &page_cluster,
697 .maxlen = sizeof(int),
699 .proc_handler = &proc_dointvec,
702 .ctl_name = VM_DIRTY_BACKGROUND,
703 .procname = "dirty_background_ratio",
704 .data = &dirty_background_ratio,
705 .maxlen = sizeof(dirty_background_ratio),
707 .proc_handler = &proc_dointvec_minmax,
708 .strategy = &sysctl_intvec,
710 .extra2 = &one_hundred,
713 .ctl_name = VM_DIRTY_RATIO,
714 .procname = "dirty_ratio",
715 .data = &vm_dirty_ratio,
716 .maxlen = sizeof(vm_dirty_ratio),
718 .proc_handler = &proc_dointvec_minmax,
719 .strategy = &sysctl_intvec,
721 .extra2 = &one_hundred,
724 .ctl_name = VM_DIRTY_WB_CS,
725 .procname = "dirty_writeback_centisecs",
726 .data = &dirty_writeback_centisecs,
727 .maxlen = sizeof(dirty_writeback_centisecs),
729 .proc_handler = &dirty_writeback_centisecs_handler,
732 .ctl_name = VM_DIRTY_EXPIRE_CS,
733 .procname = "dirty_expire_centisecs",
734 .data = &dirty_expire_centisecs,
735 .maxlen = sizeof(dirty_expire_centisecs),
737 .proc_handler = &proc_dointvec,
740 .ctl_name = VM_NR_PDFLUSH_THREADS,
741 .procname = "nr_pdflush_threads",
742 .data = &nr_pdflush_threads,
743 .maxlen = sizeof nr_pdflush_threads,
744 .mode = 0444 /* read-only*/,
745 .proc_handler = &proc_dointvec,
748 .ctl_name = VM_SWAPPINESS,
749 .procname = "swappiness",
750 .data = &vm_swappiness,
751 .maxlen = sizeof(vm_swappiness),
753 .proc_handler = &proc_dointvec_minmax,
754 .strategy = &sysctl_intvec,
756 .extra2 = &one_hundred,
758 #ifdef CONFIG_HUGETLB_PAGE
760 .ctl_name = VM_HUGETLB_PAGES,
761 .procname = "nr_hugepages",
762 .data = &max_huge_pages,
763 .maxlen = sizeof(unsigned long),
765 .proc_handler = &hugetlb_sysctl_handler,
766 .extra1 = (void *)&hugetlb_zero,
767 .extra2 = (void *)&hugetlb_infinity,
770 .ctl_name = VM_HUGETLB_GROUP,
771 .procname = "hugetlb_shm_group",
772 .data = &sysctl_hugetlb_shm_group,
773 .maxlen = sizeof(gid_t),
775 .proc_handler = &proc_dointvec,
779 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
780 .procname = "lowmem_reserve_ratio",
781 .data = &sysctl_lowmem_reserve_ratio,
782 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
784 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
785 .strategy = &sysctl_intvec,
788 .ctl_name = VM_DROP_PAGECACHE,
789 .procname = "drop_caches",
790 .data = &sysctl_drop_caches,
791 .maxlen = sizeof(int),
793 .proc_handler = drop_caches_sysctl_handler,
794 .strategy = &sysctl_intvec,
797 .ctl_name = VM_MIN_FREE_KBYTES,
798 .procname = "min_free_kbytes",
799 .data = &min_free_kbytes,
800 .maxlen = sizeof(min_free_kbytes),
802 .proc_handler = &min_free_kbytes_sysctl_handler,
803 .strategy = &sysctl_intvec,
807 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
808 .procname = "percpu_pagelist_fraction",
809 .data = &percpu_pagelist_fraction,
810 .maxlen = sizeof(percpu_pagelist_fraction),
812 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
813 .strategy = &sysctl_intvec,
814 .extra1 = &min_percpu_pagelist_fract,
818 .ctl_name = VM_MAX_MAP_COUNT,
819 .procname = "max_map_count",
820 .data = &sysctl_max_map_count,
821 .maxlen = sizeof(sysctl_max_map_count),
823 .proc_handler = &proc_dointvec
827 .ctl_name = VM_LAPTOP_MODE,
828 .procname = "laptop_mode",
829 .data = &laptop_mode,
830 .maxlen = sizeof(laptop_mode),
832 .proc_handler = &proc_dointvec,
833 .strategy = &sysctl_intvec,
837 .ctl_name = VM_BLOCK_DUMP,
838 .procname = "block_dump",
840 .maxlen = sizeof(block_dump),
842 .proc_handler = &proc_dointvec,
843 .strategy = &sysctl_intvec,
847 .ctl_name = VM_VFS_CACHE_PRESSURE,
848 .procname = "vfs_cache_pressure",
849 .data = &sysctl_vfs_cache_pressure,
850 .maxlen = sizeof(sysctl_vfs_cache_pressure),
852 .proc_handler = &proc_dointvec,
853 .strategy = &sysctl_intvec,
856 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
858 .ctl_name = VM_LEGACY_VA_LAYOUT,
859 .procname = "legacy_va_layout",
860 .data = &sysctl_legacy_va_layout,
861 .maxlen = sizeof(sysctl_legacy_va_layout),
863 .proc_handler = &proc_dointvec,
864 .strategy = &sysctl_intvec,
870 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
871 .procname = "swap_token_timeout",
872 .data = &swap_token_default_timeout,
873 .maxlen = sizeof(swap_token_default_timeout),
875 .proc_handler = &proc_dointvec_jiffies,
876 .strategy = &sysctl_jiffies,
881 .ctl_name = VM_ZONE_RECLAIM_MODE,
882 .procname = "zone_reclaim_mode",
883 .data = &zone_reclaim_mode,
884 .maxlen = sizeof(zone_reclaim_mode),
886 .proc_handler = &proc_dointvec,
887 .strategy = &sysctl_intvec,
891 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
892 .procname = "zone_reclaim_interval",
893 .data = &zone_reclaim_interval,
894 .maxlen = sizeof(zone_reclaim_interval),
896 .proc_handler = &proc_dointvec_jiffies,
897 .strategy = &sysctl_jiffies,
903 static ctl_table proc_table[] = {
907 static ctl_table fs_table[] = {
909 .ctl_name = FS_NRINODE,
910 .procname = "inode-nr",
911 .data = &inodes_stat,
912 .maxlen = 2*sizeof(int),
914 .proc_handler = &proc_dointvec,
917 .ctl_name = FS_STATINODE,
918 .procname = "inode-state",
919 .data = &inodes_stat,
920 .maxlen = 7*sizeof(int),
922 .proc_handler = &proc_dointvec,
925 .ctl_name = FS_NRFILE,
926 .procname = "file-nr",
928 .maxlen = 3*sizeof(int),
930 .proc_handler = &proc_dointvec,
933 .ctl_name = FS_MAXFILE,
934 .procname = "file-max",
935 .data = &files_stat.max_files,
936 .maxlen = sizeof(int),
938 .proc_handler = &proc_dointvec,
941 .ctl_name = FS_DENTRY,
942 .procname = "dentry-state",
943 .data = &dentry_stat,
944 .maxlen = 6*sizeof(int),
946 .proc_handler = &proc_dointvec,
949 .ctl_name = FS_OVERFLOWUID,
950 .procname = "overflowuid",
951 .data = &fs_overflowuid,
952 .maxlen = sizeof(int),
954 .proc_handler = &proc_dointvec_minmax,
955 .strategy = &sysctl_intvec,
956 .extra1 = &minolduid,
957 .extra2 = &maxolduid,
960 .ctl_name = FS_OVERFLOWGID,
961 .procname = "overflowgid",
962 .data = &fs_overflowgid,
963 .maxlen = sizeof(int),
965 .proc_handler = &proc_dointvec_minmax,
966 .strategy = &sysctl_intvec,
967 .extra1 = &minolduid,
968 .extra2 = &maxolduid,
971 .ctl_name = FS_LEASES,
972 .procname = "leases-enable",
973 .data = &leases_enable,
974 .maxlen = sizeof(int),
976 .proc_handler = &proc_dointvec,
978 #ifdef CONFIG_DNOTIFY
980 .ctl_name = FS_DIR_NOTIFY,
981 .procname = "dir-notify-enable",
982 .data = &dir_notify_enable,
983 .maxlen = sizeof(int),
985 .proc_handler = &proc_dointvec,
990 .ctl_name = FS_LEASE_TIME,
991 .procname = "lease-break-time",
992 .data = &lease_break_time,
993 .maxlen = sizeof(int),
995 .proc_handler = &proc_dointvec,
998 .ctl_name = FS_AIO_NR,
999 .procname = "aio-nr",
1001 .maxlen = sizeof(aio_nr),
1003 .proc_handler = &proc_doulongvec_minmax,
1006 .ctl_name = FS_AIO_MAX_NR,
1007 .procname = "aio-max-nr",
1008 .data = &aio_max_nr,
1009 .maxlen = sizeof(aio_max_nr),
1011 .proc_handler = &proc_doulongvec_minmax,
1013 #ifdef CONFIG_INOTIFY
1015 .ctl_name = FS_INOTIFY,
1016 .procname = "inotify",
1018 .child = inotify_table,
1023 .ctl_name = KERN_SETUID_DUMPABLE,
1024 .procname = "suid_dumpable",
1025 .data = &suid_dumpable,
1026 .maxlen = sizeof(int),
1028 .proc_handler = &proc_dointvec,
1033 static ctl_table debug_table[] = {
1037 static ctl_table dev_table[] = {
1041 extern void init_irq_proc (void);
1043 static DEFINE_SPINLOCK(sysctl_lock);
1045 /* called under sysctl_lock */
1046 static int use_table(struct ctl_table_header *p)
1048 if (unlikely(p->unregistering))
1054 /* called under sysctl_lock */
1055 static void unuse_table(struct ctl_table_header *p)
1058 if (unlikely(p->unregistering))
1059 complete(p->unregistering);
1062 /* called under sysctl_lock, will reacquire if has to wait */
1063 static void start_unregistering(struct ctl_table_header *p)
1066 * if p->used is 0, nobody will ever touch that entry again;
1067 * we'll eliminate all paths to it before dropping sysctl_lock
1069 if (unlikely(p->used)) {
1070 struct completion wait;
1071 init_completion(&wait);
1072 p->unregistering = &wait;
1073 spin_unlock(&sysctl_lock);
1074 wait_for_completion(&wait);
1075 spin_lock(&sysctl_lock);
1078 * do not remove from the list until nobody holds it; walking the
1079 * list in do_sysctl() relies on that.
1081 list_del_init(&p->ctl_entry);
1084 void __init sysctl_init(void)
1086 #ifdef CONFIG_PROC_FS
1087 register_proc_table(root_table, proc_sys_root, &root_table_header);
1092 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1093 void __user *newval, size_t newlen)
1095 struct list_head *tmp;
1096 int error = -ENOTDIR;
1098 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1102 if (!oldlenp || get_user(old_len, oldlenp))
1105 spin_lock(&sysctl_lock);
1106 tmp = &root_table_header.ctl_entry;
1108 struct ctl_table_header *head =
1109 list_entry(tmp, struct ctl_table_header, ctl_entry);
1110 void *context = NULL;
1112 if (!use_table(head))
1115 spin_unlock(&sysctl_lock);
1117 error = parse_table(name, nlen, oldval, oldlenp,
1118 newval, newlen, head->ctl_table,
1122 spin_lock(&sysctl_lock);
1124 if (error != -ENOTDIR)
1126 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1127 spin_unlock(&sysctl_lock);
1131 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1133 struct __sysctl_args tmp;
1136 if (copy_from_user(&tmp, args, sizeof(tmp)))
1140 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1141 tmp.newval, tmp.newlen);
1147 * ctl_perm does NOT grant the superuser all rights automatically, because
1148 * some sysctl variables are readonly even to root.
1151 static int test_perm(int mode, int op)
1155 else if (in_egroup_p(0))
1157 if ((mode & op & 0007) == op)
1162 static inline int ctl_perm(ctl_table *table, int op)
1165 error = security_sysctl(table, op);
1168 return test_perm(table->mode, op);
1171 static int parse_table(int __user *name, int nlen,
1172 void __user *oldval, size_t __user *oldlenp,
1173 void __user *newval, size_t newlen,
1174 ctl_table *table, void **context)
1180 if (get_user(n, name))
1182 for ( ; table->ctl_name; table++) {
1183 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1186 if (ctl_perm(table, 001))
1188 if (table->strategy) {
1189 error = table->strategy(
1192 newval, newlen, context);
1198 table = table->child;
1201 error = do_sysctl_strategy(table, name, nlen,
1203 newval, newlen, context);
1210 /* Perform the actual read/write of a sysctl table entry. */
1211 int do_sysctl_strategy (ctl_table *table,
1212 int __user *name, int nlen,
1213 void __user *oldval, size_t __user *oldlenp,
1214 void __user *newval, size_t newlen, void **context)
1223 if (ctl_perm(table, op))
1226 if (table->strategy) {
1227 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1228 newval, newlen, context);
1235 /* If there is no strategy routine, or if the strategy returns
1236 * zero, proceed with automatic r/w */
1237 if (table->data && table->maxlen) {
1238 if (oldval && oldlenp) {
1239 if (get_user(len, oldlenp))
1242 if (len > table->maxlen)
1243 len = table->maxlen;
1244 if(copy_to_user(oldval, table->data, len))
1246 if(put_user(len, oldlenp))
1250 if (newval && newlen) {
1252 if (len > table->maxlen)
1253 len = table->maxlen;
1254 if(copy_from_user(table->data, newval, len))
1262 * register_sysctl_table - register a sysctl hierarchy
1263 * @table: the top-level table structure
1264 * @insert_at_head: whether the entry should be inserted in front or at the end
1266 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1267 * array. An entry with a ctl_name of 0 terminates the table.
1269 * The members of the &ctl_table structure are used as follows:
1271 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1272 * must be unique within that level of sysctl
1274 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1275 * enter a sysctl file
1277 * data - a pointer to data for use by proc_handler
1279 * maxlen - the maximum size in bytes of the data
1281 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1283 * child - a pointer to the child sysctl table if this entry is a directory, or
1286 * proc_handler - the text handler routine (described below)
1288 * strategy - the strategy routine (described below)
1290 * de - for internal use by the sysctl routines
1292 * extra1, extra2 - extra pointers usable by the proc handler routines
1294 * Leaf nodes in the sysctl tree will be represented by a single file
1295 * under /proc; non-leaf nodes will be represented by directories.
1297 * sysctl(2) can automatically manage read and write requests through
1298 * the sysctl table. The data and maxlen fields of the ctl_table
1299 * struct enable minimal validation of the values being written to be
1300 * performed, and the mode field allows minimal authentication.
1302 * More sophisticated management can be enabled by the provision of a
1303 * strategy routine with the table entry. This will be called before
1304 * any automatic read or write of the data is performed.
1306 * The strategy routine may return
1308 * < 0 - Error occurred (error is passed to user process)
1310 * 0 - OK - proceed with automatic read or write.
1312 * > 0 - OK - read or write has been done by the strategy routine, so
1313 * return immediately.
1315 * There must be a proc_handler routine for any terminal nodes
1316 * mirrored under /proc/sys (non-terminals are handled by a built-in
1317 * directory handler). Several default handlers are available to
1318 * cover common cases -
1320 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1321 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1322 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1324 * It is the handler's job to read the input buffer from user memory
1325 * and process it. The handler should return 0 on success.
1327 * This routine returns %NULL on a failure to register, and a pointer
1328 * to the table header on success.
1330 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1333 struct ctl_table_header *tmp;
1334 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1337 tmp->ctl_table = table;
1338 INIT_LIST_HEAD(&tmp->ctl_entry);
1340 tmp->unregistering = NULL;
1341 spin_lock(&sysctl_lock);
1343 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1345 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1346 spin_unlock(&sysctl_lock);
1347 #ifdef CONFIG_PROC_FS
1348 register_proc_table(table, proc_sys_root, tmp);
1354 * unregister_sysctl_table - unregister a sysctl table hierarchy
1355 * @header: the header returned from register_sysctl_table
1357 * Unregisters the sysctl table and all children. proc entries may not
1358 * actually be removed until they are no longer used by anyone.
1360 void unregister_sysctl_table(struct ctl_table_header * header)
1363 spin_lock(&sysctl_lock);
1364 start_unregistering(header);
1365 #ifdef CONFIG_PROC_FS
1366 unregister_proc_table(header->ctl_table, proc_sys_root);
1368 spin_unlock(&sysctl_lock);
1376 #ifdef CONFIG_PROC_FS
1378 /* Scan the sysctl entries in table and add them all into /proc */
1379 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1381 struct proc_dir_entry *de;
1385 for (; table->ctl_name; table++) {
1386 /* Can't do anything without a proc name. */
1387 if (!table->procname)
1389 /* Maybe we can't do anything with it... */
1390 if (!table->proc_handler && !table->child) {
1391 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1396 len = strlen(table->procname);
1400 if (table->proc_handler)
1404 for (de = root->subdir; de; de = de->next) {
1405 if (proc_match(len, table->procname, de))
1408 /* If the subdir exists already, de is non-NULL */
1412 de = create_proc_entry(table->procname, mode, root);
1416 de->data = (void *) table;
1417 if (table->proc_handler)
1418 de->proc_fops = &proc_sys_file_operations;
1421 if (de->mode & S_IFDIR)
1422 register_proc_table(table->child, de, set);
1427 * Unregister a /proc sysctl table and any subdirectories.
1429 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1431 struct proc_dir_entry *de;
1432 for (; table->ctl_name; table++) {
1433 if (!(de = table->de))
1435 if (de->mode & S_IFDIR) {
1436 if (!table->child) {
1437 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1440 unregister_proc_table(table->child, de);
1442 /* Don't unregister directories which still have entries.. */
1448 * In any case, mark the entry as goner; we'll keep it
1449 * around if it's busy, but we'll know to do nothing with
1450 * its fields. We are under sysctl_lock here.
1454 /* Don't unregister proc entries that are still being used.. */
1455 if (atomic_read(&de->count))
1459 remove_proc_entry(table->procname, root);
1463 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1464 size_t count, loff_t *ppos)
1467 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1468 struct ctl_table *table;
1470 ssize_t error = -ENOTDIR;
1472 spin_lock(&sysctl_lock);
1473 if (de && de->data && use_table(de->set)) {
1475 * at that point we know that sysctl was not unregistered
1476 * and won't be until we finish
1478 spin_unlock(&sysctl_lock);
1479 table = (struct ctl_table *) de->data;
1480 if (!table || !table->proc_handler)
1483 op = (write ? 002 : 004);
1484 if (ctl_perm(table, op))
1487 /* careful: calling conventions are nasty here */
1489 error = (*table->proc_handler)(table, write, file,
1494 spin_lock(&sysctl_lock);
1495 unuse_table(de->set);
1497 spin_unlock(&sysctl_lock);
1501 static int proc_opensys(struct inode *inode, struct file *file)
1503 if (file->f_mode & FMODE_WRITE) {
1505 * sysctl entries that are not writable,
1506 * are _NOT_ writable, capabilities or not.
1508 if (!(inode->i_mode & S_IWUSR))
1515 static ssize_t proc_readsys(struct file * file, char __user * buf,
1516 size_t count, loff_t *ppos)
1518 return do_rw_proc(0, file, buf, count, ppos);
1521 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1522 size_t count, loff_t *ppos)
1524 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1528 * proc_dostring - read a string sysctl
1529 * @table: the sysctl table
1530 * @write: %TRUE if this is a write to the sysctl file
1531 * @filp: the file structure
1532 * @buffer: the user buffer
1533 * @lenp: the size of the user buffer
1534 * @ppos: file position
1536 * Reads/writes a string from/to the user buffer. If the kernel
1537 * buffer provided is not large enough to hold the string, the
1538 * string is truncated. The copied string is %NULL-terminated.
1539 * If the string is being read by the user process, it is copied
1540 * and a newline '\n' is added. It is truncated if the buffer is
1543 * Returns 0 on success.
1545 int proc_dostring(ctl_table *table, int write, struct file *filp,
1546 void __user *buffer, size_t *lenp, loff_t *ppos)
1552 if (!table->data || !table->maxlen || !*lenp ||
1553 (*ppos && !write)) {
1561 while (len < *lenp) {
1562 if (get_user(c, p++))
1564 if (c == 0 || c == '\n')
1568 if (len >= table->maxlen)
1569 len = table->maxlen-1;
1570 if(copy_from_user(table->data, buffer, len))
1572 ((char *) table->data)[len] = 0;
1575 len = strlen(table->data);
1576 if (len > table->maxlen)
1577 len = table->maxlen;
1581 if(copy_to_user(buffer, table->data, len))
1584 if(put_user('\n', ((char __user *) buffer) + len))
1595 * Special case of dostring for the UTS structure. This has locks
1596 * to observe. Should this be in kernel/sys.c ????
1599 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1600 void __user *buffer, size_t *lenp, loff_t *ppos)
1605 down_read(&uts_sem);
1606 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1609 down_write(&uts_sem);
1610 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1616 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1618 int write, void *data)
1621 *valp = *negp ? -*lvalp : *lvalp;
1626 *lvalp = (unsigned long)-val;
1629 *lvalp = (unsigned long)val;
1635 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1636 void __user *buffer, size_t *lenp, loff_t *ppos,
1637 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1638 int write, void *data),
1641 #define TMPBUFLEN 21
1642 int *i, vleft, first=1, neg, val;
1646 char buf[TMPBUFLEN], *p;
1647 char __user *s = buffer;
1649 if (!table->data || !table->maxlen || !*lenp ||
1650 (*ppos && !write)) {
1655 i = (int *) table->data;
1656 vleft = table->maxlen / sizeof(*i);
1660 conv = do_proc_dointvec_conv;
1662 for (; left && vleft--; i++, first=0) {
1677 if (len > sizeof(buf) - 1)
1678 len = sizeof(buf) - 1;
1679 if (copy_from_user(buf, s, len))
1683 if (*p == '-' && left > 1) {
1687 if (*p < '0' || *p > '9')
1690 lval = simple_strtoul(p, &p, 0);
1693 if ((len < left) && *p && !isspace(*p))
1700 if (conv(&neg, &lval, i, 1, data))
1707 if (conv(&neg, &lval, i, 0, data))
1710 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1714 if(copy_to_user(s, buf, len))
1721 if (!write && !first && left) {
1722 if(put_user('\n', s))
1729 if (get_user(c, s++))
1745 * proc_dointvec - read a vector of integers
1746 * @table: the sysctl table
1747 * @write: %TRUE if this is a write to the sysctl file
1748 * @filp: the file structure
1749 * @buffer: the user buffer
1750 * @lenp: the size of the user buffer
1751 * @ppos: file position
1753 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1754 * values from/to the user buffer, treated as an ASCII string.
1756 * Returns 0 on success.
1758 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1759 void __user *buffer, size_t *lenp, loff_t *ppos)
1761 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1771 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1773 int write, void *data)
1775 int op = *(int *)data;
1777 int val = *negp ? -*lvalp : *lvalp;
1779 case OP_SET: *valp = val; break;
1780 case OP_AND: *valp &= val; break;
1781 case OP_OR: *valp |= val; break;
1782 case OP_MAX: if(*valp < val)
1785 case OP_MIN: if(*valp > val)
1793 *lvalp = (unsigned long)-val;
1796 *lvalp = (unsigned long)val;
1803 * init may raise the set.
1806 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1807 void __user *buffer, size_t *lenp, loff_t *ppos)
1811 if (!capable(CAP_SYS_MODULE)) {
1815 op = (current->pid == 1) ? OP_SET : OP_AND;
1816 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1817 do_proc_dointvec_bset_conv,&op);
1820 struct do_proc_dointvec_minmax_conv_param {
1825 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1827 int write, void *data)
1829 struct do_proc_dointvec_minmax_conv_param *param = data;
1831 int val = *negp ? -*lvalp : *lvalp;
1832 if ((param->min && *param->min > val) ||
1833 (param->max && *param->max < val))
1840 *lvalp = (unsigned long)-val;
1843 *lvalp = (unsigned long)val;
1850 * proc_dointvec_minmax - read a vector of integers with min/max values
1851 * @table: the sysctl table
1852 * @write: %TRUE if this is a write to the sysctl file
1853 * @filp: the file structure
1854 * @buffer: the user buffer
1855 * @lenp: the size of the user buffer
1856 * @ppos: file position
1858 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1859 * values from/to the user buffer, treated as an ASCII string.
1861 * This routine will ensure the values are within the range specified by
1862 * table->extra1 (min) and table->extra2 (max).
1864 * Returns 0 on success.
1866 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1867 void __user *buffer, size_t *lenp, loff_t *ppos)
1869 struct do_proc_dointvec_minmax_conv_param param = {
1870 .min = (int *) table->extra1,
1871 .max = (int *) table->extra2,
1873 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1874 do_proc_dointvec_minmax_conv, ¶m);
1877 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1879 void __user *buffer,
1880 size_t *lenp, loff_t *ppos,
1881 unsigned long convmul,
1882 unsigned long convdiv)
1884 #define TMPBUFLEN 21
1885 unsigned long *i, *min, *max, val;
1886 int vleft, first=1, neg;
1888 char buf[TMPBUFLEN], *p;
1889 char __user *s = buffer;
1891 if (!table->data || !table->maxlen || !*lenp ||
1892 (*ppos && !write)) {
1897 i = (unsigned long *) table->data;
1898 min = (unsigned long *) table->extra1;
1899 max = (unsigned long *) table->extra2;
1900 vleft = table->maxlen / sizeof(unsigned long);
1903 for (; left && vleft--; i++, min++, max++, first=0) {
1918 if (len > TMPBUFLEN-1)
1920 if (copy_from_user(buf, s, len))
1924 if (*p == '-' && left > 1) {
1928 if (*p < '0' || *p > '9')
1930 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1932 if ((len < left) && *p && !isspace(*p))
1941 if ((min && val < *min) || (max && val > *max))
1948 sprintf(p, "%lu", convdiv * (*i) / convmul);
1952 if(copy_to_user(s, buf, len))
1959 if (!write && !first && left) {
1960 if(put_user('\n', s))
1967 if (get_user(c, s++))
1983 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1984 * @table: the sysctl table
1985 * @write: %TRUE if this is a write to the sysctl file
1986 * @filp: the file structure
1987 * @buffer: the user buffer
1988 * @lenp: the size of the user buffer
1989 * @ppos: file position
1991 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1992 * values from/to the user buffer, treated as an ASCII string.
1994 * This routine will ensure the values are within the range specified by
1995 * table->extra1 (min) and table->extra2 (max).
1997 * Returns 0 on success.
1999 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2000 void __user *buffer, size_t *lenp, loff_t *ppos)
2002 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2006 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2007 * @table: the sysctl table
2008 * @write: %TRUE if this is a write to the sysctl file
2009 * @filp: the file structure
2010 * @buffer: the user buffer
2011 * @lenp: the size of the user buffer
2012 * @ppos: file position
2014 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2015 * values from/to the user buffer, treated as an ASCII string. The values
2016 * are treated as milliseconds, and converted to jiffies when they are stored.
2018 * This routine will ensure the values are within the range specified by
2019 * table->extra1 (min) and table->extra2 (max).
2021 * Returns 0 on success.
2023 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2025 void __user *buffer,
2026 size_t *lenp, loff_t *ppos)
2028 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2029 lenp, ppos, HZ, 1000l);
2033 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2035 int write, void *data)
2038 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2044 lval = (unsigned long)-val;
2047 lval = (unsigned long)val;
2054 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2056 int write, void *data)
2059 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2065 lval = (unsigned long)-val;
2068 lval = (unsigned long)val;
2070 *lvalp = jiffies_to_clock_t(lval);
2075 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2077 int write, void *data)
2080 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2086 lval = (unsigned long)-val;
2089 lval = (unsigned long)val;
2091 *lvalp = jiffies_to_msecs(lval);
2097 * proc_dointvec_jiffies - read a vector of integers as seconds
2098 * @table: the sysctl table
2099 * @write: %TRUE if this is a write to the sysctl file
2100 * @filp: the file structure
2101 * @buffer: the user buffer
2102 * @lenp: the size of the user buffer
2103 * @ppos: file position
2105 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2106 * values from/to the user buffer, treated as an ASCII string.
2107 * The values read are assumed to be in seconds, and are converted into
2110 * Returns 0 on success.
2112 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2113 void __user *buffer, size_t *lenp, loff_t *ppos)
2115 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2116 do_proc_dointvec_jiffies_conv,NULL);
2120 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2121 * @table: the sysctl table
2122 * @write: %TRUE if this is a write to the sysctl file
2123 * @filp: the file structure
2124 * @buffer: the user buffer
2125 * @lenp: the size of the user buffer
2126 * @ppos: pointer to the file position
2128 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2129 * values from/to the user buffer, treated as an ASCII string.
2130 * The values read are assumed to be in 1/USER_HZ seconds, and
2131 * are converted into jiffies.
2133 * Returns 0 on success.
2135 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2136 void __user *buffer, size_t *lenp, loff_t *ppos)
2138 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2139 do_proc_dointvec_userhz_jiffies_conv,NULL);
2143 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2144 * @table: the sysctl table
2145 * @write: %TRUE if this is a write to the sysctl file
2146 * @filp: the file structure
2147 * @buffer: the user buffer
2148 * @lenp: the size of the user buffer
2149 * @ppos: file position
2150 * @ppos: the current position in the file
2152 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2153 * values from/to the user buffer, treated as an ASCII string.
2154 * The values read are assumed to be in 1/1000 seconds, and
2155 * are converted into jiffies.
2157 * Returns 0 on success.
2159 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2160 void __user *buffer, size_t *lenp, loff_t *ppos)
2162 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2163 do_proc_dointvec_ms_jiffies_conv, NULL);
2166 #else /* CONFIG_PROC_FS */
2168 int proc_dostring(ctl_table *table, int write, struct file *filp,
2169 void __user *buffer, size_t *lenp, loff_t *ppos)
2174 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2175 void __user *buffer, size_t *lenp, loff_t *ppos)
2180 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2181 void __user *buffer, size_t *lenp, loff_t *ppos)
2186 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2187 void __user *buffer, size_t *lenp, loff_t *ppos)
2192 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2193 void __user *buffer, size_t *lenp, loff_t *ppos)
2198 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2199 void __user *buffer, size_t *lenp, loff_t *ppos)
2204 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2205 void __user *buffer, size_t *lenp, loff_t *ppos)
2210 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2211 void __user *buffer, size_t *lenp, loff_t *ppos)
2216 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2217 void __user *buffer, size_t *lenp, loff_t *ppos)
2222 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2224 void __user *buffer,
2225 size_t *lenp, loff_t *ppos)
2231 #endif /* CONFIG_PROC_FS */
2235 * General sysctl support routines
2238 /* The generic string strategy routine: */
2239 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2240 void __user *oldval, size_t __user *oldlenp,
2241 void __user *newval, size_t newlen, void **context)
2243 if (!table->data || !table->maxlen)
2246 if (oldval && oldlenp) {
2248 if (get_user(bufsize, oldlenp))
2251 size_t len = strlen(table->data), copied;
2253 /* This shouldn't trigger for a well-formed sysctl */
2254 if (len > table->maxlen)
2255 len = table->maxlen;
2257 /* Copy up to a max of bufsize-1 bytes of the string */
2258 copied = (len >= bufsize) ? bufsize - 1 : len;
2260 if (copy_to_user(oldval, table->data, copied) ||
2261 put_user(0, (char __user *)(oldval + copied)))
2263 if (put_user(len, oldlenp))
2267 if (newval && newlen) {
2268 size_t len = newlen;
2269 if (len > table->maxlen)
2270 len = table->maxlen;
2271 if(copy_from_user(table->data, newval, len))
2273 if (len == table->maxlen)
2275 ((char *) table->data)[len] = 0;
2281 * This function makes sure that all of the integers in the vector
2282 * are between the minimum and maximum values given in the arrays
2283 * table->extra1 and table->extra2, respectively.
2285 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2286 void __user *oldval, size_t __user *oldlenp,
2287 void __user *newval, size_t newlen, void **context)
2290 if (newval && newlen) {
2291 int __user *vec = (int __user *) newval;
2292 int *min = (int *) table->extra1;
2293 int *max = (int *) table->extra2;
2297 if (newlen % sizeof(int) != 0)
2300 if (!table->extra1 && !table->extra2)
2303 if (newlen > table->maxlen)
2304 newlen = table->maxlen;
2305 length = newlen / sizeof(int);
2307 for (i = 0; i < length; i++) {
2309 if (get_user(value, vec + i))
2311 if (min && value < min[i])
2313 if (max && value > max[i])
2320 /* Strategy function to convert jiffies to seconds */
2321 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2322 void __user *oldval, size_t __user *oldlenp,
2323 void __user *newval, size_t newlen, void **context)
2328 if (get_user(olen, oldlenp))
2330 if (olen!=sizeof(int))
2333 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2334 (oldlenp && put_user(sizeof(int),oldlenp)))
2337 if (newval && newlen) {
2339 if (newlen != sizeof(int))
2341 if (get_user(new, (int __user *)newval))
2343 *(int *)(table->data) = new*HZ;
2348 /* Strategy function to convert jiffies to seconds */
2349 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2350 void __user *oldval, size_t __user *oldlenp,
2351 void __user *newval, size_t newlen, void **context)
2356 if (get_user(olen, oldlenp))
2358 if (olen!=sizeof(int))
2361 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2362 (oldlenp && put_user(sizeof(int),oldlenp)))
2365 if (newval && newlen) {
2367 if (newlen != sizeof(int))
2369 if (get_user(new, (int __user *)newval))
2371 *(int *)(table->data) = msecs_to_jiffies(new);
2376 #else /* CONFIG_SYSCTL */
2379 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2384 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2385 void __user *oldval, size_t __user *oldlenp,
2386 void __user *newval, size_t newlen, void **context)
2391 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2392 void __user *oldval, size_t __user *oldlenp,
2393 void __user *newval, size_t newlen, void **context)
2398 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2399 void __user *oldval, size_t __user *oldlenp,
2400 void __user *newval, size_t newlen, void **context)
2405 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2406 void __user *oldval, size_t __user *oldlenp,
2407 void __user *newval, size_t newlen, void **context)
2412 int proc_dostring(ctl_table *table, int write, struct file *filp,
2413 void __user *buffer, size_t *lenp, loff_t *ppos)
2418 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2419 void __user *buffer, size_t *lenp, loff_t *ppos)
2424 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2425 void __user *buffer, size_t *lenp, loff_t *ppos)
2430 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2431 void __user *buffer, size_t *lenp, loff_t *ppos)
2436 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2437 void __user *buffer, size_t *lenp, loff_t *ppos)
2442 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2443 void __user *buffer, size_t *lenp, loff_t *ppos)
2448 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2449 void __user *buffer, size_t *lenp, loff_t *ppos)
2454 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2455 void __user *buffer, size_t *lenp, loff_t *ppos)
2460 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2462 void __user *buffer,
2463 size_t *lenp, loff_t *ppos)
2468 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2474 void unregister_sysctl_table(struct ctl_table_header * table)
2478 #endif /* CONFIG_SYSCTL */
2481 * No sense putting this after each symbol definition, twice,
2482 * exception granted :-)
2484 EXPORT_SYMBOL(proc_dointvec);
2485 EXPORT_SYMBOL(proc_dointvec_jiffies);
2486 EXPORT_SYMBOL(proc_dointvec_minmax);
2487 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2488 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2489 EXPORT_SYMBOL(proc_dostring);
2490 EXPORT_SYMBOL(proc_doulongvec_minmax);
2491 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2492 EXPORT_SYMBOL(register_sysctl_table);
2493 EXPORT_SYMBOL(sysctl_intvec);
2494 EXPORT_SYMBOL(sysctl_jiffies);
2495 EXPORT_SYMBOL(sysctl_ms_jiffies);
2496 EXPORT_SYMBOL(sysctl_string);
2497 EXPORT_SYMBOL(unregister_sysctl_table);