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;
119 extern int sysctl_hz_timer;
121 #ifdef CONFIG_BSD_PROCESS_ACCT
122 extern int acct_parm[];
125 int randomize_va_space = 1;
127 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
128 ctl_table *, void **);
129 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
130 void __user *buffer, size_t *lenp, loff_t *ppos);
132 static ctl_table root_table[];
133 static struct ctl_table_header root_table_header =
134 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
136 static ctl_table kern_table[];
137 static ctl_table vm_table[];
139 extern ctl_table net_table[];
141 static ctl_table proc_table[];
142 static ctl_table fs_table[];
143 static ctl_table debug_table[];
144 static ctl_table dev_table[];
145 extern ctl_table random_table[];
146 #ifdef CONFIG_UNIX98_PTYS
147 extern ctl_table pty_table[];
149 #ifdef CONFIG_INOTIFY
150 extern ctl_table inotify_table[];
153 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
154 int sysctl_legacy_va_layout;
157 /* /proc declarations: */
159 #ifdef CONFIG_PROC_FS
161 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
162 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
163 static int proc_opensys(struct inode *, struct file *);
165 struct file_operations proc_sys_file_operations = {
166 .open = proc_opensys,
167 .read = proc_readsys,
168 .write = proc_writesys,
171 extern struct proc_dir_entry *proc_sys_root;
173 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
174 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
177 /* The default sysctl tables: */
179 static ctl_table root_table[] = {
181 .ctl_name = CTL_KERN,
182 .procname = "kernel",
201 .ctl_name = CTL_PROC,
213 .ctl_name = CTL_DEBUG,
216 .child = debug_table,
228 static ctl_table kern_table[] = {
230 .ctl_name = KERN_OSTYPE,
231 .procname = "ostype",
232 .data = system_utsname.sysname,
233 .maxlen = sizeof(system_utsname.sysname),
235 .proc_handler = &proc_doutsstring,
236 .strategy = &sysctl_string,
239 .ctl_name = KERN_OSRELEASE,
240 .procname = "osrelease",
241 .data = system_utsname.release,
242 .maxlen = sizeof(system_utsname.release),
244 .proc_handler = &proc_doutsstring,
245 .strategy = &sysctl_string,
248 .ctl_name = KERN_VERSION,
249 .procname = "version",
250 .data = system_utsname.version,
251 .maxlen = sizeof(system_utsname.version),
253 .proc_handler = &proc_doutsstring,
254 .strategy = &sysctl_string,
257 .ctl_name = KERN_NODENAME,
258 .procname = "hostname",
259 .data = system_utsname.nodename,
260 .maxlen = sizeof(system_utsname.nodename),
262 .proc_handler = &proc_doutsstring,
263 .strategy = &sysctl_string,
266 .ctl_name = KERN_DOMAINNAME,
267 .procname = "domainname",
268 .data = system_utsname.domainname,
269 .maxlen = sizeof(system_utsname.domainname),
271 .proc_handler = &proc_doutsstring,
272 .strategy = &sysctl_string,
275 .ctl_name = KERN_PANIC,
277 .data = &panic_timeout,
278 .maxlen = sizeof(int),
280 .proc_handler = &proc_dointvec,
283 .ctl_name = KERN_CORE_USES_PID,
284 .procname = "core_uses_pid",
285 .data = &core_uses_pid,
286 .maxlen = sizeof(int),
288 .proc_handler = &proc_dointvec,
291 .ctl_name = KERN_CORE_PATTERN,
292 .procname = "core_pattern",
293 .data = core_pattern,
296 .proc_handler = &proc_dostring,
297 .strategy = &sysctl_string,
300 .ctl_name = KERN_TAINTED,
301 .procname = "tainted",
303 .maxlen = sizeof(int),
305 .proc_handler = &proc_dointvec,
308 .ctl_name = KERN_CAP_BSET,
309 .procname = "cap-bound",
311 .maxlen = sizeof(kernel_cap_t),
313 .proc_handler = &proc_dointvec_bset,
315 #ifdef CONFIG_BLK_DEV_INITRD
317 .ctl_name = KERN_REALROOTDEV,
318 .procname = "real-root-dev",
319 .data = &real_root_dev,
320 .maxlen = sizeof(int),
322 .proc_handler = &proc_dointvec,
327 .ctl_name = KERN_SPARC_REBOOT,
328 .procname = "reboot-cmd",
329 .data = reboot_command,
332 .proc_handler = &proc_dostring,
333 .strategy = &sysctl_string,
336 .ctl_name = KERN_SPARC_STOP_A,
337 .procname = "stop-a",
338 .data = &stop_a_enabled,
339 .maxlen = sizeof (int),
341 .proc_handler = &proc_dointvec,
344 .ctl_name = KERN_SPARC_SCONS_PWROFF,
345 .procname = "scons-poweroff",
346 .data = &scons_pwroff,
347 .maxlen = sizeof (int),
349 .proc_handler = &proc_dointvec,
354 .ctl_name = KERN_HPPA_PWRSW,
355 .procname = "soft-power",
356 .data = &pwrsw_enabled,
357 .maxlen = sizeof (int),
359 .proc_handler = &proc_dointvec,
362 .ctl_name = KERN_HPPA_UNALIGNED,
363 .procname = "unaligned-trap",
364 .data = &unaligned_enabled,
365 .maxlen = sizeof (int),
367 .proc_handler = &proc_dointvec,
371 .ctl_name = KERN_CTLALTDEL,
372 .procname = "ctrl-alt-del",
374 .maxlen = sizeof(int),
376 .proc_handler = &proc_dointvec,
379 .ctl_name = KERN_PRINTK,
380 .procname = "printk",
381 .data = &console_loglevel,
382 .maxlen = 4*sizeof(int),
384 .proc_handler = &proc_dointvec,
388 .ctl_name = KERN_MODPROBE,
389 .procname = "modprobe",
390 .data = &modprobe_path,
391 .maxlen = KMOD_PATH_LEN,
393 .proc_handler = &proc_dostring,
394 .strategy = &sysctl_string,
397 #ifdef CONFIG_HOTPLUG
399 .ctl_name = KERN_HOTPLUG,
400 .procname = "hotplug",
401 .data = &hotplug_path,
402 .maxlen = HOTPLUG_PATH_LEN,
404 .proc_handler = &proc_dostring,
405 .strategy = &sysctl_string,
408 #ifdef CONFIG_CHR_DEV_SG
410 .ctl_name = KERN_SG_BIG_BUFF,
411 .procname = "sg-big-buff",
412 .data = &sg_big_buff,
413 .maxlen = sizeof (int),
415 .proc_handler = &proc_dointvec,
418 #ifdef CONFIG_BSD_PROCESS_ACCT
420 .ctl_name = KERN_ACCT,
423 .maxlen = 3*sizeof(int),
425 .proc_handler = &proc_dointvec,
428 #ifdef CONFIG_SYSVIPC
430 .ctl_name = KERN_SHMMAX,
431 .procname = "shmmax",
433 .maxlen = sizeof (size_t),
435 .proc_handler = &proc_doulongvec_minmax,
438 .ctl_name = KERN_SHMALL,
439 .procname = "shmall",
441 .maxlen = sizeof (size_t),
443 .proc_handler = &proc_doulongvec_minmax,
446 .ctl_name = KERN_SHMMNI,
447 .procname = "shmmni",
449 .maxlen = sizeof (int),
451 .proc_handler = &proc_dointvec,
454 .ctl_name = KERN_MSGMAX,
455 .procname = "msgmax",
457 .maxlen = sizeof (int),
459 .proc_handler = &proc_dointvec,
462 .ctl_name = KERN_MSGMNI,
463 .procname = "msgmni",
465 .maxlen = sizeof (int),
467 .proc_handler = &proc_dointvec,
470 .ctl_name = KERN_MSGMNB,
471 .procname = "msgmnb",
473 .maxlen = sizeof (int),
475 .proc_handler = &proc_dointvec,
478 .ctl_name = KERN_SEM,
481 .maxlen = 4*sizeof (int),
483 .proc_handler = &proc_dointvec,
486 #ifdef CONFIG_MAGIC_SYSRQ
488 .ctl_name = KERN_SYSRQ,
490 .data = &sysrq_enabled,
491 .maxlen = sizeof (int),
493 .proc_handler = &proc_dointvec,
497 .ctl_name = KERN_CADPID,
498 .procname = "cad_pid",
500 .maxlen = sizeof (int),
502 .proc_handler = &proc_dointvec,
505 .ctl_name = KERN_MAX_THREADS,
506 .procname = "threads-max",
507 .data = &max_threads,
508 .maxlen = sizeof(int),
510 .proc_handler = &proc_dointvec,
513 .ctl_name = KERN_RANDOM,
514 .procname = "random",
516 .child = random_table,
518 #ifdef CONFIG_UNIX98_PTYS
520 .ctl_name = KERN_PTY,
527 .ctl_name = KERN_OVERFLOWUID,
528 .procname = "overflowuid",
529 .data = &overflowuid,
530 .maxlen = sizeof(int),
532 .proc_handler = &proc_dointvec_minmax,
533 .strategy = &sysctl_intvec,
534 .extra1 = &minolduid,
535 .extra2 = &maxolduid,
538 .ctl_name = KERN_OVERFLOWGID,
539 .procname = "overflowgid",
540 .data = &overflowgid,
541 .maxlen = sizeof(int),
543 .proc_handler = &proc_dointvec_minmax,
544 .strategy = &sysctl_intvec,
545 .extra1 = &minolduid,
546 .extra2 = &maxolduid,
548 #ifdef CONFIG_ARCH_S390
549 #ifdef CONFIG_MATHEMU
551 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
552 .procname = "ieee_emulation_warnings",
553 .data = &sysctl_ieee_emulation_warnings,
554 .maxlen = sizeof(int),
556 .proc_handler = &proc_dointvec,
559 #ifdef CONFIG_NO_IDLE_HZ
561 .ctl_name = KERN_HZ_TIMER,
562 .procname = "hz_timer",
563 .data = &sysctl_hz_timer,
564 .maxlen = sizeof(int),
566 .proc_handler = &proc_dointvec,
570 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
571 .procname = "userprocess_debug",
572 .data = &sysctl_userprocess_debug,
573 .maxlen = sizeof(int),
575 .proc_handler = &proc_dointvec,
579 .ctl_name = KERN_PIDMAX,
580 .procname = "pid_max",
582 .maxlen = sizeof (int),
584 .proc_handler = &proc_dointvec_minmax,
585 .strategy = sysctl_intvec,
586 .extra1 = &pid_max_min,
587 .extra2 = &pid_max_max,
590 .ctl_name = KERN_PANIC_ON_OOPS,
591 .procname = "panic_on_oops",
592 .data = &panic_on_oops,
593 .maxlen = sizeof(int),
595 .proc_handler = &proc_dointvec,
598 .ctl_name = KERN_PRINTK_RATELIMIT,
599 .procname = "printk_ratelimit",
600 .data = &printk_ratelimit_jiffies,
601 .maxlen = sizeof(int),
603 .proc_handler = &proc_dointvec_jiffies,
604 .strategy = &sysctl_jiffies,
607 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
608 .procname = "printk_ratelimit_burst",
609 .data = &printk_ratelimit_burst,
610 .maxlen = sizeof(int),
612 .proc_handler = &proc_dointvec,
615 .ctl_name = KERN_NGROUPS_MAX,
616 .procname = "ngroups_max",
617 .data = &ngroups_max,
618 .maxlen = sizeof (int),
620 .proc_handler = &proc_dointvec,
622 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
624 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
625 .procname = "unknown_nmi_panic",
626 .data = &unknown_nmi_panic,
627 .maxlen = sizeof (int),
629 .proc_handler = &proc_unknown_nmi_panic,
632 #if defined(CONFIG_X86)
634 .ctl_name = KERN_BOOTLOADER_TYPE,
635 .procname = "bootloader_type",
636 .data = &bootloader_type,
637 .maxlen = sizeof (int),
639 .proc_handler = &proc_dointvec,
643 .ctl_name = KERN_RANDOMIZE,
644 .procname = "randomize_va_space",
645 .data = &randomize_va_space,
646 .maxlen = sizeof(int),
648 .proc_handler = &proc_dointvec,
654 /* Constants for minimum and maximum testing in vm_table.
655 We use these as one-element integer vectors. */
657 static int one_hundred = 100;
660 static ctl_table vm_table[] = {
662 .ctl_name = VM_OVERCOMMIT_MEMORY,
663 .procname = "overcommit_memory",
664 .data = &sysctl_overcommit_memory,
665 .maxlen = sizeof(sysctl_overcommit_memory),
667 .proc_handler = &proc_dointvec,
670 .ctl_name = VM_OVERCOMMIT_RATIO,
671 .procname = "overcommit_ratio",
672 .data = &sysctl_overcommit_ratio,
673 .maxlen = sizeof(sysctl_overcommit_ratio),
675 .proc_handler = &proc_dointvec,
678 .ctl_name = VM_PAGE_CLUSTER,
679 .procname = "page-cluster",
680 .data = &page_cluster,
681 .maxlen = sizeof(int),
683 .proc_handler = &proc_dointvec,
686 .ctl_name = VM_DIRTY_BACKGROUND,
687 .procname = "dirty_background_ratio",
688 .data = &dirty_background_ratio,
689 .maxlen = sizeof(dirty_background_ratio),
691 .proc_handler = &proc_dointvec_minmax,
692 .strategy = &sysctl_intvec,
694 .extra2 = &one_hundred,
697 .ctl_name = VM_DIRTY_RATIO,
698 .procname = "dirty_ratio",
699 .data = &vm_dirty_ratio,
700 .maxlen = sizeof(vm_dirty_ratio),
702 .proc_handler = &proc_dointvec_minmax,
703 .strategy = &sysctl_intvec,
705 .extra2 = &one_hundred,
708 .ctl_name = VM_DIRTY_WB_CS,
709 .procname = "dirty_writeback_centisecs",
710 .data = &dirty_writeback_centisecs,
711 .maxlen = sizeof(dirty_writeback_centisecs),
713 .proc_handler = &dirty_writeback_centisecs_handler,
716 .ctl_name = VM_DIRTY_EXPIRE_CS,
717 .procname = "dirty_expire_centisecs",
718 .data = &dirty_expire_centisecs,
719 .maxlen = sizeof(dirty_expire_centisecs),
721 .proc_handler = &proc_dointvec,
724 .ctl_name = VM_NR_PDFLUSH_THREADS,
725 .procname = "nr_pdflush_threads",
726 .data = &nr_pdflush_threads,
727 .maxlen = sizeof nr_pdflush_threads,
728 .mode = 0444 /* read-only*/,
729 .proc_handler = &proc_dointvec,
732 .ctl_name = VM_SWAPPINESS,
733 .procname = "swappiness",
734 .data = &vm_swappiness,
735 .maxlen = sizeof(vm_swappiness),
737 .proc_handler = &proc_dointvec_minmax,
738 .strategy = &sysctl_intvec,
740 .extra2 = &one_hundred,
742 #ifdef CONFIG_HUGETLB_PAGE
744 .ctl_name = VM_HUGETLB_PAGES,
745 .procname = "nr_hugepages",
746 .data = &max_huge_pages,
747 .maxlen = sizeof(unsigned long),
749 .proc_handler = &hugetlb_sysctl_handler,
750 .extra1 = (void *)&hugetlb_zero,
751 .extra2 = (void *)&hugetlb_infinity,
754 .ctl_name = VM_HUGETLB_GROUP,
755 .procname = "hugetlb_shm_group",
756 .data = &sysctl_hugetlb_shm_group,
757 .maxlen = sizeof(gid_t),
759 .proc_handler = &proc_dointvec,
763 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
764 .procname = "lowmem_reserve_ratio",
765 .data = &sysctl_lowmem_reserve_ratio,
766 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
768 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
769 .strategy = &sysctl_intvec,
772 .ctl_name = VM_MIN_FREE_KBYTES,
773 .procname = "min_free_kbytes",
774 .data = &min_free_kbytes,
775 .maxlen = sizeof(min_free_kbytes),
777 .proc_handler = &min_free_kbytes_sysctl_handler,
778 .strategy = &sysctl_intvec,
783 .ctl_name = VM_MAX_MAP_COUNT,
784 .procname = "max_map_count",
785 .data = &sysctl_max_map_count,
786 .maxlen = sizeof(sysctl_max_map_count),
788 .proc_handler = &proc_dointvec
792 .ctl_name = VM_LAPTOP_MODE,
793 .procname = "laptop_mode",
794 .data = &laptop_mode,
795 .maxlen = sizeof(laptop_mode),
797 .proc_handler = &proc_dointvec,
798 .strategy = &sysctl_intvec,
802 .ctl_name = VM_BLOCK_DUMP,
803 .procname = "block_dump",
805 .maxlen = sizeof(block_dump),
807 .proc_handler = &proc_dointvec,
808 .strategy = &sysctl_intvec,
812 .ctl_name = VM_VFS_CACHE_PRESSURE,
813 .procname = "vfs_cache_pressure",
814 .data = &sysctl_vfs_cache_pressure,
815 .maxlen = sizeof(sysctl_vfs_cache_pressure),
817 .proc_handler = &proc_dointvec,
818 .strategy = &sysctl_intvec,
821 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
823 .ctl_name = VM_LEGACY_VA_LAYOUT,
824 .procname = "legacy_va_layout",
825 .data = &sysctl_legacy_va_layout,
826 .maxlen = sizeof(sysctl_legacy_va_layout),
828 .proc_handler = &proc_dointvec,
829 .strategy = &sysctl_intvec,
835 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
836 .procname = "swap_token_timeout",
837 .data = &swap_token_default_timeout,
838 .maxlen = sizeof(swap_token_default_timeout),
840 .proc_handler = &proc_dointvec_jiffies,
841 .strategy = &sysctl_jiffies,
847 static ctl_table proc_table[] = {
851 static ctl_table fs_table[] = {
853 .ctl_name = FS_NRINODE,
854 .procname = "inode-nr",
855 .data = &inodes_stat,
856 .maxlen = 2*sizeof(int),
858 .proc_handler = &proc_dointvec,
861 .ctl_name = FS_STATINODE,
862 .procname = "inode-state",
863 .data = &inodes_stat,
864 .maxlen = 7*sizeof(int),
866 .proc_handler = &proc_dointvec,
869 .ctl_name = FS_NRFILE,
870 .procname = "file-nr",
872 .maxlen = 3*sizeof(int),
874 .proc_handler = &proc_dointvec,
877 .ctl_name = FS_MAXFILE,
878 .procname = "file-max",
879 .data = &files_stat.max_files,
880 .maxlen = sizeof(int),
882 .proc_handler = &proc_dointvec,
885 .ctl_name = FS_DENTRY,
886 .procname = "dentry-state",
887 .data = &dentry_stat,
888 .maxlen = 6*sizeof(int),
890 .proc_handler = &proc_dointvec,
893 .ctl_name = FS_OVERFLOWUID,
894 .procname = "overflowuid",
895 .data = &fs_overflowuid,
896 .maxlen = sizeof(int),
898 .proc_handler = &proc_dointvec_minmax,
899 .strategy = &sysctl_intvec,
900 .extra1 = &minolduid,
901 .extra2 = &maxolduid,
904 .ctl_name = FS_OVERFLOWGID,
905 .procname = "overflowgid",
906 .data = &fs_overflowgid,
907 .maxlen = sizeof(int),
909 .proc_handler = &proc_dointvec_minmax,
910 .strategy = &sysctl_intvec,
911 .extra1 = &minolduid,
912 .extra2 = &maxolduid,
915 .ctl_name = FS_LEASES,
916 .procname = "leases-enable",
917 .data = &leases_enable,
918 .maxlen = sizeof(int),
920 .proc_handler = &proc_dointvec,
922 #ifdef CONFIG_DNOTIFY
924 .ctl_name = FS_DIR_NOTIFY,
925 .procname = "dir-notify-enable",
926 .data = &dir_notify_enable,
927 .maxlen = sizeof(int),
929 .proc_handler = &proc_dointvec,
934 .ctl_name = FS_LEASE_TIME,
935 .procname = "lease-break-time",
936 .data = &lease_break_time,
937 .maxlen = sizeof(int),
939 .proc_handler = &proc_dointvec,
942 .ctl_name = FS_AIO_NR,
943 .procname = "aio-nr",
945 .maxlen = sizeof(aio_nr),
947 .proc_handler = &proc_dointvec,
950 .ctl_name = FS_AIO_MAX_NR,
951 .procname = "aio-max-nr",
953 .maxlen = sizeof(aio_max_nr),
955 .proc_handler = &proc_dointvec,
957 #ifdef CONFIG_INOTIFY
959 .ctl_name = FS_INOTIFY,
960 .procname = "inotify",
962 .child = inotify_table,
967 .ctl_name = KERN_SETUID_DUMPABLE,
968 .procname = "suid_dumpable",
969 .data = &suid_dumpable,
970 .maxlen = sizeof(int),
972 .proc_handler = &proc_dointvec,
977 static ctl_table debug_table[] = {
981 static ctl_table dev_table[] = {
985 extern void init_irq_proc (void);
987 void __init sysctl_init(void)
989 #ifdef CONFIG_PROC_FS
990 register_proc_table(root_table, proc_sys_root);
995 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
996 void __user *newval, size_t newlen)
998 struct list_head *tmp;
1000 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1004 if (!oldlenp || get_user(old_len, oldlenp))
1007 tmp = &root_table_header.ctl_entry;
1009 struct ctl_table_header *head =
1010 list_entry(tmp, struct ctl_table_header, ctl_entry);
1011 void *context = NULL;
1012 int error = parse_table(name, nlen, oldval, oldlenp,
1013 newval, newlen, head->ctl_table,
1016 if (error != -ENOTDIR)
1019 } while (tmp != &root_table_header.ctl_entry);
1023 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1025 struct __sysctl_args tmp;
1028 if (copy_from_user(&tmp, args, sizeof(tmp)))
1032 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1033 tmp.newval, tmp.newlen);
1039 * ctl_perm does NOT grant the superuser all rights automatically, because
1040 * some sysctl variables are readonly even to root.
1043 static int test_perm(int mode, int op)
1047 else if (in_egroup_p(0))
1049 if ((mode & op & 0007) == op)
1054 static inline int ctl_perm(ctl_table *table, int op)
1057 error = security_sysctl(table, op);
1060 return test_perm(table->mode, op);
1063 static int parse_table(int __user *name, int nlen,
1064 void __user *oldval, size_t __user *oldlenp,
1065 void __user *newval, size_t newlen,
1066 ctl_table *table, void **context)
1072 if (get_user(n, name))
1074 for ( ; table->ctl_name; table++) {
1075 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1078 if (ctl_perm(table, 001))
1080 if (table->strategy) {
1081 error = table->strategy(
1084 newval, newlen, context);
1090 table = table->child;
1093 error = do_sysctl_strategy(table, name, nlen,
1095 newval, newlen, context);
1102 /* Perform the actual read/write of a sysctl table entry. */
1103 int do_sysctl_strategy (ctl_table *table,
1104 int __user *name, int nlen,
1105 void __user *oldval, size_t __user *oldlenp,
1106 void __user *newval, size_t newlen, void **context)
1115 if (ctl_perm(table, op))
1118 if (table->strategy) {
1119 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1120 newval, newlen, context);
1127 /* If there is no strategy routine, or if the strategy returns
1128 * zero, proceed with automatic r/w */
1129 if (table->data && table->maxlen) {
1130 if (oldval && oldlenp) {
1131 if (get_user(len, oldlenp))
1134 if (len > table->maxlen)
1135 len = table->maxlen;
1136 if(copy_to_user(oldval, table->data, len))
1138 if(put_user(len, oldlenp))
1142 if (newval && newlen) {
1144 if (len > table->maxlen)
1145 len = table->maxlen;
1146 if(copy_from_user(table->data, newval, len))
1154 * register_sysctl_table - register a sysctl hierarchy
1155 * @table: the top-level table structure
1156 * @insert_at_head: whether the entry should be inserted in front or at the end
1158 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1159 * array. An entry with a ctl_name of 0 terminates the table.
1161 * The members of the &ctl_table structure are used as follows:
1163 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1164 * must be unique within that level of sysctl
1166 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1167 * enter a sysctl file
1169 * data - a pointer to data for use by proc_handler
1171 * maxlen - the maximum size in bytes of the data
1173 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1175 * child - a pointer to the child sysctl table if this entry is a directory, or
1178 * proc_handler - the text handler routine (described below)
1180 * strategy - the strategy routine (described below)
1182 * de - for internal use by the sysctl routines
1184 * extra1, extra2 - extra pointers usable by the proc handler routines
1186 * Leaf nodes in the sysctl tree will be represented by a single file
1187 * under /proc; non-leaf nodes will be represented by directories.
1189 * sysctl(2) can automatically manage read and write requests through
1190 * the sysctl table. The data and maxlen fields of the ctl_table
1191 * struct enable minimal validation of the values being written to be
1192 * performed, and the mode field allows minimal authentication.
1194 * More sophisticated management can be enabled by the provision of a
1195 * strategy routine with the table entry. This will be called before
1196 * any automatic read or write of the data is performed.
1198 * The strategy routine may return
1200 * < 0 - Error occurred (error is passed to user process)
1202 * 0 - OK - proceed with automatic read or write.
1204 * > 0 - OK - read or write has been done by the strategy routine, so
1205 * return immediately.
1207 * There must be a proc_handler routine for any terminal nodes
1208 * mirrored under /proc/sys (non-terminals are handled by a built-in
1209 * directory handler). Several default handlers are available to
1210 * cover common cases -
1212 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1213 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1214 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1216 * It is the handler's job to read the input buffer from user memory
1217 * and process it. The handler should return 0 on success.
1219 * This routine returns %NULL on a failure to register, and a pointer
1220 * to the table header on success.
1222 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1225 struct ctl_table_header *tmp;
1226 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1229 tmp->ctl_table = table;
1230 INIT_LIST_HEAD(&tmp->ctl_entry);
1232 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1234 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1235 #ifdef CONFIG_PROC_FS
1236 register_proc_table(table, proc_sys_root);
1242 * unregister_sysctl_table - unregister a sysctl table hierarchy
1243 * @header: the header returned from register_sysctl_table
1245 * Unregisters the sysctl table and all children. proc entries may not
1246 * actually be removed until they are no longer used by anyone.
1248 void unregister_sysctl_table(struct ctl_table_header * header)
1250 list_del(&header->ctl_entry);
1251 #ifdef CONFIG_PROC_FS
1252 unregister_proc_table(header->ctl_table, proc_sys_root);
1261 #ifdef CONFIG_PROC_FS
1263 /* Scan the sysctl entries in table and add them all into /proc */
1264 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1266 struct proc_dir_entry *de;
1270 for (; table->ctl_name; table++) {
1271 /* Can't do anything without a proc name. */
1272 if (!table->procname)
1274 /* Maybe we can't do anything with it... */
1275 if (!table->proc_handler && !table->child) {
1276 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1281 len = strlen(table->procname);
1285 if (table->proc_handler)
1289 for (de = root->subdir; de; de = de->next) {
1290 if (proc_match(len, table->procname, de))
1293 /* If the subdir exists already, de is non-NULL */
1297 de = create_proc_entry(table->procname, mode, root);
1300 de->data = (void *) table;
1301 if (table->proc_handler)
1302 de->proc_fops = &proc_sys_file_operations;
1305 if (de->mode & S_IFDIR)
1306 register_proc_table(table->child, de);
1311 * Unregister a /proc sysctl table and any subdirectories.
1313 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1315 struct proc_dir_entry *de;
1316 for (; table->ctl_name; table++) {
1317 if (!(de = table->de))
1319 if (de->mode & S_IFDIR) {
1320 if (!table->child) {
1321 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1324 unregister_proc_table(table->child, de);
1326 /* Don't unregister directories which still have entries.. */
1331 /* Don't unregister proc entries that are still being used.. */
1332 if (atomic_read(&de->count))
1336 remove_proc_entry(table->procname, root);
1340 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1341 size_t count, loff_t *ppos)
1344 struct proc_dir_entry *de;
1345 struct ctl_table *table;
1349 de = PDE(file->f_dentry->d_inode);
1350 if (!de || !de->data)
1352 table = (struct ctl_table *) de->data;
1353 if (!table || !table->proc_handler)
1355 op = (write ? 002 : 004);
1356 if (ctl_perm(table, op))
1361 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1367 static int proc_opensys(struct inode *inode, struct file *file)
1369 if (file->f_mode & FMODE_WRITE) {
1371 * sysctl entries that are not writable,
1372 * are _NOT_ writable, capabilities or not.
1374 if (!(inode->i_mode & S_IWUSR))
1381 static ssize_t proc_readsys(struct file * file, char __user * buf,
1382 size_t count, loff_t *ppos)
1384 return do_rw_proc(0, file, buf, count, ppos);
1387 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1388 size_t count, loff_t *ppos)
1390 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1394 * proc_dostring - read a string sysctl
1395 * @table: the sysctl table
1396 * @write: %TRUE if this is a write to the sysctl file
1397 * @filp: the file structure
1398 * @buffer: the user buffer
1399 * @lenp: the size of the user buffer
1400 * @ppos: file position
1402 * Reads/writes a string from/to the user buffer. If the kernel
1403 * buffer provided is not large enough to hold the string, the
1404 * string is truncated. The copied string is %NULL-terminated.
1405 * If the string is being read by the user process, it is copied
1406 * and a newline '\n' is added. It is truncated if the buffer is
1409 * Returns 0 on success.
1411 int proc_dostring(ctl_table *table, int write, struct file *filp,
1412 void __user *buffer, size_t *lenp, loff_t *ppos)
1418 if (!table->data || !table->maxlen || !*lenp ||
1419 (*ppos && !write)) {
1427 while (len < *lenp) {
1428 if (get_user(c, p++))
1430 if (c == 0 || c == '\n')
1434 if (len >= table->maxlen)
1435 len = table->maxlen-1;
1436 if(copy_from_user(table->data, buffer, len))
1438 ((char *) table->data)[len] = 0;
1441 len = strlen(table->data);
1442 if (len > table->maxlen)
1443 len = table->maxlen;
1447 if(copy_to_user(buffer, table->data, len))
1450 if(put_user('\n', ((char __user *) buffer) + len))
1461 * Special case of dostring for the UTS structure. This has locks
1462 * to observe. Should this be in kernel/sys.c ????
1465 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1466 void __user *buffer, size_t *lenp, loff_t *ppos)
1471 down_read(&uts_sem);
1472 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1475 down_write(&uts_sem);
1476 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1482 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1484 int write, void *data)
1487 *valp = *negp ? -*lvalp : *lvalp;
1492 *lvalp = (unsigned long)-val;
1495 *lvalp = (unsigned long)val;
1501 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1502 void __user *buffer, size_t *lenp, loff_t *ppos,
1503 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1504 int write, void *data),
1507 #define TMPBUFLEN 21
1508 int *i, vleft, first=1, neg, val;
1512 char buf[TMPBUFLEN], *p;
1513 char __user *s = buffer;
1515 if (!table->data || !table->maxlen || !*lenp ||
1516 (*ppos && !write)) {
1521 i = (int *) table->data;
1522 vleft = table->maxlen / sizeof(*i);
1526 conv = do_proc_dointvec_conv;
1528 for (; left && vleft--; i++, first=0) {
1543 if (len > sizeof(buf) - 1)
1544 len = sizeof(buf) - 1;
1545 if (copy_from_user(buf, s, len))
1549 if (*p == '-' && left > 1) {
1553 if (*p < '0' || *p > '9')
1556 lval = simple_strtoul(p, &p, 0);
1559 if ((len < left) && *p && !isspace(*p))
1566 if (conv(&neg, &lval, i, 1, data))
1573 if (conv(&neg, &lval, i, 0, data))
1576 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1580 if(copy_to_user(s, buf, len))
1587 if (!write && !first && left) {
1588 if(put_user('\n', s))
1595 if (get_user(c, s++))
1611 * proc_dointvec - read a vector of integers
1612 * @table: the sysctl table
1613 * @write: %TRUE if this is a write to the sysctl file
1614 * @filp: the file structure
1615 * @buffer: the user buffer
1616 * @lenp: the size of the user buffer
1617 * @ppos: file position
1619 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1620 * values from/to the user buffer, treated as an ASCII string.
1622 * Returns 0 on success.
1624 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1625 void __user *buffer, size_t *lenp, loff_t *ppos)
1627 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1637 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1639 int write, void *data)
1641 int op = *(int *)data;
1643 int val = *negp ? -*lvalp : *lvalp;
1645 case OP_SET: *valp = val; break;
1646 case OP_AND: *valp &= val; break;
1647 case OP_OR: *valp |= val; break;
1648 case OP_MAX: if(*valp < val)
1651 case OP_MIN: if(*valp > val)
1659 *lvalp = (unsigned long)-val;
1662 *lvalp = (unsigned long)val;
1669 * init may raise the set.
1672 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1673 void __user *buffer, size_t *lenp, loff_t *ppos)
1677 if (!capable(CAP_SYS_MODULE)) {
1681 op = (current->pid == 1) ? OP_SET : OP_AND;
1682 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1683 do_proc_dointvec_bset_conv,&op);
1686 struct do_proc_dointvec_minmax_conv_param {
1691 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1693 int write, void *data)
1695 struct do_proc_dointvec_minmax_conv_param *param = data;
1697 int val = *negp ? -*lvalp : *lvalp;
1698 if ((param->min && *param->min > val) ||
1699 (param->max && *param->max < val))
1706 *lvalp = (unsigned long)-val;
1709 *lvalp = (unsigned long)val;
1716 * proc_dointvec_minmax - read a vector of integers with min/max values
1717 * @table: the sysctl table
1718 * @write: %TRUE if this is a write to the sysctl file
1719 * @filp: the file structure
1720 * @buffer: the user buffer
1721 * @lenp: the size of the user buffer
1722 * @ppos: file position
1724 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1725 * values from/to the user buffer, treated as an ASCII string.
1727 * This routine will ensure the values are within the range specified by
1728 * table->extra1 (min) and table->extra2 (max).
1730 * Returns 0 on success.
1732 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1733 void __user *buffer, size_t *lenp, loff_t *ppos)
1735 struct do_proc_dointvec_minmax_conv_param param = {
1736 .min = (int *) table->extra1,
1737 .max = (int *) table->extra2,
1739 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1740 do_proc_dointvec_minmax_conv, ¶m);
1743 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1745 void __user *buffer,
1746 size_t *lenp, loff_t *ppos,
1747 unsigned long convmul,
1748 unsigned long convdiv)
1750 #define TMPBUFLEN 21
1751 unsigned long *i, *min, *max, val;
1752 int vleft, first=1, neg;
1754 char buf[TMPBUFLEN], *p;
1755 char __user *s = buffer;
1757 if (!table->data || !table->maxlen || !*lenp ||
1758 (*ppos && !write)) {
1763 i = (unsigned long *) table->data;
1764 min = (unsigned long *) table->extra1;
1765 max = (unsigned long *) table->extra2;
1766 vleft = table->maxlen / sizeof(unsigned long);
1769 for (; left && vleft--; i++, min++, max++, first=0) {
1784 if (len > TMPBUFLEN-1)
1786 if (copy_from_user(buf, s, len))
1790 if (*p == '-' && left > 1) {
1794 if (*p < '0' || *p > '9')
1796 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1798 if ((len < left) && *p && !isspace(*p))
1807 if ((min && val < *min) || (max && val > *max))
1814 sprintf(p, "%lu", convdiv * (*i) / convmul);
1818 if(copy_to_user(s, buf, len))
1825 if (!write && !first && left) {
1826 if(put_user('\n', s))
1833 if (get_user(c, s++))
1849 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1850 * @table: the sysctl table
1851 * @write: %TRUE if this is a write to the sysctl file
1852 * @filp: the file structure
1853 * @buffer: the user buffer
1854 * @lenp: the size of the user buffer
1855 * @ppos: file position
1857 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1858 * values from/to the user buffer, treated as an ASCII string.
1860 * This routine will ensure the values are within the range specified by
1861 * table->extra1 (min) and table->extra2 (max).
1863 * Returns 0 on success.
1865 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1866 void __user *buffer, size_t *lenp, loff_t *ppos)
1868 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1872 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1873 * @table: the sysctl table
1874 * @write: %TRUE if this is a write to the sysctl file
1875 * @filp: the file structure
1876 * @buffer: the user buffer
1877 * @lenp: the size of the user buffer
1878 * @ppos: file position
1880 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1881 * values from/to the user buffer, treated as an ASCII string. The values
1882 * are treated as milliseconds, and converted to jiffies when they are stored.
1884 * This routine will ensure the values are within the range specified by
1885 * table->extra1 (min) and table->extra2 (max).
1887 * Returns 0 on success.
1889 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1891 void __user *buffer,
1892 size_t *lenp, loff_t *ppos)
1894 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1895 lenp, ppos, HZ, 1000l);
1899 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1901 int write, void *data)
1904 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1910 lval = (unsigned long)-val;
1913 lval = (unsigned long)val;
1920 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1922 int write, void *data)
1925 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1931 lval = (unsigned long)-val;
1934 lval = (unsigned long)val;
1936 *lvalp = jiffies_to_clock_t(lval);
1941 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1943 int write, void *data)
1946 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1952 lval = (unsigned long)-val;
1955 lval = (unsigned long)val;
1957 *lvalp = jiffies_to_msecs(lval);
1963 * proc_dointvec_jiffies - read a vector of integers as seconds
1964 * @table: the sysctl table
1965 * @write: %TRUE if this is a write to the sysctl file
1966 * @filp: the file structure
1967 * @buffer: the user buffer
1968 * @lenp: the size of the user buffer
1969 * @ppos: file position
1971 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1972 * values from/to the user buffer, treated as an ASCII string.
1973 * The values read are assumed to be in seconds, and are converted into
1976 * Returns 0 on success.
1978 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1979 void __user *buffer, size_t *lenp, loff_t *ppos)
1981 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1982 do_proc_dointvec_jiffies_conv,NULL);
1986 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1987 * @table: the sysctl table
1988 * @write: %TRUE if this is a write to the sysctl file
1989 * @filp: the file structure
1990 * @buffer: the user buffer
1991 * @lenp: the size of the user buffer
1993 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1994 * values from/to the user buffer, treated as an ASCII string.
1995 * The values read are assumed to be in 1/USER_HZ seconds, and
1996 * are converted into jiffies.
1998 * Returns 0 on success.
2000 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2001 void __user *buffer, size_t *lenp, loff_t *ppos)
2003 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2004 do_proc_dointvec_userhz_jiffies_conv,NULL);
2008 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2009 * @table: the sysctl table
2010 * @write: %TRUE if this is a write to the sysctl file
2011 * @filp: the file structure
2012 * @buffer: the user buffer
2013 * @lenp: the size of the user buffer
2014 * @ppos: file position
2015 * @ppos: the current position in the file
2017 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2018 * values from/to the user buffer, treated as an ASCII string.
2019 * The values read are assumed to be in 1/1000 seconds, and
2020 * are converted into jiffies.
2022 * Returns 0 on success.
2024 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2025 void __user *buffer, size_t *lenp, loff_t *ppos)
2027 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2028 do_proc_dointvec_ms_jiffies_conv, NULL);
2031 #else /* CONFIG_PROC_FS */
2033 int proc_dostring(ctl_table *table, int write, struct file *filp,
2034 void __user *buffer, size_t *lenp, loff_t *ppos)
2039 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2040 void __user *buffer, size_t *lenp, loff_t *ppos)
2045 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2046 void __user *buffer, size_t *lenp, loff_t *ppos)
2051 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2052 void __user *buffer, size_t *lenp, loff_t *ppos)
2057 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2058 void __user *buffer, size_t *lenp, loff_t *ppos)
2063 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2064 void __user *buffer, size_t *lenp, loff_t *ppos)
2069 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2070 void __user *buffer, size_t *lenp, loff_t *ppos)
2075 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2076 void __user *buffer, size_t *lenp, loff_t *ppos)
2081 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2082 void __user *buffer, size_t *lenp, loff_t *ppos)
2087 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2089 void __user *buffer,
2090 size_t *lenp, loff_t *ppos)
2096 #endif /* CONFIG_PROC_FS */
2100 * General sysctl support routines
2103 /* The generic string strategy routine: */
2104 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2105 void __user *oldval, size_t __user *oldlenp,
2106 void __user *newval, size_t newlen, void **context)
2110 if (!table->data || !table->maxlen)
2113 if (oldval && oldlenp) {
2114 if (get_user(len, oldlenp))
2117 l = strlen(table->data);
2118 if (len > l) len = l;
2119 if (len >= table->maxlen)
2120 len = table->maxlen;
2121 if(copy_to_user(oldval, table->data, len))
2123 if(put_user(0, ((char __user *) oldval) + len))
2125 if(put_user(len, oldlenp))
2129 if (newval && newlen) {
2131 if (len > table->maxlen)
2132 len = table->maxlen;
2133 if(copy_from_user(table->data, newval, len))
2135 if (len == table->maxlen)
2137 ((char *) table->data)[len] = 0;
2143 * This function makes sure that all of the integers in the vector
2144 * are between the minimum and maximum values given in the arrays
2145 * table->extra1 and table->extra2, respectively.
2147 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2148 void __user *oldval, size_t __user *oldlenp,
2149 void __user *newval, size_t newlen, void **context)
2152 if (newval && newlen) {
2153 int __user *vec = (int __user *) newval;
2154 int *min = (int *) table->extra1;
2155 int *max = (int *) table->extra2;
2159 if (newlen % sizeof(int) != 0)
2162 if (!table->extra1 && !table->extra2)
2165 if (newlen > table->maxlen)
2166 newlen = table->maxlen;
2167 length = newlen / sizeof(int);
2169 for (i = 0; i < length; i++) {
2171 if (get_user(value, vec + i))
2173 if (min && value < min[i])
2175 if (max && value > max[i])
2182 /* Strategy function to convert jiffies to seconds */
2183 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2184 void __user *oldval, size_t __user *oldlenp,
2185 void __user *newval, size_t newlen, void **context)
2190 if (get_user(olen, oldlenp))
2192 if (olen!=sizeof(int))
2195 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2196 (oldlenp && put_user(sizeof(int),oldlenp)))
2199 if (newval && newlen) {
2201 if (newlen != sizeof(int))
2203 if (get_user(new, (int __user *)newval))
2205 *(int *)(table->data) = new*HZ;
2210 /* Strategy function to convert jiffies to seconds */
2211 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2212 void __user *oldval, size_t __user *oldlenp,
2213 void __user *newval, size_t newlen, void **context)
2218 if (get_user(olen, oldlenp))
2220 if (olen!=sizeof(int))
2223 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2224 (oldlenp && put_user(sizeof(int),oldlenp)))
2227 if (newval && newlen) {
2229 if (newlen != sizeof(int))
2231 if (get_user(new, (int __user *)newval))
2233 *(int *)(table->data) = msecs_to_jiffies(new);
2238 #else /* CONFIG_SYSCTL */
2241 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2246 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2247 void __user *oldval, size_t __user *oldlenp,
2248 void __user *newval, size_t newlen, void **context)
2253 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2254 void __user *oldval, size_t __user *oldlenp,
2255 void __user *newval, size_t newlen, void **context)
2260 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2261 void __user *oldval, size_t __user *oldlenp,
2262 void __user *newval, size_t newlen, void **context)
2267 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2268 void __user *oldval, size_t __user *oldlenp,
2269 void __user *newval, size_t newlen, void **context)
2274 int proc_dostring(ctl_table *table, int write, struct file *filp,
2275 void __user *buffer, size_t *lenp, loff_t *ppos)
2280 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2281 void __user *buffer, size_t *lenp, loff_t *ppos)
2286 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2287 void __user *buffer, size_t *lenp, loff_t *ppos)
2292 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2293 void __user *buffer, size_t *lenp, loff_t *ppos)
2298 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2299 void __user *buffer, size_t *lenp, loff_t *ppos)
2304 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2310 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2311 void __user *buffer, size_t *lenp, loff_t *ppos)
2316 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2317 void __user *buffer, size_t *lenp, loff_t *ppos)
2322 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2324 void __user *buffer,
2325 size_t *lenp, loff_t *ppos)
2330 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2336 void unregister_sysctl_table(struct ctl_table_header * table)
2340 #endif /* CONFIG_SYSCTL */
2343 * No sense putting this after each symbol definition, twice,
2344 * exception granted :-)
2346 EXPORT_SYMBOL(proc_dointvec);
2347 EXPORT_SYMBOL(proc_dointvec_jiffies);
2348 EXPORT_SYMBOL(proc_dointvec_minmax);
2349 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2350 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2351 EXPORT_SYMBOL(proc_dostring);
2352 EXPORT_SYMBOL(proc_doulongvec_minmax);
2353 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2354 EXPORT_SYMBOL(register_sysctl_table);
2355 EXPORT_SYMBOL(sysctl_intvec);
2356 EXPORT_SYMBOL(sysctl_jiffies);
2357 EXPORT_SYMBOL(sysctl_ms_jiffies);
2358 EXPORT_SYMBOL(sysctl_string);
2359 EXPORT_SYMBOL(unregister_sysctl_table);