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>
44 #include <linux/vserver/cvirt.h>
46 #include <asm/uaccess.h>
47 #include <asm/processor.h>
49 #ifdef CONFIG_ROOT_NFS
50 #include <linux/nfs_fs.h>
53 #if defined(CONFIG_SYSCTL)
55 /* External variables not in a header file. */
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 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 extern char vshelper_path[];
89 #ifdef CONFIG_CHR_DEV_SG
90 extern int sg_big_buff;
93 extern size_t shm_ctlmax;
94 extern size_t shm_ctlall;
95 extern int shm_ctlmni;
96 extern int msg_ctlmax;
97 extern int msg_ctlmnb;
98 extern int msg_ctlmni;
99 extern int sem_ctls[];
103 extern char reboot_command [];
104 extern int stop_a_enabled;
105 extern int scons_pwroff;
109 extern int pwrsw_enabled;
110 extern int unaligned_enabled;
113 #ifdef CONFIG_ARCH_S390
114 #ifdef CONFIG_MATHEMU
115 extern int sysctl_ieee_emulation_warnings;
117 extern int sysctl_userprocess_debug;
120 extern int sysctl_hz_timer;
122 #ifdef CONFIG_BSD_PROCESS_ACCT
123 extern int acct_parm[];
126 int randomize_va_space = 1;
128 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
129 ctl_table *, void **);
130 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
131 void __user *buffer, size_t *lenp, loff_t *ppos);
133 static ctl_table root_table[];
134 static struct ctl_table_header root_table_header =
135 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
137 static ctl_table kern_table[];
138 static ctl_table vm_table[];
140 extern ctl_table net_table[];
142 static ctl_table proc_table[];
143 static ctl_table fs_table[];
144 static ctl_table debug_table[];
145 static ctl_table dev_table[];
146 extern ctl_table random_table[];
147 #ifdef CONFIG_UNIX98_PTYS
148 extern ctl_table pty_table[];
151 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
152 int sysctl_legacy_va_layout;
155 /* /proc declarations: */
157 #ifdef CONFIG_PROC_FS
159 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
160 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
161 static int proc_opensys(struct inode *, struct file *);
163 struct file_operations proc_sys_file_operations = {
164 .open = proc_opensys,
165 .read = proc_readsys,
166 .write = proc_writesys,
169 extern struct proc_dir_entry *proc_sys_root;
171 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
172 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
175 /* The default sysctl tables: */
177 static ctl_table root_table[] = {
179 .ctl_name = CTL_KERN,
180 .procname = "kernel",
199 .ctl_name = CTL_PROC,
211 .ctl_name = CTL_DEBUG,
214 .child = debug_table,
225 static ctl_table kern_table[] = {
227 .ctl_name = KERN_OSTYPE,
228 .procname = "ostype",
229 .data = system_utsname.sysname,
230 .maxlen = sizeof(system_utsname.sysname),
232 .proc_handler = &proc_doutsstring,
233 .virt_handler = &vx_uts_virt_handler,
234 .strategy = &sysctl_string,
237 .ctl_name = KERN_OSRELEASE,
238 .procname = "osrelease",
239 .data = system_utsname.release,
240 .maxlen = sizeof(system_utsname.release),
242 .proc_handler = &proc_doutsstring,
243 .virt_handler = &vx_uts_virt_handler,
244 .strategy = &sysctl_string,
247 .ctl_name = KERN_VERSION,
248 .procname = "version",
249 .data = system_utsname.version,
250 .maxlen = sizeof(system_utsname.version),
252 .proc_handler = &proc_doutsstring,
253 .virt_handler = &vx_uts_virt_handler,
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 .virt_handler = &vx_uts_virt_handler,
264 .strategy = &sysctl_string,
267 .ctl_name = KERN_DOMAINNAME,
268 .procname = "domainname",
269 .data = system_utsname.domainname,
270 .maxlen = sizeof(system_utsname.domainname),
272 .proc_handler = &proc_doutsstring,
273 .virt_handler = &vx_uts_virt_handler,
274 .strategy = &sysctl_string,
277 .ctl_name = KERN_PANIC,
279 .data = &panic_timeout,
280 .maxlen = sizeof(int),
282 .proc_handler = &proc_dointvec,
285 .ctl_name = KERN_CORE_USES_PID,
286 .procname = "core_uses_pid",
287 .data = &core_uses_pid,
288 .maxlen = sizeof(int),
290 .proc_handler = &proc_dointvec,
293 .ctl_name = KERN_CORE_PATTERN,
294 .procname = "core_pattern",
295 .data = core_pattern,
298 .proc_handler = &proc_dostring,
299 .strategy = &sysctl_string,
302 .ctl_name = KERN_TAINTED,
303 .procname = "tainted",
305 .maxlen = sizeof(int),
307 .proc_handler = &proc_dointvec,
310 .ctl_name = KERN_CAP_BSET,
311 .procname = "cap-bound",
313 .maxlen = sizeof(kernel_cap_t),
315 .proc_handler = &proc_dointvec_bset,
317 #ifdef CONFIG_BLK_DEV_INITRD
319 .ctl_name = KERN_REALROOTDEV,
320 .procname = "real-root-dev",
321 .data = &real_root_dev,
322 .maxlen = sizeof(int),
324 .proc_handler = &proc_dointvec,
329 .ctl_name = KERN_SPARC_REBOOT,
330 .procname = "reboot-cmd",
331 .data = reboot_command,
334 .proc_handler = &proc_dostring,
335 .strategy = &sysctl_string,
338 .ctl_name = KERN_SPARC_STOP_A,
339 .procname = "stop-a",
340 .data = &stop_a_enabled,
341 .maxlen = sizeof (int),
343 .proc_handler = &proc_dointvec,
346 .ctl_name = KERN_SPARC_SCONS_PWROFF,
347 .procname = "scons-poweroff",
348 .data = &scons_pwroff,
349 .maxlen = sizeof (int),
351 .proc_handler = &proc_dointvec,
356 .ctl_name = KERN_HPPA_PWRSW,
357 .procname = "soft-power",
358 .data = &pwrsw_enabled,
359 .maxlen = sizeof (int),
361 .proc_handler = &proc_dointvec,
364 .ctl_name = KERN_HPPA_UNALIGNED,
365 .procname = "unaligned-trap",
366 .data = &unaligned_enabled,
367 .maxlen = sizeof (int),
369 .proc_handler = &proc_dointvec,
373 .ctl_name = KERN_CTLALTDEL,
374 .procname = "ctrl-alt-del",
376 .maxlen = sizeof(int),
378 .proc_handler = &proc_dointvec,
381 .ctl_name = KERN_PRINTK,
382 .procname = "printk",
383 .data = &console_loglevel,
384 .maxlen = 4*sizeof(int),
386 .proc_handler = &proc_dointvec,
390 .ctl_name = KERN_MODPROBE,
391 .procname = "modprobe",
392 .data = &modprobe_path,
393 .maxlen = KMOD_PATH_LEN,
395 .proc_handler = &proc_dostring,
396 .strategy = &sysctl_string,
399 #ifdef CONFIG_HOTPLUG
401 .ctl_name = KERN_HOTPLUG,
402 .procname = "hotplug",
403 .data = &hotplug_path,
404 .maxlen = HOTPLUG_PATH_LEN,
406 .proc_handler = &proc_dostring,
407 .strategy = &sysctl_string,
411 .ctl_name = KERN_VSHELPER,
412 .procname = "vshelper",
413 .data = &vshelper_path,
416 .proc_handler = &proc_dostring,
417 .strategy = &sysctl_string,
419 #ifdef CONFIG_CHR_DEV_SG
421 .ctl_name = KERN_SG_BIG_BUFF,
422 .procname = "sg-big-buff",
423 .data = &sg_big_buff,
424 .maxlen = sizeof (int),
426 .proc_handler = &proc_dointvec,
429 #ifdef CONFIG_BSD_PROCESS_ACCT
431 .ctl_name = KERN_ACCT,
434 .maxlen = 3*sizeof(int),
436 .proc_handler = &proc_dointvec,
439 #ifdef CONFIG_SYSVIPC
441 .ctl_name = KERN_SHMMAX,
442 .procname = "shmmax",
444 .maxlen = sizeof (size_t),
446 .proc_handler = &proc_doulongvec_minmax,
449 .ctl_name = KERN_SHMALL,
450 .procname = "shmall",
452 .maxlen = sizeof (size_t),
454 .proc_handler = &proc_doulongvec_minmax,
457 .ctl_name = KERN_SHMMNI,
458 .procname = "shmmni",
460 .maxlen = sizeof (int),
462 .proc_handler = &proc_dointvec,
465 .ctl_name = KERN_MSGMAX,
466 .procname = "msgmax",
468 .maxlen = sizeof (int),
470 .proc_handler = &proc_dointvec,
473 .ctl_name = KERN_MSGMNI,
474 .procname = "msgmni",
476 .maxlen = sizeof (int),
478 .proc_handler = &proc_dointvec,
481 .ctl_name = KERN_MSGMNB,
482 .procname = "msgmnb",
484 .maxlen = sizeof (int),
486 .proc_handler = &proc_dointvec,
489 .ctl_name = KERN_SEM,
492 .maxlen = 4*sizeof (int),
494 .proc_handler = &proc_dointvec,
497 #ifdef CONFIG_MAGIC_SYSRQ
499 .ctl_name = KERN_SYSRQ,
501 .data = &sysrq_enabled,
502 .maxlen = sizeof (int),
504 .proc_handler = &proc_dointvec,
508 .ctl_name = KERN_CADPID,
509 .procname = "cad_pid",
511 .maxlen = sizeof (int),
513 .proc_handler = &proc_dointvec,
516 .ctl_name = KERN_MAX_THREADS,
517 .procname = "threads-max",
518 .data = &max_threads,
519 .maxlen = sizeof(int),
521 .proc_handler = &proc_dointvec,
524 .ctl_name = KERN_RANDOM,
525 .procname = "random",
527 .child = random_table,
529 #ifdef CONFIG_UNIX98_PTYS
531 .ctl_name = KERN_PTY,
538 .ctl_name = KERN_OVERFLOWUID,
539 .procname = "overflowuid",
540 .data = &overflowuid,
541 .maxlen = sizeof(int),
543 .proc_handler = &proc_dointvec_minmax,
544 .strategy = &sysctl_intvec,
545 .extra1 = &minolduid,
546 .extra2 = &maxolduid,
549 .ctl_name = KERN_OVERFLOWGID,
550 .procname = "overflowgid",
551 .data = &overflowgid,
552 .maxlen = sizeof(int),
554 .proc_handler = &proc_dointvec_minmax,
555 .strategy = &sysctl_intvec,
556 .extra1 = &minolduid,
557 .extra2 = &maxolduid,
559 #ifdef CONFIG_ARCH_S390
560 #ifdef CONFIG_MATHEMU
562 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
563 .procname = "ieee_emulation_warnings",
564 .data = &sysctl_ieee_emulation_warnings,
565 .maxlen = sizeof(int),
567 .proc_handler = &proc_dointvec,
570 #ifdef CONFIG_NO_IDLE_HZ
572 .ctl_name = KERN_HZ_TIMER,
573 .procname = "hz_timer",
574 .data = &sysctl_hz_timer,
575 .maxlen = sizeof(int),
577 .proc_handler = &proc_dointvec,
581 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
582 .procname = "userprocess_debug",
583 .data = &sysctl_userprocess_debug,
584 .maxlen = sizeof(int),
586 .proc_handler = &proc_dointvec,
590 .ctl_name = KERN_PIDMAX,
591 .procname = "pid_max",
593 .maxlen = sizeof (int),
595 .proc_handler = &proc_dointvec_minmax,
596 .strategy = sysctl_intvec,
597 .extra1 = &pid_max_min,
598 .extra2 = &pid_max_max,
601 .ctl_name = KERN_PANIC_ON_OOPS,
602 .procname = "panic_on_oops",
603 .data = &panic_on_oops,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
609 .ctl_name = KERN_PRINTK_RATELIMIT,
610 .procname = "printk_ratelimit",
611 .data = &printk_ratelimit_jiffies,
612 .maxlen = sizeof(int),
614 .proc_handler = &proc_dointvec_jiffies,
615 .strategy = &sysctl_jiffies,
618 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
619 .procname = "printk_ratelimit_burst",
620 .data = &printk_ratelimit_burst,
621 .maxlen = sizeof(int),
623 .proc_handler = &proc_dointvec,
626 .ctl_name = KERN_NGROUPS_MAX,
627 .procname = "ngroups_max",
628 .data = &ngroups_max,
629 .maxlen = sizeof (int),
631 .proc_handler = &proc_dointvec,
633 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
635 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
636 .procname = "unknown_nmi_panic",
637 .data = &unknown_nmi_panic,
638 .maxlen = sizeof (int),
640 .proc_handler = &proc_unknown_nmi_panic,
643 #if defined(CONFIG_X86)
645 .ctl_name = KERN_BOOTLOADER_TYPE,
646 .procname = "bootloader_type",
647 .data = &bootloader_type,
648 .maxlen = sizeof (int),
650 .proc_handler = &proc_dointvec,
654 .ctl_name = KERN_RANDOMIZE,
655 .procname = "randomize_va_space",
656 .data = &randomize_va_space,
657 .maxlen = sizeof(int),
659 .proc_handler = &proc_dointvec,
665 /* Constants for minimum and maximum testing in vm_table.
666 We use these as one-element integer vectors. */
668 static int one_hundred = 100;
671 static ctl_table vm_table[] = {
673 .ctl_name = VM_OVERCOMMIT_MEMORY,
674 .procname = "overcommit_memory",
675 .data = &sysctl_overcommit_memory,
676 .maxlen = sizeof(sysctl_overcommit_memory),
678 .proc_handler = &proc_dointvec,
681 .ctl_name = VM_OVERCOMMIT_RATIO,
682 .procname = "overcommit_ratio",
683 .data = &sysctl_overcommit_ratio,
684 .maxlen = sizeof(sysctl_overcommit_ratio),
686 .proc_handler = &proc_dointvec,
689 .ctl_name = VM_PAGE_CLUSTER,
690 .procname = "page-cluster",
691 .data = &page_cluster,
692 .maxlen = sizeof(int),
694 .proc_handler = &proc_dointvec,
697 .ctl_name = VM_DIRTY_BACKGROUND,
698 .procname = "dirty_background_ratio",
699 .data = &dirty_background_ratio,
700 .maxlen = sizeof(dirty_background_ratio),
702 .proc_handler = &proc_dointvec_minmax,
703 .strategy = &sysctl_intvec,
705 .extra2 = &one_hundred,
708 .ctl_name = VM_DIRTY_RATIO,
709 .procname = "dirty_ratio",
710 .data = &vm_dirty_ratio,
711 .maxlen = sizeof(vm_dirty_ratio),
713 .proc_handler = &proc_dointvec_minmax,
714 .strategy = &sysctl_intvec,
716 .extra2 = &one_hundred,
719 .ctl_name = VM_DIRTY_WB_CS,
720 .procname = "dirty_writeback_centisecs",
721 .data = &dirty_writeback_centisecs,
722 .maxlen = sizeof(dirty_writeback_centisecs),
724 .proc_handler = &dirty_writeback_centisecs_handler,
727 .ctl_name = VM_DIRTY_EXPIRE_CS,
728 .procname = "dirty_expire_centisecs",
729 .data = &dirty_expire_centisecs,
730 .maxlen = sizeof(dirty_expire_centisecs),
732 .proc_handler = &proc_dointvec,
735 .ctl_name = VM_NR_PDFLUSH_THREADS,
736 .procname = "nr_pdflush_threads",
737 .data = &nr_pdflush_threads,
738 .maxlen = sizeof nr_pdflush_threads,
739 .mode = 0444 /* read-only*/,
740 .proc_handler = &proc_dointvec,
743 .ctl_name = VM_SWAPPINESS,
744 .procname = "swappiness",
745 .data = &vm_swappiness,
746 .maxlen = sizeof(vm_swappiness),
748 .proc_handler = &proc_dointvec_minmax,
749 .strategy = &sysctl_intvec,
751 .extra2 = &one_hundred,
753 #ifdef CONFIG_HUGETLB_PAGE
755 .ctl_name = VM_HUGETLB_PAGES,
756 .procname = "nr_hugepages",
757 .data = &max_huge_pages,
758 .maxlen = sizeof(unsigned long),
760 .proc_handler = &hugetlb_sysctl_handler,
761 .extra1 = (void *)&hugetlb_zero,
762 .extra2 = (void *)&hugetlb_infinity,
765 .ctl_name = VM_HUGETLB_GROUP,
766 .procname = "hugetlb_shm_group",
767 .data = &sysctl_hugetlb_shm_group,
768 .maxlen = sizeof(gid_t),
770 .proc_handler = &proc_dointvec,
774 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
775 .procname = "lowmem_reserve_ratio",
776 .data = &sysctl_lowmem_reserve_ratio,
777 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
779 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
780 .strategy = &sysctl_intvec,
783 .ctl_name = VM_MIN_FREE_KBYTES,
784 .procname = "min_free_kbytes",
785 .data = &min_free_kbytes,
786 .maxlen = sizeof(min_free_kbytes),
788 .proc_handler = &min_free_kbytes_sysctl_handler,
789 .strategy = &sysctl_intvec,
794 .ctl_name = VM_MAX_MAP_COUNT,
795 .procname = "max_map_count",
796 .data = &sysctl_max_map_count,
797 .maxlen = sizeof(sysctl_max_map_count),
799 .proc_handler = &proc_dointvec
803 .ctl_name = VM_LAPTOP_MODE,
804 .procname = "laptop_mode",
805 .data = &laptop_mode,
806 .maxlen = sizeof(laptop_mode),
808 .proc_handler = &proc_dointvec,
809 .strategy = &sysctl_intvec,
813 .ctl_name = VM_BLOCK_DUMP,
814 .procname = "block_dump",
816 .maxlen = sizeof(block_dump),
818 .proc_handler = &proc_dointvec,
819 .strategy = &sysctl_intvec,
823 .ctl_name = VM_VFS_CACHE_PRESSURE,
824 .procname = "vfs_cache_pressure",
825 .data = &sysctl_vfs_cache_pressure,
826 .maxlen = sizeof(sysctl_vfs_cache_pressure),
828 .proc_handler = &proc_dointvec,
829 .strategy = &sysctl_intvec,
832 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
834 .ctl_name = VM_LEGACY_VA_LAYOUT,
835 .procname = "legacy_va_layout",
836 .data = &sysctl_legacy_va_layout,
837 .maxlen = sizeof(sysctl_legacy_va_layout),
839 .proc_handler = &proc_dointvec,
840 .strategy = &sysctl_intvec,
846 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
847 .procname = "swap_token_timeout",
848 .data = &swap_token_default_timeout,
849 .maxlen = sizeof(swap_token_default_timeout),
851 .proc_handler = &proc_dointvec_jiffies,
852 .strategy = &sysctl_jiffies,
858 static ctl_table proc_table[] = {
862 static ctl_table fs_table[] = {
864 .ctl_name = FS_NRINODE,
865 .procname = "inode-nr",
866 .data = &inodes_stat,
867 .maxlen = 2*sizeof(int),
869 .proc_handler = &proc_dointvec,
872 .ctl_name = FS_STATINODE,
873 .procname = "inode-state",
874 .data = &inodes_stat,
875 .maxlen = 7*sizeof(int),
877 .proc_handler = &proc_dointvec,
880 .ctl_name = FS_NRFILE,
881 .procname = "file-nr",
883 .maxlen = 3*sizeof(int),
885 .proc_handler = &proc_dointvec,
888 .ctl_name = FS_MAXFILE,
889 .procname = "file-max",
890 .data = &files_stat.max_files,
891 .maxlen = sizeof(int),
893 .proc_handler = &proc_dointvec,
896 .ctl_name = FS_DENTRY,
897 .procname = "dentry-state",
898 .data = &dentry_stat,
899 .maxlen = 6*sizeof(int),
901 .proc_handler = &proc_dointvec,
904 .ctl_name = FS_OVERFLOWUID,
905 .procname = "overflowuid",
906 .data = &fs_overflowuid,
907 .maxlen = sizeof(int),
909 .proc_handler = &proc_dointvec_minmax,
910 .strategy = &sysctl_intvec,
911 .extra1 = &minolduid,
912 .extra2 = &maxolduid,
915 .ctl_name = FS_OVERFLOWGID,
916 .procname = "overflowgid",
917 .data = &fs_overflowgid,
918 .maxlen = sizeof(int),
920 .proc_handler = &proc_dointvec_minmax,
921 .strategy = &sysctl_intvec,
922 .extra1 = &minolduid,
923 .extra2 = &maxolduid,
926 .ctl_name = FS_LEASES,
927 .procname = "leases-enable",
928 .data = &leases_enable,
929 .maxlen = sizeof(int),
931 .proc_handler = &proc_dointvec,
933 #ifdef CONFIG_DNOTIFY
935 .ctl_name = FS_DIR_NOTIFY,
936 .procname = "dir-notify-enable",
937 .data = &dir_notify_enable,
938 .maxlen = sizeof(int),
940 .proc_handler = &proc_dointvec,
945 .ctl_name = FS_LEASE_TIME,
946 .procname = "lease-break-time",
947 .data = &lease_break_time,
948 .maxlen = sizeof(int),
950 .proc_handler = &proc_dointvec,
953 .ctl_name = FS_AIO_NR,
954 .procname = "aio-nr",
956 .maxlen = sizeof(aio_nr),
958 .proc_handler = &proc_dointvec,
961 .ctl_name = FS_AIO_MAX_NR,
962 .procname = "aio-max-nr",
964 .maxlen = sizeof(aio_max_nr),
966 .proc_handler = &proc_dointvec,
972 static ctl_table debug_table[] = {
976 static ctl_table dev_table[] = {
980 extern void init_irq_proc (void);
982 void __init sysctl_init(void)
984 #ifdef CONFIG_PROC_FS
985 register_proc_table(root_table, proc_sys_root);
990 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
991 void __user *newval, size_t newlen)
993 struct list_head *tmp;
995 if (nlen <= 0 || nlen >= CTL_MAXNAME)
999 if (!oldlenp || get_user(old_len, oldlenp))
1002 tmp = &root_table_header.ctl_entry;
1004 struct ctl_table_header *head =
1005 list_entry(tmp, struct ctl_table_header, ctl_entry);
1006 void *context = NULL;
1007 int error = parse_table(name, nlen, oldval, oldlenp,
1008 newval, newlen, head->ctl_table,
1012 if (error != -ENOTDIR)
1015 } while (tmp != &root_table_header.ctl_entry);
1019 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1021 struct __sysctl_args tmp;
1024 if (copy_from_user(&tmp, args, sizeof(tmp)))
1028 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1029 tmp.newval, tmp.newlen);
1035 * ctl_perm does NOT grant the superuser all rights automatically, because
1036 * some sysctl variables are readonly even to root.
1039 static int test_perm(int mode, int op)
1043 else if (in_egroup_p(0))
1045 if ((mode & op & 0007) == op)
1050 static inline int ctl_perm(ctl_table *table, int op)
1053 error = security_sysctl(table, op);
1056 return test_perm(table->mode, op);
1059 static int parse_table(int __user *name, int nlen,
1060 void __user *oldval, size_t __user *oldlenp,
1061 void __user *newval, size_t newlen,
1062 ctl_table *table, void **context)
1068 if (get_user(n, name))
1070 for ( ; table->ctl_name; table++) {
1071 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1074 if (ctl_perm(table, 001))
1076 if (table->strategy) {
1077 error = table->strategy(
1080 newval, newlen, context);
1086 table = table->child;
1089 error = do_sysctl_strategy(table, name, nlen,
1091 newval, newlen, context);
1098 /* Perform the actual read/write of a sysctl table entry. */
1099 int do_sysctl_strategy (ctl_table *table,
1100 int __user *name, int nlen,
1101 void __user *oldval, size_t __user *oldlenp,
1102 void __user *newval, size_t newlen, void **context)
1111 if (ctl_perm(table, op))
1114 if (table->strategy) {
1115 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1116 newval, newlen, context);
1123 /* If there is no strategy routine, or if the strategy returns
1124 * zero, proceed with automatic r/w */
1125 if (table->data && table->maxlen) {
1126 if (oldval && oldlenp) {
1127 if (get_user(len, oldlenp))
1130 if (len > table->maxlen)
1131 len = table->maxlen;
1132 if(copy_to_user(oldval, table->data, len))
1134 if(put_user(len, oldlenp))
1138 if (newval && newlen) {
1140 if (len > table->maxlen)
1141 len = table->maxlen;
1142 if(copy_from_user(table->data, newval, len))
1150 * register_sysctl_table - register a sysctl hierarchy
1151 * @table: the top-level table structure
1152 * @insert_at_head: whether the entry should be inserted in front or at the end
1154 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1155 * array. An entry with a ctl_name of 0 terminates the table.
1157 * The members of the &ctl_table structure are used as follows:
1159 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1160 * must be unique within that level of sysctl
1162 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1163 * enter a sysctl file
1165 * data - a pointer to data for use by proc_handler
1167 * maxlen - the maximum size in bytes of the data
1169 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1171 * child - a pointer to the child sysctl table if this entry is a directory, or
1174 * proc_handler - the text handler routine (described below)
1176 * strategy - the strategy routine (described below)
1178 * de - for internal use by the sysctl routines
1180 * extra1, extra2 - extra pointers usable by the proc handler routines
1182 * Leaf nodes in the sysctl tree will be represented by a single file
1183 * under /proc; non-leaf nodes will be represented by directories.
1185 * sysctl(2) can automatically manage read and write requests through
1186 * the sysctl table. The data and maxlen fields of the ctl_table
1187 * struct enable minimal validation of the values being written to be
1188 * performed, and the mode field allows minimal authentication.
1190 * More sophisticated management can be enabled by the provision of a
1191 * strategy routine with the table entry. This will be called before
1192 * any automatic read or write of the data is performed.
1194 * The strategy routine may return
1196 * < 0 - Error occurred (error is passed to user process)
1198 * 0 - OK - proceed with automatic read or write.
1200 * > 0 - OK - read or write has been done by the strategy routine, so
1201 * return immediately.
1203 * There must be a proc_handler routine for any terminal nodes
1204 * mirrored under /proc/sys (non-terminals are handled by a built-in
1205 * directory handler). Several default handlers are available to
1206 * cover common cases -
1208 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1209 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1210 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1212 * It is the handler's job to read the input buffer from user memory
1213 * and process it. The handler should return 0 on success.
1215 * This routine returns %NULL on a failure to register, and a pointer
1216 * to the table header on success.
1218 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1221 struct ctl_table_header *tmp;
1222 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1225 tmp->ctl_table = table;
1226 INIT_LIST_HEAD(&tmp->ctl_entry);
1228 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1230 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1231 #ifdef CONFIG_PROC_FS
1232 register_proc_table(table, proc_sys_root);
1238 * unregister_sysctl_table - unregister a sysctl table hierarchy
1239 * @header: the header returned from register_sysctl_table
1241 * Unregisters the sysctl table and all children. proc entries may not
1242 * actually be removed until they are no longer used by anyone.
1244 void unregister_sysctl_table(struct ctl_table_header * header)
1246 list_del(&header->ctl_entry);
1247 #ifdef CONFIG_PROC_FS
1248 unregister_proc_table(header->ctl_table, proc_sys_root);
1257 #ifdef CONFIG_PROC_FS
1259 /* Scan the sysctl entries in table and add them all into /proc */
1260 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1262 struct proc_dir_entry *de;
1266 for (; table->ctl_name; table++) {
1267 /* Can't do anything without a proc name. */
1268 if (!table->procname)
1270 /* Maybe we can't do anything with it... */
1271 if (!table->proc_handler && !table->child) {
1272 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1277 len = strlen(table->procname);
1281 if (table->proc_handler)
1285 for (de = root->subdir; de; de = de->next) {
1286 if (proc_match(len, table->procname, de))
1289 /* If the subdir exists already, de is non-NULL */
1293 de = create_proc_entry(table->procname, mode, root);
1296 de->data = (void *) table;
1297 if (table->proc_handler)
1298 de->proc_fops = &proc_sys_file_operations;
1301 if (de->mode & S_IFDIR)
1302 register_proc_table(table->child, de);
1307 * Unregister a /proc sysctl table and any subdirectories.
1309 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1311 struct proc_dir_entry *de;
1312 for (; table->ctl_name; table++) {
1313 if (!(de = table->de))
1315 if (de->mode & S_IFDIR) {
1316 if (!table->child) {
1317 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1320 unregister_proc_table(table->child, de);
1322 /* Don't unregister directories which still have entries.. */
1327 /* Don't unregister proc entries that are still being used.. */
1328 if (atomic_read(&de->count))
1332 remove_proc_entry(table->procname, root);
1336 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1337 size_t count, loff_t *ppos)
1340 struct proc_dir_entry *de;
1341 struct ctl_table *table;
1345 de = PDE(file->f_dentry->d_inode);
1346 if (!de || !de->data)
1348 table = (struct ctl_table *) de->data;
1349 if (!table || !table->proc_handler)
1351 op = (write ? 002 : 004);
1352 if (ctl_perm(table, op))
1357 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1363 static int proc_opensys(struct inode *inode, struct file *file)
1365 if (file->f_mode & FMODE_WRITE) {
1367 * sysctl entries that are not writable,
1368 * are _NOT_ writable, capabilities or not.
1370 if (!(inode->i_mode & S_IWUSR))
1377 static ssize_t proc_readsys(struct file * file, char __user * buf,
1378 size_t count, loff_t *ppos)
1380 return do_rw_proc(0, file, buf, count, ppos);
1383 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1384 size_t count, loff_t *ppos)
1386 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1390 * proc_dostring - read a string sysctl
1391 * @table: the sysctl table
1392 * @write: %TRUE if this is a write to the sysctl file
1393 * @filp: the file structure
1394 * @buffer: the user buffer
1395 * @lenp: the size of the user buffer
1396 * @ppos: file position
1398 * Reads/writes a string from/to the user buffer. If the kernel
1399 * buffer provided is not large enough to hold the string, the
1400 * string is truncated. The copied string is %NULL-terminated.
1401 * If the string is being read by the user process, it is copied
1402 * and a newline '\n' is added. It is truncated if the buffer is
1405 * Returns 0 on success.
1407 int proc_dostring(ctl_table *table, int write, struct file *filp,
1408 void __user *buffer, size_t *lenp, loff_t *ppos)
1416 maxlen = table->maxlen;
1418 if (!data || !maxlen || !*lenp || (*ppos && !write))
1421 if (table->virt_handler)
1422 table->virt_handler(table, write, filp->f_xid, &data, &maxlen);
1427 while (len < *lenp) {
1428 if (get_user(c, p++))
1430 if (c == 0 || c == '\n')
1436 if(copy_from_user(data, buffer, len))
1438 ((char *) data)[len] = 0;
1447 if(copy_to_user(buffer, 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);