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/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
47 #include <asm/uaccess.h>
48 #include <asm/processor.h>
50 #ifdef CONFIG_ROOT_NFS
51 #include <linux/nfs_fs.h>
54 #if defined(CONFIG_SYSCTL)
56 /* External variables not in a header file. */
58 extern int sysctl_overcommit_memory;
59 extern int sysctl_overcommit_ratio;
60 extern int max_threads;
61 extern int sysrq_enabled;
62 extern int core_uses_pid;
63 extern int suid_dumpable;
64 extern char core_pattern[];
67 extern int min_free_kbytes;
68 extern int printk_ratelimit_jiffies;
69 extern int printk_ratelimit_burst;
70 extern int pid_max_min, pid_max_max;
72 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
73 int unknown_nmi_panic;
74 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
75 void __user *, size_t *, loff_t *);
78 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
79 static int maxolduid = 65535;
82 static int ngroups_max = NGROUPS_MAX;
85 extern char modprobe_path[];
87 #ifdef CONFIG_CHR_DEV_SG
88 extern int sg_big_buff;
91 extern size_t shm_ctlmax;
92 extern size_t shm_ctlall;
93 extern int shm_ctlmni;
94 extern int msg_ctlmax;
95 extern int msg_ctlmnb;
96 extern int msg_ctlmni;
97 extern int sem_ctls[];
101 extern char reboot_command [];
102 extern int stop_a_enabled;
103 extern int scons_pwroff;
107 extern int pwrsw_enabled;
108 extern int unaligned_enabled;
111 #ifdef CONFIG_ARCH_S390
112 #ifdef CONFIG_MATHEMU
113 extern int sysctl_ieee_emulation_warnings;
115 extern int sysctl_userprocess_debug;
116 extern int spin_retry;
119 extern int sysctl_hz_timer;
121 #ifdef CONFIG_BSD_PROCESS_ACCT
122 extern int acct_parm[];
125 int randomize_va_space = 1;
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 = &hotplug_path,
399 .maxlen = HOTPLUG_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,
545 #ifdef CONFIG_ARCH_S390
546 #ifdef CONFIG_MATHEMU
548 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
549 .procname = "ieee_emulation_warnings",
550 .data = &sysctl_ieee_emulation_warnings,
551 .maxlen = sizeof(int),
553 .proc_handler = &proc_dointvec,
556 #ifdef CONFIG_NO_IDLE_HZ
558 .ctl_name = KERN_HZ_TIMER,
559 .procname = "hz_timer",
560 .data = &sysctl_hz_timer,
561 .maxlen = sizeof(int),
563 .proc_handler = &proc_dointvec,
567 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
568 .procname = "userprocess_debug",
569 .data = &sysctl_userprocess_debug,
570 .maxlen = sizeof(int),
572 .proc_handler = &proc_dointvec,
576 .ctl_name = KERN_PIDMAX,
577 .procname = "pid_max",
579 .maxlen = sizeof (int),
581 .proc_handler = &proc_dointvec_minmax,
582 .strategy = sysctl_intvec,
583 .extra1 = &pid_max_min,
584 .extra2 = &pid_max_max,
587 .ctl_name = KERN_PANIC_ON_OOPS,
588 .procname = "panic_on_oops",
589 .data = &panic_on_oops,
590 .maxlen = sizeof(int),
592 .proc_handler = &proc_dointvec,
595 .ctl_name = KERN_PRINTK_RATELIMIT,
596 .procname = "printk_ratelimit",
597 .data = &printk_ratelimit_jiffies,
598 .maxlen = sizeof(int),
600 .proc_handler = &proc_dointvec_jiffies,
601 .strategy = &sysctl_jiffies,
604 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
605 .procname = "printk_ratelimit_burst",
606 .data = &printk_ratelimit_burst,
607 .maxlen = sizeof(int),
609 .proc_handler = &proc_dointvec,
612 .ctl_name = KERN_NGROUPS_MAX,
613 .procname = "ngroups_max",
614 .data = &ngroups_max,
615 .maxlen = sizeof (int),
617 .proc_handler = &proc_dointvec,
619 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
621 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
622 .procname = "unknown_nmi_panic",
623 .data = &unknown_nmi_panic,
624 .maxlen = sizeof (int),
626 .proc_handler = &proc_unknown_nmi_panic,
629 #if defined(CONFIG_X86)
631 .ctl_name = KERN_BOOTLOADER_TYPE,
632 .procname = "bootloader_type",
633 .data = &bootloader_type,
634 .maxlen = sizeof (int),
636 .proc_handler = &proc_dointvec,
640 .ctl_name = KERN_RANDOMIZE,
641 .procname = "randomize_va_space",
642 .data = &randomize_va_space,
643 .maxlen = sizeof(int),
645 .proc_handler = &proc_dointvec,
647 #if defined(CONFIG_ARCH_S390)
649 .ctl_name = KERN_SPIN_RETRY,
650 .procname = "spin_retry",
652 .maxlen = sizeof (int),
654 .proc_handler = &proc_dointvec,
660 /* Constants for minimum and maximum testing in vm_table.
661 We use these as one-element integer vectors. */
663 static int one_hundred = 100;
666 static ctl_table vm_table[] = {
668 .ctl_name = VM_OVERCOMMIT_MEMORY,
669 .procname = "overcommit_memory",
670 .data = &sysctl_overcommit_memory,
671 .maxlen = sizeof(sysctl_overcommit_memory),
673 .proc_handler = &proc_dointvec,
676 .ctl_name = VM_OVERCOMMIT_RATIO,
677 .procname = "overcommit_ratio",
678 .data = &sysctl_overcommit_ratio,
679 .maxlen = sizeof(sysctl_overcommit_ratio),
681 .proc_handler = &proc_dointvec,
684 .ctl_name = VM_PAGE_CLUSTER,
685 .procname = "page-cluster",
686 .data = &page_cluster,
687 .maxlen = sizeof(int),
689 .proc_handler = &proc_dointvec,
692 .ctl_name = VM_DIRTY_BACKGROUND,
693 .procname = "dirty_background_ratio",
694 .data = &dirty_background_ratio,
695 .maxlen = sizeof(dirty_background_ratio),
697 .proc_handler = &proc_dointvec_minmax,
698 .strategy = &sysctl_intvec,
700 .extra2 = &one_hundred,
703 .ctl_name = VM_DIRTY_RATIO,
704 .procname = "dirty_ratio",
705 .data = &vm_dirty_ratio,
706 .maxlen = sizeof(vm_dirty_ratio),
708 .proc_handler = &proc_dointvec_minmax,
709 .strategy = &sysctl_intvec,
711 .extra2 = &one_hundred,
714 .ctl_name = VM_DIRTY_WB_CS,
715 .procname = "dirty_writeback_centisecs",
716 .data = &dirty_writeback_centisecs,
717 .maxlen = sizeof(dirty_writeback_centisecs),
719 .proc_handler = &dirty_writeback_centisecs_handler,
722 .ctl_name = VM_DIRTY_EXPIRE_CS,
723 .procname = "dirty_expire_centisecs",
724 .data = &dirty_expire_centisecs,
725 .maxlen = sizeof(dirty_expire_centisecs),
727 .proc_handler = &proc_dointvec,
730 .ctl_name = VM_NR_PDFLUSH_THREADS,
731 .procname = "nr_pdflush_threads",
732 .data = &nr_pdflush_threads,
733 .maxlen = sizeof nr_pdflush_threads,
734 .mode = 0444 /* read-only*/,
735 .proc_handler = &proc_dointvec,
738 .ctl_name = VM_SWAPPINESS,
739 .procname = "swappiness",
740 .data = &vm_swappiness,
741 .maxlen = sizeof(vm_swappiness),
743 .proc_handler = &proc_dointvec_minmax,
744 .strategy = &sysctl_intvec,
746 .extra2 = &one_hundred,
748 #ifdef CONFIG_HUGETLB_PAGE
750 .ctl_name = VM_HUGETLB_PAGES,
751 .procname = "nr_hugepages",
752 .data = &max_huge_pages,
753 .maxlen = sizeof(unsigned long),
755 .proc_handler = &hugetlb_sysctl_handler,
756 .extra1 = (void *)&hugetlb_zero,
757 .extra2 = (void *)&hugetlb_infinity,
760 .ctl_name = VM_HUGETLB_GROUP,
761 .procname = "hugetlb_shm_group",
762 .data = &sysctl_hugetlb_shm_group,
763 .maxlen = sizeof(gid_t),
765 .proc_handler = &proc_dointvec,
769 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
770 .procname = "lowmem_reserve_ratio",
771 .data = &sysctl_lowmem_reserve_ratio,
772 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
774 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
775 .strategy = &sysctl_intvec,
778 .ctl_name = VM_MIN_FREE_KBYTES,
779 .procname = "min_free_kbytes",
780 .data = &min_free_kbytes,
781 .maxlen = sizeof(min_free_kbytes),
783 .proc_handler = &min_free_kbytes_sysctl_handler,
784 .strategy = &sysctl_intvec,
789 .ctl_name = VM_MAX_MAP_COUNT,
790 .procname = "max_map_count",
791 .data = &sysctl_max_map_count,
792 .maxlen = sizeof(sysctl_max_map_count),
794 .proc_handler = &proc_dointvec
798 .ctl_name = VM_LAPTOP_MODE,
799 .procname = "laptop_mode",
800 .data = &laptop_mode,
801 .maxlen = sizeof(laptop_mode),
803 .proc_handler = &proc_dointvec,
804 .strategy = &sysctl_intvec,
808 .ctl_name = VM_BLOCK_DUMP,
809 .procname = "block_dump",
811 .maxlen = sizeof(block_dump),
813 .proc_handler = &proc_dointvec,
814 .strategy = &sysctl_intvec,
818 .ctl_name = VM_VFS_CACHE_PRESSURE,
819 .procname = "vfs_cache_pressure",
820 .data = &sysctl_vfs_cache_pressure,
821 .maxlen = sizeof(sysctl_vfs_cache_pressure),
823 .proc_handler = &proc_dointvec,
824 .strategy = &sysctl_intvec,
827 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
829 .ctl_name = VM_LEGACY_VA_LAYOUT,
830 .procname = "legacy_va_layout",
831 .data = &sysctl_legacy_va_layout,
832 .maxlen = sizeof(sysctl_legacy_va_layout),
834 .proc_handler = &proc_dointvec,
835 .strategy = &sysctl_intvec,
841 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
842 .procname = "swap_token_timeout",
843 .data = &swap_token_default_timeout,
844 .maxlen = sizeof(swap_token_default_timeout),
846 .proc_handler = &proc_dointvec_jiffies,
847 .strategy = &sysctl_jiffies,
853 static ctl_table proc_table[] = {
857 static ctl_table fs_table[] = {
859 .ctl_name = FS_NRINODE,
860 .procname = "inode-nr",
861 .data = &inodes_stat,
862 .maxlen = 2*sizeof(int),
864 .proc_handler = &proc_dointvec,
867 .ctl_name = FS_STATINODE,
868 .procname = "inode-state",
869 .data = &inodes_stat,
870 .maxlen = 7*sizeof(int),
872 .proc_handler = &proc_dointvec,
875 .ctl_name = FS_NRFILE,
876 .procname = "file-nr",
878 .maxlen = 3*sizeof(int),
880 .proc_handler = &proc_dointvec,
883 .ctl_name = FS_MAXFILE,
884 .procname = "file-max",
885 .data = &files_stat.max_files,
886 .maxlen = sizeof(int),
888 .proc_handler = &proc_dointvec,
891 .ctl_name = FS_DENTRY,
892 .procname = "dentry-state",
893 .data = &dentry_stat,
894 .maxlen = 6*sizeof(int),
896 .proc_handler = &proc_dointvec,
899 .ctl_name = FS_OVERFLOWUID,
900 .procname = "overflowuid",
901 .data = &fs_overflowuid,
902 .maxlen = sizeof(int),
904 .proc_handler = &proc_dointvec_minmax,
905 .strategy = &sysctl_intvec,
906 .extra1 = &minolduid,
907 .extra2 = &maxolduid,
910 .ctl_name = FS_OVERFLOWGID,
911 .procname = "overflowgid",
912 .data = &fs_overflowgid,
913 .maxlen = sizeof(int),
915 .proc_handler = &proc_dointvec_minmax,
916 .strategy = &sysctl_intvec,
917 .extra1 = &minolduid,
918 .extra2 = &maxolduid,
921 .ctl_name = FS_LEASES,
922 .procname = "leases-enable",
923 .data = &leases_enable,
924 .maxlen = sizeof(int),
926 .proc_handler = &proc_dointvec,
928 #ifdef CONFIG_DNOTIFY
930 .ctl_name = FS_DIR_NOTIFY,
931 .procname = "dir-notify-enable",
932 .data = &dir_notify_enable,
933 .maxlen = sizeof(int),
935 .proc_handler = &proc_dointvec,
940 .ctl_name = FS_LEASE_TIME,
941 .procname = "lease-break-time",
942 .data = &lease_break_time,
943 .maxlen = sizeof(int),
945 .proc_handler = &proc_dointvec,
948 .ctl_name = FS_AIO_NR,
949 .procname = "aio-nr",
951 .maxlen = sizeof(aio_nr),
953 .proc_handler = &proc_doulongvec_minmax,
956 .ctl_name = FS_AIO_MAX_NR,
957 .procname = "aio-max-nr",
959 .maxlen = sizeof(aio_max_nr),
961 .proc_handler = &proc_doulongvec_minmax,
963 #ifdef CONFIG_INOTIFY
965 .ctl_name = FS_INOTIFY,
966 .procname = "inotify",
968 .child = inotify_table,
973 .ctl_name = KERN_SETUID_DUMPABLE,
974 .procname = "suid_dumpable",
975 .data = &suid_dumpable,
976 .maxlen = sizeof(int),
978 .proc_handler = &proc_dointvec,
983 static ctl_table debug_table[] = {
987 static ctl_table dev_table[] = {
991 extern void init_irq_proc (void);
993 static DEFINE_SPINLOCK(sysctl_lock);
995 /* called under sysctl_lock */
996 static int use_table(struct ctl_table_header *p)
998 if (unlikely(p->unregistering))
1004 /* called under sysctl_lock */
1005 static void unuse_table(struct ctl_table_header *p)
1008 if (unlikely(p->unregistering))
1009 complete(p->unregistering);
1012 /* called under sysctl_lock, will reacquire if has to wait */
1013 static void start_unregistering(struct ctl_table_header *p)
1016 * if p->used is 0, nobody will ever touch that entry again;
1017 * we'll eliminate all paths to it before dropping sysctl_lock
1019 if (unlikely(p->used)) {
1020 struct completion wait;
1021 init_completion(&wait);
1022 p->unregistering = &wait;
1023 spin_unlock(&sysctl_lock);
1024 wait_for_completion(&wait);
1025 spin_lock(&sysctl_lock);
1028 * do not remove from the list until nobody holds it; walking the
1029 * list in do_sysctl() relies on that.
1031 list_del_init(&p->ctl_entry);
1034 void __init sysctl_init(void)
1036 #ifdef CONFIG_PROC_FS
1037 register_proc_table(root_table, proc_sys_root, &root_table_header);
1042 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1043 void __user *newval, size_t newlen)
1045 struct list_head *tmp;
1046 int error = -ENOTDIR;
1048 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1052 if (!oldlenp || get_user(old_len, oldlenp))
1055 spin_lock(&sysctl_lock);
1056 tmp = &root_table_header.ctl_entry;
1058 struct ctl_table_header *head =
1059 list_entry(tmp, struct ctl_table_header, ctl_entry);
1060 void *context = NULL;
1062 if (!use_table(head))
1065 spin_unlock(&sysctl_lock);
1067 error = parse_table(name, nlen, oldval, oldlenp,
1068 newval, newlen, head->ctl_table,
1072 spin_lock(&sysctl_lock);
1074 if (error != -ENOTDIR)
1076 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1077 spin_unlock(&sysctl_lock);
1081 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1083 struct __sysctl_args tmp;
1086 if (copy_from_user(&tmp, args, sizeof(tmp)))
1090 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1091 tmp.newval, tmp.newlen);
1097 * ctl_perm does NOT grant the superuser all rights automatically, because
1098 * some sysctl variables are readonly even to root.
1101 static int test_perm(int mode, int op)
1105 else if (in_egroup_p(0))
1107 if ((mode & op & 0007) == op)
1112 static inline int ctl_perm(ctl_table *table, int op)
1115 error = security_sysctl(table, op);
1118 return test_perm(table->mode, op);
1121 static int parse_table(int __user *name, int nlen,
1122 void __user *oldval, size_t __user *oldlenp,
1123 void __user *newval, size_t newlen,
1124 ctl_table *table, void **context)
1130 if (get_user(n, name))
1132 for ( ; table->ctl_name; table++) {
1133 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1136 if (ctl_perm(table, 001))
1138 if (table->strategy) {
1139 error = table->strategy(
1142 newval, newlen, context);
1148 table = table->child;
1151 error = do_sysctl_strategy(table, name, nlen,
1153 newval, newlen, context);
1160 /* Perform the actual read/write of a sysctl table entry. */
1161 int do_sysctl_strategy (ctl_table *table,
1162 int __user *name, int nlen,
1163 void __user *oldval, size_t __user *oldlenp,
1164 void __user *newval, size_t newlen, void **context)
1173 if (ctl_perm(table, op))
1176 if (table->strategy) {
1177 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1178 newval, newlen, context);
1185 /* If there is no strategy routine, or if the strategy returns
1186 * zero, proceed with automatic r/w */
1187 if (table->data && table->maxlen) {
1188 if (oldval && oldlenp) {
1189 if (get_user(len, oldlenp))
1192 if (len > table->maxlen)
1193 len = table->maxlen;
1194 if(copy_to_user(oldval, table->data, len))
1196 if(put_user(len, oldlenp))
1200 if (newval && newlen) {
1202 if (len > table->maxlen)
1203 len = table->maxlen;
1204 if(copy_from_user(table->data, newval, len))
1212 * register_sysctl_table - register a sysctl hierarchy
1213 * @table: the top-level table structure
1214 * @insert_at_head: whether the entry should be inserted in front or at the end
1216 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1217 * array. An entry with a ctl_name of 0 terminates the table.
1219 * The members of the &ctl_table structure are used as follows:
1221 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1222 * must be unique within that level of sysctl
1224 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1225 * enter a sysctl file
1227 * data - a pointer to data for use by proc_handler
1229 * maxlen - the maximum size in bytes of the data
1231 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1233 * child - a pointer to the child sysctl table if this entry is a directory, or
1236 * proc_handler - the text handler routine (described below)
1238 * strategy - the strategy routine (described below)
1240 * de - for internal use by the sysctl routines
1242 * extra1, extra2 - extra pointers usable by the proc handler routines
1244 * Leaf nodes in the sysctl tree will be represented by a single file
1245 * under /proc; non-leaf nodes will be represented by directories.
1247 * sysctl(2) can automatically manage read and write requests through
1248 * the sysctl table. The data and maxlen fields of the ctl_table
1249 * struct enable minimal validation of the values being written to be
1250 * performed, and the mode field allows minimal authentication.
1252 * More sophisticated management can be enabled by the provision of a
1253 * strategy routine with the table entry. This will be called before
1254 * any automatic read or write of the data is performed.
1256 * The strategy routine may return
1258 * < 0 - Error occurred (error is passed to user process)
1260 * 0 - OK - proceed with automatic read or write.
1262 * > 0 - OK - read or write has been done by the strategy routine, so
1263 * return immediately.
1265 * There must be a proc_handler routine for any terminal nodes
1266 * mirrored under /proc/sys (non-terminals are handled by a built-in
1267 * directory handler). Several default handlers are available to
1268 * cover common cases -
1270 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1271 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1272 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1274 * It is the handler's job to read the input buffer from user memory
1275 * and process it. The handler should return 0 on success.
1277 * This routine returns %NULL on a failure to register, and a pointer
1278 * to the table header on success.
1280 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1283 struct ctl_table_header *tmp;
1284 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1287 tmp->ctl_table = table;
1288 INIT_LIST_HEAD(&tmp->ctl_entry);
1290 tmp->unregistering = NULL;
1291 spin_lock(&sysctl_lock);
1293 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1295 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1296 spin_unlock(&sysctl_lock);
1297 #ifdef CONFIG_PROC_FS
1298 register_proc_table(table, proc_sys_root, tmp);
1304 * unregister_sysctl_table - unregister a sysctl table hierarchy
1305 * @header: the header returned from register_sysctl_table
1307 * Unregisters the sysctl table and all children. proc entries may not
1308 * actually be removed until they are no longer used by anyone.
1310 void unregister_sysctl_table(struct ctl_table_header * header)
1313 spin_lock(&sysctl_lock);
1314 start_unregistering(header);
1315 #ifdef CONFIG_PROC_FS
1316 unregister_proc_table(header->ctl_table, proc_sys_root);
1318 spin_unlock(&sysctl_lock);
1326 #ifdef CONFIG_PROC_FS
1328 /* Scan the sysctl entries in table and add them all into /proc */
1329 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1331 struct proc_dir_entry *de;
1335 for (; table->ctl_name; table++) {
1336 /* Can't do anything without a proc name. */
1337 if (!table->procname)
1339 /* Maybe we can't do anything with it... */
1340 if (!table->proc_handler && !table->child) {
1341 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1346 len = strlen(table->procname);
1350 if (table->proc_handler)
1354 for (de = root->subdir; de; de = de->next) {
1355 if (proc_match(len, table->procname, de))
1358 /* If the subdir exists already, de is non-NULL */
1362 de = create_proc_entry(table->procname, mode, root);
1366 de->data = (void *) table;
1367 if (table->proc_handler)
1368 de->proc_fops = &proc_sys_file_operations;
1371 if (de->mode & S_IFDIR)
1372 register_proc_table(table->child, de, set);
1377 * Unregister a /proc sysctl table and any subdirectories.
1379 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1381 struct proc_dir_entry *de;
1382 for (; table->ctl_name; table++) {
1383 if (!(de = table->de))
1385 if (de->mode & S_IFDIR) {
1386 if (!table->child) {
1387 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1390 unregister_proc_table(table->child, de);
1392 /* Don't unregister directories which still have entries.. */
1398 * In any case, mark the entry as goner; we'll keep it
1399 * around if it's busy, but we'll know to do nothing with
1400 * its fields. We are under sysctl_lock here.
1404 /* Don't unregister proc entries that are still being used.. */
1405 if (atomic_read(&de->count))
1409 remove_proc_entry(table->procname, root);
1413 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1414 size_t count, loff_t *ppos)
1417 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1418 struct ctl_table *table;
1420 ssize_t error = -ENOTDIR;
1422 spin_lock(&sysctl_lock);
1423 if (de && de->data && use_table(de->set)) {
1425 * at that point we know that sysctl was not unregistered
1426 * and won't be until we finish
1428 spin_unlock(&sysctl_lock);
1429 table = (struct ctl_table *) de->data;
1430 if (!table || !table->proc_handler)
1433 op = (write ? 002 : 004);
1434 if (ctl_perm(table, op))
1437 /* careful: calling conventions are nasty here */
1439 error = (*table->proc_handler)(table, write, file,
1444 spin_lock(&sysctl_lock);
1445 unuse_table(de->set);
1447 spin_unlock(&sysctl_lock);
1451 static int proc_opensys(struct inode *inode, struct file *file)
1453 if (file->f_mode & FMODE_WRITE) {
1455 * sysctl entries that are not writable,
1456 * are _NOT_ writable, capabilities or not.
1458 if (!(inode->i_mode & S_IWUSR))
1465 static ssize_t proc_readsys(struct file * file, char __user * buf,
1466 size_t count, loff_t *ppos)
1468 return do_rw_proc(0, file, buf, count, ppos);
1471 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1472 size_t count, loff_t *ppos)
1474 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1478 * proc_dostring - read a string sysctl
1479 * @table: the sysctl table
1480 * @write: %TRUE if this is a write to the sysctl file
1481 * @filp: the file structure
1482 * @buffer: the user buffer
1483 * @lenp: the size of the user buffer
1484 * @ppos: file position
1486 * Reads/writes a string from/to the user buffer. If the kernel
1487 * buffer provided is not large enough to hold the string, the
1488 * string is truncated. The copied string is %NULL-terminated.
1489 * If the string is being read by the user process, it is copied
1490 * and a newline '\n' is added. It is truncated if the buffer is
1493 * Returns 0 on success.
1495 int proc_dostring(ctl_table *table, int write, struct file *filp,
1496 void __user *buffer, size_t *lenp, loff_t *ppos)
1502 if (!table->data || !table->maxlen || !*lenp ||
1503 (*ppos && !write)) {
1511 while (len < *lenp) {
1512 if (get_user(c, p++))
1514 if (c == 0 || c == '\n')
1518 if (len >= table->maxlen)
1519 len = table->maxlen-1;
1520 if(copy_from_user(table->data, buffer, len))
1522 ((char *) table->data)[len] = 0;
1525 len = strlen(table->data);
1526 if (len > table->maxlen)
1527 len = table->maxlen;
1531 if(copy_to_user(buffer, table->data, len))
1534 if(put_user('\n', ((char __user *) buffer) + len))
1545 * Special case of dostring for the UTS structure. This has locks
1546 * to observe. Should this be in kernel/sys.c ????
1549 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1550 void __user *buffer, size_t *lenp, loff_t *ppos)
1555 down_read(&uts_sem);
1556 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1559 down_write(&uts_sem);
1560 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1566 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1568 int write, void *data)
1571 *valp = *negp ? -*lvalp : *lvalp;
1576 *lvalp = (unsigned long)-val;
1579 *lvalp = (unsigned long)val;
1585 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1586 void __user *buffer, size_t *lenp, loff_t *ppos,
1587 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1588 int write, void *data),
1591 #define TMPBUFLEN 21
1592 int *i, vleft, first=1, neg, val;
1596 char buf[TMPBUFLEN], *p;
1597 char __user *s = buffer;
1599 if (!table->data || !table->maxlen || !*lenp ||
1600 (*ppos && !write)) {
1605 i = (int *) table->data;
1606 vleft = table->maxlen / sizeof(*i);
1610 conv = do_proc_dointvec_conv;
1612 for (; left && vleft--; i++, first=0) {
1627 if (len > sizeof(buf) - 1)
1628 len = sizeof(buf) - 1;
1629 if (copy_from_user(buf, s, len))
1633 if (*p == '-' && left > 1) {
1637 if (*p < '0' || *p > '9')
1640 lval = simple_strtoul(p, &p, 0);
1643 if ((len < left) && *p && !isspace(*p))
1650 if (conv(&neg, &lval, i, 1, data))
1657 if (conv(&neg, &lval, i, 0, data))
1660 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1664 if(copy_to_user(s, buf, len))
1671 if (!write && !first && left) {
1672 if(put_user('\n', s))
1679 if (get_user(c, s++))
1695 * proc_dointvec - read a vector of integers
1696 * @table: the sysctl table
1697 * @write: %TRUE if this is a write to the sysctl file
1698 * @filp: the file structure
1699 * @buffer: the user buffer
1700 * @lenp: the size of the user buffer
1701 * @ppos: file position
1703 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1704 * values from/to the user buffer, treated as an ASCII string.
1706 * Returns 0 on success.
1708 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1709 void __user *buffer, size_t *lenp, loff_t *ppos)
1711 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1721 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1723 int write, void *data)
1725 int op = *(int *)data;
1727 int val = *negp ? -*lvalp : *lvalp;
1729 case OP_SET: *valp = val; break;
1730 case OP_AND: *valp &= val; break;
1731 case OP_OR: *valp |= val; break;
1732 case OP_MAX: if(*valp < val)
1735 case OP_MIN: if(*valp > val)
1743 *lvalp = (unsigned long)-val;
1746 *lvalp = (unsigned long)val;
1753 * init may raise the set.
1756 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1757 void __user *buffer, size_t *lenp, loff_t *ppos)
1761 if (!capable(CAP_SYS_MODULE)) {
1765 op = (current->pid == 1) ? OP_SET : OP_AND;
1766 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1767 do_proc_dointvec_bset_conv,&op);
1770 struct do_proc_dointvec_minmax_conv_param {
1775 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1777 int write, void *data)
1779 struct do_proc_dointvec_minmax_conv_param *param = data;
1781 int val = *negp ? -*lvalp : *lvalp;
1782 if ((param->min && *param->min > val) ||
1783 (param->max && *param->max < val))
1790 *lvalp = (unsigned long)-val;
1793 *lvalp = (unsigned long)val;
1800 * proc_dointvec_minmax - read a vector of integers with min/max values
1801 * @table: the sysctl table
1802 * @write: %TRUE if this is a write to the sysctl file
1803 * @filp: the file structure
1804 * @buffer: the user buffer
1805 * @lenp: the size of the user buffer
1806 * @ppos: file position
1808 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1809 * values from/to the user buffer, treated as an ASCII string.
1811 * This routine will ensure the values are within the range specified by
1812 * table->extra1 (min) and table->extra2 (max).
1814 * Returns 0 on success.
1816 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1817 void __user *buffer, size_t *lenp, loff_t *ppos)
1819 struct do_proc_dointvec_minmax_conv_param param = {
1820 .min = (int *) table->extra1,
1821 .max = (int *) table->extra2,
1823 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1824 do_proc_dointvec_minmax_conv, ¶m);
1827 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1829 void __user *buffer,
1830 size_t *lenp, loff_t *ppos,
1831 unsigned long convmul,
1832 unsigned long convdiv)
1834 #define TMPBUFLEN 21
1835 unsigned long *i, *min, *max, val;
1836 int vleft, first=1, neg;
1838 char buf[TMPBUFLEN], *p;
1839 char __user *s = buffer;
1841 if (!table->data || !table->maxlen || !*lenp ||
1842 (*ppos && !write)) {
1847 i = (unsigned long *) table->data;
1848 min = (unsigned long *) table->extra1;
1849 max = (unsigned long *) table->extra2;
1850 vleft = table->maxlen / sizeof(unsigned long);
1853 for (; left && vleft--; i++, min++, max++, first=0) {
1868 if (len > TMPBUFLEN-1)
1870 if (copy_from_user(buf, s, len))
1874 if (*p == '-' && left > 1) {
1878 if (*p < '0' || *p > '9')
1880 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1882 if ((len < left) && *p && !isspace(*p))
1891 if ((min && val < *min) || (max && val > *max))
1898 sprintf(p, "%lu", convdiv * (*i) / convmul);
1902 if(copy_to_user(s, buf, len))
1909 if (!write && !first && left) {
1910 if(put_user('\n', s))
1917 if (get_user(c, s++))
1933 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1934 * @table: the sysctl table
1935 * @write: %TRUE if this is a write to the sysctl file
1936 * @filp: the file structure
1937 * @buffer: the user buffer
1938 * @lenp: the size of the user buffer
1939 * @ppos: file position
1941 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1942 * values from/to the user buffer, treated as an ASCII string.
1944 * This routine will ensure the values are within the range specified by
1945 * table->extra1 (min) and table->extra2 (max).
1947 * Returns 0 on success.
1949 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1950 void __user *buffer, size_t *lenp, loff_t *ppos)
1952 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1956 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1957 * @table: the sysctl table
1958 * @write: %TRUE if this is a write to the sysctl file
1959 * @filp: the file structure
1960 * @buffer: the user buffer
1961 * @lenp: the size of the user buffer
1962 * @ppos: file position
1964 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1965 * values from/to the user buffer, treated as an ASCII string. The values
1966 * are treated as milliseconds, and converted to jiffies when they are stored.
1968 * This routine will ensure the values are within the range specified by
1969 * table->extra1 (min) and table->extra2 (max).
1971 * Returns 0 on success.
1973 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1975 void __user *buffer,
1976 size_t *lenp, loff_t *ppos)
1978 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1979 lenp, ppos, HZ, 1000l);
1983 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1985 int write, void *data)
1988 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1994 lval = (unsigned long)-val;
1997 lval = (unsigned long)val;
2004 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2006 int write, void *data)
2009 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2015 lval = (unsigned long)-val;
2018 lval = (unsigned long)val;
2020 *lvalp = jiffies_to_clock_t(lval);
2025 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2027 int write, void *data)
2030 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2036 lval = (unsigned long)-val;
2039 lval = (unsigned long)val;
2041 *lvalp = jiffies_to_msecs(lval);
2047 * proc_dointvec_jiffies - read a vector of integers as seconds
2048 * @table: the sysctl table
2049 * @write: %TRUE if this is a write to the sysctl file
2050 * @filp: the file structure
2051 * @buffer: the user buffer
2052 * @lenp: the size of the user buffer
2053 * @ppos: file position
2055 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2056 * values from/to the user buffer, treated as an ASCII string.
2057 * The values read are assumed to be in seconds, and are converted into
2060 * Returns 0 on success.
2062 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2063 void __user *buffer, size_t *lenp, loff_t *ppos)
2065 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2066 do_proc_dointvec_jiffies_conv,NULL);
2070 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2071 * @table: the sysctl table
2072 * @write: %TRUE if this is a write to the sysctl file
2073 * @filp: the file structure
2074 * @buffer: the user buffer
2075 * @lenp: the size of the user buffer
2076 * @ppos: pointer to the file position
2078 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2079 * values from/to the user buffer, treated as an ASCII string.
2080 * The values read are assumed to be in 1/USER_HZ seconds, and
2081 * are converted into jiffies.
2083 * Returns 0 on success.
2085 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2086 void __user *buffer, size_t *lenp, loff_t *ppos)
2088 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2089 do_proc_dointvec_userhz_jiffies_conv,NULL);
2093 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2094 * @table: the sysctl table
2095 * @write: %TRUE if this is a write to the sysctl file
2096 * @filp: the file structure
2097 * @buffer: the user buffer
2098 * @lenp: the size of the user buffer
2099 * @ppos: file position
2100 * @ppos: the current position in the file
2102 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2103 * values from/to the user buffer, treated as an ASCII string.
2104 * The values read are assumed to be in 1/1000 seconds, and
2105 * are converted into jiffies.
2107 * Returns 0 on success.
2109 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2110 void __user *buffer, size_t *lenp, loff_t *ppos)
2112 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2113 do_proc_dointvec_ms_jiffies_conv, NULL);
2116 #else /* CONFIG_PROC_FS */
2118 int proc_dostring(ctl_table *table, int write, struct file *filp,
2119 void __user *buffer, size_t *lenp, loff_t *ppos)
2124 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2125 void __user *buffer, size_t *lenp, loff_t *ppos)
2130 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2131 void __user *buffer, size_t *lenp, loff_t *ppos)
2136 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2137 void __user *buffer, size_t *lenp, loff_t *ppos)
2142 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2143 void __user *buffer, size_t *lenp, loff_t *ppos)
2148 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2149 void __user *buffer, size_t *lenp, loff_t *ppos)
2154 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2155 void __user *buffer, size_t *lenp, loff_t *ppos)
2160 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2161 void __user *buffer, size_t *lenp, loff_t *ppos)
2166 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2167 void __user *buffer, size_t *lenp, loff_t *ppos)
2172 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2174 void __user *buffer,
2175 size_t *lenp, loff_t *ppos)
2181 #endif /* CONFIG_PROC_FS */
2185 * General sysctl support routines
2188 /* The generic string strategy routine: */
2189 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2190 void __user *oldval, size_t __user *oldlenp,
2191 void __user *newval, size_t newlen, void **context)
2193 if (!table->data || !table->maxlen)
2196 if (oldval && oldlenp) {
2198 if (get_user(bufsize, oldlenp))
2201 size_t len = strlen(table->data), copied;
2203 /* This shouldn't trigger for a well-formed sysctl */
2204 if (len > table->maxlen)
2205 len = table->maxlen;
2207 /* Copy up to a max of bufsize-1 bytes of the string */
2208 copied = (len >= bufsize) ? bufsize - 1 : len;
2210 if (copy_to_user(oldval, table->data, copied) ||
2211 put_user(0, (char __user *)(oldval + copied)))
2213 if (put_user(len, oldlenp))
2217 if (newval && newlen) {
2218 size_t len = newlen;
2219 if (len > table->maxlen)
2220 len = table->maxlen;
2221 if(copy_from_user(table->data, newval, len))
2223 if (len == table->maxlen)
2225 ((char *) table->data)[len] = 0;
2231 * This function makes sure that all of the integers in the vector
2232 * are between the minimum and maximum values given in the arrays
2233 * table->extra1 and table->extra2, respectively.
2235 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2236 void __user *oldval, size_t __user *oldlenp,
2237 void __user *newval, size_t newlen, void **context)
2240 if (newval && newlen) {
2241 int __user *vec = (int __user *) newval;
2242 int *min = (int *) table->extra1;
2243 int *max = (int *) table->extra2;
2247 if (newlen % sizeof(int) != 0)
2250 if (!table->extra1 && !table->extra2)
2253 if (newlen > table->maxlen)
2254 newlen = table->maxlen;
2255 length = newlen / sizeof(int);
2257 for (i = 0; i < length; i++) {
2259 if (get_user(value, vec + i))
2261 if (min && value < min[i])
2263 if (max && value > max[i])
2270 /* Strategy function to convert jiffies to seconds */
2271 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2272 void __user *oldval, size_t __user *oldlenp,
2273 void __user *newval, size_t newlen, void **context)
2278 if (get_user(olen, oldlenp))
2280 if (olen!=sizeof(int))
2283 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2284 (oldlenp && put_user(sizeof(int),oldlenp)))
2287 if (newval && newlen) {
2289 if (newlen != sizeof(int))
2291 if (get_user(new, (int __user *)newval))
2293 *(int *)(table->data) = new*HZ;
2298 /* Strategy function to convert jiffies to seconds */
2299 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2300 void __user *oldval, size_t __user *oldlenp,
2301 void __user *newval, size_t newlen, void **context)
2306 if (get_user(olen, oldlenp))
2308 if (olen!=sizeof(int))
2311 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2312 (oldlenp && put_user(sizeof(int),oldlenp)))
2315 if (newval && newlen) {
2317 if (newlen != sizeof(int))
2319 if (get_user(new, (int __user *)newval))
2321 *(int *)(table->data) = msecs_to_jiffies(new);
2326 #else /* CONFIG_SYSCTL */
2329 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2334 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2335 void __user *oldval, size_t __user *oldlenp,
2336 void __user *newval, size_t newlen, void **context)
2341 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2342 void __user *oldval, size_t __user *oldlenp,
2343 void __user *newval, size_t newlen, void **context)
2348 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2349 void __user *oldval, size_t __user *oldlenp,
2350 void __user *newval, size_t newlen, void **context)
2355 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2356 void __user *oldval, size_t __user *oldlenp,
2357 void __user *newval, size_t newlen, void **context)
2362 int proc_dostring(ctl_table *table, int write, struct file *filp,
2363 void __user *buffer, size_t *lenp, loff_t *ppos)
2368 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2369 void __user *buffer, size_t *lenp, loff_t *ppos)
2374 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2375 void __user *buffer, size_t *lenp, loff_t *ppos)
2380 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2386 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2387 void __user *buffer, size_t *lenp, loff_t *ppos)
2392 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2393 void __user *buffer, size_t *lenp, loff_t *ppos)
2398 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2399 void __user *buffer, size_t *lenp, loff_t *ppos)
2404 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2405 void __user *buffer, size_t *lenp, loff_t *ppos)
2410 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2412 void __user *buffer,
2413 size_t *lenp, loff_t *ppos)
2418 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2424 void unregister_sysctl_table(struct ctl_table_header * table)
2428 #endif /* CONFIG_SYSCTL */
2431 * No sense putting this after each symbol definition, twice,
2432 * exception granted :-)
2434 EXPORT_SYMBOL(proc_dointvec);
2435 EXPORT_SYMBOL(proc_dointvec_jiffies);
2436 EXPORT_SYMBOL(proc_dointvec_minmax);
2437 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2438 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2439 EXPORT_SYMBOL(proc_dostring);
2440 EXPORT_SYMBOL(proc_doulongvec_minmax);
2441 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2442 EXPORT_SYMBOL(register_sysctl_table);
2443 EXPORT_SYMBOL(sysctl_intvec);
2444 EXPORT_SYMBOL(sysctl_jiffies);
2445 EXPORT_SYMBOL(sysctl_ms_jiffies);
2446 EXPORT_SYMBOL(sysctl_string);
2447 EXPORT_SYMBOL(unregister_sysctl_table);