2 * sysctl.c: General linux system control interface
4 * Begun 24 March 1995, Stephen Tweedie
5 * Added /proc support, Dec 1995
6 * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
7 * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
8 * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
9 * Dynamic registration fixes, Stephen Tweedie.
10 * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
11 * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13 * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
14 * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
15 * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17 * The list_for_each() macro wasn't appropriate for the sysctl loop.
18 * Removed it and replaced it with older style, 03/23/00, Bill Wendling
21 #include <linux/config.h>
22 #include <linux/module.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/sysrq.h>
35 #include <linux/highuid.h>
36 #include <linux/writeback.h>
37 #include <linux/hugetlb.h>
38 #include <linux/security.h>
39 #include <linux/initrd.h>
40 #include <linux/times.h>
41 #include <linux/limits.h>
42 #include <linux/dcache.h>
43 #include <linux/syscalls.h>
45 #include <asm/uaccess.h>
46 #include <asm/processor.h>
48 #ifdef CONFIG_ROOT_NFS
49 #include <linux/nfs_fs.h>
52 #if defined(CONFIG_SYSCTL)
54 /* External variables not in a header file. */
56 extern int sysctl_overcommit_memory;
57 extern int sysctl_overcommit_ratio;
58 extern int max_threads;
59 extern int sysrq_enabled;
60 extern int core_uses_pid;
61 extern int suid_dumpable;
62 extern char core_pattern[];
65 extern int min_free_kbytes;
66 extern int printk_ratelimit_jiffies;
67 extern int printk_ratelimit_burst;
68 extern int pid_max_min, pid_max_max;
70 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
71 int unknown_nmi_panic;
72 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
73 void __user *, size_t *, loff_t *);
76 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
77 static int maxolduid = 65535;
80 static int ngroups_max = NGROUPS_MAX;
83 extern char modprobe_path[];
86 extern char hotplug_path[];
88 #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 int randomize_va_space = 1;
127 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
128 ctl_table *, void **);
129 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
130 void __user *buffer, size_t *lenp, loff_t *ppos);
132 static ctl_table root_table[];
133 static struct ctl_table_header root_table_header =
134 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
136 static ctl_table kern_table[];
137 static ctl_table vm_table[];
139 extern ctl_table net_table[];
141 static ctl_table proc_table[];
142 static ctl_table fs_table[];
143 static ctl_table debug_table[];
144 static ctl_table dev_table[];
145 extern ctl_table random_table[];
146 #ifdef CONFIG_UNIX98_PTYS
147 extern ctl_table pty_table[];
150 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
151 int sysctl_legacy_va_layout;
154 /* /proc declarations: */
156 #ifdef CONFIG_PROC_FS
158 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
159 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
160 static int proc_opensys(struct inode *, struct file *);
162 struct file_operations proc_sys_file_operations = {
163 .open = proc_opensys,
164 .read = proc_readsys,
165 .write = proc_writesys,
168 extern struct proc_dir_entry *proc_sys_root;
170 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
171 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
174 /* The default sysctl tables: */
176 static ctl_table root_table[] = {
178 .ctl_name = CTL_KERN,
179 .procname = "kernel",
198 .ctl_name = CTL_PROC,
210 .ctl_name = CTL_DEBUG,
213 .child = debug_table,
224 static ctl_table kern_table[] = {
226 .ctl_name = KERN_OSTYPE,
227 .procname = "ostype",
228 .data = system_utsname.sysname,
229 .maxlen = sizeof(system_utsname.sysname),
231 .proc_handler = &proc_doutsstring,
232 .strategy = &sysctl_string,
235 .ctl_name = KERN_OSRELEASE,
236 .procname = "osrelease",
237 .data = system_utsname.release,
238 .maxlen = sizeof(system_utsname.release),
240 .proc_handler = &proc_doutsstring,
241 .strategy = &sysctl_string,
244 .ctl_name = KERN_VERSION,
245 .procname = "version",
246 .data = system_utsname.version,
247 .maxlen = sizeof(system_utsname.version),
249 .proc_handler = &proc_doutsstring,
250 .strategy = &sysctl_string,
253 .ctl_name = KERN_NODENAME,
254 .procname = "hostname",
255 .data = system_utsname.nodename,
256 .maxlen = sizeof(system_utsname.nodename),
258 .proc_handler = &proc_doutsstring,
259 .strategy = &sysctl_string,
262 .ctl_name = KERN_DOMAINNAME,
263 .procname = "domainname",
264 .data = system_utsname.domainname,
265 .maxlen = sizeof(system_utsname.domainname),
267 .proc_handler = &proc_doutsstring,
268 .strategy = &sysctl_string,
271 .ctl_name = KERN_PANIC,
273 .data = &panic_timeout,
274 .maxlen = sizeof(int),
276 .proc_handler = &proc_dointvec,
279 .ctl_name = KERN_CORE_USES_PID,
280 .procname = "core_uses_pid",
281 .data = &core_uses_pid,
282 .maxlen = sizeof(int),
284 .proc_handler = &proc_dointvec,
287 .ctl_name = KERN_CORE_PATTERN,
288 .procname = "core_pattern",
289 .data = core_pattern,
292 .proc_handler = &proc_dostring,
293 .strategy = &sysctl_string,
296 .ctl_name = KERN_TAINTED,
297 .procname = "tainted",
299 .maxlen = sizeof(int),
301 .proc_handler = &proc_dointvec,
304 .ctl_name = KERN_CAP_BSET,
305 .procname = "cap-bound",
307 .maxlen = sizeof(kernel_cap_t),
309 .proc_handler = &proc_dointvec_bset,
311 #ifdef CONFIG_BLK_DEV_INITRD
313 .ctl_name = KERN_REALROOTDEV,
314 .procname = "real-root-dev",
315 .data = &real_root_dev,
316 .maxlen = sizeof(int),
318 .proc_handler = &proc_dointvec,
323 .ctl_name = KERN_SPARC_REBOOT,
324 .procname = "reboot-cmd",
325 .data = reboot_command,
328 .proc_handler = &proc_dostring,
329 .strategy = &sysctl_string,
332 .ctl_name = KERN_SPARC_STOP_A,
333 .procname = "stop-a",
334 .data = &stop_a_enabled,
335 .maxlen = sizeof (int),
337 .proc_handler = &proc_dointvec,
340 .ctl_name = KERN_SPARC_SCONS_PWROFF,
341 .procname = "scons-poweroff",
342 .data = &scons_pwroff,
343 .maxlen = sizeof (int),
345 .proc_handler = &proc_dointvec,
350 .ctl_name = KERN_HPPA_PWRSW,
351 .procname = "soft-power",
352 .data = &pwrsw_enabled,
353 .maxlen = sizeof (int),
355 .proc_handler = &proc_dointvec,
358 .ctl_name = KERN_HPPA_UNALIGNED,
359 .procname = "unaligned-trap",
360 .data = &unaligned_enabled,
361 .maxlen = sizeof (int),
363 .proc_handler = &proc_dointvec,
367 .ctl_name = KERN_CTLALTDEL,
368 .procname = "ctrl-alt-del",
370 .maxlen = sizeof(int),
372 .proc_handler = &proc_dointvec,
375 .ctl_name = KERN_PRINTK,
376 .procname = "printk",
377 .data = &console_loglevel,
378 .maxlen = 4*sizeof(int),
380 .proc_handler = &proc_dointvec,
384 .ctl_name = KERN_MODPROBE,
385 .procname = "modprobe",
386 .data = &modprobe_path,
387 .maxlen = KMOD_PATH_LEN,
389 .proc_handler = &proc_dostring,
390 .strategy = &sysctl_string,
393 #ifdef CONFIG_HOTPLUG
395 .ctl_name = KERN_HOTPLUG,
396 .procname = "hotplug",
397 .data = &hotplug_path,
398 .maxlen = HOTPLUG_PATH_LEN,
400 .proc_handler = &proc_dostring,
401 .strategy = &sysctl_string,
404 #ifdef CONFIG_CHR_DEV_SG
406 .ctl_name = KERN_SG_BIG_BUFF,
407 .procname = "sg-big-buff",
408 .data = &sg_big_buff,
409 .maxlen = sizeof (int),
411 .proc_handler = &proc_dointvec,
414 #ifdef CONFIG_BSD_PROCESS_ACCT
416 .ctl_name = KERN_ACCT,
419 .maxlen = 3*sizeof(int),
421 .proc_handler = &proc_dointvec,
424 #ifdef CONFIG_SYSVIPC
426 .ctl_name = KERN_SHMMAX,
427 .procname = "shmmax",
429 .maxlen = sizeof (size_t),
431 .proc_handler = &proc_doulongvec_minmax,
434 .ctl_name = KERN_SHMALL,
435 .procname = "shmall",
437 .maxlen = sizeof (size_t),
439 .proc_handler = &proc_doulongvec_minmax,
442 .ctl_name = KERN_SHMMNI,
443 .procname = "shmmni",
445 .maxlen = sizeof (int),
447 .proc_handler = &proc_dointvec,
450 .ctl_name = KERN_MSGMAX,
451 .procname = "msgmax",
453 .maxlen = sizeof (int),
455 .proc_handler = &proc_dointvec,
458 .ctl_name = KERN_MSGMNI,
459 .procname = "msgmni",
461 .maxlen = sizeof (int),
463 .proc_handler = &proc_dointvec,
466 .ctl_name = KERN_MSGMNB,
467 .procname = "msgmnb",
469 .maxlen = sizeof (int),
471 .proc_handler = &proc_dointvec,
474 .ctl_name = KERN_SEM,
477 .maxlen = 4*sizeof (int),
479 .proc_handler = &proc_dointvec,
482 #ifdef CONFIG_MAGIC_SYSRQ
484 .ctl_name = KERN_SYSRQ,
486 .data = &sysrq_enabled,
487 .maxlen = sizeof (int),
489 .proc_handler = &proc_dointvec,
493 .ctl_name = KERN_CADPID,
494 .procname = "cad_pid",
496 .maxlen = sizeof (int),
498 .proc_handler = &proc_dointvec,
501 .ctl_name = KERN_MAX_THREADS,
502 .procname = "threads-max",
503 .data = &max_threads,
504 .maxlen = sizeof(int),
506 .proc_handler = &proc_dointvec,
509 .ctl_name = KERN_RANDOM,
510 .procname = "random",
512 .child = random_table,
514 #ifdef CONFIG_UNIX98_PTYS
516 .ctl_name = KERN_PTY,
523 .ctl_name = KERN_OVERFLOWUID,
524 .procname = "overflowuid",
525 .data = &overflowuid,
526 .maxlen = sizeof(int),
528 .proc_handler = &proc_dointvec_minmax,
529 .strategy = &sysctl_intvec,
530 .extra1 = &minolduid,
531 .extra2 = &maxolduid,
534 .ctl_name = KERN_OVERFLOWGID,
535 .procname = "overflowgid",
536 .data = &overflowgid,
537 .maxlen = sizeof(int),
539 .proc_handler = &proc_dointvec_minmax,
540 .strategy = &sysctl_intvec,
541 .extra1 = &minolduid,
542 .extra2 = &maxolduid,
544 #ifdef CONFIG_ARCH_S390
545 #ifdef CONFIG_MATHEMU
547 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
548 .procname = "ieee_emulation_warnings",
549 .data = &sysctl_ieee_emulation_warnings,
550 .maxlen = sizeof(int),
552 .proc_handler = &proc_dointvec,
555 #ifdef CONFIG_NO_IDLE_HZ
557 .ctl_name = KERN_HZ_TIMER,
558 .procname = "hz_timer",
559 .data = &sysctl_hz_timer,
560 .maxlen = sizeof(int),
562 .proc_handler = &proc_dointvec,
566 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
567 .procname = "userprocess_debug",
568 .data = &sysctl_userprocess_debug,
569 .maxlen = sizeof(int),
571 .proc_handler = &proc_dointvec,
575 .ctl_name = KERN_PIDMAX,
576 .procname = "pid_max",
578 .maxlen = sizeof (int),
580 .proc_handler = &proc_dointvec_minmax,
581 .strategy = sysctl_intvec,
582 .extra1 = &pid_max_min,
583 .extra2 = &pid_max_max,
586 .ctl_name = KERN_PANIC_ON_OOPS,
587 .procname = "panic_on_oops",
588 .data = &panic_on_oops,
589 .maxlen = sizeof(int),
591 .proc_handler = &proc_dointvec,
594 .ctl_name = KERN_PRINTK_RATELIMIT,
595 .procname = "printk_ratelimit",
596 .data = &printk_ratelimit_jiffies,
597 .maxlen = sizeof(int),
599 .proc_handler = &proc_dointvec_jiffies,
600 .strategy = &sysctl_jiffies,
603 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
604 .procname = "printk_ratelimit_burst",
605 .data = &printk_ratelimit_burst,
606 .maxlen = sizeof(int),
608 .proc_handler = &proc_dointvec,
611 .ctl_name = KERN_NGROUPS_MAX,
612 .procname = "ngroups_max",
613 .data = &ngroups_max,
614 .maxlen = sizeof (int),
616 .proc_handler = &proc_dointvec,
618 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
620 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
621 .procname = "unknown_nmi_panic",
622 .data = &unknown_nmi_panic,
623 .maxlen = sizeof (int),
625 .proc_handler = &proc_unknown_nmi_panic,
628 #if defined(CONFIG_X86)
630 .ctl_name = KERN_BOOTLOADER_TYPE,
631 .procname = "bootloader_type",
632 .data = &bootloader_type,
633 .maxlen = sizeof (int),
635 .proc_handler = &proc_dointvec,
639 .ctl_name = KERN_RANDOMIZE,
640 .procname = "randomize_va_space",
641 .data = &randomize_va_space,
642 .maxlen = sizeof(int),
644 .proc_handler = &proc_dointvec,
650 /* Constants for minimum and maximum testing in vm_table.
651 We use these as one-element integer vectors. */
653 static int one_hundred = 100;
656 static ctl_table vm_table[] = {
658 .ctl_name = VM_OVERCOMMIT_MEMORY,
659 .procname = "overcommit_memory",
660 .data = &sysctl_overcommit_memory,
661 .maxlen = sizeof(sysctl_overcommit_memory),
663 .proc_handler = &proc_dointvec,
666 .ctl_name = VM_OVERCOMMIT_RATIO,
667 .procname = "overcommit_ratio",
668 .data = &sysctl_overcommit_ratio,
669 .maxlen = sizeof(sysctl_overcommit_ratio),
671 .proc_handler = &proc_dointvec,
674 .ctl_name = VM_PAGE_CLUSTER,
675 .procname = "page-cluster",
676 .data = &page_cluster,
677 .maxlen = sizeof(int),
679 .proc_handler = &proc_dointvec,
682 .ctl_name = VM_DIRTY_BACKGROUND,
683 .procname = "dirty_background_ratio",
684 .data = &dirty_background_ratio,
685 .maxlen = sizeof(dirty_background_ratio),
687 .proc_handler = &proc_dointvec_minmax,
688 .strategy = &sysctl_intvec,
690 .extra2 = &one_hundred,
693 .ctl_name = VM_DIRTY_RATIO,
694 .procname = "dirty_ratio",
695 .data = &vm_dirty_ratio,
696 .maxlen = sizeof(vm_dirty_ratio),
698 .proc_handler = &proc_dointvec_minmax,
699 .strategy = &sysctl_intvec,
701 .extra2 = &one_hundred,
704 .ctl_name = VM_DIRTY_WB_CS,
705 .procname = "dirty_writeback_centisecs",
706 .data = &dirty_writeback_centisecs,
707 .maxlen = sizeof(dirty_writeback_centisecs),
709 .proc_handler = &dirty_writeback_centisecs_handler,
712 .ctl_name = VM_DIRTY_EXPIRE_CS,
713 .procname = "dirty_expire_centisecs",
714 .data = &dirty_expire_centisecs,
715 .maxlen = sizeof(dirty_expire_centisecs),
717 .proc_handler = &proc_dointvec,
720 .ctl_name = VM_NR_PDFLUSH_THREADS,
721 .procname = "nr_pdflush_threads",
722 .data = &nr_pdflush_threads,
723 .maxlen = sizeof nr_pdflush_threads,
724 .mode = 0444 /* read-only*/,
725 .proc_handler = &proc_dointvec,
728 .ctl_name = VM_SWAPPINESS,
729 .procname = "swappiness",
730 .data = &vm_swappiness,
731 .maxlen = sizeof(vm_swappiness),
733 .proc_handler = &proc_dointvec_minmax,
734 .strategy = &sysctl_intvec,
736 .extra2 = &one_hundred,
738 #ifdef CONFIG_HUGETLB_PAGE
740 .ctl_name = VM_HUGETLB_PAGES,
741 .procname = "nr_hugepages",
742 .data = &max_huge_pages,
743 .maxlen = sizeof(unsigned long),
745 .proc_handler = &hugetlb_sysctl_handler,
746 .extra1 = (void *)&hugetlb_zero,
747 .extra2 = (void *)&hugetlb_infinity,
750 .ctl_name = VM_HUGETLB_GROUP,
751 .procname = "hugetlb_shm_group",
752 .data = &sysctl_hugetlb_shm_group,
753 .maxlen = sizeof(gid_t),
755 .proc_handler = &proc_dointvec,
759 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
760 .procname = "lowmem_reserve_ratio",
761 .data = &sysctl_lowmem_reserve_ratio,
762 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
764 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
765 .strategy = &sysctl_intvec,
768 .ctl_name = VM_MIN_FREE_KBYTES,
769 .procname = "min_free_kbytes",
770 .data = &min_free_kbytes,
771 .maxlen = sizeof(min_free_kbytes),
773 .proc_handler = &min_free_kbytes_sysctl_handler,
774 .strategy = &sysctl_intvec,
779 .ctl_name = VM_MAX_MAP_COUNT,
780 .procname = "max_map_count",
781 .data = &sysctl_max_map_count,
782 .maxlen = sizeof(sysctl_max_map_count),
784 .proc_handler = &proc_dointvec
788 .ctl_name = VM_LAPTOP_MODE,
789 .procname = "laptop_mode",
790 .data = &laptop_mode,
791 .maxlen = sizeof(laptop_mode),
793 .proc_handler = &proc_dointvec,
794 .strategy = &sysctl_intvec,
798 .ctl_name = VM_BLOCK_DUMP,
799 .procname = "block_dump",
801 .maxlen = sizeof(block_dump),
803 .proc_handler = &proc_dointvec,
804 .strategy = &sysctl_intvec,
808 .ctl_name = VM_VFS_CACHE_PRESSURE,
809 .procname = "vfs_cache_pressure",
810 .data = &sysctl_vfs_cache_pressure,
811 .maxlen = sizeof(sysctl_vfs_cache_pressure),
813 .proc_handler = &proc_dointvec,
814 .strategy = &sysctl_intvec,
817 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
819 .ctl_name = VM_LEGACY_VA_LAYOUT,
820 .procname = "legacy_va_layout",
821 .data = &sysctl_legacy_va_layout,
822 .maxlen = sizeof(sysctl_legacy_va_layout),
824 .proc_handler = &proc_dointvec,
825 .strategy = &sysctl_intvec,
831 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
832 .procname = "swap_token_timeout",
833 .data = &swap_token_default_timeout,
834 .maxlen = sizeof(swap_token_default_timeout),
836 .proc_handler = &proc_dointvec_jiffies,
837 .strategy = &sysctl_jiffies,
843 static ctl_table proc_table[] = {
847 static ctl_table fs_table[] = {
849 .ctl_name = FS_NRINODE,
850 .procname = "inode-nr",
851 .data = &inodes_stat,
852 .maxlen = 2*sizeof(int),
854 .proc_handler = &proc_dointvec,
857 .ctl_name = FS_STATINODE,
858 .procname = "inode-state",
859 .data = &inodes_stat,
860 .maxlen = 7*sizeof(int),
862 .proc_handler = &proc_dointvec,
865 .ctl_name = FS_NRFILE,
866 .procname = "file-nr",
868 .maxlen = 3*sizeof(int),
870 .proc_handler = &proc_dointvec,
873 .ctl_name = FS_MAXFILE,
874 .procname = "file-max",
875 .data = &files_stat.max_files,
876 .maxlen = sizeof(int),
878 .proc_handler = &proc_dointvec,
881 .ctl_name = FS_DENTRY,
882 .procname = "dentry-state",
883 .data = &dentry_stat,
884 .maxlen = 6*sizeof(int),
886 .proc_handler = &proc_dointvec,
889 .ctl_name = FS_OVERFLOWUID,
890 .procname = "overflowuid",
891 .data = &fs_overflowuid,
892 .maxlen = sizeof(int),
894 .proc_handler = &proc_dointvec_minmax,
895 .strategy = &sysctl_intvec,
896 .extra1 = &minolduid,
897 .extra2 = &maxolduid,
900 .ctl_name = FS_OVERFLOWGID,
901 .procname = "overflowgid",
902 .data = &fs_overflowgid,
903 .maxlen = sizeof(int),
905 .proc_handler = &proc_dointvec_minmax,
906 .strategy = &sysctl_intvec,
907 .extra1 = &minolduid,
908 .extra2 = &maxolduid,
911 .ctl_name = FS_LEASES,
912 .procname = "leases-enable",
913 .data = &leases_enable,
914 .maxlen = sizeof(int),
916 .proc_handler = &proc_dointvec,
918 #ifdef CONFIG_DNOTIFY
920 .ctl_name = FS_DIR_NOTIFY,
921 .procname = "dir-notify-enable",
922 .data = &dir_notify_enable,
923 .maxlen = sizeof(int),
925 .proc_handler = &proc_dointvec,
930 .ctl_name = FS_LEASE_TIME,
931 .procname = "lease-break-time",
932 .data = &lease_break_time,
933 .maxlen = sizeof(int),
935 .proc_handler = &proc_dointvec,
938 .ctl_name = FS_AIO_NR,
939 .procname = "aio-nr",
941 .maxlen = sizeof(aio_nr),
943 .proc_handler = &proc_dointvec,
946 .ctl_name = FS_AIO_MAX_NR,
947 .procname = "aio-max-nr",
949 .maxlen = sizeof(aio_max_nr),
951 .proc_handler = &proc_dointvec,
955 .ctl_name = KERN_SETUID_DUMPABLE,
956 .procname = "suid_dumpable",
957 .data = &suid_dumpable,
958 .maxlen = sizeof(int),
960 .proc_handler = &proc_dointvec,
965 static ctl_table debug_table[] = {
969 static ctl_table dev_table[] = {
973 extern void init_irq_proc (void);
975 void __init sysctl_init(void)
977 #ifdef CONFIG_PROC_FS
978 register_proc_table(root_table, proc_sys_root);
983 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
984 void __user *newval, size_t newlen)
986 struct list_head *tmp;
988 if (nlen <= 0 || nlen >= CTL_MAXNAME)
992 if (!oldlenp || get_user(old_len, oldlenp))
995 tmp = &root_table_header.ctl_entry;
997 struct ctl_table_header *head =
998 list_entry(tmp, struct ctl_table_header, ctl_entry);
999 void *context = NULL;
1000 int error = parse_table(name, nlen, oldval, oldlenp,
1001 newval, newlen, head->ctl_table,
1004 if (error != -ENOTDIR)
1007 } while (tmp != &root_table_header.ctl_entry);
1011 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1013 struct __sysctl_args tmp;
1016 if (copy_from_user(&tmp, args, sizeof(tmp)))
1020 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1021 tmp.newval, tmp.newlen);
1027 * ctl_perm does NOT grant the superuser all rights automatically, because
1028 * some sysctl variables are readonly even to root.
1031 static int test_perm(int mode, int op)
1035 else if (in_egroup_p(0))
1037 if ((mode & op & 0007) == op)
1042 static inline int ctl_perm(ctl_table *table, int op)
1045 error = security_sysctl(table, op);
1048 return test_perm(table->mode, op);
1051 static int parse_table(int __user *name, int nlen,
1052 void __user *oldval, size_t __user *oldlenp,
1053 void __user *newval, size_t newlen,
1054 ctl_table *table, void **context)
1060 if (get_user(n, name))
1062 for ( ; table->ctl_name; table++) {
1063 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1066 if (ctl_perm(table, 001))
1068 if (table->strategy) {
1069 error = table->strategy(
1072 newval, newlen, context);
1078 table = table->child;
1081 error = do_sysctl_strategy(table, name, nlen,
1083 newval, newlen, context);
1090 /* Perform the actual read/write of a sysctl table entry. */
1091 int do_sysctl_strategy (ctl_table *table,
1092 int __user *name, int nlen,
1093 void __user *oldval, size_t __user *oldlenp,
1094 void __user *newval, size_t newlen, void **context)
1103 if (ctl_perm(table, op))
1106 if (table->strategy) {
1107 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1108 newval, newlen, context);
1115 /* If there is no strategy routine, or if the strategy returns
1116 * zero, proceed with automatic r/w */
1117 if (table->data && table->maxlen) {
1118 if (oldval && oldlenp) {
1119 if (get_user(len, oldlenp))
1122 if (len > table->maxlen)
1123 len = table->maxlen;
1124 if(copy_to_user(oldval, table->data, len))
1126 if(put_user(len, oldlenp))
1130 if (newval && newlen) {
1132 if (len > table->maxlen)
1133 len = table->maxlen;
1134 if(copy_from_user(table->data, newval, len))
1142 * register_sysctl_table - register a sysctl hierarchy
1143 * @table: the top-level table structure
1144 * @insert_at_head: whether the entry should be inserted in front or at the end
1146 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1147 * array. An entry with a ctl_name of 0 terminates the table.
1149 * The members of the &ctl_table structure are used as follows:
1151 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1152 * must be unique within that level of sysctl
1154 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1155 * enter a sysctl file
1157 * data - a pointer to data for use by proc_handler
1159 * maxlen - the maximum size in bytes of the data
1161 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1163 * child - a pointer to the child sysctl table if this entry is a directory, or
1166 * proc_handler - the text handler routine (described below)
1168 * strategy - the strategy routine (described below)
1170 * de - for internal use by the sysctl routines
1172 * extra1, extra2 - extra pointers usable by the proc handler routines
1174 * Leaf nodes in the sysctl tree will be represented by a single file
1175 * under /proc; non-leaf nodes will be represented by directories.
1177 * sysctl(2) can automatically manage read and write requests through
1178 * the sysctl table. The data and maxlen fields of the ctl_table
1179 * struct enable minimal validation of the values being written to be
1180 * performed, and the mode field allows minimal authentication.
1182 * More sophisticated management can be enabled by the provision of a
1183 * strategy routine with the table entry. This will be called before
1184 * any automatic read or write of the data is performed.
1186 * The strategy routine may return
1188 * < 0 - Error occurred (error is passed to user process)
1190 * 0 - OK - proceed with automatic read or write.
1192 * > 0 - OK - read or write has been done by the strategy routine, so
1193 * return immediately.
1195 * There must be a proc_handler routine for any terminal nodes
1196 * mirrored under /proc/sys (non-terminals are handled by a built-in
1197 * directory handler). Several default handlers are available to
1198 * cover common cases -
1200 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1201 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1202 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1204 * It is the handler's job to read the input buffer from user memory
1205 * and process it. The handler should return 0 on success.
1207 * This routine returns %NULL on a failure to register, and a pointer
1208 * to the table header on success.
1210 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1213 struct ctl_table_header *tmp;
1214 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1217 tmp->ctl_table = table;
1218 INIT_LIST_HEAD(&tmp->ctl_entry);
1220 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1222 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1223 #ifdef CONFIG_PROC_FS
1224 register_proc_table(table, proc_sys_root);
1230 * unregister_sysctl_table - unregister a sysctl table hierarchy
1231 * @header: the header returned from register_sysctl_table
1233 * Unregisters the sysctl table and all children. proc entries may not
1234 * actually be removed until they are no longer used by anyone.
1236 void unregister_sysctl_table(struct ctl_table_header * header)
1238 list_del(&header->ctl_entry);
1239 #ifdef CONFIG_PROC_FS
1240 unregister_proc_table(header->ctl_table, proc_sys_root);
1249 #ifdef CONFIG_PROC_FS
1251 /* Scan the sysctl entries in table and add them all into /proc */
1252 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1254 struct proc_dir_entry *de;
1258 for (; table->ctl_name; table++) {
1259 /* Can't do anything without a proc name. */
1260 if (!table->procname)
1262 /* Maybe we can't do anything with it... */
1263 if (!table->proc_handler && !table->child) {
1264 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1269 len = strlen(table->procname);
1273 if (table->proc_handler)
1277 for (de = root->subdir; de; de = de->next) {
1278 if (proc_match(len, table->procname, de))
1281 /* If the subdir exists already, de is non-NULL */
1285 de = create_proc_entry(table->procname, mode, root);
1288 de->data = (void *) table;
1289 if (table->proc_handler)
1290 de->proc_fops = &proc_sys_file_operations;
1293 if (de->mode & S_IFDIR)
1294 register_proc_table(table->child, de);
1299 * Unregister a /proc sysctl table and any subdirectories.
1301 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1303 struct proc_dir_entry *de;
1304 for (; table->ctl_name; table++) {
1305 if (!(de = table->de))
1307 if (de->mode & S_IFDIR) {
1308 if (!table->child) {
1309 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1312 unregister_proc_table(table->child, de);
1314 /* Don't unregister directories which still have entries.. */
1319 /* Don't unregister proc entries that are still being used.. */
1320 if (atomic_read(&de->count))
1324 remove_proc_entry(table->procname, root);
1328 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1329 size_t count, loff_t *ppos)
1332 struct proc_dir_entry *de;
1333 struct ctl_table *table;
1337 de = PDE(file->f_dentry->d_inode);
1338 if (!de || !de->data)
1340 table = (struct ctl_table *) de->data;
1341 if (!table || !table->proc_handler)
1343 op = (write ? 002 : 004);
1344 if (ctl_perm(table, op))
1349 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1355 static int proc_opensys(struct inode *inode, struct file *file)
1357 if (file->f_mode & FMODE_WRITE) {
1359 * sysctl entries that are not writable,
1360 * are _NOT_ writable, capabilities or not.
1362 if (!(inode->i_mode & S_IWUSR))
1369 static ssize_t proc_readsys(struct file * file, char __user * buf,
1370 size_t count, loff_t *ppos)
1372 return do_rw_proc(0, file, buf, count, ppos);
1375 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1376 size_t count, loff_t *ppos)
1378 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1382 * proc_dostring - read a string sysctl
1383 * @table: the sysctl table
1384 * @write: %TRUE if this is a write to the sysctl file
1385 * @filp: the file structure
1386 * @buffer: the user buffer
1387 * @lenp: the size of the user buffer
1388 * @ppos: file position
1390 * Reads/writes a string from/to the user buffer. If the kernel
1391 * buffer provided is not large enough to hold the string, the
1392 * string is truncated. The copied string is %NULL-terminated.
1393 * If the string is being read by the user process, it is copied
1394 * and a newline '\n' is added. It is truncated if the buffer is
1397 * Returns 0 on success.
1399 int proc_dostring(ctl_table *table, int write, struct file *filp,
1400 void __user *buffer, size_t *lenp, loff_t *ppos)
1406 if (!table->data || !table->maxlen || !*lenp ||
1407 (*ppos && !write)) {
1415 while (len < *lenp) {
1416 if (get_user(c, p++))
1418 if (c == 0 || c == '\n')
1422 if (len >= table->maxlen)
1423 len = table->maxlen-1;
1424 if(copy_from_user(table->data, buffer, len))
1426 ((char *) table->data)[len] = 0;
1429 len = strlen(table->data);
1430 if (len > table->maxlen)
1431 len = table->maxlen;
1435 if(copy_to_user(buffer, table->data, len))
1438 if(put_user('\n', ((char __user *) buffer) + len))
1449 * Special case of dostring for the UTS structure. This has locks
1450 * to observe. Should this be in kernel/sys.c ????
1453 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1454 void __user *buffer, size_t *lenp, loff_t *ppos)
1459 down_read(&uts_sem);
1460 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1463 down_write(&uts_sem);
1464 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1470 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1472 int write, void *data)
1475 *valp = *negp ? -*lvalp : *lvalp;
1480 *lvalp = (unsigned long)-val;
1483 *lvalp = (unsigned long)val;
1489 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1490 void __user *buffer, size_t *lenp, loff_t *ppos,
1491 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1492 int write, void *data),
1495 #define TMPBUFLEN 21
1496 int *i, vleft, first=1, neg, val;
1500 char buf[TMPBUFLEN], *p;
1501 char __user *s = buffer;
1503 if (!table->data || !table->maxlen || !*lenp ||
1504 (*ppos && !write)) {
1509 i = (int *) table->data;
1510 vleft = table->maxlen / sizeof(*i);
1514 conv = do_proc_dointvec_conv;
1516 for (; left && vleft--; i++, first=0) {
1531 if (len > sizeof(buf) - 1)
1532 len = sizeof(buf) - 1;
1533 if (copy_from_user(buf, s, len))
1537 if (*p == '-' && left > 1) {
1541 if (*p < '0' || *p > '9')
1544 lval = simple_strtoul(p, &p, 0);
1547 if ((len < left) && *p && !isspace(*p))
1554 if (conv(&neg, &lval, i, 1, data))
1561 if (conv(&neg, &lval, i, 0, data))
1564 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1568 if(copy_to_user(s, buf, len))
1575 if (!write && !first && left) {
1576 if(put_user('\n', s))
1583 if (get_user(c, s++))
1599 * proc_dointvec - read a vector of integers
1600 * @table: the sysctl table
1601 * @write: %TRUE if this is a write to the sysctl file
1602 * @filp: the file structure
1603 * @buffer: the user buffer
1604 * @lenp: the size of the user buffer
1605 * @ppos: file position
1607 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1608 * values from/to the user buffer, treated as an ASCII string.
1610 * Returns 0 on success.
1612 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1613 void __user *buffer, size_t *lenp, loff_t *ppos)
1615 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1625 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1627 int write, void *data)
1629 int op = *(int *)data;
1631 int val = *negp ? -*lvalp : *lvalp;
1633 case OP_SET: *valp = val; break;
1634 case OP_AND: *valp &= val; break;
1635 case OP_OR: *valp |= val; break;
1636 case OP_MAX: if(*valp < val)
1639 case OP_MIN: if(*valp > val)
1647 *lvalp = (unsigned long)-val;
1650 *lvalp = (unsigned long)val;
1657 * init may raise the set.
1660 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1661 void __user *buffer, size_t *lenp, loff_t *ppos)
1665 if (!capable(CAP_SYS_MODULE)) {
1669 op = (current->pid == 1) ? OP_SET : OP_AND;
1670 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1671 do_proc_dointvec_bset_conv,&op);
1674 struct do_proc_dointvec_minmax_conv_param {
1679 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1681 int write, void *data)
1683 struct do_proc_dointvec_minmax_conv_param *param = data;
1685 int val = *negp ? -*lvalp : *lvalp;
1686 if ((param->min && *param->min > val) ||
1687 (param->max && *param->max < val))
1694 *lvalp = (unsigned long)-val;
1697 *lvalp = (unsigned long)val;
1704 * proc_dointvec_minmax - read a vector of integers with min/max values
1705 * @table: the sysctl table
1706 * @write: %TRUE if this is a write to the sysctl file
1707 * @filp: the file structure
1708 * @buffer: the user buffer
1709 * @lenp: the size of the user buffer
1710 * @ppos: file position
1712 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1713 * values from/to the user buffer, treated as an ASCII string.
1715 * This routine will ensure the values are within the range specified by
1716 * table->extra1 (min) and table->extra2 (max).
1718 * Returns 0 on success.
1720 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1721 void __user *buffer, size_t *lenp, loff_t *ppos)
1723 struct do_proc_dointvec_minmax_conv_param param = {
1724 .min = (int *) table->extra1,
1725 .max = (int *) table->extra2,
1727 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1728 do_proc_dointvec_minmax_conv, ¶m);
1731 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1733 void __user *buffer,
1734 size_t *lenp, loff_t *ppos,
1735 unsigned long convmul,
1736 unsigned long convdiv)
1738 #define TMPBUFLEN 21
1739 unsigned long *i, *min, *max, val;
1740 int vleft, first=1, neg;
1742 char buf[TMPBUFLEN], *p;
1743 char __user *s = buffer;
1745 if (!table->data || !table->maxlen || !*lenp ||
1746 (*ppos && !write)) {
1751 i = (unsigned long *) table->data;
1752 min = (unsigned long *) table->extra1;
1753 max = (unsigned long *) table->extra2;
1754 vleft = table->maxlen / sizeof(unsigned long);
1757 for (; left && vleft--; i++, min++, max++, first=0) {
1772 if (len > TMPBUFLEN-1)
1774 if (copy_from_user(buf, s, len))
1778 if (*p == '-' && left > 1) {
1782 if (*p < '0' || *p > '9')
1784 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1786 if ((len < left) && *p && !isspace(*p))
1795 if ((min && val < *min) || (max && val > *max))
1802 sprintf(p, "%lu", convdiv * (*i) / convmul);
1806 if(copy_to_user(s, buf, len))
1813 if (!write && !first && left) {
1814 if(put_user('\n', s))
1821 if (get_user(c, s++))
1837 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1838 * @table: the sysctl table
1839 * @write: %TRUE if this is a write to the sysctl file
1840 * @filp: the file structure
1841 * @buffer: the user buffer
1842 * @lenp: the size of the user buffer
1843 * @ppos: file position
1845 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1846 * values from/to the user buffer, treated as an ASCII string.
1848 * This routine will ensure the values are within the range specified by
1849 * table->extra1 (min) and table->extra2 (max).
1851 * Returns 0 on success.
1853 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1854 void __user *buffer, size_t *lenp, loff_t *ppos)
1856 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1860 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1861 * @table: the sysctl table
1862 * @write: %TRUE if this is a write to the sysctl file
1863 * @filp: the file structure
1864 * @buffer: the user buffer
1865 * @lenp: the size of the user buffer
1866 * @ppos: file position
1868 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1869 * values from/to the user buffer, treated as an ASCII string. The values
1870 * are treated as milliseconds, and converted to jiffies when they are stored.
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_ms_jiffies_minmax(ctl_table *table, int write,
1879 void __user *buffer,
1880 size_t *lenp, loff_t *ppos)
1882 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1883 lenp, ppos, HZ, 1000l);
1887 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1889 int write, void *data)
1892 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1898 lval = (unsigned long)-val;
1901 lval = (unsigned long)val;
1908 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1910 int write, void *data)
1913 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1919 lval = (unsigned long)-val;
1922 lval = (unsigned long)val;
1924 *lvalp = jiffies_to_clock_t(lval);
1929 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1931 int write, void *data)
1934 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1940 lval = (unsigned long)-val;
1943 lval = (unsigned long)val;
1945 *lvalp = jiffies_to_msecs(lval);
1951 * proc_dointvec_jiffies - read a vector of integers as seconds
1952 * @table: the sysctl table
1953 * @write: %TRUE if this is a write to the sysctl file
1954 * @filp: the file structure
1955 * @buffer: the user buffer
1956 * @lenp: the size of the user buffer
1957 * @ppos: file position
1959 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1960 * values from/to the user buffer, treated as an ASCII string.
1961 * The values read are assumed to be in seconds, and are converted into
1964 * Returns 0 on success.
1966 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1967 void __user *buffer, size_t *lenp, loff_t *ppos)
1969 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1970 do_proc_dointvec_jiffies_conv,NULL);
1974 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1975 * @table: the sysctl table
1976 * @write: %TRUE if this is a write to the sysctl file
1977 * @filp: the file structure
1978 * @buffer: the user buffer
1979 * @lenp: the size of the user buffer
1981 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1982 * values from/to the user buffer, treated as an ASCII string.
1983 * The values read are assumed to be in 1/USER_HZ seconds, and
1984 * are converted into jiffies.
1986 * Returns 0 on success.
1988 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1989 void __user *buffer, size_t *lenp, loff_t *ppos)
1991 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1992 do_proc_dointvec_userhz_jiffies_conv,NULL);
1996 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1997 * @table: the sysctl table
1998 * @write: %TRUE if this is a write to the sysctl file
1999 * @filp: the file structure
2000 * @buffer: the user buffer
2001 * @lenp: the size of the user buffer
2002 * @ppos: file position
2003 * @ppos: the current position in the file
2005 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2006 * values from/to the user buffer, treated as an ASCII string.
2007 * The values read are assumed to be in 1/1000 seconds, and
2008 * are converted into jiffies.
2010 * Returns 0 on success.
2012 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2013 void __user *buffer, size_t *lenp, loff_t *ppos)
2015 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2016 do_proc_dointvec_ms_jiffies_conv, NULL);
2019 #else /* CONFIG_PROC_FS */
2021 int proc_dostring(ctl_table *table, int write, struct file *filp,
2022 void __user *buffer, size_t *lenp, loff_t *ppos)
2027 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2028 void __user *buffer, size_t *lenp, loff_t *ppos)
2033 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2034 void __user *buffer, size_t *lenp, loff_t *ppos)
2039 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2040 void __user *buffer, size_t *lenp, loff_t *ppos)
2045 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2046 void __user *buffer, size_t *lenp, loff_t *ppos)
2051 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2052 void __user *buffer, size_t *lenp, loff_t *ppos)
2057 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2058 void __user *buffer, size_t *lenp, loff_t *ppos)
2063 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2064 void __user *buffer, size_t *lenp, loff_t *ppos)
2069 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2070 void __user *buffer, size_t *lenp, loff_t *ppos)
2075 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2077 void __user *buffer,
2078 size_t *lenp, loff_t *ppos)
2084 #endif /* CONFIG_PROC_FS */
2088 * General sysctl support routines
2091 /* The generic string strategy routine: */
2092 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2093 void __user *oldval, size_t __user *oldlenp,
2094 void __user *newval, size_t newlen, void **context)
2098 if (!table->data || !table->maxlen)
2101 if (oldval && oldlenp) {
2102 if (get_user(len, oldlenp))
2105 l = strlen(table->data);
2106 if (len > l) len = l;
2107 if (len >= table->maxlen)
2108 len = table->maxlen;
2109 if(copy_to_user(oldval, table->data, len))
2111 if(put_user(0, ((char __user *) oldval) + len))
2113 if(put_user(len, oldlenp))
2117 if (newval && newlen) {
2119 if (len > table->maxlen)
2120 len = table->maxlen;
2121 if(copy_from_user(table->data, newval, len))
2123 if (len == table->maxlen)
2125 ((char *) table->data)[len] = 0;
2131 * This function makes sure that all of the integers in the vector
2132 * are between the minimum and maximum values given in the arrays
2133 * table->extra1 and table->extra2, respectively.
2135 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2136 void __user *oldval, size_t __user *oldlenp,
2137 void __user *newval, size_t newlen, void **context)
2140 if (newval && newlen) {
2141 int __user *vec = (int __user *) newval;
2142 int *min = (int *) table->extra1;
2143 int *max = (int *) table->extra2;
2147 if (newlen % sizeof(int) != 0)
2150 if (!table->extra1 && !table->extra2)
2153 if (newlen > table->maxlen)
2154 newlen = table->maxlen;
2155 length = newlen / sizeof(int);
2157 for (i = 0; i < length; i++) {
2159 if (get_user(value, vec + i))
2161 if (min && value < min[i])
2163 if (max && value > max[i])
2170 /* Strategy function to convert jiffies to seconds */
2171 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2172 void __user *oldval, size_t __user *oldlenp,
2173 void __user *newval, size_t newlen, void **context)
2178 if (get_user(olen, oldlenp))
2180 if (olen!=sizeof(int))
2183 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2184 (oldlenp && put_user(sizeof(int),oldlenp)))
2187 if (newval && newlen) {
2189 if (newlen != sizeof(int))
2191 if (get_user(new, (int __user *)newval))
2193 *(int *)(table->data) = new*HZ;
2198 /* Strategy function to convert jiffies to seconds */
2199 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2200 void __user *oldval, size_t __user *oldlenp,
2201 void __user *newval, size_t newlen, void **context)
2206 if (get_user(olen, oldlenp))
2208 if (olen!=sizeof(int))
2211 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2212 (oldlenp && put_user(sizeof(int),oldlenp)))
2215 if (newval && newlen) {
2217 if (newlen != sizeof(int))
2219 if (get_user(new, (int __user *)newval))
2221 *(int *)(table->data) = msecs_to_jiffies(new);
2226 #else /* CONFIG_SYSCTL */
2229 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2234 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2235 void __user *oldval, size_t __user *oldlenp,
2236 void __user *newval, size_t newlen, void **context)
2241 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2242 void __user *oldval, size_t __user *oldlenp,
2243 void __user *newval, size_t newlen, void **context)
2248 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2249 void __user *oldval, size_t __user *oldlenp,
2250 void __user *newval, size_t newlen, void **context)
2255 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2256 void __user *oldval, size_t __user *oldlenp,
2257 void __user *newval, size_t newlen, void **context)
2262 int proc_dostring(ctl_table *table, int write, struct file *filp,
2263 void __user *buffer, size_t *lenp, loff_t *ppos)
2268 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2269 void __user *buffer, size_t *lenp, loff_t *ppos)
2274 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2275 void __user *buffer, size_t *lenp, loff_t *ppos)
2280 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2281 void __user *buffer, size_t *lenp, loff_t *ppos)
2286 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2287 void __user *buffer, size_t *lenp, loff_t *ppos)
2292 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2293 void __user *buffer, size_t *lenp, loff_t *ppos)
2298 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2299 void __user *buffer, size_t *lenp, loff_t *ppos)
2304 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2310 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2312 void __user *buffer,
2313 size_t *lenp, loff_t *ppos)
2318 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2324 void unregister_sysctl_table(struct ctl_table_header * table)
2328 #endif /* CONFIG_SYSCTL */
2331 * No sense putting this after each symbol definition, twice,
2332 * exception granted :-)
2334 EXPORT_SYMBOL(proc_dointvec);
2335 EXPORT_SYMBOL(proc_dointvec_jiffies);
2336 EXPORT_SYMBOL(proc_dointvec_minmax);
2337 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2338 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2339 EXPORT_SYMBOL(proc_dostring);
2340 EXPORT_SYMBOL(proc_doulongvec_minmax);
2341 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2342 EXPORT_SYMBOL(register_sysctl_table);
2343 EXPORT_SYMBOL(sysctl_intvec);
2344 EXPORT_SYMBOL(sysctl_jiffies);
2345 EXPORT_SYMBOL(sysctl_ms_jiffies);
2346 EXPORT_SYMBOL(sysctl_string);
2347 EXPORT_SYMBOL(unregister_sysctl_table);