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>
46 #ifdef CONFIG_ROOT_NFS
47 #include <linux/nfs_fs.h>
50 #if defined(CONFIG_SYSCTL)
52 /* External variables not in a header file. */
53 extern int panic_timeout;
55 extern int sysctl_overcommit_memory;
56 extern int sysctl_overcommit_ratio;
57 extern int max_threads;
58 extern int sysrq_enabled;
59 extern int core_uses_pid;
60 extern char core_pattern[];
63 extern int sysctl_lower_zone_protection;
64 extern int min_free_kbytes;
65 extern int printk_ratelimit_jiffies;
66 extern int printk_ratelimit_burst;
68 extern unsigned int vdso_enabled;
71 int exec_shield_randomize = 1;
73 static int __init setup_exec_shield(char *str)
75 get_option (&str, &exec_shield);
80 __setup("exec-shield=", setup_exec_shield);
82 static int __init setup_exec_shield_randomize(char *str)
84 get_option (&str, &exec_shield_randomize);
89 __setup("exec-shield-randomize=", setup_exec_shield_randomize);
91 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
92 static int maxolduid = 65535;
95 static int ngroups_max = NGROUPS_MAX;
98 extern char modprobe_path[];
100 #ifdef CONFIG_HOTPLUG
101 extern char hotplug_path[];
103 extern char vshelper_path[];
104 #ifdef CONFIG_CHR_DEV_SG
105 extern int sg_big_buff;
107 #ifdef CONFIG_SYSVIPC
108 extern size_t shm_ctlmax;
109 extern size_t shm_ctlall;
110 extern int shm_ctlmni;
111 extern int msg_ctlmax;
112 extern int msg_ctlmnb;
113 extern int msg_ctlmni;
114 extern int sem_ctls[];
118 extern char reboot_command [];
119 extern int stop_a_enabled;
120 extern int scons_pwroff;
124 extern int pwrsw_enabled;
125 extern int unaligned_enabled;
128 #ifdef CONFIG_ARCH_S390
129 #ifdef CONFIG_MATHEMU
130 extern int sysctl_ieee_emulation_warnings;
132 extern int sysctl_userprocess_debug;
135 extern int sysctl_hz_timer;
137 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
138 extern unsigned long powersave_nap;
139 int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
140 void __user *buffer, size_t *lenp, loff_t *ppos);
143 #ifdef CONFIG_BSD_PROCESS_ACCT
144 extern int acct_parm[];
147 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
148 ctl_table *, void **);
149 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
150 void __user *buffer, size_t *lenp, loff_t *ppos);
152 static ctl_table root_table[];
153 static struct ctl_table_header root_table_header =
154 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
156 static ctl_table kern_table[];
157 static ctl_table vm_table[];
159 extern ctl_table net_table[];
161 static ctl_table proc_table[];
162 static ctl_table fs_table[];
163 static ctl_table debug_table[];
164 static ctl_table dev_table[];
165 extern ctl_table random_table[];
166 #ifdef CONFIG_UNIX98_PTYS
167 extern ctl_table pty_table[];
170 int sysctl_legacy_va_layout;
172 /* /proc declarations: */
174 #ifdef CONFIG_PROC_FS
176 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
177 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
178 static int proc_opensys(struct inode *, struct file *);
180 struct file_operations proc_sys_file_operations = {
181 .open = proc_opensys,
182 .read = proc_readsys,
183 .write = proc_writesys,
186 extern struct proc_dir_entry *proc_sys_root;
188 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
189 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
192 /* The default sysctl tables: */
194 static ctl_table root_table[] = {
196 .ctl_name = CTL_KERN,
197 .procname = "kernel",
216 .ctl_name = CTL_PROC,
228 .ctl_name = CTL_DEBUG,
231 .child = debug_table,
242 static ctl_table kern_table[] = {
244 .ctl_name = KERN_OSTYPE,
245 .procname = "ostype",
246 .data = system_utsname.sysname,
247 .maxlen = sizeof(system_utsname.sysname),
249 .proc_handler = &proc_doutsstring,
250 .strategy = &sysctl_string,
253 .ctl_name = KERN_OSRELEASE,
254 .procname = "osrelease",
255 .data = system_utsname.release,
256 .maxlen = sizeof(system_utsname.release),
258 .proc_handler = &proc_doutsstring,
259 .strategy = &sysctl_string,
262 .ctl_name = KERN_VERSION,
263 .procname = "version",
264 .data = system_utsname.version,
265 .maxlen = sizeof(system_utsname.version),
267 .proc_handler = &proc_doutsstring,
268 .strategy = &sysctl_string,
271 .ctl_name = KERN_NODENAME,
272 .procname = "hostname",
273 .data = system_utsname.nodename,
274 .maxlen = sizeof(system_utsname.nodename),
276 .proc_handler = &proc_doutsstring,
277 .strategy = &sysctl_string,
280 .ctl_name = KERN_DOMAINNAME,
281 .procname = "domainname",
282 .data = system_utsname.domainname,
283 .maxlen = sizeof(system_utsname.domainname),
285 .proc_handler = &proc_doutsstring,
286 .strategy = &sysctl_string,
289 .ctl_name = KERN_PANIC,
291 .data = &panic_timeout,
292 .maxlen = sizeof(int),
294 .proc_handler = &proc_dointvec,
297 .ctl_name = KERN_PANIC,
298 .procname = "exec-shield",
299 .data = &exec_shield,
300 .maxlen = sizeof(int),
302 .proc_handler = &proc_dointvec,
305 .ctl_name = KERN_PANIC,
306 .procname = "exec-shield-randomize",
307 .data = &exec_shield_randomize,
308 .maxlen = sizeof(int),
310 .proc_handler = &proc_dointvec,
313 .ctl_name = KERN_PANIC,
314 .procname = "print-fatal-signals",
315 .data = &print_fatal_signals,
316 .maxlen = sizeof(int),
318 .proc_handler = &proc_dointvec,
322 .ctl_name = KERN_PANIC,
324 .data = &vdso_enabled,
325 .maxlen = sizeof(int),
327 .proc_handler = &proc_dointvec,
331 .ctl_name = KERN_CORE_USES_PID,
332 .procname = "core_uses_pid",
333 .data = &core_uses_pid,
334 .maxlen = sizeof(int),
336 .proc_handler = &proc_dointvec,
339 .ctl_name = KERN_CORE_PATTERN,
340 .procname = "core_pattern",
341 .data = core_pattern,
344 .proc_handler = &proc_dostring,
345 .strategy = &sysctl_string,
348 .ctl_name = KERN_TAINTED,
349 .procname = "tainted",
351 .maxlen = sizeof(int),
353 .proc_handler = &proc_dointvec,
356 .ctl_name = KERN_CAP_BSET,
357 .procname = "cap-bound",
359 .maxlen = sizeof(kernel_cap_t),
361 .proc_handler = &proc_dointvec_bset,
363 #ifdef CONFIG_BLK_DEV_INITRD
365 .ctl_name = KERN_REALROOTDEV,
366 .procname = "real-root-dev",
367 .data = &real_root_dev,
368 .maxlen = sizeof(int),
370 .proc_handler = &proc_dointvec,
375 .ctl_name = KERN_SPARC_REBOOT,
376 .procname = "reboot-cmd",
377 .data = reboot_command,
380 .proc_handler = &proc_dostring,
381 .strategy = &sysctl_string,
384 .ctl_name = KERN_SPARC_STOP_A,
385 .procname = "stop-a",
386 .data = &stop_a_enabled,
387 .maxlen = sizeof (int),
389 .proc_handler = &proc_dointvec,
392 .ctl_name = KERN_SPARC_SCONS_PWROFF,
393 .procname = "scons-poweroff",
394 .data = &scons_pwroff,
395 .maxlen = sizeof (int),
397 .proc_handler = &proc_dointvec,
402 .ctl_name = KERN_HPPA_PWRSW,
403 .procname = "soft-power",
404 .data = &pwrsw_enabled,
405 .maxlen = sizeof (int),
407 .proc_handler = &proc_dointvec,
410 .ctl_name = KERN_HPPA_UNALIGNED,
411 .procname = "unaligned-trap",
412 .data = &unaligned_enabled,
413 .maxlen = sizeof (int),
415 .proc_handler = &proc_dointvec,
418 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
420 .ctl_name = KERN_PPC_POWERSAVE_NAP,
421 .procname = "powersave-nap",
422 .data = &powersave_nap,
423 .maxlen = sizeof(int),
425 .proc_handler = &proc_dointvec,
428 .ctl_name = KERN_PPC_L2CR,
431 .proc_handler = &proc_dol2crvec,
435 .ctl_name = KERN_CTLALTDEL,
436 .procname = "ctrl-alt-del",
438 .maxlen = sizeof(int),
440 .proc_handler = &proc_dointvec,
443 .ctl_name = KERN_PRINTK,
444 .procname = "printk",
445 .data = &console_loglevel,
446 .maxlen = 4*sizeof(int),
448 .proc_handler = &proc_dointvec,
452 .ctl_name = KERN_MODPROBE,
453 .procname = "modprobe",
454 .data = &modprobe_path,
455 .maxlen = KMOD_PATH_LEN,
457 .proc_handler = &proc_dostring,
458 .strategy = &sysctl_string,
461 #ifdef CONFIG_HOTPLUG
463 .ctl_name = KERN_HOTPLUG,
464 .procname = "hotplug",
465 .data = &hotplug_path,
466 .maxlen = KMOD_PATH_LEN,
468 .proc_handler = &proc_dostring,
469 .strategy = &sysctl_string,
473 .ctl_name = KERN_VSHELPER,
474 .procname = "vshelper",
475 .data = &vshelper_path,
478 .proc_handler = &proc_dostring,
479 .strategy = &sysctl_string,
481 #ifdef CONFIG_CHR_DEV_SG
483 .ctl_name = KERN_SG_BIG_BUFF,
484 .procname = "sg-big-buff",
485 .data = &sg_big_buff,
486 .maxlen = sizeof (int),
488 .proc_handler = &proc_dointvec,
491 #ifdef CONFIG_BSD_PROCESS_ACCT
493 .ctl_name = KERN_ACCT,
496 .maxlen = 3*sizeof(int),
498 .proc_handler = &proc_dointvec,
501 #ifdef CONFIG_SYSVIPC
503 .ctl_name = KERN_SHMMAX,
504 .procname = "shmmax",
506 .maxlen = sizeof (size_t),
508 .proc_handler = &proc_doulongvec_minmax,
511 .ctl_name = KERN_SHMALL,
512 .procname = "shmall",
514 .maxlen = sizeof (size_t),
516 .proc_handler = &proc_doulongvec_minmax,
519 .ctl_name = KERN_SHMMNI,
520 .procname = "shmmni",
522 .maxlen = sizeof (int),
524 .proc_handler = &proc_dointvec,
527 .ctl_name = KERN_MSGMAX,
528 .procname = "msgmax",
530 .maxlen = sizeof (int),
532 .proc_handler = &proc_dointvec,
535 .ctl_name = KERN_MSGMNI,
536 .procname = "msgmni",
538 .maxlen = sizeof (int),
540 .proc_handler = &proc_dointvec,
543 .ctl_name = KERN_MSGMNB,
544 .procname = "msgmnb",
546 .maxlen = sizeof (int),
548 .proc_handler = &proc_dointvec,
551 .ctl_name = KERN_SEM,
554 .maxlen = 4*sizeof (int),
556 .proc_handler = &proc_dointvec,
559 #ifdef CONFIG_MAGIC_SYSRQ
561 .ctl_name = KERN_SYSRQ,
563 .data = &sysrq_enabled,
564 .maxlen = sizeof (int),
566 .proc_handler = &proc_dointvec,
570 .ctl_name = KERN_CADPID,
571 .procname = "cad_pid",
573 .maxlen = sizeof (int),
575 .proc_handler = &proc_dointvec,
578 .ctl_name = KERN_MAX_THREADS,
579 .procname = "threads-max",
580 .data = &max_threads,
581 .maxlen = sizeof(int),
583 .proc_handler = &proc_dointvec,
586 .ctl_name = KERN_RANDOM,
587 .procname = "random",
589 .child = random_table,
591 #ifdef CONFIG_UNIX98_PTYS
593 .ctl_name = KERN_PTY,
600 .ctl_name = KERN_OVERFLOWUID,
601 .procname = "overflowuid",
602 .data = &overflowuid,
603 .maxlen = sizeof(int),
605 .proc_handler = &proc_dointvec_minmax,
606 .strategy = &sysctl_intvec,
607 .extra1 = &minolduid,
608 .extra2 = &maxolduid,
611 .ctl_name = KERN_OVERFLOWGID,
612 .procname = "overflowgid",
613 .data = &overflowgid,
614 .maxlen = sizeof(int),
616 .proc_handler = &proc_dointvec_minmax,
617 .strategy = &sysctl_intvec,
618 .extra1 = &minolduid,
619 .extra2 = &maxolduid,
621 #ifdef CONFIG_ARCH_S390
622 #ifdef CONFIG_MATHEMU
624 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
625 .procname = "ieee_emulation_warnings",
626 .data = &sysctl_ieee_emulation_warnings,
627 .maxlen = sizeof(int),
629 .proc_handler = &proc_dointvec,
632 #ifdef CONFIG_NO_IDLE_HZ
634 .ctl_name = KERN_HZ_TIMER,
635 .procname = "hz_timer",
636 .data = &sysctl_hz_timer,
637 .maxlen = sizeof(int),
639 .proc_handler = &proc_dointvec,
643 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
644 .procname = "userprocess_debug",
645 .data = &sysctl_userprocess_debug,
646 .maxlen = sizeof(int),
648 .proc_handler = &proc_dointvec,
652 .ctl_name = KERN_PIDMAX,
653 .procname = "pid_max",
655 .maxlen = sizeof (int),
657 .proc_handler = &proc_dointvec,
660 .ctl_name = KERN_PANIC_ON_OOPS,
661 .procname = "panic_on_oops",
662 .data = &panic_on_oops,
663 .maxlen = sizeof(int),
665 .proc_handler = &proc_dointvec,
668 .ctl_name = KERN_PRINTK_RATELIMIT,
669 .procname = "printk_ratelimit",
670 .data = &printk_ratelimit_jiffies,
671 .maxlen = sizeof(int),
673 .proc_handler = &proc_dointvec_jiffies,
674 .strategy = &sysctl_jiffies,
677 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
678 .procname = "printk_ratelimit_burst",
679 .data = &printk_ratelimit_burst,
680 .maxlen = sizeof(int),
682 .proc_handler = &proc_dointvec,
685 .ctl_name = KERN_NGROUPS_MAX,
686 .procname = "ngroups_max",
687 .data = &ngroups_max,
688 .maxlen = sizeof (int),
690 .proc_handler = &proc_dointvec,
695 /* Constants for minimum and maximum testing in vm_table.
696 We use these as one-element integer vectors. */
698 static int one_hundred = 100;
701 static ctl_table vm_table[] = {
703 .ctl_name = VM_OVERCOMMIT_MEMORY,
704 .procname = "overcommit_memory",
705 .data = &sysctl_overcommit_memory,
706 .maxlen = sizeof(sysctl_overcommit_memory),
708 .proc_handler = &proc_dointvec,
711 .ctl_name = VM_OVERCOMMIT_RATIO,
712 .procname = "overcommit_ratio",
713 .data = &sysctl_overcommit_ratio,
714 .maxlen = sizeof(sysctl_overcommit_ratio),
716 .proc_handler = &proc_dointvec,
719 .ctl_name = VM_PAGE_CLUSTER,
720 .procname = "page-cluster",
721 .data = &page_cluster,
722 .maxlen = sizeof(int),
724 .proc_handler = &proc_dointvec,
727 .ctl_name = VM_DIRTY_BACKGROUND,
728 .procname = "dirty_background_ratio",
729 .data = &dirty_background_ratio,
730 .maxlen = sizeof(dirty_background_ratio),
732 .proc_handler = &proc_dointvec_minmax,
733 .strategy = &sysctl_intvec,
735 .extra2 = &one_hundred,
738 .ctl_name = VM_DIRTY_RATIO,
739 .procname = "dirty_ratio",
740 .data = &vm_dirty_ratio,
741 .maxlen = sizeof(vm_dirty_ratio),
743 .proc_handler = &proc_dointvec_minmax,
744 .strategy = &sysctl_intvec,
746 .extra2 = &one_hundred,
749 .ctl_name = VM_DIRTY_WB_CS,
750 .procname = "dirty_writeback_centisecs",
751 .data = &dirty_writeback_centisecs,
752 .maxlen = sizeof(dirty_writeback_centisecs),
754 .proc_handler = &dirty_writeback_centisecs_handler,
757 .ctl_name = VM_DIRTY_EXPIRE_CS,
758 .procname = "dirty_expire_centisecs",
759 .data = &dirty_expire_centisecs,
760 .maxlen = sizeof(dirty_expire_centisecs),
762 .proc_handler = &proc_dointvec,
765 .ctl_name = VM_NR_PDFLUSH_THREADS,
766 .procname = "nr_pdflush_threads",
767 .data = &nr_pdflush_threads,
768 .maxlen = sizeof nr_pdflush_threads,
769 .mode = 0444 /* read-only*/,
770 .proc_handler = &proc_dointvec,
773 .ctl_name = VM_SWAPPINESS,
774 .procname = "swappiness",
775 .data = &vm_swappiness,
776 .maxlen = sizeof(vm_swappiness),
778 .proc_handler = &proc_dointvec_minmax,
779 .strategy = &sysctl_intvec,
781 .extra2 = &one_hundred,
783 #ifdef CONFIG_HUGETLB_PAGE
785 .ctl_name = VM_HUGETLB_PAGES,
786 .procname = "nr_hugepages",
787 .data = &max_huge_pages,
788 .maxlen = sizeof(unsigned long),
790 .proc_handler = &hugetlb_sysctl_handler,
791 .extra1 = (void *)&hugetlb_zero,
792 .extra2 = (void *)&hugetlb_infinity,
796 .ctl_name = VM_LOWER_ZONE_PROTECTION,
797 .procname = "lower_zone_protection",
798 .data = &sysctl_lower_zone_protection,
799 .maxlen = sizeof(sysctl_lower_zone_protection),
801 .proc_handler = &lower_zone_protection_sysctl_handler,
802 .strategy = &sysctl_intvec,
806 .ctl_name = VM_MIN_FREE_KBYTES,
807 .procname = "min_free_kbytes",
808 .data = &min_free_kbytes,
809 .maxlen = sizeof(min_free_kbytes),
811 .proc_handler = &min_free_kbytes_sysctl_handler,
812 .strategy = &sysctl_intvec,
816 .ctl_name = VM_MAX_MAP_COUNT,
817 .procname = "max_map_count",
818 .data = &sysctl_max_map_count,
819 .maxlen = sizeof(sysctl_max_map_count),
821 .proc_handler = &proc_dointvec
824 .ctl_name = VM_LAPTOP_MODE,
825 .procname = "laptop_mode",
826 .data = &laptop_mode,
827 .maxlen = sizeof(laptop_mode),
829 .proc_handler = &proc_dointvec,
830 .strategy = &sysctl_intvec,
834 .ctl_name = VM_BLOCK_DUMP,
835 .procname = "block_dump",
837 .maxlen = sizeof(block_dump),
839 .proc_handler = &proc_dointvec,
840 .strategy = &sysctl_intvec,
844 .ctl_name = VM_VFS_CACHE_PRESSURE,
845 .procname = "vfs_cache_pressure",
846 .data = &sysctl_vfs_cache_pressure,
847 .maxlen = sizeof(sysctl_vfs_cache_pressure),
849 .proc_handler = &proc_dointvec,
850 .strategy = &sysctl_intvec,
854 .ctl_name = VM_LEGACY_VA_LAYOUT,
855 .procname = "legacy_va_layout",
856 .data = &sysctl_legacy_va_layout,
857 .maxlen = sizeof(sysctl_legacy_va_layout),
859 .proc_handler = &proc_dointvec,
860 .strategy = &sysctl_intvec,
866 static ctl_table proc_table[] = {
870 static ctl_table fs_table[] = {
872 .ctl_name = FS_NRINODE,
873 .procname = "inode-nr",
874 .data = &inodes_stat,
875 .maxlen = 2*sizeof(int),
877 .proc_handler = &proc_dointvec,
880 .ctl_name = FS_STATINODE,
881 .procname = "inode-state",
882 .data = &inodes_stat,
883 .maxlen = 7*sizeof(int),
885 .proc_handler = &proc_dointvec,
888 .ctl_name = FS_NRFILE,
889 .procname = "file-nr",
891 .maxlen = 3*sizeof(int),
893 .proc_handler = &proc_dointvec,
896 .ctl_name = FS_MAXFILE,
897 .procname = "file-max",
898 .data = &files_stat.max_files,
899 .maxlen = sizeof(int),
901 .proc_handler = &proc_dointvec,
904 .ctl_name = FS_DENTRY,
905 .procname = "dentry-state",
906 .data = &dentry_stat,
907 .maxlen = 6*sizeof(int),
909 .proc_handler = &proc_dointvec,
912 .ctl_name = FS_OVERFLOWUID,
913 .procname = "overflowuid",
914 .data = &fs_overflowuid,
915 .maxlen = sizeof(int),
917 .proc_handler = &proc_dointvec_minmax,
918 .strategy = &sysctl_intvec,
919 .extra1 = &minolduid,
920 .extra2 = &maxolduid,
923 .ctl_name = FS_OVERFLOWGID,
924 .procname = "overflowgid",
925 .data = &fs_overflowgid,
926 .maxlen = sizeof(int),
928 .proc_handler = &proc_dointvec_minmax,
929 .strategy = &sysctl_intvec,
930 .extra1 = &minolduid,
931 .extra2 = &maxolduid,
934 .ctl_name = FS_LEASES,
935 .procname = "leases-enable",
936 .data = &leases_enable,
937 .maxlen = sizeof(int),
939 .proc_handler = &proc_dointvec,
942 .ctl_name = FS_DIR_NOTIFY,
943 .procname = "dir-notify-enable",
944 .data = &dir_notify_enable,
945 .maxlen = sizeof(int),
947 .proc_handler = &proc_dointvec,
950 .ctl_name = FS_LEASE_TIME,
951 .procname = "lease-break-time",
952 .data = &lease_break_time,
953 .maxlen = sizeof(int),
955 .proc_handler = &proc_dointvec,
958 .ctl_name = FS_AIO_NR,
959 .procname = "aio-nr",
961 .maxlen = sizeof(aio_nr),
963 .proc_handler = &proc_dointvec,
966 .ctl_name = FS_AIO_MAX_NR,
967 .procname = "aio-max-nr",
969 .maxlen = sizeof(aio_max_nr),
971 .proc_handler = &proc_dointvec,
976 static ctl_table debug_table[] = {
980 static ctl_table dev_table[] = {
984 extern void init_irq_proc (void);
986 void __init sysctl_init(void)
988 #ifdef CONFIG_PROC_FS
989 register_proc_table(root_table, proc_sys_root);
994 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
995 void __user *newval, size_t newlen)
997 struct list_head *tmp;
999 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1003 if (!oldlenp || get_user(old_len, oldlenp))
1006 tmp = &root_table_header.ctl_entry;
1008 struct ctl_table_header *head =
1009 list_entry(tmp, struct ctl_table_header, ctl_entry);
1010 void *context = NULL;
1011 int error = parse_table(name, nlen, oldval, oldlenp,
1012 newval, newlen, head->ctl_table,
1016 if (error != -ENOTDIR)
1019 } while (tmp != &root_table_header.ctl_entry);
1023 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1025 struct __sysctl_args tmp;
1028 if (copy_from_user(&tmp, args, sizeof(tmp)))
1032 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1033 tmp.newval, tmp.newlen);
1039 * ctl_perm does NOT grant the superuser all rights automatically, because
1040 * some sysctl variables are readonly even to root.
1043 static int test_perm(int mode, int op)
1047 else if (in_egroup_p(0))
1049 if ((mode & op & 0007) == op)
1054 static inline int ctl_perm(ctl_table *table, int op)
1057 error = security_sysctl(table, op);
1060 return test_perm(table->mode, op);
1063 static int parse_table(int __user *name, int nlen,
1064 void __user *oldval, size_t __user *oldlenp,
1065 void __user *newval, size_t newlen,
1066 ctl_table *table, void **context)
1072 if (get_user(n, name))
1074 for ( ; table->ctl_name; table++) {
1075 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1078 if (ctl_perm(table, 001))
1080 if (table->strategy) {
1081 error = table->strategy(
1084 newval, newlen, context);
1090 table = table->child;
1093 error = do_sysctl_strategy(table, name, nlen,
1095 newval, newlen, context);
1102 /* Perform the actual read/write of a sysctl table entry. */
1103 int do_sysctl_strategy (ctl_table *table,
1104 int __user *name, int nlen,
1105 void __user *oldval, size_t __user *oldlenp,
1106 void __user *newval, size_t newlen, void **context)
1115 if (ctl_perm(table, op))
1118 if (table->strategy) {
1119 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1120 newval, newlen, context);
1127 /* If there is no strategy routine, or if the strategy returns
1128 * zero, proceed with automatic r/w */
1129 if (table->data && table->maxlen) {
1130 if (oldval && oldlenp) {
1131 if (get_user(len, oldlenp))
1134 if (len > table->maxlen)
1135 len = table->maxlen;
1136 if(copy_to_user(oldval, table->data, len))
1138 if(put_user(len, oldlenp))
1142 if (newval && newlen) {
1144 if (len > table->maxlen)
1145 len = table->maxlen;
1146 if(copy_from_user(table->data, newval, len))
1154 * register_sysctl_table - register a sysctl hierarchy
1155 * @table: the top-level table structure
1156 * @insert_at_head: whether the entry should be inserted in front or at the end
1158 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1159 * array. An entry with a ctl_name of 0 terminates the table.
1161 * The members of the &ctl_table structure are used as follows:
1163 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1164 * must be unique within that level of sysctl
1166 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1167 * enter a sysctl file
1169 * data - a pointer to data for use by proc_handler
1171 * maxlen - the maximum size in bytes of the data
1173 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1175 * child - a pointer to the child sysctl table if this entry is a directory, or
1178 * proc_handler - the text handler routine (described below)
1180 * strategy - the strategy routine (described below)
1182 * de - for internal use by the sysctl routines
1184 * extra1, extra2 - extra pointers usable by the proc handler routines
1186 * Leaf nodes in the sysctl tree will be represented by a single file
1187 * under /proc; non-leaf nodes will be represented by directories.
1189 * sysctl(2) can automatically manage read and write requests through
1190 * the sysctl table. The data and maxlen fields of the ctl_table
1191 * struct enable minimal validation of the values being written to be
1192 * performed, and the mode field allows minimal authentication.
1194 * More sophisticated management can be enabled by the provision of a
1195 * strategy routine with the table entry. This will be called before
1196 * any automatic read or write of the data is performed.
1198 * The strategy routine may return
1200 * < 0 - Error occurred (error is passed to user process)
1202 * 0 - OK - proceed with automatic read or write.
1204 * > 0 - OK - read or write has been done by the strategy routine, so
1205 * return immediately.
1207 * There must be a proc_handler routine for any terminal nodes
1208 * mirrored under /proc/sys (non-terminals are handled by a built-in
1209 * directory handler). Several default handlers are available to
1210 * cover common cases -
1212 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1213 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1214 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1216 * It is the handler's job to read the input buffer from user memory
1217 * and process it. The handler should return 0 on success.
1219 * This routine returns %NULL on a failure to register, and a pointer
1220 * to the table header on success.
1222 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1225 struct ctl_table_header *tmp;
1226 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1229 tmp->ctl_table = table;
1230 INIT_LIST_HEAD(&tmp->ctl_entry);
1232 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1234 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1235 #ifdef CONFIG_PROC_FS
1236 register_proc_table(table, proc_sys_root);
1242 * unregister_sysctl_table - unregister a sysctl table hierarchy
1243 * @header: the header returned from register_sysctl_table
1245 * Unregisters the sysctl table and all children. proc entries may not
1246 * actually be removed until they are no longer used by anyone.
1248 void unregister_sysctl_table(struct ctl_table_header * header)
1250 list_del(&header->ctl_entry);
1251 #ifdef CONFIG_PROC_FS
1252 unregister_proc_table(header->ctl_table, proc_sys_root);
1261 #ifdef CONFIG_PROC_FS
1263 /* Scan the sysctl entries in table and add them all into /proc */
1264 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1266 struct proc_dir_entry *de;
1270 for (; table->ctl_name; table++) {
1271 /* Can't do anything without a proc name. */
1272 if (!table->procname)
1274 /* Maybe we can't do anything with it... */
1275 if (!table->proc_handler && !table->child) {
1276 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1281 len = strlen(table->procname);
1285 if (table->proc_handler)
1289 for (de = root->subdir; de; de = de->next) {
1290 if (proc_match(len, table->procname, de))
1293 /* If the subdir exists already, de is non-NULL */
1297 de = create_proc_entry(table->procname, mode, root);
1300 de->data = (void *) table;
1301 if (table->proc_handler)
1302 de->proc_fops = &proc_sys_file_operations;
1305 if (de->mode & S_IFDIR)
1306 register_proc_table(table->child, de);
1311 * Unregister a /proc sysctl table and any subdirectories.
1313 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1315 struct proc_dir_entry *de;
1316 for (; table->ctl_name; table++) {
1317 if (!(de = table->de))
1319 if (de->mode & S_IFDIR) {
1320 if (!table->child) {
1321 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1324 unregister_proc_table(table->child, de);
1326 /* Don't unregister directories which still have entries.. */
1331 /* Don't unregister proc entries that are still being used.. */
1332 if (atomic_read(&de->count))
1336 remove_proc_entry(table->procname, root);
1340 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1341 size_t count, loff_t *ppos)
1344 struct proc_dir_entry *de;
1345 struct ctl_table *table;
1349 de = PDE(file->f_dentry->d_inode);
1350 if (!de || !de->data)
1352 table = (struct ctl_table *) de->data;
1353 if (!table || !table->proc_handler)
1355 op = (write ? 002 : 004);
1356 if (ctl_perm(table, op))
1361 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1367 static int proc_opensys(struct inode *inode, struct file *file)
1369 if (file->f_mode & FMODE_WRITE) {
1371 * sysctl entries that are not writable,
1372 * are _NOT_ writable, capabilities or not.
1374 if (!(inode->i_mode & S_IWUSR))
1381 static ssize_t proc_readsys(struct file * file, char __user * buf,
1382 size_t count, loff_t *ppos)
1384 return do_rw_proc(0, file, buf, count, ppos);
1387 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1388 size_t count, loff_t *ppos)
1390 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1394 * proc_dostring - read a string sysctl
1395 * @table: the sysctl table
1396 * @write: %TRUE if this is a write to the sysctl file
1397 * @filp: the file structure
1398 * @buffer: the user buffer
1399 * @lenp: the size of the user buffer
1401 * Reads/writes a string from/to the user buffer. If the kernel
1402 * buffer provided is not large enough to hold the string, the
1403 * string is truncated. The copied string is %NULL-terminated.
1404 * If the string is being read by the user process, it is copied
1405 * and a newline '\n' is added. It is truncated if the buffer is
1408 * Returns 0 on success.
1410 int proc_dostring(ctl_table *table, int write, struct file *filp,
1411 void __user *buffer, size_t *lenp, loff_t *ppos)
1417 if (!table->data || !table->maxlen || !*lenp ||
1418 (*ppos && !write)) {
1426 while (len < *lenp) {
1427 if (get_user(c, p++))
1429 if (c == 0 || c == '\n')
1433 if (len >= table->maxlen)
1434 len = table->maxlen-1;
1435 if(copy_from_user(table->data, buffer, len))
1437 ((char *) table->data)[len] = 0;
1440 len = strlen(table->data);
1441 if (len > table->maxlen)
1442 len = table->maxlen;
1446 if(copy_to_user(buffer, table->data, len))
1449 if(put_user('\n', ((char __user *) buffer) + len))
1460 * Special case of dostring for the UTS structure. This has locks
1461 * to observe. Should this be in kernel/sys.c ????
1464 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1465 void __user *buffer, size_t *lenp, loff_t *ppos)
1470 down_read(&uts_sem);
1471 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1474 down_write(&uts_sem);
1475 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1481 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1483 int write, void *data)
1486 *valp = *negp ? -*lvalp : *lvalp;
1491 *lvalp = (unsigned long)-val;
1494 *lvalp = (unsigned long)val;
1500 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1501 void __user *buffer, size_t *lenp, loff_t *ppos,
1502 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1503 int write, void *data),
1506 #define TMPBUFLEN 21
1507 int *i, vleft, first=1, neg, val;
1511 char buf[TMPBUFLEN], *p;
1512 char __user *s = buffer;
1514 if (!table->data || !table->maxlen || !*lenp ||
1515 (*ppos && !write)) {
1520 i = (int *) table->data;
1521 vleft = table->maxlen / sizeof(*i);
1525 conv = do_proc_dointvec_conv;
1527 for (; left && vleft--; i++, first=0) {
1542 if (len > sizeof(buf) - 1)
1543 len = sizeof(buf) - 1;
1544 if (copy_from_user(buf, s, len))
1548 if (*p == '-' && left > 1) {
1552 if (*p < '0' || *p > '9')
1555 lval = simple_strtoul(p, &p, 0);
1558 if ((len < left) && *p && !isspace(*p))
1565 if (conv(&neg, &lval, i, 1, data))
1572 if (conv(&neg, &lval, i, 0, data))
1575 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1579 if(copy_to_user(s, buf, len))
1586 if (!write && !first && left) {
1587 if(put_user('\n', s))
1594 if (get_user(c, s++))
1610 * proc_dointvec - read a vector of integers
1611 * @table: the sysctl table
1612 * @write: %TRUE if this is a write to the sysctl file
1613 * @filp: the file structure
1614 * @buffer: the user buffer
1615 * @lenp: the size of the user buffer
1617 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1618 * values from/to the user buffer, treated as an ASCII string.
1620 * Returns 0 on success.
1622 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1623 void __user *buffer, size_t *lenp, loff_t *ppos)
1625 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1635 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1637 int write, void *data)
1639 int op = *(int *)data;
1641 int val = *negp ? -*lvalp : *lvalp;
1643 case OP_SET: *valp = val; break;
1644 case OP_AND: *valp &= val; break;
1645 case OP_OR: *valp |= val; break;
1646 case OP_MAX: if(*valp < val)
1649 case OP_MIN: if(*valp > val)
1657 *lvalp = (unsigned long)-val;
1660 *lvalp = (unsigned long)val;
1667 * init may raise the set.
1670 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1671 void __user *buffer, size_t *lenp, loff_t *ppos)
1675 if (!capable(CAP_SYS_MODULE)) {
1679 op = (current->pid == 1) ? OP_SET : OP_AND;
1680 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1681 do_proc_dointvec_bset_conv,&op);
1684 struct do_proc_dointvec_minmax_conv_param {
1689 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1691 int write, void *data)
1693 struct do_proc_dointvec_minmax_conv_param *param = data;
1695 int val = *negp ? -*lvalp : *lvalp;
1696 if ((param->min && *param->min > val) ||
1697 (param->max && *param->max < val))
1704 *lvalp = (unsigned long)-val;
1707 *lvalp = (unsigned long)val;
1714 * proc_dointvec_minmax - read a vector of integers with min/max values
1715 * @table: the sysctl table
1716 * @write: %TRUE if this is a write to the sysctl file
1717 * @filp: the file structure
1718 * @buffer: the user buffer
1719 * @lenp: the size of the user buffer
1721 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1722 * values from/to the user buffer, treated as an ASCII string.
1724 * This routine will ensure the values are within the range specified by
1725 * table->extra1 (min) and table->extra2 (max).
1727 * Returns 0 on success.
1729 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1730 void __user *buffer, size_t *lenp, loff_t *ppos)
1732 struct do_proc_dointvec_minmax_conv_param param = {
1733 .min = (int *) table->extra1,
1734 .max = (int *) table->extra2,
1736 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1737 do_proc_dointvec_minmax_conv, ¶m);
1740 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1742 void __user *buffer,
1743 size_t *lenp, loff_t *ppos,
1744 unsigned long convmul,
1745 unsigned long convdiv)
1747 #define TMPBUFLEN 21
1748 unsigned long *i, *min, *max, val;
1749 int vleft, first=1, neg;
1751 char buf[TMPBUFLEN], *p;
1752 char __user *s = buffer;
1754 if (!table->data || !table->maxlen || !*lenp ||
1755 (*ppos && !write)) {
1760 i = (unsigned long *) table->data;
1761 min = (unsigned long *) table->extra1;
1762 max = (unsigned long *) table->extra2;
1763 vleft = table->maxlen / sizeof(unsigned long);
1766 for (; left && vleft--; i++, min++, max++, first=0) {
1781 if (len > TMPBUFLEN-1)
1783 if (copy_from_user(buf, s, len))
1787 if (*p == '-' && left > 1) {
1791 if (*p < '0' || *p > '9')
1793 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1795 if ((len < left) && *p && !isspace(*p))
1804 if ((min && val < *min) || (max && val > *max))
1811 sprintf(p, "%lu", convdiv * (*i) / convmul);
1815 if(copy_to_user(s, buf, len))
1822 if (!write && !first && left) {
1823 if(put_user('\n', s))
1830 if (get_user(c, s++))
1846 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1847 * @table: the sysctl table
1848 * @write: %TRUE if this is a write to the sysctl file
1849 * @filp: the file structure
1850 * @buffer: the user buffer
1851 * @lenp: the size of the user buffer
1853 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1854 * values from/to the user buffer, treated as an ASCII string.
1856 * This routine will ensure the values are within the range specified by
1857 * table->extra1 (min) and table->extra2 (max).
1859 * Returns 0 on success.
1861 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1862 void __user *buffer, size_t *lenp, loff_t *ppos)
1864 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1868 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1869 * @table: the sysctl table
1870 * @write: %TRUE if this is a write to the sysctl file
1871 * @filp: the file structure
1872 * @buffer: the user buffer
1873 * @lenp: the size of the user buffer
1875 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1876 * values from/to the user buffer, treated as an ASCII string. The values
1877 * are treated as milliseconds, and converted to jiffies when they are stored.
1879 * This routine will ensure the values are within the range specified by
1880 * table->extra1 (min) and table->extra2 (max).
1882 * Returns 0 on success.
1884 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1886 void __user *buffer,
1887 size_t *lenp, loff_t *ppos)
1889 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1890 lenp, ppos, HZ, 1000l);
1894 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1896 int write, void *data)
1899 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1905 lval = (unsigned long)-val;
1908 lval = (unsigned long)val;
1915 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1917 int write, void *data)
1920 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1926 lval = (unsigned long)-val;
1929 lval = (unsigned long)val;
1931 *lvalp = jiffies_to_clock_t(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);
1980 #else /* CONFIG_PROC_FS */
1982 int proc_dostring(ctl_table *table, int write, struct file *filp,
1983 void __user *buffer, size_t *lenp, loff_t *ppos)
1988 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1989 void __user *buffer, size_t *lenp, loff_t *ppos)
1994 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1995 void __user *buffer, size_t *lenp, loff_t *ppos)
2000 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2001 void __user *buffer, size_t *lenp, loff_t *ppos)
2006 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2007 void __user *buffer, size_t *lenp, loff_t *ppos)
2012 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2013 void __user *buffer, size_t *lenp, loff_t *ppos)
2018 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2019 void __user *buffer, size_t *lenp, loff_t *ppos)
2024 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2025 void __user *buffer, size_t *lenp, loff_t *ppos)
2030 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2032 void __user *buffer,
2033 size_t *lenp, loff_t *ppos)
2039 #endif /* CONFIG_PROC_FS */
2043 * General sysctl support routines
2046 /* The generic string strategy routine: */
2047 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2048 void __user *oldval, size_t __user *oldlenp,
2049 void __user *newval, size_t newlen, void **context)
2053 if (!table->data || !table->maxlen)
2056 if (oldval && oldlenp) {
2057 if (get_user(len, oldlenp))
2060 l = strlen(table->data);
2061 if (len > l) len = l;
2062 if (len >= table->maxlen)
2063 len = table->maxlen;
2064 if(copy_to_user(oldval, table->data, len))
2066 if(put_user(0, ((char __user *) oldval) + len))
2068 if(put_user(len, oldlenp))
2072 if (newval && newlen) {
2074 if (len > table->maxlen)
2075 len = table->maxlen;
2076 if(copy_from_user(table->data, newval, len))
2078 if (len == table->maxlen)
2080 ((char *) table->data)[len] = 0;
2086 * This function makes sure that all of the integers in the vector
2087 * are between the minimum and maximum values given in the arrays
2088 * table->extra1 and table->extra2, respectively.
2090 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2091 void __user *oldval, size_t __user *oldlenp,
2092 void __user *newval, size_t newlen, void **context)
2095 if (newval && newlen) {
2096 int __user *vec = (int __user *) newval;
2097 int *min = (int *) table->extra1;
2098 int *max = (int *) table->extra2;
2102 if (newlen % sizeof(int) != 0)
2105 if (!table->extra1 && !table->extra2)
2108 if (newlen > table->maxlen)
2109 newlen = table->maxlen;
2110 length = newlen / sizeof(int);
2112 for (i = 0; i < length; i++) {
2114 if (get_user(value, vec + i))
2116 if (min && value < min[i])
2118 if (max && value > max[i])
2125 /* Strategy function to convert jiffies to seconds */
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 if (get_user(olen, oldlenp))
2135 if (olen!=sizeof(int))
2138 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2139 (oldlenp && put_user(sizeof(int),oldlenp)))
2142 if (newval && newlen) {
2144 if (newlen != sizeof(int))
2146 if (get_user(new, (int __user *)newval))
2148 *(int *)(table->data) = new*HZ;
2154 #else /* CONFIG_SYSCTL */
2157 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2162 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2163 void __user *oldval, size_t __user *oldlenp,
2164 void __user *newval, size_t newlen, void **context)
2169 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2170 void __user *oldval, size_t __user *oldlenp,
2171 void __user *newval, size_t newlen, void **context)
2176 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2177 void __user *oldval, size_t __user *oldlenp,
2178 void __user *newval, size_t newlen, void **context)
2183 int proc_dostring(ctl_table *table, int write, struct file *filp,
2184 void __user *buffer, size_t *lenp, loff_t *ppos)
2189 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2190 void __user *buffer, size_t *lenp, loff_t *ppos)
2195 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2196 void __user *buffer, size_t *lenp, loff_t *ppos)
2201 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2202 void __user *buffer, size_t *lenp, loff_t *ppos)
2207 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2208 void __user *buffer, size_t *lenp, loff_t *ppos)
2213 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2214 void __user *buffer, size_t *lenp, loff_t *ppos)
2219 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2220 void __user *buffer, size_t *lenp, loff_t *ppos)
2225 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2227 void __user *buffer,
2228 size_t *lenp, loff_t *ppos)
2233 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2239 void unregister_sysctl_table(struct ctl_table_header * table)
2243 #endif /* CONFIG_SYSCTL */
2246 * No sense putting this after each symbol definition, twice,
2247 * exception granted :-)
2249 EXPORT_SYMBOL(proc_dointvec);
2250 EXPORT_SYMBOL(proc_dointvec_jiffies);
2251 EXPORT_SYMBOL(proc_dointvec_minmax);
2252 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2253 EXPORT_SYMBOL(proc_dostring);
2254 EXPORT_SYMBOL(proc_doulongvec_minmax);
2255 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2256 EXPORT_SYMBOL(register_sysctl_table);
2257 EXPORT_SYMBOL(sysctl_intvec);
2258 EXPORT_SYMBOL(sysctl_jiffies);
2259 EXPORT_SYMBOL(sysctl_string);
2260 EXPORT_SYMBOL(unregister_sysctl_table);