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>
49 #include <linux/vserver/cvirt.h>
51 #include <asm/uaccess.h>
52 #include <asm/processor.h>
54 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
55 void __user *buffer, size_t *lenp, loff_t *ppos);
57 #if defined(CONFIG_SYSCTL)
59 /* External variables not in a header file. */
61 extern int sysctl_overcommit_memory;
62 extern int sysctl_overcommit_ratio;
63 extern int max_threads;
64 extern int sysrq_enabled;
65 extern int core_uses_pid;
66 extern int suid_dumpable;
67 extern char core_pattern[];
70 extern int min_free_kbytes;
71 extern int printk_ratelimit_jiffies;
72 extern int printk_ratelimit_burst;
73 extern int pid_max_min, pid_max_max;
74 extern int sysctl_drop_caches;
75 extern int percpu_pagelist_fraction;
77 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
78 int unknown_nmi_panic;
79 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
80 void __user *, size_t *, loff_t *);
83 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
84 static int maxolduid = 65535;
86 static int min_percpu_pagelist_fract = 8;
88 static int ngroups_max = NGROUPS_MAX;
91 extern char modprobe_path[];
93 extern char vshelper_path[];
94 #ifdef CONFIG_CHR_DEV_SG
95 extern int sg_big_buff;
98 extern size_t shm_ctlmax;
99 extern size_t shm_ctlall;
100 extern int shm_ctlmni;
101 extern int msg_ctlmax;
102 extern int msg_ctlmnb;
103 extern int msg_ctlmni;
104 extern int sem_ctls[];
108 extern char reboot_command [];
109 extern int stop_a_enabled;
110 extern int scons_pwroff;
114 extern int pwrsw_enabled;
115 extern int unaligned_enabled;
119 #ifdef CONFIG_MATHEMU
120 extern int sysctl_ieee_emulation_warnings;
122 extern int sysctl_userprocess_debug;
123 extern int spin_retry;
126 extern int sysctl_hz_timer;
128 #ifdef CONFIG_BSD_PROCESS_ACCT
129 extern int acct_parm[];
133 extern int no_unaligned_warning;
136 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
137 ctl_table *, void **);
138 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
139 void __user *buffer, size_t *lenp, loff_t *ppos);
141 static ctl_table root_table[];
142 static struct ctl_table_header root_table_header =
143 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
145 static ctl_table kern_table[];
146 static ctl_table vm_table[];
147 static ctl_table proc_table[];
148 static ctl_table fs_table[];
149 static ctl_table debug_table[];
150 static ctl_table dev_table[];
151 extern ctl_table random_table[];
152 #ifdef CONFIG_UNIX98_PTYS
153 extern ctl_table pty_table[];
155 #ifdef CONFIG_INOTIFY
156 extern ctl_table inotify_table[];
159 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
160 int sysctl_legacy_va_layout;
163 /* /proc declarations: */
165 #ifdef CONFIG_PROC_FS
167 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
168 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
169 static int proc_opensys(struct inode *, struct file *);
171 struct file_operations proc_sys_file_operations = {
172 .open = proc_opensys,
173 .read = proc_readsys,
174 .write = proc_writesys,
177 extern struct proc_dir_entry *proc_sys_root;
179 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
180 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
183 /* The default sysctl tables: */
185 static ctl_table root_table[] = {
187 .ctl_name = CTL_KERN,
188 .procname = "kernel",
207 .ctl_name = CTL_PROC,
219 .ctl_name = CTL_DEBUG,
222 .child = debug_table,
234 static ctl_table kern_table[] = {
236 .ctl_name = KERN_OSTYPE,
237 .procname = "ostype",
238 .data = system_utsname.sysname,
239 .maxlen = sizeof(system_utsname.sysname),
241 .proc_handler = &proc_doutsstring,
242 .virt_handler = &vx_uts_virt_handler,
243 .strategy = &sysctl_string,
246 .ctl_name = KERN_OSRELEASE,
247 .procname = "osrelease",
248 .data = system_utsname.release,
249 .maxlen = sizeof(system_utsname.release),
251 .proc_handler = &proc_doutsstring,
252 .virt_handler = &vx_uts_virt_handler,
253 .strategy = &sysctl_string,
256 .ctl_name = KERN_VERSION,
257 .procname = "version",
258 .data = system_utsname.version,
259 .maxlen = sizeof(system_utsname.version),
261 .proc_handler = &proc_doutsstring,
262 .virt_handler = &vx_uts_virt_handler,
263 .strategy = &sysctl_string,
266 .ctl_name = KERN_NODENAME,
267 .procname = "hostname",
268 .data = system_utsname.nodename,
269 .maxlen = sizeof(system_utsname.nodename),
271 .proc_handler = &proc_doutsstring,
272 .virt_handler = &vx_uts_virt_handler,
273 .strategy = &sysctl_string,
276 .ctl_name = KERN_DOMAINNAME,
277 .procname = "domainname",
278 .data = system_utsname.domainname,
279 .maxlen = sizeof(system_utsname.domainname),
281 .proc_handler = &proc_doutsstring,
282 .virt_handler = &vx_uts_virt_handler,
283 .strategy = &sysctl_string,
286 .ctl_name = KERN_PANIC,
288 .data = &panic_timeout,
289 .maxlen = sizeof(int),
291 .proc_handler = &proc_dointvec,
294 .ctl_name = KERN_CORE_USES_PID,
295 .procname = "core_uses_pid",
296 .data = &core_uses_pid,
297 .maxlen = sizeof(int),
299 .proc_handler = &proc_dointvec,
302 .ctl_name = KERN_CORE_PATTERN,
303 .procname = "core_pattern",
304 .data = core_pattern,
307 .proc_handler = &proc_dostring,
308 .strategy = &sysctl_string,
311 .ctl_name = KERN_TAINTED,
312 .procname = "tainted",
314 .maxlen = sizeof(int),
316 .proc_handler = &proc_dointvec,
319 .ctl_name = KERN_CAP_BSET,
320 .procname = "cap-bound",
322 .maxlen = sizeof(kernel_cap_t),
324 .proc_handler = &proc_dointvec_bset,
326 #ifdef CONFIG_BLK_DEV_INITRD
328 .ctl_name = KERN_REALROOTDEV,
329 .procname = "real-root-dev",
330 .data = &real_root_dev,
331 .maxlen = sizeof(int),
333 .proc_handler = &proc_dointvec,
338 .ctl_name = KERN_SPARC_REBOOT,
339 .procname = "reboot-cmd",
340 .data = reboot_command,
343 .proc_handler = &proc_dostring,
344 .strategy = &sysctl_string,
347 .ctl_name = KERN_SPARC_STOP_A,
348 .procname = "stop-a",
349 .data = &stop_a_enabled,
350 .maxlen = sizeof (int),
352 .proc_handler = &proc_dointvec,
355 .ctl_name = KERN_SPARC_SCONS_PWROFF,
356 .procname = "scons-poweroff",
357 .data = &scons_pwroff,
358 .maxlen = sizeof (int),
360 .proc_handler = &proc_dointvec,
365 .ctl_name = KERN_HPPA_PWRSW,
366 .procname = "soft-power",
367 .data = &pwrsw_enabled,
368 .maxlen = sizeof (int),
370 .proc_handler = &proc_dointvec,
373 .ctl_name = KERN_HPPA_UNALIGNED,
374 .procname = "unaligned-trap",
375 .data = &unaligned_enabled,
376 .maxlen = sizeof (int),
378 .proc_handler = &proc_dointvec,
382 .ctl_name = KERN_CTLALTDEL,
383 .procname = "ctrl-alt-del",
385 .maxlen = sizeof(int),
387 .proc_handler = &proc_dointvec,
390 .ctl_name = KERN_PRINTK,
391 .procname = "printk",
392 .data = &console_loglevel,
393 .maxlen = 4*sizeof(int),
395 .proc_handler = &proc_dointvec,
399 .ctl_name = KERN_MODPROBE,
400 .procname = "modprobe",
401 .data = &modprobe_path,
402 .maxlen = KMOD_PATH_LEN,
404 .proc_handler = &proc_dostring,
405 .strategy = &sysctl_string,
408 #ifdef CONFIG_HOTPLUG
410 .ctl_name = KERN_HOTPLUG,
411 .procname = "hotplug",
412 .data = &uevent_helper,
413 .maxlen = UEVENT_HELPER_PATH_LEN,
415 .proc_handler = &proc_dostring,
416 .strategy = &sysctl_string,
420 .ctl_name = KERN_VSHELPER,
421 .procname = "vshelper",
422 .data = &vshelper_path,
425 .proc_handler = &proc_dostring,
426 .strategy = &sysctl_string,
428 #ifdef CONFIG_CHR_DEV_SG
430 .ctl_name = KERN_SG_BIG_BUFF,
431 .procname = "sg-big-buff",
432 .data = &sg_big_buff,
433 .maxlen = sizeof (int),
435 .proc_handler = &proc_dointvec,
438 #ifdef CONFIG_BSD_PROCESS_ACCT
440 .ctl_name = KERN_ACCT,
443 .maxlen = 3*sizeof(int),
445 .proc_handler = &proc_dointvec,
448 #ifdef CONFIG_SYSVIPC
450 .ctl_name = KERN_SHMMAX,
451 .procname = "shmmax",
453 .maxlen = sizeof (size_t),
455 .proc_handler = &proc_doulongvec_minmax,
458 .ctl_name = KERN_SHMALL,
459 .procname = "shmall",
461 .maxlen = sizeof (size_t),
463 .proc_handler = &proc_doulongvec_minmax,
466 .ctl_name = KERN_SHMMNI,
467 .procname = "shmmni",
469 .maxlen = sizeof (int),
471 .proc_handler = &proc_dointvec,
474 .ctl_name = KERN_MSGMAX,
475 .procname = "msgmax",
477 .maxlen = sizeof (int),
479 .proc_handler = &proc_dointvec,
482 .ctl_name = KERN_MSGMNI,
483 .procname = "msgmni",
485 .maxlen = sizeof (int),
487 .proc_handler = &proc_dointvec,
490 .ctl_name = KERN_MSGMNB,
491 .procname = "msgmnb",
493 .maxlen = sizeof (int),
495 .proc_handler = &proc_dointvec,
498 .ctl_name = KERN_SEM,
501 .maxlen = 4*sizeof (int),
503 .proc_handler = &proc_dointvec,
506 #ifdef CONFIG_MAGIC_SYSRQ
508 .ctl_name = KERN_SYSRQ,
510 .data = &sysrq_enabled,
511 .maxlen = sizeof (int),
513 .proc_handler = &proc_dointvec,
517 .ctl_name = KERN_CADPID,
518 .procname = "cad_pid",
520 .maxlen = sizeof (int),
522 .proc_handler = &proc_dointvec,
525 .ctl_name = KERN_MAX_THREADS,
526 .procname = "threads-max",
527 .data = &max_threads,
528 .maxlen = sizeof(int),
530 .proc_handler = &proc_dointvec,
533 .ctl_name = KERN_RANDOM,
534 .procname = "random",
536 .child = random_table,
538 #ifdef CONFIG_UNIX98_PTYS
540 .ctl_name = KERN_PTY,
547 .ctl_name = KERN_OVERFLOWUID,
548 .procname = "overflowuid",
549 .data = &overflowuid,
550 .maxlen = sizeof(int),
552 .proc_handler = &proc_dointvec_minmax,
553 .strategy = &sysctl_intvec,
554 .extra1 = &minolduid,
555 .extra2 = &maxolduid,
558 .ctl_name = KERN_OVERFLOWGID,
559 .procname = "overflowgid",
560 .data = &overflowgid,
561 .maxlen = sizeof(int),
563 .proc_handler = &proc_dointvec_minmax,
564 .strategy = &sysctl_intvec,
565 .extra1 = &minolduid,
566 .extra2 = &maxolduid,
569 #ifdef CONFIG_MATHEMU
571 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
572 .procname = "ieee_emulation_warnings",
573 .data = &sysctl_ieee_emulation_warnings,
574 .maxlen = sizeof(int),
576 .proc_handler = &proc_dointvec,
579 #ifdef CONFIG_NO_IDLE_HZ
581 .ctl_name = KERN_HZ_TIMER,
582 .procname = "hz_timer",
583 .data = &sysctl_hz_timer,
584 .maxlen = sizeof(int),
586 .proc_handler = &proc_dointvec,
590 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
591 .procname = "userprocess_debug",
592 .data = &sysctl_userprocess_debug,
593 .maxlen = sizeof(int),
595 .proc_handler = &proc_dointvec,
599 .ctl_name = KERN_PIDMAX,
600 .procname = "pid_max",
602 .maxlen = sizeof (int),
604 .proc_handler = &proc_dointvec_minmax,
605 .strategy = sysctl_intvec,
606 .extra1 = &pid_max_min,
607 .extra2 = &pid_max_max,
610 .ctl_name = KERN_PANIC_ON_OOPS,
611 .procname = "panic_on_oops",
612 .data = &panic_on_oops,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
618 .ctl_name = KERN_PRINTK_RATELIMIT,
619 .procname = "printk_ratelimit",
620 .data = &printk_ratelimit_jiffies,
621 .maxlen = sizeof(int),
623 .proc_handler = &proc_dointvec_jiffies,
624 .strategy = &sysctl_jiffies,
627 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
628 .procname = "printk_ratelimit_burst",
629 .data = &printk_ratelimit_burst,
630 .maxlen = sizeof(int),
632 .proc_handler = &proc_dointvec,
635 .ctl_name = KERN_NGROUPS_MAX,
636 .procname = "ngroups_max",
637 .data = &ngroups_max,
638 .maxlen = sizeof (int),
640 .proc_handler = &proc_dointvec,
642 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
644 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
645 .procname = "unknown_nmi_panic",
646 .data = &unknown_nmi_panic,
647 .maxlen = sizeof (int),
649 .proc_handler = &proc_unknown_nmi_panic,
652 #if defined(CONFIG_X86)
654 .ctl_name = KERN_BOOTLOADER_TYPE,
655 .procname = "bootloader_type",
656 .data = &bootloader_type,
657 .maxlen = sizeof (int),
659 .proc_handler = &proc_dointvec,
662 #if defined(CONFIG_MMU)
664 .ctl_name = KERN_RANDOMIZE,
665 .procname = "randomize_va_space",
666 .data = &randomize_va_space,
667 .maxlen = sizeof(int),
669 .proc_handler = &proc_dointvec,
672 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
674 .ctl_name = KERN_SPIN_RETRY,
675 .procname = "spin_retry",
677 .maxlen = sizeof (int),
679 .proc_handler = &proc_dointvec,
682 #ifdef CONFIG_ACPI_SLEEP
684 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
685 .procname = "acpi_video_flags",
686 .data = &acpi_video_flags,
687 .maxlen = sizeof (unsigned long),
689 .proc_handler = &proc_doulongvec_minmax,
694 .ctl_name = KERN_IA64_UNALIGNED,
695 .procname = "ignore-unaligned-usertrap",
696 .data = &no_unaligned_warning,
697 .maxlen = sizeof (int),
699 .proc_handler = &proc_dointvec,
705 /* Constants for minimum and maximum testing in vm_table.
706 We use these as one-element integer vectors. */
708 static int one_hundred = 100;
711 static ctl_table vm_table[] = {
713 .ctl_name = VM_OVERCOMMIT_MEMORY,
714 .procname = "overcommit_memory",
715 .data = &sysctl_overcommit_memory,
716 .maxlen = sizeof(sysctl_overcommit_memory),
718 .proc_handler = &proc_dointvec,
721 .ctl_name = VM_OVERCOMMIT_RATIO,
722 .procname = "overcommit_ratio",
723 .data = &sysctl_overcommit_ratio,
724 .maxlen = sizeof(sysctl_overcommit_ratio),
726 .proc_handler = &proc_dointvec,
729 .ctl_name = VM_PAGE_CLUSTER,
730 .procname = "page-cluster",
731 .data = &page_cluster,
732 .maxlen = sizeof(int),
734 .proc_handler = &proc_dointvec,
737 .ctl_name = VM_DIRTY_BACKGROUND,
738 .procname = "dirty_background_ratio",
739 .data = &dirty_background_ratio,
740 .maxlen = sizeof(dirty_background_ratio),
742 .proc_handler = &proc_dointvec_minmax,
743 .strategy = &sysctl_intvec,
745 .extra2 = &one_hundred,
748 .ctl_name = VM_DIRTY_RATIO,
749 .procname = "dirty_ratio",
750 .data = &vm_dirty_ratio,
751 .maxlen = sizeof(vm_dirty_ratio),
753 .proc_handler = &proc_dointvec_minmax,
754 .strategy = &sysctl_intvec,
756 .extra2 = &one_hundred,
759 .ctl_name = VM_DIRTY_WB_CS,
760 .procname = "dirty_writeback_centisecs",
761 .data = &dirty_writeback_centisecs,
762 .maxlen = sizeof(dirty_writeback_centisecs),
764 .proc_handler = &dirty_writeback_centisecs_handler,
767 .ctl_name = VM_DIRTY_EXPIRE_CS,
768 .procname = "dirty_expire_centisecs",
769 .data = &dirty_expire_centisecs,
770 .maxlen = sizeof(dirty_expire_centisecs),
772 .proc_handler = &proc_dointvec,
775 .ctl_name = VM_NR_PDFLUSH_THREADS,
776 .procname = "nr_pdflush_threads",
777 .data = &nr_pdflush_threads,
778 .maxlen = sizeof nr_pdflush_threads,
779 .mode = 0444 /* read-only*/,
780 .proc_handler = &proc_dointvec,
783 .ctl_name = VM_SWAPPINESS,
784 .procname = "swappiness",
785 .data = &vm_swappiness,
786 .maxlen = sizeof(vm_swappiness),
788 .proc_handler = &proc_dointvec_minmax,
789 .strategy = &sysctl_intvec,
791 .extra2 = &one_hundred,
793 #ifdef CONFIG_HUGETLB_PAGE
795 .ctl_name = VM_HUGETLB_PAGES,
796 .procname = "nr_hugepages",
797 .data = &max_huge_pages,
798 .maxlen = sizeof(unsigned long),
800 .proc_handler = &hugetlb_sysctl_handler,
801 .extra1 = (void *)&hugetlb_zero,
802 .extra2 = (void *)&hugetlb_infinity,
805 .ctl_name = VM_HUGETLB_GROUP,
806 .procname = "hugetlb_shm_group",
807 .data = &sysctl_hugetlb_shm_group,
808 .maxlen = sizeof(gid_t),
810 .proc_handler = &proc_dointvec,
814 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
815 .procname = "lowmem_reserve_ratio",
816 .data = &sysctl_lowmem_reserve_ratio,
817 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
819 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
820 .strategy = &sysctl_intvec,
823 .ctl_name = VM_DROP_PAGECACHE,
824 .procname = "drop_caches",
825 .data = &sysctl_drop_caches,
826 .maxlen = sizeof(int),
828 .proc_handler = drop_caches_sysctl_handler,
829 .strategy = &sysctl_intvec,
832 .ctl_name = VM_MIN_FREE_KBYTES,
833 .procname = "min_free_kbytes",
834 .data = &min_free_kbytes,
835 .maxlen = sizeof(min_free_kbytes),
837 .proc_handler = &min_free_kbytes_sysctl_handler,
838 .strategy = &sysctl_intvec,
842 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
843 .procname = "percpu_pagelist_fraction",
844 .data = &percpu_pagelist_fraction,
845 .maxlen = sizeof(percpu_pagelist_fraction),
847 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
848 .strategy = &sysctl_intvec,
849 .extra1 = &min_percpu_pagelist_fract,
853 .ctl_name = VM_MAX_MAP_COUNT,
854 .procname = "max_map_count",
855 .data = &sysctl_max_map_count,
856 .maxlen = sizeof(sysctl_max_map_count),
858 .proc_handler = &proc_dointvec
862 .ctl_name = VM_LAPTOP_MODE,
863 .procname = "laptop_mode",
864 .data = &laptop_mode,
865 .maxlen = sizeof(laptop_mode),
867 .proc_handler = &proc_dointvec,
868 .strategy = &sysctl_intvec,
872 .ctl_name = VM_BLOCK_DUMP,
873 .procname = "block_dump",
875 .maxlen = sizeof(block_dump),
877 .proc_handler = &proc_dointvec,
878 .strategy = &sysctl_intvec,
882 .ctl_name = VM_VFS_CACHE_PRESSURE,
883 .procname = "vfs_cache_pressure",
884 .data = &sysctl_vfs_cache_pressure,
885 .maxlen = sizeof(sysctl_vfs_cache_pressure),
887 .proc_handler = &proc_dointvec,
888 .strategy = &sysctl_intvec,
891 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
893 .ctl_name = VM_LEGACY_VA_LAYOUT,
894 .procname = "legacy_va_layout",
895 .data = &sysctl_legacy_va_layout,
896 .maxlen = sizeof(sysctl_legacy_va_layout),
898 .proc_handler = &proc_dointvec,
899 .strategy = &sysctl_intvec,
905 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
906 .procname = "swap_token_timeout",
907 .data = &swap_token_default_timeout,
908 .maxlen = sizeof(swap_token_default_timeout),
910 .proc_handler = &proc_dointvec_jiffies,
911 .strategy = &sysctl_jiffies,
916 .ctl_name = VM_ZONE_RECLAIM_MODE,
917 .procname = "zone_reclaim_mode",
918 .data = &zone_reclaim_mode,
919 .maxlen = sizeof(zone_reclaim_mode),
921 .proc_handler = &proc_dointvec,
922 .strategy = &sysctl_intvec,
926 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
927 .procname = "zone_reclaim_interval",
928 .data = &zone_reclaim_interval,
929 .maxlen = sizeof(zone_reclaim_interval),
931 .proc_handler = &proc_dointvec_jiffies,
932 .strategy = &sysctl_jiffies,
938 static ctl_table proc_table[] = {
942 static ctl_table fs_table[] = {
944 .ctl_name = FS_NRINODE,
945 .procname = "inode-nr",
946 .data = &inodes_stat,
947 .maxlen = 2*sizeof(int),
949 .proc_handler = &proc_dointvec,
952 .ctl_name = FS_STATINODE,
953 .procname = "inode-state",
954 .data = &inodes_stat,
955 .maxlen = 7*sizeof(int),
957 .proc_handler = &proc_dointvec,
960 .ctl_name = FS_NRFILE,
961 .procname = "file-nr",
963 .maxlen = 3*sizeof(int),
965 .proc_handler = &proc_nr_files,
968 .ctl_name = FS_MAXFILE,
969 .procname = "file-max",
970 .data = &files_stat.max_files,
971 .maxlen = sizeof(int),
973 .proc_handler = &proc_dointvec,
976 .ctl_name = FS_DENTRY,
977 .procname = "dentry-state",
978 .data = &dentry_stat,
979 .maxlen = 6*sizeof(int),
981 .proc_handler = &proc_dointvec,
984 .ctl_name = FS_OVERFLOWUID,
985 .procname = "overflowuid",
986 .data = &fs_overflowuid,
987 .maxlen = sizeof(int),
989 .proc_handler = &proc_dointvec_minmax,
990 .strategy = &sysctl_intvec,
991 .extra1 = &minolduid,
992 .extra2 = &maxolduid,
995 .ctl_name = FS_OVERFLOWGID,
996 .procname = "overflowgid",
997 .data = &fs_overflowgid,
998 .maxlen = sizeof(int),
1000 .proc_handler = &proc_dointvec_minmax,
1001 .strategy = &sysctl_intvec,
1002 .extra1 = &minolduid,
1003 .extra2 = &maxolduid,
1006 .ctl_name = FS_LEASES,
1007 .procname = "leases-enable",
1008 .data = &leases_enable,
1009 .maxlen = sizeof(int),
1011 .proc_handler = &proc_dointvec,
1013 #ifdef CONFIG_DNOTIFY
1015 .ctl_name = FS_DIR_NOTIFY,
1016 .procname = "dir-notify-enable",
1017 .data = &dir_notify_enable,
1018 .maxlen = sizeof(int),
1020 .proc_handler = &proc_dointvec,
1025 .ctl_name = FS_LEASE_TIME,
1026 .procname = "lease-break-time",
1027 .data = &lease_break_time,
1028 .maxlen = sizeof(int),
1030 .proc_handler = &proc_dointvec,
1033 .ctl_name = FS_AIO_NR,
1034 .procname = "aio-nr",
1036 .maxlen = sizeof(aio_nr),
1038 .proc_handler = &proc_doulongvec_minmax,
1041 .ctl_name = FS_AIO_MAX_NR,
1042 .procname = "aio-max-nr",
1043 .data = &aio_max_nr,
1044 .maxlen = sizeof(aio_max_nr),
1046 .proc_handler = &proc_doulongvec_minmax,
1048 #ifdef CONFIG_INOTIFY
1050 .ctl_name = FS_INOTIFY,
1051 .procname = "inotify",
1053 .child = inotify_table,
1058 .ctl_name = KERN_SETUID_DUMPABLE,
1059 .procname = "suid_dumpable",
1060 .data = &suid_dumpable,
1061 .maxlen = sizeof(int),
1063 .proc_handler = &proc_dointvec,
1068 static ctl_table debug_table[] = {
1072 static ctl_table dev_table[] = {
1076 extern void init_irq_proc (void);
1078 static DEFINE_SPINLOCK(sysctl_lock);
1080 /* called under sysctl_lock */
1081 static int use_table(struct ctl_table_header *p)
1083 if (unlikely(p->unregistering))
1089 /* called under sysctl_lock */
1090 static void unuse_table(struct ctl_table_header *p)
1093 if (unlikely(p->unregistering))
1094 complete(p->unregistering);
1097 /* called under sysctl_lock, will reacquire if has to wait */
1098 static void start_unregistering(struct ctl_table_header *p)
1101 * if p->used is 0, nobody will ever touch that entry again;
1102 * we'll eliminate all paths to it before dropping sysctl_lock
1104 if (unlikely(p->used)) {
1105 struct completion wait;
1106 init_completion(&wait);
1107 p->unregistering = &wait;
1108 spin_unlock(&sysctl_lock);
1109 wait_for_completion(&wait);
1110 spin_lock(&sysctl_lock);
1113 * do not remove from the list until nobody holds it; walking the
1114 * list in do_sysctl() relies on that.
1116 list_del_init(&p->ctl_entry);
1119 void __init sysctl_init(void)
1121 #ifdef CONFIG_PROC_FS
1122 register_proc_table(root_table, proc_sys_root, &root_table_header);
1127 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1128 void __user *newval, size_t newlen)
1130 struct list_head *tmp;
1131 int error = -ENOTDIR;
1133 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1137 if (!oldlenp || get_user(old_len, oldlenp))
1140 spin_lock(&sysctl_lock);
1141 tmp = &root_table_header.ctl_entry;
1143 struct ctl_table_header *head =
1144 list_entry(tmp, struct ctl_table_header, ctl_entry);
1145 void *context = NULL;
1147 if (!use_table(head))
1150 spin_unlock(&sysctl_lock);
1152 error = parse_table(name, nlen, oldval, oldlenp,
1153 newval, newlen, head->ctl_table,
1157 spin_lock(&sysctl_lock);
1159 if (error != -ENOTDIR)
1161 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1162 spin_unlock(&sysctl_lock);
1166 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1168 struct __sysctl_args tmp;
1171 if (copy_from_user(&tmp, args, sizeof(tmp)))
1175 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1176 tmp.newval, tmp.newlen);
1182 * ctl_perm does NOT grant the superuser all rights automatically, because
1183 * some sysctl variables are readonly even to root.
1186 static int test_perm(int mode, int op)
1190 else if (in_egroup_p(0))
1192 if ((mode & op & 0007) == op)
1197 static inline int ctl_perm(ctl_table *table, int op)
1200 error = security_sysctl(table, op);
1203 return test_perm(table->mode, op);
1206 static int parse_table(int __user *name, int nlen,
1207 void __user *oldval, size_t __user *oldlenp,
1208 void __user *newval, size_t newlen,
1209 ctl_table *table, void **context)
1215 if (get_user(n, name))
1217 for ( ; table->ctl_name; table++) {
1218 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1221 if (ctl_perm(table, 001))
1223 if (table->strategy) {
1224 error = table->strategy(
1227 newval, newlen, context);
1233 table = table->child;
1236 error = do_sysctl_strategy(table, name, nlen,
1238 newval, newlen, context);
1245 /* Perform the actual read/write of a sysctl table entry. */
1246 int do_sysctl_strategy (ctl_table *table,
1247 int __user *name, int nlen,
1248 void __user *oldval, size_t __user *oldlenp,
1249 void __user *newval, size_t newlen, void **context)
1258 if (ctl_perm(table, op))
1261 if (table->strategy) {
1262 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1263 newval, newlen, context);
1270 /* If there is no strategy routine, or if the strategy returns
1271 * zero, proceed with automatic r/w */
1272 if (table->data && table->maxlen) {
1273 if (oldval && oldlenp) {
1274 if (get_user(len, oldlenp))
1277 if (len > table->maxlen)
1278 len = table->maxlen;
1279 if(copy_to_user(oldval, table->data, len))
1281 if(put_user(len, oldlenp))
1285 if (newval && newlen) {
1287 if (len > table->maxlen)
1288 len = table->maxlen;
1289 if(copy_from_user(table->data, newval, len))
1297 * register_sysctl_table - register a sysctl hierarchy
1298 * @table: the top-level table structure
1299 * @insert_at_head: whether the entry should be inserted in front or at the end
1301 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1302 * array. An entry with a ctl_name of 0 terminates the table.
1304 * The members of the &ctl_table structure are used as follows:
1306 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1307 * must be unique within that level of sysctl
1309 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1310 * enter a sysctl file
1312 * data - a pointer to data for use by proc_handler
1314 * maxlen - the maximum size in bytes of the data
1316 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1318 * child - a pointer to the child sysctl table if this entry is a directory, or
1321 * proc_handler - the text handler routine (described below)
1323 * strategy - the strategy routine (described below)
1325 * de - for internal use by the sysctl routines
1327 * extra1, extra2 - extra pointers usable by the proc handler routines
1329 * Leaf nodes in the sysctl tree will be represented by a single file
1330 * under /proc; non-leaf nodes will be represented by directories.
1332 * sysctl(2) can automatically manage read and write requests through
1333 * the sysctl table. The data and maxlen fields of the ctl_table
1334 * struct enable minimal validation of the values being written to be
1335 * performed, and the mode field allows minimal authentication.
1337 * More sophisticated management can be enabled by the provision of a
1338 * strategy routine with the table entry. This will be called before
1339 * any automatic read or write of the data is performed.
1341 * The strategy routine may return
1343 * < 0 - Error occurred (error is passed to user process)
1345 * 0 - OK - proceed with automatic read or write.
1347 * > 0 - OK - read or write has been done by the strategy routine, so
1348 * return immediately.
1350 * There must be a proc_handler routine for any terminal nodes
1351 * mirrored under /proc/sys (non-terminals are handled by a built-in
1352 * directory handler). Several default handlers are available to
1353 * cover common cases -
1355 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1356 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1357 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1359 * It is the handler's job to read the input buffer from user memory
1360 * and process it. The handler should return 0 on success.
1362 * This routine returns %NULL on a failure to register, and a pointer
1363 * to the table header on success.
1365 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1368 struct ctl_table_header *tmp;
1369 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1372 tmp->ctl_table = table;
1373 INIT_LIST_HEAD(&tmp->ctl_entry);
1375 tmp->unregistering = NULL;
1376 spin_lock(&sysctl_lock);
1378 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1380 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1381 spin_unlock(&sysctl_lock);
1382 #ifdef CONFIG_PROC_FS
1383 register_proc_table(table, proc_sys_root, tmp);
1389 * unregister_sysctl_table - unregister a sysctl table hierarchy
1390 * @header: the header returned from register_sysctl_table
1392 * Unregisters the sysctl table and all children. proc entries may not
1393 * actually be removed until they are no longer used by anyone.
1395 void unregister_sysctl_table(struct ctl_table_header * header)
1398 spin_lock(&sysctl_lock);
1399 start_unregistering(header);
1400 #ifdef CONFIG_PROC_FS
1401 unregister_proc_table(header->ctl_table, proc_sys_root);
1403 spin_unlock(&sysctl_lock);
1411 #ifdef CONFIG_PROC_FS
1413 /* Scan the sysctl entries in table and add them all into /proc */
1414 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1416 struct proc_dir_entry *de;
1420 for (; table->ctl_name; table++) {
1421 /* Can't do anything without a proc name. */
1422 if (!table->procname)
1424 /* Maybe we can't do anything with it... */
1425 if (!table->proc_handler && !table->child) {
1426 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1431 len = strlen(table->procname);
1435 if (table->proc_handler)
1439 for (de = root->subdir; de; de = de->next) {
1440 if (proc_match(len, table->procname, de))
1443 /* If the subdir exists already, de is non-NULL */
1447 de = create_proc_entry(table->procname, mode, root);
1451 de->data = (void *) table;
1452 if (table->proc_handler)
1453 de->proc_fops = &proc_sys_file_operations;
1456 if (de->mode & S_IFDIR)
1457 register_proc_table(table->child, de, set);
1462 * Unregister a /proc sysctl table and any subdirectories.
1464 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1466 struct proc_dir_entry *de;
1467 for (; table->ctl_name; table++) {
1468 if (!(de = table->de))
1470 if (de->mode & S_IFDIR) {
1471 if (!table->child) {
1472 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1475 unregister_proc_table(table->child, de);
1477 /* Don't unregister directories which still have entries.. */
1483 * In any case, mark the entry as goner; we'll keep it
1484 * around if it's busy, but we'll know to do nothing with
1485 * its fields. We are under sysctl_lock here.
1489 /* Don't unregister proc entries that are still being used.. */
1490 if (atomic_read(&de->count))
1494 remove_proc_entry(table->procname, root);
1498 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1499 size_t count, loff_t *ppos)
1502 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1503 struct ctl_table *table;
1505 ssize_t error = -ENOTDIR;
1507 spin_lock(&sysctl_lock);
1508 if (de && de->data && use_table(de->set)) {
1510 * at that point we know that sysctl was not unregistered
1511 * and won't be until we finish
1513 spin_unlock(&sysctl_lock);
1514 table = (struct ctl_table *) de->data;
1515 if (!table || !table->proc_handler)
1518 op = (write ? 002 : 004);
1519 if (ctl_perm(table, op))
1522 /* careful: calling conventions are nasty here */
1524 error = (*table->proc_handler)(table, write, file,
1529 spin_lock(&sysctl_lock);
1530 unuse_table(de->set);
1532 spin_unlock(&sysctl_lock);
1536 static int proc_opensys(struct inode *inode, struct file *file)
1538 if (file->f_mode & FMODE_WRITE) {
1540 * sysctl entries that are not writable,
1541 * are _NOT_ writable, capabilities or not.
1543 if (!(inode->i_mode & S_IWUSR))
1550 static ssize_t proc_readsys(struct file * file, char __user * buf,
1551 size_t count, loff_t *ppos)
1553 return do_rw_proc(0, file, buf, count, ppos);
1556 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1557 size_t count, loff_t *ppos)
1559 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1563 * proc_dostring - read a string sysctl
1564 * @table: the sysctl table
1565 * @write: %TRUE if this is a write to the sysctl file
1566 * @filp: the file structure
1567 * @buffer: the user buffer
1568 * @lenp: the size of the user buffer
1569 * @ppos: file position
1571 * Reads/writes a string from/to the user buffer. If the kernel
1572 * buffer provided is not large enough to hold the string, the
1573 * string is truncated. The copied string is %NULL-terminated.
1574 * If the string is being read by the user process, it is copied
1575 * and a newline '\n' is added. It is truncated if the buffer is
1578 * Returns 0 on success.
1580 int proc_dostring(ctl_table *table, int write, struct file *filp,
1581 void __user *buffer, size_t *lenp, loff_t *ppos)
1589 maxlen = table->maxlen;
1591 if (!data || !maxlen || !*lenp || (*ppos && !write))
1594 if (table->virt_handler)
1595 table->virt_handler(table, write, filp->f_xid, &data, &maxlen);
1600 while (len < *lenp) {
1601 if (get_user(c, p++))
1603 if (c == 0 || c == '\n')
1609 if(copy_from_user(data, buffer, len))
1611 ((char *) data)[len] = 0;
1620 if(copy_to_user(buffer, data, len))
1623 if(put_user('\n', ((char __user *) buffer) + len))
1634 * Special case of dostring for the UTS structure. This has locks
1635 * to observe. Should this be in kernel/sys.c ????
1638 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1639 void __user *buffer, size_t *lenp, loff_t *ppos)
1644 down_read(&uts_sem);
1645 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1648 down_write(&uts_sem);
1649 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1655 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1657 int write, void *data)
1660 *valp = *negp ? -*lvalp : *lvalp;
1665 *lvalp = (unsigned long)-val;
1668 *lvalp = (unsigned long)val;
1674 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1675 void __user *buffer, size_t *lenp, loff_t *ppos,
1676 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1677 int write, void *data),
1680 #define TMPBUFLEN 21
1681 int *i, vleft, first=1, neg, val;
1685 char buf[TMPBUFLEN], *p;
1686 char __user *s = buffer;
1688 if (!table->data || !table->maxlen || !*lenp ||
1689 (*ppos && !write)) {
1694 i = (int *) table->data;
1695 vleft = table->maxlen / sizeof(*i);
1699 conv = do_proc_dointvec_conv;
1701 for (; left && vleft--; i++, first=0) {
1716 if (len > sizeof(buf) - 1)
1717 len = sizeof(buf) - 1;
1718 if (copy_from_user(buf, s, len))
1722 if (*p == '-' && left > 1) {
1726 if (*p < '0' || *p > '9')
1729 lval = simple_strtoul(p, &p, 0);
1732 if ((len < left) && *p && !isspace(*p))
1739 if (conv(&neg, &lval, i, 1, data))
1746 if (conv(&neg, &lval, i, 0, data))
1749 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1753 if(copy_to_user(s, buf, len))
1760 if (!write && !first && left) {
1761 if(put_user('\n', s))
1768 if (get_user(c, s++))
1784 * proc_dointvec - read a vector of integers
1785 * @table: the sysctl table
1786 * @write: %TRUE if this is a write to the sysctl file
1787 * @filp: the file structure
1788 * @buffer: the user buffer
1789 * @lenp: the size of the user buffer
1790 * @ppos: file position
1792 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1793 * values from/to the user buffer, treated as an ASCII string.
1795 * Returns 0 on success.
1797 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1798 void __user *buffer, size_t *lenp, loff_t *ppos)
1800 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1810 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1812 int write, void *data)
1814 int op = *(int *)data;
1816 int val = *negp ? -*lvalp : *lvalp;
1818 case OP_SET: *valp = val; break;
1819 case OP_AND: *valp &= val; break;
1820 case OP_OR: *valp |= val; break;
1821 case OP_MAX: if(*valp < val)
1824 case OP_MIN: if(*valp > val)
1832 *lvalp = (unsigned long)-val;
1835 *lvalp = (unsigned long)val;
1842 * init may raise the set.
1845 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1846 void __user *buffer, size_t *lenp, loff_t *ppos)
1850 if (!capable(CAP_SYS_MODULE)) {
1854 op = (current->pid == 1) ? OP_SET : OP_AND;
1855 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1856 do_proc_dointvec_bset_conv,&op);
1859 struct do_proc_dointvec_minmax_conv_param {
1864 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1866 int write, void *data)
1868 struct do_proc_dointvec_minmax_conv_param *param = data;
1870 int val = *negp ? -*lvalp : *lvalp;
1871 if ((param->min && *param->min > val) ||
1872 (param->max && *param->max < val))
1879 *lvalp = (unsigned long)-val;
1882 *lvalp = (unsigned long)val;
1889 * proc_dointvec_minmax - read a vector of integers with min/max values
1890 * @table: the sysctl table
1891 * @write: %TRUE if this is a write to the sysctl file
1892 * @filp: the file structure
1893 * @buffer: the user buffer
1894 * @lenp: the size of the user buffer
1895 * @ppos: file position
1897 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1898 * values from/to the user buffer, treated as an ASCII string.
1900 * This routine will ensure the values are within the range specified by
1901 * table->extra1 (min) and table->extra2 (max).
1903 * Returns 0 on success.
1905 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1906 void __user *buffer, size_t *lenp, loff_t *ppos)
1908 struct do_proc_dointvec_minmax_conv_param param = {
1909 .min = (int *) table->extra1,
1910 .max = (int *) table->extra2,
1912 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1913 do_proc_dointvec_minmax_conv, ¶m);
1916 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1918 void __user *buffer,
1919 size_t *lenp, loff_t *ppos,
1920 unsigned long convmul,
1921 unsigned long convdiv)
1923 #define TMPBUFLEN 21
1924 unsigned long *i, *min, *max, val;
1925 int vleft, first=1, neg;
1927 char buf[TMPBUFLEN], *p;
1928 char __user *s = buffer;
1930 if (!table->data || !table->maxlen || !*lenp ||
1931 (*ppos && !write)) {
1936 i = (unsigned long *) table->data;
1937 min = (unsigned long *) table->extra1;
1938 max = (unsigned long *) table->extra2;
1939 vleft = table->maxlen / sizeof(unsigned long);
1942 for (; left && vleft--; i++, min++, max++, first=0) {
1957 if (len > TMPBUFLEN-1)
1959 if (copy_from_user(buf, s, len))
1963 if (*p == '-' && left > 1) {
1967 if (*p < '0' || *p > '9')
1969 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1971 if ((len < left) && *p && !isspace(*p))
1980 if ((min && val < *min) || (max && val > *max))
1987 sprintf(p, "%lu", convdiv * (*i) / convmul);
1991 if(copy_to_user(s, buf, len))
1998 if (!write && !first && left) {
1999 if(put_user('\n', s))
2006 if (get_user(c, s++))
2022 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2023 * @table: the sysctl table
2024 * @write: %TRUE if this is a write to the sysctl file
2025 * @filp: the file structure
2026 * @buffer: the user buffer
2027 * @lenp: the size of the user buffer
2028 * @ppos: file position
2030 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2031 * values from/to the user buffer, treated as an ASCII string.
2033 * This routine will ensure the values are within the range specified by
2034 * table->extra1 (min) and table->extra2 (max).
2036 * Returns 0 on success.
2038 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2039 void __user *buffer, size_t *lenp, loff_t *ppos)
2041 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2045 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2046 * @table: the sysctl table
2047 * @write: %TRUE if this is a write to the sysctl file
2048 * @filp: the file structure
2049 * @buffer: the user buffer
2050 * @lenp: the size of the user buffer
2051 * @ppos: file position
2053 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2054 * values from/to the user buffer, treated as an ASCII string. The values
2055 * are treated as milliseconds, and converted to jiffies when they are stored.
2057 * This routine will ensure the values are within the range specified by
2058 * table->extra1 (min) and table->extra2 (max).
2060 * Returns 0 on success.
2062 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2064 void __user *buffer,
2065 size_t *lenp, loff_t *ppos)
2067 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2068 lenp, ppos, HZ, 1000l);
2072 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2074 int write, void *data)
2077 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2083 lval = (unsigned long)-val;
2086 lval = (unsigned long)val;
2093 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2095 int write, void *data)
2098 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2104 lval = (unsigned long)-val;
2107 lval = (unsigned long)val;
2109 *lvalp = jiffies_to_clock_t(lval);
2114 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2116 int write, void *data)
2119 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2125 lval = (unsigned long)-val;
2128 lval = (unsigned long)val;
2130 *lvalp = jiffies_to_msecs(lval);
2136 * proc_dointvec_jiffies - read a vector of integers as seconds
2137 * @table: the sysctl table
2138 * @write: %TRUE if this is a write to the sysctl file
2139 * @filp: the file structure
2140 * @buffer: the user buffer
2141 * @lenp: the size of the user buffer
2142 * @ppos: file position
2144 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2145 * values from/to the user buffer, treated as an ASCII string.
2146 * The values read are assumed to be in seconds, and are converted into
2149 * Returns 0 on success.
2151 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2152 void __user *buffer, size_t *lenp, loff_t *ppos)
2154 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2155 do_proc_dointvec_jiffies_conv,NULL);
2159 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2160 * @table: the sysctl table
2161 * @write: %TRUE if this is a write to the sysctl file
2162 * @filp: the file structure
2163 * @buffer: the user buffer
2164 * @lenp: the size of the user buffer
2165 * @ppos: pointer to the file position
2167 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2168 * values from/to the user buffer, treated as an ASCII string.
2169 * The values read are assumed to be in 1/USER_HZ seconds, and
2170 * are converted into jiffies.
2172 * Returns 0 on success.
2174 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2175 void __user *buffer, size_t *lenp, loff_t *ppos)
2177 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2178 do_proc_dointvec_userhz_jiffies_conv,NULL);
2182 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2183 * @table: the sysctl table
2184 * @write: %TRUE if this is a write to the sysctl file
2185 * @filp: the file structure
2186 * @buffer: the user buffer
2187 * @lenp: the size of the user buffer
2188 * @ppos: file position
2189 * @ppos: the current position in the file
2191 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2192 * values from/to the user buffer, treated as an ASCII string.
2193 * The values read are assumed to be in 1/1000 seconds, and
2194 * are converted into jiffies.
2196 * Returns 0 on success.
2198 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2199 void __user *buffer, size_t *lenp, loff_t *ppos)
2201 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2202 do_proc_dointvec_ms_jiffies_conv, NULL);
2205 #else /* CONFIG_PROC_FS */
2207 int proc_dostring(ctl_table *table, int write, struct file *filp,
2208 void __user *buffer, size_t *lenp, loff_t *ppos)
2213 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2214 void __user *buffer, size_t *lenp, loff_t *ppos)
2219 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2220 void __user *buffer, size_t *lenp, loff_t *ppos)
2225 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2226 void __user *buffer, size_t *lenp, loff_t *ppos)
2231 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2232 void __user *buffer, size_t *lenp, loff_t *ppos)
2237 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2238 void __user *buffer, size_t *lenp, loff_t *ppos)
2243 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2244 void __user *buffer, size_t *lenp, loff_t *ppos)
2249 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2250 void __user *buffer, size_t *lenp, loff_t *ppos)
2255 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2256 void __user *buffer, size_t *lenp, loff_t *ppos)
2261 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2263 void __user *buffer,
2264 size_t *lenp, loff_t *ppos)
2270 #endif /* CONFIG_PROC_FS */
2274 * General sysctl support routines
2277 /* The generic string strategy routine: */
2278 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2279 void __user *oldval, size_t __user *oldlenp,
2280 void __user *newval, size_t newlen, void **context)
2282 if (!table->data || !table->maxlen)
2285 if (oldval && oldlenp) {
2287 if (get_user(bufsize, oldlenp))
2290 size_t len = strlen(table->data), copied;
2292 /* This shouldn't trigger for a well-formed sysctl */
2293 if (len > table->maxlen)
2294 len = table->maxlen;
2296 /* Copy up to a max of bufsize-1 bytes of the string */
2297 copied = (len >= bufsize) ? bufsize - 1 : len;
2299 if (copy_to_user(oldval, table->data, copied) ||
2300 put_user(0, (char __user *)(oldval + copied)))
2302 if (put_user(len, oldlenp))
2306 if (newval && newlen) {
2307 size_t len = newlen;
2308 if (len > table->maxlen)
2309 len = table->maxlen;
2310 if(copy_from_user(table->data, newval, len))
2312 if (len == table->maxlen)
2314 ((char *) table->data)[len] = 0;
2320 * This function makes sure that all of the integers in the vector
2321 * are between the minimum and maximum values given in the arrays
2322 * table->extra1 and table->extra2, respectively.
2324 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2325 void __user *oldval, size_t __user *oldlenp,
2326 void __user *newval, size_t newlen, void **context)
2329 if (newval && newlen) {
2330 int __user *vec = (int __user *) newval;
2331 int *min = (int *) table->extra1;
2332 int *max = (int *) table->extra2;
2336 if (newlen % sizeof(int) != 0)
2339 if (!table->extra1 && !table->extra2)
2342 if (newlen > table->maxlen)
2343 newlen = table->maxlen;
2344 length = newlen / sizeof(int);
2346 for (i = 0; i < length; i++) {
2348 if (get_user(value, vec + i))
2350 if (min && value < min[i])
2352 if (max && value > max[i])
2359 /* Strategy function to convert jiffies to seconds */
2360 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2361 void __user *oldval, size_t __user *oldlenp,
2362 void __user *newval, size_t newlen, void **context)
2367 if (get_user(olen, oldlenp))
2369 if (olen!=sizeof(int))
2372 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2373 (oldlenp && put_user(sizeof(int),oldlenp)))
2376 if (newval && newlen) {
2378 if (newlen != sizeof(int))
2380 if (get_user(new, (int __user *)newval))
2382 *(int *)(table->data) = new*HZ;
2387 /* Strategy function to convert jiffies to seconds */
2388 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2389 void __user *oldval, size_t __user *oldlenp,
2390 void __user *newval, size_t newlen, void **context)
2395 if (get_user(olen, oldlenp))
2397 if (olen!=sizeof(int))
2400 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2401 (oldlenp && put_user(sizeof(int),oldlenp)))
2404 if (newval && newlen) {
2406 if (newlen != sizeof(int))
2408 if (get_user(new, (int __user *)newval))
2410 *(int *)(table->data) = msecs_to_jiffies(new);
2415 #else /* CONFIG_SYSCTL */
2418 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2423 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2424 void __user *oldval, size_t __user *oldlenp,
2425 void __user *newval, size_t newlen, void **context)
2430 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2431 void __user *oldval, size_t __user *oldlenp,
2432 void __user *newval, size_t newlen, void **context)
2437 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2438 void __user *oldval, size_t __user *oldlenp,
2439 void __user *newval, size_t newlen, void **context)
2444 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2445 void __user *oldval, size_t __user *oldlenp,
2446 void __user *newval, size_t newlen, void **context)
2451 int proc_dostring(ctl_table *table, int write, struct file *filp,
2452 void __user *buffer, size_t *lenp, loff_t *ppos)
2457 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2458 void __user *buffer, size_t *lenp, loff_t *ppos)
2463 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2464 void __user *buffer, size_t *lenp, loff_t *ppos)
2469 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2470 void __user *buffer, size_t *lenp, loff_t *ppos)
2475 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2476 void __user *buffer, size_t *lenp, loff_t *ppos)
2481 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2482 void __user *buffer, size_t *lenp, loff_t *ppos)
2487 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2488 void __user *buffer, size_t *lenp, loff_t *ppos)
2493 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2494 void __user *buffer, size_t *lenp, loff_t *ppos)
2499 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2501 void __user *buffer,
2502 size_t *lenp, loff_t *ppos)
2507 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2513 void unregister_sysctl_table(struct ctl_table_header * table)
2517 #endif /* CONFIG_SYSCTL */
2520 * No sense putting this after each symbol definition, twice,
2521 * exception granted :-)
2523 EXPORT_SYMBOL(proc_dointvec);
2524 EXPORT_SYMBOL(proc_dointvec_jiffies);
2525 EXPORT_SYMBOL(proc_dointvec_minmax);
2526 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2527 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2528 EXPORT_SYMBOL(proc_dostring);
2529 EXPORT_SYMBOL(proc_doulongvec_minmax);
2530 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2531 EXPORT_SYMBOL(register_sysctl_table);
2532 EXPORT_SYMBOL(sysctl_intvec);
2533 EXPORT_SYMBOL(sysctl_jiffies);
2534 EXPORT_SYMBOL(sysctl_ms_jiffies);
2535 EXPORT_SYMBOL(sysctl_string);
2536 EXPORT_SYMBOL(unregister_sysctl_table);