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 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
54 void __user *buffer, size_t *lenp, loff_t *ppos);
56 #if defined(CONFIG_SYSCTL)
58 /* External variables not in a header file. */
60 extern int sysctl_overcommit_memory;
61 extern int sysctl_overcommit_ratio;
62 extern int max_threads;
63 extern int sysrq_enabled;
64 extern int core_uses_pid;
65 extern int suid_dumpable;
66 extern char core_pattern[];
69 extern int min_free_kbytes;
70 extern int printk_ratelimit_jiffies;
71 extern int printk_ratelimit_burst;
72 extern int pid_max_min, pid_max_max;
73 extern int sysctl_drop_caches;
74 extern int percpu_pagelist_fraction;
76 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
77 int unknown_nmi_panic;
78 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
79 void __user *, size_t *, loff_t *);
82 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83 static int maxolduid = 65535;
85 static int min_percpu_pagelist_fract = 8;
87 static int ngroups_max = NGROUPS_MAX;
90 extern char modprobe_path[];
92 #ifdef CONFIG_CHR_DEV_SG
93 extern int sg_big_buff;
96 extern size_t shm_ctlmax;
97 extern size_t shm_ctlall;
98 extern int shm_ctlmni;
99 extern int msg_ctlmax;
100 extern int msg_ctlmnb;
101 extern int msg_ctlmni;
102 extern int sem_ctls[];
106 extern char reboot_command [];
107 extern int stop_a_enabled;
108 extern int scons_pwroff;
112 extern int pwrsw_enabled;
113 extern int unaligned_enabled;
117 #ifdef CONFIG_MATHEMU
118 extern int sysctl_ieee_emulation_warnings;
120 extern int sysctl_userprocess_debug;
121 extern int spin_retry;
124 extern int sysctl_hz_timer;
126 #ifdef CONFIG_BSD_PROCESS_ACCT
127 extern int acct_parm[];
131 extern int no_unaligned_warning;
134 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
135 ctl_table *, void **);
136 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
137 void __user *buffer, size_t *lenp, loff_t *ppos);
139 static ctl_table root_table[];
140 static struct ctl_table_header root_table_header =
141 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
143 static ctl_table kern_table[];
144 static ctl_table vm_table[];
145 static ctl_table proc_table[];
146 static ctl_table fs_table[];
147 static ctl_table debug_table[];
148 static ctl_table dev_table[];
149 extern ctl_table random_table[];
150 #ifdef CONFIG_UNIX98_PTYS
151 extern ctl_table pty_table[];
153 #ifdef CONFIG_INOTIFY
154 extern ctl_table inotify_table[];
157 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
158 int sysctl_legacy_va_layout;
161 /* /proc declarations: */
163 #ifdef CONFIG_PROC_FS
165 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
166 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
167 static int proc_opensys(struct inode *, struct file *);
169 struct file_operations proc_sys_file_operations = {
170 .open = proc_opensys,
171 .read = proc_readsys,
172 .write = proc_writesys,
175 extern struct proc_dir_entry *proc_sys_root;
177 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
178 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
181 /* The default sysctl tables: */
183 static ctl_table root_table[] = {
185 .ctl_name = CTL_KERN,
186 .procname = "kernel",
205 .ctl_name = CTL_PROC,
217 .ctl_name = CTL_DEBUG,
220 .child = debug_table,
232 static ctl_table kern_table[] = {
234 .ctl_name = KERN_OSTYPE,
235 .procname = "ostype",
236 .data = system_utsname.sysname,
237 .maxlen = sizeof(system_utsname.sysname),
239 .proc_handler = &proc_doutsstring,
240 .strategy = &sysctl_string,
243 .ctl_name = KERN_OSRELEASE,
244 .procname = "osrelease",
245 .data = system_utsname.release,
246 .maxlen = sizeof(system_utsname.release),
248 .proc_handler = &proc_doutsstring,
249 .strategy = &sysctl_string,
252 .ctl_name = KERN_VERSION,
253 .procname = "version",
254 .data = system_utsname.version,
255 .maxlen = sizeof(system_utsname.version),
257 .proc_handler = &proc_doutsstring,
258 .strategy = &sysctl_string,
261 .ctl_name = KERN_NODENAME,
262 .procname = "hostname",
263 .data = system_utsname.nodename,
264 .maxlen = sizeof(system_utsname.nodename),
266 .proc_handler = &proc_doutsstring,
267 .strategy = &sysctl_string,
270 .ctl_name = KERN_DOMAINNAME,
271 .procname = "domainname",
272 .data = system_utsname.domainname,
273 .maxlen = sizeof(system_utsname.domainname),
275 .proc_handler = &proc_doutsstring,
276 .strategy = &sysctl_string,
279 .ctl_name = KERN_PANIC,
281 .data = &panic_timeout,
282 .maxlen = sizeof(int),
284 .proc_handler = &proc_dointvec,
287 .ctl_name = KERN_CORE_USES_PID,
288 .procname = "core_uses_pid",
289 .data = &core_uses_pid,
290 .maxlen = sizeof(int),
292 .proc_handler = &proc_dointvec,
295 .ctl_name = KERN_CORE_PATTERN,
296 .procname = "core_pattern",
297 .data = core_pattern,
300 .proc_handler = &proc_dostring,
301 .strategy = &sysctl_string,
304 .ctl_name = KERN_TAINTED,
305 .procname = "tainted",
307 .maxlen = sizeof(int),
309 .proc_handler = &proc_dointvec,
312 .ctl_name = KERN_CAP_BSET,
313 .procname = "cap-bound",
315 .maxlen = sizeof(kernel_cap_t),
317 .proc_handler = &proc_dointvec_bset,
319 #ifdef CONFIG_BLK_DEV_INITRD
321 .ctl_name = KERN_REALROOTDEV,
322 .procname = "real-root-dev",
323 .data = &real_root_dev,
324 .maxlen = sizeof(int),
326 .proc_handler = &proc_dointvec,
331 .ctl_name = KERN_SPARC_REBOOT,
332 .procname = "reboot-cmd",
333 .data = reboot_command,
336 .proc_handler = &proc_dostring,
337 .strategy = &sysctl_string,
340 .ctl_name = KERN_SPARC_STOP_A,
341 .procname = "stop-a",
342 .data = &stop_a_enabled,
343 .maxlen = sizeof (int),
345 .proc_handler = &proc_dointvec,
348 .ctl_name = KERN_SPARC_SCONS_PWROFF,
349 .procname = "scons-poweroff",
350 .data = &scons_pwroff,
351 .maxlen = sizeof (int),
353 .proc_handler = &proc_dointvec,
358 .ctl_name = KERN_HPPA_PWRSW,
359 .procname = "soft-power",
360 .data = &pwrsw_enabled,
361 .maxlen = sizeof (int),
363 .proc_handler = &proc_dointvec,
366 .ctl_name = KERN_HPPA_UNALIGNED,
367 .procname = "unaligned-trap",
368 .data = &unaligned_enabled,
369 .maxlen = sizeof (int),
371 .proc_handler = &proc_dointvec,
375 .ctl_name = KERN_CTLALTDEL,
376 .procname = "ctrl-alt-del",
378 .maxlen = sizeof(int),
380 .proc_handler = &proc_dointvec,
383 .ctl_name = KERN_PRINTK,
384 .procname = "printk",
385 .data = &console_loglevel,
386 .maxlen = 4*sizeof(int),
388 .proc_handler = &proc_dointvec,
392 .ctl_name = KERN_MODPROBE,
393 .procname = "modprobe",
394 .data = &modprobe_path,
395 .maxlen = KMOD_PATH_LEN,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
401 #ifdef CONFIG_HOTPLUG
403 .ctl_name = KERN_HOTPLUG,
404 .procname = "hotplug",
405 .data = &uevent_helper,
406 .maxlen = UEVENT_HELPER_PATH_LEN,
408 .proc_handler = &proc_dostring,
409 .strategy = &sysctl_string,
412 #ifdef CONFIG_CHR_DEV_SG
414 .ctl_name = KERN_SG_BIG_BUFF,
415 .procname = "sg-big-buff",
416 .data = &sg_big_buff,
417 .maxlen = sizeof (int),
419 .proc_handler = &proc_dointvec,
422 #ifdef CONFIG_BSD_PROCESS_ACCT
424 .ctl_name = KERN_ACCT,
427 .maxlen = 3*sizeof(int),
429 .proc_handler = &proc_dointvec,
432 #ifdef CONFIG_SYSVIPC
434 .ctl_name = KERN_SHMMAX,
435 .procname = "shmmax",
437 .maxlen = sizeof (size_t),
439 .proc_handler = &proc_doulongvec_minmax,
442 .ctl_name = KERN_SHMALL,
443 .procname = "shmall",
445 .maxlen = sizeof (size_t),
447 .proc_handler = &proc_doulongvec_minmax,
450 .ctl_name = KERN_SHMMNI,
451 .procname = "shmmni",
453 .maxlen = sizeof (int),
455 .proc_handler = &proc_dointvec,
458 .ctl_name = KERN_MSGMAX,
459 .procname = "msgmax",
461 .maxlen = sizeof (int),
463 .proc_handler = &proc_dointvec,
466 .ctl_name = KERN_MSGMNI,
467 .procname = "msgmni",
469 .maxlen = sizeof (int),
471 .proc_handler = &proc_dointvec,
474 .ctl_name = KERN_MSGMNB,
475 .procname = "msgmnb",
477 .maxlen = sizeof (int),
479 .proc_handler = &proc_dointvec,
482 .ctl_name = KERN_SEM,
485 .maxlen = 4*sizeof (int),
487 .proc_handler = &proc_dointvec,
490 #ifdef CONFIG_MAGIC_SYSRQ
492 .ctl_name = KERN_SYSRQ,
494 .data = &sysrq_enabled,
495 .maxlen = sizeof (int),
497 .proc_handler = &proc_dointvec,
501 .ctl_name = KERN_CADPID,
502 .procname = "cad_pid",
504 .maxlen = sizeof (int),
506 .proc_handler = &proc_dointvec,
509 .ctl_name = KERN_MAX_THREADS,
510 .procname = "threads-max",
511 .data = &max_threads,
512 .maxlen = sizeof(int),
514 .proc_handler = &proc_dointvec,
517 .ctl_name = KERN_RANDOM,
518 .procname = "random",
520 .child = random_table,
522 #ifdef CONFIG_UNIX98_PTYS
524 .ctl_name = KERN_PTY,
531 .ctl_name = KERN_OVERFLOWUID,
532 .procname = "overflowuid",
533 .data = &overflowuid,
534 .maxlen = sizeof(int),
536 .proc_handler = &proc_dointvec_minmax,
537 .strategy = &sysctl_intvec,
538 .extra1 = &minolduid,
539 .extra2 = &maxolduid,
542 .ctl_name = KERN_OVERFLOWGID,
543 .procname = "overflowgid",
544 .data = &overflowgid,
545 .maxlen = sizeof(int),
547 .proc_handler = &proc_dointvec_minmax,
548 .strategy = &sysctl_intvec,
549 .extra1 = &minolduid,
550 .extra2 = &maxolduid,
553 #ifdef CONFIG_MATHEMU
555 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
556 .procname = "ieee_emulation_warnings",
557 .data = &sysctl_ieee_emulation_warnings,
558 .maxlen = sizeof(int),
560 .proc_handler = &proc_dointvec,
563 #ifdef CONFIG_NO_IDLE_HZ
565 .ctl_name = KERN_HZ_TIMER,
566 .procname = "hz_timer",
567 .data = &sysctl_hz_timer,
568 .maxlen = sizeof(int),
570 .proc_handler = &proc_dointvec,
574 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
575 .procname = "userprocess_debug",
576 .data = &sysctl_userprocess_debug,
577 .maxlen = sizeof(int),
579 .proc_handler = &proc_dointvec,
583 .ctl_name = KERN_PIDMAX,
584 .procname = "pid_max",
586 .maxlen = sizeof (int),
588 .proc_handler = &proc_dointvec_minmax,
589 .strategy = sysctl_intvec,
590 .extra1 = &pid_max_min,
591 .extra2 = &pid_max_max,
594 .ctl_name = KERN_PANIC_ON_OOPS,
595 .procname = "panic_on_oops",
596 .data = &panic_on_oops,
597 .maxlen = sizeof(int),
599 .proc_handler = &proc_dointvec,
602 .ctl_name = KERN_PRINTK_RATELIMIT,
603 .procname = "printk_ratelimit",
604 .data = &printk_ratelimit_jiffies,
605 .maxlen = sizeof(int),
607 .proc_handler = &proc_dointvec_jiffies,
608 .strategy = &sysctl_jiffies,
611 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
612 .procname = "printk_ratelimit_burst",
613 .data = &printk_ratelimit_burst,
614 .maxlen = sizeof(int),
616 .proc_handler = &proc_dointvec,
619 .ctl_name = KERN_NGROUPS_MAX,
620 .procname = "ngroups_max",
621 .data = &ngroups_max,
622 .maxlen = sizeof (int),
624 .proc_handler = &proc_dointvec,
626 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
628 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
629 .procname = "unknown_nmi_panic",
630 .data = &unknown_nmi_panic,
631 .maxlen = sizeof (int),
633 .proc_handler = &proc_unknown_nmi_panic,
636 #if defined(CONFIG_X86)
638 .ctl_name = KERN_BOOTLOADER_TYPE,
639 .procname = "bootloader_type",
640 .data = &bootloader_type,
641 .maxlen = sizeof (int),
643 .proc_handler = &proc_dointvec,
646 #if defined(CONFIG_MMU)
648 .ctl_name = KERN_RANDOMIZE,
649 .procname = "randomize_va_space",
650 .data = &randomize_va_space,
651 .maxlen = sizeof(int),
653 .proc_handler = &proc_dointvec,
656 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
658 .ctl_name = KERN_SPIN_RETRY,
659 .procname = "spin_retry",
661 .maxlen = sizeof (int),
663 .proc_handler = &proc_dointvec,
666 #ifdef CONFIG_ACPI_SLEEP
668 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
669 .procname = "acpi_video_flags",
670 .data = &acpi_video_flags,
671 .maxlen = sizeof (unsigned long),
673 .proc_handler = &proc_doulongvec_minmax,
678 .ctl_name = KERN_IA64_UNALIGNED,
679 .procname = "ignore-unaligned-usertrap",
680 .data = &no_unaligned_warning,
681 .maxlen = sizeof (int),
683 .proc_handler = &proc_dointvec,
689 /* Constants for minimum and maximum testing in vm_table.
690 We use these as one-element integer vectors. */
692 static int one_hundred = 100;
695 static ctl_table vm_table[] = {
697 .ctl_name = VM_OVERCOMMIT_MEMORY,
698 .procname = "overcommit_memory",
699 .data = &sysctl_overcommit_memory,
700 .maxlen = sizeof(sysctl_overcommit_memory),
702 .proc_handler = &proc_dointvec,
705 .ctl_name = VM_OVERCOMMIT_RATIO,
706 .procname = "overcommit_ratio",
707 .data = &sysctl_overcommit_ratio,
708 .maxlen = sizeof(sysctl_overcommit_ratio),
710 .proc_handler = &proc_dointvec,
713 .ctl_name = VM_PAGE_CLUSTER,
714 .procname = "page-cluster",
715 .data = &page_cluster,
716 .maxlen = sizeof(int),
718 .proc_handler = &proc_dointvec,
721 .ctl_name = VM_DIRTY_BACKGROUND,
722 .procname = "dirty_background_ratio",
723 .data = &dirty_background_ratio,
724 .maxlen = sizeof(dirty_background_ratio),
726 .proc_handler = &proc_dointvec_minmax,
727 .strategy = &sysctl_intvec,
729 .extra2 = &one_hundred,
732 .ctl_name = VM_DIRTY_RATIO,
733 .procname = "dirty_ratio",
734 .data = &vm_dirty_ratio,
735 .maxlen = sizeof(vm_dirty_ratio),
737 .proc_handler = &proc_dointvec_minmax,
738 .strategy = &sysctl_intvec,
740 .extra2 = &one_hundred,
743 .ctl_name = VM_DIRTY_WB_CS,
744 .procname = "dirty_writeback_centisecs",
745 .data = &dirty_writeback_centisecs,
746 .maxlen = sizeof(dirty_writeback_centisecs),
748 .proc_handler = &dirty_writeback_centisecs_handler,
751 .ctl_name = VM_DIRTY_EXPIRE_CS,
752 .procname = "dirty_expire_centisecs",
753 .data = &dirty_expire_centisecs,
754 .maxlen = sizeof(dirty_expire_centisecs),
756 .proc_handler = &proc_dointvec,
759 .ctl_name = VM_NR_PDFLUSH_THREADS,
760 .procname = "nr_pdflush_threads",
761 .data = &nr_pdflush_threads,
762 .maxlen = sizeof nr_pdflush_threads,
763 .mode = 0444 /* read-only*/,
764 .proc_handler = &proc_dointvec,
767 .ctl_name = VM_SWAPPINESS,
768 .procname = "swappiness",
769 .data = &vm_swappiness,
770 .maxlen = sizeof(vm_swappiness),
772 .proc_handler = &proc_dointvec_minmax,
773 .strategy = &sysctl_intvec,
775 .extra2 = &one_hundred,
777 #ifdef CONFIG_HUGETLB_PAGE
779 .ctl_name = VM_HUGETLB_PAGES,
780 .procname = "nr_hugepages",
781 .data = &max_huge_pages,
782 .maxlen = sizeof(unsigned long),
784 .proc_handler = &hugetlb_sysctl_handler,
785 .extra1 = (void *)&hugetlb_zero,
786 .extra2 = (void *)&hugetlb_infinity,
789 .ctl_name = VM_HUGETLB_GROUP,
790 .procname = "hugetlb_shm_group",
791 .data = &sysctl_hugetlb_shm_group,
792 .maxlen = sizeof(gid_t),
794 .proc_handler = &proc_dointvec,
798 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
799 .procname = "lowmem_reserve_ratio",
800 .data = &sysctl_lowmem_reserve_ratio,
801 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
803 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
804 .strategy = &sysctl_intvec,
807 .ctl_name = VM_DROP_PAGECACHE,
808 .procname = "drop_caches",
809 .data = &sysctl_drop_caches,
810 .maxlen = sizeof(int),
812 .proc_handler = drop_caches_sysctl_handler,
813 .strategy = &sysctl_intvec,
816 .ctl_name = VM_MIN_FREE_KBYTES,
817 .procname = "min_free_kbytes",
818 .data = &min_free_kbytes,
819 .maxlen = sizeof(min_free_kbytes),
821 .proc_handler = &min_free_kbytes_sysctl_handler,
822 .strategy = &sysctl_intvec,
826 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
827 .procname = "percpu_pagelist_fraction",
828 .data = &percpu_pagelist_fraction,
829 .maxlen = sizeof(percpu_pagelist_fraction),
831 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
832 .strategy = &sysctl_intvec,
833 .extra1 = &min_percpu_pagelist_fract,
837 .ctl_name = VM_MAX_MAP_COUNT,
838 .procname = "max_map_count",
839 .data = &sysctl_max_map_count,
840 .maxlen = sizeof(sysctl_max_map_count),
842 .proc_handler = &proc_dointvec
846 .ctl_name = VM_LAPTOP_MODE,
847 .procname = "laptop_mode",
848 .data = &laptop_mode,
849 .maxlen = sizeof(laptop_mode),
851 .proc_handler = &proc_dointvec,
852 .strategy = &sysctl_intvec,
856 .ctl_name = VM_BLOCK_DUMP,
857 .procname = "block_dump",
859 .maxlen = sizeof(block_dump),
861 .proc_handler = &proc_dointvec,
862 .strategy = &sysctl_intvec,
866 .ctl_name = VM_VFS_CACHE_PRESSURE,
867 .procname = "vfs_cache_pressure",
868 .data = &sysctl_vfs_cache_pressure,
869 .maxlen = sizeof(sysctl_vfs_cache_pressure),
871 .proc_handler = &proc_dointvec,
872 .strategy = &sysctl_intvec,
875 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
877 .ctl_name = VM_LEGACY_VA_LAYOUT,
878 .procname = "legacy_va_layout",
879 .data = &sysctl_legacy_va_layout,
880 .maxlen = sizeof(sysctl_legacy_va_layout),
882 .proc_handler = &proc_dointvec,
883 .strategy = &sysctl_intvec,
889 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
890 .procname = "swap_token_timeout",
891 .data = &swap_token_default_timeout,
892 .maxlen = sizeof(swap_token_default_timeout),
894 .proc_handler = &proc_dointvec_jiffies,
895 .strategy = &sysctl_jiffies,
900 .ctl_name = VM_ZONE_RECLAIM_MODE,
901 .procname = "zone_reclaim_mode",
902 .data = &zone_reclaim_mode,
903 .maxlen = sizeof(zone_reclaim_mode),
905 .proc_handler = &proc_dointvec,
906 .strategy = &sysctl_intvec,
910 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
911 .procname = "zone_reclaim_interval",
912 .data = &zone_reclaim_interval,
913 .maxlen = sizeof(zone_reclaim_interval),
915 .proc_handler = &proc_dointvec_jiffies,
916 .strategy = &sysctl_jiffies,
922 static ctl_table proc_table[] = {
926 static ctl_table fs_table[] = {
928 .ctl_name = FS_NRINODE,
929 .procname = "inode-nr",
930 .data = &inodes_stat,
931 .maxlen = 2*sizeof(int),
933 .proc_handler = &proc_dointvec,
936 .ctl_name = FS_STATINODE,
937 .procname = "inode-state",
938 .data = &inodes_stat,
939 .maxlen = 7*sizeof(int),
941 .proc_handler = &proc_dointvec,
944 .ctl_name = FS_NRFILE,
945 .procname = "file-nr",
947 .maxlen = 3*sizeof(int),
949 .proc_handler = &proc_nr_files,
952 .ctl_name = FS_MAXFILE,
953 .procname = "file-max",
954 .data = &files_stat.max_files,
955 .maxlen = sizeof(int),
957 .proc_handler = &proc_dointvec,
960 .ctl_name = FS_DENTRY,
961 .procname = "dentry-state",
962 .data = &dentry_stat,
963 .maxlen = 6*sizeof(int),
965 .proc_handler = &proc_dointvec,
968 .ctl_name = FS_OVERFLOWUID,
969 .procname = "overflowuid",
970 .data = &fs_overflowuid,
971 .maxlen = sizeof(int),
973 .proc_handler = &proc_dointvec_minmax,
974 .strategy = &sysctl_intvec,
975 .extra1 = &minolduid,
976 .extra2 = &maxolduid,
979 .ctl_name = FS_OVERFLOWGID,
980 .procname = "overflowgid",
981 .data = &fs_overflowgid,
982 .maxlen = sizeof(int),
984 .proc_handler = &proc_dointvec_minmax,
985 .strategy = &sysctl_intvec,
986 .extra1 = &minolduid,
987 .extra2 = &maxolduid,
990 .ctl_name = FS_LEASES,
991 .procname = "leases-enable",
992 .data = &leases_enable,
993 .maxlen = sizeof(int),
995 .proc_handler = &proc_dointvec,
997 #ifdef CONFIG_DNOTIFY
999 .ctl_name = FS_DIR_NOTIFY,
1000 .procname = "dir-notify-enable",
1001 .data = &dir_notify_enable,
1002 .maxlen = sizeof(int),
1004 .proc_handler = &proc_dointvec,
1009 .ctl_name = FS_LEASE_TIME,
1010 .procname = "lease-break-time",
1011 .data = &lease_break_time,
1012 .maxlen = sizeof(int),
1014 .proc_handler = &proc_dointvec,
1017 .ctl_name = FS_AIO_NR,
1018 .procname = "aio-nr",
1020 .maxlen = sizeof(aio_nr),
1022 .proc_handler = &proc_doulongvec_minmax,
1025 .ctl_name = FS_AIO_MAX_NR,
1026 .procname = "aio-max-nr",
1027 .data = &aio_max_nr,
1028 .maxlen = sizeof(aio_max_nr),
1030 .proc_handler = &proc_doulongvec_minmax,
1032 #ifdef CONFIG_INOTIFY
1034 .ctl_name = FS_INOTIFY,
1035 .procname = "inotify",
1037 .child = inotify_table,
1042 .ctl_name = KERN_SETUID_DUMPABLE,
1043 .procname = "suid_dumpable",
1044 .data = &suid_dumpable,
1045 .maxlen = sizeof(int),
1047 .proc_handler = &proc_dointvec,
1052 static ctl_table debug_table[] = {
1056 static ctl_table dev_table[] = {
1060 extern void init_irq_proc (void);
1062 static DEFINE_SPINLOCK(sysctl_lock);
1064 /* called under sysctl_lock */
1065 static int use_table(struct ctl_table_header *p)
1067 if (unlikely(p->unregistering))
1073 /* called under sysctl_lock */
1074 static void unuse_table(struct ctl_table_header *p)
1077 if (unlikely(p->unregistering))
1078 complete(p->unregistering);
1081 /* called under sysctl_lock, will reacquire if has to wait */
1082 static void start_unregistering(struct ctl_table_header *p)
1085 * if p->used is 0, nobody will ever touch that entry again;
1086 * we'll eliminate all paths to it before dropping sysctl_lock
1088 if (unlikely(p->used)) {
1089 struct completion wait;
1090 init_completion(&wait);
1091 p->unregistering = &wait;
1092 spin_unlock(&sysctl_lock);
1093 wait_for_completion(&wait);
1094 spin_lock(&sysctl_lock);
1097 * do not remove from the list until nobody holds it; walking the
1098 * list in do_sysctl() relies on that.
1100 list_del_init(&p->ctl_entry);
1103 void __init sysctl_init(void)
1105 #ifdef CONFIG_PROC_FS
1106 register_proc_table(root_table, proc_sys_root, &root_table_header);
1111 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1112 void __user *newval, size_t newlen)
1114 struct list_head *tmp;
1115 int error = -ENOTDIR;
1117 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1121 if (!oldlenp || get_user(old_len, oldlenp))
1124 spin_lock(&sysctl_lock);
1125 tmp = &root_table_header.ctl_entry;
1127 struct ctl_table_header *head =
1128 list_entry(tmp, struct ctl_table_header, ctl_entry);
1129 void *context = NULL;
1131 if (!use_table(head))
1134 spin_unlock(&sysctl_lock);
1136 error = parse_table(name, nlen, oldval, oldlenp,
1137 newval, newlen, head->ctl_table,
1141 spin_lock(&sysctl_lock);
1143 if (error != -ENOTDIR)
1145 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1146 spin_unlock(&sysctl_lock);
1150 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1152 struct __sysctl_args tmp;
1155 if (copy_from_user(&tmp, args, sizeof(tmp)))
1159 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1160 tmp.newval, tmp.newlen);
1166 * ctl_perm does NOT grant the superuser all rights automatically, because
1167 * some sysctl variables are readonly even to root.
1170 static int test_perm(int mode, int op)
1174 else if (in_egroup_p(0))
1176 if ((mode & op & 0007) == op)
1181 static inline int ctl_perm(ctl_table *table, int op)
1184 error = security_sysctl(table, op);
1187 return test_perm(table->mode, op);
1190 static int parse_table(int __user *name, int nlen,
1191 void __user *oldval, size_t __user *oldlenp,
1192 void __user *newval, size_t newlen,
1193 ctl_table *table, void **context)
1199 if (get_user(n, name))
1201 for ( ; table->ctl_name; table++) {
1202 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1205 if (ctl_perm(table, 001))
1207 if (table->strategy) {
1208 error = table->strategy(
1211 newval, newlen, context);
1217 table = table->child;
1220 error = do_sysctl_strategy(table, name, nlen,
1222 newval, newlen, context);
1229 /* Perform the actual read/write of a sysctl table entry. */
1230 int do_sysctl_strategy (ctl_table *table,
1231 int __user *name, int nlen,
1232 void __user *oldval, size_t __user *oldlenp,
1233 void __user *newval, size_t newlen, void **context)
1242 if (ctl_perm(table, op))
1245 if (table->strategy) {
1246 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1247 newval, newlen, context);
1254 /* If there is no strategy routine, or if the strategy returns
1255 * zero, proceed with automatic r/w */
1256 if (table->data && table->maxlen) {
1257 if (oldval && oldlenp) {
1258 if (get_user(len, oldlenp))
1261 if (len > table->maxlen)
1262 len = table->maxlen;
1263 if(copy_to_user(oldval, table->data, len))
1265 if(put_user(len, oldlenp))
1269 if (newval && newlen) {
1271 if (len > table->maxlen)
1272 len = table->maxlen;
1273 if(copy_from_user(table->data, newval, len))
1281 * register_sysctl_table - register a sysctl hierarchy
1282 * @table: the top-level table structure
1283 * @insert_at_head: whether the entry should be inserted in front or at the end
1285 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1286 * array. An entry with a ctl_name of 0 terminates the table.
1288 * The members of the &ctl_table structure are used as follows:
1290 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1291 * must be unique within that level of sysctl
1293 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1294 * enter a sysctl file
1296 * data - a pointer to data for use by proc_handler
1298 * maxlen - the maximum size in bytes of the data
1300 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1302 * child - a pointer to the child sysctl table if this entry is a directory, or
1305 * proc_handler - the text handler routine (described below)
1307 * strategy - the strategy routine (described below)
1309 * de - for internal use by the sysctl routines
1311 * extra1, extra2 - extra pointers usable by the proc handler routines
1313 * Leaf nodes in the sysctl tree will be represented by a single file
1314 * under /proc; non-leaf nodes will be represented by directories.
1316 * sysctl(2) can automatically manage read and write requests through
1317 * the sysctl table. The data and maxlen fields of the ctl_table
1318 * struct enable minimal validation of the values being written to be
1319 * performed, and the mode field allows minimal authentication.
1321 * More sophisticated management can be enabled by the provision of a
1322 * strategy routine with the table entry. This will be called before
1323 * any automatic read or write of the data is performed.
1325 * The strategy routine may return
1327 * < 0 - Error occurred (error is passed to user process)
1329 * 0 - OK - proceed with automatic read or write.
1331 * > 0 - OK - read or write has been done by the strategy routine, so
1332 * return immediately.
1334 * There must be a proc_handler routine for any terminal nodes
1335 * mirrored under /proc/sys (non-terminals are handled by a built-in
1336 * directory handler). Several default handlers are available to
1337 * cover common cases -
1339 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1340 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1341 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1343 * It is the handler's job to read the input buffer from user memory
1344 * and process it. The handler should return 0 on success.
1346 * This routine returns %NULL on a failure to register, and a pointer
1347 * to the table header on success.
1349 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1352 struct ctl_table_header *tmp;
1353 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1356 tmp->ctl_table = table;
1357 INIT_LIST_HEAD(&tmp->ctl_entry);
1359 tmp->unregistering = NULL;
1360 spin_lock(&sysctl_lock);
1362 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1364 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1365 spin_unlock(&sysctl_lock);
1366 #ifdef CONFIG_PROC_FS
1367 register_proc_table(table, proc_sys_root, tmp);
1373 * unregister_sysctl_table - unregister a sysctl table hierarchy
1374 * @header: the header returned from register_sysctl_table
1376 * Unregisters the sysctl table and all children. proc entries may not
1377 * actually be removed until they are no longer used by anyone.
1379 void unregister_sysctl_table(struct ctl_table_header * header)
1382 spin_lock(&sysctl_lock);
1383 start_unregistering(header);
1384 #ifdef CONFIG_PROC_FS
1385 unregister_proc_table(header->ctl_table, proc_sys_root);
1387 spin_unlock(&sysctl_lock);
1395 #ifdef CONFIG_PROC_FS
1397 /* Scan the sysctl entries in table and add them all into /proc */
1398 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1400 struct proc_dir_entry *de;
1404 for (; table->ctl_name; table++) {
1405 /* Can't do anything without a proc name. */
1406 if (!table->procname)
1408 /* Maybe we can't do anything with it... */
1409 if (!table->proc_handler && !table->child) {
1410 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1415 len = strlen(table->procname);
1419 if (table->proc_handler)
1423 for (de = root->subdir; de; de = de->next) {
1424 if (proc_match(len, table->procname, de))
1427 /* If the subdir exists already, de is non-NULL */
1431 de = create_proc_entry(table->procname, mode, root);
1435 de->data = (void *) table;
1436 if (table->proc_handler)
1437 de->proc_fops = &proc_sys_file_operations;
1440 if (de->mode & S_IFDIR)
1441 register_proc_table(table->child, de, set);
1446 * Unregister a /proc sysctl table and any subdirectories.
1448 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1450 struct proc_dir_entry *de;
1451 for (; table->ctl_name; table++) {
1452 if (!(de = table->de))
1454 if (de->mode & S_IFDIR) {
1455 if (!table->child) {
1456 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1459 unregister_proc_table(table->child, de);
1461 /* Don't unregister directories which still have entries.. */
1467 * In any case, mark the entry as goner; we'll keep it
1468 * around if it's busy, but we'll know to do nothing with
1469 * its fields. We are under sysctl_lock here.
1473 /* Don't unregister proc entries that are still being used.. */
1474 if (atomic_read(&de->count))
1478 remove_proc_entry(table->procname, root);
1482 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1483 size_t count, loff_t *ppos)
1486 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1487 struct ctl_table *table;
1489 ssize_t error = -ENOTDIR;
1491 spin_lock(&sysctl_lock);
1492 if (de && de->data && use_table(de->set)) {
1494 * at that point we know that sysctl was not unregistered
1495 * and won't be until we finish
1497 spin_unlock(&sysctl_lock);
1498 table = (struct ctl_table *) de->data;
1499 if (!table || !table->proc_handler)
1502 op = (write ? 002 : 004);
1503 if (ctl_perm(table, op))
1506 /* careful: calling conventions are nasty here */
1508 error = (*table->proc_handler)(table, write, file,
1513 spin_lock(&sysctl_lock);
1514 unuse_table(de->set);
1516 spin_unlock(&sysctl_lock);
1520 static int proc_opensys(struct inode *inode, struct file *file)
1522 if (file->f_mode & FMODE_WRITE) {
1524 * sysctl entries that are not writable,
1525 * are _NOT_ writable, capabilities or not.
1527 if (!(inode->i_mode & S_IWUSR))
1534 static ssize_t proc_readsys(struct file * file, char __user * buf,
1535 size_t count, loff_t *ppos)
1537 return do_rw_proc(0, file, buf, count, ppos);
1540 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1541 size_t count, loff_t *ppos)
1543 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1547 * proc_dostring - read a string sysctl
1548 * @table: the sysctl table
1549 * @write: %TRUE if this is a write to the sysctl file
1550 * @filp: the file structure
1551 * @buffer: the user buffer
1552 * @lenp: the size of the user buffer
1553 * @ppos: file position
1555 * Reads/writes a string from/to the user buffer. If the kernel
1556 * buffer provided is not large enough to hold the string, the
1557 * string is truncated. The copied string is %NULL-terminated.
1558 * If the string is being read by the user process, it is copied
1559 * and a newline '\n' is added. It is truncated if the buffer is
1562 * Returns 0 on success.
1564 int proc_dostring(ctl_table *table, int write, struct file *filp,
1565 void __user *buffer, size_t *lenp, loff_t *ppos)
1571 if (!table->data || !table->maxlen || !*lenp ||
1572 (*ppos && !write)) {
1580 while (len < *lenp) {
1581 if (get_user(c, p++))
1583 if (c == 0 || c == '\n')
1587 if (len >= table->maxlen)
1588 len = table->maxlen-1;
1589 if(copy_from_user(table->data, buffer, len))
1591 ((char *) table->data)[len] = 0;
1594 len = strlen(table->data);
1595 if (len > table->maxlen)
1596 len = table->maxlen;
1600 if(copy_to_user(buffer, table->data, len))
1603 if(put_user('\n', ((char __user *) buffer) + len))
1614 * Special case of dostring for the UTS structure. This has locks
1615 * to observe. Should this be in kernel/sys.c ????
1618 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1619 void __user *buffer, size_t *lenp, loff_t *ppos)
1624 down_read(&uts_sem);
1625 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1628 down_write(&uts_sem);
1629 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1635 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1637 int write, void *data)
1640 *valp = *negp ? -*lvalp : *lvalp;
1645 *lvalp = (unsigned long)-val;
1648 *lvalp = (unsigned long)val;
1654 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1655 void __user *buffer, size_t *lenp, loff_t *ppos,
1656 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1657 int write, void *data),
1660 #define TMPBUFLEN 21
1661 int *i, vleft, first=1, neg, val;
1665 char buf[TMPBUFLEN], *p;
1666 char __user *s = buffer;
1668 if (!table->data || !table->maxlen || !*lenp ||
1669 (*ppos && !write)) {
1674 i = (int *) table->data;
1675 vleft = table->maxlen / sizeof(*i);
1679 conv = do_proc_dointvec_conv;
1681 for (; left && vleft--; i++, first=0) {
1696 if (len > sizeof(buf) - 1)
1697 len = sizeof(buf) - 1;
1698 if (copy_from_user(buf, s, len))
1702 if (*p == '-' && left > 1) {
1706 if (*p < '0' || *p > '9')
1709 lval = simple_strtoul(p, &p, 0);
1712 if ((len < left) && *p && !isspace(*p))
1719 if (conv(&neg, &lval, i, 1, data))
1726 if (conv(&neg, &lval, i, 0, data))
1729 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1733 if(copy_to_user(s, buf, len))
1740 if (!write && !first && left) {
1741 if(put_user('\n', s))
1748 if (get_user(c, s++))
1764 * proc_dointvec - read a vector of integers
1765 * @table: the sysctl table
1766 * @write: %TRUE if this is a write to the sysctl file
1767 * @filp: the file structure
1768 * @buffer: the user buffer
1769 * @lenp: the size of the user buffer
1770 * @ppos: file position
1772 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1773 * values from/to the user buffer, treated as an ASCII string.
1775 * Returns 0 on success.
1777 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1778 void __user *buffer, size_t *lenp, loff_t *ppos)
1780 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1790 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1792 int write, void *data)
1794 int op = *(int *)data;
1796 int val = *negp ? -*lvalp : *lvalp;
1798 case OP_SET: *valp = val; break;
1799 case OP_AND: *valp &= val; break;
1800 case OP_OR: *valp |= val; break;
1801 case OP_MAX: if(*valp < val)
1804 case OP_MIN: if(*valp > val)
1812 *lvalp = (unsigned long)-val;
1815 *lvalp = (unsigned long)val;
1822 * init may raise the set.
1825 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1826 void __user *buffer, size_t *lenp, loff_t *ppos)
1830 if (!capable(CAP_SYS_MODULE)) {
1834 op = (current->pid == 1) ? OP_SET : OP_AND;
1835 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1836 do_proc_dointvec_bset_conv,&op);
1839 struct do_proc_dointvec_minmax_conv_param {
1844 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1846 int write, void *data)
1848 struct do_proc_dointvec_minmax_conv_param *param = data;
1850 int val = *negp ? -*lvalp : *lvalp;
1851 if ((param->min && *param->min > val) ||
1852 (param->max && *param->max < val))
1859 *lvalp = (unsigned long)-val;
1862 *lvalp = (unsigned long)val;
1869 * proc_dointvec_minmax - read a vector of integers with min/max values
1870 * @table: the sysctl table
1871 * @write: %TRUE if this is a write to the sysctl file
1872 * @filp: the file structure
1873 * @buffer: the user buffer
1874 * @lenp: the size of the user buffer
1875 * @ppos: file position
1877 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1878 * values from/to the user buffer, treated as an ASCII string.
1880 * This routine will ensure the values are within the range specified by
1881 * table->extra1 (min) and table->extra2 (max).
1883 * Returns 0 on success.
1885 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1886 void __user *buffer, size_t *lenp, loff_t *ppos)
1888 struct do_proc_dointvec_minmax_conv_param param = {
1889 .min = (int *) table->extra1,
1890 .max = (int *) table->extra2,
1892 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1893 do_proc_dointvec_minmax_conv, ¶m);
1896 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1898 void __user *buffer,
1899 size_t *lenp, loff_t *ppos,
1900 unsigned long convmul,
1901 unsigned long convdiv)
1903 #define TMPBUFLEN 21
1904 unsigned long *i, *min, *max, val;
1905 int vleft, first=1, neg;
1907 char buf[TMPBUFLEN], *p;
1908 char __user *s = buffer;
1910 if (!table->data || !table->maxlen || !*lenp ||
1911 (*ppos && !write)) {
1916 i = (unsigned long *) table->data;
1917 min = (unsigned long *) table->extra1;
1918 max = (unsigned long *) table->extra2;
1919 vleft = table->maxlen / sizeof(unsigned long);
1922 for (; left && vleft--; i++, min++, max++, first=0) {
1937 if (len > TMPBUFLEN-1)
1939 if (copy_from_user(buf, s, len))
1943 if (*p == '-' && left > 1) {
1947 if (*p < '0' || *p > '9')
1949 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1951 if ((len < left) && *p && !isspace(*p))
1960 if ((min && val < *min) || (max && val > *max))
1967 sprintf(p, "%lu", convdiv * (*i) / convmul);
1971 if(copy_to_user(s, buf, len))
1978 if (!write && !first && left) {
1979 if(put_user('\n', s))
1986 if (get_user(c, s++))
2002 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2003 * @table: the sysctl table
2004 * @write: %TRUE if this is a write to the sysctl file
2005 * @filp: the file structure
2006 * @buffer: the user buffer
2007 * @lenp: the size of the user buffer
2008 * @ppos: file position
2010 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2011 * values from/to the user buffer, treated as an ASCII string.
2013 * This routine will ensure the values are within the range specified by
2014 * table->extra1 (min) and table->extra2 (max).
2016 * Returns 0 on success.
2018 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2019 void __user *buffer, size_t *lenp, loff_t *ppos)
2021 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2025 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2026 * @table: the sysctl table
2027 * @write: %TRUE if this is a write to the sysctl file
2028 * @filp: the file structure
2029 * @buffer: the user buffer
2030 * @lenp: the size of the user buffer
2031 * @ppos: file position
2033 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2034 * values from/to the user buffer, treated as an ASCII string. The values
2035 * are treated as milliseconds, and converted to jiffies when they are stored.
2037 * This routine will ensure the values are within the range specified by
2038 * table->extra1 (min) and table->extra2 (max).
2040 * Returns 0 on success.
2042 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2044 void __user *buffer,
2045 size_t *lenp, loff_t *ppos)
2047 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2048 lenp, ppos, HZ, 1000l);
2052 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2054 int write, void *data)
2057 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2063 lval = (unsigned long)-val;
2066 lval = (unsigned long)val;
2073 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2075 int write, void *data)
2078 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2084 lval = (unsigned long)-val;
2087 lval = (unsigned long)val;
2089 *lvalp = jiffies_to_clock_t(lval);
2094 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2096 int write, void *data)
2099 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2105 lval = (unsigned long)-val;
2108 lval = (unsigned long)val;
2110 *lvalp = jiffies_to_msecs(lval);
2116 * proc_dointvec_jiffies - read a vector of integers as seconds
2117 * @table: the sysctl table
2118 * @write: %TRUE if this is a write to the sysctl file
2119 * @filp: the file structure
2120 * @buffer: the user buffer
2121 * @lenp: the size of the user buffer
2122 * @ppos: file position
2124 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2125 * values from/to the user buffer, treated as an ASCII string.
2126 * The values read are assumed to be in seconds, and are converted into
2129 * Returns 0 on success.
2131 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2132 void __user *buffer, size_t *lenp, loff_t *ppos)
2134 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2135 do_proc_dointvec_jiffies_conv,NULL);
2139 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2140 * @table: the sysctl table
2141 * @write: %TRUE if this is a write to the sysctl file
2142 * @filp: the file structure
2143 * @buffer: the user buffer
2144 * @lenp: the size of the user buffer
2145 * @ppos: pointer to the file position
2147 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2148 * values from/to the user buffer, treated as an ASCII string.
2149 * The values read are assumed to be in 1/USER_HZ seconds, and
2150 * are converted into jiffies.
2152 * Returns 0 on success.
2154 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2155 void __user *buffer, size_t *lenp, loff_t *ppos)
2157 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2158 do_proc_dointvec_userhz_jiffies_conv,NULL);
2162 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2163 * @table: the sysctl table
2164 * @write: %TRUE if this is a write to the sysctl file
2165 * @filp: the file structure
2166 * @buffer: the user buffer
2167 * @lenp: the size of the user buffer
2168 * @ppos: file position
2169 * @ppos: the current position in the file
2171 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2172 * values from/to the user buffer, treated as an ASCII string.
2173 * The values read are assumed to be in 1/1000 seconds, and
2174 * are converted into jiffies.
2176 * Returns 0 on success.
2178 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2179 void __user *buffer, size_t *lenp, loff_t *ppos)
2181 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2182 do_proc_dointvec_ms_jiffies_conv, NULL);
2185 #else /* CONFIG_PROC_FS */
2187 int proc_dostring(ctl_table *table, int write, struct file *filp,
2188 void __user *buffer, size_t *lenp, loff_t *ppos)
2193 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2194 void __user *buffer, size_t *lenp, loff_t *ppos)
2199 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2200 void __user *buffer, size_t *lenp, loff_t *ppos)
2205 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2206 void __user *buffer, size_t *lenp, loff_t *ppos)
2211 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2212 void __user *buffer, size_t *lenp, loff_t *ppos)
2217 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2218 void __user *buffer, size_t *lenp, loff_t *ppos)
2223 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2229 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2230 void __user *buffer, size_t *lenp, loff_t *ppos)
2235 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2236 void __user *buffer, size_t *lenp, loff_t *ppos)
2241 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2243 void __user *buffer,
2244 size_t *lenp, loff_t *ppos)
2250 #endif /* CONFIG_PROC_FS */
2254 * General sysctl support routines
2257 /* The generic string strategy routine: */
2258 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2259 void __user *oldval, size_t __user *oldlenp,
2260 void __user *newval, size_t newlen, void **context)
2262 if (!table->data || !table->maxlen)
2265 if (oldval && oldlenp) {
2267 if (get_user(bufsize, oldlenp))
2270 size_t len = strlen(table->data), copied;
2272 /* This shouldn't trigger for a well-formed sysctl */
2273 if (len > table->maxlen)
2274 len = table->maxlen;
2276 /* Copy up to a max of bufsize-1 bytes of the string */
2277 copied = (len >= bufsize) ? bufsize - 1 : len;
2279 if (copy_to_user(oldval, table->data, copied) ||
2280 put_user(0, (char __user *)(oldval + copied)))
2282 if (put_user(len, oldlenp))
2286 if (newval && newlen) {
2287 size_t len = newlen;
2288 if (len > table->maxlen)
2289 len = table->maxlen;
2290 if(copy_from_user(table->data, newval, len))
2292 if (len == table->maxlen)
2294 ((char *) table->data)[len] = 0;
2300 * This function makes sure that all of the integers in the vector
2301 * are between the minimum and maximum values given in the arrays
2302 * table->extra1 and table->extra2, respectively.
2304 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2305 void __user *oldval, size_t __user *oldlenp,
2306 void __user *newval, size_t newlen, void **context)
2309 if (newval && newlen) {
2310 int __user *vec = (int __user *) newval;
2311 int *min = (int *) table->extra1;
2312 int *max = (int *) table->extra2;
2316 if (newlen % sizeof(int) != 0)
2319 if (!table->extra1 && !table->extra2)
2322 if (newlen > table->maxlen)
2323 newlen = table->maxlen;
2324 length = newlen / sizeof(int);
2326 for (i = 0; i < length; i++) {
2328 if (get_user(value, vec + i))
2330 if (min && value < min[i])
2332 if (max && value > max[i])
2339 /* Strategy function to convert jiffies to seconds */
2340 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2341 void __user *oldval, size_t __user *oldlenp,
2342 void __user *newval, size_t newlen, void **context)
2347 if (get_user(olen, oldlenp))
2349 if (olen!=sizeof(int))
2352 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2353 (oldlenp && put_user(sizeof(int),oldlenp)))
2356 if (newval && newlen) {
2358 if (newlen != sizeof(int))
2360 if (get_user(new, (int __user *)newval))
2362 *(int *)(table->data) = new*HZ;
2367 /* Strategy function to convert jiffies to seconds */
2368 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2369 void __user *oldval, size_t __user *oldlenp,
2370 void __user *newval, size_t newlen, void **context)
2375 if (get_user(olen, oldlenp))
2377 if (olen!=sizeof(int))
2380 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2381 (oldlenp && put_user(sizeof(int),oldlenp)))
2384 if (newval && newlen) {
2386 if (newlen != sizeof(int))
2388 if (get_user(new, (int __user *)newval))
2390 *(int *)(table->data) = msecs_to_jiffies(new);
2395 #else /* CONFIG_SYSCTL */
2398 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2403 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2404 void __user *oldval, size_t __user *oldlenp,
2405 void __user *newval, size_t newlen, void **context)
2410 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2411 void __user *oldval, size_t __user *oldlenp,
2412 void __user *newval, size_t newlen, void **context)
2417 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2418 void __user *oldval, size_t __user *oldlenp,
2419 void __user *newval, size_t newlen, void **context)
2424 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2425 void __user *oldval, size_t __user *oldlenp,
2426 void __user *newval, size_t newlen, void **context)
2431 int proc_dostring(ctl_table *table, int write, struct file *filp,
2432 void __user *buffer, size_t *lenp, loff_t *ppos)
2437 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2438 void __user *buffer, size_t *lenp, loff_t *ppos)
2443 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2444 void __user *buffer, size_t *lenp, loff_t *ppos)
2449 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2450 void __user *buffer, size_t *lenp, loff_t *ppos)
2455 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2456 void __user *buffer, size_t *lenp, loff_t *ppos)
2461 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2462 void __user *buffer, size_t *lenp, loff_t *ppos)
2467 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2468 void __user *buffer, size_t *lenp, loff_t *ppos)
2473 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2474 void __user *buffer, size_t *lenp, loff_t *ppos)
2479 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2481 void __user *buffer,
2482 size_t *lenp, loff_t *ppos)
2487 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2493 void unregister_sysctl_table(struct ctl_table_header * table)
2497 #endif /* CONFIG_SYSCTL */
2500 * No sense putting this after each symbol definition, twice,
2501 * exception granted :-)
2503 EXPORT_SYMBOL(proc_dointvec);
2504 EXPORT_SYMBOL(proc_dointvec_jiffies);
2505 EXPORT_SYMBOL(proc_dointvec_minmax);
2506 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2507 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2508 EXPORT_SYMBOL(proc_dostring);
2509 EXPORT_SYMBOL(proc_doulongvec_minmax);
2510 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2511 EXPORT_SYMBOL(register_sysctl_table);
2512 EXPORT_SYMBOL(sysctl_intvec);
2513 EXPORT_SYMBOL(sysctl_jiffies);
2514 EXPORT_SYMBOL(sysctl_ms_jiffies);
2515 EXPORT_SYMBOL(sysctl_string);
2516 EXPORT_SYMBOL(unregister_sysctl_table);