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_interval,
746 .maxlen = sizeof(dirty_writeback_interval),
748 .proc_handler = &dirty_writeback_centisecs_handler,
751 .ctl_name = VM_DIRTY_EXPIRE_CS,
752 .procname = "dirty_expire_centisecs",
753 .data = &dirty_expire_interval,
754 .maxlen = sizeof(dirty_expire_interval),
756 .proc_handler = &proc_dointvec_userhz_jiffies,
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_jiffies,
852 .strategy = &sysctl_jiffies,
855 .ctl_name = VM_BLOCK_DUMP,
856 .procname = "block_dump",
858 .maxlen = sizeof(block_dump),
860 .proc_handler = &proc_dointvec,
861 .strategy = &sysctl_intvec,
865 .ctl_name = VM_VFS_CACHE_PRESSURE,
866 .procname = "vfs_cache_pressure",
867 .data = &sysctl_vfs_cache_pressure,
868 .maxlen = sizeof(sysctl_vfs_cache_pressure),
870 .proc_handler = &proc_dointvec,
871 .strategy = &sysctl_intvec,
874 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
876 .ctl_name = VM_LEGACY_VA_LAYOUT,
877 .procname = "legacy_va_layout",
878 .data = &sysctl_legacy_va_layout,
879 .maxlen = sizeof(sysctl_legacy_va_layout),
881 .proc_handler = &proc_dointvec,
882 .strategy = &sysctl_intvec,
888 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
889 .procname = "swap_token_timeout",
890 .data = &swap_token_default_timeout,
891 .maxlen = sizeof(swap_token_default_timeout),
893 .proc_handler = &proc_dointvec_jiffies,
894 .strategy = &sysctl_jiffies,
899 .ctl_name = VM_ZONE_RECLAIM_MODE,
900 .procname = "zone_reclaim_mode",
901 .data = &zone_reclaim_mode,
902 .maxlen = sizeof(zone_reclaim_mode),
904 .proc_handler = &proc_dointvec,
905 .strategy = &sysctl_intvec,
909 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
910 .procname = "zone_reclaim_interval",
911 .data = &zone_reclaim_interval,
912 .maxlen = sizeof(zone_reclaim_interval),
914 .proc_handler = &proc_dointvec_jiffies,
915 .strategy = &sysctl_jiffies,
921 static ctl_table proc_table[] = {
925 static ctl_table fs_table[] = {
927 .ctl_name = FS_NRINODE,
928 .procname = "inode-nr",
929 .data = &inodes_stat,
930 .maxlen = 2*sizeof(int),
932 .proc_handler = &proc_dointvec,
935 .ctl_name = FS_STATINODE,
936 .procname = "inode-state",
937 .data = &inodes_stat,
938 .maxlen = 7*sizeof(int),
940 .proc_handler = &proc_dointvec,
943 .ctl_name = FS_NRFILE,
944 .procname = "file-nr",
946 .maxlen = 3*sizeof(int),
948 .proc_handler = &proc_nr_files,
951 .ctl_name = FS_MAXFILE,
952 .procname = "file-max",
953 .data = &files_stat.max_files,
954 .maxlen = sizeof(int),
956 .proc_handler = &proc_dointvec,
959 .ctl_name = FS_DENTRY,
960 .procname = "dentry-state",
961 .data = &dentry_stat,
962 .maxlen = 6*sizeof(int),
964 .proc_handler = &proc_dointvec,
967 .ctl_name = FS_OVERFLOWUID,
968 .procname = "overflowuid",
969 .data = &fs_overflowuid,
970 .maxlen = sizeof(int),
972 .proc_handler = &proc_dointvec_minmax,
973 .strategy = &sysctl_intvec,
974 .extra1 = &minolduid,
975 .extra2 = &maxolduid,
978 .ctl_name = FS_OVERFLOWGID,
979 .procname = "overflowgid",
980 .data = &fs_overflowgid,
981 .maxlen = sizeof(int),
983 .proc_handler = &proc_dointvec_minmax,
984 .strategy = &sysctl_intvec,
985 .extra1 = &minolduid,
986 .extra2 = &maxolduid,
989 .ctl_name = FS_LEASES,
990 .procname = "leases-enable",
991 .data = &leases_enable,
992 .maxlen = sizeof(int),
994 .proc_handler = &proc_dointvec,
996 #ifdef CONFIG_DNOTIFY
998 .ctl_name = FS_DIR_NOTIFY,
999 .procname = "dir-notify-enable",
1000 .data = &dir_notify_enable,
1001 .maxlen = sizeof(int),
1003 .proc_handler = &proc_dointvec,
1008 .ctl_name = FS_LEASE_TIME,
1009 .procname = "lease-break-time",
1010 .data = &lease_break_time,
1011 .maxlen = sizeof(int),
1013 .proc_handler = &proc_dointvec,
1016 .ctl_name = FS_AIO_NR,
1017 .procname = "aio-nr",
1019 .maxlen = sizeof(aio_nr),
1021 .proc_handler = &proc_doulongvec_minmax,
1024 .ctl_name = FS_AIO_MAX_NR,
1025 .procname = "aio-max-nr",
1026 .data = &aio_max_nr,
1027 .maxlen = sizeof(aio_max_nr),
1029 .proc_handler = &proc_doulongvec_minmax,
1031 #ifdef CONFIG_INOTIFY
1033 .ctl_name = FS_INOTIFY,
1034 .procname = "inotify",
1036 .child = inotify_table,
1041 .ctl_name = KERN_SETUID_DUMPABLE,
1042 .procname = "suid_dumpable",
1043 .data = &suid_dumpable,
1044 .maxlen = sizeof(int),
1046 .proc_handler = &proc_dointvec,
1051 static ctl_table debug_table[] = {
1055 static ctl_table dev_table[] = {
1059 extern void init_irq_proc (void);
1061 static DEFINE_SPINLOCK(sysctl_lock);
1063 /* called under sysctl_lock */
1064 static int use_table(struct ctl_table_header *p)
1066 if (unlikely(p->unregistering))
1072 /* called under sysctl_lock */
1073 static void unuse_table(struct ctl_table_header *p)
1076 if (unlikely(p->unregistering))
1077 complete(p->unregistering);
1080 /* called under sysctl_lock, will reacquire if has to wait */
1081 static void start_unregistering(struct ctl_table_header *p)
1084 * if p->used is 0, nobody will ever touch that entry again;
1085 * we'll eliminate all paths to it before dropping sysctl_lock
1087 if (unlikely(p->used)) {
1088 struct completion wait;
1089 init_completion(&wait);
1090 p->unregistering = &wait;
1091 spin_unlock(&sysctl_lock);
1092 wait_for_completion(&wait);
1093 spin_lock(&sysctl_lock);
1096 * do not remove from the list until nobody holds it; walking the
1097 * list in do_sysctl() relies on that.
1099 list_del_init(&p->ctl_entry);
1102 void __init sysctl_init(void)
1104 #ifdef CONFIG_PROC_FS
1105 register_proc_table(root_table, proc_sys_root, &root_table_header);
1110 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1111 void __user *newval, size_t newlen)
1113 struct list_head *tmp;
1114 int error = -ENOTDIR;
1116 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1120 if (!oldlenp || get_user(old_len, oldlenp))
1123 spin_lock(&sysctl_lock);
1124 tmp = &root_table_header.ctl_entry;
1126 struct ctl_table_header *head =
1127 list_entry(tmp, struct ctl_table_header, ctl_entry);
1128 void *context = NULL;
1130 if (!use_table(head))
1133 spin_unlock(&sysctl_lock);
1135 error = parse_table(name, nlen, oldval, oldlenp,
1136 newval, newlen, head->ctl_table,
1140 spin_lock(&sysctl_lock);
1142 if (error != -ENOTDIR)
1144 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1145 spin_unlock(&sysctl_lock);
1149 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1151 struct __sysctl_args tmp;
1154 if (copy_from_user(&tmp, args, sizeof(tmp)))
1158 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1159 tmp.newval, tmp.newlen);
1165 * ctl_perm does NOT grant the superuser all rights automatically, because
1166 * some sysctl variables are readonly even to root.
1169 static int test_perm(int mode, int op)
1173 else if (in_egroup_p(0))
1175 if ((mode & op & 0007) == op)
1180 static inline int ctl_perm(ctl_table *table, int op)
1183 error = security_sysctl(table, op);
1186 return test_perm(table->mode, op);
1189 static int parse_table(int __user *name, int nlen,
1190 void __user *oldval, size_t __user *oldlenp,
1191 void __user *newval, size_t newlen,
1192 ctl_table *table, void **context)
1198 if (get_user(n, name))
1200 for ( ; table->ctl_name; table++) {
1201 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1204 if (ctl_perm(table, 001))
1206 if (table->strategy) {
1207 error = table->strategy(
1210 newval, newlen, context);
1216 table = table->child;
1219 error = do_sysctl_strategy(table, name, nlen,
1221 newval, newlen, context);
1228 /* Perform the actual read/write of a sysctl table entry. */
1229 int do_sysctl_strategy (ctl_table *table,
1230 int __user *name, int nlen,
1231 void __user *oldval, size_t __user *oldlenp,
1232 void __user *newval, size_t newlen, void **context)
1241 if (ctl_perm(table, op))
1244 if (table->strategy) {
1245 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1246 newval, newlen, context);
1253 /* If there is no strategy routine, or if the strategy returns
1254 * zero, proceed with automatic r/w */
1255 if (table->data && table->maxlen) {
1256 if (oldval && oldlenp) {
1257 if (get_user(len, oldlenp))
1260 if (len > table->maxlen)
1261 len = table->maxlen;
1262 if(copy_to_user(oldval, table->data, len))
1264 if(put_user(len, oldlenp))
1268 if (newval && newlen) {
1270 if (len > table->maxlen)
1271 len = table->maxlen;
1272 if(copy_from_user(table->data, newval, len))
1280 * register_sysctl_table - register a sysctl hierarchy
1281 * @table: the top-level table structure
1282 * @insert_at_head: whether the entry should be inserted in front or at the end
1284 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1285 * array. An entry with a ctl_name of 0 terminates the table.
1287 * The members of the &ctl_table structure are used as follows:
1289 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1290 * must be unique within that level of sysctl
1292 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1293 * enter a sysctl file
1295 * data - a pointer to data for use by proc_handler
1297 * maxlen - the maximum size in bytes of the data
1299 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1301 * child - a pointer to the child sysctl table if this entry is a directory, or
1304 * proc_handler - the text handler routine (described below)
1306 * strategy - the strategy routine (described below)
1308 * de - for internal use by the sysctl routines
1310 * extra1, extra2 - extra pointers usable by the proc handler routines
1312 * Leaf nodes in the sysctl tree will be represented by a single file
1313 * under /proc; non-leaf nodes will be represented by directories.
1315 * sysctl(2) can automatically manage read and write requests through
1316 * the sysctl table. The data and maxlen fields of the ctl_table
1317 * struct enable minimal validation of the values being written to be
1318 * performed, and the mode field allows minimal authentication.
1320 * More sophisticated management can be enabled by the provision of a
1321 * strategy routine with the table entry. This will be called before
1322 * any automatic read or write of the data is performed.
1324 * The strategy routine may return
1326 * < 0 - Error occurred (error is passed to user process)
1328 * 0 - OK - proceed with automatic read or write.
1330 * > 0 - OK - read or write has been done by the strategy routine, so
1331 * return immediately.
1333 * There must be a proc_handler routine for any terminal nodes
1334 * mirrored under /proc/sys (non-terminals are handled by a built-in
1335 * directory handler). Several default handlers are available to
1336 * cover common cases -
1338 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1339 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1340 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1342 * It is the handler's job to read the input buffer from user memory
1343 * and process it. The handler should return 0 on success.
1345 * This routine returns %NULL on a failure to register, and a pointer
1346 * to the table header on success.
1348 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1351 struct ctl_table_header *tmp;
1352 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1355 tmp->ctl_table = table;
1356 INIT_LIST_HEAD(&tmp->ctl_entry);
1358 tmp->unregistering = NULL;
1359 spin_lock(&sysctl_lock);
1361 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1363 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1364 spin_unlock(&sysctl_lock);
1365 #ifdef CONFIG_PROC_FS
1366 register_proc_table(table, proc_sys_root, tmp);
1372 * unregister_sysctl_table - unregister a sysctl table hierarchy
1373 * @header: the header returned from register_sysctl_table
1375 * Unregisters the sysctl table and all children. proc entries may not
1376 * actually be removed until they are no longer used by anyone.
1378 void unregister_sysctl_table(struct ctl_table_header * header)
1381 spin_lock(&sysctl_lock);
1382 start_unregistering(header);
1383 #ifdef CONFIG_PROC_FS
1384 unregister_proc_table(header->ctl_table, proc_sys_root);
1386 spin_unlock(&sysctl_lock);
1394 #ifdef CONFIG_PROC_FS
1396 /* Scan the sysctl entries in table and add them all into /proc */
1397 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1399 struct proc_dir_entry *de;
1403 for (; table->ctl_name; table++) {
1404 /* Can't do anything without a proc name. */
1405 if (!table->procname)
1407 /* Maybe we can't do anything with it... */
1408 if (!table->proc_handler && !table->child) {
1409 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1414 len = strlen(table->procname);
1418 if (table->proc_handler)
1422 for (de = root->subdir; de; de = de->next) {
1423 if (proc_match(len, table->procname, de))
1426 /* If the subdir exists already, de is non-NULL */
1430 de = create_proc_entry(table->procname, mode, root);
1434 de->data = (void *) table;
1435 if (table->proc_handler)
1436 de->proc_fops = &proc_sys_file_operations;
1439 if (de->mode & S_IFDIR)
1440 register_proc_table(table->child, de, set);
1445 * Unregister a /proc sysctl table and any subdirectories.
1447 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1449 struct proc_dir_entry *de;
1450 for (; table->ctl_name; table++) {
1451 if (!(de = table->de))
1453 if (de->mode & S_IFDIR) {
1454 if (!table->child) {
1455 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1458 unregister_proc_table(table->child, de);
1460 /* Don't unregister directories which still have entries.. */
1466 * In any case, mark the entry as goner; we'll keep it
1467 * around if it's busy, but we'll know to do nothing with
1468 * its fields. We are under sysctl_lock here.
1472 /* Don't unregister proc entries that are still being used.. */
1473 if (atomic_read(&de->count))
1477 remove_proc_entry(table->procname, root);
1481 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1482 size_t count, loff_t *ppos)
1485 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1486 struct ctl_table *table;
1488 ssize_t error = -ENOTDIR;
1490 spin_lock(&sysctl_lock);
1491 if (de && de->data && use_table(de->set)) {
1493 * at that point we know that sysctl was not unregistered
1494 * and won't be until we finish
1496 spin_unlock(&sysctl_lock);
1497 table = (struct ctl_table *) de->data;
1498 if (!table || !table->proc_handler)
1501 op = (write ? 002 : 004);
1502 if (ctl_perm(table, op))
1505 /* careful: calling conventions are nasty here */
1507 error = (*table->proc_handler)(table, write, file,
1512 spin_lock(&sysctl_lock);
1513 unuse_table(de->set);
1515 spin_unlock(&sysctl_lock);
1519 static int proc_opensys(struct inode *inode, struct file *file)
1521 if (file->f_mode & FMODE_WRITE) {
1523 * sysctl entries that are not writable,
1524 * are _NOT_ writable, capabilities or not.
1526 if (!(inode->i_mode & S_IWUSR))
1533 static ssize_t proc_readsys(struct file * file, char __user * buf,
1534 size_t count, loff_t *ppos)
1536 return do_rw_proc(0, file, buf, count, ppos);
1539 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1540 size_t count, loff_t *ppos)
1542 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1546 * proc_dostring - read a string sysctl
1547 * @table: the sysctl table
1548 * @write: %TRUE if this is a write to the sysctl file
1549 * @filp: the file structure
1550 * @buffer: the user buffer
1551 * @lenp: the size of the user buffer
1552 * @ppos: file position
1554 * Reads/writes a string from/to the user buffer. If the kernel
1555 * buffer provided is not large enough to hold the string, the
1556 * string is truncated. The copied string is %NULL-terminated.
1557 * If the string is being read by the user process, it is copied
1558 * and a newline '\n' is added. It is truncated if the buffer is
1561 * Returns 0 on success.
1563 int proc_dostring(ctl_table *table, int write, struct file *filp,
1564 void __user *buffer, size_t *lenp, loff_t *ppos)
1570 if (!table->data || !table->maxlen || !*lenp ||
1571 (*ppos && !write)) {
1579 while (len < *lenp) {
1580 if (get_user(c, p++))
1582 if (c == 0 || c == '\n')
1586 if (len >= table->maxlen)
1587 len = table->maxlen-1;
1588 if(copy_from_user(table->data, buffer, len))
1590 ((char *) table->data)[len] = 0;
1593 len = strlen(table->data);
1594 if (len > table->maxlen)
1595 len = table->maxlen;
1599 if(copy_to_user(buffer, table->data, len))
1602 if(put_user('\n', ((char __user *) buffer) + len))
1613 * Special case of dostring for the UTS structure. This has locks
1614 * to observe. Should this be in kernel/sys.c ????
1617 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1618 void __user *buffer, size_t *lenp, loff_t *ppos)
1623 down_read(&uts_sem);
1624 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1627 down_write(&uts_sem);
1628 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1634 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1636 int write, void *data)
1639 *valp = *negp ? -*lvalp : *lvalp;
1644 *lvalp = (unsigned long)-val;
1647 *lvalp = (unsigned long)val;
1653 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1654 void __user *buffer, size_t *lenp, loff_t *ppos,
1655 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1656 int write, void *data),
1659 #define TMPBUFLEN 21
1660 int *i, vleft, first=1, neg, val;
1664 char buf[TMPBUFLEN], *p;
1665 char __user *s = buffer;
1667 if (!table->data || !table->maxlen || !*lenp ||
1668 (*ppos && !write)) {
1673 i = (int *) table->data;
1674 vleft = table->maxlen / sizeof(*i);
1678 conv = do_proc_dointvec_conv;
1680 for (; left && vleft--; i++, first=0) {
1695 if (len > sizeof(buf) - 1)
1696 len = sizeof(buf) - 1;
1697 if (copy_from_user(buf, s, len))
1701 if (*p == '-' && left > 1) {
1705 if (*p < '0' || *p > '9')
1708 lval = simple_strtoul(p, &p, 0);
1711 if ((len < left) && *p && !isspace(*p))
1718 if (conv(&neg, &lval, i, 1, data))
1725 if (conv(&neg, &lval, i, 0, data))
1728 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1732 if(copy_to_user(s, buf, len))
1739 if (!write && !first && left) {
1740 if(put_user('\n', s))
1747 if (get_user(c, s++))
1763 * proc_dointvec - read a vector of integers
1764 * @table: the sysctl table
1765 * @write: %TRUE if this is a write to the sysctl file
1766 * @filp: the file structure
1767 * @buffer: the user buffer
1768 * @lenp: the size of the user buffer
1769 * @ppos: file position
1771 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1772 * values from/to the user buffer, treated as an ASCII string.
1774 * Returns 0 on success.
1776 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1777 void __user *buffer, size_t *lenp, loff_t *ppos)
1779 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1789 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1791 int write, void *data)
1793 int op = *(int *)data;
1795 int val = *negp ? -*lvalp : *lvalp;
1797 case OP_SET: *valp = val; break;
1798 case OP_AND: *valp &= val; break;
1799 case OP_OR: *valp |= val; break;
1800 case OP_MAX: if(*valp < val)
1803 case OP_MIN: if(*valp > val)
1811 *lvalp = (unsigned long)-val;
1814 *lvalp = (unsigned long)val;
1821 * init may raise the set.
1824 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1825 void __user *buffer, size_t *lenp, loff_t *ppos)
1829 if (!capable(CAP_SYS_MODULE)) {
1833 op = (current->pid == 1) ? OP_SET : OP_AND;
1834 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1835 do_proc_dointvec_bset_conv,&op);
1838 struct do_proc_dointvec_minmax_conv_param {
1843 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1845 int write, void *data)
1847 struct do_proc_dointvec_minmax_conv_param *param = data;
1849 int val = *negp ? -*lvalp : *lvalp;
1850 if ((param->min && *param->min > val) ||
1851 (param->max && *param->max < val))
1858 *lvalp = (unsigned long)-val;
1861 *lvalp = (unsigned long)val;
1868 * proc_dointvec_minmax - read a vector of integers with min/max values
1869 * @table: the sysctl table
1870 * @write: %TRUE if this is a write to the sysctl file
1871 * @filp: the file structure
1872 * @buffer: the user buffer
1873 * @lenp: the size of the user buffer
1874 * @ppos: file position
1876 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1877 * values from/to the user buffer, treated as an ASCII string.
1879 * This routine will ensure the values are within the range specified by
1880 * table->extra1 (min) and table->extra2 (max).
1882 * Returns 0 on success.
1884 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1885 void __user *buffer, size_t *lenp, loff_t *ppos)
1887 struct do_proc_dointvec_minmax_conv_param param = {
1888 .min = (int *) table->extra1,
1889 .max = (int *) table->extra2,
1891 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1892 do_proc_dointvec_minmax_conv, ¶m);
1895 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1897 void __user *buffer,
1898 size_t *lenp, loff_t *ppos,
1899 unsigned long convmul,
1900 unsigned long convdiv)
1902 #define TMPBUFLEN 21
1903 unsigned long *i, *min, *max, val;
1904 int vleft, first=1, neg;
1906 char buf[TMPBUFLEN], *p;
1907 char __user *s = buffer;
1909 if (!table->data || !table->maxlen || !*lenp ||
1910 (*ppos && !write)) {
1915 i = (unsigned long *) table->data;
1916 min = (unsigned long *) table->extra1;
1917 max = (unsigned long *) table->extra2;
1918 vleft = table->maxlen / sizeof(unsigned long);
1921 for (; left && vleft--; i++, min++, max++, first=0) {
1936 if (len > TMPBUFLEN-1)
1938 if (copy_from_user(buf, s, len))
1942 if (*p == '-' && left > 1) {
1946 if (*p < '0' || *p > '9')
1948 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1950 if ((len < left) && *p && !isspace(*p))
1959 if ((min && val < *min) || (max && val > *max))
1966 sprintf(p, "%lu", convdiv * (*i) / convmul);
1970 if(copy_to_user(s, buf, len))
1977 if (!write && !first && left) {
1978 if(put_user('\n', s))
1985 if (get_user(c, s++))
2001 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2002 * @table: the sysctl table
2003 * @write: %TRUE if this is a write to the sysctl file
2004 * @filp: the file structure
2005 * @buffer: the user buffer
2006 * @lenp: the size of the user buffer
2007 * @ppos: file position
2009 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2010 * values from/to the user buffer, treated as an ASCII string.
2012 * This routine will ensure the values are within the range specified by
2013 * table->extra1 (min) and table->extra2 (max).
2015 * Returns 0 on success.
2017 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2018 void __user *buffer, size_t *lenp, loff_t *ppos)
2020 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2024 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2025 * @table: the sysctl table
2026 * @write: %TRUE if this is a write to the sysctl file
2027 * @filp: the file structure
2028 * @buffer: the user buffer
2029 * @lenp: the size of the user buffer
2030 * @ppos: file position
2032 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2033 * values from/to the user buffer, treated as an ASCII string. The values
2034 * are treated as milliseconds, and converted to jiffies when they are stored.
2036 * This routine will ensure the values are within the range specified by
2037 * table->extra1 (min) and table->extra2 (max).
2039 * Returns 0 on success.
2041 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2043 void __user *buffer,
2044 size_t *lenp, loff_t *ppos)
2046 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2047 lenp, ppos, HZ, 1000l);
2051 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2053 int write, void *data)
2056 if (*lvalp > LONG_MAX / HZ)
2058 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2064 lval = (unsigned long)-val;
2067 lval = (unsigned long)val;
2074 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2076 int write, void *data)
2079 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2081 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2087 lval = (unsigned long)-val;
2090 lval = (unsigned long)val;
2092 *lvalp = jiffies_to_clock_t(lval);
2097 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2099 int write, void *data)
2102 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2108 lval = (unsigned long)-val;
2111 lval = (unsigned long)val;
2113 *lvalp = jiffies_to_msecs(lval);
2119 * proc_dointvec_jiffies - read a vector of integers as seconds
2120 * @table: the sysctl table
2121 * @write: %TRUE if this is a write to the sysctl file
2122 * @filp: the file structure
2123 * @buffer: the user buffer
2124 * @lenp: the size of the user buffer
2125 * @ppos: file position
2127 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2128 * values from/to the user buffer, treated as an ASCII string.
2129 * The values read are assumed to be in seconds, and are converted into
2132 * Returns 0 on success.
2134 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2135 void __user *buffer, size_t *lenp, loff_t *ppos)
2137 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2138 do_proc_dointvec_jiffies_conv,NULL);
2142 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2143 * @table: the sysctl table
2144 * @write: %TRUE if this is a write to the sysctl file
2145 * @filp: the file structure
2146 * @buffer: the user buffer
2147 * @lenp: the size of the user buffer
2148 * @ppos: pointer to the file position
2150 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2151 * values from/to the user buffer, treated as an ASCII string.
2152 * The values read are assumed to be in 1/USER_HZ seconds, and
2153 * are converted into jiffies.
2155 * Returns 0 on success.
2157 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2158 void __user *buffer, size_t *lenp, loff_t *ppos)
2160 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2161 do_proc_dointvec_userhz_jiffies_conv,NULL);
2165 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2166 * @table: the sysctl table
2167 * @write: %TRUE if this is a write to the sysctl file
2168 * @filp: the file structure
2169 * @buffer: the user buffer
2170 * @lenp: the size of the user buffer
2171 * @ppos: file position
2172 * @ppos: the current position in the file
2174 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2175 * values from/to the user buffer, treated as an ASCII string.
2176 * The values read are assumed to be in 1/1000 seconds, and
2177 * are converted into jiffies.
2179 * Returns 0 on success.
2181 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2182 void __user *buffer, size_t *lenp, loff_t *ppos)
2184 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2185 do_proc_dointvec_ms_jiffies_conv, NULL);
2188 #else /* CONFIG_PROC_FS */
2190 int proc_dostring(ctl_table *table, int write, struct file *filp,
2191 void __user *buffer, size_t *lenp, loff_t *ppos)
2196 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2197 void __user *buffer, size_t *lenp, loff_t *ppos)
2202 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2203 void __user *buffer, size_t *lenp, loff_t *ppos)
2208 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2209 void __user *buffer, size_t *lenp, loff_t *ppos)
2214 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2215 void __user *buffer, size_t *lenp, loff_t *ppos)
2220 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2221 void __user *buffer, size_t *lenp, loff_t *ppos)
2226 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2227 void __user *buffer, size_t *lenp, loff_t *ppos)
2232 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2233 void __user *buffer, size_t *lenp, loff_t *ppos)
2238 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2239 void __user *buffer, size_t *lenp, loff_t *ppos)
2244 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2246 void __user *buffer,
2247 size_t *lenp, loff_t *ppos)
2253 #endif /* CONFIG_PROC_FS */
2257 * General sysctl support routines
2260 /* The generic string strategy routine: */
2261 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2262 void __user *oldval, size_t __user *oldlenp,
2263 void __user *newval, size_t newlen, void **context)
2265 if (!table->data || !table->maxlen)
2268 if (oldval && oldlenp) {
2270 if (get_user(bufsize, oldlenp))
2273 size_t len = strlen(table->data), copied;
2275 /* This shouldn't trigger for a well-formed sysctl */
2276 if (len > table->maxlen)
2277 len = table->maxlen;
2279 /* Copy up to a max of bufsize-1 bytes of the string */
2280 copied = (len >= bufsize) ? bufsize - 1 : len;
2282 if (copy_to_user(oldval, table->data, copied) ||
2283 put_user(0, (char __user *)(oldval + copied)))
2285 if (put_user(len, oldlenp))
2289 if (newval && newlen) {
2290 size_t len = newlen;
2291 if (len > table->maxlen)
2292 len = table->maxlen;
2293 if(copy_from_user(table->data, newval, len))
2295 if (len == table->maxlen)
2297 ((char *) table->data)[len] = 0;
2303 * This function makes sure that all of the integers in the vector
2304 * are between the minimum and maximum values given in the arrays
2305 * table->extra1 and table->extra2, respectively.
2307 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2308 void __user *oldval, size_t __user *oldlenp,
2309 void __user *newval, size_t newlen, void **context)
2312 if (newval && newlen) {
2313 int __user *vec = (int __user *) newval;
2314 int *min = (int *) table->extra1;
2315 int *max = (int *) table->extra2;
2319 if (newlen % sizeof(int) != 0)
2322 if (!table->extra1 && !table->extra2)
2325 if (newlen > table->maxlen)
2326 newlen = table->maxlen;
2327 length = newlen / sizeof(int);
2329 for (i = 0; i < length; i++) {
2331 if (get_user(value, vec + i))
2333 if (min && value < min[i])
2335 if (max && value > max[i])
2342 /* Strategy function to convert jiffies to seconds */
2343 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2344 void __user *oldval, size_t __user *oldlenp,
2345 void __user *newval, size_t newlen, void **context)
2350 if (get_user(olen, oldlenp))
2352 if (olen!=sizeof(int))
2355 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2356 (oldlenp && put_user(sizeof(int),oldlenp)))
2359 if (newval && newlen) {
2361 if (newlen != sizeof(int))
2363 if (get_user(new, (int __user *)newval))
2365 *(int *)(table->data) = new*HZ;
2370 /* Strategy function to convert jiffies to seconds */
2371 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2372 void __user *oldval, size_t __user *oldlenp,
2373 void __user *newval, size_t newlen, void **context)
2378 if (get_user(olen, oldlenp))
2380 if (olen!=sizeof(int))
2383 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2384 (oldlenp && put_user(sizeof(int),oldlenp)))
2387 if (newval && newlen) {
2389 if (newlen != sizeof(int))
2391 if (get_user(new, (int __user *)newval))
2393 *(int *)(table->data) = msecs_to_jiffies(new);
2398 #else /* CONFIG_SYSCTL */
2401 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2406 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2407 void __user *oldval, size_t __user *oldlenp,
2408 void __user *newval, size_t newlen, void **context)
2413 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2414 void __user *oldval, size_t __user *oldlenp,
2415 void __user *newval, size_t newlen, void **context)
2420 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2421 void __user *oldval, size_t __user *oldlenp,
2422 void __user *newval, size_t newlen, void **context)
2427 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2428 void __user *oldval, size_t __user *oldlenp,
2429 void __user *newval, size_t newlen, void **context)
2434 int proc_dostring(ctl_table *table, int write, struct file *filp,
2435 void __user *buffer, size_t *lenp, loff_t *ppos)
2440 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2441 void __user *buffer, size_t *lenp, loff_t *ppos)
2446 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2447 void __user *buffer, size_t *lenp, loff_t *ppos)
2452 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2453 void __user *buffer, size_t *lenp, loff_t *ppos)
2458 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2459 void __user *buffer, size_t *lenp, loff_t *ppos)
2464 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2465 void __user *buffer, size_t *lenp, loff_t *ppos)
2470 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2471 void __user *buffer, size_t *lenp, loff_t *ppos)
2476 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2477 void __user *buffer, size_t *lenp, loff_t *ppos)
2482 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2484 void __user *buffer,
2485 size_t *lenp, loff_t *ppos)
2490 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2496 void unregister_sysctl_table(struct ctl_table_header * table)
2500 #endif /* CONFIG_SYSCTL */
2503 * No sense putting this after each symbol definition, twice,
2504 * exception granted :-)
2506 EXPORT_SYMBOL(proc_dointvec);
2507 EXPORT_SYMBOL(proc_dointvec_jiffies);
2508 EXPORT_SYMBOL(proc_dointvec_minmax);
2509 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2510 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2511 EXPORT_SYMBOL(proc_dostring);
2512 EXPORT_SYMBOL(proc_doulongvec_minmax);
2513 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2514 EXPORT_SYMBOL(register_sysctl_table);
2515 EXPORT_SYMBOL(sysctl_intvec);
2516 EXPORT_SYMBOL(sysctl_jiffies);
2517 EXPORT_SYMBOL(sysctl_ms_jiffies);
2518 EXPORT_SYMBOL(sysctl_string);
2519 EXPORT_SYMBOL(unregister_sysctl_table);