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/sysrq.h>
35 #include <linux/highuid.h>
36 #include <linux/writeback.h>
37 #include <linux/hugetlb.h>
38 #include <linux/security.h>
39 #include <linux/initrd.h>
40 #include <linux/times.h>
41 #include <linux/limits.h>
42 #include <linux/dcache.h>
43 #include <linux/syscalls.h>
45 #include <asm/uaccess.h>
46 #include <asm/processor.h>
48 #ifdef CONFIG_ROOT_NFS
49 #include <linux/nfs_fs.h>
52 #if defined(CONFIG_SYSCTL)
54 /* External variables not in a header file. */
56 extern int sysctl_overcommit_memory;
57 extern int sysctl_overcommit_ratio;
58 extern int max_threads;
59 extern int sysrq_enabled;
60 extern int core_uses_pid;
61 extern int suid_dumpable;
62 extern char core_pattern[];
65 extern int min_free_kbytes;
66 extern int printk_ratelimit_jiffies;
67 extern int printk_ratelimit_burst;
68 extern int pid_max_min, pid_max_max;
70 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
71 int unknown_nmi_panic;
72 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
73 void __user *, size_t *, loff_t *);
76 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
77 static int maxolduid = 65535;
80 static int ngroups_max = NGROUPS_MAX;
83 extern char modprobe_path[];
86 extern char hotplug_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;
112 #ifdef CONFIG_ARCH_S390
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[];
140 extern ctl_table net_table[];
142 static ctl_table proc_table[];
143 static ctl_table fs_table[];
144 static ctl_table debug_table[];
145 static ctl_table dev_table[];
146 extern ctl_table random_table[];
147 #ifdef CONFIG_UNIX98_PTYS
148 extern ctl_table pty_table[];
150 #ifdef CONFIG_INOTIFY
151 extern ctl_table inotify_table[];
154 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
155 int sysctl_legacy_va_layout;
158 /* /proc declarations: */
160 #ifdef CONFIG_PROC_FS
162 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
163 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
164 static int proc_opensys(struct inode *, struct file *);
166 struct file_operations proc_sys_file_operations = {
167 .open = proc_opensys,
168 .read = proc_readsys,
169 .write = proc_writesys,
172 extern struct proc_dir_entry *proc_sys_root;
174 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
175 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
178 /* The default sysctl tables: */
180 static ctl_table root_table[] = {
182 .ctl_name = CTL_KERN,
183 .procname = "kernel",
202 .ctl_name = CTL_PROC,
214 .ctl_name = CTL_DEBUG,
217 .child = debug_table,
229 static ctl_table kern_table[] = {
231 .ctl_name = KERN_OSTYPE,
232 .procname = "ostype",
233 .data = system_utsname.sysname,
234 .maxlen = sizeof(system_utsname.sysname),
236 .proc_handler = &proc_doutsstring,
237 .strategy = &sysctl_string,
240 .ctl_name = KERN_OSRELEASE,
241 .procname = "osrelease",
242 .data = system_utsname.release,
243 .maxlen = sizeof(system_utsname.release),
245 .proc_handler = &proc_doutsstring,
246 .strategy = &sysctl_string,
249 .ctl_name = KERN_VERSION,
250 .procname = "version",
251 .data = system_utsname.version,
252 .maxlen = sizeof(system_utsname.version),
254 .proc_handler = &proc_doutsstring,
255 .strategy = &sysctl_string,
258 .ctl_name = KERN_NODENAME,
259 .procname = "hostname",
260 .data = system_utsname.nodename,
261 .maxlen = sizeof(system_utsname.nodename),
263 .proc_handler = &proc_doutsstring,
264 .strategy = &sysctl_string,
267 .ctl_name = KERN_DOMAINNAME,
268 .procname = "domainname",
269 .data = system_utsname.domainname,
270 .maxlen = sizeof(system_utsname.domainname),
272 .proc_handler = &proc_doutsstring,
273 .strategy = &sysctl_string,
276 .ctl_name = KERN_PANIC,
278 .data = &panic_timeout,
279 .maxlen = sizeof(int),
281 .proc_handler = &proc_dointvec,
284 .ctl_name = KERN_CORE_USES_PID,
285 .procname = "core_uses_pid",
286 .data = &core_uses_pid,
287 .maxlen = sizeof(int),
289 .proc_handler = &proc_dointvec,
292 .ctl_name = KERN_CORE_PATTERN,
293 .procname = "core_pattern",
294 .data = core_pattern,
297 .proc_handler = &proc_dostring,
298 .strategy = &sysctl_string,
301 .ctl_name = KERN_TAINTED,
302 .procname = "tainted",
304 .maxlen = sizeof(int),
306 .proc_handler = &proc_dointvec,
309 .ctl_name = KERN_CAP_BSET,
310 .procname = "cap-bound",
312 .maxlen = sizeof(kernel_cap_t),
314 .proc_handler = &proc_dointvec_bset,
316 #ifdef CONFIG_BLK_DEV_INITRD
318 .ctl_name = KERN_REALROOTDEV,
319 .procname = "real-root-dev",
320 .data = &real_root_dev,
321 .maxlen = sizeof(int),
323 .proc_handler = &proc_dointvec,
328 .ctl_name = KERN_SPARC_REBOOT,
329 .procname = "reboot-cmd",
330 .data = reboot_command,
333 .proc_handler = &proc_dostring,
334 .strategy = &sysctl_string,
337 .ctl_name = KERN_SPARC_STOP_A,
338 .procname = "stop-a",
339 .data = &stop_a_enabled,
340 .maxlen = sizeof (int),
342 .proc_handler = &proc_dointvec,
345 .ctl_name = KERN_SPARC_SCONS_PWROFF,
346 .procname = "scons-poweroff",
347 .data = &scons_pwroff,
348 .maxlen = sizeof (int),
350 .proc_handler = &proc_dointvec,
355 .ctl_name = KERN_HPPA_PWRSW,
356 .procname = "soft-power",
357 .data = &pwrsw_enabled,
358 .maxlen = sizeof (int),
360 .proc_handler = &proc_dointvec,
363 .ctl_name = KERN_HPPA_UNALIGNED,
364 .procname = "unaligned-trap",
365 .data = &unaligned_enabled,
366 .maxlen = sizeof (int),
368 .proc_handler = &proc_dointvec,
372 .ctl_name = KERN_CTLALTDEL,
373 .procname = "ctrl-alt-del",
375 .maxlen = sizeof(int),
377 .proc_handler = &proc_dointvec,
380 .ctl_name = KERN_PRINTK,
381 .procname = "printk",
382 .data = &console_loglevel,
383 .maxlen = 4*sizeof(int),
385 .proc_handler = &proc_dointvec,
389 .ctl_name = KERN_MODPROBE,
390 .procname = "modprobe",
391 .data = &modprobe_path,
392 .maxlen = KMOD_PATH_LEN,
394 .proc_handler = &proc_dostring,
395 .strategy = &sysctl_string,
398 #ifdef CONFIG_HOTPLUG
400 .ctl_name = KERN_HOTPLUG,
401 .procname = "hotplug",
402 .data = &hotplug_path,
403 .maxlen = HOTPLUG_PATH_LEN,
405 .proc_handler = &proc_dostring,
406 .strategy = &sysctl_string,
409 #ifdef CONFIG_CHR_DEV_SG
411 .ctl_name = KERN_SG_BIG_BUFF,
412 .procname = "sg-big-buff",
413 .data = &sg_big_buff,
414 .maxlen = sizeof (int),
416 .proc_handler = &proc_dointvec,
419 #ifdef CONFIG_BSD_PROCESS_ACCT
421 .ctl_name = KERN_ACCT,
424 .maxlen = 3*sizeof(int),
426 .proc_handler = &proc_dointvec,
429 #ifdef CONFIG_SYSVIPC
431 .ctl_name = KERN_SHMMAX,
432 .procname = "shmmax",
434 .maxlen = sizeof (size_t),
436 .proc_handler = &proc_doulongvec_minmax,
439 .ctl_name = KERN_SHMALL,
440 .procname = "shmall",
442 .maxlen = sizeof (size_t),
444 .proc_handler = &proc_doulongvec_minmax,
447 .ctl_name = KERN_SHMMNI,
448 .procname = "shmmni",
450 .maxlen = sizeof (int),
452 .proc_handler = &proc_dointvec,
455 .ctl_name = KERN_MSGMAX,
456 .procname = "msgmax",
458 .maxlen = sizeof (int),
460 .proc_handler = &proc_dointvec,
463 .ctl_name = KERN_MSGMNI,
464 .procname = "msgmni",
466 .maxlen = sizeof (int),
468 .proc_handler = &proc_dointvec,
471 .ctl_name = KERN_MSGMNB,
472 .procname = "msgmnb",
474 .maxlen = sizeof (int),
476 .proc_handler = &proc_dointvec,
479 .ctl_name = KERN_SEM,
482 .maxlen = 4*sizeof (int),
484 .proc_handler = &proc_dointvec,
487 #ifdef CONFIG_MAGIC_SYSRQ
489 .ctl_name = KERN_SYSRQ,
491 .data = &sysrq_enabled,
492 .maxlen = sizeof (int),
494 .proc_handler = &proc_dointvec,
498 .ctl_name = KERN_CADPID,
499 .procname = "cad_pid",
501 .maxlen = sizeof (int),
503 .proc_handler = &proc_dointvec,
506 .ctl_name = KERN_MAX_THREADS,
507 .procname = "threads-max",
508 .data = &max_threads,
509 .maxlen = sizeof(int),
511 .proc_handler = &proc_dointvec,
514 .ctl_name = KERN_RANDOM,
515 .procname = "random",
517 .child = random_table,
519 #ifdef CONFIG_UNIX98_PTYS
521 .ctl_name = KERN_PTY,
528 .ctl_name = KERN_OVERFLOWUID,
529 .procname = "overflowuid",
530 .data = &overflowuid,
531 .maxlen = sizeof(int),
533 .proc_handler = &proc_dointvec_minmax,
534 .strategy = &sysctl_intvec,
535 .extra1 = &minolduid,
536 .extra2 = &maxolduid,
539 .ctl_name = KERN_OVERFLOWGID,
540 .procname = "overflowgid",
541 .data = &overflowgid,
542 .maxlen = sizeof(int),
544 .proc_handler = &proc_dointvec_minmax,
545 .strategy = &sysctl_intvec,
546 .extra1 = &minolduid,
547 .extra2 = &maxolduid,
549 #ifdef CONFIG_ARCH_S390
550 #ifdef CONFIG_MATHEMU
552 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
553 .procname = "ieee_emulation_warnings",
554 .data = &sysctl_ieee_emulation_warnings,
555 .maxlen = sizeof(int),
557 .proc_handler = &proc_dointvec,
560 #ifdef CONFIG_NO_IDLE_HZ
562 .ctl_name = KERN_HZ_TIMER,
563 .procname = "hz_timer",
564 .data = &sysctl_hz_timer,
565 .maxlen = sizeof(int),
567 .proc_handler = &proc_dointvec,
571 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
572 .procname = "userprocess_debug",
573 .data = &sysctl_userprocess_debug,
574 .maxlen = sizeof(int),
576 .proc_handler = &proc_dointvec,
580 .ctl_name = KERN_PIDMAX,
581 .procname = "pid_max",
583 .maxlen = sizeof (int),
585 .proc_handler = &proc_dointvec_minmax,
586 .strategy = sysctl_intvec,
587 .extra1 = &pid_max_min,
588 .extra2 = &pid_max_max,
591 .ctl_name = KERN_PANIC_ON_OOPS,
592 .procname = "panic_on_oops",
593 .data = &panic_on_oops,
594 .maxlen = sizeof(int),
596 .proc_handler = &proc_dointvec,
599 .ctl_name = KERN_PRINTK_RATELIMIT,
600 .procname = "printk_ratelimit",
601 .data = &printk_ratelimit_jiffies,
602 .maxlen = sizeof(int),
604 .proc_handler = &proc_dointvec_jiffies,
605 .strategy = &sysctl_jiffies,
608 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
609 .procname = "printk_ratelimit_burst",
610 .data = &printk_ratelimit_burst,
611 .maxlen = sizeof(int),
613 .proc_handler = &proc_dointvec,
616 .ctl_name = KERN_NGROUPS_MAX,
617 .procname = "ngroups_max",
618 .data = &ngroups_max,
619 .maxlen = sizeof (int),
621 .proc_handler = &proc_dointvec,
623 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
625 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
626 .procname = "unknown_nmi_panic",
627 .data = &unknown_nmi_panic,
628 .maxlen = sizeof (int),
630 .proc_handler = &proc_unknown_nmi_panic,
633 #if defined(CONFIG_X86)
635 .ctl_name = KERN_BOOTLOADER_TYPE,
636 .procname = "bootloader_type",
637 .data = &bootloader_type,
638 .maxlen = sizeof (int),
640 .proc_handler = &proc_dointvec,
644 .ctl_name = KERN_RANDOMIZE,
645 .procname = "randomize_va_space",
646 .data = &randomize_va_space,
647 .maxlen = sizeof(int),
649 .proc_handler = &proc_dointvec,
651 #if defined(CONFIG_ARCH_S390)
653 .ctl_name = KERN_SPIN_RETRY,
654 .procname = "spin_retry",
656 .maxlen = sizeof (int),
658 .proc_handler = &proc_dointvec,
664 /* Constants for minimum and maximum testing in vm_table.
665 We use these as one-element integer vectors. */
667 static int one_hundred = 100;
670 static ctl_table vm_table[] = {
672 .ctl_name = VM_OVERCOMMIT_MEMORY,
673 .procname = "overcommit_memory",
674 .data = &sysctl_overcommit_memory,
675 .maxlen = sizeof(sysctl_overcommit_memory),
677 .proc_handler = &proc_dointvec,
680 .ctl_name = VM_OVERCOMMIT_RATIO,
681 .procname = "overcommit_ratio",
682 .data = &sysctl_overcommit_ratio,
683 .maxlen = sizeof(sysctl_overcommit_ratio),
685 .proc_handler = &proc_dointvec,
688 .ctl_name = VM_PAGE_CLUSTER,
689 .procname = "page-cluster",
690 .data = &page_cluster,
691 .maxlen = sizeof(int),
693 .proc_handler = &proc_dointvec,
696 .ctl_name = VM_DIRTY_BACKGROUND,
697 .procname = "dirty_background_ratio",
698 .data = &dirty_background_ratio,
699 .maxlen = sizeof(dirty_background_ratio),
701 .proc_handler = &proc_dointvec_minmax,
702 .strategy = &sysctl_intvec,
704 .extra2 = &one_hundred,
707 .ctl_name = VM_DIRTY_RATIO,
708 .procname = "dirty_ratio",
709 .data = &vm_dirty_ratio,
710 .maxlen = sizeof(vm_dirty_ratio),
712 .proc_handler = &proc_dointvec_minmax,
713 .strategy = &sysctl_intvec,
715 .extra2 = &one_hundred,
718 .ctl_name = VM_DIRTY_WB_CS,
719 .procname = "dirty_writeback_centisecs",
720 .data = &dirty_writeback_centisecs,
721 .maxlen = sizeof(dirty_writeback_centisecs),
723 .proc_handler = &dirty_writeback_centisecs_handler,
726 .ctl_name = VM_DIRTY_EXPIRE_CS,
727 .procname = "dirty_expire_centisecs",
728 .data = &dirty_expire_centisecs,
729 .maxlen = sizeof(dirty_expire_centisecs),
731 .proc_handler = &proc_dointvec,
734 .ctl_name = VM_NR_PDFLUSH_THREADS,
735 .procname = "nr_pdflush_threads",
736 .data = &nr_pdflush_threads,
737 .maxlen = sizeof nr_pdflush_threads,
738 .mode = 0444 /* read-only*/,
739 .proc_handler = &proc_dointvec,
742 .ctl_name = VM_SWAPPINESS,
743 .procname = "swappiness",
744 .data = &vm_swappiness,
745 .maxlen = sizeof(vm_swappiness),
747 .proc_handler = &proc_dointvec_minmax,
748 .strategy = &sysctl_intvec,
750 .extra2 = &one_hundred,
752 #ifdef CONFIG_HUGETLB_PAGE
754 .ctl_name = VM_HUGETLB_PAGES,
755 .procname = "nr_hugepages",
756 .data = &max_huge_pages,
757 .maxlen = sizeof(unsigned long),
759 .proc_handler = &hugetlb_sysctl_handler,
760 .extra1 = (void *)&hugetlb_zero,
761 .extra2 = (void *)&hugetlb_infinity,
764 .ctl_name = VM_HUGETLB_GROUP,
765 .procname = "hugetlb_shm_group",
766 .data = &sysctl_hugetlb_shm_group,
767 .maxlen = sizeof(gid_t),
769 .proc_handler = &proc_dointvec,
773 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
774 .procname = "lowmem_reserve_ratio",
775 .data = &sysctl_lowmem_reserve_ratio,
776 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
778 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
779 .strategy = &sysctl_intvec,
782 .ctl_name = VM_MIN_FREE_KBYTES,
783 .procname = "min_free_kbytes",
784 .data = &min_free_kbytes,
785 .maxlen = sizeof(min_free_kbytes),
787 .proc_handler = &min_free_kbytes_sysctl_handler,
788 .strategy = &sysctl_intvec,
793 .ctl_name = VM_MAX_MAP_COUNT,
794 .procname = "max_map_count",
795 .data = &sysctl_max_map_count,
796 .maxlen = sizeof(sysctl_max_map_count),
798 .proc_handler = &proc_dointvec
802 .ctl_name = VM_LAPTOP_MODE,
803 .procname = "laptop_mode",
804 .data = &laptop_mode,
805 .maxlen = sizeof(laptop_mode),
807 .proc_handler = &proc_dointvec,
808 .strategy = &sysctl_intvec,
812 .ctl_name = VM_BLOCK_DUMP,
813 .procname = "block_dump",
815 .maxlen = sizeof(block_dump),
817 .proc_handler = &proc_dointvec,
818 .strategy = &sysctl_intvec,
822 .ctl_name = VM_VFS_CACHE_PRESSURE,
823 .procname = "vfs_cache_pressure",
824 .data = &sysctl_vfs_cache_pressure,
825 .maxlen = sizeof(sysctl_vfs_cache_pressure),
827 .proc_handler = &proc_dointvec,
828 .strategy = &sysctl_intvec,
831 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
833 .ctl_name = VM_LEGACY_VA_LAYOUT,
834 .procname = "legacy_va_layout",
835 .data = &sysctl_legacy_va_layout,
836 .maxlen = sizeof(sysctl_legacy_va_layout),
838 .proc_handler = &proc_dointvec,
839 .strategy = &sysctl_intvec,
845 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
846 .procname = "swap_token_timeout",
847 .data = &swap_token_default_timeout,
848 .maxlen = sizeof(swap_token_default_timeout),
850 .proc_handler = &proc_dointvec_jiffies,
851 .strategy = &sysctl_jiffies,
857 static ctl_table proc_table[] = {
861 static ctl_table fs_table[] = {
863 .ctl_name = FS_NRINODE,
864 .procname = "inode-nr",
865 .data = &inodes_stat,
866 .maxlen = 2*sizeof(int),
868 .proc_handler = &proc_dointvec,
871 .ctl_name = FS_STATINODE,
872 .procname = "inode-state",
873 .data = &inodes_stat,
874 .maxlen = 7*sizeof(int),
876 .proc_handler = &proc_dointvec,
879 .ctl_name = FS_NRFILE,
880 .procname = "file-nr",
882 .maxlen = 3*sizeof(int),
884 .proc_handler = &proc_dointvec,
887 .ctl_name = FS_MAXFILE,
888 .procname = "file-max",
889 .data = &files_stat.max_files,
890 .maxlen = sizeof(int),
892 .proc_handler = &proc_dointvec,
895 .ctl_name = FS_DENTRY,
896 .procname = "dentry-state",
897 .data = &dentry_stat,
898 .maxlen = 6*sizeof(int),
900 .proc_handler = &proc_dointvec,
903 .ctl_name = FS_OVERFLOWUID,
904 .procname = "overflowuid",
905 .data = &fs_overflowuid,
906 .maxlen = sizeof(int),
908 .proc_handler = &proc_dointvec_minmax,
909 .strategy = &sysctl_intvec,
910 .extra1 = &minolduid,
911 .extra2 = &maxolduid,
914 .ctl_name = FS_OVERFLOWGID,
915 .procname = "overflowgid",
916 .data = &fs_overflowgid,
917 .maxlen = sizeof(int),
919 .proc_handler = &proc_dointvec_minmax,
920 .strategy = &sysctl_intvec,
921 .extra1 = &minolduid,
922 .extra2 = &maxolduid,
925 .ctl_name = FS_LEASES,
926 .procname = "leases-enable",
927 .data = &leases_enable,
928 .maxlen = sizeof(int),
930 .proc_handler = &proc_dointvec,
932 #ifdef CONFIG_DNOTIFY
934 .ctl_name = FS_DIR_NOTIFY,
935 .procname = "dir-notify-enable",
936 .data = &dir_notify_enable,
937 .maxlen = sizeof(int),
939 .proc_handler = &proc_dointvec,
944 .ctl_name = FS_LEASE_TIME,
945 .procname = "lease-break-time",
946 .data = &lease_break_time,
947 .maxlen = sizeof(int),
949 .proc_handler = &proc_dointvec,
952 .ctl_name = FS_AIO_NR,
953 .procname = "aio-nr",
955 .maxlen = sizeof(aio_nr),
957 .proc_handler = &proc_dointvec,
960 .ctl_name = FS_AIO_MAX_NR,
961 .procname = "aio-max-nr",
963 .maxlen = sizeof(aio_max_nr),
965 .proc_handler = &proc_dointvec,
967 #ifdef CONFIG_INOTIFY
969 .ctl_name = FS_INOTIFY,
970 .procname = "inotify",
972 .child = inotify_table,
977 .ctl_name = KERN_SETUID_DUMPABLE,
978 .procname = "suid_dumpable",
979 .data = &suid_dumpable,
980 .maxlen = sizeof(int),
982 .proc_handler = &proc_dointvec,
987 static ctl_table debug_table[] = {
991 static ctl_table dev_table[] = {
995 extern void init_irq_proc (void);
997 static DEFINE_SPINLOCK(sysctl_lock);
999 /* called under sysctl_lock */
1000 static int use_table(struct ctl_table_header *p)
1002 if (unlikely(p->unregistering))
1008 /* called under sysctl_lock */
1009 static void unuse_table(struct ctl_table_header *p)
1012 if (unlikely(p->unregistering))
1013 complete(p->unregistering);
1016 /* called under sysctl_lock, will reacquire if has to wait */
1017 static void start_unregistering(struct ctl_table_header *p)
1020 * if p->used is 0, nobody will ever touch that entry again;
1021 * we'll eliminate all paths to it before dropping sysctl_lock
1023 if (unlikely(p->used)) {
1024 struct completion wait;
1025 init_completion(&wait);
1026 p->unregistering = &wait;
1027 spin_unlock(&sysctl_lock);
1028 wait_for_completion(&wait);
1029 spin_lock(&sysctl_lock);
1032 * do not remove from the list until nobody holds it; walking the
1033 * list in do_sysctl() relies on that.
1035 list_del_init(&p->ctl_entry);
1038 void __init sysctl_init(void)
1040 #ifdef CONFIG_PROC_FS
1041 register_proc_table(root_table, proc_sys_root, &root_table_header);
1046 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1047 void __user *newval, size_t newlen)
1049 struct list_head *tmp;
1050 int error = -ENOTDIR;
1052 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1056 if (!oldlenp || get_user(old_len, oldlenp))
1059 spin_lock(&sysctl_lock);
1060 tmp = &root_table_header.ctl_entry;
1062 struct ctl_table_header *head =
1063 list_entry(tmp, struct ctl_table_header, ctl_entry);
1064 void *context = NULL;
1066 if (!use_table(head))
1069 spin_unlock(&sysctl_lock);
1071 error = parse_table(name, nlen, oldval, oldlenp,
1072 newval, newlen, head->ctl_table,
1076 spin_lock(&sysctl_lock);
1078 if (error != -ENOTDIR)
1080 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1081 spin_unlock(&sysctl_lock);
1085 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1087 struct __sysctl_args tmp;
1090 if (copy_from_user(&tmp, args, sizeof(tmp)))
1094 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1095 tmp.newval, tmp.newlen);
1101 * ctl_perm does NOT grant the superuser all rights automatically, because
1102 * some sysctl variables are readonly even to root.
1105 static int test_perm(int mode, int op)
1109 else if (in_egroup_p(0))
1111 if ((mode & op & 0007) == op)
1116 static inline int ctl_perm(ctl_table *table, int op)
1119 error = security_sysctl(table, op);
1122 return test_perm(table->mode, op);
1125 static int parse_table(int __user *name, int nlen,
1126 void __user *oldval, size_t __user *oldlenp,
1127 void __user *newval, size_t newlen,
1128 ctl_table *table, void **context)
1134 if (get_user(n, name))
1136 for ( ; table->ctl_name; table++) {
1137 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1140 if (ctl_perm(table, 001))
1142 if (table->strategy) {
1143 error = table->strategy(
1146 newval, newlen, context);
1152 table = table->child;
1155 error = do_sysctl_strategy(table, name, nlen,
1157 newval, newlen, context);
1164 /* Perform the actual read/write of a sysctl table entry. */
1165 int do_sysctl_strategy (ctl_table *table,
1166 int __user *name, int nlen,
1167 void __user *oldval, size_t __user *oldlenp,
1168 void __user *newval, size_t newlen, void **context)
1177 if (ctl_perm(table, op))
1180 if (table->strategy) {
1181 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1182 newval, newlen, context);
1189 /* If there is no strategy routine, or if the strategy returns
1190 * zero, proceed with automatic r/w */
1191 if (table->data && table->maxlen) {
1192 if (oldval && oldlenp) {
1193 if (get_user(len, oldlenp))
1196 if (len > table->maxlen)
1197 len = table->maxlen;
1198 if(copy_to_user(oldval, table->data, len))
1200 if(put_user(len, oldlenp))
1204 if (newval && newlen) {
1206 if (len > table->maxlen)
1207 len = table->maxlen;
1208 if(copy_from_user(table->data, newval, len))
1216 * register_sysctl_table - register a sysctl hierarchy
1217 * @table: the top-level table structure
1218 * @insert_at_head: whether the entry should be inserted in front or at the end
1220 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1221 * array. An entry with a ctl_name of 0 terminates the table.
1223 * The members of the &ctl_table structure are used as follows:
1225 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1226 * must be unique within that level of sysctl
1228 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1229 * enter a sysctl file
1231 * data - a pointer to data for use by proc_handler
1233 * maxlen - the maximum size in bytes of the data
1235 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1237 * child - a pointer to the child sysctl table if this entry is a directory, or
1240 * proc_handler - the text handler routine (described below)
1242 * strategy - the strategy routine (described below)
1244 * de - for internal use by the sysctl routines
1246 * extra1, extra2 - extra pointers usable by the proc handler routines
1248 * Leaf nodes in the sysctl tree will be represented by a single file
1249 * under /proc; non-leaf nodes will be represented by directories.
1251 * sysctl(2) can automatically manage read and write requests through
1252 * the sysctl table. The data and maxlen fields of the ctl_table
1253 * struct enable minimal validation of the values being written to be
1254 * performed, and the mode field allows minimal authentication.
1256 * More sophisticated management can be enabled by the provision of a
1257 * strategy routine with the table entry. This will be called before
1258 * any automatic read or write of the data is performed.
1260 * The strategy routine may return
1262 * < 0 - Error occurred (error is passed to user process)
1264 * 0 - OK - proceed with automatic read or write.
1266 * > 0 - OK - read or write has been done by the strategy routine, so
1267 * return immediately.
1269 * There must be a proc_handler routine for any terminal nodes
1270 * mirrored under /proc/sys (non-terminals are handled by a built-in
1271 * directory handler). Several default handlers are available to
1272 * cover common cases -
1274 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1275 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1276 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1278 * It is the handler's job to read the input buffer from user memory
1279 * and process it. The handler should return 0 on success.
1281 * This routine returns %NULL on a failure to register, and a pointer
1282 * to the table header on success.
1284 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1287 struct ctl_table_header *tmp;
1288 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1291 tmp->ctl_table = table;
1292 INIT_LIST_HEAD(&tmp->ctl_entry);
1294 tmp->unregistering = NULL;
1295 spin_lock(&sysctl_lock);
1297 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1299 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1300 spin_unlock(&sysctl_lock);
1301 #ifdef CONFIG_PROC_FS
1302 register_proc_table(table, proc_sys_root, tmp);
1308 * unregister_sysctl_table - unregister a sysctl table hierarchy
1309 * @header: the header returned from register_sysctl_table
1311 * Unregisters the sysctl table and all children. proc entries may not
1312 * actually be removed until they are no longer used by anyone.
1314 void unregister_sysctl_table(struct ctl_table_header * header)
1317 spin_lock(&sysctl_lock);
1318 start_unregistering(header);
1319 #ifdef CONFIG_PROC_FS
1320 unregister_proc_table(header->ctl_table, proc_sys_root);
1322 spin_unlock(&sysctl_lock);
1330 #ifdef CONFIG_PROC_FS
1332 /* Scan the sysctl entries in table and add them all into /proc */
1333 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1335 struct proc_dir_entry *de;
1339 for (; table->ctl_name; table++) {
1340 /* Can't do anything without a proc name. */
1341 if (!table->procname)
1343 /* Maybe we can't do anything with it... */
1344 if (!table->proc_handler && !table->child) {
1345 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1350 len = strlen(table->procname);
1354 if (table->proc_handler)
1358 for (de = root->subdir; de; de = de->next) {
1359 if (proc_match(len, table->procname, de))
1362 /* If the subdir exists already, de is non-NULL */
1366 de = create_proc_entry(table->procname, mode, root);
1370 de->data = (void *) table;
1371 if (table->proc_handler)
1372 de->proc_fops = &proc_sys_file_operations;
1375 if (de->mode & S_IFDIR)
1376 register_proc_table(table->child, de, set);
1381 * Unregister a /proc sysctl table and any subdirectories.
1383 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1385 struct proc_dir_entry *de;
1386 for (; table->ctl_name; table++) {
1387 if (!(de = table->de))
1389 if (de->mode & S_IFDIR) {
1390 if (!table->child) {
1391 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1394 unregister_proc_table(table->child, de);
1396 /* Don't unregister directories which still have entries.. */
1402 * In any case, mark the entry as goner; we'll keep it
1403 * around if it's busy, but we'll know to do nothing with
1404 * its fields. We are under sysctl_lock here.
1408 /* Don't unregister proc entries that are still being used.. */
1409 if (atomic_read(&de->count))
1413 remove_proc_entry(table->procname, root);
1417 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1418 size_t count, loff_t *ppos)
1421 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1422 struct ctl_table *table;
1424 ssize_t error = -ENOTDIR;
1426 spin_lock(&sysctl_lock);
1427 if (de && de->data && use_table(de->set)) {
1429 * at that point we know that sysctl was not unregistered
1430 * and won't be until we finish
1432 spin_unlock(&sysctl_lock);
1433 table = (struct ctl_table *) de->data;
1434 if (!table || !table->proc_handler)
1437 op = (write ? 002 : 004);
1438 if (ctl_perm(table, op))
1441 /* careful: calling conventions are nasty here */
1443 error = (*table->proc_handler)(table, write, file,
1448 spin_lock(&sysctl_lock);
1449 unuse_table(de->set);
1451 spin_unlock(&sysctl_lock);
1455 static int proc_opensys(struct inode *inode, struct file *file)
1457 if (file->f_mode & FMODE_WRITE) {
1459 * sysctl entries that are not writable,
1460 * are _NOT_ writable, capabilities or not.
1462 if (!(inode->i_mode & S_IWUSR))
1469 static ssize_t proc_readsys(struct file * file, char __user * buf,
1470 size_t count, loff_t *ppos)
1472 return do_rw_proc(0, file, buf, count, ppos);
1475 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1476 size_t count, loff_t *ppos)
1478 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1482 * proc_dostring - read a string sysctl
1483 * @table: the sysctl table
1484 * @write: %TRUE if this is a write to the sysctl file
1485 * @filp: the file structure
1486 * @buffer: the user buffer
1487 * @lenp: the size of the user buffer
1488 * @ppos: file position
1490 * Reads/writes a string from/to the user buffer. If the kernel
1491 * buffer provided is not large enough to hold the string, the
1492 * string is truncated. The copied string is %NULL-terminated.
1493 * If the string is being read by the user process, it is copied
1494 * and a newline '\n' is added. It is truncated if the buffer is
1497 * Returns 0 on success.
1499 int proc_dostring(ctl_table *table, int write, struct file *filp,
1500 void __user *buffer, size_t *lenp, loff_t *ppos)
1506 if (!table->data || !table->maxlen || !*lenp ||
1507 (*ppos && !write)) {
1515 while (len < *lenp) {
1516 if (get_user(c, p++))
1518 if (c == 0 || c == '\n')
1522 if (len >= table->maxlen)
1523 len = table->maxlen-1;
1524 if(copy_from_user(table->data, buffer, len))
1526 ((char *) table->data)[len] = 0;
1529 len = strlen(table->data);
1530 if (len > table->maxlen)
1531 len = table->maxlen;
1535 if(copy_to_user(buffer, table->data, len))
1538 if(put_user('\n', ((char __user *) buffer) + len))
1549 * Special case of dostring for the UTS structure. This has locks
1550 * to observe. Should this be in kernel/sys.c ????
1553 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1554 void __user *buffer, size_t *lenp, loff_t *ppos)
1559 down_read(&uts_sem);
1560 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1563 down_write(&uts_sem);
1564 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1570 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1572 int write, void *data)
1575 *valp = *negp ? -*lvalp : *lvalp;
1580 *lvalp = (unsigned long)-val;
1583 *lvalp = (unsigned long)val;
1589 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1590 void __user *buffer, size_t *lenp, loff_t *ppos,
1591 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1592 int write, void *data),
1595 #define TMPBUFLEN 21
1596 int *i, vleft, first=1, neg, val;
1600 char buf[TMPBUFLEN], *p;
1601 char __user *s = buffer;
1603 if (!table->data || !table->maxlen || !*lenp ||
1604 (*ppos && !write)) {
1609 i = (int *) table->data;
1610 vleft = table->maxlen / sizeof(*i);
1614 conv = do_proc_dointvec_conv;
1616 for (; left && vleft--; i++, first=0) {
1631 if (len > sizeof(buf) - 1)
1632 len = sizeof(buf) - 1;
1633 if (copy_from_user(buf, s, len))
1637 if (*p == '-' && left > 1) {
1641 if (*p < '0' || *p > '9')
1644 lval = simple_strtoul(p, &p, 0);
1647 if ((len < left) && *p && !isspace(*p))
1654 if (conv(&neg, &lval, i, 1, data))
1661 if (conv(&neg, &lval, i, 0, data))
1664 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1668 if(copy_to_user(s, buf, len))
1675 if (!write && !first && left) {
1676 if(put_user('\n', s))
1683 if (get_user(c, s++))
1699 * proc_dointvec - read a vector of integers
1700 * @table: the sysctl table
1701 * @write: %TRUE if this is a write to the sysctl file
1702 * @filp: the file structure
1703 * @buffer: the user buffer
1704 * @lenp: the size of the user buffer
1705 * @ppos: file position
1707 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1708 * values from/to the user buffer, treated as an ASCII string.
1710 * Returns 0 on success.
1712 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1713 void __user *buffer, size_t *lenp, loff_t *ppos)
1715 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1725 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1727 int write, void *data)
1729 int op = *(int *)data;
1731 int val = *negp ? -*lvalp : *lvalp;
1733 case OP_SET: *valp = val; break;
1734 case OP_AND: *valp &= val; break;
1735 case OP_OR: *valp |= val; break;
1736 case OP_MAX: if(*valp < val)
1739 case OP_MIN: if(*valp > val)
1747 *lvalp = (unsigned long)-val;
1750 *lvalp = (unsigned long)val;
1757 * init may raise the set.
1760 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1761 void __user *buffer, size_t *lenp, loff_t *ppos)
1765 if (!capable(CAP_SYS_MODULE)) {
1769 op = (current->pid == 1) ? OP_SET : OP_AND;
1770 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1771 do_proc_dointvec_bset_conv,&op);
1774 struct do_proc_dointvec_minmax_conv_param {
1779 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1781 int write, void *data)
1783 struct do_proc_dointvec_minmax_conv_param *param = data;
1785 int val = *negp ? -*lvalp : *lvalp;
1786 if ((param->min && *param->min > val) ||
1787 (param->max && *param->max < val))
1794 *lvalp = (unsigned long)-val;
1797 *lvalp = (unsigned long)val;
1804 * proc_dointvec_minmax - read a vector of integers with min/max values
1805 * @table: the sysctl table
1806 * @write: %TRUE if this is a write to the sysctl file
1807 * @filp: the file structure
1808 * @buffer: the user buffer
1809 * @lenp: the size of the user buffer
1810 * @ppos: file position
1812 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1813 * values from/to the user buffer, treated as an ASCII string.
1815 * This routine will ensure the values are within the range specified by
1816 * table->extra1 (min) and table->extra2 (max).
1818 * Returns 0 on success.
1820 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1821 void __user *buffer, size_t *lenp, loff_t *ppos)
1823 struct do_proc_dointvec_minmax_conv_param param = {
1824 .min = (int *) table->extra1,
1825 .max = (int *) table->extra2,
1827 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1828 do_proc_dointvec_minmax_conv, ¶m);
1831 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1833 void __user *buffer,
1834 size_t *lenp, loff_t *ppos,
1835 unsigned long convmul,
1836 unsigned long convdiv)
1838 #define TMPBUFLEN 21
1839 unsigned long *i, *min, *max, val;
1840 int vleft, first=1, neg;
1842 char buf[TMPBUFLEN], *p;
1843 char __user *s = buffer;
1845 if (!table->data || !table->maxlen || !*lenp ||
1846 (*ppos && !write)) {
1851 i = (unsigned long *) table->data;
1852 min = (unsigned long *) table->extra1;
1853 max = (unsigned long *) table->extra2;
1854 vleft = table->maxlen / sizeof(unsigned long);
1857 for (; left && vleft--; i++, min++, max++, first=0) {
1872 if (len > TMPBUFLEN-1)
1874 if (copy_from_user(buf, s, len))
1878 if (*p == '-' && left > 1) {
1882 if (*p < '0' || *p > '9')
1884 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1886 if ((len < left) && *p && !isspace(*p))
1895 if ((min && val < *min) || (max && val > *max))
1902 sprintf(p, "%lu", convdiv * (*i) / convmul);
1906 if(copy_to_user(s, buf, len))
1913 if (!write && !first && left) {
1914 if(put_user('\n', s))
1921 if (get_user(c, s++))
1937 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1938 * @table: the sysctl table
1939 * @write: %TRUE if this is a write to the sysctl file
1940 * @filp: the file structure
1941 * @buffer: the user buffer
1942 * @lenp: the size of the user buffer
1943 * @ppos: file position
1945 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1946 * values from/to the user buffer, treated as an ASCII string.
1948 * This routine will ensure the values are within the range specified by
1949 * table->extra1 (min) and table->extra2 (max).
1951 * Returns 0 on success.
1953 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1954 void __user *buffer, size_t *lenp, loff_t *ppos)
1956 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1960 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1961 * @table: the sysctl table
1962 * @write: %TRUE if this is a write to the sysctl file
1963 * @filp: the file structure
1964 * @buffer: the user buffer
1965 * @lenp: the size of the user buffer
1966 * @ppos: file position
1968 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1969 * values from/to the user buffer, treated as an ASCII string. The values
1970 * are treated as milliseconds, and converted to jiffies when they are stored.
1972 * This routine will ensure the values are within the range specified by
1973 * table->extra1 (min) and table->extra2 (max).
1975 * Returns 0 on success.
1977 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1979 void __user *buffer,
1980 size_t *lenp, loff_t *ppos)
1982 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1983 lenp, ppos, HZ, 1000l);
1987 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1989 int write, void *data)
1992 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1998 lval = (unsigned long)-val;
2001 lval = (unsigned long)val;
2008 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2010 int write, void *data)
2013 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2019 lval = (unsigned long)-val;
2022 lval = (unsigned long)val;
2024 *lvalp = jiffies_to_clock_t(lval);
2029 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2031 int write, void *data)
2034 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2040 lval = (unsigned long)-val;
2043 lval = (unsigned long)val;
2045 *lvalp = jiffies_to_msecs(lval);
2051 * proc_dointvec_jiffies - read a vector of integers as seconds
2052 * @table: the sysctl table
2053 * @write: %TRUE if this is a write to the sysctl file
2054 * @filp: the file structure
2055 * @buffer: the user buffer
2056 * @lenp: the size of the user buffer
2057 * @ppos: file position
2059 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2060 * values from/to the user buffer, treated as an ASCII string.
2061 * The values read are assumed to be in seconds, and are converted into
2064 * Returns 0 on success.
2066 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2067 void __user *buffer, size_t *lenp, loff_t *ppos)
2069 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2070 do_proc_dointvec_jiffies_conv,NULL);
2074 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2075 * @table: the sysctl table
2076 * @write: %TRUE if this is a write to the sysctl file
2077 * @filp: the file structure
2078 * @buffer: the user buffer
2079 * @lenp: the size of the user buffer
2081 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2082 * values from/to the user buffer, treated as an ASCII string.
2083 * The values read are assumed to be in 1/USER_HZ seconds, and
2084 * are converted into jiffies.
2086 * Returns 0 on success.
2088 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2089 void __user *buffer, size_t *lenp, loff_t *ppos)
2091 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2092 do_proc_dointvec_userhz_jiffies_conv,NULL);
2096 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2097 * @table: the sysctl table
2098 * @write: %TRUE if this is a write to the sysctl file
2099 * @filp: the file structure
2100 * @buffer: the user buffer
2101 * @lenp: the size of the user buffer
2102 * @ppos: file position
2103 * @ppos: the current position in the file
2105 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2106 * values from/to the user buffer, treated as an ASCII string.
2107 * The values read are assumed to be in 1/1000 seconds, and
2108 * are converted into jiffies.
2110 * Returns 0 on success.
2112 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2113 void __user *buffer, size_t *lenp, loff_t *ppos)
2115 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2116 do_proc_dointvec_ms_jiffies_conv, NULL);
2119 #else /* CONFIG_PROC_FS */
2121 int proc_dostring(ctl_table *table, int write, struct file *filp,
2122 void __user *buffer, size_t *lenp, loff_t *ppos)
2127 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2128 void __user *buffer, size_t *lenp, loff_t *ppos)
2133 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2134 void __user *buffer, size_t *lenp, loff_t *ppos)
2139 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2140 void __user *buffer, size_t *lenp, loff_t *ppos)
2145 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2146 void __user *buffer, size_t *lenp, loff_t *ppos)
2151 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2152 void __user *buffer, size_t *lenp, loff_t *ppos)
2157 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2158 void __user *buffer, size_t *lenp, loff_t *ppos)
2163 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2164 void __user *buffer, size_t *lenp, loff_t *ppos)
2169 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2170 void __user *buffer, size_t *lenp, loff_t *ppos)
2175 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2177 void __user *buffer,
2178 size_t *lenp, loff_t *ppos)
2184 #endif /* CONFIG_PROC_FS */
2188 * General sysctl support routines
2191 /* The generic string strategy routine: */
2192 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2193 void __user *oldval, size_t __user *oldlenp,
2194 void __user *newval, size_t newlen, void **context)
2198 if (!table->data || !table->maxlen)
2201 if (oldval && oldlenp) {
2202 if (get_user(len, oldlenp))
2205 l = strlen(table->data);
2206 if (len > l) len = l;
2207 if (len >= table->maxlen)
2208 len = table->maxlen;
2209 if(copy_to_user(oldval, table->data, len))
2211 if(put_user(0, ((char __user *) oldval) + len))
2213 if(put_user(len, oldlenp))
2217 if (newval && 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);