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>
44 #include <linux/vserver/cvirt.h>
46 #include <asm/uaccess.h>
47 #include <asm/processor.h>
49 #ifdef CONFIG_ROOT_NFS
50 #include <linux/nfs_fs.h>
53 #if defined(CONFIG_SYSCTL)
55 /* External variables not in a header file. */
57 extern int sysctl_overcommit_memory;
58 extern int sysctl_overcommit_ratio;
59 extern int max_threads;
60 extern int sysrq_enabled;
61 extern int core_uses_pid;
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 extern char vshelper_path[];
89 #ifdef CONFIG_CHR_DEV_SG
90 extern int sg_big_buff;
93 extern size_t shm_ctlmax;
94 extern size_t shm_ctlall;
95 extern int shm_ctlmni;
96 extern int msg_ctlmax;
97 extern int msg_ctlmnb;
98 extern int msg_ctlmni;
99 extern int sem_ctls[];
103 extern char reboot_command [];
104 extern int stop_a_enabled;
105 extern int scons_pwroff;
109 extern int pwrsw_enabled;
110 extern int unaligned_enabled;
113 #ifdef CONFIG_ARCH_S390
114 #ifdef CONFIG_MATHEMU
115 extern int sysctl_ieee_emulation_warnings;
117 extern int sysctl_userprocess_debug;
120 extern int sysctl_hz_timer;
122 #ifdef CONFIG_BSD_PROCESS_ACCT
123 extern int acct_parm[];
126 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
127 ctl_table *, void **);
128 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
129 void __user *buffer, size_t *lenp, loff_t *ppos);
131 static ctl_table root_table[];
132 static struct ctl_table_header root_table_header =
133 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
135 static ctl_table kern_table[];
136 static ctl_table vm_table[];
138 extern ctl_table net_table[];
140 static ctl_table proc_table[];
141 static ctl_table fs_table[];
142 static ctl_table debug_table[];
143 static ctl_table dev_table[];
144 extern ctl_table random_table[];
145 #ifdef CONFIG_UNIX98_PTYS
146 extern ctl_table pty_table[];
149 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
150 int sysctl_legacy_va_layout;
153 /* /proc declarations: */
155 #ifdef CONFIG_PROC_FS
157 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
158 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
159 static int proc_opensys(struct inode *, struct file *);
161 struct file_operations proc_sys_file_operations = {
162 .open = proc_opensys,
163 .read = proc_readsys,
164 .write = proc_writesys,
167 extern struct proc_dir_entry *proc_sys_root;
169 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
170 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
173 /* The default sysctl tables: */
175 static ctl_table root_table[] = {
177 .ctl_name = CTL_KERN,
178 .procname = "kernel",
197 .ctl_name = CTL_PROC,
209 .ctl_name = CTL_DEBUG,
212 .child = debug_table,
223 static ctl_table kern_table[] = {
225 .ctl_name = KERN_OSTYPE,
226 .procname = "ostype",
227 .data = system_utsname.sysname,
228 .maxlen = sizeof(system_utsname.sysname),
230 .proc_handler = &proc_doutsstring,
231 .virt_handler = &vx_uts_virt_handler,
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 .virt_handler = &vx_uts_virt_handler,
242 .strategy = &sysctl_string,
245 .ctl_name = KERN_VERSION,
246 .procname = "version",
247 .data = system_utsname.version,
248 .maxlen = sizeof(system_utsname.version),
250 .proc_handler = &proc_doutsstring,
251 .virt_handler = &vx_uts_virt_handler,
252 .strategy = &sysctl_string,
255 .ctl_name = KERN_NODENAME,
256 .procname = "hostname",
257 .data = system_utsname.nodename,
258 .maxlen = sizeof(system_utsname.nodename),
260 .proc_handler = &proc_doutsstring,
261 .virt_handler = &vx_uts_virt_handler,
262 .strategy = &sysctl_string,
265 .ctl_name = KERN_DOMAINNAME,
266 .procname = "domainname",
267 .data = system_utsname.domainname,
268 .maxlen = sizeof(system_utsname.domainname),
270 .proc_handler = &proc_doutsstring,
271 .virt_handler = &vx_uts_virt_handler,
272 .strategy = &sysctl_string,
275 .ctl_name = KERN_PANIC,
277 .data = &panic_timeout,
278 .maxlen = sizeof(int),
280 .proc_handler = &proc_dointvec,
283 .ctl_name = KERN_CORE_USES_PID,
284 .procname = "core_uses_pid",
285 .data = &core_uses_pid,
286 .maxlen = sizeof(int),
288 .proc_handler = &proc_dointvec,
291 .ctl_name = KERN_CORE_PATTERN,
292 .procname = "core_pattern",
293 .data = core_pattern,
296 .proc_handler = &proc_dostring,
297 .strategy = &sysctl_string,
300 .ctl_name = KERN_TAINTED,
301 .procname = "tainted",
303 .maxlen = sizeof(int),
305 .proc_handler = &proc_dointvec,
308 .ctl_name = KERN_CAP_BSET,
309 .procname = "cap-bound",
311 .maxlen = sizeof(kernel_cap_t),
313 .proc_handler = &proc_dointvec_bset,
315 #ifdef CONFIG_BLK_DEV_INITRD
317 .ctl_name = KERN_REALROOTDEV,
318 .procname = "real-root-dev",
319 .data = &real_root_dev,
320 .maxlen = sizeof(int),
322 .proc_handler = &proc_dointvec,
327 .ctl_name = KERN_SPARC_REBOOT,
328 .procname = "reboot-cmd",
329 .data = reboot_command,
332 .proc_handler = &proc_dostring,
333 .strategy = &sysctl_string,
336 .ctl_name = KERN_SPARC_STOP_A,
337 .procname = "stop-a",
338 .data = &stop_a_enabled,
339 .maxlen = sizeof (int),
341 .proc_handler = &proc_dointvec,
344 .ctl_name = KERN_SPARC_SCONS_PWROFF,
345 .procname = "scons-poweroff",
346 .data = &scons_pwroff,
347 .maxlen = sizeof (int),
349 .proc_handler = &proc_dointvec,
354 .ctl_name = KERN_HPPA_PWRSW,
355 .procname = "soft-power",
356 .data = &pwrsw_enabled,
357 .maxlen = sizeof (int),
359 .proc_handler = &proc_dointvec,
362 .ctl_name = KERN_HPPA_UNALIGNED,
363 .procname = "unaligned-trap",
364 .data = &unaligned_enabled,
365 .maxlen = sizeof (int),
367 .proc_handler = &proc_dointvec,
371 .ctl_name = KERN_CTLALTDEL,
372 .procname = "ctrl-alt-del",
374 .maxlen = sizeof(int),
376 .proc_handler = &proc_dointvec,
379 .ctl_name = KERN_PRINTK,
380 .procname = "printk",
381 .data = &console_loglevel,
382 .maxlen = 4*sizeof(int),
384 .proc_handler = &proc_dointvec,
388 .ctl_name = KERN_MODPROBE,
389 .procname = "modprobe",
390 .data = &modprobe_path,
391 .maxlen = KMOD_PATH_LEN,
393 .proc_handler = &proc_dostring,
394 .strategy = &sysctl_string,
397 #ifdef CONFIG_HOTPLUG
399 .ctl_name = KERN_HOTPLUG,
400 .procname = "hotplug",
401 .data = &hotplug_path,
402 .maxlen = HOTPLUG_PATH_LEN,
404 .proc_handler = &proc_dostring,
405 .strategy = &sysctl_string,
409 .ctl_name = KERN_VSHELPER,
410 .procname = "vshelper",
411 .data = &vshelper_path,
414 .proc_handler = &proc_dostring,
415 .strategy = &sysctl_string,
417 #ifdef CONFIG_CHR_DEV_SG
419 .ctl_name = KERN_SG_BIG_BUFF,
420 .procname = "sg-big-buff",
421 .data = &sg_big_buff,
422 .maxlen = sizeof (int),
424 .proc_handler = &proc_dointvec,
427 #ifdef CONFIG_BSD_PROCESS_ACCT
429 .ctl_name = KERN_ACCT,
432 .maxlen = 3*sizeof(int),
434 .proc_handler = &proc_dointvec,
437 #ifdef CONFIG_SYSVIPC
439 .ctl_name = KERN_SHMMAX,
440 .procname = "shmmax",
442 .maxlen = sizeof (size_t),
444 .proc_handler = &proc_doulongvec_minmax,
447 .ctl_name = KERN_SHMALL,
448 .procname = "shmall",
450 .maxlen = sizeof (size_t),
452 .proc_handler = &proc_doulongvec_minmax,
455 .ctl_name = KERN_SHMMNI,
456 .procname = "shmmni",
458 .maxlen = sizeof (int),
460 .proc_handler = &proc_dointvec,
463 .ctl_name = KERN_MSGMAX,
464 .procname = "msgmax",
466 .maxlen = sizeof (int),
468 .proc_handler = &proc_dointvec,
471 .ctl_name = KERN_MSGMNI,
472 .procname = "msgmni",
474 .maxlen = sizeof (int),
476 .proc_handler = &proc_dointvec,
479 .ctl_name = KERN_MSGMNB,
480 .procname = "msgmnb",
482 .maxlen = sizeof (int),
484 .proc_handler = &proc_dointvec,
487 .ctl_name = KERN_SEM,
490 .maxlen = 4*sizeof (int),
492 .proc_handler = &proc_dointvec,
495 #ifdef CONFIG_MAGIC_SYSRQ
497 .ctl_name = KERN_SYSRQ,
499 .data = &sysrq_enabled,
500 .maxlen = sizeof (int),
502 .proc_handler = &proc_dointvec,
506 .ctl_name = KERN_CADPID,
507 .procname = "cad_pid",
509 .maxlen = sizeof (int),
511 .proc_handler = &proc_dointvec,
514 .ctl_name = KERN_MAX_THREADS,
515 .procname = "threads-max",
516 .data = &max_threads,
517 .maxlen = sizeof(int),
519 .proc_handler = &proc_dointvec,
522 .ctl_name = KERN_RANDOM,
523 .procname = "random",
525 .child = random_table,
527 #ifdef CONFIG_UNIX98_PTYS
529 .ctl_name = KERN_PTY,
536 .ctl_name = KERN_OVERFLOWUID,
537 .procname = "overflowuid",
538 .data = &overflowuid,
539 .maxlen = sizeof(int),
541 .proc_handler = &proc_dointvec_minmax,
542 .strategy = &sysctl_intvec,
543 .extra1 = &minolduid,
544 .extra2 = &maxolduid,
547 .ctl_name = KERN_OVERFLOWGID,
548 .procname = "overflowgid",
549 .data = &overflowgid,
550 .maxlen = sizeof(int),
552 .proc_handler = &proc_dointvec_minmax,
553 .strategy = &sysctl_intvec,
554 .extra1 = &minolduid,
555 .extra2 = &maxolduid,
557 #ifdef CONFIG_ARCH_S390
558 #ifdef CONFIG_MATHEMU
560 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
561 .procname = "ieee_emulation_warnings",
562 .data = &sysctl_ieee_emulation_warnings,
563 .maxlen = sizeof(int),
565 .proc_handler = &proc_dointvec,
568 #ifdef CONFIG_NO_IDLE_HZ
570 .ctl_name = KERN_HZ_TIMER,
571 .procname = "hz_timer",
572 .data = &sysctl_hz_timer,
573 .maxlen = sizeof(int),
575 .proc_handler = &proc_dointvec,
579 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
580 .procname = "userprocess_debug",
581 .data = &sysctl_userprocess_debug,
582 .maxlen = sizeof(int),
584 .proc_handler = &proc_dointvec,
588 .ctl_name = KERN_PIDMAX,
589 .procname = "pid_max",
591 .maxlen = sizeof (int),
593 .proc_handler = &proc_dointvec_minmax,
594 .strategy = sysctl_intvec,
595 .extra1 = &pid_max_min,
596 .extra2 = &pid_max_max,
599 .ctl_name = KERN_PANIC_ON_OOPS,
600 .procname = "panic_on_oops",
601 .data = &panic_on_oops,
602 .maxlen = sizeof(int),
604 .proc_handler = &proc_dointvec,
607 .ctl_name = KERN_PRINTK_RATELIMIT,
608 .procname = "printk_ratelimit",
609 .data = &printk_ratelimit_jiffies,
610 .maxlen = sizeof(int),
612 .proc_handler = &proc_dointvec_jiffies,
613 .strategy = &sysctl_jiffies,
616 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
617 .procname = "printk_ratelimit_burst",
618 .data = &printk_ratelimit_burst,
619 .maxlen = sizeof(int),
621 .proc_handler = &proc_dointvec,
624 .ctl_name = KERN_NGROUPS_MAX,
625 .procname = "ngroups_max",
626 .data = &ngroups_max,
627 .maxlen = sizeof (int),
629 .proc_handler = &proc_dointvec,
631 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
633 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
634 .procname = "unknown_nmi_panic",
635 .data = &unknown_nmi_panic,
636 .maxlen = sizeof (int),
638 .proc_handler = &proc_unknown_nmi_panic,
641 #if defined(CONFIG_X86)
643 .ctl_name = KERN_BOOTLOADER_TYPE,
644 .procname = "bootloader_type",
645 .data = &bootloader_type,
646 .maxlen = sizeof (int),
648 .proc_handler = &proc_dointvec,
654 /* Constants for minimum and maximum testing in vm_table.
655 We use these as one-element integer vectors. */
657 static int one_hundred = 100;
660 static ctl_table vm_table[] = {
662 .ctl_name = VM_OVERCOMMIT_MEMORY,
663 .procname = "overcommit_memory",
664 .data = &sysctl_overcommit_memory,
665 .maxlen = sizeof(sysctl_overcommit_memory),
667 .proc_handler = &proc_dointvec,
670 .ctl_name = VM_OVERCOMMIT_RATIO,
671 .procname = "overcommit_ratio",
672 .data = &sysctl_overcommit_ratio,
673 .maxlen = sizeof(sysctl_overcommit_ratio),
675 .proc_handler = &proc_dointvec,
678 .ctl_name = VM_PAGE_CLUSTER,
679 .procname = "page-cluster",
680 .data = &page_cluster,
681 .maxlen = sizeof(int),
683 .proc_handler = &proc_dointvec,
686 .ctl_name = VM_DIRTY_BACKGROUND,
687 .procname = "dirty_background_ratio",
688 .data = &dirty_background_ratio,
689 .maxlen = sizeof(dirty_background_ratio),
691 .proc_handler = &proc_dointvec_minmax,
692 .strategy = &sysctl_intvec,
694 .extra2 = &one_hundred,
697 .ctl_name = VM_DIRTY_RATIO,
698 .procname = "dirty_ratio",
699 .data = &vm_dirty_ratio,
700 .maxlen = sizeof(vm_dirty_ratio),
702 .proc_handler = &proc_dointvec_minmax,
703 .strategy = &sysctl_intvec,
705 .extra2 = &one_hundred,
708 .ctl_name = VM_DIRTY_WB_CS,
709 .procname = "dirty_writeback_centisecs",
710 .data = &dirty_writeback_centisecs,
711 .maxlen = sizeof(dirty_writeback_centisecs),
713 .proc_handler = &dirty_writeback_centisecs_handler,
716 .ctl_name = VM_DIRTY_EXPIRE_CS,
717 .procname = "dirty_expire_centisecs",
718 .data = &dirty_expire_centisecs,
719 .maxlen = sizeof(dirty_expire_centisecs),
721 .proc_handler = &proc_dointvec,
724 .ctl_name = VM_NR_PDFLUSH_THREADS,
725 .procname = "nr_pdflush_threads",
726 .data = &nr_pdflush_threads,
727 .maxlen = sizeof nr_pdflush_threads,
728 .mode = 0444 /* read-only*/,
729 .proc_handler = &proc_dointvec,
732 .ctl_name = VM_SWAPPINESS,
733 .procname = "swappiness",
734 .data = &vm_swappiness,
735 .maxlen = sizeof(vm_swappiness),
737 .proc_handler = &proc_dointvec_minmax,
738 .strategy = &sysctl_intvec,
740 .extra2 = &one_hundred,
742 #ifdef CONFIG_HUGETLB_PAGE
744 .ctl_name = VM_HUGETLB_PAGES,
745 .procname = "nr_hugepages",
746 .data = &max_huge_pages,
747 .maxlen = sizeof(unsigned long),
749 .proc_handler = &hugetlb_sysctl_handler,
750 .extra1 = (void *)&hugetlb_zero,
751 .extra2 = (void *)&hugetlb_infinity,
754 .ctl_name = VM_HUGETLB_GROUP,
755 .procname = "hugetlb_shm_group",
756 .data = &sysctl_hugetlb_shm_group,
757 .maxlen = sizeof(gid_t),
759 .proc_handler = &proc_dointvec,
763 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
764 .procname = "lowmem_reserve_ratio",
765 .data = &sysctl_lowmem_reserve_ratio,
766 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
768 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
769 .strategy = &sysctl_intvec,
772 .ctl_name = VM_MIN_FREE_KBYTES,
773 .procname = "min_free_kbytes",
774 .data = &min_free_kbytes,
775 .maxlen = sizeof(min_free_kbytes),
777 .proc_handler = &min_free_kbytes_sysctl_handler,
778 .strategy = &sysctl_intvec,
783 .ctl_name = VM_MAX_MAP_COUNT,
784 .procname = "max_map_count",
785 .data = &sysctl_max_map_count,
786 .maxlen = sizeof(sysctl_max_map_count),
788 .proc_handler = &proc_dointvec
792 .ctl_name = VM_LAPTOP_MODE,
793 .procname = "laptop_mode",
794 .data = &laptop_mode,
795 .maxlen = sizeof(laptop_mode),
797 .proc_handler = &proc_dointvec,
798 .strategy = &sysctl_intvec,
802 .ctl_name = VM_BLOCK_DUMP,
803 .procname = "block_dump",
805 .maxlen = sizeof(block_dump),
807 .proc_handler = &proc_dointvec,
808 .strategy = &sysctl_intvec,
812 .ctl_name = VM_VFS_CACHE_PRESSURE,
813 .procname = "vfs_cache_pressure",
814 .data = &sysctl_vfs_cache_pressure,
815 .maxlen = sizeof(sysctl_vfs_cache_pressure),
817 .proc_handler = &proc_dointvec,
818 .strategy = &sysctl_intvec,
821 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
823 .ctl_name = VM_LEGACY_VA_LAYOUT,
824 .procname = "legacy_va_layout",
825 .data = &sysctl_legacy_va_layout,
826 .maxlen = sizeof(sysctl_legacy_va_layout),
828 .proc_handler = &proc_dointvec,
829 .strategy = &sysctl_intvec,
835 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
836 .procname = "swap_token_timeout",
837 .data = &swap_token_default_timeout,
838 .maxlen = sizeof(swap_token_default_timeout),
840 .proc_handler = &proc_dointvec_jiffies,
841 .strategy = &sysctl_jiffies,
847 static ctl_table proc_table[] = {
851 static ctl_table fs_table[] = {
853 .ctl_name = FS_NRINODE,
854 .procname = "inode-nr",
855 .data = &inodes_stat,
856 .maxlen = 2*sizeof(int),
858 .proc_handler = &proc_dointvec,
861 .ctl_name = FS_STATINODE,
862 .procname = "inode-state",
863 .data = &inodes_stat,
864 .maxlen = 7*sizeof(int),
866 .proc_handler = &proc_dointvec,
869 .ctl_name = FS_NRFILE,
870 .procname = "file-nr",
872 .maxlen = 3*sizeof(int),
874 .proc_handler = &proc_dointvec,
877 .ctl_name = FS_MAXFILE,
878 .procname = "file-max",
879 .data = &files_stat.max_files,
880 .maxlen = sizeof(int),
882 .proc_handler = &proc_dointvec,
885 .ctl_name = FS_DENTRY,
886 .procname = "dentry-state",
887 .data = &dentry_stat,
888 .maxlen = 6*sizeof(int),
890 .proc_handler = &proc_dointvec,
893 .ctl_name = FS_OVERFLOWUID,
894 .procname = "overflowuid",
895 .data = &fs_overflowuid,
896 .maxlen = sizeof(int),
898 .proc_handler = &proc_dointvec_minmax,
899 .strategy = &sysctl_intvec,
900 .extra1 = &minolduid,
901 .extra2 = &maxolduid,
904 .ctl_name = FS_OVERFLOWGID,
905 .procname = "overflowgid",
906 .data = &fs_overflowgid,
907 .maxlen = sizeof(int),
909 .proc_handler = &proc_dointvec_minmax,
910 .strategy = &sysctl_intvec,
911 .extra1 = &minolduid,
912 .extra2 = &maxolduid,
915 .ctl_name = FS_LEASES,
916 .procname = "leases-enable",
917 .data = &leases_enable,
918 .maxlen = sizeof(int),
920 .proc_handler = &proc_dointvec,
922 #ifdef CONFIG_DNOTIFY
924 .ctl_name = FS_DIR_NOTIFY,
925 .procname = "dir-notify-enable",
926 .data = &dir_notify_enable,
927 .maxlen = sizeof(int),
929 .proc_handler = &proc_dointvec,
934 .ctl_name = FS_LEASE_TIME,
935 .procname = "lease-break-time",
936 .data = &lease_break_time,
937 .maxlen = sizeof(int),
939 .proc_handler = &proc_dointvec,
942 .ctl_name = FS_AIO_NR,
943 .procname = "aio-nr",
945 .maxlen = sizeof(aio_nr),
947 .proc_handler = &proc_dointvec,
950 .ctl_name = FS_AIO_MAX_NR,
951 .procname = "aio-max-nr",
953 .maxlen = sizeof(aio_max_nr),
955 .proc_handler = &proc_dointvec,
961 static ctl_table debug_table[] = {
965 static ctl_table dev_table[] = {
969 extern void init_irq_proc (void);
971 void __init sysctl_init(void)
973 #ifdef CONFIG_PROC_FS
974 register_proc_table(root_table, proc_sys_root);
979 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
980 void __user *newval, size_t newlen)
982 struct list_head *tmp;
984 if (nlen <= 0 || nlen >= CTL_MAXNAME)
988 if (!oldlenp || get_user(old_len, oldlenp))
991 tmp = &root_table_header.ctl_entry;
993 struct ctl_table_header *head =
994 list_entry(tmp, struct ctl_table_header, ctl_entry);
995 void *context = NULL;
996 int error = parse_table(name, nlen, oldval, oldlenp,
997 newval, newlen, head->ctl_table,
1001 if (error != -ENOTDIR)
1004 } while (tmp != &root_table_header.ctl_entry);
1008 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1010 struct __sysctl_args tmp;
1013 if (copy_from_user(&tmp, args, sizeof(tmp)))
1017 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1018 tmp.newval, tmp.newlen);
1024 * ctl_perm does NOT grant the superuser all rights automatically, because
1025 * some sysctl variables are readonly even to root.
1028 static int test_perm(int mode, int op)
1032 else if (in_egroup_p(0))
1034 if ((mode & op & 0007) == op)
1039 static inline int ctl_perm(ctl_table *table, int op)
1042 error = security_sysctl(table, op);
1045 return test_perm(table->mode, op);
1048 static int parse_table(int __user *name, int nlen,
1049 void __user *oldval, size_t __user *oldlenp,
1050 void __user *newval, size_t newlen,
1051 ctl_table *table, void **context)
1057 if (get_user(n, name))
1059 for ( ; table->ctl_name; table++) {
1060 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1063 if (ctl_perm(table, 001))
1065 if (table->strategy) {
1066 error = table->strategy(
1069 newval, newlen, context);
1075 table = table->child;
1078 error = do_sysctl_strategy(table, name, nlen,
1080 newval, newlen, context);
1087 /* Perform the actual read/write of a sysctl table entry. */
1088 int do_sysctl_strategy (ctl_table *table,
1089 int __user *name, int nlen,
1090 void __user *oldval, size_t __user *oldlenp,
1091 void __user *newval, size_t newlen, void **context)
1100 if (ctl_perm(table, op))
1103 if (table->strategy) {
1104 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1105 newval, newlen, context);
1112 /* If there is no strategy routine, or if the strategy returns
1113 * zero, proceed with automatic r/w */
1114 if (table->data && table->maxlen) {
1115 if (oldval && oldlenp) {
1116 if (get_user(len, oldlenp))
1119 if (len > table->maxlen)
1120 len = table->maxlen;
1121 if(copy_to_user(oldval, table->data, len))
1123 if(put_user(len, oldlenp))
1127 if (newval && newlen) {
1129 if (len > table->maxlen)
1130 len = table->maxlen;
1131 if(copy_from_user(table->data, newval, len))
1139 * register_sysctl_table - register a sysctl hierarchy
1140 * @table: the top-level table structure
1141 * @insert_at_head: whether the entry should be inserted in front or at the end
1143 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1144 * array. An entry with a ctl_name of 0 terminates the table.
1146 * The members of the &ctl_table structure are used as follows:
1148 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1149 * must be unique within that level of sysctl
1151 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1152 * enter a sysctl file
1154 * data - a pointer to data for use by proc_handler
1156 * maxlen - the maximum size in bytes of the data
1158 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1160 * child - a pointer to the child sysctl table if this entry is a directory, or
1163 * proc_handler - the text handler routine (described below)
1165 * strategy - the strategy routine (described below)
1167 * de - for internal use by the sysctl routines
1169 * extra1, extra2 - extra pointers usable by the proc handler routines
1171 * Leaf nodes in the sysctl tree will be represented by a single file
1172 * under /proc; non-leaf nodes will be represented by directories.
1174 * sysctl(2) can automatically manage read and write requests through
1175 * the sysctl table. The data and maxlen fields of the ctl_table
1176 * struct enable minimal validation of the values being written to be
1177 * performed, and the mode field allows minimal authentication.
1179 * More sophisticated management can be enabled by the provision of a
1180 * strategy routine with the table entry. This will be called before
1181 * any automatic read or write of the data is performed.
1183 * The strategy routine may return
1185 * < 0 - Error occurred (error is passed to user process)
1187 * 0 - OK - proceed with automatic read or write.
1189 * > 0 - OK - read or write has been done by the strategy routine, so
1190 * return immediately.
1192 * There must be a proc_handler routine for any terminal nodes
1193 * mirrored under /proc/sys (non-terminals are handled by a built-in
1194 * directory handler). Several default handlers are available to
1195 * cover common cases -
1197 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1198 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1199 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1201 * It is the handler's job to read the input buffer from user memory
1202 * and process it. The handler should return 0 on success.
1204 * This routine returns %NULL on a failure to register, and a pointer
1205 * to the table header on success.
1207 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1210 struct ctl_table_header *tmp;
1211 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1214 tmp->ctl_table = table;
1215 INIT_LIST_HEAD(&tmp->ctl_entry);
1217 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1219 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1220 #ifdef CONFIG_PROC_FS
1221 register_proc_table(table, proc_sys_root);
1227 * unregister_sysctl_table - unregister a sysctl table hierarchy
1228 * @header: the header returned from register_sysctl_table
1230 * Unregisters the sysctl table and all children. proc entries may not
1231 * actually be removed until they are no longer used by anyone.
1233 void unregister_sysctl_table(struct ctl_table_header * header)
1235 list_del(&header->ctl_entry);
1236 #ifdef CONFIG_PROC_FS
1237 unregister_proc_table(header->ctl_table, proc_sys_root);
1246 #ifdef CONFIG_PROC_FS
1248 /* Scan the sysctl entries in table and add them all into /proc */
1249 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1251 struct proc_dir_entry *de;
1255 for (; table->ctl_name; table++) {
1256 /* Can't do anything without a proc name. */
1257 if (!table->procname)
1259 /* Maybe we can't do anything with it... */
1260 if (!table->proc_handler && !table->child) {
1261 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1266 len = strlen(table->procname);
1270 if (table->proc_handler)
1274 for (de = root->subdir; de; de = de->next) {
1275 if (proc_match(len, table->procname, de))
1278 /* If the subdir exists already, de is non-NULL */
1282 de = create_proc_entry(table->procname, mode, root);
1285 de->data = (void *) table;
1286 if (table->proc_handler)
1287 de->proc_fops = &proc_sys_file_operations;
1290 if (de->mode & S_IFDIR)
1291 register_proc_table(table->child, de);
1296 * Unregister a /proc sysctl table and any subdirectories.
1298 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1300 struct proc_dir_entry *de;
1301 for (; table->ctl_name; table++) {
1302 if (!(de = table->de))
1304 if (de->mode & S_IFDIR) {
1305 if (!table->child) {
1306 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1309 unregister_proc_table(table->child, de);
1311 /* Don't unregister directories which still have entries.. */
1316 /* Don't unregister proc entries that are still being used.. */
1317 if (atomic_read(&de->count))
1321 remove_proc_entry(table->procname, root);
1325 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1326 size_t count, loff_t *ppos)
1329 struct proc_dir_entry *de;
1330 struct ctl_table *table;
1334 de = PDE(file->f_dentry->d_inode);
1335 if (!de || !de->data)
1337 table = (struct ctl_table *) de->data;
1338 if (!table || !table->proc_handler)
1340 op = (write ? 002 : 004);
1341 if (ctl_perm(table, op))
1346 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1352 static int proc_opensys(struct inode *inode, struct file *file)
1354 if (file->f_mode & FMODE_WRITE) {
1356 * sysctl entries that are not writable,
1357 * are _NOT_ writable, capabilities or not.
1359 if (!(inode->i_mode & S_IWUSR))
1366 static ssize_t proc_readsys(struct file * file, char __user * buf,
1367 size_t count, loff_t *ppos)
1369 return do_rw_proc(0, file, buf, count, ppos);
1372 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1373 size_t count, loff_t *ppos)
1375 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1379 * proc_dostring - read a string sysctl
1380 * @table: the sysctl table
1381 * @write: %TRUE if this is a write to the sysctl file
1382 * @filp: the file structure
1383 * @buffer: the user buffer
1384 * @lenp: the size of the user buffer
1386 * Reads/writes a string from/to the user buffer. If the kernel
1387 * buffer provided is not large enough to hold the string, the
1388 * string is truncated. The copied string is %NULL-terminated.
1389 * If the string is being read by the user process, it is copied
1390 * and a newline '\n' is added. It is truncated if the buffer is
1393 * Returns 0 on success.
1395 int proc_dostring(ctl_table *table, int write, struct file *filp,
1396 void __user *buffer, size_t *lenp, loff_t *ppos)
1404 maxlen = table->maxlen;
1405 if (table->virt_handler)
1406 table->virt_handler(table, write, filp->f_xid, &data, &maxlen);
1408 if (!table->data || !table->maxlen || !*lenp ||
1409 (*ppos && !write)) {
1417 while (len < *lenp) {
1418 if (get_user(c, p++))
1420 if (c == 0 || c == '\n')
1426 if(copy_from_user(data, buffer, len))
1428 ((char *) data)[len] = 0;
1437 if(copy_to_user(buffer, data, len))
1440 if(put_user('\n', ((char __user *) buffer) + len))
1451 * Special case of dostring for the UTS structure. This has locks
1452 * to observe. Should this be in kernel/sys.c ????
1455 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1456 void __user *buffer, size_t *lenp, loff_t *ppos)
1461 down_read(&uts_sem);
1462 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1465 down_write(&uts_sem);
1466 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1472 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1474 int write, void *data)
1477 *valp = *negp ? -*lvalp : *lvalp;
1482 *lvalp = (unsigned long)-val;
1485 *lvalp = (unsigned long)val;
1491 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1492 void __user *buffer, size_t *lenp, loff_t *ppos,
1493 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1494 int write, void *data),
1497 #define TMPBUFLEN 21
1498 int *i, vleft, first=1, neg, val;
1502 char buf[TMPBUFLEN], *p;
1503 char __user *s = buffer;
1505 if (!table->data || !table->maxlen || !*lenp ||
1506 (*ppos && !write)) {
1511 i = (int *) table->data;
1512 vleft = table->maxlen / sizeof(*i);
1516 conv = do_proc_dointvec_conv;
1518 for (; left && vleft--; i++, first=0) {
1533 if (len > sizeof(buf) - 1)
1534 len = sizeof(buf) - 1;
1535 if (copy_from_user(buf, s, len))
1539 if (*p == '-' && left > 1) {
1543 if (*p < '0' || *p > '9')
1546 lval = simple_strtoul(p, &p, 0);
1549 if ((len < left) && *p && !isspace(*p))
1556 if (conv(&neg, &lval, i, 1, data))
1563 if (conv(&neg, &lval, i, 0, data))
1566 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1570 if(copy_to_user(s, buf, len))
1577 if (!write && !first && left) {
1578 if(put_user('\n', s))
1585 if (get_user(c, s++))
1601 * proc_dointvec - read a vector of integers
1602 * @table: the sysctl table
1603 * @write: %TRUE if this is a write to the sysctl file
1604 * @filp: the file structure
1605 * @buffer: the user buffer
1606 * @lenp: the size of the user buffer
1608 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1609 * values from/to the user buffer, treated as an ASCII string.
1611 * Returns 0 on success.
1613 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1614 void __user *buffer, size_t *lenp, loff_t *ppos)
1616 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1626 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1628 int write, void *data)
1630 int op = *(int *)data;
1632 int val = *negp ? -*lvalp : *lvalp;
1634 case OP_SET: *valp = val; break;
1635 case OP_AND: *valp &= val; break;
1636 case OP_OR: *valp |= val; break;
1637 case OP_MAX: if(*valp < val)
1640 case OP_MIN: if(*valp > val)
1648 *lvalp = (unsigned long)-val;
1651 *lvalp = (unsigned long)val;
1658 * init may raise the set.
1661 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1662 void __user *buffer, size_t *lenp, loff_t *ppos)
1666 if (!capable(CAP_SYS_MODULE)) {
1670 op = (current->pid == 1) ? OP_SET : OP_AND;
1671 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1672 do_proc_dointvec_bset_conv,&op);
1675 struct do_proc_dointvec_minmax_conv_param {
1680 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1682 int write, void *data)
1684 struct do_proc_dointvec_minmax_conv_param *param = data;
1686 int val = *negp ? -*lvalp : *lvalp;
1687 if ((param->min && *param->min > val) ||
1688 (param->max && *param->max < val))
1695 *lvalp = (unsigned long)-val;
1698 *lvalp = (unsigned long)val;
1705 * proc_dointvec_minmax - read a vector of integers with min/max values
1706 * @table: the sysctl table
1707 * @write: %TRUE if this is a write to the sysctl file
1708 * @filp: the file structure
1709 * @buffer: the user buffer
1710 * @lenp: the size of the user buffer
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
1844 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1845 * values from/to the user buffer, treated as an ASCII string.
1847 * This routine will ensure the values are within the range specified by
1848 * table->extra1 (min) and table->extra2 (max).
1850 * Returns 0 on success.
1852 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1853 void __user *buffer, size_t *lenp, loff_t *ppos)
1855 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1859 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1860 * @table: the sysctl table
1861 * @write: %TRUE if this is a write to the sysctl file
1862 * @filp: the file structure
1863 * @buffer: the user buffer
1864 * @lenp: the size of the user buffer
1866 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1867 * values from/to the user buffer, treated as an ASCII string. The values
1868 * are treated as milliseconds, and converted to jiffies when they are stored.
1870 * This routine will ensure the values are within the range specified by
1871 * table->extra1 (min) and table->extra2 (max).
1873 * Returns 0 on success.
1875 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1877 void __user *buffer,
1878 size_t *lenp, loff_t *ppos)
1880 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1881 lenp, ppos, HZ, 1000l);
1885 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1887 int write, void *data)
1890 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1896 lval = (unsigned long)-val;
1899 lval = (unsigned long)val;
1906 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1908 int write, void *data)
1911 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1917 lval = (unsigned long)-val;
1920 lval = (unsigned long)val;
1922 *lvalp = jiffies_to_clock_t(lval);
1927 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1929 int write, void *data)
1932 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1938 lval = (unsigned long)-val;
1941 lval = (unsigned long)val;
1943 *lvalp = jiffies_to_msecs(lval);
1949 * proc_dointvec_jiffies - read a vector of integers as seconds
1950 * @table: the sysctl table
1951 * @write: %TRUE if this is a write to the sysctl file
1952 * @filp: the file structure
1953 * @buffer: the user buffer
1954 * @lenp: the size of the user buffer
1956 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1957 * values from/to the user buffer, treated as an ASCII string.
1958 * The values read are assumed to be in seconds, and are converted into
1961 * Returns 0 on success.
1963 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1964 void __user *buffer, size_t *lenp, loff_t *ppos)
1966 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1967 do_proc_dointvec_jiffies_conv,NULL);
1971 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1972 * @table: the sysctl table
1973 * @write: %TRUE if this is a write to the sysctl file
1974 * @filp: the file structure
1975 * @buffer: the user buffer
1976 * @lenp: the size of the user buffer
1978 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1979 * values from/to the user buffer, treated as an ASCII string.
1980 * The values read are assumed to be in 1/USER_HZ seconds, and
1981 * are converted into jiffies.
1983 * Returns 0 on success.
1985 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1986 void __user *buffer, size_t *lenp, loff_t *ppos)
1988 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1989 do_proc_dointvec_userhz_jiffies_conv,NULL);
1993 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
1994 * @table: the sysctl table
1995 * @write: %TRUE if this is a write to the sysctl file
1996 * @filp: the file structure
1997 * @buffer: the user buffer
1998 * @lenp: the size of the user buffer
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 1/1000 seconds, and
2003 * are converted into jiffies.
2005 * Returns 0 on success.
2007 int proc_dointvec_ms_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_ms_jiffies_conv, NULL);
2014 #else /* CONFIG_PROC_FS */
2016 int proc_dostring(ctl_table *table, int write, struct file *filp,
2017 void __user *buffer, size_t *lenp, loff_t *ppos)
2022 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2023 void __user *buffer, size_t *lenp, loff_t *ppos)
2028 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2029 void __user *buffer, size_t *lenp, loff_t *ppos)
2034 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2035 void __user *buffer, size_t *lenp, loff_t *ppos)
2040 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2041 void __user *buffer, size_t *lenp, loff_t *ppos)
2046 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2047 void __user *buffer, size_t *lenp, loff_t *ppos)
2052 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2053 void __user *buffer, size_t *lenp, loff_t *ppos)
2058 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2059 void __user *buffer, size_t *lenp, loff_t *ppos)
2064 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2065 void __user *buffer, size_t *lenp, loff_t *ppos)
2070 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2072 void __user *buffer,
2073 size_t *lenp, loff_t *ppos)
2079 #endif /* CONFIG_PROC_FS */
2083 * General sysctl support routines
2086 /* The generic string strategy routine: */
2087 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2088 void __user *oldval, size_t __user *oldlenp,
2089 void __user *newval, size_t newlen, void **context)
2093 if (!table->data || !table->maxlen)
2096 if (oldval && oldlenp) {
2097 if (get_user(len, oldlenp))
2100 l = strlen(table->data);
2101 if (len > l) len = l;
2102 if (len >= table->maxlen)
2103 len = table->maxlen;
2104 if(copy_to_user(oldval, table->data, len))
2106 if(put_user(0, ((char __user *) oldval) + len))
2108 if(put_user(len, oldlenp))
2112 if (newval && newlen) {
2114 if (len > table->maxlen)
2115 len = table->maxlen;
2116 if(copy_from_user(table->data, newval, len))
2118 if (len == table->maxlen)
2120 ((char *) table->data)[len] = 0;
2126 * This function makes sure that all of the integers in the vector
2127 * are between the minimum and maximum values given in the arrays
2128 * table->extra1 and table->extra2, respectively.
2130 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2131 void __user *oldval, size_t __user *oldlenp,
2132 void __user *newval, size_t newlen, void **context)
2135 if (newval && newlen) {
2136 int __user *vec = (int __user *) newval;
2137 int *min = (int *) table->extra1;
2138 int *max = (int *) table->extra2;
2142 if (newlen % sizeof(int) != 0)
2145 if (!table->extra1 && !table->extra2)
2148 if (newlen > table->maxlen)
2149 newlen = table->maxlen;
2150 length = newlen / sizeof(int);
2152 for (i = 0; i < length; i++) {
2154 if (get_user(value, vec + i))
2156 if (min && value < min[i])
2158 if (max && value > max[i])
2165 /* Strategy function to convert jiffies to seconds */
2166 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2167 void __user *oldval, size_t __user *oldlenp,
2168 void __user *newval, size_t newlen, void **context)
2173 if (get_user(olen, oldlenp))
2175 if (olen!=sizeof(int))
2178 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2179 (oldlenp && put_user(sizeof(int),oldlenp)))
2182 if (newval && newlen) {
2184 if (newlen != sizeof(int))
2186 if (get_user(new, (int __user *)newval))
2188 *(int *)(table->data) = new*HZ;
2193 /* Strategy function to convert jiffies to seconds */
2194 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2195 void __user *oldval, size_t __user *oldlenp,
2196 void __user *newval, size_t newlen, void **context)
2201 if (get_user(olen, oldlenp))
2203 if (olen!=sizeof(int))
2206 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2207 (oldlenp && put_user(sizeof(int),oldlenp)))
2210 if (newval && newlen) {
2212 if (newlen != sizeof(int))
2214 if (get_user(new, (int __user *)newval))
2216 *(int *)(table->data) = msecs_to_jiffies(new);
2221 #else /* CONFIG_SYSCTL */
2224 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2229 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2230 void __user *oldval, size_t __user *oldlenp,
2231 void __user *newval, size_t newlen, void **context)
2236 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2237 void __user *oldval, size_t __user *oldlenp,
2238 void __user *newval, size_t newlen, void **context)
2243 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2244 void __user *oldval, size_t __user *oldlenp,
2245 void __user *newval, size_t newlen, void **context)
2250 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2251 void __user *oldval, size_t __user *oldlenp,
2252 void __user *newval, size_t newlen, void **context)
2257 int proc_dostring(ctl_table *table, int write, struct file *filp,
2258 void __user *buffer, size_t *lenp, loff_t *ppos)
2263 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2264 void __user *buffer, size_t *lenp, loff_t *ppos)
2269 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2270 void __user *buffer, size_t *lenp, loff_t *ppos)
2275 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2276 void __user *buffer, size_t *lenp, loff_t *ppos)
2281 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2287 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2288 void __user *buffer, size_t *lenp, loff_t *ppos)
2293 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2299 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2300 void __user *buffer, size_t *lenp, loff_t *ppos)
2305 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2307 void __user *buffer,
2308 size_t *lenp, loff_t *ppos)
2313 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2319 void unregister_sysctl_table(struct ctl_table_header * table)
2323 #endif /* CONFIG_SYSCTL */
2326 * No sense putting this after each symbol definition, twice,
2327 * exception granted :-)
2329 EXPORT_SYMBOL(proc_dointvec);
2330 EXPORT_SYMBOL(proc_dointvec_jiffies);
2331 EXPORT_SYMBOL(proc_dointvec_minmax);
2332 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2333 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2334 EXPORT_SYMBOL(proc_dostring);
2335 EXPORT_SYMBOL(proc_doulongvec_minmax);
2336 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2337 EXPORT_SYMBOL(register_sysctl_table);
2338 EXPORT_SYMBOL(sysctl_intvec);
2339 EXPORT_SYMBOL(sysctl_jiffies);
2340 EXPORT_SYMBOL(sysctl_ms_jiffies);
2341 EXPORT_SYMBOL(sysctl_string);
2342 EXPORT_SYMBOL(unregister_sysctl_table);