2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/config.h>
22 #include <linux/module.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/capability.h>
29 #include <linux/ctype.h>
30 #include <linux/utsname.h>
31 #include <linux/capability.h>
32 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/security.h>
42 #include <linux/initrd.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
53 #if defined(CONFIG_SYSCTL)
55 /* External variables not in a header file. */
57 extern int sysctl_overcommit_memory;
58 extern int sysctl_overcommit_ratio;
59 extern int max_threads;
60 extern int sysrq_enabled;
61 extern int core_uses_pid;
62 extern int suid_dumpable;
63 extern char core_pattern[];
66 extern int min_free_kbytes;
67 extern int printk_ratelimit_jiffies;
68 extern int printk_ratelimit_burst;
69 extern int pid_max_min, pid_max_max;
70 extern int sysctl_drop_caches;
71 extern int percpu_pagelist_fraction;
73 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
74 int unknown_nmi_panic;
75 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
76 void __user *, size_t *, loff_t *);
79 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
80 static int maxolduid = 65535;
82 static int min_percpu_pagelist_fract = 8;
84 static int ngroups_max = NGROUPS_MAX;
87 extern char modprobe_path[];
89 #ifdef CONFIG_CHR_DEV_SG
90 extern int sg_big_buff;
93 extern size_t shm_ctlmax;
94 extern size_t shm_ctlall;
95 extern int shm_ctlmni;
96 extern int msg_ctlmax;
97 extern int msg_ctlmnb;
98 extern int msg_ctlmni;
99 extern int sem_ctls[];
103 extern char reboot_command [];
104 extern int stop_a_enabled;
105 extern int scons_pwroff;
109 extern int pwrsw_enabled;
110 extern int unaligned_enabled;
114 #ifdef CONFIG_MATHEMU
115 extern int sysctl_ieee_emulation_warnings;
117 extern int sysctl_userprocess_debug;
118 extern int spin_retry;
121 extern int sysctl_hz_timer;
123 #ifdef CONFIG_BSD_PROCESS_ACCT
124 extern int acct_parm[];
127 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
128 ctl_table *, void **);
129 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
130 void __user *buffer, size_t *lenp, loff_t *ppos);
132 static ctl_table root_table[];
133 static struct ctl_table_header root_table_header =
134 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
136 static ctl_table kern_table[];
137 static ctl_table vm_table[];
138 static ctl_table proc_table[];
139 static ctl_table fs_table[];
140 static ctl_table debug_table[];
141 static ctl_table dev_table[];
142 extern ctl_table random_table[];
143 #ifdef CONFIG_UNIX98_PTYS
144 extern ctl_table pty_table[];
146 #ifdef CONFIG_INOTIFY
147 extern ctl_table inotify_table[];
150 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
151 int sysctl_legacy_va_layout;
154 /* /proc declarations: */
156 #ifdef CONFIG_PROC_FS
158 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
159 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
160 static int proc_opensys(struct inode *, struct file *);
162 struct file_operations proc_sys_file_operations = {
163 .open = proc_opensys,
164 .read = proc_readsys,
165 .write = proc_writesys,
168 extern struct proc_dir_entry *proc_sys_root;
170 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
171 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
174 /* The default sysctl tables: */
176 static ctl_table root_table[] = {
178 .ctl_name = CTL_KERN,
179 .procname = "kernel",
198 .ctl_name = CTL_PROC,
210 .ctl_name = CTL_DEBUG,
213 .child = debug_table,
225 static ctl_table kern_table[] = {
227 .ctl_name = KERN_OSTYPE,
228 .procname = "ostype",
229 .data = system_utsname.sysname,
230 .maxlen = sizeof(system_utsname.sysname),
232 .proc_handler = &proc_doutsstring,
233 .strategy = &sysctl_string,
236 .ctl_name = KERN_OSRELEASE,
237 .procname = "osrelease",
238 .data = system_utsname.release,
239 .maxlen = sizeof(system_utsname.release),
241 .proc_handler = &proc_doutsstring,
242 .strategy = &sysctl_string,
245 .ctl_name = KERN_VERSION,
246 .procname = "version",
247 .data = system_utsname.version,
248 .maxlen = sizeof(system_utsname.version),
250 .proc_handler = &proc_doutsstring,
251 .strategy = &sysctl_string,
254 .ctl_name = KERN_NODENAME,
255 .procname = "hostname",
256 .data = system_utsname.nodename,
257 .maxlen = sizeof(system_utsname.nodename),
259 .proc_handler = &proc_doutsstring,
260 .strategy = &sysctl_string,
263 .ctl_name = KERN_DOMAINNAME,
264 .procname = "domainname",
265 .data = system_utsname.domainname,
266 .maxlen = sizeof(system_utsname.domainname),
268 .proc_handler = &proc_doutsstring,
269 .strategy = &sysctl_string,
272 .ctl_name = KERN_PANIC,
274 .data = &panic_timeout,
275 .maxlen = sizeof(int),
277 .proc_handler = &proc_dointvec,
280 .ctl_name = KERN_CORE_USES_PID,
281 .procname = "core_uses_pid",
282 .data = &core_uses_pid,
283 .maxlen = sizeof(int),
285 .proc_handler = &proc_dointvec,
288 .ctl_name = KERN_CORE_PATTERN,
289 .procname = "core_pattern",
290 .data = core_pattern,
293 .proc_handler = &proc_dostring,
294 .strategy = &sysctl_string,
297 .ctl_name = KERN_TAINTED,
298 .procname = "tainted",
300 .maxlen = sizeof(int),
302 .proc_handler = &proc_dointvec,
305 .ctl_name = KERN_CAP_BSET,
306 .procname = "cap-bound",
308 .maxlen = sizeof(kernel_cap_t),
310 .proc_handler = &proc_dointvec_bset,
312 #ifdef CONFIG_BLK_DEV_INITRD
314 .ctl_name = KERN_REALROOTDEV,
315 .procname = "real-root-dev",
316 .data = &real_root_dev,
317 .maxlen = sizeof(int),
319 .proc_handler = &proc_dointvec,
324 .ctl_name = KERN_SPARC_REBOOT,
325 .procname = "reboot-cmd",
326 .data = reboot_command,
329 .proc_handler = &proc_dostring,
330 .strategy = &sysctl_string,
333 .ctl_name = KERN_SPARC_STOP_A,
334 .procname = "stop-a",
335 .data = &stop_a_enabled,
336 .maxlen = sizeof (int),
338 .proc_handler = &proc_dointvec,
341 .ctl_name = KERN_SPARC_SCONS_PWROFF,
342 .procname = "scons-poweroff",
343 .data = &scons_pwroff,
344 .maxlen = sizeof (int),
346 .proc_handler = &proc_dointvec,
351 .ctl_name = KERN_HPPA_PWRSW,
352 .procname = "soft-power",
353 .data = &pwrsw_enabled,
354 .maxlen = sizeof (int),
356 .proc_handler = &proc_dointvec,
359 .ctl_name = KERN_HPPA_UNALIGNED,
360 .procname = "unaligned-trap",
361 .data = &unaligned_enabled,
362 .maxlen = sizeof (int),
364 .proc_handler = &proc_dointvec,
368 .ctl_name = KERN_CTLALTDEL,
369 .procname = "ctrl-alt-del",
371 .maxlen = sizeof(int),
373 .proc_handler = &proc_dointvec,
376 .ctl_name = KERN_PRINTK,
377 .procname = "printk",
378 .data = &console_loglevel,
379 .maxlen = 4*sizeof(int),
381 .proc_handler = &proc_dointvec,
385 .ctl_name = KERN_MODPROBE,
386 .procname = "modprobe",
387 .data = &modprobe_path,
388 .maxlen = KMOD_PATH_LEN,
390 .proc_handler = &proc_dostring,
391 .strategy = &sysctl_string,
394 #ifdef CONFIG_HOTPLUG
396 .ctl_name = KERN_HOTPLUG,
397 .procname = "hotplug",
398 .data = &uevent_helper,
399 .maxlen = UEVENT_HELPER_PATH_LEN,
401 .proc_handler = &proc_dostring,
402 .strategy = &sysctl_string,
405 #ifdef CONFIG_CHR_DEV_SG
407 .ctl_name = KERN_SG_BIG_BUFF,
408 .procname = "sg-big-buff",
409 .data = &sg_big_buff,
410 .maxlen = sizeof (int),
412 .proc_handler = &proc_dointvec,
415 #ifdef CONFIG_BSD_PROCESS_ACCT
417 .ctl_name = KERN_ACCT,
420 .maxlen = 3*sizeof(int),
422 .proc_handler = &proc_dointvec,
425 #ifdef CONFIG_SYSVIPC
427 .ctl_name = KERN_SHMMAX,
428 .procname = "shmmax",
430 .maxlen = sizeof (size_t),
432 .proc_handler = &proc_doulongvec_minmax,
435 .ctl_name = KERN_SHMALL,
436 .procname = "shmall",
438 .maxlen = sizeof (size_t),
440 .proc_handler = &proc_doulongvec_minmax,
443 .ctl_name = KERN_SHMMNI,
444 .procname = "shmmni",
446 .maxlen = sizeof (int),
448 .proc_handler = &proc_dointvec,
451 .ctl_name = KERN_MSGMAX,
452 .procname = "msgmax",
454 .maxlen = sizeof (int),
456 .proc_handler = &proc_dointvec,
459 .ctl_name = KERN_MSGMNI,
460 .procname = "msgmni",
462 .maxlen = sizeof (int),
464 .proc_handler = &proc_dointvec,
467 .ctl_name = KERN_MSGMNB,
468 .procname = "msgmnb",
470 .maxlen = sizeof (int),
472 .proc_handler = &proc_dointvec,
475 .ctl_name = KERN_SEM,
478 .maxlen = 4*sizeof (int),
480 .proc_handler = &proc_dointvec,
483 #ifdef CONFIG_MAGIC_SYSRQ
485 .ctl_name = KERN_SYSRQ,
487 .data = &sysrq_enabled,
488 .maxlen = sizeof (int),
490 .proc_handler = &proc_dointvec,
494 .ctl_name = KERN_CADPID,
495 .procname = "cad_pid",
497 .maxlen = sizeof (int),
499 .proc_handler = &proc_dointvec,
502 .ctl_name = KERN_MAX_THREADS,
503 .procname = "threads-max",
504 .data = &max_threads,
505 .maxlen = sizeof(int),
507 .proc_handler = &proc_dointvec,
510 .ctl_name = KERN_RANDOM,
511 .procname = "random",
513 .child = random_table,
515 #ifdef CONFIG_UNIX98_PTYS
517 .ctl_name = KERN_PTY,
524 .ctl_name = KERN_OVERFLOWUID,
525 .procname = "overflowuid",
526 .data = &overflowuid,
527 .maxlen = sizeof(int),
529 .proc_handler = &proc_dointvec_minmax,
530 .strategy = &sysctl_intvec,
531 .extra1 = &minolduid,
532 .extra2 = &maxolduid,
535 .ctl_name = KERN_OVERFLOWGID,
536 .procname = "overflowgid",
537 .data = &overflowgid,
538 .maxlen = sizeof(int),
540 .proc_handler = &proc_dointvec_minmax,
541 .strategy = &sysctl_intvec,
542 .extra1 = &minolduid,
543 .extra2 = &maxolduid,
546 #ifdef CONFIG_MATHEMU
548 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
549 .procname = "ieee_emulation_warnings",
550 .data = &sysctl_ieee_emulation_warnings,
551 .maxlen = sizeof(int),
553 .proc_handler = &proc_dointvec,
556 #ifdef CONFIG_NO_IDLE_HZ
558 .ctl_name = KERN_HZ_TIMER,
559 .procname = "hz_timer",
560 .data = &sysctl_hz_timer,
561 .maxlen = sizeof(int),
563 .proc_handler = &proc_dointvec,
567 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
568 .procname = "userprocess_debug",
569 .data = &sysctl_userprocess_debug,
570 .maxlen = sizeof(int),
572 .proc_handler = &proc_dointvec,
576 .ctl_name = KERN_PIDMAX,
577 .procname = "pid_max",
579 .maxlen = sizeof (int),
581 .proc_handler = &proc_dointvec_minmax,
582 .strategy = sysctl_intvec,
583 .extra1 = &pid_max_min,
584 .extra2 = &pid_max_max,
587 .ctl_name = KERN_PANIC_ON_OOPS,
588 .procname = "panic_on_oops",
589 .data = &panic_on_oops,
590 .maxlen = sizeof(int),
592 .proc_handler = &proc_dointvec,
595 .ctl_name = KERN_PRINTK_RATELIMIT,
596 .procname = "printk_ratelimit",
597 .data = &printk_ratelimit_jiffies,
598 .maxlen = sizeof(int),
600 .proc_handler = &proc_dointvec_jiffies,
601 .strategy = &sysctl_jiffies,
604 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
605 .procname = "printk_ratelimit_burst",
606 .data = &printk_ratelimit_burst,
607 .maxlen = sizeof(int),
609 .proc_handler = &proc_dointvec,
612 .ctl_name = KERN_NGROUPS_MAX,
613 .procname = "ngroups_max",
614 .data = &ngroups_max,
615 .maxlen = sizeof (int),
617 .proc_handler = &proc_dointvec,
619 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
621 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
622 .procname = "unknown_nmi_panic",
623 .data = &unknown_nmi_panic,
624 .maxlen = sizeof (int),
626 .proc_handler = &proc_unknown_nmi_panic,
629 #if defined(CONFIG_X86)
631 .ctl_name = KERN_BOOTLOADER_TYPE,
632 .procname = "bootloader_type",
633 .data = &bootloader_type,
634 .maxlen = sizeof (int),
636 .proc_handler = &proc_dointvec,
639 #if defined(CONFIG_MMU)
641 .ctl_name = KERN_RANDOMIZE,
642 .procname = "randomize_va_space",
643 .data = &randomize_va_space,
644 .maxlen = sizeof(int),
646 .proc_handler = &proc_dointvec,
649 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
651 .ctl_name = KERN_SPIN_RETRY,
652 .procname = "spin_retry",
654 .maxlen = sizeof (int),
656 .proc_handler = &proc_dointvec,
659 #ifdef CONFIG_ACPI_SLEEP
661 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
662 .procname = "acpi_video_flags",
663 .data = &acpi_video_flags,
664 .maxlen = sizeof (unsigned long),
666 .proc_handler = &proc_dointvec,
672 /* Constants for minimum and maximum testing in vm_table.
673 We use these as one-element integer vectors. */
675 static int one_hundred = 100;
678 static ctl_table vm_table[] = {
680 .ctl_name = VM_OVERCOMMIT_MEMORY,
681 .procname = "overcommit_memory",
682 .data = &sysctl_overcommit_memory,
683 .maxlen = sizeof(sysctl_overcommit_memory),
685 .proc_handler = &proc_dointvec,
688 .ctl_name = VM_OVERCOMMIT_RATIO,
689 .procname = "overcommit_ratio",
690 .data = &sysctl_overcommit_ratio,
691 .maxlen = sizeof(sysctl_overcommit_ratio),
693 .proc_handler = &proc_dointvec,
696 .ctl_name = VM_PAGE_CLUSTER,
697 .procname = "page-cluster",
698 .data = &page_cluster,
699 .maxlen = sizeof(int),
701 .proc_handler = &proc_dointvec,
704 .ctl_name = VM_DIRTY_BACKGROUND,
705 .procname = "dirty_background_ratio",
706 .data = &dirty_background_ratio,
707 .maxlen = sizeof(dirty_background_ratio),
709 .proc_handler = &proc_dointvec_minmax,
710 .strategy = &sysctl_intvec,
712 .extra2 = &one_hundred,
715 .ctl_name = VM_DIRTY_RATIO,
716 .procname = "dirty_ratio",
717 .data = &vm_dirty_ratio,
718 .maxlen = sizeof(vm_dirty_ratio),
720 .proc_handler = &proc_dointvec_minmax,
721 .strategy = &sysctl_intvec,
723 .extra2 = &one_hundred,
726 .ctl_name = VM_DIRTY_WB_CS,
727 .procname = "dirty_writeback_centisecs",
728 .data = &dirty_writeback_centisecs,
729 .maxlen = sizeof(dirty_writeback_centisecs),
731 .proc_handler = &dirty_writeback_centisecs_handler,
734 .ctl_name = VM_DIRTY_EXPIRE_CS,
735 .procname = "dirty_expire_centisecs",
736 .data = &dirty_expire_centisecs,
737 .maxlen = sizeof(dirty_expire_centisecs),
739 .proc_handler = &proc_dointvec,
742 .ctl_name = VM_NR_PDFLUSH_THREADS,
743 .procname = "nr_pdflush_threads",
744 .data = &nr_pdflush_threads,
745 .maxlen = sizeof nr_pdflush_threads,
746 .mode = 0444 /* read-only*/,
747 .proc_handler = &proc_dointvec,
750 .ctl_name = VM_SWAPPINESS,
751 .procname = "swappiness",
752 .data = &vm_swappiness,
753 .maxlen = sizeof(vm_swappiness),
755 .proc_handler = &proc_dointvec_minmax,
756 .strategy = &sysctl_intvec,
758 .extra2 = &one_hundred,
760 #ifdef CONFIG_HUGETLB_PAGE
762 .ctl_name = VM_HUGETLB_PAGES,
763 .procname = "nr_hugepages",
764 .data = &max_huge_pages,
765 .maxlen = sizeof(unsigned long),
767 .proc_handler = &hugetlb_sysctl_handler,
768 .extra1 = (void *)&hugetlb_zero,
769 .extra2 = (void *)&hugetlb_infinity,
772 .ctl_name = VM_HUGETLB_GROUP,
773 .procname = "hugetlb_shm_group",
774 .data = &sysctl_hugetlb_shm_group,
775 .maxlen = sizeof(gid_t),
777 .proc_handler = &proc_dointvec,
781 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
782 .procname = "lowmem_reserve_ratio",
783 .data = &sysctl_lowmem_reserve_ratio,
784 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
786 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
787 .strategy = &sysctl_intvec,
790 .ctl_name = VM_DROP_PAGECACHE,
791 .procname = "drop_caches",
792 .data = &sysctl_drop_caches,
793 .maxlen = sizeof(int),
795 .proc_handler = drop_caches_sysctl_handler,
796 .strategy = &sysctl_intvec,
799 .ctl_name = VM_MIN_FREE_KBYTES,
800 .procname = "min_free_kbytes",
801 .data = &min_free_kbytes,
802 .maxlen = sizeof(min_free_kbytes),
804 .proc_handler = &min_free_kbytes_sysctl_handler,
805 .strategy = &sysctl_intvec,
809 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
810 .procname = "percpu_pagelist_fraction",
811 .data = &percpu_pagelist_fraction,
812 .maxlen = sizeof(percpu_pagelist_fraction),
814 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
815 .strategy = &sysctl_intvec,
816 .extra1 = &min_percpu_pagelist_fract,
820 .ctl_name = VM_MAX_MAP_COUNT,
821 .procname = "max_map_count",
822 .data = &sysctl_max_map_count,
823 .maxlen = sizeof(sysctl_max_map_count),
825 .proc_handler = &proc_dointvec
829 .ctl_name = VM_LAPTOP_MODE,
830 .procname = "laptop_mode",
831 .data = &laptop_mode,
832 .maxlen = sizeof(laptop_mode),
834 .proc_handler = &proc_dointvec,
835 .strategy = &sysctl_intvec,
839 .ctl_name = VM_BLOCK_DUMP,
840 .procname = "block_dump",
842 .maxlen = sizeof(block_dump),
844 .proc_handler = &proc_dointvec,
845 .strategy = &sysctl_intvec,
849 .ctl_name = VM_VFS_CACHE_PRESSURE,
850 .procname = "vfs_cache_pressure",
851 .data = &sysctl_vfs_cache_pressure,
852 .maxlen = sizeof(sysctl_vfs_cache_pressure),
854 .proc_handler = &proc_dointvec,
855 .strategy = &sysctl_intvec,
858 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
860 .ctl_name = VM_LEGACY_VA_LAYOUT,
861 .procname = "legacy_va_layout",
862 .data = &sysctl_legacy_va_layout,
863 .maxlen = sizeof(sysctl_legacy_va_layout),
865 .proc_handler = &proc_dointvec,
866 .strategy = &sysctl_intvec,
872 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
873 .procname = "swap_token_timeout",
874 .data = &swap_token_default_timeout,
875 .maxlen = sizeof(swap_token_default_timeout),
877 .proc_handler = &proc_dointvec_jiffies,
878 .strategy = &sysctl_jiffies,
883 .ctl_name = VM_ZONE_RECLAIM_MODE,
884 .procname = "zone_reclaim_mode",
885 .data = &zone_reclaim_mode,
886 .maxlen = sizeof(zone_reclaim_mode),
888 .proc_handler = &proc_dointvec,
889 .strategy = &sysctl_intvec,
893 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
894 .procname = "zone_reclaim_interval",
895 .data = &zone_reclaim_interval,
896 .maxlen = sizeof(zone_reclaim_interval),
898 .proc_handler = &proc_dointvec_jiffies,
899 .strategy = &sysctl_jiffies,
905 static ctl_table proc_table[] = {
909 static ctl_table fs_table[] = {
911 .ctl_name = FS_NRINODE,
912 .procname = "inode-nr",
913 .data = &inodes_stat,
914 .maxlen = 2*sizeof(int),
916 .proc_handler = &proc_dointvec,
919 .ctl_name = FS_STATINODE,
920 .procname = "inode-state",
921 .data = &inodes_stat,
922 .maxlen = 7*sizeof(int),
924 .proc_handler = &proc_dointvec,
927 .ctl_name = FS_NRFILE,
928 .procname = "file-nr",
930 .maxlen = 3*sizeof(int),
932 .proc_handler = &proc_dointvec,
935 .ctl_name = FS_MAXFILE,
936 .procname = "file-max",
937 .data = &files_stat.max_files,
938 .maxlen = sizeof(int),
940 .proc_handler = &proc_dointvec,
943 .ctl_name = FS_DENTRY,
944 .procname = "dentry-state",
945 .data = &dentry_stat,
946 .maxlen = 6*sizeof(int),
948 .proc_handler = &proc_dointvec,
951 .ctl_name = FS_OVERFLOWUID,
952 .procname = "overflowuid",
953 .data = &fs_overflowuid,
954 .maxlen = sizeof(int),
956 .proc_handler = &proc_dointvec_minmax,
957 .strategy = &sysctl_intvec,
958 .extra1 = &minolduid,
959 .extra2 = &maxolduid,
962 .ctl_name = FS_OVERFLOWGID,
963 .procname = "overflowgid",
964 .data = &fs_overflowgid,
965 .maxlen = sizeof(int),
967 .proc_handler = &proc_dointvec_minmax,
968 .strategy = &sysctl_intvec,
969 .extra1 = &minolduid,
970 .extra2 = &maxolduid,
973 .ctl_name = FS_LEASES,
974 .procname = "leases-enable",
975 .data = &leases_enable,
976 .maxlen = sizeof(int),
978 .proc_handler = &proc_dointvec,
980 #ifdef CONFIG_DNOTIFY
982 .ctl_name = FS_DIR_NOTIFY,
983 .procname = "dir-notify-enable",
984 .data = &dir_notify_enable,
985 .maxlen = sizeof(int),
987 .proc_handler = &proc_dointvec,
992 .ctl_name = FS_LEASE_TIME,
993 .procname = "lease-break-time",
994 .data = &lease_break_time,
995 .maxlen = sizeof(int),
997 .proc_handler = &proc_dointvec,
1000 .ctl_name = FS_AIO_NR,
1001 .procname = "aio-nr",
1003 .maxlen = sizeof(aio_nr),
1005 .proc_handler = &proc_doulongvec_minmax,
1008 .ctl_name = FS_AIO_MAX_NR,
1009 .procname = "aio-max-nr",
1010 .data = &aio_max_nr,
1011 .maxlen = sizeof(aio_max_nr),
1013 .proc_handler = &proc_doulongvec_minmax,
1015 #ifdef CONFIG_INOTIFY
1017 .ctl_name = FS_INOTIFY,
1018 .procname = "inotify",
1020 .child = inotify_table,
1025 .ctl_name = KERN_SETUID_DUMPABLE,
1026 .procname = "suid_dumpable",
1027 .data = &suid_dumpable,
1028 .maxlen = sizeof(int),
1030 .proc_handler = &proc_dointvec,
1035 static ctl_table debug_table[] = {
1039 static ctl_table dev_table[] = {
1043 extern void init_irq_proc (void);
1045 static DEFINE_SPINLOCK(sysctl_lock);
1047 /* called under sysctl_lock */
1048 static int use_table(struct ctl_table_header *p)
1050 if (unlikely(p->unregistering))
1056 /* called under sysctl_lock */
1057 static void unuse_table(struct ctl_table_header *p)
1060 if (unlikely(p->unregistering))
1061 complete(p->unregistering);
1064 /* called under sysctl_lock, will reacquire if has to wait */
1065 static void start_unregistering(struct ctl_table_header *p)
1068 * if p->used is 0, nobody will ever touch that entry again;
1069 * we'll eliminate all paths to it before dropping sysctl_lock
1071 if (unlikely(p->used)) {
1072 struct completion wait;
1073 init_completion(&wait);
1074 p->unregistering = &wait;
1075 spin_unlock(&sysctl_lock);
1076 wait_for_completion(&wait);
1077 spin_lock(&sysctl_lock);
1080 * do not remove from the list until nobody holds it; walking the
1081 * list in do_sysctl() relies on that.
1083 list_del_init(&p->ctl_entry);
1086 void __init sysctl_init(void)
1088 #ifdef CONFIG_PROC_FS
1089 register_proc_table(root_table, proc_sys_root, &root_table_header);
1094 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1095 void __user *newval, size_t newlen)
1097 struct list_head *tmp;
1098 int error = -ENOTDIR;
1100 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1104 if (!oldlenp || get_user(old_len, oldlenp))
1107 spin_lock(&sysctl_lock);
1108 tmp = &root_table_header.ctl_entry;
1110 struct ctl_table_header *head =
1111 list_entry(tmp, struct ctl_table_header, ctl_entry);
1112 void *context = NULL;
1114 if (!use_table(head))
1117 spin_unlock(&sysctl_lock);
1119 error = parse_table(name, nlen, oldval, oldlenp,
1120 newval, newlen, head->ctl_table,
1124 spin_lock(&sysctl_lock);
1126 if (error != -ENOTDIR)
1128 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1129 spin_unlock(&sysctl_lock);
1133 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1135 struct __sysctl_args tmp;
1138 if (copy_from_user(&tmp, args, sizeof(tmp)))
1142 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1143 tmp.newval, tmp.newlen);
1149 * ctl_perm does NOT grant the superuser all rights automatically, because
1150 * some sysctl variables are readonly even to root.
1153 static int test_perm(int mode, int op)
1157 else if (in_egroup_p(0))
1159 if ((mode & op & 0007) == op)
1164 static inline int ctl_perm(ctl_table *table, int op)
1167 error = security_sysctl(table, op);
1170 return test_perm(table->mode, op);
1173 static int parse_table(int __user *name, int nlen,
1174 void __user *oldval, size_t __user *oldlenp,
1175 void __user *newval, size_t newlen,
1176 ctl_table *table, void **context)
1182 if (get_user(n, name))
1184 for ( ; table->ctl_name; table++) {
1185 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1188 if (ctl_perm(table, 001))
1190 if (table->strategy) {
1191 error = table->strategy(
1194 newval, newlen, context);
1200 table = table->child;
1203 error = do_sysctl_strategy(table, name, nlen,
1205 newval, newlen, context);
1212 /* Perform the actual read/write of a sysctl table entry. */
1213 int do_sysctl_strategy (ctl_table *table,
1214 int __user *name, int nlen,
1215 void __user *oldval, size_t __user *oldlenp,
1216 void __user *newval, size_t newlen, void **context)
1225 if (ctl_perm(table, op))
1228 if (table->strategy) {
1229 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1230 newval, newlen, context);
1237 /* If there is no strategy routine, or if the strategy returns
1238 * zero, proceed with automatic r/w */
1239 if (table->data && table->maxlen) {
1240 if (oldval && oldlenp) {
1241 if (get_user(len, oldlenp))
1244 if (len > table->maxlen)
1245 len = table->maxlen;
1246 if(copy_to_user(oldval, table->data, len))
1248 if(put_user(len, oldlenp))
1252 if (newval && newlen) {
1254 if (len > table->maxlen)
1255 len = table->maxlen;
1256 if(copy_from_user(table->data, newval, len))
1264 * register_sysctl_table - register a sysctl hierarchy
1265 * @table: the top-level table structure
1266 * @insert_at_head: whether the entry should be inserted in front or at the end
1268 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1269 * array. An entry with a ctl_name of 0 terminates the table.
1271 * The members of the &ctl_table structure are used as follows:
1273 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1274 * must be unique within that level of sysctl
1276 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1277 * enter a sysctl file
1279 * data - a pointer to data for use by proc_handler
1281 * maxlen - the maximum size in bytes of the data
1283 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1285 * child - a pointer to the child sysctl table if this entry is a directory, or
1288 * proc_handler - the text handler routine (described below)
1290 * strategy - the strategy routine (described below)
1292 * de - for internal use by the sysctl routines
1294 * extra1, extra2 - extra pointers usable by the proc handler routines
1296 * Leaf nodes in the sysctl tree will be represented by a single file
1297 * under /proc; non-leaf nodes will be represented by directories.
1299 * sysctl(2) can automatically manage read and write requests through
1300 * the sysctl table. The data and maxlen fields of the ctl_table
1301 * struct enable minimal validation of the values being written to be
1302 * performed, and the mode field allows minimal authentication.
1304 * More sophisticated management can be enabled by the provision of a
1305 * strategy routine with the table entry. This will be called before
1306 * any automatic read or write of the data is performed.
1308 * The strategy routine may return
1310 * < 0 - Error occurred (error is passed to user process)
1312 * 0 - OK - proceed with automatic read or write.
1314 * > 0 - OK - read or write has been done by the strategy routine, so
1315 * return immediately.
1317 * There must be a proc_handler routine for any terminal nodes
1318 * mirrored under /proc/sys (non-terminals are handled by a built-in
1319 * directory handler). Several default handlers are available to
1320 * cover common cases -
1322 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1323 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1324 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1326 * It is the handler's job to read the input buffer from user memory
1327 * and process it. The handler should return 0 on success.
1329 * This routine returns %NULL on a failure to register, and a pointer
1330 * to the table header on success.
1332 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1335 struct ctl_table_header *tmp;
1336 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1339 tmp->ctl_table = table;
1340 INIT_LIST_HEAD(&tmp->ctl_entry);
1342 tmp->unregistering = NULL;
1343 spin_lock(&sysctl_lock);
1345 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1347 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1348 spin_unlock(&sysctl_lock);
1349 #ifdef CONFIG_PROC_FS
1350 register_proc_table(table, proc_sys_root, tmp);
1356 * unregister_sysctl_table - unregister a sysctl table hierarchy
1357 * @header: the header returned from register_sysctl_table
1359 * Unregisters the sysctl table and all children. proc entries may not
1360 * actually be removed until they are no longer used by anyone.
1362 void unregister_sysctl_table(struct ctl_table_header * header)
1365 spin_lock(&sysctl_lock);
1366 start_unregistering(header);
1367 #ifdef CONFIG_PROC_FS
1368 unregister_proc_table(header->ctl_table, proc_sys_root);
1370 spin_unlock(&sysctl_lock);
1378 #ifdef CONFIG_PROC_FS
1380 /* Scan the sysctl entries in table and add them all into /proc */
1381 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1383 struct proc_dir_entry *de;
1387 for (; table->ctl_name; table++) {
1388 /* Can't do anything without a proc name. */
1389 if (!table->procname)
1391 /* Maybe we can't do anything with it... */
1392 if (!table->proc_handler && !table->child) {
1393 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1398 len = strlen(table->procname);
1402 if (table->proc_handler)
1406 for (de = root->subdir; de; de = de->next) {
1407 if (proc_match(len, table->procname, de))
1410 /* If the subdir exists already, de is non-NULL */
1414 de = create_proc_entry(table->procname, mode, root);
1418 de->data = (void *) table;
1419 if (table->proc_handler)
1420 de->proc_fops = &proc_sys_file_operations;
1423 if (de->mode & S_IFDIR)
1424 register_proc_table(table->child, de, set);
1429 * Unregister a /proc sysctl table and any subdirectories.
1431 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1433 struct proc_dir_entry *de;
1434 for (; table->ctl_name; table++) {
1435 if (!(de = table->de))
1437 if (de->mode & S_IFDIR) {
1438 if (!table->child) {
1439 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1442 unregister_proc_table(table->child, de);
1444 /* Don't unregister directories which still have entries.. */
1450 * In any case, mark the entry as goner; we'll keep it
1451 * around if it's busy, but we'll know to do nothing with
1452 * its fields. We are under sysctl_lock here.
1456 /* Don't unregister proc entries that are still being used.. */
1457 if (atomic_read(&de->count))
1461 remove_proc_entry(table->procname, root);
1465 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1466 size_t count, loff_t *ppos)
1469 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1470 struct ctl_table *table;
1472 ssize_t error = -ENOTDIR;
1474 spin_lock(&sysctl_lock);
1475 if (de && de->data && use_table(de->set)) {
1477 * at that point we know that sysctl was not unregistered
1478 * and won't be until we finish
1480 spin_unlock(&sysctl_lock);
1481 table = (struct ctl_table *) de->data;
1482 if (!table || !table->proc_handler)
1485 op = (write ? 002 : 004);
1486 if (ctl_perm(table, op))
1489 /* careful: calling conventions are nasty here */
1491 error = (*table->proc_handler)(table, write, file,
1496 spin_lock(&sysctl_lock);
1497 unuse_table(de->set);
1499 spin_unlock(&sysctl_lock);
1503 static int proc_opensys(struct inode *inode, struct file *file)
1505 if (file->f_mode & FMODE_WRITE) {
1507 * sysctl entries that are not writable,
1508 * are _NOT_ writable, capabilities or not.
1510 if (!(inode->i_mode & S_IWUSR))
1517 static ssize_t proc_readsys(struct file * file, char __user * buf,
1518 size_t count, loff_t *ppos)
1520 return do_rw_proc(0, file, buf, count, ppos);
1523 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1524 size_t count, loff_t *ppos)
1526 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1530 * proc_dostring - read a string sysctl
1531 * @table: the sysctl table
1532 * @write: %TRUE if this is a write to the sysctl file
1533 * @filp: the file structure
1534 * @buffer: the user buffer
1535 * @lenp: the size of the user buffer
1536 * @ppos: file position
1538 * Reads/writes a string from/to the user buffer. If the kernel
1539 * buffer provided is not large enough to hold the string, the
1540 * string is truncated. The copied string is %NULL-terminated.
1541 * If the string is being read by the user process, it is copied
1542 * and a newline '\n' is added. It is truncated if the buffer is
1545 * Returns 0 on success.
1547 int proc_dostring(ctl_table *table, int write, struct file *filp,
1548 void __user *buffer, size_t *lenp, loff_t *ppos)
1554 if (!table->data || !table->maxlen || !*lenp ||
1555 (*ppos && !write)) {
1563 while (len < *lenp) {
1564 if (get_user(c, p++))
1566 if (c == 0 || c == '\n')
1570 if (len >= table->maxlen)
1571 len = table->maxlen-1;
1572 if(copy_from_user(table->data, buffer, len))
1574 ((char *) table->data)[len] = 0;
1577 len = strlen(table->data);
1578 if (len > table->maxlen)
1579 len = table->maxlen;
1583 if(copy_to_user(buffer, table->data, len))
1586 if(put_user('\n', ((char __user *) buffer) + len))
1597 * Special case of dostring for the UTS structure. This has locks
1598 * to observe. Should this be in kernel/sys.c ????
1601 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1602 void __user *buffer, size_t *lenp, loff_t *ppos)
1607 down_read(&uts_sem);
1608 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1611 down_write(&uts_sem);
1612 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1618 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1620 int write, void *data)
1623 *valp = *negp ? -*lvalp : *lvalp;
1628 *lvalp = (unsigned long)-val;
1631 *lvalp = (unsigned long)val;
1637 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1638 void __user *buffer, size_t *lenp, loff_t *ppos,
1639 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1640 int write, void *data),
1643 #define TMPBUFLEN 21
1644 int *i, vleft, first=1, neg, val;
1648 char buf[TMPBUFLEN], *p;
1649 char __user *s = buffer;
1651 if (!table->data || !table->maxlen || !*lenp ||
1652 (*ppos && !write)) {
1657 i = (int *) table->data;
1658 vleft = table->maxlen / sizeof(*i);
1662 conv = do_proc_dointvec_conv;
1664 for (; left && vleft--; i++, first=0) {
1679 if (len > sizeof(buf) - 1)
1680 len = sizeof(buf) - 1;
1681 if (copy_from_user(buf, s, len))
1685 if (*p == '-' && left > 1) {
1689 if (*p < '0' || *p > '9')
1692 lval = simple_strtoul(p, &p, 0);
1695 if ((len < left) && *p && !isspace(*p))
1702 if (conv(&neg, &lval, i, 1, data))
1709 if (conv(&neg, &lval, i, 0, data))
1712 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1716 if(copy_to_user(s, buf, len))
1723 if (!write && !first && left) {
1724 if(put_user('\n', s))
1731 if (get_user(c, s++))
1747 * proc_dointvec - read a vector of integers
1748 * @table: the sysctl table
1749 * @write: %TRUE if this is a write to the sysctl file
1750 * @filp: the file structure
1751 * @buffer: the user buffer
1752 * @lenp: the size of the user buffer
1753 * @ppos: file position
1755 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1756 * values from/to the user buffer, treated as an ASCII string.
1758 * Returns 0 on success.
1760 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1761 void __user *buffer, size_t *lenp, loff_t *ppos)
1763 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1773 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1775 int write, void *data)
1777 int op = *(int *)data;
1779 int val = *negp ? -*lvalp : *lvalp;
1781 case OP_SET: *valp = val; break;
1782 case OP_AND: *valp &= val; break;
1783 case OP_OR: *valp |= val; break;
1784 case OP_MAX: if(*valp < val)
1787 case OP_MIN: if(*valp > val)
1795 *lvalp = (unsigned long)-val;
1798 *lvalp = (unsigned long)val;
1805 * init may raise the set.
1808 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1809 void __user *buffer, size_t *lenp, loff_t *ppos)
1813 if (!capable(CAP_SYS_MODULE)) {
1817 op = (current->pid == 1) ? OP_SET : OP_AND;
1818 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1819 do_proc_dointvec_bset_conv,&op);
1822 struct do_proc_dointvec_minmax_conv_param {
1827 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1829 int write, void *data)
1831 struct do_proc_dointvec_minmax_conv_param *param = data;
1833 int val = *negp ? -*lvalp : *lvalp;
1834 if ((param->min && *param->min > val) ||
1835 (param->max && *param->max < val))
1842 *lvalp = (unsigned long)-val;
1845 *lvalp = (unsigned long)val;
1852 * proc_dointvec_minmax - read a vector of integers with min/max values
1853 * @table: the sysctl table
1854 * @write: %TRUE if this is a write to the sysctl file
1855 * @filp: the file structure
1856 * @buffer: the user buffer
1857 * @lenp: the size of the user buffer
1858 * @ppos: file position
1860 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1861 * values from/to the user buffer, treated as an ASCII string.
1863 * This routine will ensure the values are within the range specified by
1864 * table->extra1 (min) and table->extra2 (max).
1866 * Returns 0 on success.
1868 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1869 void __user *buffer, size_t *lenp, loff_t *ppos)
1871 struct do_proc_dointvec_minmax_conv_param param = {
1872 .min = (int *) table->extra1,
1873 .max = (int *) table->extra2,
1875 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1876 do_proc_dointvec_minmax_conv, ¶m);
1879 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1881 void __user *buffer,
1882 size_t *lenp, loff_t *ppos,
1883 unsigned long convmul,
1884 unsigned long convdiv)
1886 #define TMPBUFLEN 21
1887 unsigned long *i, *min, *max, val;
1888 int vleft, first=1, neg;
1890 char buf[TMPBUFLEN], *p;
1891 char __user *s = buffer;
1893 if (!table->data || !table->maxlen || !*lenp ||
1894 (*ppos && !write)) {
1899 i = (unsigned long *) table->data;
1900 min = (unsigned long *) table->extra1;
1901 max = (unsigned long *) table->extra2;
1902 vleft = table->maxlen / sizeof(unsigned long);
1905 for (; left && vleft--; i++, min++, max++, first=0) {
1920 if (len > TMPBUFLEN-1)
1922 if (copy_from_user(buf, s, len))
1926 if (*p == '-' && left > 1) {
1930 if (*p < '0' || *p > '9')
1932 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1934 if ((len < left) && *p && !isspace(*p))
1943 if ((min && val < *min) || (max && val > *max))
1950 sprintf(p, "%lu", convdiv * (*i) / convmul);
1954 if(copy_to_user(s, buf, len))
1961 if (!write && !first && left) {
1962 if(put_user('\n', s))
1969 if (get_user(c, s++))
1985 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1986 * @table: the sysctl table
1987 * @write: %TRUE if this is a write to the sysctl file
1988 * @filp: the file structure
1989 * @buffer: the user buffer
1990 * @lenp: the size of the user buffer
1991 * @ppos: file position
1993 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1994 * values from/to the user buffer, treated as an ASCII string.
1996 * This routine will ensure the values are within the range specified by
1997 * table->extra1 (min) and table->extra2 (max).
1999 * Returns 0 on success.
2001 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2002 void __user *buffer, size_t *lenp, loff_t *ppos)
2004 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2008 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2009 * @table: the sysctl table
2010 * @write: %TRUE if this is a write to the sysctl file
2011 * @filp: the file structure
2012 * @buffer: the user buffer
2013 * @lenp: the size of the user buffer
2014 * @ppos: file position
2016 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2017 * values from/to the user buffer, treated as an ASCII string. The values
2018 * are treated as milliseconds, and converted to jiffies when they are stored.
2020 * This routine will ensure the values are within the range specified by
2021 * table->extra1 (min) and table->extra2 (max).
2023 * Returns 0 on success.
2025 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2027 void __user *buffer,
2028 size_t *lenp, loff_t *ppos)
2030 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2031 lenp, ppos, HZ, 1000l);
2035 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2037 int write, void *data)
2040 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2046 lval = (unsigned long)-val;
2049 lval = (unsigned long)val;
2056 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2058 int write, void *data)
2061 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2067 lval = (unsigned long)-val;
2070 lval = (unsigned long)val;
2072 *lvalp = jiffies_to_clock_t(lval);
2077 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2079 int write, void *data)
2082 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2088 lval = (unsigned long)-val;
2091 lval = (unsigned long)val;
2093 *lvalp = jiffies_to_msecs(lval);
2099 * proc_dointvec_jiffies - read a vector of integers as seconds
2100 * @table: the sysctl table
2101 * @write: %TRUE if this is a write to the sysctl file
2102 * @filp: the file structure
2103 * @buffer: the user buffer
2104 * @lenp: the size of the user buffer
2105 * @ppos: file position
2107 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2108 * values from/to the user buffer, treated as an ASCII string.
2109 * The values read are assumed to be in seconds, and are converted into
2112 * Returns 0 on success.
2114 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2115 void __user *buffer, size_t *lenp, loff_t *ppos)
2117 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2118 do_proc_dointvec_jiffies_conv,NULL);
2122 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2123 * @table: the sysctl table
2124 * @write: %TRUE if this is a write to the sysctl file
2125 * @filp: the file structure
2126 * @buffer: the user buffer
2127 * @lenp: the size of the user buffer
2128 * @ppos: pointer to the file position
2130 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2131 * values from/to the user buffer, treated as an ASCII string.
2132 * The values read are assumed to be in 1/USER_HZ seconds, and
2133 * are converted into jiffies.
2135 * Returns 0 on success.
2137 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2138 void __user *buffer, size_t *lenp, loff_t *ppos)
2140 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2141 do_proc_dointvec_userhz_jiffies_conv,NULL);
2145 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2146 * @table: the sysctl table
2147 * @write: %TRUE if this is a write to the sysctl file
2148 * @filp: the file structure
2149 * @buffer: the user buffer
2150 * @lenp: the size of the user buffer
2151 * @ppos: file position
2152 * @ppos: the current position in the file
2154 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2155 * values from/to the user buffer, treated as an ASCII string.
2156 * The values read are assumed to be in 1/1000 seconds, and
2157 * are converted into jiffies.
2159 * Returns 0 on success.
2161 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2162 void __user *buffer, size_t *lenp, loff_t *ppos)
2164 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2165 do_proc_dointvec_ms_jiffies_conv, NULL);
2168 #else /* CONFIG_PROC_FS */
2170 int proc_dostring(ctl_table *table, int write, struct file *filp,
2171 void __user *buffer, size_t *lenp, loff_t *ppos)
2176 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2177 void __user *buffer, size_t *lenp, loff_t *ppos)
2182 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2183 void __user *buffer, size_t *lenp, loff_t *ppos)
2188 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2189 void __user *buffer, size_t *lenp, loff_t *ppos)
2194 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2195 void __user *buffer, size_t *lenp, loff_t *ppos)
2200 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2201 void __user *buffer, size_t *lenp, loff_t *ppos)
2206 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2207 void __user *buffer, size_t *lenp, loff_t *ppos)
2212 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2213 void __user *buffer, size_t *lenp, loff_t *ppos)
2218 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2219 void __user *buffer, size_t *lenp, loff_t *ppos)
2224 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2226 void __user *buffer,
2227 size_t *lenp, loff_t *ppos)
2233 #endif /* CONFIG_PROC_FS */
2237 * General sysctl support routines
2240 /* The generic string strategy routine: */
2241 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2242 void __user *oldval, size_t __user *oldlenp,
2243 void __user *newval, size_t newlen, void **context)
2245 if (!table->data || !table->maxlen)
2248 if (oldval && oldlenp) {
2250 if (get_user(bufsize, oldlenp))
2253 size_t len = strlen(table->data), copied;
2255 /* This shouldn't trigger for a well-formed sysctl */
2256 if (len > table->maxlen)
2257 len = table->maxlen;
2259 /* Copy up to a max of bufsize-1 bytes of the string */
2260 copied = (len >= bufsize) ? bufsize - 1 : len;
2262 if (copy_to_user(oldval, table->data, copied) ||
2263 put_user(0, (char __user *)(oldval + copied)))
2265 if (put_user(len, oldlenp))
2269 if (newval && newlen) {
2270 size_t len = newlen;
2271 if (len > table->maxlen)
2272 len = table->maxlen;
2273 if(copy_from_user(table->data, newval, len))
2275 if (len == table->maxlen)
2277 ((char *) table->data)[len] = 0;
2283 * This function makes sure that all of the integers in the vector
2284 * are between the minimum and maximum values given in the arrays
2285 * table->extra1 and table->extra2, respectively.
2287 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2288 void __user *oldval, size_t __user *oldlenp,
2289 void __user *newval, size_t newlen, void **context)
2292 if (newval && newlen) {
2293 int __user *vec = (int __user *) newval;
2294 int *min = (int *) table->extra1;
2295 int *max = (int *) table->extra2;
2299 if (newlen % sizeof(int) != 0)
2302 if (!table->extra1 && !table->extra2)
2305 if (newlen > table->maxlen)
2306 newlen = table->maxlen;
2307 length = newlen / sizeof(int);
2309 for (i = 0; i < length; i++) {
2311 if (get_user(value, vec + i))
2313 if (min && value < min[i])
2315 if (max && value > max[i])
2322 /* Strategy function to convert jiffies to seconds */
2323 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2324 void __user *oldval, size_t __user *oldlenp,
2325 void __user *newval, size_t newlen, void **context)
2330 if (get_user(olen, oldlenp))
2332 if (olen!=sizeof(int))
2335 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2336 (oldlenp && put_user(sizeof(int),oldlenp)))
2339 if (newval && newlen) {
2341 if (newlen != sizeof(int))
2343 if (get_user(new, (int __user *)newval))
2345 *(int *)(table->data) = new*HZ;
2350 /* Strategy function to convert jiffies to seconds */
2351 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2352 void __user *oldval, size_t __user *oldlenp,
2353 void __user *newval, size_t newlen, void **context)
2358 if (get_user(olen, oldlenp))
2360 if (olen!=sizeof(int))
2363 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2364 (oldlenp && put_user(sizeof(int),oldlenp)))
2367 if (newval && newlen) {
2369 if (newlen != sizeof(int))
2371 if (get_user(new, (int __user *)newval))
2373 *(int *)(table->data) = msecs_to_jiffies(new);
2378 #else /* CONFIG_SYSCTL */
2381 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2386 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2387 void __user *oldval, size_t __user *oldlenp,
2388 void __user *newval, size_t newlen, void **context)
2393 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2394 void __user *oldval, size_t __user *oldlenp,
2395 void __user *newval, size_t newlen, void **context)
2400 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2401 void __user *oldval, size_t __user *oldlenp,
2402 void __user *newval, size_t newlen, void **context)
2407 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2408 void __user *oldval, size_t __user *oldlenp,
2409 void __user *newval, size_t newlen, void **context)
2414 int proc_dostring(ctl_table *table, int write, struct file *filp,
2415 void __user *buffer, size_t *lenp, loff_t *ppos)
2420 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2421 void __user *buffer, size_t *lenp, loff_t *ppos)
2426 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2427 void __user *buffer, size_t *lenp, loff_t *ppos)
2432 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2433 void __user *buffer, size_t *lenp, loff_t *ppos)
2438 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2439 void __user *buffer, size_t *lenp, loff_t *ppos)
2444 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2445 void __user *buffer, size_t *lenp, loff_t *ppos)
2450 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2451 void __user *buffer, size_t *lenp, loff_t *ppos)
2456 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2457 void __user *buffer, size_t *lenp, loff_t *ppos)
2462 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2464 void __user *buffer,
2465 size_t *lenp, loff_t *ppos)
2470 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2476 void unregister_sysctl_table(struct ctl_table_header * table)
2480 #endif /* CONFIG_SYSCTL */
2483 * No sense putting this after each symbol definition, twice,
2484 * exception granted :-)
2486 EXPORT_SYMBOL(proc_dointvec);
2487 EXPORT_SYMBOL(proc_dointvec_jiffies);
2488 EXPORT_SYMBOL(proc_dointvec_minmax);
2489 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2490 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2491 EXPORT_SYMBOL(proc_dostring);
2492 EXPORT_SYMBOL(proc_doulongvec_minmax);
2493 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2494 EXPORT_SYMBOL(register_sysctl_table);
2495 EXPORT_SYMBOL(sysctl_intvec);
2496 EXPORT_SYMBOL(sysctl_jiffies);
2497 EXPORT_SYMBOL(sysctl_ms_jiffies);
2498 EXPORT_SYMBOL(sysctl_string);
2499 EXPORT_SYMBOL(unregister_sysctl_table);