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. */
55 extern int panic_timeout;
57 extern int sysctl_overcommit_memory;
58 extern int sysctl_overcommit_ratio;
59 extern int max_threads;
60 extern int sysrq_enabled;
61 extern int core_uses_pid;
62 extern int suid_dumpable;
63 extern char core_pattern[];
66 extern int sysctl_lower_zone_protection;
67 extern int min_free_kbytes;
68 extern int printk_ratelimit_jiffies;
69 extern int printk_ratelimit_burst;
70 extern int pid_max_min, pid_max_max;
72 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
73 int unknown_nmi_panic;
74 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
75 void __user *, size_t *, loff_t *);
78 extern unsigned int vdso_enabled;
81 int exec_shield_randomize = 1;
83 static int __init setup_exec_shield(char *str)
85 get_option (&str, &exec_shield);
90 __setup("exec-shield=", setup_exec_shield);
92 static int __init setup_exec_shield_randomize(char *str)
94 get_option (&str, &exec_shield_randomize);
99 __setup("exec-shield-randomize=", setup_exec_shield_randomize);
101 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
102 static int maxolduid = 65535;
103 static int minolduid;
105 static int ngroups_max = NGROUPS_MAX;
108 extern char modprobe_path[];
110 #ifdef CONFIG_HOTPLUG
111 extern char hotplug_path[];
113 extern char vshelper_path[];
114 #ifdef CONFIG_CHR_DEV_SG
115 extern int sg_big_buff;
117 #ifdef CONFIG_SYSVIPC
118 extern size_t shm_ctlmax;
119 extern size_t shm_ctlall;
120 extern int shm_ctlmni;
121 extern int msg_ctlmax;
122 extern int msg_ctlmnb;
123 extern int msg_ctlmni;
124 extern int sem_ctls[];
128 extern char reboot_command [];
129 extern int stop_a_enabled;
130 extern int scons_pwroff;
134 extern int pwrsw_enabled;
135 extern int unaligned_enabled;
138 #ifdef CONFIG_ARCH_S390
139 #ifdef CONFIG_MATHEMU
140 extern int sysctl_ieee_emulation_warnings;
142 extern int sysctl_userprocess_debug;
145 extern int sysctl_hz_timer;
147 #ifdef CONFIG_BSD_PROCESS_ACCT
148 extern int acct_parm[];
151 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
152 ctl_table *, void **);
153 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
156 static ctl_table root_table[];
157 static struct ctl_table_header root_table_header =
158 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
160 static ctl_table kern_table[];
161 static ctl_table vm_table[];
163 extern ctl_table net_table[];
165 static ctl_table proc_table[];
166 static ctl_table fs_table[];
167 static ctl_table debug_table[];
168 static ctl_table dev_table[];
169 extern ctl_table random_table[];
170 #ifdef CONFIG_UNIX98_PTYS
171 extern ctl_table pty_table[];
174 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
175 int sysctl_legacy_va_layout;
178 /* /proc declarations: */
180 #ifdef CONFIG_PROC_FS
182 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
183 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
184 static int proc_opensys(struct inode *, struct file *);
186 struct file_operations proc_sys_file_operations = {
187 .open = proc_opensys,
188 .read = proc_readsys,
189 .write = proc_writesys,
192 extern struct proc_dir_entry *proc_sys_root;
194 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
195 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
198 /* The default sysctl tables: */
200 static ctl_table root_table[] = {
202 .ctl_name = CTL_KERN,
203 .procname = "kernel",
222 .ctl_name = CTL_PROC,
234 .ctl_name = CTL_DEBUG,
237 .child = debug_table,
248 static ctl_table kern_table[] = {
250 .ctl_name = KERN_OSTYPE,
251 .procname = "ostype",
252 .data = system_utsname.sysname,
253 .maxlen = sizeof(system_utsname.sysname),
255 .proc_handler = &proc_doutsstring,
256 .strategy = &sysctl_string,
259 .ctl_name = KERN_OSRELEASE,
260 .procname = "osrelease",
261 .data = system_utsname.release,
262 .maxlen = sizeof(system_utsname.release),
264 .proc_handler = &proc_doutsstring,
265 .strategy = &sysctl_string,
268 .ctl_name = KERN_VERSION,
269 .procname = "version",
270 .data = system_utsname.version,
271 .maxlen = sizeof(system_utsname.version),
273 .proc_handler = &proc_doutsstring,
274 .strategy = &sysctl_string,
277 .ctl_name = KERN_NODENAME,
278 .procname = "hostname",
279 .data = system_utsname.nodename,
280 .maxlen = sizeof(system_utsname.nodename),
282 .proc_handler = &proc_doutsstring,
283 .strategy = &sysctl_string,
286 .ctl_name = KERN_DOMAINNAME,
287 .procname = "domainname",
288 .data = system_utsname.domainname,
289 .maxlen = sizeof(system_utsname.domainname),
291 .proc_handler = &proc_doutsstring,
292 .strategy = &sysctl_string,
295 .ctl_name = KERN_PANIC,
297 .data = &panic_timeout,
298 .maxlen = sizeof(int),
300 .proc_handler = &proc_dointvec,
303 .ctl_name = KERN_PANIC,
304 .procname = "exec-shield",
305 .data = &exec_shield,
306 .maxlen = sizeof(int),
308 .proc_handler = &proc_dointvec,
311 .ctl_name = KERN_PANIC,
312 .procname = "exec-shield-randomize",
313 .data = &exec_shield_randomize,
314 .maxlen = sizeof(int),
316 .proc_handler = &proc_dointvec,
319 .ctl_name = KERN_PANIC,
320 .procname = "print-fatal-signals",
321 .data = &print_fatal_signals,
322 .maxlen = sizeof(int),
324 .proc_handler = &proc_dointvec,
328 .ctl_name = KERN_PANIC,
330 .data = &vdso_enabled,
331 .maxlen = sizeof(int),
333 .proc_handler = &proc_dointvec,
337 .ctl_name = KERN_CORE_USES_PID,
338 .procname = "core_uses_pid",
339 .data = &core_uses_pid,
340 .maxlen = sizeof(int),
342 .proc_handler = &proc_dointvec,
345 .ctl_name = KERN_CORE_PATTERN,
346 .procname = "core_pattern",
347 .data = core_pattern,
350 .proc_handler = &proc_dostring,
351 .strategy = &sysctl_string,
354 .ctl_name = KERN_TAINTED,
355 .procname = "tainted",
357 .maxlen = sizeof(int),
359 .proc_handler = &proc_dointvec,
362 .ctl_name = KERN_CAP_BSET,
363 .procname = "cap-bound",
365 .maxlen = sizeof(kernel_cap_t),
367 .proc_handler = &proc_dointvec_bset,
369 #ifdef CONFIG_BLK_DEV_INITRD
371 .ctl_name = KERN_REALROOTDEV,
372 .procname = "real-root-dev",
373 .data = &real_root_dev,
374 .maxlen = sizeof(int),
376 .proc_handler = &proc_dointvec,
381 .ctl_name = KERN_SPARC_REBOOT,
382 .procname = "reboot-cmd",
383 .data = reboot_command,
386 .proc_handler = &proc_dostring,
387 .strategy = &sysctl_string,
390 .ctl_name = KERN_SPARC_STOP_A,
391 .procname = "stop-a",
392 .data = &stop_a_enabled,
393 .maxlen = sizeof (int),
395 .proc_handler = &proc_dointvec,
398 .ctl_name = KERN_SPARC_SCONS_PWROFF,
399 .procname = "scons-poweroff",
400 .data = &scons_pwroff,
401 .maxlen = sizeof (int),
403 .proc_handler = &proc_dointvec,
408 .ctl_name = KERN_HPPA_PWRSW,
409 .procname = "soft-power",
410 .data = &pwrsw_enabled,
411 .maxlen = sizeof (int),
413 .proc_handler = &proc_dointvec,
416 .ctl_name = KERN_HPPA_UNALIGNED,
417 .procname = "unaligned-trap",
418 .data = &unaligned_enabled,
419 .maxlen = sizeof (int),
421 .proc_handler = &proc_dointvec,
425 .ctl_name = KERN_CTLALTDEL,
426 .procname = "ctrl-alt-del",
428 .maxlen = sizeof(int),
430 .proc_handler = &proc_dointvec,
433 .ctl_name = KERN_PRINTK,
434 .procname = "printk",
435 .data = &console_loglevel,
436 .maxlen = 4*sizeof(int),
438 .proc_handler = &proc_dointvec,
442 .ctl_name = KERN_MODPROBE,
443 .procname = "modprobe",
444 .data = &modprobe_path,
445 .maxlen = KMOD_PATH_LEN,
447 .proc_handler = &proc_dostring,
448 .strategy = &sysctl_string,
451 #ifdef CONFIG_HOTPLUG
453 .ctl_name = KERN_HOTPLUG,
454 .procname = "hotplug",
455 .data = &hotplug_path,
456 .maxlen = HOTPLUG_PATH_LEN,
458 .proc_handler = &proc_dostring,
459 .strategy = &sysctl_string,
463 .ctl_name = KERN_VSHELPER,
464 .procname = "vshelper",
465 .data = &vshelper_path,
468 .proc_handler = &proc_dostring,
469 .strategy = &sysctl_string,
471 #ifdef CONFIG_CHR_DEV_SG
473 .ctl_name = KERN_SG_BIG_BUFF,
474 .procname = "sg-big-buff",
475 .data = &sg_big_buff,
476 .maxlen = sizeof (int),
478 .proc_handler = &proc_dointvec,
481 #ifdef CONFIG_BSD_PROCESS_ACCT
483 .ctl_name = KERN_ACCT,
486 .maxlen = 3*sizeof(int),
488 .proc_handler = &proc_dointvec,
491 #ifdef CONFIG_SYSVIPC
493 .ctl_name = KERN_SHMMAX,
494 .procname = "shmmax",
496 .maxlen = sizeof (size_t),
498 .proc_handler = &proc_doulongvec_minmax,
501 .ctl_name = KERN_SHMALL,
502 .procname = "shmall",
504 .maxlen = sizeof (size_t),
506 .proc_handler = &proc_doulongvec_minmax,
509 .ctl_name = KERN_SHMMNI,
510 .procname = "shmmni",
512 .maxlen = sizeof (int),
514 .proc_handler = &proc_dointvec,
517 .ctl_name = KERN_MSGMAX,
518 .procname = "msgmax",
520 .maxlen = sizeof (int),
522 .proc_handler = &proc_dointvec,
525 .ctl_name = KERN_MSGMNI,
526 .procname = "msgmni",
528 .maxlen = sizeof (int),
530 .proc_handler = &proc_dointvec,
533 .ctl_name = KERN_MSGMNB,
534 .procname = "msgmnb",
536 .maxlen = sizeof (int),
538 .proc_handler = &proc_dointvec,
541 .ctl_name = KERN_SEM,
544 .maxlen = 4*sizeof (int),
546 .proc_handler = &proc_dointvec,
549 #ifdef CONFIG_MAGIC_SYSRQ
551 .ctl_name = KERN_SYSRQ,
553 .data = &sysrq_enabled,
554 .maxlen = sizeof (int),
556 .proc_handler = &proc_dointvec,
560 .ctl_name = KERN_CADPID,
561 .procname = "cad_pid",
563 .maxlen = sizeof (int),
565 .proc_handler = &proc_dointvec,
568 .ctl_name = KERN_MAX_THREADS,
569 .procname = "threads-max",
570 .data = &max_threads,
571 .maxlen = sizeof(int),
573 .proc_handler = &proc_dointvec,
576 .ctl_name = KERN_RANDOM,
577 .procname = "random",
579 .child = random_table,
581 #ifdef CONFIG_UNIX98_PTYS
583 .ctl_name = KERN_PTY,
590 .ctl_name = KERN_OVERFLOWUID,
591 .procname = "overflowuid",
592 .data = &overflowuid,
593 .maxlen = sizeof(int),
595 .proc_handler = &proc_dointvec_minmax,
596 .strategy = &sysctl_intvec,
597 .extra1 = &minolduid,
598 .extra2 = &maxolduid,
601 .ctl_name = KERN_OVERFLOWGID,
602 .procname = "overflowgid",
603 .data = &overflowgid,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec_minmax,
607 .strategy = &sysctl_intvec,
608 .extra1 = &minolduid,
609 .extra2 = &maxolduid,
611 #ifdef CONFIG_ARCH_S390
612 #ifdef CONFIG_MATHEMU
614 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
615 .procname = "ieee_emulation_warnings",
616 .data = &sysctl_ieee_emulation_warnings,
617 .maxlen = sizeof(int),
619 .proc_handler = &proc_dointvec,
622 #ifdef CONFIG_NO_IDLE_HZ
624 .ctl_name = KERN_HZ_TIMER,
625 .procname = "hz_timer",
626 .data = &sysctl_hz_timer,
627 .maxlen = sizeof(int),
629 .proc_handler = &proc_dointvec,
633 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
634 .procname = "userprocess_debug",
635 .data = &sysctl_userprocess_debug,
636 .maxlen = sizeof(int),
638 .proc_handler = &proc_dointvec,
642 .ctl_name = KERN_PIDMAX,
643 .procname = "pid_max",
645 .maxlen = sizeof (int),
647 .proc_handler = &proc_dointvec_minmax,
648 .strategy = sysctl_intvec,
649 .extra1 = &pid_max_min,
650 .extra2 = &pid_max_max,
653 .ctl_name = KERN_PANIC_ON_OOPS,
654 .procname = "panic_on_oops",
655 .data = &panic_on_oops,
656 .maxlen = sizeof(int),
658 .proc_handler = &proc_dointvec,
661 .ctl_name = KERN_PRINTK_RATELIMIT,
662 .procname = "printk_ratelimit",
663 .data = &printk_ratelimit_jiffies,
664 .maxlen = sizeof(int),
666 .proc_handler = &proc_dointvec_jiffies,
667 .strategy = &sysctl_jiffies,
670 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
671 .procname = "printk_ratelimit_burst",
672 .data = &printk_ratelimit_burst,
673 .maxlen = sizeof(int),
675 .proc_handler = &proc_dointvec,
678 .ctl_name = KERN_NGROUPS_MAX,
679 .procname = "ngroups_max",
680 .data = &ngroups_max,
681 .maxlen = sizeof (int),
683 .proc_handler = &proc_dointvec,
685 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
687 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
688 .procname = "unknown_nmi_panic",
689 .data = &unknown_nmi_panic,
690 .maxlen = sizeof (int),
692 .proc_handler = &proc_unknown_nmi_panic,
696 .ctl_name = KERN_SETUID_DUMPABLE,
697 .procname = "suid_dumpable",
698 .data = &suid_dumpable,
699 .maxlen = sizeof(int),
701 .proc_handler = &proc_dointvec,
706 /* Constants for minimum and maximum testing in vm_table.
707 We use these as one-element integer vectors. */
709 static int one_hundred = 100;
712 static ctl_table vm_table[] = {
714 .ctl_name = VM_OVERCOMMIT_MEMORY,
715 .procname = "overcommit_memory",
716 .data = &sysctl_overcommit_memory,
717 .maxlen = sizeof(sysctl_overcommit_memory),
719 .proc_handler = &proc_dointvec,
722 .ctl_name = VM_OVERCOMMIT_RATIO,
723 .procname = "overcommit_ratio",
724 .data = &sysctl_overcommit_ratio,
725 .maxlen = sizeof(sysctl_overcommit_ratio),
727 .proc_handler = &proc_dointvec,
730 .ctl_name = VM_PAGE_CLUSTER,
731 .procname = "page-cluster",
732 .data = &page_cluster,
733 .maxlen = sizeof(int),
735 .proc_handler = &proc_dointvec,
738 .ctl_name = VM_DIRTY_BACKGROUND,
739 .procname = "dirty_background_ratio",
740 .data = &dirty_background_ratio,
741 .maxlen = sizeof(dirty_background_ratio),
743 .proc_handler = &proc_dointvec_minmax,
744 .strategy = &sysctl_intvec,
746 .extra2 = &one_hundred,
749 .ctl_name = VM_DIRTY_RATIO,
750 .procname = "dirty_ratio",
751 .data = &vm_dirty_ratio,
752 .maxlen = sizeof(vm_dirty_ratio),
754 .proc_handler = &proc_dointvec_minmax,
755 .strategy = &sysctl_intvec,
757 .extra2 = &one_hundred,
760 .ctl_name = VM_DIRTY_WB_CS,
761 .procname = "dirty_writeback_centisecs",
762 .data = &dirty_writeback_centisecs,
763 .maxlen = sizeof(dirty_writeback_centisecs),
765 .proc_handler = &dirty_writeback_centisecs_handler,
768 .ctl_name = VM_DIRTY_EXPIRE_CS,
769 .procname = "dirty_expire_centisecs",
770 .data = &dirty_expire_centisecs,
771 .maxlen = sizeof(dirty_expire_centisecs),
773 .proc_handler = &proc_dointvec,
776 .ctl_name = VM_NR_PDFLUSH_THREADS,
777 .procname = "nr_pdflush_threads",
778 .data = &nr_pdflush_threads,
779 .maxlen = sizeof nr_pdflush_threads,
780 .mode = 0444 /* read-only*/,
781 .proc_handler = &proc_dointvec,
784 .ctl_name = VM_SWAPPINESS,
785 .procname = "swappiness",
786 .data = &vm_swappiness,
787 .maxlen = sizeof(vm_swappiness),
789 .proc_handler = &proc_dointvec_minmax,
790 .strategy = &sysctl_intvec,
792 .extra2 = &one_hundred,
794 #ifdef CONFIG_HUGETLB_PAGE
796 .ctl_name = VM_HUGETLB_PAGES,
797 .procname = "nr_hugepages",
798 .data = &max_huge_pages,
799 .maxlen = sizeof(unsigned long),
801 .proc_handler = &hugetlb_sysctl_handler,
802 .extra1 = (void *)&hugetlb_zero,
803 .extra2 = (void *)&hugetlb_infinity,
806 .ctl_name = VM_HUGETLB_GROUP,
807 .procname = "hugetlb_shm_group",
808 .data = &sysctl_hugetlb_shm_group,
809 .maxlen = sizeof(gid_t),
811 .proc_handler = &proc_dointvec,
815 .ctl_name = VM_LOWER_ZONE_PROTECTION,
816 .procname = "lower_zone_protection",
817 .data = &sysctl_lower_zone_protection,
818 .maxlen = sizeof(sysctl_lower_zone_protection),
820 .proc_handler = &lower_zone_protection_sysctl_handler,
821 .strategy = &sysctl_intvec,
825 .ctl_name = VM_MIN_FREE_KBYTES,
826 .procname = "min_free_kbytes",
827 .data = &min_free_kbytes,
828 .maxlen = sizeof(min_free_kbytes),
830 .proc_handler = &min_free_kbytes_sysctl_handler,
831 .strategy = &sysctl_intvec,
835 .ctl_name = VM_MAX_MAP_COUNT,
836 .procname = "max_map_count",
837 .data = &sysctl_max_map_count,
838 .maxlen = sizeof(sysctl_max_map_count),
840 .proc_handler = &proc_dointvec
843 .ctl_name = VM_LAPTOP_MODE,
844 .procname = "laptop_mode",
845 .data = &laptop_mode,
846 .maxlen = sizeof(laptop_mode),
848 .proc_handler = &proc_dointvec,
849 .strategy = &sysctl_intvec,
853 .ctl_name = VM_BLOCK_DUMP,
854 .procname = "block_dump",
856 .maxlen = sizeof(block_dump),
858 .proc_handler = &proc_dointvec,
859 .strategy = &sysctl_intvec,
863 .ctl_name = VM_VFS_CACHE_PRESSURE,
864 .procname = "vfs_cache_pressure",
865 .data = &sysctl_vfs_cache_pressure,
866 .maxlen = sizeof(sysctl_vfs_cache_pressure),
868 .proc_handler = &proc_dointvec,
869 .strategy = &sysctl_intvec,
872 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
874 .ctl_name = VM_LEGACY_VA_LAYOUT,
875 .procname = "legacy_va_layout",
876 .data = &sysctl_legacy_va_layout,
877 .maxlen = sizeof(sysctl_legacy_va_layout),
879 .proc_handler = &proc_dointvec,
880 .strategy = &sysctl_intvec,
886 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
887 .procname = "swap_token_timeout",
888 .data = &swap_token_default_timeout,
889 .maxlen = sizeof(swap_token_default_timeout),
891 .proc_handler = &proc_dointvec_jiffies,
892 .strategy = &sysctl_jiffies,
898 static ctl_table proc_table[] = {
902 static ctl_table fs_table[] = {
904 .ctl_name = FS_NRINODE,
905 .procname = "inode-nr",
906 .data = &inodes_stat,
907 .maxlen = 2*sizeof(int),
909 .proc_handler = &proc_dointvec,
912 .ctl_name = FS_STATINODE,
913 .procname = "inode-state",
914 .data = &inodes_stat,
915 .maxlen = 7*sizeof(int),
917 .proc_handler = &proc_dointvec,
920 .ctl_name = FS_NRFILE,
921 .procname = "file-nr",
923 .maxlen = 3*sizeof(int),
925 .proc_handler = &proc_dointvec,
928 .ctl_name = FS_MAXFILE,
929 .procname = "file-max",
930 .data = &files_stat.max_files,
931 .maxlen = sizeof(int),
933 .proc_handler = &proc_dointvec,
936 .ctl_name = FS_DENTRY,
937 .procname = "dentry-state",
938 .data = &dentry_stat,
939 .maxlen = 6*sizeof(int),
941 .proc_handler = &proc_dointvec,
944 .ctl_name = FS_OVERFLOWUID,
945 .procname = "overflowuid",
946 .data = &fs_overflowuid,
947 .maxlen = sizeof(int),
949 .proc_handler = &proc_dointvec_minmax,
950 .strategy = &sysctl_intvec,
951 .extra1 = &minolduid,
952 .extra2 = &maxolduid,
955 .ctl_name = FS_OVERFLOWGID,
956 .procname = "overflowgid",
957 .data = &fs_overflowgid,
958 .maxlen = sizeof(int),
960 .proc_handler = &proc_dointvec_minmax,
961 .strategy = &sysctl_intvec,
962 .extra1 = &minolduid,
963 .extra2 = &maxolduid,
966 .ctl_name = FS_LEASES,
967 .procname = "leases-enable",
968 .data = &leases_enable,
969 .maxlen = sizeof(int),
971 .proc_handler = &proc_dointvec,
973 #ifdef CONFIG_DNOTIFY
975 .ctl_name = FS_DIR_NOTIFY,
976 .procname = "dir-notify-enable",
977 .data = &dir_notify_enable,
978 .maxlen = sizeof(int),
980 .proc_handler = &proc_dointvec,
984 .ctl_name = FS_LEASE_TIME,
985 .procname = "lease-break-time",
986 .data = &lease_break_time,
987 .maxlen = sizeof(int),
989 .proc_handler = &proc_dointvec,
992 .ctl_name = FS_AIO_NR,
993 .procname = "aio-nr",
995 .maxlen = sizeof(aio_nr),
997 .proc_handler = &proc_dointvec,
1000 .ctl_name = FS_AIO_MAX_NR,
1001 .procname = "aio-max-nr",
1002 .data = &aio_max_nr,
1003 .maxlen = sizeof(aio_max_nr),
1005 .proc_handler = &proc_dointvec,
1010 static ctl_table debug_table[] = {
1014 static ctl_table dev_table[] = {
1018 extern void init_irq_proc (void);
1020 void __init sysctl_init(void)
1022 #ifdef CONFIG_PROC_FS
1023 register_proc_table(root_table, proc_sys_root);
1028 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1029 void __user *newval, size_t newlen)
1031 struct list_head *tmp;
1033 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1037 if (!oldlenp || get_user(old_len, oldlenp))
1040 tmp = &root_table_header.ctl_entry;
1042 struct ctl_table_header *head =
1043 list_entry(tmp, struct ctl_table_header, ctl_entry);
1044 void *context = NULL;
1045 int error = parse_table(name, nlen, oldval, oldlenp,
1046 newval, newlen, head->ctl_table,
1050 if (error != -ENOTDIR)
1053 } while (tmp != &root_table_header.ctl_entry);
1057 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1059 struct __sysctl_args tmp;
1062 if (copy_from_user(&tmp, args, sizeof(tmp)))
1066 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1067 tmp.newval, tmp.newlen);
1073 * ctl_perm does NOT grant the superuser all rights automatically, because
1074 * some sysctl variables are readonly even to root.
1077 static int test_perm(int mode, int op)
1081 else if (in_egroup_p(0))
1083 if ((mode & op & 0007) == op)
1088 static inline int ctl_perm(ctl_table *table, int op)
1091 error = security_sysctl(table, op);
1094 return test_perm(table->mode, op);
1097 static int parse_table(int __user *name, int nlen,
1098 void __user *oldval, size_t __user *oldlenp,
1099 void __user *newval, size_t newlen,
1100 ctl_table *table, void **context)
1106 if (get_user(n, name))
1108 for ( ; table->ctl_name; table++) {
1109 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1112 if (ctl_perm(table, 001))
1114 if (table->strategy) {
1115 error = table->strategy(
1118 newval, newlen, context);
1124 table = table->child;
1127 error = do_sysctl_strategy(table, name, nlen,
1129 newval, newlen, context);
1136 /* Perform the actual read/write of a sysctl table entry. */
1137 int do_sysctl_strategy (ctl_table *table,
1138 int __user *name, int nlen,
1139 void __user *oldval, size_t __user *oldlenp,
1140 void __user *newval, size_t newlen, void **context)
1149 if (ctl_perm(table, op))
1152 if (table->strategy) {
1153 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1154 newval, newlen, context);
1161 /* If there is no strategy routine, or if the strategy returns
1162 * zero, proceed with automatic r/w */
1163 if (table->data && table->maxlen) {
1164 if (oldval && oldlenp) {
1165 if (get_user(len, oldlenp))
1168 if (len > table->maxlen)
1169 len = table->maxlen;
1170 if(copy_to_user(oldval, table->data, len))
1172 if(put_user(len, oldlenp))
1176 if (newval && newlen) {
1178 if (len > table->maxlen)
1179 len = table->maxlen;
1180 if(copy_from_user(table->data, newval, len))
1188 * register_sysctl_table - register a sysctl hierarchy
1189 * @table: the top-level table structure
1190 * @insert_at_head: whether the entry should be inserted in front or at the end
1192 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1193 * array. An entry with a ctl_name of 0 terminates the table.
1195 * The members of the &ctl_table structure are used as follows:
1197 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1198 * must be unique within that level of sysctl
1200 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1201 * enter a sysctl file
1203 * data - a pointer to data for use by proc_handler
1205 * maxlen - the maximum size in bytes of the data
1207 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1209 * child - a pointer to the child sysctl table if this entry is a directory, or
1212 * proc_handler - the text handler routine (described below)
1214 * strategy - the strategy routine (described below)
1216 * de - for internal use by the sysctl routines
1218 * extra1, extra2 - extra pointers usable by the proc handler routines
1220 * Leaf nodes in the sysctl tree will be represented by a single file
1221 * under /proc; non-leaf nodes will be represented by directories.
1223 * sysctl(2) can automatically manage read and write requests through
1224 * the sysctl table. The data and maxlen fields of the ctl_table
1225 * struct enable minimal validation of the values being written to be
1226 * performed, and the mode field allows minimal authentication.
1228 * More sophisticated management can be enabled by the provision of a
1229 * strategy routine with the table entry. This will be called before
1230 * any automatic read or write of the data is performed.
1232 * The strategy routine may return
1234 * < 0 - Error occurred (error is passed to user process)
1236 * 0 - OK - proceed with automatic read or write.
1238 * > 0 - OK - read or write has been done by the strategy routine, so
1239 * return immediately.
1241 * There must be a proc_handler routine for any terminal nodes
1242 * mirrored under /proc/sys (non-terminals are handled by a built-in
1243 * directory handler). Several default handlers are available to
1244 * cover common cases -
1246 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1247 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1248 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1250 * It is the handler's job to read the input buffer from user memory
1251 * and process it. The handler should return 0 on success.
1253 * This routine returns %NULL on a failure to register, and a pointer
1254 * to the table header on success.
1256 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1259 struct ctl_table_header *tmp;
1260 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1263 tmp->ctl_table = table;
1264 INIT_LIST_HEAD(&tmp->ctl_entry);
1266 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1268 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1269 #ifdef CONFIG_PROC_FS
1270 register_proc_table(table, proc_sys_root);
1276 * unregister_sysctl_table - unregister a sysctl table hierarchy
1277 * @header: the header returned from register_sysctl_table
1279 * Unregisters the sysctl table and all children. proc entries may not
1280 * actually be removed until they are no longer used by anyone.
1282 void unregister_sysctl_table(struct ctl_table_header * header)
1284 list_del(&header->ctl_entry);
1285 #ifdef CONFIG_PROC_FS
1286 unregister_proc_table(header->ctl_table, proc_sys_root);
1295 #ifdef CONFIG_PROC_FS
1297 /* Scan the sysctl entries in table and add them all into /proc */
1298 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1300 struct proc_dir_entry *de;
1304 for (; table->ctl_name; table++) {
1305 /* Can't do anything without a proc name. */
1306 if (!table->procname)
1308 /* Maybe we can't do anything with it... */
1309 if (!table->proc_handler && !table->child) {
1310 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1315 len = strlen(table->procname);
1319 if (table->proc_handler)
1323 for (de = root->subdir; de; de = de->next) {
1324 if (proc_match(len, table->procname, de))
1327 /* If the subdir exists already, de is non-NULL */
1331 de = create_proc_entry(table->procname, mode, root);
1334 de->data = (void *) table;
1335 if (table->proc_handler)
1336 de->proc_fops = &proc_sys_file_operations;
1339 if (de->mode & S_IFDIR)
1340 register_proc_table(table->child, de);
1345 * Unregister a /proc sysctl table and any subdirectories.
1347 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1349 struct proc_dir_entry *de;
1350 for (; table->ctl_name; table++) {
1351 if (!(de = table->de))
1353 if (de->mode & S_IFDIR) {
1354 if (!table->child) {
1355 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1358 unregister_proc_table(table->child, de);
1360 /* Don't unregister directories which still have entries.. */
1365 /* Don't unregister proc entries that are still being used.. */
1366 if (atomic_read(&de->count))
1370 remove_proc_entry(table->procname, root);
1374 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1375 size_t count, loff_t *ppos)
1378 struct proc_dir_entry *de;
1379 struct ctl_table *table;
1383 de = PDE(file->f_dentry->d_inode);
1384 if (!de || !de->data)
1386 table = (struct ctl_table *) de->data;
1387 if (!table || !table->proc_handler)
1389 op = (write ? 002 : 004);
1390 if (ctl_perm(table, op))
1395 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1401 static int proc_opensys(struct inode *inode, struct file *file)
1403 if (file->f_mode & FMODE_WRITE) {
1405 * sysctl entries that are not writable,
1406 * are _NOT_ writable, capabilities or not.
1408 if (!(inode->i_mode & S_IWUSR))
1415 static ssize_t proc_readsys(struct file * file, char __user * buf,
1416 size_t count, loff_t *ppos)
1418 return do_rw_proc(0, file, buf, count, ppos);
1421 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1422 size_t count, loff_t *ppos)
1424 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1428 * proc_dostring - read a string sysctl
1429 * @table: the sysctl table
1430 * @write: %TRUE if this is a write to the sysctl file
1431 * @filp: the file structure
1432 * @buffer: the user buffer
1433 * @lenp: the size of the user buffer
1435 * Reads/writes a string from/to the user buffer. If the kernel
1436 * buffer provided is not large enough to hold the string, the
1437 * string is truncated. The copied string is %NULL-terminated.
1438 * If the string is being read by the user process, it is copied
1439 * and a newline '\n' is added. It is truncated if the buffer is
1442 * Returns 0 on success.
1444 int proc_dostring(ctl_table *table, int write, struct file *filp,
1445 void __user *buffer, size_t *lenp, loff_t *ppos)
1451 if (!table->data || !table->maxlen || !*lenp ||
1452 (*ppos && !write)) {
1460 while (len < *lenp) {
1461 if (get_user(c, p++))
1463 if (c == 0 || c == '\n')
1467 if (len >= table->maxlen)
1468 len = table->maxlen-1;
1469 if(copy_from_user(table->data, buffer, len))
1471 ((char *) table->data)[len] = 0;
1474 len = strlen(table->data);
1475 if (len > table->maxlen)
1476 len = table->maxlen;
1480 if(copy_to_user(buffer, table->data, len))
1483 if(put_user('\n', ((char __user *) buffer) + len))
1494 * Special case of dostring for the UTS structure. This has locks
1495 * to observe. Should this be in kernel/sys.c ????
1498 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1499 void __user *buffer, size_t *lenp, loff_t *ppos)
1504 down_read(&uts_sem);
1505 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1508 down_write(&uts_sem);
1509 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1515 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1517 int write, void *data)
1520 *valp = *negp ? -*lvalp : *lvalp;
1525 *lvalp = (unsigned long)-val;
1528 *lvalp = (unsigned long)val;
1534 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1535 void __user *buffer, size_t *lenp, loff_t *ppos,
1536 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1537 int write, void *data),
1540 #define TMPBUFLEN 21
1541 int *i, vleft, first=1, neg, val;
1545 char buf[TMPBUFLEN], *p;
1546 char __user *s = buffer;
1548 if (!table->data || !table->maxlen || !*lenp ||
1549 (*ppos && !write)) {
1554 i = (int *) table->data;
1555 vleft = table->maxlen / sizeof(*i);
1559 conv = do_proc_dointvec_conv;
1561 for (; left && vleft--; i++, first=0) {
1576 if (len > sizeof(buf) - 1)
1577 len = sizeof(buf) - 1;
1578 if (copy_from_user(buf, s, len))
1582 if (*p == '-' && left > 1) {
1586 if (*p < '0' || *p > '9')
1589 lval = simple_strtoul(p, &p, 0);
1592 if ((len < left) && *p && !isspace(*p))
1599 if (conv(&neg, &lval, i, 1, data))
1606 if (conv(&neg, &lval, i, 0, data))
1609 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1613 if(copy_to_user(s, buf, len))
1620 if (!write && !first && left) {
1621 if(put_user('\n', s))
1628 if (get_user(c, s++))
1644 * proc_dointvec - read a vector of integers
1645 * @table: the sysctl table
1646 * @write: %TRUE if this is a write to the sysctl file
1647 * @filp: the file structure
1648 * @buffer: the user buffer
1649 * @lenp: the size of the user buffer
1651 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1652 * values from/to the user buffer, treated as an ASCII string.
1654 * Returns 0 on success.
1656 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1657 void __user *buffer, size_t *lenp, loff_t *ppos)
1659 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1669 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1671 int write, void *data)
1673 int op = *(int *)data;
1675 int val = *negp ? -*lvalp : *lvalp;
1677 case OP_SET: *valp = val; break;
1678 case OP_AND: *valp &= val; break;
1679 case OP_OR: *valp |= val; break;
1680 case OP_MAX: if(*valp < val)
1683 case OP_MIN: if(*valp > val)
1691 *lvalp = (unsigned long)-val;
1694 *lvalp = (unsigned long)val;
1701 * init may raise the set.
1704 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1705 void __user *buffer, size_t *lenp, loff_t *ppos)
1709 if (!capable(CAP_SYS_MODULE)) {
1713 op = (current->pid == 1) ? OP_SET : OP_AND;
1714 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1715 do_proc_dointvec_bset_conv,&op);
1718 struct do_proc_dointvec_minmax_conv_param {
1723 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1725 int write, void *data)
1727 struct do_proc_dointvec_minmax_conv_param *param = data;
1729 int val = *negp ? -*lvalp : *lvalp;
1730 if ((param->min && *param->min > val) ||
1731 (param->max && *param->max < val))
1738 *lvalp = (unsigned long)-val;
1741 *lvalp = (unsigned long)val;
1748 * proc_dointvec_minmax - read a vector of integers with min/max values
1749 * @table: the sysctl table
1750 * @write: %TRUE if this is a write to the sysctl file
1751 * @filp: the file structure
1752 * @buffer: the user buffer
1753 * @lenp: the size of the user buffer
1755 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1756 * values from/to the user buffer, treated as an ASCII string.
1758 * This routine will ensure the values are within the range specified by
1759 * table->extra1 (min) and table->extra2 (max).
1761 * Returns 0 on success.
1763 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1764 void __user *buffer, size_t *lenp, loff_t *ppos)
1766 struct do_proc_dointvec_minmax_conv_param param = {
1767 .min = (int *) table->extra1,
1768 .max = (int *) table->extra2,
1770 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1771 do_proc_dointvec_minmax_conv, ¶m);
1774 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1776 void __user *buffer,
1777 size_t *lenp, loff_t *ppos,
1778 unsigned long convmul,
1779 unsigned long convdiv)
1781 #define TMPBUFLEN 21
1782 unsigned long *i, *min, *max, val;
1783 int vleft, first=1, neg;
1785 char buf[TMPBUFLEN], *p;
1786 char __user *s = buffer;
1788 if (!table->data || !table->maxlen || !*lenp ||
1789 (*ppos && !write)) {
1794 i = (unsigned long *) table->data;
1795 min = (unsigned long *) table->extra1;
1796 max = (unsigned long *) table->extra2;
1797 vleft = table->maxlen / sizeof(unsigned long);
1800 for (; left && vleft--; i++, min++, max++, first=0) {
1815 if (len > TMPBUFLEN-1)
1817 if (copy_from_user(buf, s, len))
1821 if (*p == '-' && left > 1) {
1825 if (*p < '0' || *p > '9')
1827 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1829 if ((len < left) && *p && !isspace(*p))
1838 if ((min && val < *min) || (max && val > *max))
1845 sprintf(p, "%lu", convdiv * (*i) / convmul);
1849 if(copy_to_user(s, buf, len))
1856 if (!write && !first && left) {
1857 if(put_user('\n', s))
1864 if (get_user(c, s++))
1880 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1881 * @table: the sysctl table
1882 * @write: %TRUE if this is a write to the sysctl file
1883 * @filp: the file structure
1884 * @buffer: the user buffer
1885 * @lenp: the size of the user buffer
1887 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1888 * values from/to the user buffer, treated as an ASCII string.
1890 * This routine will ensure the values are within the range specified by
1891 * table->extra1 (min) and table->extra2 (max).
1893 * Returns 0 on success.
1895 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1896 void __user *buffer, size_t *lenp, loff_t *ppos)
1898 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1902 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1903 * @table: the sysctl table
1904 * @write: %TRUE if this is a write to the sysctl file
1905 * @filp: the file structure
1906 * @buffer: the user buffer
1907 * @lenp: the size of the user buffer
1909 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1910 * values from/to the user buffer, treated as an ASCII string. The values
1911 * are treated as milliseconds, and converted to jiffies when they are stored.
1913 * This routine will ensure the values are within the range specified by
1914 * table->extra1 (min) and table->extra2 (max).
1916 * Returns 0 on success.
1918 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1920 void __user *buffer,
1921 size_t *lenp, loff_t *ppos)
1923 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1924 lenp, ppos, HZ, 1000l);
1928 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1930 int write, void *data)
1933 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1939 lval = (unsigned long)-val;
1942 lval = (unsigned long)val;
1949 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1951 int write, void *data)
1954 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1960 lval = (unsigned long)-val;
1963 lval = (unsigned long)val;
1965 *lvalp = jiffies_to_clock_t(lval);
1971 * proc_dointvec_jiffies - read a vector of integers as seconds
1972 * @table: the sysctl table
1973 * @write: %TRUE if this is a write to the sysctl file
1974 * @filp: the file structure
1975 * @buffer: the user buffer
1976 * @lenp: the size of the user buffer
1978 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1979 * values from/to the user buffer, treated as an ASCII string.
1980 * The values read are assumed to be in seconds, and are converted into
1983 * Returns 0 on success.
1985 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1986 void __user *buffer, size_t *lenp, loff_t *ppos)
1988 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1989 do_proc_dointvec_jiffies_conv,NULL);
1993 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1994 * @table: the sysctl table
1995 * @write: %TRUE if this is a write to the sysctl file
1996 * @filp: the file structure
1997 * @buffer: the user buffer
1998 * @lenp: the size of the user buffer
2000 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2001 * values from/to the user buffer, treated as an ASCII string.
2002 * The values read are assumed to be in 1/USER_HZ seconds, and
2003 * are converted into jiffies.
2005 * Returns 0 on success.
2007 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2008 void __user *buffer, size_t *lenp, loff_t *ppos)
2010 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2011 do_proc_dointvec_userhz_jiffies_conv,NULL);
2014 #else /* CONFIG_PROC_FS */
2016 int proc_dostring(ctl_table *table, int write, struct file *filp,
2017 void __user *buffer, size_t *lenp, loff_t *ppos)
2022 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2023 void __user *buffer, size_t *lenp, loff_t *ppos)
2028 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2029 void __user *buffer, size_t *lenp, loff_t *ppos)
2034 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2035 void __user *buffer, size_t *lenp, loff_t *ppos)
2040 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2041 void __user *buffer, size_t *lenp, loff_t *ppos)
2046 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2047 void __user *buffer, size_t *lenp, loff_t *ppos)
2052 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2053 void __user *buffer, size_t *lenp, loff_t *ppos)
2058 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2059 void __user *buffer, size_t *lenp, loff_t *ppos)
2064 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2066 void __user *buffer,
2067 size_t *lenp, loff_t *ppos)
2073 #endif /* CONFIG_PROC_FS */
2077 * General sysctl support routines
2080 /* The generic string strategy routine: */
2081 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2082 void __user *oldval, size_t __user *oldlenp,
2083 void __user *newval, size_t newlen, void **context)
2087 if (!table->data || !table->maxlen)
2090 if (oldval && oldlenp) {
2091 if (get_user(len, oldlenp))
2094 l = strlen(table->data);
2095 if (len > l) len = l;
2096 if (len >= table->maxlen)
2097 len = table->maxlen;
2098 if(copy_to_user(oldval, table->data, len))
2100 if(put_user(0, ((char __user *) oldval) + len))
2102 if(put_user(len, oldlenp))
2106 if (newval && newlen) {
2108 if (len > table->maxlen)
2109 len = table->maxlen;
2110 if(copy_from_user(table->data, newval, len))
2112 if (len == table->maxlen)
2114 ((char *) table->data)[len] = 0;
2120 * This function makes sure that all of the integers in the vector
2121 * are between the minimum and maximum values given in the arrays
2122 * table->extra1 and table->extra2, respectively.
2124 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2125 void __user *oldval, size_t __user *oldlenp,
2126 void __user *newval, size_t newlen, void **context)
2129 if (newval && newlen) {
2130 int __user *vec = (int __user *) newval;
2131 int *min = (int *) table->extra1;
2132 int *max = (int *) table->extra2;
2136 if (newlen % sizeof(int) != 0)
2139 if (!table->extra1 && !table->extra2)
2142 if (newlen > table->maxlen)
2143 newlen = table->maxlen;
2144 length = newlen / sizeof(int);
2146 for (i = 0; i < length; i++) {
2148 if (get_user(value, vec + i))
2150 if (min && value < min[i])
2152 if (max && value > max[i])
2159 /* Strategy function to convert jiffies to seconds */
2160 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2161 void __user *oldval, size_t __user *oldlenp,
2162 void __user *newval, size_t newlen, void **context)
2167 if (get_user(olen, oldlenp))
2169 if (olen!=sizeof(int))
2172 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2173 (oldlenp && put_user(sizeof(int),oldlenp)))
2176 if (newval && newlen) {
2178 if (newlen != sizeof(int))
2180 if (get_user(new, (int __user *)newval))
2182 *(int *)(table->data) = new*HZ;
2188 #else /* CONFIG_SYSCTL */
2191 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2196 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2197 void __user *oldval, size_t __user *oldlenp,
2198 void __user *newval, size_t newlen, void **context)
2203 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2204 void __user *oldval, size_t __user *oldlenp,
2205 void __user *newval, size_t newlen, void **context)
2210 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2211 void __user *oldval, size_t __user *oldlenp,
2212 void __user *newval, size_t newlen, void **context)
2217 int proc_dostring(ctl_table *table, int write, struct file *filp,
2218 void __user *buffer, size_t *lenp, loff_t *ppos)
2223 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2229 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2230 void __user *buffer, size_t *lenp, loff_t *ppos)
2235 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2236 void __user *buffer, size_t *lenp, loff_t *ppos)
2241 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2242 void __user *buffer, size_t *lenp, loff_t *ppos)
2247 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2248 void __user *buffer, size_t *lenp, loff_t *ppos)
2253 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2254 void __user *buffer, size_t *lenp, loff_t *ppos)
2259 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2261 void __user *buffer,
2262 size_t *lenp, loff_t *ppos)
2267 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2273 void unregister_sysctl_table(struct ctl_table_header * table)
2277 #endif /* CONFIG_SYSCTL */
2280 * No sense putting this after each symbol definition, twice,
2281 * exception granted :-)
2283 EXPORT_SYMBOL(proc_dointvec);
2284 EXPORT_SYMBOL(proc_dointvec_jiffies);
2285 EXPORT_SYMBOL(proc_dointvec_minmax);
2286 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2287 EXPORT_SYMBOL(proc_dostring);
2288 EXPORT_SYMBOL(proc_doulongvec_minmax);
2289 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2290 EXPORT_SYMBOL(register_sysctl_table);
2291 EXPORT_SYMBOL(sysctl_intvec);
2292 EXPORT_SYMBOL(sysctl_jiffies);
2293 EXPORT_SYMBOL(sysctl_string);
2294 EXPORT_SYMBOL(unregister_sysctl_table);