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;
71 extern int sysctl_drop_caches;
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;
83 static int ngroups_max = NGROUPS_MAX;
86 extern char modprobe_path[];
88 #ifdef CONFIG_CHR_DEV_SG
89 extern int sg_big_buff;
92 extern size_t shm_ctlmax;
93 extern size_t shm_ctlall;
94 extern int shm_ctlmni;
95 extern int msg_ctlmax;
96 extern int msg_ctlmnb;
97 extern int msg_ctlmni;
98 extern int sem_ctls[];
102 extern char reboot_command [];
103 extern int stop_a_enabled;
104 extern int scons_pwroff;
108 extern int pwrsw_enabled;
109 extern int unaligned_enabled;
113 #ifdef CONFIG_MATHEMU
114 extern int sysctl_ieee_emulation_warnings;
116 extern int sysctl_userprocess_debug;
117 extern int spin_retry;
120 extern int sysctl_hz_timer;
122 #ifdef CONFIG_BSD_PROCESS_ACCT
123 extern int acct_parm[];
126 int randomize_va_space = 1;
128 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
129 ctl_table *, void **);
130 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
131 void __user *buffer, size_t *lenp, loff_t *ppos);
133 static ctl_table root_table[];
134 static struct ctl_table_header root_table_header =
135 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
137 static ctl_table kern_table[];
138 static ctl_table vm_table[];
139 static ctl_table proc_table[];
140 static ctl_table fs_table[];
141 static ctl_table debug_table[];
142 static ctl_table dev_table[];
143 extern ctl_table random_table[];
144 #ifdef CONFIG_UNIX98_PTYS
145 extern ctl_table pty_table[];
147 #ifdef CONFIG_INOTIFY
148 extern ctl_table inotify_table[];
151 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
152 int sysctl_legacy_va_layout;
155 /* /proc declarations: */
157 #ifdef CONFIG_PROC_FS
159 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
160 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
161 static int proc_opensys(struct inode *, struct file *);
163 struct file_operations proc_sys_file_operations = {
164 .open = proc_opensys,
165 .read = proc_readsys,
166 .write = proc_writesys,
169 extern struct proc_dir_entry *proc_sys_root;
171 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
172 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
175 /* The default sysctl tables: */
177 static ctl_table root_table[] = {
179 .ctl_name = CTL_KERN,
180 .procname = "kernel",
199 .ctl_name = CTL_PROC,
211 .ctl_name = CTL_DEBUG,
214 .child = debug_table,
226 static ctl_table kern_table[] = {
228 .ctl_name = KERN_OSTYPE,
229 .procname = "ostype",
230 .data = system_utsname.sysname,
231 .maxlen = sizeof(system_utsname.sysname),
233 .proc_handler = &proc_doutsstring,
234 .strategy = &sysctl_string,
237 .ctl_name = KERN_OSRELEASE,
238 .procname = "osrelease",
239 .data = system_utsname.release,
240 .maxlen = sizeof(system_utsname.release),
242 .proc_handler = &proc_doutsstring,
243 .strategy = &sysctl_string,
246 .ctl_name = KERN_VERSION,
247 .procname = "version",
248 .data = system_utsname.version,
249 .maxlen = sizeof(system_utsname.version),
251 .proc_handler = &proc_doutsstring,
252 .strategy = &sysctl_string,
255 .ctl_name = KERN_NODENAME,
256 .procname = "hostname",
257 .data = system_utsname.nodename,
258 .maxlen = sizeof(system_utsname.nodename),
260 .proc_handler = &proc_doutsstring,
261 .strategy = &sysctl_string,
264 .ctl_name = KERN_DOMAINNAME,
265 .procname = "domainname",
266 .data = system_utsname.domainname,
267 .maxlen = sizeof(system_utsname.domainname),
269 .proc_handler = &proc_doutsstring,
270 .strategy = &sysctl_string,
273 .ctl_name = KERN_PANIC,
275 .data = &panic_timeout,
276 .maxlen = sizeof(int),
278 .proc_handler = &proc_dointvec,
281 .ctl_name = KERN_CORE_USES_PID,
282 .procname = "core_uses_pid",
283 .data = &core_uses_pid,
284 .maxlen = sizeof(int),
286 .proc_handler = &proc_dointvec,
289 .ctl_name = KERN_CORE_PATTERN,
290 .procname = "core_pattern",
291 .data = core_pattern,
294 .proc_handler = &proc_dostring,
295 .strategy = &sysctl_string,
298 .ctl_name = KERN_TAINTED,
299 .procname = "tainted",
301 .maxlen = sizeof(int),
303 .proc_handler = &proc_dointvec,
306 .ctl_name = KERN_CAP_BSET,
307 .procname = "cap-bound",
309 .maxlen = sizeof(kernel_cap_t),
311 .proc_handler = &proc_dointvec_bset,
313 #ifdef CONFIG_BLK_DEV_INITRD
315 .ctl_name = KERN_REALROOTDEV,
316 .procname = "real-root-dev",
317 .data = &real_root_dev,
318 .maxlen = sizeof(int),
320 .proc_handler = &proc_dointvec,
325 .ctl_name = KERN_SPARC_REBOOT,
326 .procname = "reboot-cmd",
327 .data = reboot_command,
330 .proc_handler = &proc_dostring,
331 .strategy = &sysctl_string,
334 .ctl_name = KERN_SPARC_STOP_A,
335 .procname = "stop-a",
336 .data = &stop_a_enabled,
337 .maxlen = sizeof (int),
339 .proc_handler = &proc_dointvec,
342 .ctl_name = KERN_SPARC_SCONS_PWROFF,
343 .procname = "scons-poweroff",
344 .data = &scons_pwroff,
345 .maxlen = sizeof (int),
347 .proc_handler = &proc_dointvec,
352 .ctl_name = KERN_HPPA_PWRSW,
353 .procname = "soft-power",
354 .data = &pwrsw_enabled,
355 .maxlen = sizeof (int),
357 .proc_handler = &proc_dointvec,
360 .ctl_name = KERN_HPPA_UNALIGNED,
361 .procname = "unaligned-trap",
362 .data = &unaligned_enabled,
363 .maxlen = sizeof (int),
365 .proc_handler = &proc_dointvec,
369 .ctl_name = KERN_CTLALTDEL,
370 .procname = "ctrl-alt-del",
372 .maxlen = sizeof(int),
374 .proc_handler = &proc_dointvec,
377 .ctl_name = KERN_PRINTK,
378 .procname = "printk",
379 .data = &console_loglevel,
380 .maxlen = 4*sizeof(int),
382 .proc_handler = &proc_dointvec,
386 .ctl_name = KERN_MODPROBE,
387 .procname = "modprobe",
388 .data = &modprobe_path,
389 .maxlen = KMOD_PATH_LEN,
391 .proc_handler = &proc_dostring,
392 .strategy = &sysctl_string,
395 #ifdef CONFIG_HOTPLUG
397 .ctl_name = KERN_HOTPLUG,
398 .procname = "hotplug",
399 .data = &uevent_helper,
400 .maxlen = UEVENT_HELPER_PATH_LEN,
402 .proc_handler = &proc_dostring,
403 .strategy = &sysctl_string,
406 #ifdef CONFIG_CHR_DEV_SG
408 .ctl_name = KERN_SG_BIG_BUFF,
409 .procname = "sg-big-buff",
410 .data = &sg_big_buff,
411 .maxlen = sizeof (int),
413 .proc_handler = &proc_dointvec,
416 #ifdef CONFIG_BSD_PROCESS_ACCT
418 .ctl_name = KERN_ACCT,
421 .maxlen = 3*sizeof(int),
423 .proc_handler = &proc_dointvec,
426 #ifdef CONFIG_SYSVIPC
428 .ctl_name = KERN_SHMMAX,
429 .procname = "shmmax",
431 .maxlen = sizeof (size_t),
433 .proc_handler = &proc_doulongvec_minmax,
436 .ctl_name = KERN_SHMALL,
437 .procname = "shmall",
439 .maxlen = sizeof (size_t),
441 .proc_handler = &proc_doulongvec_minmax,
444 .ctl_name = KERN_SHMMNI,
445 .procname = "shmmni",
447 .maxlen = sizeof (int),
449 .proc_handler = &proc_dointvec,
452 .ctl_name = KERN_MSGMAX,
453 .procname = "msgmax",
455 .maxlen = sizeof (int),
457 .proc_handler = &proc_dointvec,
460 .ctl_name = KERN_MSGMNI,
461 .procname = "msgmni",
463 .maxlen = sizeof (int),
465 .proc_handler = &proc_dointvec,
468 .ctl_name = KERN_MSGMNB,
469 .procname = "msgmnb",
471 .maxlen = sizeof (int),
473 .proc_handler = &proc_dointvec,
476 .ctl_name = KERN_SEM,
479 .maxlen = 4*sizeof (int),
481 .proc_handler = &proc_dointvec,
484 #ifdef CONFIG_MAGIC_SYSRQ
486 .ctl_name = KERN_SYSRQ,
488 .data = &sysrq_enabled,
489 .maxlen = sizeof (int),
491 .proc_handler = &proc_dointvec,
495 .ctl_name = KERN_CADPID,
496 .procname = "cad_pid",
498 .maxlen = sizeof (int),
500 .proc_handler = &proc_dointvec,
503 .ctl_name = KERN_MAX_THREADS,
504 .procname = "threads-max",
505 .data = &max_threads,
506 .maxlen = sizeof(int),
508 .proc_handler = &proc_dointvec,
511 .ctl_name = KERN_RANDOM,
512 .procname = "random",
514 .child = random_table,
516 #ifdef CONFIG_UNIX98_PTYS
518 .ctl_name = KERN_PTY,
525 .ctl_name = KERN_OVERFLOWUID,
526 .procname = "overflowuid",
527 .data = &overflowuid,
528 .maxlen = sizeof(int),
530 .proc_handler = &proc_dointvec_minmax,
531 .strategy = &sysctl_intvec,
532 .extra1 = &minolduid,
533 .extra2 = &maxolduid,
536 .ctl_name = KERN_OVERFLOWGID,
537 .procname = "overflowgid",
538 .data = &overflowgid,
539 .maxlen = sizeof(int),
541 .proc_handler = &proc_dointvec_minmax,
542 .strategy = &sysctl_intvec,
543 .extra1 = &minolduid,
544 .extra2 = &maxolduid,
547 #ifdef CONFIG_MATHEMU
549 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
550 .procname = "ieee_emulation_warnings",
551 .data = &sysctl_ieee_emulation_warnings,
552 .maxlen = sizeof(int),
554 .proc_handler = &proc_dointvec,
557 #ifdef CONFIG_NO_IDLE_HZ
559 .ctl_name = KERN_HZ_TIMER,
560 .procname = "hz_timer",
561 .data = &sysctl_hz_timer,
562 .maxlen = sizeof(int),
564 .proc_handler = &proc_dointvec,
568 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
569 .procname = "userprocess_debug",
570 .data = &sysctl_userprocess_debug,
571 .maxlen = sizeof(int),
573 .proc_handler = &proc_dointvec,
577 .ctl_name = KERN_PIDMAX,
578 .procname = "pid_max",
580 .maxlen = sizeof (int),
582 .proc_handler = &proc_dointvec_minmax,
583 .strategy = sysctl_intvec,
584 .extra1 = &pid_max_min,
585 .extra2 = &pid_max_max,
588 .ctl_name = KERN_PANIC_ON_OOPS,
589 .procname = "panic_on_oops",
590 .data = &panic_on_oops,
591 .maxlen = sizeof(int),
593 .proc_handler = &proc_dointvec,
596 .ctl_name = KERN_PRINTK_RATELIMIT,
597 .procname = "printk_ratelimit",
598 .data = &printk_ratelimit_jiffies,
599 .maxlen = sizeof(int),
601 .proc_handler = &proc_dointvec_jiffies,
602 .strategy = &sysctl_jiffies,
605 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
606 .procname = "printk_ratelimit_burst",
607 .data = &printk_ratelimit_burst,
608 .maxlen = sizeof(int),
610 .proc_handler = &proc_dointvec,
613 .ctl_name = KERN_NGROUPS_MAX,
614 .procname = "ngroups_max",
615 .data = &ngroups_max,
616 .maxlen = sizeof (int),
618 .proc_handler = &proc_dointvec,
620 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
622 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
623 .procname = "unknown_nmi_panic",
624 .data = &unknown_nmi_panic,
625 .maxlen = sizeof (int),
627 .proc_handler = &proc_unknown_nmi_panic,
630 #if defined(CONFIG_X86)
632 .ctl_name = KERN_BOOTLOADER_TYPE,
633 .procname = "bootloader_type",
634 .data = &bootloader_type,
635 .maxlen = sizeof (int),
637 .proc_handler = &proc_dointvec,
641 .ctl_name = KERN_RANDOMIZE,
642 .procname = "randomize_va_space",
643 .data = &randomize_va_space,
644 .maxlen = sizeof(int),
646 .proc_handler = &proc_dointvec,
648 #if defined(CONFIG_S390)
650 .ctl_name = KERN_SPIN_RETRY,
651 .procname = "spin_retry",
653 .maxlen = sizeof (int),
655 .proc_handler = &proc_dointvec,
661 /* Constants for minimum and maximum testing in vm_table.
662 We use these as one-element integer vectors. */
664 static int one_hundred = 100;
667 static ctl_table vm_table[] = {
669 .ctl_name = VM_OVERCOMMIT_MEMORY,
670 .procname = "overcommit_memory",
671 .data = &sysctl_overcommit_memory,
672 .maxlen = sizeof(sysctl_overcommit_memory),
674 .proc_handler = &proc_dointvec,
677 .ctl_name = VM_OVERCOMMIT_RATIO,
678 .procname = "overcommit_ratio",
679 .data = &sysctl_overcommit_ratio,
680 .maxlen = sizeof(sysctl_overcommit_ratio),
682 .proc_handler = &proc_dointvec,
685 .ctl_name = VM_PAGE_CLUSTER,
686 .procname = "page-cluster",
687 .data = &page_cluster,
688 .maxlen = sizeof(int),
690 .proc_handler = &proc_dointvec,
693 .ctl_name = VM_DIRTY_BACKGROUND,
694 .procname = "dirty_background_ratio",
695 .data = &dirty_background_ratio,
696 .maxlen = sizeof(dirty_background_ratio),
698 .proc_handler = &proc_dointvec_minmax,
699 .strategy = &sysctl_intvec,
701 .extra2 = &one_hundred,
704 .ctl_name = VM_DIRTY_RATIO,
705 .procname = "dirty_ratio",
706 .data = &vm_dirty_ratio,
707 .maxlen = sizeof(vm_dirty_ratio),
709 .proc_handler = &proc_dointvec_minmax,
710 .strategy = &sysctl_intvec,
712 .extra2 = &one_hundred,
715 .ctl_name = VM_DIRTY_WB_CS,
716 .procname = "dirty_writeback_centisecs",
717 .data = &dirty_writeback_centisecs,
718 .maxlen = sizeof(dirty_writeback_centisecs),
720 .proc_handler = &dirty_writeback_centisecs_handler,
723 .ctl_name = VM_DIRTY_EXPIRE_CS,
724 .procname = "dirty_expire_centisecs",
725 .data = &dirty_expire_centisecs,
726 .maxlen = sizeof(dirty_expire_centisecs),
728 .proc_handler = &proc_dointvec,
731 .ctl_name = VM_NR_PDFLUSH_THREADS,
732 .procname = "nr_pdflush_threads",
733 .data = &nr_pdflush_threads,
734 .maxlen = sizeof nr_pdflush_threads,
735 .mode = 0444 /* read-only*/,
736 .proc_handler = &proc_dointvec,
739 .ctl_name = VM_SWAPPINESS,
740 .procname = "swappiness",
741 .data = &vm_swappiness,
742 .maxlen = sizeof(vm_swappiness),
744 .proc_handler = &proc_dointvec_minmax,
745 .strategy = &sysctl_intvec,
747 .extra2 = &one_hundred,
749 #ifdef CONFIG_HUGETLB_PAGE
751 .ctl_name = VM_HUGETLB_PAGES,
752 .procname = "nr_hugepages",
753 .data = &max_huge_pages,
754 .maxlen = sizeof(unsigned long),
756 .proc_handler = &hugetlb_sysctl_handler,
757 .extra1 = (void *)&hugetlb_zero,
758 .extra2 = (void *)&hugetlb_infinity,
761 .ctl_name = VM_HUGETLB_GROUP,
762 .procname = "hugetlb_shm_group",
763 .data = &sysctl_hugetlb_shm_group,
764 .maxlen = sizeof(gid_t),
766 .proc_handler = &proc_dointvec,
770 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
771 .procname = "lowmem_reserve_ratio",
772 .data = &sysctl_lowmem_reserve_ratio,
773 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
775 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
776 .strategy = &sysctl_intvec,
779 .ctl_name = VM_DROP_PAGECACHE,
780 .procname = "drop_caches",
781 .data = &sysctl_drop_caches,
782 .maxlen = sizeof(int),
784 .proc_handler = drop_caches_sysctl_handler,
785 .strategy = &sysctl_intvec,
788 .ctl_name = VM_MIN_FREE_KBYTES,
789 .procname = "min_free_kbytes",
790 .data = &min_free_kbytes,
791 .maxlen = sizeof(min_free_kbytes),
793 .proc_handler = &min_free_kbytes_sysctl_handler,
794 .strategy = &sysctl_intvec,
799 .ctl_name = VM_MAX_MAP_COUNT,
800 .procname = "max_map_count",
801 .data = &sysctl_max_map_count,
802 .maxlen = sizeof(sysctl_max_map_count),
804 .proc_handler = &proc_dointvec
808 .ctl_name = VM_LAPTOP_MODE,
809 .procname = "laptop_mode",
810 .data = &laptop_mode,
811 .maxlen = sizeof(laptop_mode),
813 .proc_handler = &proc_dointvec,
814 .strategy = &sysctl_intvec,
818 .ctl_name = VM_BLOCK_DUMP,
819 .procname = "block_dump",
821 .maxlen = sizeof(block_dump),
823 .proc_handler = &proc_dointvec,
824 .strategy = &sysctl_intvec,
828 .ctl_name = VM_VFS_CACHE_PRESSURE,
829 .procname = "vfs_cache_pressure",
830 .data = &sysctl_vfs_cache_pressure,
831 .maxlen = sizeof(sysctl_vfs_cache_pressure),
833 .proc_handler = &proc_dointvec,
834 .strategy = &sysctl_intvec,
837 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
839 .ctl_name = VM_LEGACY_VA_LAYOUT,
840 .procname = "legacy_va_layout",
841 .data = &sysctl_legacy_va_layout,
842 .maxlen = sizeof(sysctl_legacy_va_layout),
844 .proc_handler = &proc_dointvec,
845 .strategy = &sysctl_intvec,
851 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
852 .procname = "swap_token_timeout",
853 .data = &swap_token_default_timeout,
854 .maxlen = sizeof(swap_token_default_timeout),
856 .proc_handler = &proc_dointvec_jiffies,
857 .strategy = &sysctl_jiffies,
863 static ctl_table proc_table[] = {
867 static ctl_table fs_table[] = {
869 .ctl_name = FS_NRINODE,
870 .procname = "inode-nr",
871 .data = &inodes_stat,
872 .maxlen = 2*sizeof(int),
874 .proc_handler = &proc_dointvec,
877 .ctl_name = FS_STATINODE,
878 .procname = "inode-state",
879 .data = &inodes_stat,
880 .maxlen = 7*sizeof(int),
882 .proc_handler = &proc_dointvec,
885 .ctl_name = FS_NRFILE,
886 .procname = "file-nr",
888 .maxlen = 3*sizeof(int),
890 .proc_handler = &proc_dointvec,
893 .ctl_name = FS_MAXFILE,
894 .procname = "file-max",
895 .data = &files_stat.max_files,
896 .maxlen = sizeof(int),
898 .proc_handler = &proc_dointvec,
901 .ctl_name = FS_DENTRY,
902 .procname = "dentry-state",
903 .data = &dentry_stat,
904 .maxlen = 6*sizeof(int),
906 .proc_handler = &proc_dointvec,
909 .ctl_name = FS_OVERFLOWUID,
910 .procname = "overflowuid",
911 .data = &fs_overflowuid,
912 .maxlen = sizeof(int),
914 .proc_handler = &proc_dointvec_minmax,
915 .strategy = &sysctl_intvec,
916 .extra1 = &minolduid,
917 .extra2 = &maxolduid,
920 .ctl_name = FS_OVERFLOWGID,
921 .procname = "overflowgid",
922 .data = &fs_overflowgid,
923 .maxlen = sizeof(int),
925 .proc_handler = &proc_dointvec_minmax,
926 .strategy = &sysctl_intvec,
927 .extra1 = &minolduid,
928 .extra2 = &maxolduid,
931 .ctl_name = FS_LEASES,
932 .procname = "leases-enable",
933 .data = &leases_enable,
934 .maxlen = sizeof(int),
936 .proc_handler = &proc_dointvec,
938 #ifdef CONFIG_DNOTIFY
940 .ctl_name = FS_DIR_NOTIFY,
941 .procname = "dir-notify-enable",
942 .data = &dir_notify_enable,
943 .maxlen = sizeof(int),
945 .proc_handler = &proc_dointvec,
950 .ctl_name = FS_LEASE_TIME,
951 .procname = "lease-break-time",
952 .data = &lease_break_time,
953 .maxlen = sizeof(int),
955 .proc_handler = &proc_dointvec,
958 .ctl_name = FS_AIO_NR,
959 .procname = "aio-nr",
961 .maxlen = sizeof(aio_nr),
963 .proc_handler = &proc_doulongvec_minmax,
966 .ctl_name = FS_AIO_MAX_NR,
967 .procname = "aio-max-nr",
969 .maxlen = sizeof(aio_max_nr),
971 .proc_handler = &proc_doulongvec_minmax,
973 #ifdef CONFIG_INOTIFY
975 .ctl_name = FS_INOTIFY,
976 .procname = "inotify",
978 .child = inotify_table,
983 .ctl_name = KERN_SETUID_DUMPABLE,
984 .procname = "suid_dumpable",
985 .data = &suid_dumpable,
986 .maxlen = sizeof(int),
988 .proc_handler = &proc_dointvec,
993 static ctl_table debug_table[] = {
997 static ctl_table dev_table[] = {
1001 extern void init_irq_proc (void);
1003 static DEFINE_SPINLOCK(sysctl_lock);
1005 /* called under sysctl_lock */
1006 static int use_table(struct ctl_table_header *p)
1008 if (unlikely(p->unregistering))
1014 /* called under sysctl_lock */
1015 static void unuse_table(struct ctl_table_header *p)
1018 if (unlikely(p->unregistering))
1019 complete(p->unregistering);
1022 /* called under sysctl_lock, will reacquire if has to wait */
1023 static void start_unregistering(struct ctl_table_header *p)
1026 * if p->used is 0, nobody will ever touch that entry again;
1027 * we'll eliminate all paths to it before dropping sysctl_lock
1029 if (unlikely(p->used)) {
1030 struct completion wait;
1031 init_completion(&wait);
1032 p->unregistering = &wait;
1033 spin_unlock(&sysctl_lock);
1034 wait_for_completion(&wait);
1035 spin_lock(&sysctl_lock);
1038 * do not remove from the list until nobody holds it; walking the
1039 * list in do_sysctl() relies on that.
1041 list_del_init(&p->ctl_entry);
1044 void __init sysctl_init(void)
1046 #ifdef CONFIG_PROC_FS
1047 register_proc_table(root_table, proc_sys_root, &root_table_header);
1052 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1053 void __user *newval, size_t newlen)
1055 struct list_head *tmp;
1056 int error = -ENOTDIR;
1058 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1062 if (!oldlenp || get_user(old_len, oldlenp))
1065 spin_lock(&sysctl_lock);
1066 tmp = &root_table_header.ctl_entry;
1068 struct ctl_table_header *head =
1069 list_entry(tmp, struct ctl_table_header, ctl_entry);
1070 void *context = NULL;
1072 if (!use_table(head))
1075 spin_unlock(&sysctl_lock);
1077 error = parse_table(name, nlen, oldval, oldlenp,
1078 newval, newlen, head->ctl_table,
1082 spin_lock(&sysctl_lock);
1084 if (error != -ENOTDIR)
1086 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1087 spin_unlock(&sysctl_lock);
1091 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1093 struct __sysctl_args tmp;
1096 if (copy_from_user(&tmp, args, sizeof(tmp)))
1100 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1101 tmp.newval, tmp.newlen);
1107 * ctl_perm does NOT grant the superuser all rights automatically, because
1108 * some sysctl variables are readonly even to root.
1111 static int test_perm(int mode, int op)
1115 else if (in_egroup_p(0))
1117 if ((mode & op & 0007) == op)
1122 static inline int ctl_perm(ctl_table *table, int op)
1125 error = security_sysctl(table, op);
1128 return test_perm(table->mode, op);
1131 static int parse_table(int __user *name, int nlen,
1132 void __user *oldval, size_t __user *oldlenp,
1133 void __user *newval, size_t newlen,
1134 ctl_table *table, void **context)
1140 if (get_user(n, name))
1142 for ( ; table->ctl_name; table++) {
1143 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1146 if (ctl_perm(table, 001))
1148 if (table->strategy) {
1149 error = table->strategy(
1152 newval, newlen, context);
1158 table = table->child;
1161 error = do_sysctl_strategy(table, name, nlen,
1163 newval, newlen, context);
1170 /* Perform the actual read/write of a sysctl table entry. */
1171 int do_sysctl_strategy (ctl_table *table,
1172 int __user *name, int nlen,
1173 void __user *oldval, size_t __user *oldlenp,
1174 void __user *newval, size_t newlen, void **context)
1183 if (ctl_perm(table, op))
1186 if (table->strategy) {
1187 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1188 newval, newlen, context);
1195 /* If there is no strategy routine, or if the strategy returns
1196 * zero, proceed with automatic r/w */
1197 if (table->data && table->maxlen) {
1198 if (oldval && oldlenp) {
1199 if (get_user(len, oldlenp))
1202 if (len > table->maxlen)
1203 len = table->maxlen;
1204 if(copy_to_user(oldval, table->data, len))
1206 if(put_user(len, oldlenp))
1210 if (newval && newlen) {
1212 if (len > table->maxlen)
1213 len = table->maxlen;
1214 if(copy_from_user(table->data, newval, len))
1222 * register_sysctl_table - register a sysctl hierarchy
1223 * @table: the top-level table structure
1224 * @insert_at_head: whether the entry should be inserted in front or at the end
1226 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1227 * array. An entry with a ctl_name of 0 terminates the table.
1229 * The members of the &ctl_table structure are used as follows:
1231 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1232 * must be unique within that level of sysctl
1234 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1235 * enter a sysctl file
1237 * data - a pointer to data for use by proc_handler
1239 * maxlen - the maximum size in bytes of the data
1241 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1243 * child - a pointer to the child sysctl table if this entry is a directory, or
1246 * proc_handler - the text handler routine (described below)
1248 * strategy - the strategy routine (described below)
1250 * de - for internal use by the sysctl routines
1252 * extra1, extra2 - extra pointers usable by the proc handler routines
1254 * Leaf nodes in the sysctl tree will be represented by a single file
1255 * under /proc; non-leaf nodes will be represented by directories.
1257 * sysctl(2) can automatically manage read and write requests through
1258 * the sysctl table. The data and maxlen fields of the ctl_table
1259 * struct enable minimal validation of the values being written to be
1260 * performed, and the mode field allows minimal authentication.
1262 * More sophisticated management can be enabled by the provision of a
1263 * strategy routine with the table entry. This will be called before
1264 * any automatic read or write of the data is performed.
1266 * The strategy routine may return
1268 * < 0 - Error occurred (error is passed to user process)
1270 * 0 - OK - proceed with automatic read or write.
1272 * > 0 - OK - read or write has been done by the strategy routine, so
1273 * return immediately.
1275 * There must be a proc_handler routine for any terminal nodes
1276 * mirrored under /proc/sys (non-terminals are handled by a built-in
1277 * directory handler). Several default handlers are available to
1278 * cover common cases -
1280 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1281 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1282 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1284 * It is the handler's job to read the input buffer from user memory
1285 * and process it. The handler should return 0 on success.
1287 * This routine returns %NULL on a failure to register, and a pointer
1288 * to the table header on success.
1290 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1293 struct ctl_table_header *tmp;
1294 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1297 tmp->ctl_table = table;
1298 INIT_LIST_HEAD(&tmp->ctl_entry);
1300 tmp->unregistering = NULL;
1301 spin_lock(&sysctl_lock);
1303 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1305 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1306 spin_unlock(&sysctl_lock);
1307 #ifdef CONFIG_PROC_FS
1308 register_proc_table(table, proc_sys_root, tmp);
1314 * unregister_sysctl_table - unregister a sysctl table hierarchy
1315 * @header: the header returned from register_sysctl_table
1317 * Unregisters the sysctl table and all children. proc entries may not
1318 * actually be removed until they are no longer used by anyone.
1320 void unregister_sysctl_table(struct ctl_table_header * header)
1323 spin_lock(&sysctl_lock);
1324 start_unregistering(header);
1325 #ifdef CONFIG_PROC_FS
1326 unregister_proc_table(header->ctl_table, proc_sys_root);
1328 spin_unlock(&sysctl_lock);
1336 #ifdef CONFIG_PROC_FS
1338 /* Scan the sysctl entries in table and add them all into /proc */
1339 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1341 struct proc_dir_entry *de;
1345 for (; table->ctl_name; table++) {
1346 /* Can't do anything without a proc name. */
1347 if (!table->procname)
1349 /* Maybe we can't do anything with it... */
1350 if (!table->proc_handler && !table->child) {
1351 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1356 len = strlen(table->procname);
1360 if (table->proc_handler)
1364 for (de = root->subdir; de; de = de->next) {
1365 if (proc_match(len, table->procname, de))
1368 /* If the subdir exists already, de is non-NULL */
1372 de = create_proc_entry(table->procname, mode, root);
1376 de->data = (void *) table;
1377 if (table->proc_handler)
1378 de->proc_fops = &proc_sys_file_operations;
1381 if (de->mode & S_IFDIR)
1382 register_proc_table(table->child, de, set);
1387 * Unregister a /proc sysctl table and any subdirectories.
1389 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1391 struct proc_dir_entry *de;
1392 for (; table->ctl_name; table++) {
1393 if (!(de = table->de))
1395 if (de->mode & S_IFDIR) {
1396 if (!table->child) {
1397 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1400 unregister_proc_table(table->child, de);
1402 /* Don't unregister directories which still have entries.. */
1408 * In any case, mark the entry as goner; we'll keep it
1409 * around if it's busy, but we'll know to do nothing with
1410 * its fields. We are under sysctl_lock here.
1414 /* Don't unregister proc entries that are still being used.. */
1415 if (atomic_read(&de->count))
1419 remove_proc_entry(table->procname, root);
1423 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1424 size_t count, loff_t *ppos)
1427 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1428 struct ctl_table *table;
1430 ssize_t error = -ENOTDIR;
1432 spin_lock(&sysctl_lock);
1433 if (de && de->data && use_table(de->set)) {
1435 * at that point we know that sysctl was not unregistered
1436 * and won't be until we finish
1438 spin_unlock(&sysctl_lock);
1439 table = (struct ctl_table *) de->data;
1440 if (!table || !table->proc_handler)
1443 op = (write ? 002 : 004);
1444 if (ctl_perm(table, op))
1447 /* careful: calling conventions are nasty here */
1449 error = (*table->proc_handler)(table, write, file,
1454 spin_lock(&sysctl_lock);
1455 unuse_table(de->set);
1457 spin_unlock(&sysctl_lock);
1461 static int proc_opensys(struct inode *inode, struct file *file)
1463 if (file->f_mode & FMODE_WRITE) {
1465 * sysctl entries that are not writable,
1466 * are _NOT_ writable, capabilities or not.
1468 if (!(inode->i_mode & S_IWUSR))
1475 static ssize_t proc_readsys(struct file * file, char __user * buf,
1476 size_t count, loff_t *ppos)
1478 return do_rw_proc(0, file, buf, count, ppos);
1481 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1482 size_t count, loff_t *ppos)
1484 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1488 * proc_dostring - read a string sysctl
1489 * @table: the sysctl table
1490 * @write: %TRUE if this is a write to the sysctl file
1491 * @filp: the file structure
1492 * @buffer: the user buffer
1493 * @lenp: the size of the user buffer
1494 * @ppos: file position
1496 * Reads/writes a string from/to the user buffer. If the kernel
1497 * buffer provided is not large enough to hold the string, the
1498 * string is truncated. The copied string is %NULL-terminated.
1499 * If the string is being read by the user process, it is copied
1500 * and a newline '\n' is added. It is truncated if the buffer is
1503 * Returns 0 on success.
1505 int proc_dostring(ctl_table *table, int write, struct file *filp,
1506 void __user *buffer, size_t *lenp, loff_t *ppos)
1512 if (!table->data || !table->maxlen || !*lenp ||
1513 (*ppos && !write)) {
1521 while (len < *lenp) {
1522 if (get_user(c, p++))
1524 if (c == 0 || c == '\n')
1528 if (len >= table->maxlen)
1529 len = table->maxlen-1;
1530 if(copy_from_user(table->data, buffer, len))
1532 ((char *) table->data)[len] = 0;
1535 len = strlen(table->data);
1536 if (len > table->maxlen)
1537 len = table->maxlen;
1541 if(copy_to_user(buffer, table->data, len))
1544 if(put_user('\n', ((char __user *) buffer) + len))
1555 * Special case of dostring for the UTS structure. This has locks
1556 * to observe. Should this be in kernel/sys.c ????
1559 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1560 void __user *buffer, size_t *lenp, loff_t *ppos)
1565 down_read(&uts_sem);
1566 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1569 down_write(&uts_sem);
1570 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1576 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1578 int write, void *data)
1581 *valp = *negp ? -*lvalp : *lvalp;
1586 *lvalp = (unsigned long)-val;
1589 *lvalp = (unsigned long)val;
1595 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1596 void __user *buffer, size_t *lenp, loff_t *ppos,
1597 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1598 int write, void *data),
1601 #define TMPBUFLEN 21
1602 int *i, vleft, first=1, neg, val;
1606 char buf[TMPBUFLEN], *p;
1607 char __user *s = buffer;
1609 if (!table->data || !table->maxlen || !*lenp ||
1610 (*ppos && !write)) {
1615 i = (int *) table->data;
1616 vleft = table->maxlen / sizeof(*i);
1620 conv = do_proc_dointvec_conv;
1622 for (; left && vleft--; i++, first=0) {
1637 if (len > sizeof(buf) - 1)
1638 len = sizeof(buf) - 1;
1639 if (copy_from_user(buf, s, len))
1643 if (*p == '-' && left > 1) {
1647 if (*p < '0' || *p > '9')
1650 lval = simple_strtoul(p, &p, 0);
1653 if ((len < left) && *p && !isspace(*p))
1660 if (conv(&neg, &lval, i, 1, data))
1667 if (conv(&neg, &lval, i, 0, data))
1670 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1674 if(copy_to_user(s, buf, len))
1681 if (!write && !first && left) {
1682 if(put_user('\n', s))
1689 if (get_user(c, s++))
1705 * proc_dointvec - read a vector of integers
1706 * @table: the sysctl table
1707 * @write: %TRUE if this is a write to the sysctl file
1708 * @filp: the file structure
1709 * @buffer: the user buffer
1710 * @lenp: the size of the user buffer
1711 * @ppos: file position
1713 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1714 * values from/to the user buffer, treated as an ASCII string.
1716 * Returns 0 on success.
1718 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1719 void __user *buffer, size_t *lenp, loff_t *ppos)
1721 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1731 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1733 int write, void *data)
1735 int op = *(int *)data;
1737 int val = *negp ? -*lvalp : *lvalp;
1739 case OP_SET: *valp = val; break;
1740 case OP_AND: *valp &= val; break;
1741 case OP_OR: *valp |= val; break;
1742 case OP_MAX: if(*valp < val)
1745 case OP_MIN: if(*valp > val)
1753 *lvalp = (unsigned long)-val;
1756 *lvalp = (unsigned long)val;
1763 * init may raise the set.
1766 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1767 void __user *buffer, size_t *lenp, loff_t *ppos)
1771 if (!capable(CAP_SYS_MODULE)) {
1775 op = (current->pid == 1) ? OP_SET : OP_AND;
1776 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1777 do_proc_dointvec_bset_conv,&op);
1780 struct do_proc_dointvec_minmax_conv_param {
1785 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1787 int write, void *data)
1789 struct do_proc_dointvec_minmax_conv_param *param = data;
1791 int val = *negp ? -*lvalp : *lvalp;
1792 if ((param->min && *param->min > val) ||
1793 (param->max && *param->max < val))
1800 *lvalp = (unsigned long)-val;
1803 *lvalp = (unsigned long)val;
1810 * proc_dointvec_minmax - read a vector of integers with min/max values
1811 * @table: the sysctl table
1812 * @write: %TRUE if this is a write to the sysctl file
1813 * @filp: the file structure
1814 * @buffer: the user buffer
1815 * @lenp: the size of the user buffer
1816 * @ppos: file position
1818 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1819 * values from/to the user buffer, treated as an ASCII string.
1821 * This routine will ensure the values are within the range specified by
1822 * table->extra1 (min) and table->extra2 (max).
1824 * Returns 0 on success.
1826 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1827 void __user *buffer, size_t *lenp, loff_t *ppos)
1829 struct do_proc_dointvec_minmax_conv_param param = {
1830 .min = (int *) table->extra1,
1831 .max = (int *) table->extra2,
1833 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1834 do_proc_dointvec_minmax_conv, ¶m);
1837 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1839 void __user *buffer,
1840 size_t *lenp, loff_t *ppos,
1841 unsigned long convmul,
1842 unsigned long convdiv)
1844 #define TMPBUFLEN 21
1845 unsigned long *i, *min, *max, val;
1846 int vleft, first=1, neg;
1848 char buf[TMPBUFLEN], *p;
1849 char __user *s = buffer;
1851 if (!table->data || !table->maxlen || !*lenp ||
1852 (*ppos && !write)) {
1857 i = (unsigned long *) table->data;
1858 min = (unsigned long *) table->extra1;
1859 max = (unsigned long *) table->extra2;
1860 vleft = table->maxlen / sizeof(unsigned long);
1863 for (; left && vleft--; i++, min++, max++, first=0) {
1878 if (len > TMPBUFLEN-1)
1880 if (copy_from_user(buf, s, len))
1884 if (*p == '-' && left > 1) {
1888 if (*p < '0' || *p > '9')
1890 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1892 if ((len < left) && *p && !isspace(*p))
1901 if ((min && val < *min) || (max && val > *max))
1908 sprintf(p, "%lu", convdiv * (*i) / convmul);
1912 if(copy_to_user(s, buf, len))
1919 if (!write && !first && left) {
1920 if(put_user('\n', s))
1927 if (get_user(c, s++))
1943 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1944 * @table: the sysctl table
1945 * @write: %TRUE if this is a write to the sysctl file
1946 * @filp: the file structure
1947 * @buffer: the user buffer
1948 * @lenp: the size of the user buffer
1949 * @ppos: file position
1951 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1952 * values from/to the user buffer, treated as an ASCII string.
1954 * This routine will ensure the values are within the range specified by
1955 * table->extra1 (min) and table->extra2 (max).
1957 * Returns 0 on success.
1959 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1960 void __user *buffer, size_t *lenp, loff_t *ppos)
1962 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1966 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1967 * @table: the sysctl table
1968 * @write: %TRUE if this is a write to the sysctl file
1969 * @filp: the file structure
1970 * @buffer: the user buffer
1971 * @lenp: the size of the user buffer
1972 * @ppos: file position
1974 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1975 * values from/to the user buffer, treated as an ASCII string. The values
1976 * are treated as milliseconds, and converted to jiffies when they are stored.
1978 * This routine will ensure the values are within the range specified by
1979 * table->extra1 (min) and table->extra2 (max).
1981 * Returns 0 on success.
1983 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1985 void __user *buffer,
1986 size_t *lenp, loff_t *ppos)
1988 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1989 lenp, ppos, HZ, 1000l);
1993 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1995 int write, void *data)
1998 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2004 lval = (unsigned long)-val;
2007 lval = (unsigned long)val;
2014 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2016 int write, void *data)
2019 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2025 lval = (unsigned long)-val;
2028 lval = (unsigned long)val;
2030 *lvalp = jiffies_to_clock_t(lval);
2035 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2037 int write, void *data)
2040 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2046 lval = (unsigned long)-val;
2049 lval = (unsigned long)val;
2051 *lvalp = jiffies_to_msecs(lval);
2057 * proc_dointvec_jiffies - read a vector of integers as seconds
2058 * @table: the sysctl table
2059 * @write: %TRUE if this is a write to the sysctl file
2060 * @filp: the file structure
2061 * @buffer: the user buffer
2062 * @lenp: the size of the user buffer
2063 * @ppos: file position
2065 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2066 * values from/to the user buffer, treated as an ASCII string.
2067 * The values read are assumed to be in seconds, and are converted into
2070 * Returns 0 on success.
2072 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2073 void __user *buffer, size_t *lenp, loff_t *ppos)
2075 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2076 do_proc_dointvec_jiffies_conv,NULL);
2080 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2081 * @table: the sysctl table
2082 * @write: %TRUE if this is a write to the sysctl file
2083 * @filp: the file structure
2084 * @buffer: the user buffer
2085 * @lenp: the size of the user buffer
2086 * @ppos: pointer to the file position
2088 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2089 * values from/to the user buffer, treated as an ASCII string.
2090 * The values read are assumed to be in 1/USER_HZ seconds, and
2091 * are converted into jiffies.
2093 * Returns 0 on success.
2095 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2096 void __user *buffer, size_t *lenp, loff_t *ppos)
2098 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2099 do_proc_dointvec_userhz_jiffies_conv,NULL);
2103 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2104 * @table: the sysctl table
2105 * @write: %TRUE if this is a write to the sysctl file
2106 * @filp: the file structure
2107 * @buffer: the user buffer
2108 * @lenp: the size of the user buffer
2109 * @ppos: file position
2110 * @ppos: the current position in the file
2112 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2113 * values from/to the user buffer, treated as an ASCII string.
2114 * The values read are assumed to be in 1/1000 seconds, and
2115 * are converted into jiffies.
2117 * Returns 0 on success.
2119 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2120 void __user *buffer, size_t *lenp, loff_t *ppos)
2122 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2123 do_proc_dointvec_ms_jiffies_conv, NULL);
2126 #else /* CONFIG_PROC_FS */
2128 int proc_dostring(ctl_table *table, int write, struct file *filp,
2129 void __user *buffer, size_t *lenp, loff_t *ppos)
2134 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2135 void __user *buffer, size_t *lenp, loff_t *ppos)
2140 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2141 void __user *buffer, size_t *lenp, loff_t *ppos)
2146 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2147 void __user *buffer, size_t *lenp, loff_t *ppos)
2152 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2153 void __user *buffer, size_t *lenp, loff_t *ppos)
2158 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2159 void __user *buffer, size_t *lenp, loff_t *ppos)
2164 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2165 void __user *buffer, size_t *lenp, loff_t *ppos)
2170 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2171 void __user *buffer, size_t *lenp, loff_t *ppos)
2176 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2177 void __user *buffer, size_t *lenp, loff_t *ppos)
2182 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2184 void __user *buffer,
2185 size_t *lenp, loff_t *ppos)
2191 #endif /* CONFIG_PROC_FS */
2195 * General sysctl support routines
2198 /* The generic string strategy routine: */
2199 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2200 void __user *oldval, size_t __user *oldlenp,
2201 void __user *newval, size_t newlen, void **context)
2203 if (!table->data || !table->maxlen)
2206 if (oldval && oldlenp) {
2208 if (get_user(bufsize, oldlenp))
2211 size_t len = strlen(table->data), copied;
2213 /* This shouldn't trigger for a well-formed sysctl */
2214 if (len > table->maxlen)
2215 len = table->maxlen;
2217 /* Copy up to a max of bufsize-1 bytes of the string */
2218 copied = (len >= bufsize) ? bufsize - 1 : len;
2220 if (copy_to_user(oldval, table->data, copied) ||
2221 put_user(0, (char __user *)(oldval + copied)))
2223 if (put_user(len, oldlenp))
2227 if (newval && newlen) {
2228 size_t len = newlen;
2229 if (len > table->maxlen)
2230 len = table->maxlen;
2231 if(copy_from_user(table->data, newval, len))
2233 if (len == table->maxlen)
2235 ((char *) table->data)[len] = 0;
2241 * This function makes sure that all of the integers in the vector
2242 * are between the minimum and maximum values given in the arrays
2243 * table->extra1 and table->extra2, respectively.
2245 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2246 void __user *oldval, size_t __user *oldlenp,
2247 void __user *newval, size_t newlen, void **context)
2250 if (newval && newlen) {
2251 int __user *vec = (int __user *) newval;
2252 int *min = (int *) table->extra1;
2253 int *max = (int *) table->extra2;
2257 if (newlen % sizeof(int) != 0)
2260 if (!table->extra1 && !table->extra2)
2263 if (newlen > table->maxlen)
2264 newlen = table->maxlen;
2265 length = newlen / sizeof(int);
2267 for (i = 0; i < length; i++) {
2269 if (get_user(value, vec + i))
2271 if (min && value < min[i])
2273 if (max && value > max[i])
2280 /* Strategy function to convert jiffies to seconds */
2281 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2282 void __user *oldval, size_t __user *oldlenp,
2283 void __user *newval, size_t newlen, void **context)
2288 if (get_user(olen, oldlenp))
2290 if (olen!=sizeof(int))
2293 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2294 (oldlenp && put_user(sizeof(int),oldlenp)))
2297 if (newval && newlen) {
2299 if (newlen != sizeof(int))
2301 if (get_user(new, (int __user *)newval))
2303 *(int *)(table->data) = new*HZ;
2308 /* Strategy function to convert jiffies to seconds */
2309 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2310 void __user *oldval, size_t __user *oldlenp,
2311 void __user *newval, size_t newlen, void **context)
2316 if (get_user(olen, oldlenp))
2318 if (olen!=sizeof(int))
2321 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2322 (oldlenp && put_user(sizeof(int),oldlenp)))
2325 if (newval && newlen) {
2327 if (newlen != sizeof(int))
2329 if (get_user(new, (int __user *)newval))
2331 *(int *)(table->data) = msecs_to_jiffies(new);
2336 #else /* CONFIG_SYSCTL */
2339 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2344 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2345 void __user *oldval, size_t __user *oldlenp,
2346 void __user *newval, size_t newlen, void **context)
2351 int sysctl_intvec(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 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2359 void __user *oldval, size_t __user *oldlenp,
2360 void __user *newval, size_t newlen, void **context)
2365 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2366 void __user *oldval, size_t __user *oldlenp,
2367 void __user *newval, size_t newlen, void **context)
2372 int proc_dostring(ctl_table *table, int write, struct file *filp,
2373 void __user *buffer, size_t *lenp, loff_t *ppos)
2378 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2379 void __user *buffer, size_t *lenp, loff_t *ppos)
2384 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2385 void __user *buffer, size_t *lenp, loff_t *ppos)
2390 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2391 void __user *buffer, size_t *lenp, loff_t *ppos)
2396 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2397 void __user *buffer, size_t *lenp, loff_t *ppos)
2402 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2403 void __user *buffer, size_t *lenp, loff_t *ppos)
2408 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2409 void __user *buffer, size_t *lenp, loff_t *ppos)
2414 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2415 void __user *buffer, size_t *lenp, loff_t *ppos)
2420 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2422 void __user *buffer,
2423 size_t *lenp, loff_t *ppos)
2428 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2434 void unregister_sysctl_table(struct ctl_table_header * table)
2438 #endif /* CONFIG_SYSCTL */
2441 * No sense putting this after each symbol definition, twice,
2442 * exception granted :-)
2444 EXPORT_SYMBOL(proc_dointvec);
2445 EXPORT_SYMBOL(proc_dointvec_jiffies);
2446 EXPORT_SYMBOL(proc_dointvec_minmax);
2447 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2448 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2449 EXPORT_SYMBOL(proc_dostring);
2450 EXPORT_SYMBOL(proc_doulongvec_minmax);
2451 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2452 EXPORT_SYMBOL(register_sysctl_table);
2453 EXPORT_SYMBOL(sysctl_intvec);
2454 EXPORT_SYMBOL(sysctl_jiffies);
2455 EXPORT_SYMBOL(sysctl_ms_jiffies);
2456 EXPORT_SYMBOL(sysctl_string);
2457 EXPORT_SYMBOL(unregister_sysctl_table);