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>
44 #include <asm/uaccess.h>
45 #include <asm/processor.h>
47 #ifdef CONFIG_ROOT_NFS
48 #include <linux/nfs_fs.h>
51 #if defined(CONFIG_SYSCTL)
53 /* External variables not in a header file. */
54 extern int panic_timeout;
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 sysctl_lower_zone_protection;
65 extern int min_free_kbytes;
66 extern int printk_ratelimit_jiffies;
67 extern int printk_ratelimit_burst;
69 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
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 = KMOD_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,
590 .ctl_name = KERN_PANIC_ON_OOPS,
591 .procname = "panic_on_oops",
592 .data = &panic_on_oops,
593 .maxlen = sizeof(int),
595 .proc_handler = &proc_dointvec,
598 .ctl_name = KERN_PRINTK_RATELIMIT,
599 .procname = "printk_ratelimit",
600 .data = &printk_ratelimit_jiffies,
601 .maxlen = sizeof(int),
603 .proc_handler = &proc_dointvec_jiffies,
604 .strategy = &sysctl_jiffies,
607 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
608 .procname = "printk_ratelimit_burst",
609 .data = &printk_ratelimit_burst,
610 .maxlen = sizeof(int),
612 .proc_handler = &proc_dointvec,
615 .ctl_name = KERN_NGROUPS_MAX,
616 .procname = "ngroups_max",
617 .data = &ngroups_max,
618 .maxlen = sizeof (int),
620 .proc_handler = &proc_dointvec,
622 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
624 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
625 .procname = "unknown_nmi_panic",
626 .data = &unknown_nmi_panic,
627 .maxlen = sizeof (int),
629 .proc_handler = &proc_unknown_nmi_panic,
635 /* Constants for minimum and maximum testing in vm_table.
636 We use these as one-element integer vectors. */
638 static int one_hundred = 100;
641 static ctl_table vm_table[] = {
643 .ctl_name = VM_OVERCOMMIT_MEMORY,
644 .procname = "overcommit_memory",
645 .data = &sysctl_overcommit_memory,
646 .maxlen = sizeof(sysctl_overcommit_memory),
648 .proc_handler = &proc_dointvec,
651 .ctl_name = VM_OVERCOMMIT_RATIO,
652 .procname = "overcommit_ratio",
653 .data = &sysctl_overcommit_ratio,
654 .maxlen = sizeof(sysctl_overcommit_ratio),
656 .proc_handler = &proc_dointvec,
659 .ctl_name = VM_PAGE_CLUSTER,
660 .procname = "page-cluster",
661 .data = &page_cluster,
662 .maxlen = sizeof(int),
664 .proc_handler = &proc_dointvec,
667 .ctl_name = VM_DIRTY_BACKGROUND,
668 .procname = "dirty_background_ratio",
669 .data = &dirty_background_ratio,
670 .maxlen = sizeof(dirty_background_ratio),
672 .proc_handler = &proc_dointvec_minmax,
673 .strategy = &sysctl_intvec,
675 .extra2 = &one_hundred,
678 .ctl_name = VM_DIRTY_RATIO,
679 .procname = "dirty_ratio",
680 .data = &vm_dirty_ratio,
681 .maxlen = sizeof(vm_dirty_ratio),
683 .proc_handler = &proc_dointvec_minmax,
684 .strategy = &sysctl_intvec,
686 .extra2 = &one_hundred,
689 .ctl_name = VM_DIRTY_WB_CS,
690 .procname = "dirty_writeback_centisecs",
691 .data = &dirty_writeback_centisecs,
692 .maxlen = sizeof(dirty_writeback_centisecs),
694 .proc_handler = &dirty_writeback_centisecs_handler,
697 .ctl_name = VM_DIRTY_EXPIRE_CS,
698 .procname = "dirty_expire_centisecs",
699 .data = &dirty_expire_centisecs,
700 .maxlen = sizeof(dirty_expire_centisecs),
702 .proc_handler = &proc_dointvec,
705 .ctl_name = VM_NR_PDFLUSH_THREADS,
706 .procname = "nr_pdflush_threads",
707 .data = &nr_pdflush_threads,
708 .maxlen = sizeof nr_pdflush_threads,
709 .mode = 0444 /* read-only*/,
710 .proc_handler = &proc_dointvec,
713 .ctl_name = VM_SWAPPINESS,
714 .procname = "swappiness",
715 .data = &vm_swappiness,
716 .maxlen = sizeof(vm_swappiness),
718 .proc_handler = &proc_dointvec_minmax,
719 .strategy = &sysctl_intvec,
721 .extra2 = &one_hundred,
723 #ifdef CONFIG_HUGETLB_PAGE
725 .ctl_name = VM_HUGETLB_PAGES,
726 .procname = "nr_hugepages",
727 .data = &max_huge_pages,
728 .maxlen = sizeof(unsigned long),
730 .proc_handler = &hugetlb_sysctl_handler,
731 .extra1 = (void *)&hugetlb_zero,
732 .extra2 = (void *)&hugetlb_infinity,
735 .ctl_name = VM_HUGETLB_GROUP,
736 .procname = "hugetlb_shm_group",
737 .data = &sysctl_hugetlb_shm_group,
738 .maxlen = sizeof(gid_t),
740 .proc_handler = &proc_dointvec,
744 .ctl_name = VM_LOWER_ZONE_PROTECTION,
745 .procname = "lower_zone_protection",
746 .data = &sysctl_lower_zone_protection,
747 .maxlen = sizeof(sysctl_lower_zone_protection),
749 .proc_handler = &lower_zone_protection_sysctl_handler,
750 .strategy = &sysctl_intvec,
754 .ctl_name = VM_MIN_FREE_KBYTES,
755 .procname = "min_free_kbytes",
756 .data = &min_free_kbytes,
757 .maxlen = sizeof(min_free_kbytes),
759 .proc_handler = &min_free_kbytes_sysctl_handler,
760 .strategy = &sysctl_intvec,
764 .ctl_name = VM_MAX_MAP_COUNT,
765 .procname = "max_map_count",
766 .data = &sysctl_max_map_count,
767 .maxlen = sizeof(sysctl_max_map_count),
769 .proc_handler = &proc_dointvec
772 .ctl_name = VM_LAPTOP_MODE,
773 .procname = "laptop_mode",
774 .data = &laptop_mode,
775 .maxlen = sizeof(laptop_mode),
777 .proc_handler = &proc_dointvec,
778 .strategy = &sysctl_intvec,
782 .ctl_name = VM_BLOCK_DUMP,
783 .procname = "block_dump",
785 .maxlen = sizeof(block_dump),
787 .proc_handler = &proc_dointvec,
788 .strategy = &sysctl_intvec,
792 .ctl_name = VM_VFS_CACHE_PRESSURE,
793 .procname = "vfs_cache_pressure",
794 .data = &sysctl_vfs_cache_pressure,
795 .maxlen = sizeof(sysctl_vfs_cache_pressure),
797 .proc_handler = &proc_dointvec,
798 .strategy = &sysctl_intvec,
801 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
803 .ctl_name = VM_LEGACY_VA_LAYOUT,
804 .procname = "legacy_va_layout",
805 .data = &sysctl_legacy_va_layout,
806 .maxlen = sizeof(sysctl_legacy_va_layout),
808 .proc_handler = &proc_dointvec,
809 .strategy = &sysctl_intvec,
816 static ctl_table proc_table[] = {
820 static ctl_table fs_table[] = {
822 .ctl_name = FS_NRINODE,
823 .procname = "inode-nr",
824 .data = &inodes_stat,
825 .maxlen = 2*sizeof(int),
827 .proc_handler = &proc_dointvec,
830 .ctl_name = FS_STATINODE,
831 .procname = "inode-state",
832 .data = &inodes_stat,
833 .maxlen = 7*sizeof(int),
835 .proc_handler = &proc_dointvec,
838 .ctl_name = FS_NRFILE,
839 .procname = "file-nr",
841 .maxlen = 3*sizeof(int),
843 .proc_handler = &proc_dointvec,
846 .ctl_name = FS_MAXFILE,
847 .procname = "file-max",
848 .data = &files_stat.max_files,
849 .maxlen = sizeof(int),
851 .proc_handler = &proc_dointvec,
854 .ctl_name = FS_DENTRY,
855 .procname = "dentry-state",
856 .data = &dentry_stat,
857 .maxlen = 6*sizeof(int),
859 .proc_handler = &proc_dointvec,
862 .ctl_name = FS_OVERFLOWUID,
863 .procname = "overflowuid",
864 .data = &fs_overflowuid,
865 .maxlen = sizeof(int),
867 .proc_handler = &proc_dointvec_minmax,
868 .strategy = &sysctl_intvec,
869 .extra1 = &minolduid,
870 .extra2 = &maxolduid,
873 .ctl_name = FS_OVERFLOWGID,
874 .procname = "overflowgid",
875 .data = &fs_overflowgid,
876 .maxlen = sizeof(int),
878 .proc_handler = &proc_dointvec_minmax,
879 .strategy = &sysctl_intvec,
880 .extra1 = &minolduid,
881 .extra2 = &maxolduid,
884 .ctl_name = FS_LEASES,
885 .procname = "leases-enable",
886 .data = &leases_enable,
887 .maxlen = sizeof(int),
889 .proc_handler = &proc_dointvec,
892 .ctl_name = FS_DIR_NOTIFY,
893 .procname = "dir-notify-enable",
894 .data = &dir_notify_enable,
895 .maxlen = sizeof(int),
897 .proc_handler = &proc_dointvec,
900 .ctl_name = FS_LEASE_TIME,
901 .procname = "lease-break-time",
902 .data = &lease_break_time,
903 .maxlen = sizeof(int),
905 .proc_handler = &proc_dointvec,
908 .ctl_name = FS_AIO_NR,
909 .procname = "aio-nr",
911 .maxlen = sizeof(aio_nr),
913 .proc_handler = &proc_dointvec,
916 .ctl_name = FS_AIO_MAX_NR,
917 .procname = "aio-max-nr",
919 .maxlen = sizeof(aio_max_nr),
921 .proc_handler = &proc_dointvec,
926 static ctl_table debug_table[] = {
930 static ctl_table dev_table[] = {
934 extern void init_irq_proc (void);
936 void __init sysctl_init(void)
938 #ifdef CONFIG_PROC_FS
939 register_proc_table(root_table, proc_sys_root);
944 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
945 void __user *newval, size_t newlen)
947 struct list_head *tmp;
949 if (nlen <= 0 || nlen >= CTL_MAXNAME)
953 if (!oldlenp || get_user(old_len, oldlenp))
956 tmp = &root_table_header.ctl_entry;
958 struct ctl_table_header *head =
959 list_entry(tmp, struct ctl_table_header, ctl_entry);
960 void *context = NULL;
961 int error = parse_table(name, nlen, oldval, oldlenp,
962 newval, newlen, head->ctl_table,
966 if (error != -ENOTDIR)
969 } while (tmp != &root_table_header.ctl_entry);
973 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
975 struct __sysctl_args tmp;
978 if (copy_from_user(&tmp, args, sizeof(tmp)))
982 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
983 tmp.newval, tmp.newlen);
989 * ctl_perm does NOT grant the superuser all rights automatically, because
990 * some sysctl variables are readonly even to root.
993 static int test_perm(int mode, int op)
997 else if (in_egroup_p(0))
999 if ((mode & op & 0007) == op)
1004 static inline int ctl_perm(ctl_table *table, int op)
1007 error = security_sysctl(table, op);
1010 return test_perm(table->mode, op);
1013 static int parse_table(int __user *name, int nlen,
1014 void __user *oldval, size_t __user *oldlenp,
1015 void __user *newval, size_t newlen,
1016 ctl_table *table, void **context)
1022 if (get_user(n, name))
1024 for ( ; table->ctl_name; table++) {
1025 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1028 if (ctl_perm(table, 001))
1030 if (table->strategy) {
1031 error = table->strategy(
1034 newval, newlen, context);
1040 table = table->child;
1043 error = do_sysctl_strategy(table, name, nlen,
1045 newval, newlen, context);
1052 /* Perform the actual read/write of a sysctl table entry. */
1053 int do_sysctl_strategy (ctl_table *table,
1054 int __user *name, int nlen,
1055 void __user *oldval, size_t __user *oldlenp,
1056 void __user *newval, size_t newlen, void **context)
1065 if (ctl_perm(table, op))
1068 if (table->strategy) {
1069 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1070 newval, newlen, context);
1077 /* If there is no strategy routine, or if the strategy returns
1078 * zero, proceed with automatic r/w */
1079 if (table->data && table->maxlen) {
1080 if (oldval && oldlenp) {
1081 if (get_user(len, oldlenp))
1084 if (len > table->maxlen)
1085 len = table->maxlen;
1086 if(copy_to_user(oldval, table->data, len))
1088 if(put_user(len, oldlenp))
1092 if (newval && newlen) {
1094 if (len > table->maxlen)
1095 len = table->maxlen;
1096 if(copy_from_user(table->data, newval, len))
1104 * register_sysctl_table - register a sysctl hierarchy
1105 * @table: the top-level table structure
1106 * @insert_at_head: whether the entry should be inserted in front or at the end
1108 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1109 * array. An entry with a ctl_name of 0 terminates the table.
1111 * The members of the &ctl_table structure are used as follows:
1113 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1114 * must be unique within that level of sysctl
1116 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1117 * enter a sysctl file
1119 * data - a pointer to data for use by proc_handler
1121 * maxlen - the maximum size in bytes of the data
1123 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1125 * child - a pointer to the child sysctl table if this entry is a directory, or
1128 * proc_handler - the text handler routine (described below)
1130 * strategy - the strategy routine (described below)
1132 * de - for internal use by the sysctl routines
1134 * extra1, extra2 - extra pointers usable by the proc handler routines
1136 * Leaf nodes in the sysctl tree will be represented by a single file
1137 * under /proc; non-leaf nodes will be represented by directories.
1139 * sysctl(2) can automatically manage read and write requests through
1140 * the sysctl table. The data and maxlen fields of the ctl_table
1141 * struct enable minimal validation of the values being written to be
1142 * performed, and the mode field allows minimal authentication.
1144 * More sophisticated management can be enabled by the provision of a
1145 * strategy routine with the table entry. This will be called before
1146 * any automatic read or write of the data is performed.
1148 * The strategy routine may return
1150 * < 0 - Error occurred (error is passed to user process)
1152 * 0 - OK - proceed with automatic read or write.
1154 * > 0 - OK - read or write has been done by the strategy routine, so
1155 * return immediately.
1157 * There must be a proc_handler routine for any terminal nodes
1158 * mirrored under /proc/sys (non-terminals are handled by a built-in
1159 * directory handler). Several default handlers are available to
1160 * cover common cases -
1162 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1163 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1164 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1166 * It is the handler's job to read the input buffer from user memory
1167 * and process it. The handler should return 0 on success.
1169 * This routine returns %NULL on a failure to register, and a pointer
1170 * to the table header on success.
1172 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1175 struct ctl_table_header *tmp;
1176 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1179 tmp->ctl_table = table;
1180 INIT_LIST_HEAD(&tmp->ctl_entry);
1182 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1184 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1185 #ifdef CONFIG_PROC_FS
1186 register_proc_table(table, proc_sys_root);
1192 * unregister_sysctl_table - unregister a sysctl table hierarchy
1193 * @header: the header returned from register_sysctl_table
1195 * Unregisters the sysctl table and all children. proc entries may not
1196 * actually be removed until they are no longer used by anyone.
1198 void unregister_sysctl_table(struct ctl_table_header * header)
1200 list_del(&header->ctl_entry);
1201 #ifdef CONFIG_PROC_FS
1202 unregister_proc_table(header->ctl_table, proc_sys_root);
1211 #ifdef CONFIG_PROC_FS
1213 /* Scan the sysctl entries in table and add them all into /proc */
1214 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1216 struct proc_dir_entry *de;
1220 for (; table->ctl_name; table++) {
1221 /* Can't do anything without a proc name. */
1222 if (!table->procname)
1224 /* Maybe we can't do anything with it... */
1225 if (!table->proc_handler && !table->child) {
1226 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1231 len = strlen(table->procname);
1235 if (table->proc_handler)
1239 for (de = root->subdir; de; de = de->next) {
1240 if (proc_match(len, table->procname, de))
1243 /* If the subdir exists already, de is non-NULL */
1247 de = create_proc_entry(table->procname, mode, root);
1250 de->data = (void *) table;
1251 if (table->proc_handler)
1252 de->proc_fops = &proc_sys_file_operations;
1255 if (de->mode & S_IFDIR)
1256 register_proc_table(table->child, de);
1261 * Unregister a /proc sysctl table and any subdirectories.
1263 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1265 struct proc_dir_entry *de;
1266 for (; table->ctl_name; table++) {
1267 if (!(de = table->de))
1269 if (de->mode & S_IFDIR) {
1270 if (!table->child) {
1271 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1274 unregister_proc_table(table->child, de);
1276 /* Don't unregister directories which still have entries.. */
1281 /* Don't unregister proc entries that are still being used.. */
1282 if (atomic_read(&de->count))
1286 remove_proc_entry(table->procname, root);
1290 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1291 size_t count, loff_t *ppos)
1294 struct proc_dir_entry *de;
1295 struct ctl_table *table;
1299 de = PDE(file->f_dentry->d_inode);
1300 if (!de || !de->data)
1302 table = (struct ctl_table *) de->data;
1303 if (!table || !table->proc_handler)
1305 op = (write ? 002 : 004);
1306 if (ctl_perm(table, op))
1311 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1317 static int proc_opensys(struct inode *inode, struct file *file)
1319 if (file->f_mode & FMODE_WRITE) {
1321 * sysctl entries that are not writable,
1322 * are _NOT_ writable, capabilities or not.
1324 if (!(inode->i_mode & S_IWUSR))
1331 static ssize_t proc_readsys(struct file * file, char __user * buf,
1332 size_t count, loff_t *ppos)
1334 return do_rw_proc(0, file, buf, count, ppos);
1337 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1338 size_t count, loff_t *ppos)
1340 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1344 * proc_dostring - read a string sysctl
1345 * @table: the sysctl table
1346 * @write: %TRUE if this is a write to the sysctl file
1347 * @filp: the file structure
1348 * @buffer: the user buffer
1349 * @lenp: the size of the user buffer
1351 * Reads/writes a string from/to the user buffer. If the kernel
1352 * buffer provided is not large enough to hold the string, the
1353 * string is truncated. The copied string is %NULL-terminated.
1354 * If the string is being read by the user process, it is copied
1355 * and a newline '\n' is added. It is truncated if the buffer is
1358 * Returns 0 on success.
1360 int proc_dostring(ctl_table *table, int write, struct file *filp,
1361 void __user *buffer, size_t *lenp, loff_t *ppos)
1367 if (!table->data || !table->maxlen || !*lenp ||
1368 (*ppos && !write)) {
1376 while (len < *lenp) {
1377 if (get_user(c, p++))
1379 if (c == 0 || c == '\n')
1383 if (len >= table->maxlen)
1384 len = table->maxlen-1;
1385 if(copy_from_user(table->data, buffer, len))
1387 ((char *) table->data)[len] = 0;
1390 len = strlen(table->data);
1391 if (len > table->maxlen)
1392 len = table->maxlen;
1396 if(copy_to_user(buffer, table->data, len))
1399 if(put_user('\n', ((char __user *) buffer) + len))
1410 * Special case of dostring for the UTS structure. This has locks
1411 * to observe. Should this be in kernel/sys.c ????
1414 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1415 void __user *buffer, size_t *lenp, loff_t *ppos)
1420 down_read(&uts_sem);
1421 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1424 down_write(&uts_sem);
1425 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1431 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1433 int write, void *data)
1436 *valp = *negp ? -*lvalp : *lvalp;
1441 *lvalp = (unsigned long)-val;
1444 *lvalp = (unsigned long)val;
1450 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1451 void __user *buffer, size_t *lenp, loff_t *ppos,
1452 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1453 int write, void *data),
1456 #define TMPBUFLEN 21
1457 int *i, vleft, first=1, neg, val;
1461 char buf[TMPBUFLEN], *p;
1462 char __user *s = buffer;
1464 if (!table->data || !table->maxlen || !*lenp ||
1465 (*ppos && !write)) {
1470 i = (int *) table->data;
1471 vleft = table->maxlen / sizeof(*i);
1475 conv = do_proc_dointvec_conv;
1477 for (; left && vleft--; i++, first=0) {
1492 if (len > sizeof(buf) - 1)
1493 len = sizeof(buf) - 1;
1494 if (copy_from_user(buf, s, len))
1498 if (*p == '-' && left > 1) {
1502 if (*p < '0' || *p > '9')
1505 lval = simple_strtoul(p, &p, 0);
1508 if ((len < left) && *p && !isspace(*p))
1515 if (conv(&neg, &lval, i, 1, data))
1522 if (conv(&neg, &lval, i, 0, data))
1525 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1529 if(copy_to_user(s, buf, len))
1536 if (!write && !first && left) {
1537 if(put_user('\n', s))
1544 if (get_user(c, s++))
1560 * proc_dointvec - read a vector of integers
1561 * @table: the sysctl table
1562 * @write: %TRUE if this is a write to the sysctl file
1563 * @filp: the file structure
1564 * @buffer: the user buffer
1565 * @lenp: the size of the user buffer
1567 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1568 * values from/to the user buffer, treated as an ASCII string.
1570 * Returns 0 on success.
1572 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1573 void __user *buffer, size_t *lenp, loff_t *ppos)
1575 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1585 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1587 int write, void *data)
1589 int op = *(int *)data;
1591 int val = *negp ? -*lvalp : *lvalp;
1593 case OP_SET: *valp = val; break;
1594 case OP_AND: *valp &= val; break;
1595 case OP_OR: *valp |= val; break;
1596 case OP_MAX: if(*valp < val)
1599 case OP_MIN: if(*valp > val)
1607 *lvalp = (unsigned long)-val;
1610 *lvalp = (unsigned long)val;
1617 * init may raise the set.
1620 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1621 void __user *buffer, size_t *lenp, loff_t *ppos)
1625 if (!capable(CAP_SYS_MODULE)) {
1629 op = (current->pid == 1) ? OP_SET : OP_AND;
1630 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1631 do_proc_dointvec_bset_conv,&op);
1634 struct do_proc_dointvec_minmax_conv_param {
1639 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1641 int write, void *data)
1643 struct do_proc_dointvec_minmax_conv_param *param = data;
1645 int val = *negp ? -*lvalp : *lvalp;
1646 if ((param->min && *param->min > val) ||
1647 (param->max && *param->max < val))
1654 *lvalp = (unsigned long)-val;
1657 *lvalp = (unsigned long)val;
1664 * proc_dointvec_minmax - read a vector of integers with min/max values
1665 * @table: the sysctl table
1666 * @write: %TRUE if this is a write to the sysctl file
1667 * @filp: the file structure
1668 * @buffer: the user buffer
1669 * @lenp: the size of the user buffer
1671 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1672 * values from/to the user buffer, treated as an ASCII string.
1674 * This routine will ensure the values are within the range specified by
1675 * table->extra1 (min) and table->extra2 (max).
1677 * Returns 0 on success.
1679 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1680 void __user *buffer, size_t *lenp, loff_t *ppos)
1682 struct do_proc_dointvec_minmax_conv_param param = {
1683 .min = (int *) table->extra1,
1684 .max = (int *) table->extra2,
1686 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1687 do_proc_dointvec_minmax_conv, ¶m);
1690 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1692 void __user *buffer,
1693 size_t *lenp, loff_t *ppos,
1694 unsigned long convmul,
1695 unsigned long convdiv)
1697 #define TMPBUFLEN 21
1698 unsigned long *i, *min, *max, val;
1699 int vleft, first=1, neg;
1701 char buf[TMPBUFLEN], *p;
1702 char __user *s = buffer;
1704 if (!table->data || !table->maxlen || !*lenp ||
1705 (*ppos && !write)) {
1710 i = (unsigned long *) table->data;
1711 min = (unsigned long *) table->extra1;
1712 max = (unsigned long *) table->extra2;
1713 vleft = table->maxlen / sizeof(unsigned long);
1716 for (; left && vleft--; i++, min++, max++, first=0) {
1731 if (len > TMPBUFLEN-1)
1733 if (copy_from_user(buf, s, len))
1737 if (*p == '-' && left > 1) {
1741 if (*p < '0' || *p > '9')
1743 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1745 if ((len < left) && *p && !isspace(*p))
1754 if ((min && val < *min) || (max && val > *max))
1761 sprintf(p, "%lu", convdiv * (*i) / convmul);
1765 if(copy_to_user(s, buf, len))
1772 if (!write && !first && left) {
1773 if(put_user('\n', s))
1780 if (get_user(c, s++))
1796 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1797 * @table: the sysctl table
1798 * @write: %TRUE if this is a write to the sysctl file
1799 * @filp: the file structure
1800 * @buffer: the user buffer
1801 * @lenp: the size of the user buffer
1803 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1804 * values from/to the user buffer, treated as an ASCII string.
1806 * This routine will ensure the values are within the range specified by
1807 * table->extra1 (min) and table->extra2 (max).
1809 * Returns 0 on success.
1811 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1812 void __user *buffer, size_t *lenp, loff_t *ppos)
1814 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1818 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1819 * @table: the sysctl table
1820 * @write: %TRUE if this is a write to the sysctl file
1821 * @filp: the file structure
1822 * @buffer: the user buffer
1823 * @lenp: the size of the user buffer
1825 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1826 * values from/to the user buffer, treated as an ASCII string. The values
1827 * are treated as milliseconds, and converted to jiffies when they are stored.
1829 * This routine will ensure the values are within the range specified by
1830 * table->extra1 (min) and table->extra2 (max).
1832 * Returns 0 on success.
1834 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1836 void __user *buffer,
1837 size_t *lenp, loff_t *ppos)
1839 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1840 lenp, ppos, HZ, 1000l);
1844 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1846 int write, void *data)
1849 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1855 lval = (unsigned long)-val;
1858 lval = (unsigned long)val;
1865 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1867 int write, void *data)
1870 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1876 lval = (unsigned long)-val;
1879 lval = (unsigned long)val;
1881 *lvalp = jiffies_to_clock_t(lval);
1887 * proc_dointvec_jiffies - read a vector of integers as seconds
1888 * @table: the sysctl table
1889 * @write: %TRUE if this is a write to the sysctl file
1890 * @filp: the file structure
1891 * @buffer: the user buffer
1892 * @lenp: the size of the user buffer
1894 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1895 * values from/to the user buffer, treated as an ASCII string.
1896 * The values read are assumed to be in seconds, and are converted into
1899 * Returns 0 on success.
1901 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1902 void __user *buffer, size_t *lenp, loff_t *ppos)
1904 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1905 do_proc_dointvec_jiffies_conv,NULL);
1909 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1910 * @table: the sysctl table
1911 * @write: %TRUE if this is a write to the sysctl file
1912 * @filp: the file structure
1913 * @buffer: the user buffer
1914 * @lenp: the size of the user buffer
1916 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1917 * values from/to the user buffer, treated as an ASCII string.
1918 * The values read are assumed to be in 1/USER_HZ seconds, and
1919 * are converted into jiffies.
1921 * Returns 0 on success.
1923 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1924 void __user *buffer, size_t *lenp, loff_t *ppos)
1926 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1927 do_proc_dointvec_userhz_jiffies_conv,NULL);
1930 #else /* CONFIG_PROC_FS */
1932 int proc_dostring(ctl_table *table, int write, struct file *filp,
1933 void __user *buffer, size_t *lenp, loff_t *ppos)
1938 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1939 void __user *buffer, size_t *lenp, loff_t *ppos)
1944 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1945 void __user *buffer, size_t *lenp, loff_t *ppos)
1950 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1951 void __user *buffer, size_t *lenp, loff_t *ppos)
1956 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1957 void __user *buffer, size_t *lenp, loff_t *ppos)
1962 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1963 void __user *buffer, size_t *lenp, loff_t *ppos)
1968 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1969 void __user *buffer, size_t *lenp, loff_t *ppos)
1974 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1975 void __user *buffer, size_t *lenp, loff_t *ppos)
1980 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1982 void __user *buffer,
1983 size_t *lenp, loff_t *ppos)
1989 #endif /* CONFIG_PROC_FS */
1993 * General sysctl support routines
1996 /* The generic string strategy routine: */
1997 int sysctl_string(ctl_table *table, int __user *name, int nlen,
1998 void __user *oldval, size_t __user *oldlenp,
1999 void __user *newval, size_t newlen, void **context)
2003 if (!table->data || !table->maxlen)
2006 if (oldval && oldlenp) {
2007 if (get_user(len, oldlenp))
2010 l = strlen(table->data);
2011 if (len > l) len = l;
2012 if (len >= table->maxlen)
2013 len = table->maxlen;
2014 if(copy_to_user(oldval, table->data, len))
2016 if(put_user(0, ((char __user *) oldval) + len))
2018 if(put_user(len, oldlenp))
2022 if (newval && newlen) {
2024 if (len > table->maxlen)
2025 len = table->maxlen;
2026 if(copy_from_user(table->data, newval, len))
2028 if (len == table->maxlen)
2030 ((char *) table->data)[len] = 0;
2036 * This function makes sure that all of the integers in the vector
2037 * are between the minimum and maximum values given in the arrays
2038 * table->extra1 and table->extra2, respectively.
2040 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2041 void __user *oldval, size_t __user *oldlenp,
2042 void __user *newval, size_t newlen, void **context)
2045 if (newval && newlen) {
2046 int __user *vec = (int __user *) newval;
2047 int *min = (int *) table->extra1;
2048 int *max = (int *) table->extra2;
2052 if (newlen % sizeof(int) != 0)
2055 if (!table->extra1 && !table->extra2)
2058 if (newlen > table->maxlen)
2059 newlen = table->maxlen;
2060 length = newlen / sizeof(int);
2062 for (i = 0; i < length; i++) {
2064 if (get_user(value, vec + i))
2066 if (min && value < min[i])
2068 if (max && value > max[i])
2075 /* Strategy function to convert jiffies to seconds */
2076 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2077 void __user *oldval, size_t __user *oldlenp,
2078 void __user *newval, size_t newlen, void **context)
2083 if (get_user(olen, oldlenp))
2085 if (olen!=sizeof(int))
2088 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2089 (oldlenp && put_user(sizeof(int),oldlenp)))
2092 if (newval && newlen) {
2094 if (newlen != sizeof(int))
2096 if (get_user(new, (int __user *)newval))
2098 *(int *)(table->data) = new*HZ;
2104 #else /* CONFIG_SYSCTL */
2107 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2112 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2113 void __user *oldval, size_t __user *oldlenp,
2114 void __user *newval, size_t newlen, void **context)
2119 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2120 void __user *oldval, size_t __user *oldlenp,
2121 void __user *newval, size_t newlen, void **context)
2126 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2127 void __user *oldval, size_t __user *oldlenp,
2128 void __user *newval, size_t newlen, void **context)
2133 int proc_dostring(ctl_table *table, int write, struct file *filp,
2134 void __user *buffer, size_t *lenp, loff_t *ppos)
2139 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2140 void __user *buffer, size_t *lenp, loff_t *ppos)
2145 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2146 void __user *buffer, size_t *lenp, loff_t *ppos)
2151 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2152 void __user *buffer, size_t *lenp, loff_t *ppos)
2157 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2158 void __user *buffer, size_t *lenp, loff_t *ppos)
2163 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2164 void __user *buffer, size_t *lenp, loff_t *ppos)
2169 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2170 void __user *buffer, size_t *lenp, loff_t *ppos)
2175 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2177 void __user *buffer,
2178 size_t *lenp, loff_t *ppos)
2183 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2189 void unregister_sysctl_table(struct ctl_table_header * table)
2193 #endif /* CONFIG_SYSCTL */
2196 * No sense putting this after each symbol definition, twice,
2197 * exception granted :-)
2199 EXPORT_SYMBOL(proc_dointvec);
2200 EXPORT_SYMBOL(proc_dointvec_jiffies);
2201 EXPORT_SYMBOL(proc_dointvec_minmax);
2202 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2203 EXPORT_SYMBOL(proc_dostring);
2204 EXPORT_SYMBOL(proc_doulongvec_minmax);
2205 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2206 EXPORT_SYMBOL(register_sysctl_table);
2207 EXPORT_SYMBOL(sysctl_intvec);
2208 EXPORT_SYMBOL(sysctl_jiffies);
2209 EXPORT_SYMBOL(sysctl_string);
2210 EXPORT_SYMBOL(unregister_sysctl_table);