2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/config.h>
22 #include <linux/module.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/sysrq.h>
35 #include <linux/highuid.h>
36 #include <linux/writeback.h>
37 #include <linux/hugetlb.h>
38 #include <linux/security.h>
39 #include <linux/initrd.h>
40 #include <linux/times.h>
41 #include <linux/limits.h>
42 #include <linux/dcache.h>
43 #include <linux/syscalls.h>
45 #include <asm/uaccess.h>
46 #include <asm/processor.h>
48 #ifdef CONFIG_ROOT_NFS
49 #include <linux/nfs_fs.h>
52 #if defined(CONFIG_SYSCTL)
54 /* External variables not in a header file. */
56 extern int sysctl_overcommit_memory;
57 extern int sysctl_overcommit_ratio;
58 extern int max_threads;
59 extern int sysrq_enabled;
60 extern int core_uses_pid;
61 extern char core_pattern[];
64 extern int min_free_kbytes;
65 extern int printk_ratelimit_jiffies;
66 extern int printk_ratelimit_burst;
67 extern int pid_max_min, pid_max_max;
69 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
70 int unknown_nmi_panic;
71 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
72 void __user *, size_t *, loff_t *);
75 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
76 static int maxolduid = 65535;
79 static int ngroups_max = NGROUPS_MAX;
82 extern char modprobe_path[];
85 extern char hotplug_path[];
87 extern char vshelper_path[];
88 #ifdef CONFIG_CHR_DEV_SG
89 extern int sg_big_buff;
92 extern size_t shm_ctlmax;
93 extern size_t shm_ctlall;
94 extern int shm_ctlmni;
95 extern int msg_ctlmax;
96 extern int msg_ctlmnb;
97 extern int msg_ctlmni;
98 extern int sem_ctls[];
102 extern char reboot_command [];
103 extern int stop_a_enabled;
104 extern int scons_pwroff;
108 extern int pwrsw_enabled;
109 extern int unaligned_enabled;
112 #ifdef CONFIG_ARCH_S390
113 #ifdef CONFIG_MATHEMU
114 extern int sysctl_ieee_emulation_warnings;
116 extern int sysctl_userprocess_debug;
119 extern int sysctl_hz_timer;
121 #ifdef CONFIG_BSD_PROCESS_ACCT
122 extern int acct_parm[];
125 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
126 ctl_table *, void **);
127 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
128 void __user *buffer, size_t *lenp, loff_t *ppos);
130 static ctl_table root_table[];
131 static struct ctl_table_header root_table_header =
132 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
134 static ctl_table kern_table[];
135 static ctl_table vm_table[];
137 extern ctl_table net_table[];
139 static ctl_table proc_table[];
140 static ctl_table fs_table[];
141 static ctl_table debug_table[];
142 static ctl_table dev_table[];
143 extern ctl_table random_table[];
144 #ifdef CONFIG_UNIX98_PTYS
145 extern ctl_table pty_table[];
148 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
149 int sysctl_legacy_va_layout;
152 /* /proc declarations: */
154 #ifdef CONFIG_PROC_FS
156 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
157 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
158 static int proc_opensys(struct inode *, struct file *);
160 struct file_operations proc_sys_file_operations = {
161 .open = proc_opensys,
162 .read = proc_readsys,
163 .write = proc_writesys,
166 extern struct proc_dir_entry *proc_sys_root;
168 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
169 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
172 /* The default sysctl tables: */
174 static ctl_table root_table[] = {
176 .ctl_name = CTL_KERN,
177 .procname = "kernel",
196 .ctl_name = CTL_PROC,
208 .ctl_name = CTL_DEBUG,
211 .child = debug_table,
222 static ctl_table kern_table[] = {
224 .ctl_name = KERN_OSTYPE,
225 .procname = "ostype",
226 .data = system_utsname.sysname,
227 .maxlen = sizeof(system_utsname.sysname),
229 .proc_handler = &proc_doutsstring,
230 .strategy = &sysctl_string,
233 .ctl_name = KERN_OSRELEASE,
234 .procname = "osrelease",
235 .data = system_utsname.release,
236 .maxlen = sizeof(system_utsname.release),
238 .proc_handler = &proc_doutsstring,
239 .strategy = &sysctl_string,
242 .ctl_name = KERN_VERSION,
243 .procname = "version",
244 .data = system_utsname.version,
245 .maxlen = sizeof(system_utsname.version),
247 .proc_handler = &proc_doutsstring,
248 .strategy = &sysctl_string,
251 .ctl_name = KERN_NODENAME,
252 .procname = "hostname",
253 .data = system_utsname.nodename,
254 .maxlen = sizeof(system_utsname.nodename),
256 .proc_handler = &proc_doutsstring,
257 .strategy = &sysctl_string,
260 .ctl_name = KERN_DOMAINNAME,
261 .procname = "domainname",
262 .data = system_utsname.domainname,
263 .maxlen = sizeof(system_utsname.domainname),
265 .proc_handler = &proc_doutsstring,
266 .strategy = &sysctl_string,
269 .ctl_name = KERN_PANIC,
271 .data = &panic_timeout,
272 .maxlen = sizeof(int),
274 .proc_handler = &proc_dointvec,
277 .ctl_name = KERN_CORE_USES_PID,
278 .procname = "core_uses_pid",
279 .data = &core_uses_pid,
280 .maxlen = sizeof(int),
282 .proc_handler = &proc_dointvec,
285 .ctl_name = KERN_CORE_PATTERN,
286 .procname = "core_pattern",
287 .data = core_pattern,
290 .proc_handler = &proc_dostring,
291 .strategy = &sysctl_string,
294 .ctl_name = KERN_TAINTED,
295 .procname = "tainted",
297 .maxlen = sizeof(int),
299 .proc_handler = &proc_dointvec,
302 .ctl_name = KERN_CAP_BSET,
303 .procname = "cap-bound",
305 .maxlen = sizeof(kernel_cap_t),
307 .proc_handler = &proc_dointvec_bset,
309 #ifdef CONFIG_BLK_DEV_INITRD
311 .ctl_name = KERN_REALROOTDEV,
312 .procname = "real-root-dev",
313 .data = &real_root_dev,
314 .maxlen = sizeof(int),
316 .proc_handler = &proc_dointvec,
321 .ctl_name = KERN_SPARC_REBOOT,
322 .procname = "reboot-cmd",
323 .data = reboot_command,
326 .proc_handler = &proc_dostring,
327 .strategy = &sysctl_string,
330 .ctl_name = KERN_SPARC_STOP_A,
331 .procname = "stop-a",
332 .data = &stop_a_enabled,
333 .maxlen = sizeof (int),
335 .proc_handler = &proc_dointvec,
338 .ctl_name = KERN_SPARC_SCONS_PWROFF,
339 .procname = "scons-poweroff",
340 .data = &scons_pwroff,
341 .maxlen = sizeof (int),
343 .proc_handler = &proc_dointvec,
348 .ctl_name = KERN_HPPA_PWRSW,
349 .procname = "soft-power",
350 .data = &pwrsw_enabled,
351 .maxlen = sizeof (int),
353 .proc_handler = &proc_dointvec,
356 .ctl_name = KERN_HPPA_UNALIGNED,
357 .procname = "unaligned-trap",
358 .data = &unaligned_enabled,
359 .maxlen = sizeof (int),
361 .proc_handler = &proc_dointvec,
365 .ctl_name = KERN_CTLALTDEL,
366 .procname = "ctrl-alt-del",
368 .maxlen = sizeof(int),
370 .proc_handler = &proc_dointvec,
373 .ctl_name = KERN_PRINTK,
374 .procname = "printk",
375 .data = &console_loglevel,
376 .maxlen = 4*sizeof(int),
378 .proc_handler = &proc_dointvec,
382 .ctl_name = KERN_MODPROBE,
383 .procname = "modprobe",
384 .data = &modprobe_path,
385 .maxlen = KMOD_PATH_LEN,
387 .proc_handler = &proc_dostring,
388 .strategy = &sysctl_string,
391 #ifdef CONFIG_HOTPLUG
393 .ctl_name = KERN_HOTPLUG,
394 .procname = "hotplug",
395 .data = &hotplug_path,
396 .maxlen = HOTPLUG_PATH_LEN,
398 .proc_handler = &proc_dostring,
399 .strategy = &sysctl_string,
403 .ctl_name = KERN_VSHELPER,
404 .procname = "vshelper",
405 .data = &vshelper_path,
408 .proc_handler = &proc_dostring,
409 .strategy = &sysctl_string,
411 #ifdef CONFIG_CHR_DEV_SG
413 .ctl_name = KERN_SG_BIG_BUFF,
414 .procname = "sg-big-buff",
415 .data = &sg_big_buff,
416 .maxlen = sizeof (int),
418 .proc_handler = &proc_dointvec,
421 #ifdef CONFIG_BSD_PROCESS_ACCT
423 .ctl_name = KERN_ACCT,
426 .maxlen = 3*sizeof(int),
428 .proc_handler = &proc_dointvec,
431 #ifdef CONFIG_SYSVIPC
433 .ctl_name = KERN_SHMMAX,
434 .procname = "shmmax",
436 .maxlen = sizeof (size_t),
438 .proc_handler = &proc_doulongvec_minmax,
441 .ctl_name = KERN_SHMALL,
442 .procname = "shmall",
444 .maxlen = sizeof (size_t),
446 .proc_handler = &proc_doulongvec_minmax,
449 .ctl_name = KERN_SHMMNI,
450 .procname = "shmmni",
452 .maxlen = sizeof (int),
454 .proc_handler = &proc_dointvec,
457 .ctl_name = KERN_MSGMAX,
458 .procname = "msgmax",
460 .maxlen = sizeof (int),
462 .proc_handler = &proc_dointvec,
465 .ctl_name = KERN_MSGMNI,
466 .procname = "msgmni",
468 .maxlen = sizeof (int),
470 .proc_handler = &proc_dointvec,
473 .ctl_name = KERN_MSGMNB,
474 .procname = "msgmnb",
476 .maxlen = sizeof (int),
478 .proc_handler = &proc_dointvec,
481 .ctl_name = KERN_SEM,
484 .maxlen = 4*sizeof (int),
486 .proc_handler = &proc_dointvec,
489 #ifdef CONFIG_MAGIC_SYSRQ
491 .ctl_name = KERN_SYSRQ,
493 .data = &sysrq_enabled,
494 .maxlen = sizeof (int),
496 .proc_handler = &proc_dointvec,
500 .ctl_name = KERN_CADPID,
501 .procname = "cad_pid",
503 .maxlen = sizeof (int),
505 .proc_handler = &proc_dointvec,
508 .ctl_name = KERN_MAX_THREADS,
509 .procname = "threads-max",
510 .data = &max_threads,
511 .maxlen = sizeof(int),
513 .proc_handler = &proc_dointvec,
516 .ctl_name = KERN_RANDOM,
517 .procname = "random",
519 .child = random_table,
521 #ifdef CONFIG_UNIX98_PTYS
523 .ctl_name = KERN_PTY,
530 .ctl_name = KERN_OVERFLOWUID,
531 .procname = "overflowuid",
532 .data = &overflowuid,
533 .maxlen = sizeof(int),
535 .proc_handler = &proc_dointvec_minmax,
536 .strategy = &sysctl_intvec,
537 .extra1 = &minolduid,
538 .extra2 = &maxolduid,
541 .ctl_name = KERN_OVERFLOWGID,
542 .procname = "overflowgid",
543 .data = &overflowgid,
544 .maxlen = sizeof(int),
546 .proc_handler = &proc_dointvec_minmax,
547 .strategy = &sysctl_intvec,
548 .extra1 = &minolduid,
549 .extra2 = &maxolduid,
551 #ifdef CONFIG_ARCH_S390
552 #ifdef CONFIG_MATHEMU
554 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
555 .procname = "ieee_emulation_warnings",
556 .data = &sysctl_ieee_emulation_warnings,
557 .maxlen = sizeof(int),
559 .proc_handler = &proc_dointvec,
562 #ifdef CONFIG_NO_IDLE_HZ
564 .ctl_name = KERN_HZ_TIMER,
565 .procname = "hz_timer",
566 .data = &sysctl_hz_timer,
567 .maxlen = sizeof(int),
569 .proc_handler = &proc_dointvec,
573 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
574 .procname = "userprocess_debug",
575 .data = &sysctl_userprocess_debug,
576 .maxlen = sizeof(int),
578 .proc_handler = &proc_dointvec,
582 .ctl_name = KERN_PIDMAX,
583 .procname = "pid_max",
585 .maxlen = sizeof (int),
587 .proc_handler = &proc_dointvec_minmax,
588 .strategy = sysctl_intvec,
589 .extra1 = &pid_max_min,
590 .extra2 = &pid_max_max,
593 .ctl_name = KERN_PANIC_ON_OOPS,
594 .procname = "panic_on_oops",
595 .data = &panic_on_oops,
596 .maxlen = sizeof(int),
598 .proc_handler = &proc_dointvec,
601 .ctl_name = KERN_PRINTK_RATELIMIT,
602 .procname = "printk_ratelimit",
603 .data = &printk_ratelimit_jiffies,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec_jiffies,
607 .strategy = &sysctl_jiffies,
610 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
611 .procname = "printk_ratelimit_burst",
612 .data = &printk_ratelimit_burst,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
618 .ctl_name = KERN_NGROUPS_MAX,
619 .procname = "ngroups_max",
620 .data = &ngroups_max,
621 .maxlen = sizeof (int),
623 .proc_handler = &proc_dointvec,
625 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
627 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
628 .procname = "unknown_nmi_panic",
629 .data = &unknown_nmi_panic,
630 .maxlen = sizeof (int),
632 .proc_handler = &proc_unknown_nmi_panic,
635 #if defined(CONFIG_X86)
637 .ctl_name = KERN_BOOTLOADER_TYPE,
638 .procname = "bootloader_type",
639 .data = &bootloader_type,
640 .maxlen = sizeof (int),
642 .proc_handler = &proc_dointvec,
648 /* Constants for minimum and maximum testing in vm_table.
649 We use these as one-element integer vectors. */
651 static int one_hundred = 100;
654 static ctl_table vm_table[] = {
656 .ctl_name = VM_OVERCOMMIT_MEMORY,
657 .procname = "overcommit_memory",
658 .data = &sysctl_overcommit_memory,
659 .maxlen = sizeof(sysctl_overcommit_memory),
661 .proc_handler = &proc_dointvec,
664 .ctl_name = VM_OVERCOMMIT_RATIO,
665 .procname = "overcommit_ratio",
666 .data = &sysctl_overcommit_ratio,
667 .maxlen = sizeof(sysctl_overcommit_ratio),
669 .proc_handler = &proc_dointvec,
672 .ctl_name = VM_PAGE_CLUSTER,
673 .procname = "page-cluster",
674 .data = &page_cluster,
675 .maxlen = sizeof(int),
677 .proc_handler = &proc_dointvec,
680 .ctl_name = VM_DIRTY_BACKGROUND,
681 .procname = "dirty_background_ratio",
682 .data = &dirty_background_ratio,
683 .maxlen = sizeof(dirty_background_ratio),
685 .proc_handler = &proc_dointvec_minmax,
686 .strategy = &sysctl_intvec,
688 .extra2 = &one_hundred,
691 .ctl_name = VM_DIRTY_RATIO,
692 .procname = "dirty_ratio",
693 .data = &vm_dirty_ratio,
694 .maxlen = sizeof(vm_dirty_ratio),
696 .proc_handler = &proc_dointvec_minmax,
697 .strategy = &sysctl_intvec,
699 .extra2 = &one_hundred,
702 .ctl_name = VM_DIRTY_WB_CS,
703 .procname = "dirty_writeback_centisecs",
704 .data = &dirty_writeback_centisecs,
705 .maxlen = sizeof(dirty_writeback_centisecs),
707 .proc_handler = &dirty_writeback_centisecs_handler,
710 .ctl_name = VM_DIRTY_EXPIRE_CS,
711 .procname = "dirty_expire_centisecs",
712 .data = &dirty_expire_centisecs,
713 .maxlen = sizeof(dirty_expire_centisecs),
715 .proc_handler = &proc_dointvec,
718 .ctl_name = VM_NR_PDFLUSH_THREADS,
719 .procname = "nr_pdflush_threads",
720 .data = &nr_pdflush_threads,
721 .maxlen = sizeof nr_pdflush_threads,
722 .mode = 0444 /* read-only*/,
723 .proc_handler = &proc_dointvec,
726 .ctl_name = VM_SWAPPINESS,
727 .procname = "swappiness",
728 .data = &vm_swappiness,
729 .maxlen = sizeof(vm_swappiness),
731 .proc_handler = &proc_dointvec_minmax,
732 .strategy = &sysctl_intvec,
734 .extra2 = &one_hundred,
736 #ifdef CONFIG_HUGETLB_PAGE
738 .ctl_name = VM_HUGETLB_PAGES,
739 .procname = "nr_hugepages",
740 .data = &max_huge_pages,
741 .maxlen = sizeof(unsigned long),
743 .proc_handler = &hugetlb_sysctl_handler,
744 .extra1 = (void *)&hugetlb_zero,
745 .extra2 = (void *)&hugetlb_infinity,
748 .ctl_name = VM_HUGETLB_GROUP,
749 .procname = "hugetlb_shm_group",
750 .data = &sysctl_hugetlb_shm_group,
751 .maxlen = sizeof(gid_t),
753 .proc_handler = &proc_dointvec,
757 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
758 .procname = "lowmem_reserve_ratio",
759 .data = &sysctl_lowmem_reserve_ratio,
760 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
762 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
763 .strategy = &sysctl_intvec,
766 .ctl_name = VM_MIN_FREE_KBYTES,
767 .procname = "min_free_kbytes",
768 .data = &min_free_kbytes,
769 .maxlen = sizeof(min_free_kbytes),
771 .proc_handler = &min_free_kbytes_sysctl_handler,
772 .strategy = &sysctl_intvec,
777 .ctl_name = VM_MAX_MAP_COUNT,
778 .procname = "max_map_count",
779 .data = &sysctl_max_map_count,
780 .maxlen = sizeof(sysctl_max_map_count),
782 .proc_handler = &proc_dointvec
786 .ctl_name = VM_LAPTOP_MODE,
787 .procname = "laptop_mode",
788 .data = &laptop_mode,
789 .maxlen = sizeof(laptop_mode),
791 .proc_handler = &proc_dointvec,
792 .strategy = &sysctl_intvec,
796 .ctl_name = VM_BLOCK_DUMP,
797 .procname = "block_dump",
799 .maxlen = sizeof(block_dump),
801 .proc_handler = &proc_dointvec,
802 .strategy = &sysctl_intvec,
806 .ctl_name = VM_VFS_CACHE_PRESSURE,
807 .procname = "vfs_cache_pressure",
808 .data = &sysctl_vfs_cache_pressure,
809 .maxlen = sizeof(sysctl_vfs_cache_pressure),
811 .proc_handler = &proc_dointvec,
812 .strategy = &sysctl_intvec,
815 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
817 .ctl_name = VM_LEGACY_VA_LAYOUT,
818 .procname = "legacy_va_layout",
819 .data = &sysctl_legacy_va_layout,
820 .maxlen = sizeof(sysctl_legacy_va_layout),
822 .proc_handler = &proc_dointvec,
823 .strategy = &sysctl_intvec,
829 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
830 .procname = "swap_token_timeout",
831 .data = &swap_token_default_timeout,
832 .maxlen = sizeof(swap_token_default_timeout),
834 .proc_handler = &proc_dointvec_jiffies,
835 .strategy = &sysctl_jiffies,
841 static ctl_table proc_table[] = {
845 static ctl_table fs_table[] = {
847 .ctl_name = FS_NRINODE,
848 .procname = "inode-nr",
849 .data = &inodes_stat,
850 .maxlen = 2*sizeof(int),
852 .proc_handler = &proc_dointvec,
855 .ctl_name = FS_STATINODE,
856 .procname = "inode-state",
857 .data = &inodes_stat,
858 .maxlen = 7*sizeof(int),
860 .proc_handler = &proc_dointvec,
863 .ctl_name = FS_NRFILE,
864 .procname = "file-nr",
866 .maxlen = 3*sizeof(int),
868 .proc_handler = &proc_dointvec,
871 .ctl_name = FS_MAXFILE,
872 .procname = "file-max",
873 .data = &files_stat.max_files,
874 .maxlen = sizeof(int),
876 .proc_handler = &proc_dointvec,
879 .ctl_name = FS_DENTRY,
880 .procname = "dentry-state",
881 .data = &dentry_stat,
882 .maxlen = 6*sizeof(int),
884 .proc_handler = &proc_dointvec,
887 .ctl_name = FS_OVERFLOWUID,
888 .procname = "overflowuid",
889 .data = &fs_overflowuid,
890 .maxlen = sizeof(int),
892 .proc_handler = &proc_dointvec_minmax,
893 .strategy = &sysctl_intvec,
894 .extra1 = &minolduid,
895 .extra2 = &maxolduid,
898 .ctl_name = FS_OVERFLOWGID,
899 .procname = "overflowgid",
900 .data = &fs_overflowgid,
901 .maxlen = sizeof(int),
903 .proc_handler = &proc_dointvec_minmax,
904 .strategy = &sysctl_intvec,
905 .extra1 = &minolduid,
906 .extra2 = &maxolduid,
909 .ctl_name = FS_LEASES,
910 .procname = "leases-enable",
911 .data = &leases_enable,
912 .maxlen = sizeof(int),
914 .proc_handler = &proc_dointvec,
916 #ifdef CONFIG_DNOTIFY
918 .ctl_name = FS_DIR_NOTIFY,
919 .procname = "dir-notify-enable",
920 .data = &dir_notify_enable,
921 .maxlen = sizeof(int),
923 .proc_handler = &proc_dointvec,
928 .ctl_name = FS_LEASE_TIME,
929 .procname = "lease-break-time",
930 .data = &lease_break_time,
931 .maxlen = sizeof(int),
933 .proc_handler = &proc_dointvec,
936 .ctl_name = FS_AIO_NR,
937 .procname = "aio-nr",
939 .maxlen = sizeof(aio_nr),
941 .proc_handler = &proc_dointvec,
944 .ctl_name = FS_AIO_MAX_NR,
945 .procname = "aio-max-nr",
947 .maxlen = sizeof(aio_max_nr),
949 .proc_handler = &proc_dointvec,
955 static ctl_table debug_table[] = {
959 static ctl_table dev_table[] = {
963 extern void init_irq_proc (void);
965 void __init sysctl_init(void)
967 #ifdef CONFIG_PROC_FS
968 register_proc_table(root_table, proc_sys_root);
973 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
974 void __user *newval, size_t newlen)
976 struct list_head *tmp;
978 if (nlen <= 0 || nlen >= CTL_MAXNAME)
982 if (!oldlenp || get_user(old_len, oldlenp))
985 tmp = &root_table_header.ctl_entry;
987 struct ctl_table_header *head =
988 list_entry(tmp, struct ctl_table_header, ctl_entry);
989 void *context = NULL;
990 int error = parse_table(name, nlen, oldval, oldlenp,
991 newval, newlen, head->ctl_table,
995 if (error != -ENOTDIR)
998 } while (tmp != &root_table_header.ctl_entry);
1002 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1004 struct __sysctl_args tmp;
1007 if (copy_from_user(&tmp, args, sizeof(tmp)))
1011 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1012 tmp.newval, tmp.newlen);
1018 * ctl_perm does NOT grant the superuser all rights automatically, because
1019 * some sysctl variables are readonly even to root.
1022 static int test_perm(int mode, int op)
1026 else if (in_egroup_p(0))
1028 if ((mode & op & 0007) == op)
1033 static inline int ctl_perm(ctl_table *table, int op)
1036 error = security_sysctl(table, op);
1039 return test_perm(table->mode, op);
1042 static int parse_table(int __user *name, int nlen,
1043 void __user *oldval, size_t __user *oldlenp,
1044 void __user *newval, size_t newlen,
1045 ctl_table *table, void **context)
1051 if (get_user(n, name))
1053 for ( ; table->ctl_name; table++) {
1054 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1057 if (ctl_perm(table, 001))
1059 if (table->strategy) {
1060 error = table->strategy(
1063 newval, newlen, context);
1069 table = table->child;
1072 error = do_sysctl_strategy(table, name, nlen,
1074 newval, newlen, context);
1081 /* Perform the actual read/write of a sysctl table entry. */
1082 int do_sysctl_strategy (ctl_table *table,
1083 int __user *name, int nlen,
1084 void __user *oldval, size_t __user *oldlenp,
1085 void __user *newval, size_t newlen, void **context)
1094 if (ctl_perm(table, op))
1097 if (table->strategy) {
1098 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1099 newval, newlen, context);
1106 /* If there is no strategy routine, or if the strategy returns
1107 * zero, proceed with automatic r/w */
1108 if (table->data && table->maxlen) {
1109 if (oldval && oldlenp) {
1110 if (get_user(len, oldlenp))
1113 if (len > table->maxlen)
1114 len = table->maxlen;
1115 if(copy_to_user(oldval, table->data, len))
1117 if(put_user(len, oldlenp))
1121 if (newval && newlen) {
1123 if (len > table->maxlen)
1124 len = table->maxlen;
1125 if(copy_from_user(table->data, newval, len))
1133 * register_sysctl_table - register a sysctl hierarchy
1134 * @table: the top-level table structure
1135 * @insert_at_head: whether the entry should be inserted in front or at the end
1137 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1138 * array. An entry with a ctl_name of 0 terminates the table.
1140 * The members of the &ctl_table structure are used as follows:
1142 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1143 * must be unique within that level of sysctl
1145 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1146 * enter a sysctl file
1148 * data - a pointer to data for use by proc_handler
1150 * maxlen - the maximum size in bytes of the data
1152 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1154 * child - a pointer to the child sysctl table if this entry is a directory, or
1157 * proc_handler - the text handler routine (described below)
1159 * strategy - the strategy routine (described below)
1161 * de - for internal use by the sysctl routines
1163 * extra1, extra2 - extra pointers usable by the proc handler routines
1165 * Leaf nodes in the sysctl tree will be represented by a single file
1166 * under /proc; non-leaf nodes will be represented by directories.
1168 * sysctl(2) can automatically manage read and write requests through
1169 * the sysctl table. The data and maxlen fields of the ctl_table
1170 * struct enable minimal validation of the values being written to be
1171 * performed, and the mode field allows minimal authentication.
1173 * More sophisticated management can be enabled by the provision of a
1174 * strategy routine with the table entry. This will be called before
1175 * any automatic read or write of the data is performed.
1177 * The strategy routine may return
1179 * < 0 - Error occurred (error is passed to user process)
1181 * 0 - OK - proceed with automatic read or write.
1183 * > 0 - OK - read or write has been done by the strategy routine, so
1184 * return immediately.
1186 * There must be a proc_handler routine for any terminal nodes
1187 * mirrored under /proc/sys (non-terminals are handled by a built-in
1188 * directory handler). Several default handlers are available to
1189 * cover common cases -
1191 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1192 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1193 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1195 * It is the handler's job to read the input buffer from user memory
1196 * and process it. The handler should return 0 on success.
1198 * This routine returns %NULL on a failure to register, and a pointer
1199 * to the table header on success.
1201 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1204 struct ctl_table_header *tmp;
1205 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1208 tmp->ctl_table = table;
1209 INIT_LIST_HEAD(&tmp->ctl_entry);
1211 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1213 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1214 #ifdef CONFIG_PROC_FS
1215 register_proc_table(table, proc_sys_root);
1221 * unregister_sysctl_table - unregister a sysctl table hierarchy
1222 * @header: the header returned from register_sysctl_table
1224 * Unregisters the sysctl table and all children. proc entries may not
1225 * actually be removed until they are no longer used by anyone.
1227 void unregister_sysctl_table(struct ctl_table_header * header)
1229 list_del(&header->ctl_entry);
1230 #ifdef CONFIG_PROC_FS
1231 unregister_proc_table(header->ctl_table, proc_sys_root);
1240 #ifdef CONFIG_PROC_FS
1242 /* Scan the sysctl entries in table and add them all into /proc */
1243 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1245 struct proc_dir_entry *de;
1249 for (; table->ctl_name; table++) {
1250 /* Can't do anything without a proc name. */
1251 if (!table->procname)
1253 /* Maybe we can't do anything with it... */
1254 if (!table->proc_handler && !table->child) {
1255 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1260 len = strlen(table->procname);
1264 if (table->proc_handler)
1268 for (de = root->subdir; de; de = de->next) {
1269 if (proc_match(len, table->procname, de))
1272 /* If the subdir exists already, de is non-NULL */
1276 de = create_proc_entry(table->procname, mode, root);
1279 de->data = (void *) table;
1280 if (table->proc_handler)
1281 de->proc_fops = &proc_sys_file_operations;
1284 if (de->mode & S_IFDIR)
1285 register_proc_table(table->child, de);
1290 * Unregister a /proc sysctl table and any subdirectories.
1292 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1294 struct proc_dir_entry *de;
1295 for (; table->ctl_name; table++) {
1296 if (!(de = table->de))
1298 if (de->mode & S_IFDIR) {
1299 if (!table->child) {
1300 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1303 unregister_proc_table(table->child, de);
1305 /* Don't unregister directories which still have entries.. */
1310 /* Don't unregister proc entries that are still being used.. */
1311 if (atomic_read(&de->count))
1315 remove_proc_entry(table->procname, root);
1319 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1320 size_t count, loff_t *ppos)
1323 struct proc_dir_entry *de;
1324 struct ctl_table *table;
1328 de = PDE(file->f_dentry->d_inode);
1329 if (!de || !de->data)
1331 table = (struct ctl_table *) de->data;
1332 if (!table || !table->proc_handler)
1334 op = (write ? 002 : 004);
1335 if (ctl_perm(table, op))
1340 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1346 static int proc_opensys(struct inode *inode, struct file *file)
1348 if (file->f_mode & FMODE_WRITE) {
1350 * sysctl entries that are not writable,
1351 * are _NOT_ writable, capabilities or not.
1353 if (!(inode->i_mode & S_IWUSR))
1360 static ssize_t proc_readsys(struct file * file, char __user * buf,
1361 size_t count, loff_t *ppos)
1363 return do_rw_proc(0, file, buf, count, ppos);
1366 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1367 size_t count, loff_t *ppos)
1369 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1373 * proc_dostring - read a string sysctl
1374 * @table: the sysctl table
1375 * @write: %TRUE if this is a write to the sysctl file
1376 * @filp: the file structure
1377 * @buffer: the user buffer
1378 * @lenp: the size of the user buffer
1380 * Reads/writes a string from/to the user buffer. If the kernel
1381 * buffer provided is not large enough to hold the string, the
1382 * string is truncated. The copied string is %NULL-terminated.
1383 * If the string is being read by the user process, it is copied
1384 * and a newline '\n' is added. It is truncated if the buffer is
1387 * Returns 0 on success.
1389 int proc_dostring(ctl_table *table, int write, struct file *filp,
1390 void __user *buffer, size_t *lenp, loff_t *ppos)
1396 if (!table->data || !table->maxlen || !*lenp ||
1397 (*ppos && !write)) {
1405 while (len < *lenp) {
1406 if (get_user(c, p++))
1408 if (c == 0 || c == '\n')
1412 if (len >= table->maxlen)
1413 len = table->maxlen-1;
1414 if(copy_from_user(table->data, buffer, len))
1416 ((char *) table->data)[len] = 0;
1419 len = strlen(table->data);
1420 if (len > table->maxlen)
1421 len = table->maxlen;
1425 if(copy_to_user(buffer, table->data, len))
1428 if(put_user('\n', ((char __user *) buffer) + len))
1439 * Special case of dostring for the UTS structure. This has locks
1440 * to observe. Should this be in kernel/sys.c ????
1443 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1444 void __user *buffer, size_t *lenp, loff_t *ppos)
1449 down_read(&uts_sem);
1450 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1453 down_write(&uts_sem);
1454 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1460 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1462 int write, void *data)
1465 *valp = *negp ? -*lvalp : *lvalp;
1470 *lvalp = (unsigned long)-val;
1473 *lvalp = (unsigned long)val;
1479 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1480 void __user *buffer, size_t *lenp, loff_t *ppos,
1481 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1482 int write, void *data),
1485 #define TMPBUFLEN 21
1486 int *i, vleft, first=1, neg, val;
1490 char buf[TMPBUFLEN], *p;
1491 char __user *s = buffer;
1493 if (!table->data || !table->maxlen || !*lenp ||
1494 (*ppos && !write)) {
1499 i = (int *) table->data;
1500 vleft = table->maxlen / sizeof(*i);
1504 conv = do_proc_dointvec_conv;
1506 for (; left && vleft--; i++, first=0) {
1521 if (len > sizeof(buf) - 1)
1522 len = sizeof(buf) - 1;
1523 if (copy_from_user(buf, s, len))
1527 if (*p == '-' && left > 1) {
1531 if (*p < '0' || *p > '9')
1534 lval = simple_strtoul(p, &p, 0);
1537 if ((len < left) && *p && !isspace(*p))
1544 if (conv(&neg, &lval, i, 1, data))
1551 if (conv(&neg, &lval, i, 0, data))
1554 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1558 if(copy_to_user(s, buf, len))
1565 if (!write && !first && left) {
1566 if(put_user('\n', s))
1573 if (get_user(c, s++))
1589 * proc_dointvec - read a vector of integers
1590 * @table: the sysctl table
1591 * @write: %TRUE if this is a write to the sysctl file
1592 * @filp: the file structure
1593 * @buffer: the user buffer
1594 * @lenp: the size of the user buffer
1596 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1597 * values from/to the user buffer, treated as an ASCII string.
1599 * Returns 0 on success.
1601 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1602 void __user *buffer, size_t *lenp, loff_t *ppos)
1604 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1614 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1616 int write, void *data)
1618 int op = *(int *)data;
1620 int val = *negp ? -*lvalp : *lvalp;
1622 case OP_SET: *valp = val; break;
1623 case OP_AND: *valp &= val; break;
1624 case OP_OR: *valp |= val; break;
1625 case OP_MAX: if(*valp < val)
1628 case OP_MIN: if(*valp > val)
1636 *lvalp = (unsigned long)-val;
1639 *lvalp = (unsigned long)val;
1646 * init may raise the set.
1649 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1650 void __user *buffer, size_t *lenp, loff_t *ppos)
1654 if (!capable(CAP_SYS_MODULE)) {
1658 op = (current->pid == 1) ? OP_SET : OP_AND;
1659 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1660 do_proc_dointvec_bset_conv,&op);
1663 struct do_proc_dointvec_minmax_conv_param {
1668 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1670 int write, void *data)
1672 struct do_proc_dointvec_minmax_conv_param *param = data;
1674 int val = *negp ? -*lvalp : *lvalp;
1675 if ((param->min && *param->min > val) ||
1676 (param->max && *param->max < val))
1683 *lvalp = (unsigned long)-val;
1686 *lvalp = (unsigned long)val;
1693 * proc_dointvec_minmax - read a vector of integers with min/max values
1694 * @table: the sysctl table
1695 * @write: %TRUE if this is a write to the sysctl file
1696 * @filp: the file structure
1697 * @buffer: the user buffer
1698 * @lenp: the size of the user buffer
1700 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1701 * values from/to the user buffer, treated as an ASCII string.
1703 * This routine will ensure the values are within the range specified by
1704 * table->extra1 (min) and table->extra2 (max).
1706 * Returns 0 on success.
1708 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1709 void __user *buffer, size_t *lenp, loff_t *ppos)
1711 struct do_proc_dointvec_minmax_conv_param param = {
1712 .min = (int *) table->extra1,
1713 .max = (int *) table->extra2,
1715 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1716 do_proc_dointvec_minmax_conv, ¶m);
1719 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1721 void __user *buffer,
1722 size_t *lenp, loff_t *ppos,
1723 unsigned long convmul,
1724 unsigned long convdiv)
1726 #define TMPBUFLEN 21
1727 unsigned long *i, *min, *max, val;
1728 int vleft, first=1, neg;
1730 char buf[TMPBUFLEN], *p;
1731 char __user *s = buffer;
1733 if (!table->data || !table->maxlen || !*lenp ||
1734 (*ppos && !write)) {
1739 i = (unsigned long *) table->data;
1740 min = (unsigned long *) table->extra1;
1741 max = (unsigned long *) table->extra2;
1742 vleft = table->maxlen / sizeof(unsigned long);
1745 for (; left && vleft--; i++, min++, max++, first=0) {
1760 if (len > TMPBUFLEN-1)
1762 if (copy_from_user(buf, s, len))
1766 if (*p == '-' && left > 1) {
1770 if (*p < '0' || *p > '9')
1772 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1774 if ((len < left) && *p && !isspace(*p))
1783 if ((min && val < *min) || (max && val > *max))
1790 sprintf(p, "%lu", convdiv * (*i) / convmul);
1794 if(copy_to_user(s, buf, len))
1801 if (!write && !first && left) {
1802 if(put_user('\n', s))
1809 if (get_user(c, s++))
1825 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1826 * @table: the sysctl table
1827 * @write: %TRUE if this is a write to the sysctl file
1828 * @filp: the file structure
1829 * @buffer: the user buffer
1830 * @lenp: the size of the user buffer
1832 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1833 * values from/to the user buffer, treated as an ASCII string.
1835 * This routine will ensure the values are within the range specified by
1836 * table->extra1 (min) and table->extra2 (max).
1838 * Returns 0 on success.
1840 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1841 void __user *buffer, size_t *lenp, loff_t *ppos)
1843 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1847 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1848 * @table: the sysctl table
1849 * @write: %TRUE if this is a write to the sysctl file
1850 * @filp: the file structure
1851 * @buffer: the user buffer
1852 * @lenp: the size of the user buffer
1854 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1855 * values from/to the user buffer, treated as an ASCII string. The values
1856 * are treated as milliseconds, and converted to jiffies when they are stored.
1858 * This routine will ensure the values are within the range specified by
1859 * table->extra1 (min) and table->extra2 (max).
1861 * Returns 0 on success.
1863 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1865 void __user *buffer,
1866 size_t *lenp, loff_t *ppos)
1868 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1869 lenp, ppos, HZ, 1000l);
1873 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1875 int write, void *data)
1878 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1884 lval = (unsigned long)-val;
1887 lval = (unsigned long)val;
1894 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1896 int write, void *data)
1899 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1905 lval = (unsigned long)-val;
1908 lval = (unsigned long)val;
1910 *lvalp = jiffies_to_clock_t(lval);
1915 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1917 int write, void *data)
1920 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1926 lval = (unsigned long)-val;
1929 lval = (unsigned long)val;
1931 *lvalp = jiffies_to_msecs(lval);
1937 * proc_dointvec_jiffies - read a vector of integers as seconds
1938 * @table: the sysctl table
1939 * @write: %TRUE if this is a write to the sysctl file
1940 * @filp: the file structure
1941 * @buffer: the user buffer
1942 * @lenp: the size of the user buffer
1944 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1945 * values from/to the user buffer, treated as an ASCII string.
1946 * The values read are assumed to be in seconds, and are converted into
1949 * Returns 0 on success.
1951 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1952 void __user *buffer, size_t *lenp, loff_t *ppos)
1954 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1955 do_proc_dointvec_jiffies_conv,NULL);
1959 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1960 * @table: the sysctl table
1961 * @write: %TRUE if this is a write to the sysctl file
1962 * @filp: the file structure
1963 * @buffer: the user buffer
1964 * @lenp: the size of the user buffer
1966 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1967 * values from/to the user buffer, treated as an ASCII string.
1968 * The values read are assumed to be in 1/USER_HZ seconds, and
1969 * are converted into jiffies.
1971 * Returns 0 on success.
1973 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1974 void __user *buffer, size_t *lenp, loff_t *ppos)
1976 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1977 do_proc_dointvec_userhz_jiffies_conv,NULL);
1981 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1982 * @table: the sysctl table
1983 * @write: %TRUE if this is a write to the sysctl file
1984 * @filp: the file structure
1985 * @buffer: the user buffer
1986 * @lenp: the size of the user buffer
1988 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1989 * values from/to the user buffer, treated as an ASCII string.
1990 * The values read are assumed to be in 1/1000 seconds, and
1991 * are converted into jiffies.
1993 * Returns 0 on success.
1995 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
1996 void __user *buffer, size_t *lenp, loff_t *ppos)
1998 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1999 do_proc_dointvec_ms_jiffies_conv, NULL);
2002 #else /* CONFIG_PROC_FS */
2004 int proc_dostring(ctl_table *table, int write, struct file *filp,
2005 void __user *buffer, size_t *lenp, loff_t *ppos)
2010 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2011 void __user *buffer, size_t *lenp, loff_t *ppos)
2016 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2017 void __user *buffer, size_t *lenp, loff_t *ppos)
2022 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2023 void __user *buffer, size_t *lenp, loff_t *ppos)
2028 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2029 void __user *buffer, size_t *lenp, loff_t *ppos)
2034 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2035 void __user *buffer, size_t *lenp, loff_t *ppos)
2040 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2041 void __user *buffer, size_t *lenp, loff_t *ppos)
2046 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2047 void __user *buffer, size_t *lenp, loff_t *ppos)
2052 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2053 void __user *buffer, size_t *lenp, loff_t *ppos)
2058 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2060 void __user *buffer,
2061 size_t *lenp, loff_t *ppos)
2067 #endif /* CONFIG_PROC_FS */
2071 * General sysctl support routines
2074 /* The generic string strategy routine: */
2075 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2076 void __user *oldval, size_t __user *oldlenp,
2077 void __user *newval, size_t newlen, void **context)
2081 if (!table->data || !table->maxlen)
2084 if (oldval && oldlenp) {
2085 if (get_user(len, oldlenp))
2088 l = strlen(table->data);
2089 if (len > l) len = l;
2090 if (len >= table->maxlen)
2091 len = table->maxlen;
2092 if(copy_to_user(oldval, table->data, len))
2094 if(put_user(0, ((char __user *) oldval) + len))
2096 if(put_user(len, oldlenp))
2100 if (newval && newlen) {
2102 if (len > table->maxlen)
2103 len = table->maxlen;
2104 if(copy_from_user(table->data, newval, len))
2106 if (len == table->maxlen)
2108 ((char *) table->data)[len] = 0;
2114 * This function makes sure that all of the integers in the vector
2115 * are between the minimum and maximum values given in the arrays
2116 * table->extra1 and table->extra2, respectively.
2118 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2119 void __user *oldval, size_t __user *oldlenp,
2120 void __user *newval, size_t newlen, void **context)
2123 if (newval && newlen) {
2124 int __user *vec = (int __user *) newval;
2125 int *min = (int *) table->extra1;
2126 int *max = (int *) table->extra2;
2130 if (newlen % sizeof(int) != 0)
2133 if (!table->extra1 && !table->extra2)
2136 if (newlen > table->maxlen)
2137 newlen = table->maxlen;
2138 length = newlen / sizeof(int);
2140 for (i = 0; i < length; i++) {
2142 if (get_user(value, vec + i))
2144 if (min && value < min[i])
2146 if (max && value > max[i])
2153 /* Strategy function to convert jiffies to seconds */
2154 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2155 void __user *oldval, size_t __user *oldlenp,
2156 void __user *newval, size_t newlen, void **context)
2161 if (get_user(olen, oldlenp))
2163 if (olen!=sizeof(int))
2166 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2167 (oldlenp && put_user(sizeof(int),oldlenp)))
2170 if (newval && newlen) {
2172 if (newlen != sizeof(int))
2174 if (get_user(new, (int __user *)newval))
2176 *(int *)(table->data) = new*HZ;
2181 /* Strategy function to convert jiffies to seconds */
2182 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2183 void __user *oldval, size_t __user *oldlenp,
2184 void __user *newval, size_t newlen, void **context)
2189 if (get_user(olen, oldlenp))
2191 if (olen!=sizeof(int))
2194 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2195 (oldlenp && put_user(sizeof(int),oldlenp)))
2198 if (newval && newlen) {
2200 if (newlen != sizeof(int))
2202 if (get_user(new, (int __user *)newval))
2204 *(int *)(table->data) = msecs_to_jiffies(new);
2209 #else /* CONFIG_SYSCTL */
2212 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2217 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2218 void __user *oldval, size_t __user *oldlenp,
2219 void __user *newval, size_t newlen, void **context)
2224 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2225 void __user *oldval, size_t __user *oldlenp,
2226 void __user *newval, size_t newlen, void **context)
2231 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2232 void __user *oldval, size_t __user *oldlenp,
2233 void __user *newval, size_t newlen, void **context)
2238 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2239 void __user *oldval, size_t __user *oldlenp,
2240 void __user *newval, size_t newlen, void **context)
2245 int proc_dostring(ctl_table *table, int write, struct file *filp,
2246 void __user *buffer, size_t *lenp, loff_t *ppos)
2251 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2252 void __user *buffer, size_t *lenp, loff_t *ppos)
2257 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2258 void __user *buffer, size_t *lenp, loff_t *ppos)
2263 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2264 void __user *buffer, size_t *lenp, loff_t *ppos)
2269 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2270 void __user *buffer, size_t *lenp, loff_t *ppos)
2275 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2276 void __user *buffer, size_t *lenp, loff_t *ppos)
2281 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2287 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2288 void __user *buffer, size_t *lenp, loff_t *ppos)
2293 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2295 void __user *buffer,
2296 size_t *lenp, loff_t *ppos)
2301 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2307 void unregister_sysctl_table(struct ctl_table_header * table)
2311 #endif /* CONFIG_SYSCTL */
2314 * No sense putting this after each symbol definition, twice,
2315 * exception granted :-)
2317 EXPORT_SYMBOL(proc_dointvec);
2318 EXPORT_SYMBOL(proc_dointvec_jiffies);
2319 EXPORT_SYMBOL(proc_dointvec_minmax);
2320 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2321 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2322 EXPORT_SYMBOL(proc_dostring);
2323 EXPORT_SYMBOL(proc_doulongvec_minmax);
2324 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2325 EXPORT_SYMBOL(register_sysctl_table);
2326 EXPORT_SYMBOL(sysctl_intvec);
2327 EXPORT_SYMBOL(sysctl_jiffies);
2328 EXPORT_SYMBOL(sysctl_ms_jiffies);
2329 EXPORT_SYMBOL(sysctl_string);
2330 EXPORT_SYMBOL(unregister_sysctl_table);