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 int suid_dumpable;
62 extern char core_pattern[];
65 extern int sysctl_lower_zone_protection;
66 extern int min_free_kbytes;
67 extern int printk_ratelimit_jiffies;
68 extern int printk_ratelimit_burst;
70 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
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 extern unsigned int vdso_enabled;
79 int exec_shield_randomize = 1;
81 static int __init setup_exec_shield(char *str)
83 get_option (&str, &exec_shield);
88 __setup("exec-shield=", setup_exec_shield);
90 static int __init setup_exec_shield_randomize(char *str)
92 get_option (&str, &exec_shield_randomize);
97 __setup("exec-shield-randomize=", setup_exec_shield_randomize);
99 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
100 static int maxolduid = 65535;
101 static int minolduid;
103 static int ngroups_max = NGROUPS_MAX;
106 extern char modprobe_path[];
108 #ifdef CONFIG_HOTPLUG
109 extern char hotplug_path[];
111 extern char vshelper_path[];
112 #ifdef CONFIG_CHR_DEV_SG
113 extern int sg_big_buff;
115 #ifdef CONFIG_SYSVIPC
116 extern size_t shm_ctlmax;
117 extern size_t shm_ctlall;
118 extern int shm_ctlmni;
119 extern int msg_ctlmax;
120 extern int msg_ctlmnb;
121 extern int msg_ctlmni;
122 extern int sem_ctls[];
126 extern char reboot_command [];
127 extern int stop_a_enabled;
128 extern int scons_pwroff;
132 extern int pwrsw_enabled;
133 extern int unaligned_enabled;
136 #ifdef CONFIG_ARCH_S390
137 #ifdef CONFIG_MATHEMU
138 extern int sysctl_ieee_emulation_warnings;
140 extern int sysctl_userprocess_debug;
143 extern int sysctl_hz_timer;
145 #ifdef CONFIG_BSD_PROCESS_ACCT
146 extern int acct_parm[];
149 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
150 ctl_table *, void **);
151 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
152 void __user *buffer, size_t *lenp, loff_t *ppos);
154 static ctl_table root_table[];
155 static struct ctl_table_header root_table_header =
156 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
158 static ctl_table kern_table[];
159 static ctl_table vm_table[];
161 extern ctl_table net_table[];
163 static ctl_table proc_table[];
164 static ctl_table fs_table[];
165 static ctl_table debug_table[];
166 static ctl_table dev_table[];
167 extern ctl_table random_table[];
168 #ifdef CONFIG_UNIX98_PTYS
169 extern ctl_table pty_table[];
172 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
173 int sysctl_legacy_va_layout;
176 /* /proc declarations: */
178 #ifdef CONFIG_PROC_FS
180 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
181 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
182 static int proc_opensys(struct inode *, struct file *);
184 struct file_operations proc_sys_file_operations = {
185 .open = proc_opensys,
186 .read = proc_readsys,
187 .write = proc_writesys,
190 extern struct proc_dir_entry *proc_sys_root;
192 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
193 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
196 /* The default sysctl tables: */
198 static ctl_table root_table[] = {
200 .ctl_name = CTL_KERN,
201 .procname = "kernel",
220 .ctl_name = CTL_PROC,
232 .ctl_name = CTL_DEBUG,
235 .child = debug_table,
246 static ctl_table kern_table[] = {
248 .ctl_name = KERN_OSTYPE,
249 .procname = "ostype",
250 .data = system_utsname.sysname,
251 .maxlen = sizeof(system_utsname.sysname),
253 .proc_handler = &proc_doutsstring,
254 .strategy = &sysctl_string,
257 .ctl_name = KERN_OSRELEASE,
258 .procname = "osrelease",
259 .data = system_utsname.release,
260 .maxlen = sizeof(system_utsname.release),
262 .proc_handler = &proc_doutsstring,
263 .strategy = &sysctl_string,
266 .ctl_name = KERN_VERSION,
267 .procname = "version",
268 .data = system_utsname.version,
269 .maxlen = sizeof(system_utsname.version),
271 .proc_handler = &proc_doutsstring,
272 .strategy = &sysctl_string,
275 .ctl_name = KERN_NODENAME,
276 .procname = "hostname",
277 .data = system_utsname.nodename,
278 .maxlen = sizeof(system_utsname.nodename),
280 .proc_handler = &proc_doutsstring,
281 .strategy = &sysctl_string,
284 .ctl_name = KERN_DOMAINNAME,
285 .procname = "domainname",
286 .data = system_utsname.domainname,
287 .maxlen = sizeof(system_utsname.domainname),
289 .proc_handler = &proc_doutsstring,
290 .strategy = &sysctl_string,
293 .ctl_name = KERN_PANIC,
295 .data = &panic_timeout,
296 .maxlen = sizeof(int),
298 .proc_handler = &proc_dointvec,
301 .ctl_name = KERN_PANIC,
302 .procname = "exec-shield",
303 .data = &exec_shield,
304 .maxlen = sizeof(int),
306 .proc_handler = &proc_dointvec,
309 .ctl_name = KERN_PANIC,
310 .procname = "exec-shield-randomize",
311 .data = &exec_shield_randomize,
312 .maxlen = sizeof(int),
314 .proc_handler = &proc_dointvec,
317 .ctl_name = KERN_PANIC,
318 .procname = "print-fatal-signals",
319 .data = &print_fatal_signals,
320 .maxlen = sizeof(int),
322 .proc_handler = &proc_dointvec,
326 .ctl_name = KERN_PANIC,
328 .data = &vdso_enabled,
329 .maxlen = sizeof(int),
331 .proc_handler = &proc_dointvec,
335 .ctl_name = KERN_CORE_USES_PID,
336 .procname = "core_uses_pid",
337 .data = &core_uses_pid,
338 .maxlen = sizeof(int),
340 .proc_handler = &proc_dointvec,
343 .ctl_name = KERN_CORE_PATTERN,
344 .procname = "core_pattern",
345 .data = core_pattern,
348 .proc_handler = &proc_dostring,
349 .strategy = &sysctl_string,
352 .ctl_name = KERN_TAINTED,
353 .procname = "tainted",
355 .maxlen = sizeof(int),
357 .proc_handler = &proc_dointvec,
360 .ctl_name = KERN_CAP_BSET,
361 .procname = "cap-bound",
363 .maxlen = sizeof(kernel_cap_t),
365 .proc_handler = &proc_dointvec_bset,
367 #ifdef CONFIG_BLK_DEV_INITRD
369 .ctl_name = KERN_REALROOTDEV,
370 .procname = "real-root-dev",
371 .data = &real_root_dev,
372 .maxlen = sizeof(int),
374 .proc_handler = &proc_dointvec,
379 .ctl_name = KERN_SPARC_REBOOT,
380 .procname = "reboot-cmd",
381 .data = reboot_command,
384 .proc_handler = &proc_dostring,
385 .strategy = &sysctl_string,
388 .ctl_name = KERN_SPARC_STOP_A,
389 .procname = "stop-a",
390 .data = &stop_a_enabled,
391 .maxlen = sizeof (int),
393 .proc_handler = &proc_dointvec,
396 .ctl_name = KERN_SPARC_SCONS_PWROFF,
397 .procname = "scons-poweroff",
398 .data = &scons_pwroff,
399 .maxlen = sizeof (int),
401 .proc_handler = &proc_dointvec,
406 .ctl_name = KERN_HPPA_PWRSW,
407 .procname = "soft-power",
408 .data = &pwrsw_enabled,
409 .maxlen = sizeof (int),
411 .proc_handler = &proc_dointvec,
414 .ctl_name = KERN_HPPA_UNALIGNED,
415 .procname = "unaligned-trap",
416 .data = &unaligned_enabled,
417 .maxlen = sizeof (int),
419 .proc_handler = &proc_dointvec,
423 .ctl_name = KERN_CTLALTDEL,
424 .procname = "ctrl-alt-del",
426 .maxlen = sizeof(int),
428 .proc_handler = &proc_dointvec,
431 .ctl_name = KERN_PRINTK,
432 .procname = "printk",
433 .data = &console_loglevel,
434 .maxlen = 4*sizeof(int),
436 .proc_handler = &proc_dointvec,
440 .ctl_name = KERN_MODPROBE,
441 .procname = "modprobe",
442 .data = &modprobe_path,
443 .maxlen = KMOD_PATH_LEN,
445 .proc_handler = &proc_dostring,
446 .strategy = &sysctl_string,
449 #ifdef CONFIG_HOTPLUG
451 .ctl_name = KERN_HOTPLUG,
452 .procname = "hotplug",
453 .data = &hotplug_path,
454 .maxlen = KMOD_PATH_LEN,
456 .proc_handler = &proc_dostring,
457 .strategy = &sysctl_string,
461 .ctl_name = KERN_VSHELPER,
462 .procname = "vshelper",
463 .data = &vshelper_path,
466 .proc_handler = &proc_dostring,
467 .strategy = &sysctl_string,
469 #ifdef CONFIG_CHR_DEV_SG
471 .ctl_name = KERN_SG_BIG_BUFF,
472 .procname = "sg-big-buff",
473 .data = &sg_big_buff,
474 .maxlen = sizeof (int),
476 .proc_handler = &proc_dointvec,
479 #ifdef CONFIG_BSD_PROCESS_ACCT
481 .ctl_name = KERN_ACCT,
484 .maxlen = 3*sizeof(int),
486 .proc_handler = &proc_dointvec,
489 #ifdef CONFIG_SYSVIPC
491 .ctl_name = KERN_SHMMAX,
492 .procname = "shmmax",
494 .maxlen = sizeof (size_t),
496 .proc_handler = &proc_doulongvec_minmax,
499 .ctl_name = KERN_SHMALL,
500 .procname = "shmall",
502 .maxlen = sizeof (size_t),
504 .proc_handler = &proc_doulongvec_minmax,
507 .ctl_name = KERN_SHMMNI,
508 .procname = "shmmni",
510 .maxlen = sizeof (int),
512 .proc_handler = &proc_dointvec,
515 .ctl_name = KERN_MSGMAX,
516 .procname = "msgmax",
518 .maxlen = sizeof (int),
520 .proc_handler = &proc_dointvec,
523 .ctl_name = KERN_MSGMNI,
524 .procname = "msgmni",
526 .maxlen = sizeof (int),
528 .proc_handler = &proc_dointvec,
531 .ctl_name = KERN_MSGMNB,
532 .procname = "msgmnb",
534 .maxlen = sizeof (int),
536 .proc_handler = &proc_dointvec,
539 .ctl_name = KERN_SEM,
542 .maxlen = 4*sizeof (int),
544 .proc_handler = &proc_dointvec,
547 #ifdef CONFIG_MAGIC_SYSRQ
549 .ctl_name = KERN_SYSRQ,
551 .data = &sysrq_enabled,
552 .maxlen = sizeof (int),
554 .proc_handler = &proc_dointvec,
558 .ctl_name = KERN_CADPID,
559 .procname = "cad_pid",
561 .maxlen = sizeof (int),
563 .proc_handler = &proc_dointvec,
566 .ctl_name = KERN_MAX_THREADS,
567 .procname = "threads-max",
568 .data = &max_threads,
569 .maxlen = sizeof(int),
571 .proc_handler = &proc_dointvec,
574 .ctl_name = KERN_RANDOM,
575 .procname = "random",
577 .child = random_table,
579 #ifdef CONFIG_UNIX98_PTYS
581 .ctl_name = KERN_PTY,
588 .ctl_name = KERN_OVERFLOWUID,
589 .procname = "overflowuid",
590 .data = &overflowuid,
591 .maxlen = sizeof(int),
593 .proc_handler = &proc_dointvec_minmax,
594 .strategy = &sysctl_intvec,
595 .extra1 = &minolduid,
596 .extra2 = &maxolduid,
599 .ctl_name = KERN_OVERFLOWGID,
600 .procname = "overflowgid",
601 .data = &overflowgid,
602 .maxlen = sizeof(int),
604 .proc_handler = &proc_dointvec_minmax,
605 .strategy = &sysctl_intvec,
606 .extra1 = &minolduid,
607 .extra2 = &maxolduid,
609 #ifdef CONFIG_ARCH_S390
610 #ifdef CONFIG_MATHEMU
612 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
613 .procname = "ieee_emulation_warnings",
614 .data = &sysctl_ieee_emulation_warnings,
615 .maxlen = sizeof(int),
617 .proc_handler = &proc_dointvec,
620 #ifdef CONFIG_NO_IDLE_HZ
622 .ctl_name = KERN_HZ_TIMER,
623 .procname = "hz_timer",
624 .data = &sysctl_hz_timer,
625 .maxlen = sizeof(int),
627 .proc_handler = &proc_dointvec,
631 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
632 .procname = "userprocess_debug",
633 .data = &sysctl_userprocess_debug,
634 .maxlen = sizeof(int),
636 .proc_handler = &proc_dointvec,
640 .ctl_name = KERN_PIDMAX,
641 .procname = "pid_max",
643 .maxlen = sizeof (int),
645 .proc_handler = &proc_dointvec,
648 .ctl_name = KERN_PANIC_ON_OOPS,
649 .procname = "panic_on_oops",
650 .data = &panic_on_oops,
651 .maxlen = sizeof(int),
653 .proc_handler = &proc_dointvec,
656 .ctl_name = KERN_PRINTK_RATELIMIT,
657 .procname = "printk_ratelimit",
658 .data = &printk_ratelimit_jiffies,
659 .maxlen = sizeof(int),
661 .proc_handler = &proc_dointvec_jiffies,
662 .strategy = &sysctl_jiffies,
665 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
666 .procname = "printk_ratelimit_burst",
667 .data = &printk_ratelimit_burst,
668 .maxlen = sizeof(int),
670 .proc_handler = &proc_dointvec,
673 .ctl_name = KERN_NGROUPS_MAX,
674 .procname = "ngroups_max",
675 .data = &ngroups_max,
676 .maxlen = sizeof (int),
678 .proc_handler = &proc_dointvec,
680 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
682 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
683 .procname = "unknown_nmi_panic",
684 .data = &unknown_nmi_panic,
685 .maxlen = sizeof (int),
687 .proc_handler = &proc_unknown_nmi_panic,
691 .ctl_name = KERN_SETUID_DUMPABLE,
692 .procname = "suid_dumpable",
693 .data = &suid_dumpable,
694 .maxlen = sizeof(int),
696 .proc_handler = &proc_dointvec,
701 /* Constants for minimum and maximum testing in vm_table.
702 We use these as one-element integer vectors. */
704 static int one_hundred = 100;
707 static ctl_table vm_table[] = {
709 .ctl_name = VM_OVERCOMMIT_MEMORY,
710 .procname = "overcommit_memory",
711 .data = &sysctl_overcommit_memory,
712 .maxlen = sizeof(sysctl_overcommit_memory),
714 .proc_handler = &proc_dointvec,
717 .ctl_name = VM_OVERCOMMIT_RATIO,
718 .procname = "overcommit_ratio",
719 .data = &sysctl_overcommit_ratio,
720 .maxlen = sizeof(sysctl_overcommit_ratio),
722 .proc_handler = &proc_dointvec,
725 .ctl_name = VM_PAGE_CLUSTER,
726 .procname = "page-cluster",
727 .data = &page_cluster,
728 .maxlen = sizeof(int),
730 .proc_handler = &proc_dointvec,
733 .ctl_name = VM_DIRTY_BACKGROUND,
734 .procname = "dirty_background_ratio",
735 .data = &dirty_background_ratio,
736 .maxlen = sizeof(dirty_background_ratio),
738 .proc_handler = &proc_dointvec_minmax,
739 .strategy = &sysctl_intvec,
741 .extra2 = &one_hundred,
744 .ctl_name = VM_DIRTY_RATIO,
745 .procname = "dirty_ratio",
746 .data = &vm_dirty_ratio,
747 .maxlen = sizeof(vm_dirty_ratio),
749 .proc_handler = &proc_dointvec_minmax,
750 .strategy = &sysctl_intvec,
752 .extra2 = &one_hundred,
755 .ctl_name = VM_DIRTY_WB_CS,
756 .procname = "dirty_writeback_centisecs",
757 .data = &dirty_writeback_centisecs,
758 .maxlen = sizeof(dirty_writeback_centisecs),
760 .proc_handler = &dirty_writeback_centisecs_handler,
763 .ctl_name = VM_DIRTY_EXPIRE_CS,
764 .procname = "dirty_expire_centisecs",
765 .data = &dirty_expire_centisecs,
766 .maxlen = sizeof(dirty_expire_centisecs),
768 .proc_handler = &proc_dointvec,
771 .ctl_name = VM_NR_PDFLUSH_THREADS,
772 .procname = "nr_pdflush_threads",
773 .data = &nr_pdflush_threads,
774 .maxlen = sizeof nr_pdflush_threads,
775 .mode = 0444 /* read-only*/,
776 .proc_handler = &proc_dointvec,
779 .ctl_name = VM_SWAPPINESS,
780 .procname = "swappiness",
781 .data = &vm_swappiness,
782 .maxlen = sizeof(vm_swappiness),
784 .proc_handler = &proc_dointvec_minmax,
785 .strategy = &sysctl_intvec,
787 .extra2 = &one_hundred,
789 #ifdef CONFIG_HUGETLB_PAGE
791 .ctl_name = VM_HUGETLB_PAGES,
792 .procname = "nr_hugepages",
793 .data = &max_huge_pages,
794 .maxlen = sizeof(unsigned long),
796 .proc_handler = &hugetlb_sysctl_handler,
797 .extra1 = (void *)&hugetlb_zero,
798 .extra2 = (void *)&hugetlb_infinity,
801 .ctl_name = VM_HUGETLB_GROUP,
802 .procname = "hugetlb_shm_group",
803 .data = &sysctl_hugetlb_shm_group,
804 .maxlen = sizeof(gid_t),
806 .proc_handler = &proc_dointvec,
810 .ctl_name = VM_LOWER_ZONE_PROTECTION,
811 .procname = "lower_zone_protection",
812 .data = &sysctl_lower_zone_protection,
813 .maxlen = sizeof(sysctl_lower_zone_protection),
815 .proc_handler = &lower_zone_protection_sysctl_handler,
816 .strategy = &sysctl_intvec,
820 .ctl_name = VM_MIN_FREE_KBYTES,
821 .procname = "min_free_kbytes",
822 .data = &min_free_kbytes,
823 .maxlen = sizeof(min_free_kbytes),
825 .proc_handler = &min_free_kbytes_sysctl_handler,
826 .strategy = &sysctl_intvec,
830 .ctl_name = VM_MAX_MAP_COUNT,
831 .procname = "max_map_count",
832 .data = &sysctl_max_map_count,
833 .maxlen = sizeof(sysctl_max_map_count),
835 .proc_handler = &proc_dointvec
838 .ctl_name = VM_LAPTOP_MODE,
839 .procname = "laptop_mode",
840 .data = &laptop_mode,
841 .maxlen = sizeof(laptop_mode),
843 .proc_handler = &proc_dointvec,
844 .strategy = &sysctl_intvec,
848 .ctl_name = VM_BLOCK_DUMP,
849 .procname = "block_dump",
851 .maxlen = sizeof(block_dump),
853 .proc_handler = &proc_dointvec,
854 .strategy = &sysctl_intvec,
858 .ctl_name = VM_VFS_CACHE_PRESSURE,
859 .procname = "vfs_cache_pressure",
860 .data = &sysctl_vfs_cache_pressure,
861 .maxlen = sizeof(sysctl_vfs_cache_pressure),
863 .proc_handler = &proc_dointvec,
864 .strategy = &sysctl_intvec,
867 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
869 .ctl_name = VM_LEGACY_VA_LAYOUT,
870 .procname = "legacy_va_layout",
871 .data = &sysctl_legacy_va_layout,
872 .maxlen = sizeof(sysctl_legacy_va_layout),
874 .proc_handler = &proc_dointvec,
875 .strategy = &sysctl_intvec,
882 static ctl_table proc_table[] = {
886 static ctl_table fs_table[] = {
888 .ctl_name = FS_NRINODE,
889 .procname = "inode-nr",
890 .data = &inodes_stat,
891 .maxlen = 2*sizeof(int),
893 .proc_handler = &proc_dointvec,
896 .ctl_name = FS_STATINODE,
897 .procname = "inode-state",
898 .data = &inodes_stat,
899 .maxlen = 7*sizeof(int),
901 .proc_handler = &proc_dointvec,
904 .ctl_name = FS_NRFILE,
905 .procname = "file-nr",
907 .maxlen = 3*sizeof(int),
909 .proc_handler = &proc_dointvec,
912 .ctl_name = FS_MAXFILE,
913 .procname = "file-max",
914 .data = &files_stat.max_files,
915 .maxlen = sizeof(int),
917 .proc_handler = &proc_dointvec,
920 .ctl_name = FS_DENTRY,
921 .procname = "dentry-state",
922 .data = &dentry_stat,
923 .maxlen = 6*sizeof(int),
925 .proc_handler = &proc_dointvec,
928 .ctl_name = FS_OVERFLOWUID,
929 .procname = "overflowuid",
930 .data = &fs_overflowuid,
931 .maxlen = sizeof(int),
933 .proc_handler = &proc_dointvec_minmax,
934 .strategy = &sysctl_intvec,
935 .extra1 = &minolduid,
936 .extra2 = &maxolduid,
939 .ctl_name = FS_OVERFLOWGID,
940 .procname = "overflowgid",
941 .data = &fs_overflowgid,
942 .maxlen = sizeof(int),
944 .proc_handler = &proc_dointvec_minmax,
945 .strategy = &sysctl_intvec,
946 .extra1 = &minolduid,
947 .extra2 = &maxolduid,
950 .ctl_name = FS_LEASES,
951 .procname = "leases-enable",
952 .data = &leases_enable,
953 .maxlen = sizeof(int),
955 .proc_handler = &proc_dointvec,
958 .ctl_name = FS_DIR_NOTIFY,
959 .procname = "dir-notify-enable",
960 .data = &dir_notify_enable,
961 .maxlen = sizeof(int),
963 .proc_handler = &proc_dointvec,
966 .ctl_name = FS_LEASE_TIME,
967 .procname = "lease-break-time",
968 .data = &lease_break_time,
969 .maxlen = sizeof(int),
971 .proc_handler = &proc_dointvec,
974 .ctl_name = FS_AIO_NR,
975 .procname = "aio-nr",
977 .maxlen = sizeof(aio_nr),
979 .proc_handler = &proc_dointvec,
982 .ctl_name = FS_AIO_MAX_NR,
983 .procname = "aio-max-nr",
985 .maxlen = sizeof(aio_max_nr),
987 .proc_handler = &proc_dointvec,
992 static ctl_table debug_table[] = {
996 static ctl_table dev_table[] = {
1000 extern void init_irq_proc (void);
1002 void __init sysctl_init(void)
1004 #ifdef CONFIG_PROC_FS
1005 register_proc_table(root_table, proc_sys_root);
1010 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1011 void __user *newval, size_t newlen)
1013 struct list_head *tmp;
1015 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1019 if (!oldlenp || get_user(old_len, oldlenp))
1022 tmp = &root_table_header.ctl_entry;
1024 struct ctl_table_header *head =
1025 list_entry(tmp, struct ctl_table_header, ctl_entry);
1026 void *context = NULL;
1027 int error = parse_table(name, nlen, oldval, oldlenp,
1028 newval, newlen, head->ctl_table,
1032 if (error != -ENOTDIR)
1035 } while (tmp != &root_table_header.ctl_entry);
1039 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1041 struct __sysctl_args tmp;
1044 if (copy_from_user(&tmp, args, sizeof(tmp)))
1048 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1049 tmp.newval, tmp.newlen);
1055 * ctl_perm does NOT grant the superuser all rights automatically, because
1056 * some sysctl variables are readonly even to root.
1059 static int test_perm(int mode, int op)
1063 else if (in_egroup_p(0))
1065 if ((mode & op & 0007) == op)
1070 static inline int ctl_perm(ctl_table *table, int op)
1073 error = security_sysctl(table, op);
1076 return test_perm(table->mode, op);
1079 static int parse_table(int __user *name, int nlen,
1080 void __user *oldval, size_t __user *oldlenp,
1081 void __user *newval, size_t newlen,
1082 ctl_table *table, void **context)
1088 if (get_user(n, name))
1090 for ( ; table->ctl_name; table++) {
1091 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1094 if (ctl_perm(table, 001))
1096 if (table->strategy) {
1097 error = table->strategy(
1100 newval, newlen, context);
1106 table = table->child;
1109 error = do_sysctl_strategy(table, name, nlen,
1111 newval, newlen, context);
1118 /* Perform the actual read/write of a sysctl table entry. */
1119 int do_sysctl_strategy (ctl_table *table,
1120 int __user *name, int nlen,
1121 void __user *oldval, size_t __user *oldlenp,
1122 void __user *newval, size_t newlen, void **context)
1131 if (ctl_perm(table, op))
1134 if (table->strategy) {
1135 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1136 newval, newlen, context);
1143 /* If there is no strategy routine, or if the strategy returns
1144 * zero, proceed with automatic r/w */
1145 if (table->data && table->maxlen) {
1146 if (oldval && oldlenp) {
1147 if (get_user(len, oldlenp))
1150 if (len > table->maxlen)
1151 len = table->maxlen;
1152 if(copy_to_user(oldval, table->data, len))
1154 if(put_user(len, oldlenp))
1158 if (newval && newlen) {
1160 if (len > table->maxlen)
1161 len = table->maxlen;
1162 if(copy_from_user(table->data, newval, len))
1170 * register_sysctl_table - register a sysctl hierarchy
1171 * @table: the top-level table structure
1172 * @insert_at_head: whether the entry should be inserted in front or at the end
1174 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1175 * array. An entry with a ctl_name of 0 terminates the table.
1177 * The members of the &ctl_table structure are used as follows:
1179 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1180 * must be unique within that level of sysctl
1182 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1183 * enter a sysctl file
1185 * data - a pointer to data for use by proc_handler
1187 * maxlen - the maximum size in bytes of the data
1189 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1191 * child - a pointer to the child sysctl table if this entry is a directory, or
1194 * proc_handler - the text handler routine (described below)
1196 * strategy - the strategy routine (described below)
1198 * de - for internal use by the sysctl routines
1200 * extra1, extra2 - extra pointers usable by the proc handler routines
1202 * Leaf nodes in the sysctl tree will be represented by a single file
1203 * under /proc; non-leaf nodes will be represented by directories.
1205 * sysctl(2) can automatically manage read and write requests through
1206 * the sysctl table. The data and maxlen fields of the ctl_table
1207 * struct enable minimal validation of the values being written to be
1208 * performed, and the mode field allows minimal authentication.
1210 * More sophisticated management can be enabled by the provision of a
1211 * strategy routine with the table entry. This will be called before
1212 * any automatic read or write of the data is performed.
1214 * The strategy routine may return
1216 * < 0 - Error occurred (error is passed to user process)
1218 * 0 - OK - proceed with automatic read or write.
1220 * > 0 - OK - read or write has been done by the strategy routine, so
1221 * return immediately.
1223 * There must be a proc_handler routine for any terminal nodes
1224 * mirrored under /proc/sys (non-terminals are handled by a built-in
1225 * directory handler). Several default handlers are available to
1226 * cover common cases -
1228 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1229 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1230 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1232 * It is the handler's job to read the input buffer from user memory
1233 * and process it. The handler should return 0 on success.
1235 * This routine returns %NULL on a failure to register, and a pointer
1236 * to the table header on success.
1238 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1241 struct ctl_table_header *tmp;
1242 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1245 tmp->ctl_table = table;
1246 INIT_LIST_HEAD(&tmp->ctl_entry);
1248 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1250 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1251 #ifdef CONFIG_PROC_FS
1252 register_proc_table(table, proc_sys_root);
1258 * unregister_sysctl_table - unregister a sysctl table hierarchy
1259 * @header: the header returned from register_sysctl_table
1261 * Unregisters the sysctl table and all children. proc entries may not
1262 * actually be removed until they are no longer used by anyone.
1264 void unregister_sysctl_table(struct ctl_table_header * header)
1266 list_del(&header->ctl_entry);
1267 #ifdef CONFIG_PROC_FS
1268 unregister_proc_table(header->ctl_table, proc_sys_root);
1277 #ifdef CONFIG_PROC_FS
1279 /* Scan the sysctl entries in table and add them all into /proc */
1280 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1282 struct proc_dir_entry *de;
1286 for (; table->ctl_name; table++) {
1287 /* Can't do anything without a proc name. */
1288 if (!table->procname)
1290 /* Maybe we can't do anything with it... */
1291 if (!table->proc_handler && !table->child) {
1292 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1297 len = strlen(table->procname);
1301 if (table->proc_handler)
1305 for (de = root->subdir; de; de = de->next) {
1306 if (proc_match(len, table->procname, de))
1309 /* If the subdir exists already, de is non-NULL */
1313 de = create_proc_entry(table->procname, mode, root);
1316 de->data = (void *) table;
1317 if (table->proc_handler)
1318 de->proc_fops = &proc_sys_file_operations;
1321 if (de->mode & S_IFDIR)
1322 register_proc_table(table->child, de);
1327 * Unregister a /proc sysctl table and any subdirectories.
1329 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1331 struct proc_dir_entry *de;
1332 for (; table->ctl_name; table++) {
1333 if (!(de = table->de))
1335 if (de->mode & S_IFDIR) {
1336 if (!table->child) {
1337 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1340 unregister_proc_table(table->child, de);
1342 /* Don't unregister directories which still have entries.. */
1347 /* Don't unregister proc entries that are still being used.. */
1348 if (atomic_read(&de->count))
1352 remove_proc_entry(table->procname, root);
1356 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1357 size_t count, loff_t *ppos)
1360 struct proc_dir_entry *de;
1361 struct ctl_table *table;
1365 de = PDE(file->f_dentry->d_inode);
1366 if (!de || !de->data)
1368 table = (struct ctl_table *) de->data;
1369 if (!table || !table->proc_handler)
1371 op = (write ? 002 : 004);
1372 if (ctl_perm(table, op))
1377 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1383 static int proc_opensys(struct inode *inode, struct file *file)
1385 if (file->f_mode & FMODE_WRITE) {
1387 * sysctl entries that are not writable,
1388 * are _NOT_ writable, capabilities or not.
1390 if (!(inode->i_mode & S_IWUSR))
1397 static ssize_t proc_readsys(struct file * file, char __user * buf,
1398 size_t count, loff_t *ppos)
1400 return do_rw_proc(0, file, buf, count, ppos);
1403 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1404 size_t count, loff_t *ppos)
1406 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1410 * proc_dostring - read a string sysctl
1411 * @table: the sysctl table
1412 * @write: %TRUE if this is a write to the sysctl file
1413 * @filp: the file structure
1414 * @buffer: the user buffer
1415 * @lenp: the size of the user buffer
1417 * Reads/writes a string from/to the user buffer. If the kernel
1418 * buffer provided is not large enough to hold the string, the
1419 * string is truncated. The copied string is %NULL-terminated.
1420 * If the string is being read by the user process, it is copied
1421 * and a newline '\n' is added. It is truncated if the buffer is
1424 * Returns 0 on success.
1426 int proc_dostring(ctl_table *table, int write, struct file *filp,
1427 void __user *buffer, size_t *lenp, loff_t *ppos)
1433 if (!table->data || !table->maxlen || !*lenp ||
1434 (*ppos && !write)) {
1442 while (len < *lenp) {
1443 if (get_user(c, p++))
1445 if (c == 0 || c == '\n')
1449 if (len >= table->maxlen)
1450 len = table->maxlen-1;
1451 if(copy_from_user(table->data, buffer, len))
1453 ((char *) table->data)[len] = 0;
1456 len = strlen(table->data);
1457 if (len > table->maxlen)
1458 len = table->maxlen;
1462 if(copy_to_user(buffer, table->data, len))
1465 if(put_user('\n', ((char __user *) buffer) + len))
1476 * Special case of dostring for the UTS structure. This has locks
1477 * to observe. Should this be in kernel/sys.c ????
1480 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1481 void __user *buffer, size_t *lenp, loff_t *ppos)
1486 down_read(&uts_sem);
1487 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1490 down_write(&uts_sem);
1491 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1497 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1499 int write, void *data)
1502 *valp = *negp ? -*lvalp : *lvalp;
1507 *lvalp = (unsigned long)-val;
1510 *lvalp = (unsigned long)val;
1516 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1517 void __user *buffer, size_t *lenp, loff_t *ppos,
1518 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1519 int write, void *data),
1522 #define TMPBUFLEN 21
1523 int *i, vleft, first=1, neg, val;
1527 char buf[TMPBUFLEN], *p;
1528 char __user *s = buffer;
1530 if (!table->data || !table->maxlen || !*lenp ||
1531 (*ppos && !write)) {
1536 i = (int *) table->data;
1537 vleft = table->maxlen / sizeof(*i);
1541 conv = do_proc_dointvec_conv;
1543 for (; left && vleft--; i++, first=0) {
1558 if (len > sizeof(buf) - 1)
1559 len = sizeof(buf) - 1;
1560 if (copy_from_user(buf, s, len))
1564 if (*p == '-' && left > 1) {
1568 if (*p < '0' || *p > '9')
1571 lval = simple_strtoul(p, &p, 0);
1574 if ((len < left) && *p && !isspace(*p))
1581 if (conv(&neg, &lval, i, 1, data))
1588 if (conv(&neg, &lval, i, 0, data))
1591 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1595 if(copy_to_user(s, buf, len))
1602 if (!write && !first && left) {
1603 if(put_user('\n', s))
1610 if (get_user(c, s++))
1626 * proc_dointvec - read a vector of integers
1627 * @table: the sysctl table
1628 * @write: %TRUE if this is a write to the sysctl file
1629 * @filp: the file structure
1630 * @buffer: the user buffer
1631 * @lenp: the size of the user buffer
1633 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1634 * values from/to the user buffer, treated as an ASCII string.
1636 * Returns 0 on success.
1638 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1639 void __user *buffer, size_t *lenp, loff_t *ppos)
1641 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1651 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1653 int write, void *data)
1655 int op = *(int *)data;
1657 int val = *negp ? -*lvalp : *lvalp;
1659 case OP_SET: *valp = val; break;
1660 case OP_AND: *valp &= val; break;
1661 case OP_OR: *valp |= val; break;
1662 case OP_MAX: if(*valp < val)
1665 case OP_MIN: if(*valp > val)
1673 *lvalp = (unsigned long)-val;
1676 *lvalp = (unsigned long)val;
1683 * init may raise the set.
1686 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1687 void __user *buffer, size_t *lenp, loff_t *ppos)
1691 if (!capable(CAP_SYS_MODULE)) {
1695 op = (current->pid == 1) ? OP_SET : OP_AND;
1696 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1697 do_proc_dointvec_bset_conv,&op);
1700 struct do_proc_dointvec_minmax_conv_param {
1705 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1707 int write, void *data)
1709 struct do_proc_dointvec_minmax_conv_param *param = data;
1711 int val = *negp ? -*lvalp : *lvalp;
1712 if ((param->min && *param->min > val) ||
1713 (param->max && *param->max < val))
1720 *lvalp = (unsigned long)-val;
1723 *lvalp = (unsigned long)val;
1730 * proc_dointvec_minmax - read a vector of integers with min/max values
1731 * @table: the sysctl table
1732 * @write: %TRUE if this is a write to the sysctl file
1733 * @filp: the file structure
1734 * @buffer: the user buffer
1735 * @lenp: the size of the user buffer
1737 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1738 * values from/to the user buffer, treated as an ASCII string.
1740 * This routine will ensure the values are within the range specified by
1741 * table->extra1 (min) and table->extra2 (max).
1743 * Returns 0 on success.
1745 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1746 void __user *buffer, size_t *lenp, loff_t *ppos)
1748 struct do_proc_dointvec_minmax_conv_param param = {
1749 .min = (int *) table->extra1,
1750 .max = (int *) table->extra2,
1752 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1753 do_proc_dointvec_minmax_conv, ¶m);
1756 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1758 void __user *buffer,
1759 size_t *lenp, loff_t *ppos,
1760 unsigned long convmul,
1761 unsigned long convdiv)
1763 #define TMPBUFLEN 21
1764 unsigned long *i, *min, *max, val;
1765 int vleft, first=1, neg;
1767 char buf[TMPBUFLEN], *p;
1768 char __user *s = buffer;
1770 if (!table->data || !table->maxlen || !*lenp ||
1771 (*ppos && !write)) {
1776 i = (unsigned long *) table->data;
1777 min = (unsigned long *) table->extra1;
1778 max = (unsigned long *) table->extra2;
1779 vleft = table->maxlen / sizeof(unsigned long);
1782 for (; left && vleft--; i++, min++, max++, first=0) {
1797 if (len > TMPBUFLEN-1)
1799 if (copy_from_user(buf, s, len))
1803 if (*p == '-' && left > 1) {
1807 if (*p < '0' || *p > '9')
1809 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1811 if ((len < left) && *p && !isspace(*p))
1820 if ((min && val < *min) || (max && val > *max))
1827 sprintf(p, "%lu", convdiv * (*i) / convmul);
1831 if(copy_to_user(s, buf, len))
1838 if (!write && !first && left) {
1839 if(put_user('\n', s))
1846 if (get_user(c, s++))
1862 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1863 * @table: the sysctl table
1864 * @write: %TRUE if this is a write to the sysctl file
1865 * @filp: the file structure
1866 * @buffer: the user buffer
1867 * @lenp: the size of the user buffer
1869 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1870 * values from/to the user buffer, treated as an ASCII string.
1872 * This routine will ensure the values are within the range specified by
1873 * table->extra1 (min) and table->extra2 (max).
1875 * Returns 0 on success.
1877 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1878 void __user *buffer, size_t *lenp, loff_t *ppos)
1880 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1884 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1885 * @table: the sysctl table
1886 * @write: %TRUE if this is a write to the sysctl file
1887 * @filp: the file structure
1888 * @buffer: the user buffer
1889 * @lenp: the size of the user buffer
1891 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1892 * values from/to the user buffer, treated as an ASCII string. The values
1893 * are treated as milliseconds, and converted to jiffies when they are stored.
1895 * This routine will ensure the values are within the range specified by
1896 * table->extra1 (min) and table->extra2 (max).
1898 * Returns 0 on success.
1900 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1902 void __user *buffer,
1903 size_t *lenp, loff_t *ppos)
1905 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1906 lenp, ppos, HZ, 1000l);
1910 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1912 int write, void *data)
1915 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1921 lval = (unsigned long)-val;
1924 lval = (unsigned long)val;
1931 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1933 int write, void *data)
1936 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1942 lval = (unsigned long)-val;
1945 lval = (unsigned long)val;
1947 *lvalp = jiffies_to_clock_t(lval);
1953 * proc_dointvec_jiffies - read a vector of integers as seconds
1954 * @table: the sysctl table
1955 * @write: %TRUE if this is a write to the sysctl file
1956 * @filp: the file structure
1957 * @buffer: the user buffer
1958 * @lenp: the size of the user buffer
1960 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1961 * values from/to the user buffer, treated as an ASCII string.
1962 * The values read are assumed to be in seconds, and are converted into
1965 * Returns 0 on success.
1967 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1968 void __user *buffer, size_t *lenp, loff_t *ppos)
1970 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1971 do_proc_dointvec_jiffies_conv,NULL);
1975 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1976 * @table: the sysctl table
1977 * @write: %TRUE if this is a write to the sysctl file
1978 * @filp: the file structure
1979 * @buffer: the user buffer
1980 * @lenp: the size of the user buffer
1982 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1983 * values from/to the user buffer, treated as an ASCII string.
1984 * The values read are assumed to be in 1/USER_HZ seconds, and
1985 * are converted into jiffies.
1987 * Returns 0 on success.
1989 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1990 void __user *buffer, size_t *lenp, loff_t *ppos)
1992 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1993 do_proc_dointvec_userhz_jiffies_conv,NULL);
1996 #else /* CONFIG_PROC_FS */
1998 int proc_dostring(ctl_table *table, int write, struct file *filp,
1999 void __user *buffer, size_t *lenp, loff_t *ppos)
2004 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2005 void __user *buffer, size_t *lenp, loff_t *ppos)
2010 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2011 void __user *buffer, size_t *lenp, loff_t *ppos)
2016 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2017 void __user *buffer, size_t *lenp, loff_t *ppos)
2022 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2023 void __user *buffer, size_t *lenp, loff_t *ppos)
2028 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2029 void __user *buffer, size_t *lenp, loff_t *ppos)
2034 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2035 void __user *buffer, size_t *lenp, loff_t *ppos)
2040 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2041 void __user *buffer, size_t *lenp, loff_t *ppos)
2046 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2048 void __user *buffer,
2049 size_t *lenp, loff_t *ppos)
2055 #endif /* CONFIG_PROC_FS */
2059 * General sysctl support routines
2062 /* The generic string strategy routine: */
2063 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2064 void __user *oldval, size_t __user *oldlenp,
2065 void __user *newval, size_t newlen, void **context)
2069 if (!table->data || !table->maxlen)
2072 if (oldval && oldlenp) {
2073 if (get_user(len, oldlenp))
2076 l = strlen(table->data);
2077 if (len > l) len = l;
2078 if (len >= table->maxlen)
2079 len = table->maxlen;
2080 if(copy_to_user(oldval, table->data, len))
2082 if(put_user(0, ((char __user *) oldval) + len))
2084 if(put_user(len, oldlenp))
2088 if (newval && newlen) {
2090 if (len > table->maxlen)
2091 len = table->maxlen;
2092 if(copy_from_user(table->data, newval, len))
2094 if (len == table->maxlen)
2096 ((char *) table->data)[len] = 0;
2102 * This function makes sure that all of the integers in the vector
2103 * are between the minimum and maximum values given in the arrays
2104 * table->extra1 and table->extra2, respectively.
2106 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2107 void __user *oldval, size_t __user *oldlenp,
2108 void __user *newval, size_t newlen, void **context)
2111 if (newval && newlen) {
2112 int __user *vec = (int __user *) newval;
2113 int *min = (int *) table->extra1;
2114 int *max = (int *) table->extra2;
2118 if (newlen % sizeof(int) != 0)
2121 if (!table->extra1 && !table->extra2)
2124 if (newlen > table->maxlen)
2125 newlen = table->maxlen;
2126 length = newlen / sizeof(int);
2128 for (i = 0; i < length; i++) {
2130 if (get_user(value, vec + i))
2132 if (min && value < min[i])
2134 if (max && value > max[i])
2141 /* Strategy function to convert jiffies to seconds */
2142 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2143 void __user *oldval, size_t __user *oldlenp,
2144 void __user *newval, size_t newlen, void **context)
2149 if (get_user(olen, oldlenp))
2151 if (olen!=sizeof(int))
2154 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2155 (oldlenp && put_user(sizeof(int),oldlenp)))
2158 if (newval && newlen) {
2160 if (newlen != sizeof(int))
2162 if (get_user(new, (int __user *)newval))
2164 *(int *)(table->data) = new*HZ;
2170 #else /* CONFIG_SYSCTL */
2173 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2178 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2179 void __user *oldval, size_t __user *oldlenp,
2180 void __user *newval, size_t newlen, void **context)
2185 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2186 void __user *oldval, size_t __user *oldlenp,
2187 void __user *newval, size_t newlen, void **context)
2192 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2193 void __user *oldval, size_t __user *oldlenp,
2194 void __user *newval, size_t newlen, void **context)
2199 int proc_dostring(ctl_table *table, int write, struct file *filp,
2200 void __user *buffer, size_t *lenp, loff_t *ppos)
2205 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2206 void __user *buffer, size_t *lenp, loff_t *ppos)
2211 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2212 void __user *buffer, size_t *lenp, loff_t *ppos)
2217 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2218 void __user *buffer, size_t *lenp, loff_t *ppos)
2223 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2224 void __user *buffer, size_t *lenp, loff_t *ppos)
2229 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2230 void __user *buffer, size_t *lenp, loff_t *ppos)
2235 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2236 void __user *buffer, size_t *lenp, loff_t *ppos)
2241 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2243 void __user *buffer,
2244 size_t *lenp, loff_t *ppos)
2249 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2255 void unregister_sysctl_table(struct ctl_table_header * table)
2259 #endif /* CONFIG_SYSCTL */
2262 * No sense putting this after each symbol definition, twice,
2263 * exception granted :-)
2265 EXPORT_SYMBOL(proc_dointvec);
2266 EXPORT_SYMBOL(proc_dointvec_jiffies);
2267 EXPORT_SYMBOL(proc_dointvec_minmax);
2268 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2269 EXPORT_SYMBOL(proc_dostring);
2270 EXPORT_SYMBOL(proc_doulongvec_minmax);
2271 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2272 EXPORT_SYMBOL(register_sysctl_table);
2273 EXPORT_SYMBOL(sysctl_intvec);
2274 EXPORT_SYMBOL(sysctl_jiffies);
2275 EXPORT_SYMBOL(sysctl_string);
2276 EXPORT_SYMBOL(unregister_sysctl_table);