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;
71 extern int inotify_max_user_devices;
72 extern int inotify_max_user_watches;
73 extern int inotify_max_queued_events;
76 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
77 int unknown_nmi_panic;
78 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
79 void __user *, size_t *, loff_t *);
82 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83 static int maxolduid = 65535;
86 static int ngroups_max = NGROUPS_MAX;
89 extern char modprobe_path[];
92 extern char hotplug_path[];
94 #ifdef CONFIG_CHR_DEV_SG
95 extern int sg_big_buff;
98 extern size_t shm_ctlmax;
99 extern size_t shm_ctlall;
100 extern int shm_ctlmni;
101 extern int msg_ctlmax;
102 extern int msg_ctlmnb;
103 extern int msg_ctlmni;
104 extern int sem_ctls[];
108 extern char reboot_command [];
109 extern int stop_a_enabled;
110 extern int scons_pwroff;
114 extern int pwrsw_enabled;
115 extern int unaligned_enabled;
118 #ifdef CONFIG_ARCH_S390
119 #ifdef CONFIG_MATHEMU
120 extern int sysctl_ieee_emulation_warnings;
122 extern int sysctl_userprocess_debug;
125 extern int sysctl_hz_timer;
127 #ifdef CONFIG_BSD_PROCESS_ACCT
128 extern int acct_parm[];
131 int randomize_va_space = 1;
133 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
134 ctl_table *, void **);
135 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
136 void __user *buffer, size_t *lenp, loff_t *ppos);
138 static ctl_table root_table[];
139 static struct ctl_table_header root_table_header =
140 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
142 static ctl_table kern_table[];
143 static ctl_table vm_table[];
145 extern ctl_table net_table[];
147 static ctl_table proc_table[];
148 static ctl_table fs_table[];
149 static ctl_table debug_table[];
150 static ctl_table dev_table[];
151 extern ctl_table random_table[];
152 #ifdef CONFIG_UNIX98_PTYS
153 extern ctl_table pty_table[];
156 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
157 int sysctl_legacy_va_layout;
160 /* /proc declarations: */
162 #ifdef CONFIG_PROC_FS
164 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
165 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
166 static int proc_opensys(struct inode *, struct file *);
168 struct file_operations proc_sys_file_operations = {
169 .open = proc_opensys,
170 .read = proc_readsys,
171 .write = proc_writesys,
174 extern struct proc_dir_entry *proc_sys_root;
176 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
177 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
180 /* The default sysctl tables: */
182 static ctl_table root_table[] = {
184 .ctl_name = CTL_KERN,
185 .procname = "kernel",
204 .ctl_name = CTL_PROC,
216 .ctl_name = CTL_DEBUG,
219 .child = debug_table,
231 static ctl_table kern_table[] = {
233 .ctl_name = KERN_OSTYPE,
234 .procname = "ostype",
235 .data = system_utsname.sysname,
236 .maxlen = sizeof(system_utsname.sysname),
238 .proc_handler = &proc_doutsstring,
239 .strategy = &sysctl_string,
242 .ctl_name = KERN_OSRELEASE,
243 .procname = "osrelease",
244 .data = system_utsname.release,
245 .maxlen = sizeof(system_utsname.release),
247 .proc_handler = &proc_doutsstring,
248 .strategy = &sysctl_string,
251 .ctl_name = KERN_VERSION,
252 .procname = "version",
253 .data = system_utsname.version,
254 .maxlen = sizeof(system_utsname.version),
256 .proc_handler = &proc_doutsstring,
257 .strategy = &sysctl_string,
260 .ctl_name = KERN_NODENAME,
261 .procname = "hostname",
262 .data = system_utsname.nodename,
263 .maxlen = sizeof(system_utsname.nodename),
265 .proc_handler = &proc_doutsstring,
266 .strategy = &sysctl_string,
269 .ctl_name = KERN_DOMAINNAME,
270 .procname = "domainname",
271 .data = system_utsname.domainname,
272 .maxlen = sizeof(system_utsname.domainname),
274 .proc_handler = &proc_doutsstring,
275 .strategy = &sysctl_string,
278 .ctl_name = KERN_PANIC,
280 .data = &panic_timeout,
281 .maxlen = sizeof(int),
283 .proc_handler = &proc_dointvec,
286 .ctl_name = KERN_CORE_USES_PID,
287 .procname = "core_uses_pid",
288 .data = &core_uses_pid,
289 .maxlen = sizeof(int),
291 .proc_handler = &proc_dointvec,
294 .ctl_name = KERN_CORE_PATTERN,
295 .procname = "core_pattern",
296 .data = core_pattern,
299 .proc_handler = &proc_dostring,
300 .strategy = &sysctl_string,
303 .ctl_name = KERN_TAINTED,
304 .procname = "tainted",
306 .maxlen = sizeof(int),
308 .proc_handler = &proc_dointvec,
311 .ctl_name = KERN_CAP_BSET,
312 .procname = "cap-bound",
314 .maxlen = sizeof(kernel_cap_t),
316 .proc_handler = &proc_dointvec_bset,
318 #ifdef CONFIG_BLK_DEV_INITRD
320 .ctl_name = KERN_REALROOTDEV,
321 .procname = "real-root-dev",
322 .data = &real_root_dev,
323 .maxlen = sizeof(int),
325 .proc_handler = &proc_dointvec,
330 .ctl_name = KERN_SPARC_REBOOT,
331 .procname = "reboot-cmd",
332 .data = reboot_command,
335 .proc_handler = &proc_dostring,
336 .strategy = &sysctl_string,
339 .ctl_name = KERN_SPARC_STOP_A,
340 .procname = "stop-a",
341 .data = &stop_a_enabled,
342 .maxlen = sizeof (int),
344 .proc_handler = &proc_dointvec,
347 .ctl_name = KERN_SPARC_SCONS_PWROFF,
348 .procname = "scons-poweroff",
349 .data = &scons_pwroff,
350 .maxlen = sizeof (int),
352 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_HPPA_PWRSW,
358 .procname = "soft-power",
359 .data = &pwrsw_enabled,
360 .maxlen = sizeof (int),
362 .proc_handler = &proc_dointvec,
365 .ctl_name = KERN_HPPA_UNALIGNED,
366 .procname = "unaligned-trap",
367 .data = &unaligned_enabled,
368 .maxlen = sizeof (int),
370 .proc_handler = &proc_dointvec,
374 .ctl_name = KERN_CTLALTDEL,
375 .procname = "ctrl-alt-del",
377 .maxlen = sizeof(int),
379 .proc_handler = &proc_dointvec,
382 .ctl_name = KERN_PRINTK,
383 .procname = "printk",
384 .data = &console_loglevel,
385 .maxlen = 4*sizeof(int),
387 .proc_handler = &proc_dointvec,
391 .ctl_name = KERN_MODPROBE,
392 .procname = "modprobe",
393 .data = &modprobe_path,
394 .maxlen = KMOD_PATH_LEN,
396 .proc_handler = &proc_dostring,
397 .strategy = &sysctl_string,
400 #ifdef CONFIG_HOTPLUG
402 .ctl_name = KERN_HOTPLUG,
403 .procname = "hotplug",
404 .data = &hotplug_path,
405 .maxlen = HOTPLUG_PATH_LEN,
407 .proc_handler = &proc_dostring,
408 .strategy = &sysctl_string,
411 #ifdef CONFIG_CHR_DEV_SG
413 .ctl_name = KERN_SG_BIG_BUFF,
414 .procname = "sg-big-buff",
415 .data = &sg_big_buff,
416 .maxlen = sizeof (int),
418 .proc_handler = &proc_dointvec,
421 #ifdef CONFIG_BSD_PROCESS_ACCT
423 .ctl_name = KERN_ACCT,
426 .maxlen = 3*sizeof(int),
428 .proc_handler = &proc_dointvec,
431 #ifdef CONFIG_SYSVIPC
433 .ctl_name = KERN_SHMMAX,
434 .procname = "shmmax",
436 .maxlen = sizeof (size_t),
438 .proc_handler = &proc_doulongvec_minmax,
441 .ctl_name = KERN_SHMALL,
442 .procname = "shmall",
444 .maxlen = sizeof (size_t),
446 .proc_handler = &proc_doulongvec_minmax,
449 .ctl_name = KERN_SHMMNI,
450 .procname = "shmmni",
452 .maxlen = sizeof (int),
454 .proc_handler = &proc_dointvec,
457 .ctl_name = KERN_MSGMAX,
458 .procname = "msgmax",
460 .maxlen = sizeof (int),
462 .proc_handler = &proc_dointvec,
465 .ctl_name = KERN_MSGMNI,
466 .procname = "msgmni",
468 .maxlen = sizeof (int),
470 .proc_handler = &proc_dointvec,
473 .ctl_name = KERN_MSGMNB,
474 .procname = "msgmnb",
476 .maxlen = sizeof (int),
478 .proc_handler = &proc_dointvec,
481 .ctl_name = KERN_SEM,
484 .maxlen = 4*sizeof (int),
486 .proc_handler = &proc_dointvec,
489 #ifdef CONFIG_MAGIC_SYSRQ
491 .ctl_name = KERN_SYSRQ,
493 .data = &sysrq_enabled,
494 .maxlen = sizeof (int),
496 .proc_handler = &proc_dointvec,
500 .ctl_name = KERN_CADPID,
501 .procname = "cad_pid",
503 .maxlen = sizeof (int),
505 .proc_handler = &proc_dointvec,
508 .ctl_name = KERN_MAX_THREADS,
509 .procname = "threads-max",
510 .data = &max_threads,
511 .maxlen = sizeof(int),
513 .proc_handler = &proc_dointvec,
516 .ctl_name = KERN_RANDOM,
517 .procname = "random",
519 .child = random_table,
521 #ifdef CONFIG_UNIX98_PTYS
523 .ctl_name = KERN_PTY,
530 .ctl_name = KERN_OVERFLOWUID,
531 .procname = "overflowuid",
532 .data = &overflowuid,
533 .maxlen = sizeof(int),
535 .proc_handler = &proc_dointvec_minmax,
536 .strategy = &sysctl_intvec,
537 .extra1 = &minolduid,
538 .extra2 = &maxolduid,
541 .ctl_name = KERN_OVERFLOWGID,
542 .procname = "overflowgid",
543 .data = &overflowgid,
544 .maxlen = sizeof(int),
546 .proc_handler = &proc_dointvec_minmax,
547 .strategy = &sysctl_intvec,
548 .extra1 = &minolduid,
549 .extra2 = &maxolduid,
551 #ifdef CONFIG_ARCH_S390
552 #ifdef CONFIG_MATHEMU
554 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
555 .procname = "ieee_emulation_warnings",
556 .data = &sysctl_ieee_emulation_warnings,
557 .maxlen = sizeof(int),
559 .proc_handler = &proc_dointvec,
562 #ifdef CONFIG_NO_IDLE_HZ
564 .ctl_name = KERN_HZ_TIMER,
565 .procname = "hz_timer",
566 .data = &sysctl_hz_timer,
567 .maxlen = sizeof(int),
569 .proc_handler = &proc_dointvec,
573 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
574 .procname = "userprocess_debug",
575 .data = &sysctl_userprocess_debug,
576 .maxlen = sizeof(int),
578 .proc_handler = &proc_dointvec,
582 .ctl_name = KERN_PIDMAX,
583 .procname = "pid_max",
585 .maxlen = sizeof (int),
587 .proc_handler = &proc_dointvec_minmax,
588 .strategy = sysctl_intvec,
589 .extra1 = &pid_max_min,
590 .extra2 = &pid_max_max,
593 .ctl_name = KERN_PANIC_ON_OOPS,
594 .procname = "panic_on_oops",
595 .data = &panic_on_oops,
596 .maxlen = sizeof(int),
598 .proc_handler = &proc_dointvec,
601 .ctl_name = KERN_PRINTK_RATELIMIT,
602 .procname = "printk_ratelimit",
603 .data = &printk_ratelimit_jiffies,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec_jiffies,
607 .strategy = &sysctl_jiffies,
610 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
611 .procname = "printk_ratelimit_burst",
612 .data = &printk_ratelimit_burst,
613 .maxlen = sizeof(int),
615 .proc_handler = &proc_dointvec,
618 .ctl_name = KERN_NGROUPS_MAX,
619 .procname = "ngroups_max",
620 .data = &ngroups_max,
621 .maxlen = sizeof (int),
623 .proc_handler = &proc_dointvec,
625 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
627 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
628 .procname = "unknown_nmi_panic",
629 .data = &unknown_nmi_panic,
630 .maxlen = sizeof (int),
632 .proc_handler = &proc_unknown_nmi_panic,
635 #if defined(CONFIG_X86)
637 .ctl_name = KERN_BOOTLOADER_TYPE,
638 .procname = "bootloader_type",
639 .data = &bootloader_type,
640 .maxlen = sizeof (int),
642 .proc_handler = &proc_dointvec,
646 .ctl_name = KERN_RANDOMIZE,
647 .procname = "randomize_va_space",
648 .data = &randomize_va_space,
649 .maxlen = sizeof(int),
651 .proc_handler = &proc_dointvec,
657 /* Constants for minimum and maximum testing in vm_table.
658 We use these as one-element integer vectors. */
660 static int one_hundred = 100;
663 static ctl_table vm_table[] = {
665 .ctl_name = VM_OVERCOMMIT_MEMORY,
666 .procname = "overcommit_memory",
667 .data = &sysctl_overcommit_memory,
668 .maxlen = sizeof(sysctl_overcommit_memory),
670 .proc_handler = &proc_dointvec,
673 .ctl_name = VM_OVERCOMMIT_RATIO,
674 .procname = "overcommit_ratio",
675 .data = &sysctl_overcommit_ratio,
676 .maxlen = sizeof(sysctl_overcommit_ratio),
678 .proc_handler = &proc_dointvec,
681 .ctl_name = VM_PAGE_CLUSTER,
682 .procname = "page-cluster",
683 .data = &page_cluster,
684 .maxlen = sizeof(int),
686 .proc_handler = &proc_dointvec,
689 .ctl_name = VM_DIRTY_BACKGROUND,
690 .procname = "dirty_background_ratio",
691 .data = &dirty_background_ratio,
692 .maxlen = sizeof(dirty_background_ratio),
694 .proc_handler = &proc_dointvec_minmax,
695 .strategy = &sysctl_intvec,
697 .extra2 = &one_hundred,
700 .ctl_name = VM_DIRTY_RATIO,
701 .procname = "dirty_ratio",
702 .data = &vm_dirty_ratio,
703 .maxlen = sizeof(vm_dirty_ratio),
705 .proc_handler = &proc_dointvec_minmax,
706 .strategy = &sysctl_intvec,
708 .extra2 = &one_hundred,
711 .ctl_name = VM_DIRTY_WB_CS,
712 .procname = "dirty_writeback_centisecs",
713 .data = &dirty_writeback_centisecs,
714 .maxlen = sizeof(dirty_writeback_centisecs),
716 .proc_handler = &dirty_writeback_centisecs_handler,
719 .ctl_name = VM_DIRTY_EXPIRE_CS,
720 .procname = "dirty_expire_centisecs",
721 .data = &dirty_expire_centisecs,
722 .maxlen = sizeof(dirty_expire_centisecs),
724 .proc_handler = &proc_dointvec,
727 .ctl_name = VM_NR_PDFLUSH_THREADS,
728 .procname = "nr_pdflush_threads",
729 .data = &nr_pdflush_threads,
730 .maxlen = sizeof nr_pdflush_threads,
731 .mode = 0444 /* read-only*/,
732 .proc_handler = &proc_dointvec,
735 .ctl_name = VM_SWAPPINESS,
736 .procname = "swappiness",
737 .data = &vm_swappiness,
738 .maxlen = sizeof(vm_swappiness),
740 .proc_handler = &proc_dointvec_minmax,
741 .strategy = &sysctl_intvec,
743 .extra2 = &one_hundred,
745 #ifdef CONFIG_HUGETLB_PAGE
747 .ctl_name = VM_HUGETLB_PAGES,
748 .procname = "nr_hugepages",
749 .data = &max_huge_pages,
750 .maxlen = sizeof(unsigned long),
752 .proc_handler = &hugetlb_sysctl_handler,
753 .extra1 = (void *)&hugetlb_zero,
754 .extra2 = (void *)&hugetlb_infinity,
757 .ctl_name = VM_HUGETLB_GROUP,
758 .procname = "hugetlb_shm_group",
759 .data = &sysctl_hugetlb_shm_group,
760 .maxlen = sizeof(gid_t),
762 .proc_handler = &proc_dointvec,
766 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
767 .procname = "lowmem_reserve_ratio",
768 .data = &sysctl_lowmem_reserve_ratio,
769 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
771 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
772 .strategy = &sysctl_intvec,
775 .ctl_name = VM_MIN_FREE_KBYTES,
776 .procname = "min_free_kbytes",
777 .data = &min_free_kbytes,
778 .maxlen = sizeof(min_free_kbytes),
780 .proc_handler = &min_free_kbytes_sysctl_handler,
781 .strategy = &sysctl_intvec,
786 .ctl_name = VM_MAX_MAP_COUNT,
787 .procname = "max_map_count",
788 .data = &sysctl_max_map_count,
789 .maxlen = sizeof(sysctl_max_map_count),
791 .proc_handler = &proc_dointvec
795 .ctl_name = VM_LAPTOP_MODE,
796 .procname = "laptop_mode",
797 .data = &laptop_mode,
798 .maxlen = sizeof(laptop_mode),
800 .proc_handler = &proc_dointvec,
801 .strategy = &sysctl_intvec,
805 .ctl_name = VM_BLOCK_DUMP,
806 .procname = "block_dump",
808 .maxlen = sizeof(block_dump),
810 .proc_handler = &proc_dointvec,
811 .strategy = &sysctl_intvec,
815 .ctl_name = VM_VFS_CACHE_PRESSURE,
816 .procname = "vfs_cache_pressure",
817 .data = &sysctl_vfs_cache_pressure,
818 .maxlen = sizeof(sysctl_vfs_cache_pressure),
820 .proc_handler = &proc_dointvec,
821 .strategy = &sysctl_intvec,
824 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
826 .ctl_name = VM_LEGACY_VA_LAYOUT,
827 .procname = "legacy_va_layout",
828 .data = &sysctl_legacy_va_layout,
829 .maxlen = sizeof(sysctl_legacy_va_layout),
831 .proc_handler = &proc_dointvec,
832 .strategy = &sysctl_intvec,
838 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
839 .procname = "swap_token_timeout",
840 .data = &swap_token_default_timeout,
841 .maxlen = sizeof(swap_token_default_timeout),
843 .proc_handler = &proc_dointvec_jiffies,
844 .strategy = &sysctl_jiffies,
850 static ctl_table proc_table[] = {
854 static ctl_table fs_table[] = {
856 .ctl_name = FS_NRINODE,
857 .procname = "inode-nr",
858 .data = &inodes_stat,
859 .maxlen = 2*sizeof(int),
861 .proc_handler = &proc_dointvec,
864 .ctl_name = FS_STATINODE,
865 .procname = "inode-state",
866 .data = &inodes_stat,
867 .maxlen = 7*sizeof(int),
869 .proc_handler = &proc_dointvec,
872 .ctl_name = FS_NRFILE,
873 .procname = "file-nr",
875 .maxlen = 3*sizeof(int),
877 .proc_handler = &proc_dointvec,
880 .ctl_name = FS_MAXFILE,
881 .procname = "file-max",
882 .data = &files_stat.max_files,
883 .maxlen = sizeof(int),
885 .proc_handler = &proc_dointvec,
888 .ctl_name = FS_DENTRY,
889 .procname = "dentry-state",
890 .data = &dentry_stat,
891 .maxlen = 6*sizeof(int),
893 .proc_handler = &proc_dointvec,
896 .ctl_name = FS_OVERFLOWUID,
897 .procname = "overflowuid",
898 .data = &fs_overflowuid,
899 .maxlen = sizeof(int),
901 .proc_handler = &proc_dointvec_minmax,
902 .strategy = &sysctl_intvec,
903 .extra1 = &minolduid,
904 .extra2 = &maxolduid,
907 .ctl_name = FS_OVERFLOWGID,
908 .procname = "overflowgid",
909 .data = &fs_overflowgid,
910 .maxlen = sizeof(int),
912 .proc_handler = &proc_dointvec_minmax,
913 .strategy = &sysctl_intvec,
914 .extra1 = &minolduid,
915 .extra2 = &maxolduid,
918 .ctl_name = FS_LEASES,
919 .procname = "leases-enable",
920 .data = &leases_enable,
921 .maxlen = sizeof(int),
923 .proc_handler = &proc_dointvec,
925 #ifdef CONFIG_DNOTIFY
927 .ctl_name = FS_DIR_NOTIFY,
928 .procname = "dir-notify-enable",
929 .data = &dir_notify_enable,
930 .maxlen = sizeof(int),
932 .proc_handler = &proc_dointvec,
937 .ctl_name = FS_LEASE_TIME,
938 .procname = "lease-break-time",
939 .data = &lease_break_time,
940 .maxlen = sizeof(int),
942 .proc_handler = &proc_dointvec,
945 .ctl_name = FS_AIO_NR,
946 .procname = "aio-nr",
948 .maxlen = sizeof(aio_nr),
950 .proc_handler = &proc_dointvec,
953 .ctl_name = FS_AIO_MAX_NR,
954 .procname = "aio-max-nr",
956 .maxlen = sizeof(aio_max_nr),
958 .proc_handler = &proc_dointvec,
962 .ctl_name = KERN_SETUID_DUMPABLE,
963 .procname = "suid_dumpable",
964 .data = &suid_dumpable,
965 .maxlen = sizeof(int),
967 .proc_handler = &proc_dointvec,
969 #ifdef CONFIG_INOTIFY
971 .ctl_name = INOTIFY_MAX_USER_DEVICES,
972 .procname = "max_user_devices",
973 .data = &inotify_max_user_devices,
974 .maxlen = sizeof(int),
976 .proc_handler = &proc_dointvec_minmax,
977 .strategy = &sysctl_intvec,
982 .ctl_name = INOTIFY_MAX_USER_WATCHES,
983 .procname = "max_user_watches",
984 .data = &inotify_max_user_watches,
985 .maxlen = sizeof(int),
987 .proc_handler = &proc_dointvec_minmax,
988 .strategy = &sysctl_intvec,
993 .ctl_name = INOTIFY_MAX_QUEUED_EVENTS,
994 .procname = "max_queued_events",
995 .data = &inotify_max_queued_events,
996 .maxlen = sizeof(int),
998 .proc_handler = &proc_dointvec_minmax,
999 .strategy = &sysctl_intvec,
1006 static ctl_table debug_table[] = {
1010 static ctl_table dev_table[] = {
1014 extern void init_irq_proc (void);
1016 void __init sysctl_init(void)
1018 #ifdef CONFIG_PROC_FS
1019 register_proc_table(root_table, proc_sys_root);
1024 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1025 void __user *newval, size_t newlen)
1027 struct list_head *tmp;
1029 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1033 if (!oldlenp || get_user(old_len, oldlenp))
1036 tmp = &root_table_header.ctl_entry;
1038 struct ctl_table_header *head =
1039 list_entry(tmp, struct ctl_table_header, ctl_entry);
1040 void *context = NULL;
1041 int error = parse_table(name, nlen, oldval, oldlenp,
1042 newval, newlen, head->ctl_table,
1045 if (error != -ENOTDIR)
1048 } while (tmp != &root_table_header.ctl_entry);
1052 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1054 struct __sysctl_args tmp;
1057 if (copy_from_user(&tmp, args, sizeof(tmp)))
1061 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1062 tmp.newval, tmp.newlen);
1068 * ctl_perm does NOT grant the superuser all rights automatically, because
1069 * some sysctl variables are readonly even to root.
1072 static int test_perm(int mode, int op)
1076 else if (in_egroup_p(0))
1078 if ((mode & op & 0007) == op)
1083 static inline int ctl_perm(ctl_table *table, int op)
1086 error = security_sysctl(table, op);
1089 return test_perm(table->mode, op);
1092 static int parse_table(int __user *name, int nlen,
1093 void __user *oldval, size_t __user *oldlenp,
1094 void __user *newval, size_t newlen,
1095 ctl_table *table, void **context)
1101 if (get_user(n, name))
1103 for ( ; table->ctl_name; table++) {
1104 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1107 if (ctl_perm(table, 001))
1109 if (table->strategy) {
1110 error = table->strategy(
1113 newval, newlen, context);
1119 table = table->child;
1122 error = do_sysctl_strategy(table, name, nlen,
1124 newval, newlen, context);
1131 /* Perform the actual read/write of a sysctl table entry. */
1132 int do_sysctl_strategy (ctl_table *table,
1133 int __user *name, int nlen,
1134 void __user *oldval, size_t __user *oldlenp,
1135 void __user *newval, size_t newlen, void **context)
1144 if (ctl_perm(table, op))
1147 if (table->strategy) {
1148 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1149 newval, newlen, context);
1156 /* If there is no strategy routine, or if the strategy returns
1157 * zero, proceed with automatic r/w */
1158 if (table->data && table->maxlen) {
1159 if (oldval && oldlenp) {
1160 if (get_user(len, oldlenp))
1163 if (len > table->maxlen)
1164 len = table->maxlen;
1165 if(copy_to_user(oldval, table->data, len))
1167 if(put_user(len, oldlenp))
1171 if (newval && newlen) {
1173 if (len > table->maxlen)
1174 len = table->maxlen;
1175 if(copy_from_user(table->data, newval, len))
1183 * register_sysctl_table - register a sysctl hierarchy
1184 * @table: the top-level table structure
1185 * @insert_at_head: whether the entry should be inserted in front or at the end
1187 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1188 * array. An entry with a ctl_name of 0 terminates the table.
1190 * The members of the &ctl_table structure are used as follows:
1192 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1193 * must be unique within that level of sysctl
1195 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1196 * enter a sysctl file
1198 * data - a pointer to data for use by proc_handler
1200 * maxlen - the maximum size in bytes of the data
1202 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1204 * child - a pointer to the child sysctl table if this entry is a directory, or
1207 * proc_handler - the text handler routine (described below)
1209 * strategy - the strategy routine (described below)
1211 * de - for internal use by the sysctl routines
1213 * extra1, extra2 - extra pointers usable by the proc handler routines
1215 * Leaf nodes in the sysctl tree will be represented by a single file
1216 * under /proc; non-leaf nodes will be represented by directories.
1218 * sysctl(2) can automatically manage read and write requests through
1219 * the sysctl table. The data and maxlen fields of the ctl_table
1220 * struct enable minimal validation of the values being written to be
1221 * performed, and the mode field allows minimal authentication.
1223 * More sophisticated management can be enabled by the provision of a
1224 * strategy routine with the table entry. This will be called before
1225 * any automatic read or write of the data is performed.
1227 * The strategy routine may return
1229 * < 0 - Error occurred (error is passed to user process)
1231 * 0 - OK - proceed with automatic read or write.
1233 * > 0 - OK - read or write has been done by the strategy routine, so
1234 * return immediately.
1236 * There must be a proc_handler routine for any terminal nodes
1237 * mirrored under /proc/sys (non-terminals are handled by a built-in
1238 * directory handler). Several default handlers are available to
1239 * cover common cases -
1241 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1242 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1243 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1245 * It is the handler's job to read the input buffer from user memory
1246 * and process it. The handler should return 0 on success.
1248 * This routine returns %NULL on a failure to register, and a pointer
1249 * to the table header on success.
1251 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1254 struct ctl_table_header *tmp;
1255 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1258 tmp->ctl_table = table;
1259 INIT_LIST_HEAD(&tmp->ctl_entry);
1261 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1263 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1264 #ifdef CONFIG_PROC_FS
1265 register_proc_table(table, proc_sys_root);
1271 * unregister_sysctl_table - unregister a sysctl table hierarchy
1272 * @header: the header returned from register_sysctl_table
1274 * Unregisters the sysctl table and all children. proc entries may not
1275 * actually be removed until they are no longer used by anyone.
1277 void unregister_sysctl_table(struct ctl_table_header * header)
1279 list_del(&header->ctl_entry);
1280 #ifdef CONFIG_PROC_FS
1281 unregister_proc_table(header->ctl_table, proc_sys_root);
1290 #ifdef CONFIG_PROC_FS
1292 /* Scan the sysctl entries in table and add them all into /proc */
1293 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1295 struct proc_dir_entry *de;
1299 for (; table->ctl_name; table++) {
1300 /* Can't do anything without a proc name. */
1301 if (!table->procname)
1303 /* Maybe we can't do anything with it... */
1304 if (!table->proc_handler && !table->child) {
1305 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1310 len = strlen(table->procname);
1314 if (table->proc_handler)
1318 for (de = root->subdir; de; de = de->next) {
1319 if (proc_match(len, table->procname, de))
1322 /* If the subdir exists already, de is non-NULL */
1326 de = create_proc_entry(table->procname, mode, root);
1329 de->data = (void *) table;
1330 if (table->proc_handler)
1331 de->proc_fops = &proc_sys_file_operations;
1334 if (de->mode & S_IFDIR)
1335 register_proc_table(table->child, de);
1340 * Unregister a /proc sysctl table and any subdirectories.
1342 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1344 struct proc_dir_entry *de;
1345 for (; table->ctl_name; table++) {
1346 if (!(de = table->de))
1348 if (de->mode & S_IFDIR) {
1349 if (!table->child) {
1350 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1353 unregister_proc_table(table->child, de);
1355 /* Don't unregister directories which still have entries.. */
1360 /* Don't unregister proc entries that are still being used.. */
1361 if (atomic_read(&de->count))
1365 remove_proc_entry(table->procname, root);
1369 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1370 size_t count, loff_t *ppos)
1373 struct proc_dir_entry *de;
1374 struct ctl_table *table;
1378 de = PDE(file->f_dentry->d_inode);
1379 if (!de || !de->data)
1381 table = (struct ctl_table *) de->data;
1382 if (!table || !table->proc_handler)
1384 op = (write ? 002 : 004);
1385 if (ctl_perm(table, op))
1390 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1396 static int proc_opensys(struct inode *inode, struct file *file)
1398 if (file->f_mode & FMODE_WRITE) {
1400 * sysctl entries that are not writable,
1401 * are _NOT_ writable, capabilities or not.
1403 if (!(inode->i_mode & S_IWUSR))
1410 static ssize_t proc_readsys(struct file * file, char __user * buf,
1411 size_t count, loff_t *ppos)
1413 return do_rw_proc(0, file, buf, count, ppos);
1416 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1417 size_t count, loff_t *ppos)
1419 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1423 * proc_dostring - read a string sysctl
1424 * @table: the sysctl table
1425 * @write: %TRUE if this is a write to the sysctl file
1426 * @filp: the file structure
1427 * @buffer: the user buffer
1428 * @lenp: the size of the user buffer
1429 * @ppos: file position
1431 * Reads/writes a string from/to the user buffer. If the kernel
1432 * buffer provided is not large enough to hold the string, the
1433 * string is truncated. The copied string is %NULL-terminated.
1434 * If the string is being read by the user process, it is copied
1435 * and a newline '\n' is added. It is truncated if the buffer is
1438 * Returns 0 on success.
1440 int proc_dostring(ctl_table *table, int write, struct file *filp,
1441 void __user *buffer, size_t *lenp, loff_t *ppos)
1447 if (!table->data || !table->maxlen || !*lenp ||
1448 (*ppos && !write)) {
1456 while (len < *lenp) {
1457 if (get_user(c, p++))
1459 if (c == 0 || c == '\n')
1463 if (len >= table->maxlen)
1464 len = table->maxlen-1;
1465 if(copy_from_user(table->data, buffer, len))
1467 ((char *) table->data)[len] = 0;
1470 len = strlen(table->data);
1471 if (len > table->maxlen)
1472 len = table->maxlen;
1476 if(copy_to_user(buffer, table->data, len))
1479 if(put_user('\n', ((char __user *) buffer) + len))
1490 * Special case of dostring for the UTS structure. This has locks
1491 * to observe. Should this be in kernel/sys.c ????
1494 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1495 void __user *buffer, size_t *lenp, loff_t *ppos)
1500 down_read(&uts_sem);
1501 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1504 down_write(&uts_sem);
1505 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1511 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1513 int write, void *data)
1516 *valp = *negp ? -*lvalp : *lvalp;
1521 *lvalp = (unsigned long)-val;
1524 *lvalp = (unsigned long)val;
1530 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1531 void __user *buffer, size_t *lenp, loff_t *ppos,
1532 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1533 int write, void *data),
1536 #define TMPBUFLEN 21
1537 int *i, vleft, first=1, neg, val;
1541 char buf[TMPBUFLEN], *p;
1542 char __user *s = buffer;
1544 if (!table->data || !table->maxlen || !*lenp ||
1545 (*ppos && !write)) {
1550 i = (int *) table->data;
1551 vleft = table->maxlen / sizeof(*i);
1555 conv = do_proc_dointvec_conv;
1557 for (; left && vleft--; i++, first=0) {
1572 if (len > sizeof(buf) - 1)
1573 len = sizeof(buf) - 1;
1574 if (copy_from_user(buf, s, len))
1578 if (*p == '-' && left > 1) {
1582 if (*p < '0' || *p > '9')
1585 lval = simple_strtoul(p, &p, 0);
1588 if ((len < left) && *p && !isspace(*p))
1595 if (conv(&neg, &lval, i, 1, data))
1602 if (conv(&neg, &lval, i, 0, data))
1605 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1609 if(copy_to_user(s, buf, len))
1616 if (!write && !first && left) {
1617 if(put_user('\n', s))
1624 if (get_user(c, s++))
1640 * proc_dointvec - read a vector of integers
1641 * @table: the sysctl table
1642 * @write: %TRUE if this is a write to the sysctl file
1643 * @filp: the file structure
1644 * @buffer: the user buffer
1645 * @lenp: the size of the user buffer
1646 * @ppos: file position
1648 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1649 * values from/to the user buffer, treated as an ASCII string.
1651 * Returns 0 on success.
1653 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1654 void __user *buffer, size_t *lenp, loff_t *ppos)
1656 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1666 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1668 int write, void *data)
1670 int op = *(int *)data;
1672 int val = *negp ? -*lvalp : *lvalp;
1674 case OP_SET: *valp = val; break;
1675 case OP_AND: *valp &= val; break;
1676 case OP_OR: *valp |= val; break;
1677 case OP_MAX: if(*valp < val)
1680 case OP_MIN: if(*valp > val)
1688 *lvalp = (unsigned long)-val;
1691 *lvalp = (unsigned long)val;
1698 * init may raise the set.
1701 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1702 void __user *buffer, size_t *lenp, loff_t *ppos)
1706 if (!capable(CAP_SYS_MODULE)) {
1710 op = (current->pid == 1) ? OP_SET : OP_AND;
1711 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1712 do_proc_dointvec_bset_conv,&op);
1715 struct do_proc_dointvec_minmax_conv_param {
1720 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1722 int write, void *data)
1724 struct do_proc_dointvec_minmax_conv_param *param = data;
1726 int val = *negp ? -*lvalp : *lvalp;
1727 if ((param->min && *param->min > val) ||
1728 (param->max && *param->max < val))
1735 *lvalp = (unsigned long)-val;
1738 *lvalp = (unsigned long)val;
1745 * proc_dointvec_minmax - read a vector of integers with min/max values
1746 * @table: the sysctl table
1747 * @write: %TRUE if this is a write to the sysctl file
1748 * @filp: the file structure
1749 * @buffer: the user buffer
1750 * @lenp: the size of the user buffer
1751 * @ppos: file position
1753 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1754 * values from/to the user buffer, treated as an ASCII string.
1756 * This routine will ensure the values are within the range specified by
1757 * table->extra1 (min) and table->extra2 (max).
1759 * Returns 0 on success.
1761 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1762 void __user *buffer, size_t *lenp, loff_t *ppos)
1764 struct do_proc_dointvec_minmax_conv_param param = {
1765 .min = (int *) table->extra1,
1766 .max = (int *) table->extra2,
1768 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1769 do_proc_dointvec_minmax_conv, ¶m);
1772 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1774 void __user *buffer,
1775 size_t *lenp, loff_t *ppos,
1776 unsigned long convmul,
1777 unsigned long convdiv)
1779 #define TMPBUFLEN 21
1780 unsigned long *i, *min, *max, val;
1781 int vleft, first=1, neg;
1783 char buf[TMPBUFLEN], *p;
1784 char __user *s = buffer;
1786 if (!table->data || !table->maxlen || !*lenp ||
1787 (*ppos && !write)) {
1792 i = (unsigned long *) table->data;
1793 min = (unsigned long *) table->extra1;
1794 max = (unsigned long *) table->extra2;
1795 vleft = table->maxlen / sizeof(unsigned long);
1798 for (; left && vleft--; i++, min++, max++, first=0) {
1813 if (len > TMPBUFLEN-1)
1815 if (copy_from_user(buf, s, len))
1819 if (*p == '-' && left > 1) {
1823 if (*p < '0' || *p > '9')
1825 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1827 if ((len < left) && *p && !isspace(*p))
1836 if ((min && val < *min) || (max && val > *max))
1843 sprintf(p, "%lu", convdiv * (*i) / convmul);
1847 if(copy_to_user(s, buf, len))
1854 if (!write && !first && left) {
1855 if(put_user('\n', s))
1862 if (get_user(c, s++))
1878 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1879 * @table: the sysctl table
1880 * @write: %TRUE if this is a write to the sysctl file
1881 * @filp: the file structure
1882 * @buffer: the user buffer
1883 * @lenp: the size of the user buffer
1884 * @ppos: file position
1886 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1887 * values from/to the user buffer, treated as an ASCII string.
1889 * This routine will ensure the values are within the range specified by
1890 * table->extra1 (min) and table->extra2 (max).
1892 * Returns 0 on success.
1894 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1895 void __user *buffer, size_t *lenp, loff_t *ppos)
1897 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1901 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1902 * @table: the sysctl table
1903 * @write: %TRUE if this is a write to the sysctl file
1904 * @filp: the file structure
1905 * @buffer: the user buffer
1906 * @lenp: the size of the user buffer
1907 * @ppos: file position
1909 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1910 * values from/to the user buffer, treated as an ASCII string. The values
1911 * are treated as milliseconds, and converted to jiffies when they are stored.
1913 * This routine will ensure the values are within the range specified by
1914 * table->extra1 (min) and table->extra2 (max).
1916 * Returns 0 on success.
1918 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1920 void __user *buffer,
1921 size_t *lenp, loff_t *ppos)
1923 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1924 lenp, ppos, HZ, 1000l);
1928 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1930 int write, void *data)
1933 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1939 lval = (unsigned long)-val;
1942 lval = (unsigned long)val;
1949 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1951 int write, void *data)
1954 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1960 lval = (unsigned long)-val;
1963 lval = (unsigned long)val;
1965 *lvalp = jiffies_to_clock_t(lval);
1970 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1972 int write, void *data)
1975 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1981 lval = (unsigned long)-val;
1984 lval = (unsigned long)val;
1986 *lvalp = jiffies_to_msecs(lval);
1992 * proc_dointvec_jiffies - read a vector of integers as seconds
1993 * @table: the sysctl table
1994 * @write: %TRUE if this is a write to the sysctl file
1995 * @filp: the file structure
1996 * @buffer: the user buffer
1997 * @lenp: the size of the user buffer
1998 * @ppos: file position
2000 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2001 * values from/to the user buffer, treated as an ASCII string.
2002 * The values read are assumed to be in seconds, and are converted into
2005 * Returns 0 on success.
2007 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2008 void __user *buffer, size_t *lenp, loff_t *ppos)
2010 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2011 do_proc_dointvec_jiffies_conv,NULL);
2015 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2016 * @table: the sysctl table
2017 * @write: %TRUE if this is a write to the sysctl file
2018 * @filp: the file structure
2019 * @buffer: the user buffer
2020 * @lenp: the size of the user buffer
2022 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2023 * values from/to the user buffer, treated as an ASCII string.
2024 * The values read are assumed to be in 1/USER_HZ seconds, and
2025 * are converted into jiffies.
2027 * Returns 0 on success.
2029 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2030 void __user *buffer, size_t *lenp, loff_t *ppos)
2032 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2033 do_proc_dointvec_userhz_jiffies_conv,NULL);
2037 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2038 * @table: the sysctl table
2039 * @write: %TRUE if this is a write to the sysctl file
2040 * @filp: the file structure
2041 * @buffer: the user buffer
2042 * @lenp: the size of the user buffer
2043 * @ppos: file position
2044 * @ppos: the current position in the file
2046 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2047 * values from/to the user buffer, treated as an ASCII string.
2048 * The values read are assumed to be in 1/1000 seconds, and
2049 * are converted into jiffies.
2051 * Returns 0 on success.
2053 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2054 void __user *buffer, size_t *lenp, loff_t *ppos)
2056 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2057 do_proc_dointvec_ms_jiffies_conv, NULL);
2060 #else /* CONFIG_PROC_FS */
2062 int proc_dostring(ctl_table *table, int write, struct file *filp,
2063 void __user *buffer, size_t *lenp, loff_t *ppos)
2068 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2069 void __user *buffer, size_t *lenp, loff_t *ppos)
2074 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2075 void __user *buffer, size_t *lenp, loff_t *ppos)
2080 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2081 void __user *buffer, size_t *lenp, loff_t *ppos)
2086 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2087 void __user *buffer, size_t *lenp, loff_t *ppos)
2092 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2093 void __user *buffer, size_t *lenp, loff_t *ppos)
2098 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2099 void __user *buffer, size_t *lenp, loff_t *ppos)
2104 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2105 void __user *buffer, size_t *lenp, loff_t *ppos)
2110 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2111 void __user *buffer, size_t *lenp, loff_t *ppos)
2116 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2118 void __user *buffer,
2119 size_t *lenp, loff_t *ppos)
2125 #endif /* CONFIG_PROC_FS */
2129 * General sysctl support routines
2132 /* The generic string strategy routine: */
2133 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2134 void __user *oldval, size_t __user *oldlenp,
2135 void __user *newval, size_t newlen, void **context)
2139 if (!table->data || !table->maxlen)
2142 if (oldval && oldlenp) {
2143 if (get_user(len, oldlenp))
2146 l = strlen(table->data);
2147 if (len > l) len = l;
2148 if (len >= table->maxlen)
2149 len = table->maxlen;
2150 if(copy_to_user(oldval, table->data, len))
2152 if(put_user(0, ((char __user *) oldval) + len))
2154 if(put_user(len, oldlenp))
2158 if (newval && newlen) {
2160 if (len > table->maxlen)
2161 len = table->maxlen;
2162 if(copy_from_user(table->data, newval, len))
2164 if (len == table->maxlen)
2166 ((char *) table->data)[len] = 0;
2172 * This function makes sure that all of the integers in the vector
2173 * are between the minimum and maximum values given in the arrays
2174 * table->extra1 and table->extra2, respectively.
2176 int sysctl_intvec(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)
2181 if (newval && newlen) {
2182 int __user *vec = (int __user *) newval;
2183 int *min = (int *) table->extra1;
2184 int *max = (int *) table->extra2;
2188 if (newlen % sizeof(int) != 0)
2191 if (!table->extra1 && !table->extra2)
2194 if (newlen > table->maxlen)
2195 newlen = table->maxlen;
2196 length = newlen / sizeof(int);
2198 for (i = 0; i < length; i++) {
2200 if (get_user(value, vec + i))
2202 if (min && value < min[i])
2204 if (max && value > max[i])
2211 /* Strategy function to convert jiffies to seconds */
2212 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2213 void __user *oldval, size_t __user *oldlenp,
2214 void __user *newval, size_t newlen, void **context)
2219 if (get_user(olen, oldlenp))
2221 if (olen!=sizeof(int))
2224 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2225 (oldlenp && put_user(sizeof(int),oldlenp)))
2228 if (newval && newlen) {
2230 if (newlen != sizeof(int))
2232 if (get_user(new, (int __user *)newval))
2234 *(int *)(table->data) = new*HZ;
2239 /* Strategy function to convert jiffies to seconds */
2240 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2241 void __user *oldval, size_t __user *oldlenp,
2242 void __user *newval, size_t newlen, void **context)
2247 if (get_user(olen, oldlenp))
2249 if (olen!=sizeof(int))
2252 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2253 (oldlenp && put_user(sizeof(int),oldlenp)))
2256 if (newval && newlen) {
2258 if (newlen != sizeof(int))
2260 if (get_user(new, (int __user *)newval))
2262 *(int *)(table->data) = msecs_to_jiffies(new);
2267 #else /* CONFIG_SYSCTL */
2270 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2275 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2276 void __user *oldval, size_t __user *oldlenp,
2277 void __user *newval, size_t newlen, void **context)
2282 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2283 void __user *oldval, size_t __user *oldlenp,
2284 void __user *newval, size_t newlen, void **context)
2289 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2290 void __user *oldval, size_t __user *oldlenp,
2291 void __user *newval, size_t newlen, void **context)
2296 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2297 void __user *oldval, size_t __user *oldlenp,
2298 void __user *newval, size_t newlen, void **context)
2303 int proc_dostring(ctl_table *table, int write, struct file *filp,
2304 void __user *buffer, size_t *lenp, loff_t *ppos)
2309 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2310 void __user *buffer, size_t *lenp, loff_t *ppos)
2315 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2316 void __user *buffer, size_t *lenp, loff_t *ppos)
2321 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2322 void __user *buffer, size_t *lenp, loff_t *ppos)
2327 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2328 void __user *buffer, size_t *lenp, loff_t *ppos)
2333 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2334 void __user *buffer, size_t *lenp, loff_t *ppos)
2339 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2340 void __user *buffer, size_t *lenp, loff_t *ppos)
2345 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2346 void __user *buffer, size_t *lenp, loff_t *ppos)
2351 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2353 void __user *buffer,
2354 size_t *lenp, loff_t *ppos)
2359 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2365 void unregister_sysctl_table(struct ctl_table_header * table)
2369 #endif /* CONFIG_SYSCTL */
2372 * No sense putting this after each symbol definition, twice,
2373 * exception granted :-)
2375 EXPORT_SYMBOL(proc_dointvec);
2376 EXPORT_SYMBOL(proc_dointvec_jiffies);
2377 EXPORT_SYMBOL(proc_dointvec_minmax);
2378 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2379 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2380 EXPORT_SYMBOL(proc_dostring);
2381 EXPORT_SYMBOL(proc_doulongvec_minmax);
2382 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2383 EXPORT_SYMBOL(register_sysctl_table);
2384 EXPORT_SYMBOL(sysctl_intvec);
2385 EXPORT_SYMBOL(sysctl_jiffies);
2386 EXPORT_SYMBOL(sysctl_ms_jiffies);
2387 EXPORT_SYMBOL(sysctl_string);
2388 EXPORT_SYMBOL(unregister_sysctl_table);