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 extern unsigned int vdso_enabled;
80 static int __init setup_exec_shield(char *str)
82 get_option (&str, &exec_shield);
87 __setup("exec-shield=", setup_exec_shield);
89 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
90 static int maxolduid = 65535;
93 static int ngroups_max = NGROUPS_MAX;
96 extern char modprobe_path[];
99 extern char hotplug_path[];
101 extern char vshelper_path[];
102 #ifdef CONFIG_CHR_DEV_SG
103 extern int sg_big_buff;
105 #ifdef CONFIG_SYSVIPC
106 extern size_t shm_ctlmax;
107 extern size_t shm_ctlall;
108 extern int shm_ctlmni;
109 extern int msg_ctlmax;
110 extern int msg_ctlmnb;
111 extern int msg_ctlmni;
112 extern int sem_ctls[];
116 extern char reboot_command [];
117 extern int stop_a_enabled;
118 extern int scons_pwroff;
122 extern int pwrsw_enabled;
123 extern int unaligned_enabled;
126 #ifdef CONFIG_ARCH_S390
127 #ifdef CONFIG_MATHEMU
128 extern int sysctl_ieee_emulation_warnings;
130 extern int sysctl_userprocess_debug;
133 extern int sysctl_hz_timer;
135 #ifdef CONFIG_BSD_PROCESS_ACCT
136 extern int acct_parm[];
139 int randomize_va_space = 1;
141 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
142 ctl_table *, void **);
143 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
144 void __user *buffer, size_t *lenp, loff_t *ppos);
146 static ctl_table root_table[];
147 static struct ctl_table_header root_table_header =
148 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
150 static ctl_table kern_table[];
151 static ctl_table vm_table[];
153 extern ctl_table net_table[];
155 static ctl_table proc_table[];
156 static ctl_table fs_table[];
157 static ctl_table debug_table[];
158 static ctl_table dev_table[];
159 extern ctl_table random_table[];
160 #ifdef CONFIG_UNIX98_PTYS
161 extern ctl_table pty_table[];
164 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
165 int sysctl_legacy_va_layout;
168 /* /proc declarations: */
170 #ifdef CONFIG_PROC_FS
172 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
173 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
174 static int proc_opensys(struct inode *, struct file *);
176 struct file_operations proc_sys_file_operations = {
177 .open = proc_opensys,
178 .read = proc_readsys,
179 .write = proc_writesys,
182 extern struct proc_dir_entry *proc_sys_root;
184 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
185 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
188 /* The default sysctl tables: */
190 static ctl_table root_table[] = {
192 .ctl_name = CTL_KERN,
193 .procname = "kernel",
212 .ctl_name = CTL_PROC,
224 .ctl_name = CTL_DEBUG,
227 .child = debug_table,
238 static ctl_table kern_table[] = {
240 .ctl_name = KERN_OSTYPE,
241 .procname = "ostype",
242 .data = system_utsname.sysname,
243 .maxlen = sizeof(system_utsname.sysname),
245 .proc_handler = &proc_doutsstring,
246 .virt_handler = &vx_uts_virt_handler,
247 .strategy = &sysctl_string,
250 .ctl_name = KERN_OSRELEASE,
251 .procname = "osrelease",
252 .data = system_utsname.release,
253 .maxlen = sizeof(system_utsname.release),
255 .proc_handler = &proc_doutsstring,
256 .virt_handler = &vx_uts_virt_handler,
257 .strategy = &sysctl_string,
260 .ctl_name = KERN_VERSION,
261 .procname = "version",
262 .data = system_utsname.version,
263 .maxlen = sizeof(system_utsname.version),
265 .proc_handler = &proc_doutsstring,
266 .virt_handler = &vx_uts_virt_handler,
267 .strategy = &sysctl_string,
270 .ctl_name = KERN_NODENAME,
271 .procname = "hostname",
272 .data = system_utsname.nodename,
273 .maxlen = sizeof(system_utsname.nodename),
275 .proc_handler = &proc_doutsstring,
276 .virt_handler = &vx_uts_virt_handler,
277 .strategy = &sysctl_string,
280 .ctl_name = KERN_DOMAINNAME,
281 .procname = "domainname",
282 .data = system_utsname.domainname,
283 .maxlen = sizeof(system_utsname.domainname),
285 .proc_handler = &proc_doutsstring,
286 .virt_handler = &vx_uts_virt_handler,
287 .strategy = &sysctl_string,
290 .ctl_name = KERN_PANIC,
292 .data = &panic_timeout,
293 .maxlen = sizeof(int),
295 .proc_handler = &proc_dointvec,
298 .ctl_name = KERN_EXEC_SHIELD,
299 .procname = "exec-shield",
300 .data = &exec_shield,
301 .maxlen = sizeof(int),
303 .proc_handler = &proc_dointvec,
306 .ctl_name = KERN_PRINT_FATAL,
307 .procname = "print-fatal-signals",
308 .data = &print_fatal_signals,
309 .maxlen = sizeof(int),
311 .proc_handler = &proc_dointvec,
315 .ctl_name = KERN_VDSO,
317 .data = &vdso_enabled,
318 .maxlen = sizeof(int),
320 .proc_handler = &proc_dointvec,
324 .ctl_name = KERN_CORE_USES_PID,
325 .procname = "core_uses_pid",
326 .data = &core_uses_pid,
327 .maxlen = sizeof(int),
329 .proc_handler = &proc_dointvec,
332 .ctl_name = KERN_CORE_PATTERN,
333 .procname = "core_pattern",
334 .data = core_pattern,
337 .proc_handler = &proc_dostring,
338 .strategy = &sysctl_string,
341 .ctl_name = KERN_TAINTED,
342 .procname = "tainted",
344 .maxlen = sizeof(int),
346 .proc_handler = &proc_dointvec,
349 .ctl_name = KERN_CAP_BSET,
350 .procname = "cap-bound",
352 .maxlen = sizeof(kernel_cap_t),
354 .proc_handler = &proc_dointvec_bset,
356 #ifdef CONFIG_BLK_DEV_INITRD
358 .ctl_name = KERN_REALROOTDEV,
359 .procname = "real-root-dev",
360 .data = &real_root_dev,
361 .maxlen = sizeof(int),
363 .proc_handler = &proc_dointvec,
368 .ctl_name = KERN_SPARC_REBOOT,
369 .procname = "reboot-cmd",
370 .data = reboot_command,
373 .proc_handler = &proc_dostring,
374 .strategy = &sysctl_string,
377 .ctl_name = KERN_SPARC_STOP_A,
378 .procname = "stop-a",
379 .data = &stop_a_enabled,
380 .maxlen = sizeof (int),
382 .proc_handler = &proc_dointvec,
385 .ctl_name = KERN_SPARC_SCONS_PWROFF,
386 .procname = "scons-poweroff",
387 .data = &scons_pwroff,
388 .maxlen = sizeof (int),
390 .proc_handler = &proc_dointvec,
395 .ctl_name = KERN_HPPA_PWRSW,
396 .procname = "soft-power",
397 .data = &pwrsw_enabled,
398 .maxlen = sizeof (int),
400 .proc_handler = &proc_dointvec,
403 .ctl_name = KERN_HPPA_UNALIGNED,
404 .procname = "unaligned-trap",
405 .data = &unaligned_enabled,
406 .maxlen = sizeof (int),
408 .proc_handler = &proc_dointvec,
412 .ctl_name = KERN_CTLALTDEL,
413 .procname = "ctrl-alt-del",
415 .maxlen = sizeof(int),
417 .proc_handler = &proc_dointvec,
420 .ctl_name = KERN_PRINTK,
421 .procname = "printk",
422 .data = &console_loglevel,
423 .maxlen = 4*sizeof(int),
425 .proc_handler = &proc_dointvec,
429 .ctl_name = KERN_MODPROBE,
430 .procname = "modprobe",
431 .data = &modprobe_path,
432 .maxlen = KMOD_PATH_LEN,
434 .proc_handler = &proc_dostring,
435 .strategy = &sysctl_string,
438 #ifdef CONFIG_HOTPLUG
440 .ctl_name = KERN_HOTPLUG,
441 .procname = "hotplug",
442 .data = &hotplug_path,
443 .maxlen = HOTPLUG_PATH_LEN,
445 .proc_handler = &proc_dostring,
446 .strategy = &sysctl_string,
450 .ctl_name = KERN_VSHELPER,
451 .procname = "vshelper",
452 .data = &vshelper_path,
455 .proc_handler = &proc_dostring,
456 .strategy = &sysctl_string,
458 #ifdef CONFIG_CHR_DEV_SG
460 .ctl_name = KERN_SG_BIG_BUFF,
461 .procname = "sg-big-buff",
462 .data = &sg_big_buff,
463 .maxlen = sizeof (int),
465 .proc_handler = &proc_dointvec,
468 #ifdef CONFIG_BSD_PROCESS_ACCT
470 .ctl_name = KERN_ACCT,
473 .maxlen = 3*sizeof(int),
475 .proc_handler = &proc_dointvec,
478 #ifdef CONFIG_SYSVIPC
480 .ctl_name = KERN_SHMMAX,
481 .procname = "shmmax",
483 .maxlen = sizeof (size_t),
485 .proc_handler = &proc_doulongvec_minmax,
488 .ctl_name = KERN_SHMALL,
489 .procname = "shmall",
491 .maxlen = sizeof (size_t),
493 .proc_handler = &proc_doulongvec_minmax,
496 .ctl_name = KERN_SHMMNI,
497 .procname = "shmmni",
499 .maxlen = sizeof (int),
501 .proc_handler = &proc_dointvec,
504 .ctl_name = KERN_MSGMAX,
505 .procname = "msgmax",
507 .maxlen = sizeof (int),
509 .proc_handler = &proc_dointvec,
512 .ctl_name = KERN_MSGMNI,
513 .procname = "msgmni",
515 .maxlen = sizeof (int),
517 .proc_handler = &proc_dointvec,
520 .ctl_name = KERN_MSGMNB,
521 .procname = "msgmnb",
523 .maxlen = sizeof (int),
525 .proc_handler = &proc_dointvec,
528 .ctl_name = KERN_SEM,
531 .maxlen = 4*sizeof (int),
533 .proc_handler = &proc_dointvec,
536 #ifdef CONFIG_MAGIC_SYSRQ
538 .ctl_name = KERN_SYSRQ,
540 .data = &sysrq_enabled,
541 .maxlen = sizeof (int),
543 .proc_handler = &proc_dointvec,
547 .ctl_name = KERN_CADPID,
548 .procname = "cad_pid",
550 .maxlen = sizeof (int),
552 .proc_handler = &proc_dointvec,
555 .ctl_name = KERN_MAX_THREADS,
556 .procname = "threads-max",
557 .data = &max_threads,
558 .maxlen = sizeof(int),
560 .proc_handler = &proc_dointvec,
563 .ctl_name = KERN_RANDOM,
564 .procname = "random",
566 .child = random_table,
568 #ifdef CONFIG_UNIX98_PTYS
570 .ctl_name = KERN_PTY,
577 .ctl_name = KERN_OVERFLOWUID,
578 .procname = "overflowuid",
579 .data = &overflowuid,
580 .maxlen = sizeof(int),
582 .proc_handler = &proc_dointvec_minmax,
583 .strategy = &sysctl_intvec,
584 .extra1 = &minolduid,
585 .extra2 = &maxolduid,
588 .ctl_name = KERN_OVERFLOWGID,
589 .procname = "overflowgid",
590 .data = &overflowgid,
591 .maxlen = sizeof(int),
593 .proc_handler = &proc_dointvec_minmax,
594 .strategy = &sysctl_intvec,
595 .extra1 = &minolduid,
596 .extra2 = &maxolduid,
598 #ifdef CONFIG_ARCH_S390
599 #ifdef CONFIG_MATHEMU
601 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
602 .procname = "ieee_emulation_warnings",
603 .data = &sysctl_ieee_emulation_warnings,
604 .maxlen = sizeof(int),
606 .proc_handler = &proc_dointvec,
609 #ifdef CONFIG_NO_IDLE_HZ
611 .ctl_name = KERN_HZ_TIMER,
612 .procname = "hz_timer",
613 .data = &sysctl_hz_timer,
614 .maxlen = sizeof(int),
616 .proc_handler = &proc_dointvec,
620 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
621 .procname = "userprocess_debug",
622 .data = &sysctl_userprocess_debug,
623 .maxlen = sizeof(int),
625 .proc_handler = &proc_dointvec,
629 .ctl_name = KERN_PIDMAX,
630 .procname = "pid_max",
632 .maxlen = sizeof (int),
634 .proc_handler = &proc_dointvec_minmax,
635 .strategy = sysctl_intvec,
636 .extra1 = &pid_max_min,
637 .extra2 = &pid_max_max,
640 .ctl_name = KERN_PANIC_ON_OOPS,
641 .procname = "panic_on_oops",
642 .data = &panic_on_oops,
643 .maxlen = sizeof(int),
645 .proc_handler = &proc_dointvec,
648 .ctl_name = KERN_PRINTK_RATELIMIT,
649 .procname = "printk_ratelimit",
650 .data = &printk_ratelimit_jiffies,
651 .maxlen = sizeof(int),
653 .proc_handler = &proc_dointvec_jiffies,
654 .strategy = &sysctl_jiffies,
657 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
658 .procname = "printk_ratelimit_burst",
659 .data = &printk_ratelimit_burst,
660 .maxlen = sizeof(int),
662 .proc_handler = &proc_dointvec,
665 .ctl_name = KERN_NGROUPS_MAX,
666 .procname = "ngroups_max",
667 .data = &ngroups_max,
668 .maxlen = sizeof (int),
670 .proc_handler = &proc_dointvec,
672 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
674 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
675 .procname = "unknown_nmi_panic",
676 .data = &unknown_nmi_panic,
677 .maxlen = sizeof (int),
679 .proc_handler = &proc_unknown_nmi_panic,
682 #if defined(CONFIG_X86)
684 .ctl_name = KERN_BOOTLOADER_TYPE,
685 .procname = "bootloader_type",
686 .data = &bootloader_type,
687 .maxlen = sizeof (int),
689 .proc_handler = &proc_dointvec,
693 .ctl_name = KERN_RANDOMIZE,
694 .procname = "randomize_va_space",
695 .data = &randomize_va_space,
696 .maxlen = sizeof(int),
698 .proc_handler = &proc_dointvec,
704 /* Constants for minimum and maximum testing in vm_table.
705 We use these as one-element integer vectors. */
707 static int one_hundred = 100;
710 static ctl_table vm_table[] = {
712 .ctl_name = VM_OVERCOMMIT_MEMORY,
713 .procname = "overcommit_memory",
714 .data = &sysctl_overcommit_memory,
715 .maxlen = sizeof(sysctl_overcommit_memory),
717 .proc_handler = &proc_dointvec,
720 .ctl_name = VM_OVERCOMMIT_RATIO,
721 .procname = "overcommit_ratio",
722 .data = &sysctl_overcommit_ratio,
723 .maxlen = sizeof(sysctl_overcommit_ratio),
725 .proc_handler = &proc_dointvec,
728 .ctl_name = VM_PAGE_CLUSTER,
729 .procname = "page-cluster",
730 .data = &page_cluster,
731 .maxlen = sizeof(int),
733 .proc_handler = &proc_dointvec,
736 .ctl_name = VM_DIRTY_BACKGROUND,
737 .procname = "dirty_background_ratio",
738 .data = &dirty_background_ratio,
739 .maxlen = sizeof(dirty_background_ratio),
741 .proc_handler = &proc_dointvec_minmax,
742 .strategy = &sysctl_intvec,
744 .extra2 = &one_hundred,
747 .ctl_name = VM_DIRTY_RATIO,
748 .procname = "dirty_ratio",
749 .data = &vm_dirty_ratio,
750 .maxlen = sizeof(vm_dirty_ratio),
752 .proc_handler = &proc_dointvec_minmax,
753 .strategy = &sysctl_intvec,
755 .extra2 = &one_hundred,
758 .ctl_name = VM_DIRTY_WB_CS,
759 .procname = "dirty_writeback_centisecs",
760 .data = &dirty_writeback_centisecs,
761 .maxlen = sizeof(dirty_writeback_centisecs),
763 .proc_handler = &dirty_writeback_centisecs_handler,
766 .ctl_name = VM_DIRTY_EXPIRE_CS,
767 .procname = "dirty_expire_centisecs",
768 .data = &dirty_expire_centisecs,
769 .maxlen = sizeof(dirty_expire_centisecs),
771 .proc_handler = &proc_dointvec,
774 .ctl_name = VM_NR_PDFLUSH_THREADS,
775 .procname = "nr_pdflush_threads",
776 .data = &nr_pdflush_threads,
777 .maxlen = sizeof nr_pdflush_threads,
778 .mode = 0444 /* read-only*/,
779 .proc_handler = &proc_dointvec,
782 .ctl_name = VM_SWAPPINESS,
783 .procname = "swappiness",
784 .data = &vm_swappiness,
785 .maxlen = sizeof(vm_swappiness),
787 .proc_handler = &proc_dointvec_minmax,
788 .strategy = &sysctl_intvec,
790 .extra2 = &one_hundred,
792 #ifdef CONFIG_HUGETLB_PAGE
794 .ctl_name = VM_HUGETLB_PAGES,
795 .procname = "nr_hugepages",
796 .data = &max_huge_pages,
797 .maxlen = sizeof(unsigned long),
799 .proc_handler = &hugetlb_sysctl_handler,
800 .extra1 = (void *)&hugetlb_zero,
801 .extra2 = (void *)&hugetlb_infinity,
804 .ctl_name = VM_HUGETLB_GROUP,
805 .procname = "hugetlb_shm_group",
806 .data = &sysctl_hugetlb_shm_group,
807 .maxlen = sizeof(gid_t),
809 .proc_handler = &proc_dointvec,
813 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
814 .procname = "lowmem_reserve_ratio",
815 .data = &sysctl_lowmem_reserve_ratio,
816 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
818 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
819 .strategy = &sysctl_intvec,
822 .ctl_name = VM_MIN_FREE_KBYTES,
823 .procname = "min_free_kbytes",
824 .data = &min_free_kbytes,
825 .maxlen = sizeof(min_free_kbytes),
827 .proc_handler = &min_free_kbytes_sysctl_handler,
828 .strategy = &sysctl_intvec,
833 .ctl_name = VM_MAX_MAP_COUNT,
834 .procname = "max_map_count",
835 .data = &sysctl_max_map_count,
836 .maxlen = sizeof(sysctl_max_map_count),
838 .proc_handler = &proc_dointvec
842 .ctl_name = VM_LAPTOP_MODE,
843 .procname = "laptop_mode",
844 .data = &laptop_mode,
845 .maxlen = sizeof(laptop_mode),
847 .proc_handler = &proc_dointvec,
848 .strategy = &sysctl_intvec,
852 .ctl_name = VM_BLOCK_DUMP,
853 .procname = "block_dump",
855 .maxlen = sizeof(block_dump),
857 .proc_handler = &proc_dointvec,
858 .strategy = &sysctl_intvec,
862 .ctl_name = VM_VFS_CACHE_PRESSURE,
863 .procname = "vfs_cache_pressure",
864 .data = &sysctl_vfs_cache_pressure,
865 .maxlen = sizeof(sysctl_vfs_cache_pressure),
867 .proc_handler = &proc_dointvec,
868 .strategy = &sysctl_intvec,
871 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
873 .ctl_name = VM_LEGACY_VA_LAYOUT,
874 .procname = "legacy_va_layout",
875 .data = &sysctl_legacy_va_layout,
876 .maxlen = sizeof(sysctl_legacy_va_layout),
878 .proc_handler = &proc_dointvec,
879 .strategy = &sysctl_intvec,
885 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
886 .procname = "swap_token_timeout",
887 .data = &swap_token_default_timeout,
888 .maxlen = sizeof(swap_token_default_timeout),
890 .proc_handler = &proc_dointvec_jiffies,
891 .strategy = &sysctl_jiffies,
897 static ctl_table proc_table[] = {
901 static ctl_table fs_table[] = {
903 .ctl_name = FS_NRINODE,
904 .procname = "inode-nr",
905 .data = &inodes_stat,
906 .maxlen = 2*sizeof(int),
908 .proc_handler = &proc_dointvec,
911 .ctl_name = FS_STATINODE,
912 .procname = "inode-state",
913 .data = &inodes_stat,
914 .maxlen = 7*sizeof(int),
916 .proc_handler = &proc_dointvec,
919 .ctl_name = FS_NRFILE,
920 .procname = "file-nr",
922 .maxlen = 3*sizeof(int),
924 .proc_handler = &proc_dointvec,
927 .ctl_name = FS_MAXFILE,
928 .procname = "file-max",
929 .data = &files_stat.max_files,
930 .maxlen = sizeof(int),
932 .proc_handler = &proc_dointvec,
935 .ctl_name = FS_DENTRY,
936 .procname = "dentry-state",
937 .data = &dentry_stat,
938 .maxlen = 6*sizeof(int),
940 .proc_handler = &proc_dointvec,
943 .ctl_name = FS_OVERFLOWUID,
944 .procname = "overflowuid",
945 .data = &fs_overflowuid,
946 .maxlen = sizeof(int),
948 .proc_handler = &proc_dointvec_minmax,
949 .strategy = &sysctl_intvec,
950 .extra1 = &minolduid,
951 .extra2 = &maxolduid,
954 .ctl_name = FS_OVERFLOWGID,
955 .procname = "overflowgid",
956 .data = &fs_overflowgid,
957 .maxlen = sizeof(int),
959 .proc_handler = &proc_dointvec_minmax,
960 .strategy = &sysctl_intvec,
961 .extra1 = &minolduid,
962 .extra2 = &maxolduid,
965 .ctl_name = FS_LEASES,
966 .procname = "leases-enable",
967 .data = &leases_enable,
968 .maxlen = sizeof(int),
970 .proc_handler = &proc_dointvec,
972 #ifdef CONFIG_DNOTIFY
974 .ctl_name = FS_DIR_NOTIFY,
975 .procname = "dir-notify-enable",
976 .data = &dir_notify_enable,
977 .maxlen = sizeof(int),
979 .proc_handler = &proc_dointvec,
984 .ctl_name = FS_LEASE_TIME,
985 .procname = "lease-break-time",
986 .data = &lease_break_time,
987 .maxlen = sizeof(int),
989 .proc_handler = &proc_dointvec,
992 .ctl_name = FS_AIO_NR,
993 .procname = "aio-nr",
995 .maxlen = sizeof(aio_nr),
997 .proc_handler = &proc_dointvec,
1000 .ctl_name = FS_AIO_MAX_NR,
1001 .procname = "aio-max-nr",
1002 .data = &aio_max_nr,
1003 .maxlen = sizeof(aio_max_nr),
1005 .proc_handler = &proc_dointvec,
1011 static ctl_table debug_table[] = {
1015 static ctl_table dev_table[] = {
1019 extern void init_irq_proc (void);
1021 void __init sysctl_init(void)
1023 #ifdef CONFIG_PROC_FS
1024 register_proc_table(root_table, proc_sys_root);
1029 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1030 void __user *newval, size_t newlen)
1032 struct list_head *tmp;
1034 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1038 if (!oldlenp || get_user(old_len, oldlenp))
1041 tmp = &root_table_header.ctl_entry;
1043 struct ctl_table_header *head =
1044 list_entry(tmp, struct ctl_table_header, ctl_entry);
1045 void *context = NULL;
1046 int error = parse_table(name, nlen, oldval, oldlenp,
1047 newval, newlen, head->ctl_table,
1051 if (error != -ENOTDIR)
1054 } while (tmp != &root_table_header.ctl_entry);
1058 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1060 struct __sysctl_args tmp;
1063 if (copy_from_user(&tmp, args, sizeof(tmp)))
1067 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1068 tmp.newval, tmp.newlen);
1074 * ctl_perm does NOT grant the superuser all rights automatically, because
1075 * some sysctl variables are readonly even to root.
1078 static int test_perm(int mode, int op)
1082 else if (in_egroup_p(0))
1084 if ((mode & op & 0007) == op)
1089 static inline int ctl_perm(ctl_table *table, int op)
1092 error = security_sysctl(table, op);
1095 return test_perm(table->mode, op);
1098 static int parse_table(int __user *name, int nlen,
1099 void __user *oldval, size_t __user *oldlenp,
1100 void __user *newval, size_t newlen,
1101 ctl_table *table, void **context)
1107 if (get_user(n, name))
1109 for ( ; table->ctl_name; table++) {
1110 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1113 if (ctl_perm(table, 001))
1115 if (table->strategy) {
1116 error = table->strategy(
1119 newval, newlen, context);
1125 table = table->child;
1128 error = do_sysctl_strategy(table, name, nlen,
1130 newval, newlen, context);
1137 /* Perform the actual read/write of a sysctl table entry. */
1138 int do_sysctl_strategy (ctl_table *table,
1139 int __user *name, int nlen,
1140 void __user *oldval, size_t __user *oldlenp,
1141 void __user *newval, size_t newlen, void **context)
1150 if (ctl_perm(table, op))
1153 if (table->strategy) {
1154 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1155 newval, newlen, context);
1162 /* If there is no strategy routine, or if the strategy returns
1163 * zero, proceed with automatic r/w */
1164 if (table->data && table->maxlen) {
1165 if (oldval && oldlenp) {
1166 if (get_user(len, oldlenp))
1169 if (len > table->maxlen)
1170 len = table->maxlen;
1171 if(copy_to_user(oldval, table->data, len))
1173 if(put_user(len, oldlenp))
1177 if (newval && newlen) {
1179 if (len > table->maxlen)
1180 len = table->maxlen;
1181 if(copy_from_user(table->data, newval, len))
1189 * register_sysctl_table - register a sysctl hierarchy
1190 * @table: the top-level table structure
1191 * @insert_at_head: whether the entry should be inserted in front or at the end
1193 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1194 * array. An entry with a ctl_name of 0 terminates the table.
1196 * The members of the &ctl_table structure are used as follows:
1198 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1199 * must be unique within that level of sysctl
1201 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1202 * enter a sysctl file
1204 * data - a pointer to data for use by proc_handler
1206 * maxlen - the maximum size in bytes of the data
1208 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1210 * child - a pointer to the child sysctl table if this entry is a directory, or
1213 * proc_handler - the text handler routine (described below)
1215 * strategy - the strategy routine (described below)
1217 * de - for internal use by the sysctl routines
1219 * extra1, extra2 - extra pointers usable by the proc handler routines
1221 * Leaf nodes in the sysctl tree will be represented by a single file
1222 * under /proc; non-leaf nodes will be represented by directories.
1224 * sysctl(2) can automatically manage read and write requests through
1225 * the sysctl table. The data and maxlen fields of the ctl_table
1226 * struct enable minimal validation of the values being written to be
1227 * performed, and the mode field allows minimal authentication.
1229 * More sophisticated management can be enabled by the provision of a
1230 * strategy routine with the table entry. This will be called before
1231 * any automatic read or write of the data is performed.
1233 * The strategy routine may return
1235 * < 0 - Error occurred (error is passed to user process)
1237 * 0 - OK - proceed with automatic read or write.
1239 * > 0 - OK - read or write has been done by the strategy routine, so
1240 * return immediately.
1242 * There must be a proc_handler routine for any terminal nodes
1243 * mirrored under /proc/sys (non-terminals are handled by a built-in
1244 * directory handler). Several default handlers are available to
1245 * cover common cases -
1247 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1248 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1249 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1251 * It is the handler's job to read the input buffer from user memory
1252 * and process it. The handler should return 0 on success.
1254 * This routine returns %NULL on a failure to register, and a pointer
1255 * to the table header on success.
1257 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1260 struct ctl_table_header *tmp;
1261 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1264 tmp->ctl_table = table;
1265 INIT_LIST_HEAD(&tmp->ctl_entry);
1267 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1269 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1270 #ifdef CONFIG_PROC_FS
1271 register_proc_table(table, proc_sys_root);
1277 * unregister_sysctl_table - unregister a sysctl table hierarchy
1278 * @header: the header returned from register_sysctl_table
1280 * Unregisters the sysctl table and all children. proc entries may not
1281 * actually be removed until they are no longer used by anyone.
1283 void unregister_sysctl_table(struct ctl_table_header * header)
1285 list_del(&header->ctl_entry);
1286 #ifdef CONFIG_PROC_FS
1287 unregister_proc_table(header->ctl_table, proc_sys_root);
1296 #ifdef CONFIG_PROC_FS
1298 /* Scan the sysctl entries in table and add them all into /proc */
1299 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1301 struct proc_dir_entry *de;
1305 for (; table->ctl_name; table++) {
1306 /* Can't do anything without a proc name. */
1307 if (!table->procname)
1309 /* Maybe we can't do anything with it... */
1310 if (!table->proc_handler && !table->child) {
1311 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1316 len = strlen(table->procname);
1320 if (table->proc_handler)
1324 for (de = root->subdir; de; de = de->next) {
1325 if (proc_match(len, table->procname, de))
1328 /* If the subdir exists already, de is non-NULL */
1332 de = create_proc_entry(table->procname, mode, root);
1335 de->data = (void *) table;
1336 if (table->proc_handler)
1337 de->proc_fops = &proc_sys_file_operations;
1340 if (de->mode & S_IFDIR)
1341 register_proc_table(table->child, de);
1346 * Unregister a /proc sysctl table and any subdirectories.
1348 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1350 struct proc_dir_entry *de;
1351 for (; table->ctl_name; table++) {
1352 if (!(de = table->de))
1354 if (de->mode & S_IFDIR) {
1355 if (!table->child) {
1356 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1359 unregister_proc_table(table->child, de);
1361 /* Don't unregister directories which still have entries.. */
1366 /* Don't unregister proc entries that are still being used.. */
1367 if (atomic_read(&de->count))
1371 remove_proc_entry(table->procname, root);
1375 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1376 size_t count, loff_t *ppos)
1379 struct proc_dir_entry *de;
1380 struct ctl_table *table;
1384 de = PDE(file->f_dentry->d_inode);
1385 if (!de || !de->data)
1387 table = (struct ctl_table *) de->data;
1388 if (!table || !table->proc_handler)
1390 op = (write ? 002 : 004);
1391 if (ctl_perm(table, op))
1396 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1402 static int proc_opensys(struct inode *inode, struct file *file)
1404 if (file->f_mode & FMODE_WRITE) {
1406 * sysctl entries that are not writable,
1407 * are _NOT_ writable, capabilities or not.
1409 if (!(inode->i_mode & S_IWUSR))
1416 static ssize_t proc_readsys(struct file * file, char __user * buf,
1417 size_t count, loff_t *ppos)
1419 return do_rw_proc(0, file, buf, count, ppos);
1422 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1423 size_t count, loff_t *ppos)
1425 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1429 * proc_dostring - read a string sysctl
1430 * @table: the sysctl table
1431 * @write: %TRUE if this is a write to the sysctl file
1432 * @filp: the file structure
1433 * @buffer: the user buffer
1434 * @lenp: the size of the user buffer
1435 * @ppos: file position
1437 * Reads/writes a string from/to the user buffer. If the kernel
1438 * buffer provided is not large enough to hold the string, the
1439 * string is truncated. The copied string is %NULL-terminated.
1440 * If the string is being read by the user process, it is copied
1441 * and a newline '\n' is added. It is truncated if the buffer is
1444 * Returns 0 on success.
1446 int proc_dostring(ctl_table *table, int write, struct file *filp,
1447 void __user *buffer, size_t *lenp, loff_t *ppos)
1455 maxlen = table->maxlen;
1457 if (!data || !maxlen || !*lenp || (*ppos && !write))
1460 if (table->virt_handler)
1461 table->virt_handler(table, write, filp->f_xid, &data, &maxlen);
1466 while (len < *lenp) {
1467 if (get_user(c, p++))
1469 if (c == 0 || c == '\n')
1475 if(copy_from_user(data, buffer, len))
1477 ((char *) data)[len] = 0;
1486 if(copy_to_user(buffer, data, len))
1489 if(put_user('\n', ((char __user *) buffer) + len))
1500 * Special case of dostring for the UTS structure. This has locks
1501 * to observe. Should this be in kernel/sys.c ????
1504 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1505 void __user *buffer, size_t *lenp, loff_t *ppos)
1510 down_read(&uts_sem);
1511 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1514 down_write(&uts_sem);
1515 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1521 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1523 int write, void *data)
1526 *valp = *negp ? -*lvalp : *lvalp;
1531 *lvalp = (unsigned long)-val;
1534 *lvalp = (unsigned long)val;
1540 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1541 void __user *buffer, size_t *lenp, loff_t *ppos,
1542 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1543 int write, void *data),
1546 #define TMPBUFLEN 21
1547 int *i, vleft, first=1, neg, val;
1551 char buf[TMPBUFLEN], *p;
1552 char __user *s = buffer;
1554 if (!table->data || !table->maxlen || !*lenp ||
1555 (*ppos && !write)) {
1560 i = (int *) table->data;
1561 vleft = table->maxlen / sizeof(*i);
1565 conv = do_proc_dointvec_conv;
1567 for (; left && vleft--; i++, first=0) {
1582 if (len > sizeof(buf) - 1)
1583 len = sizeof(buf) - 1;
1584 if (copy_from_user(buf, s, len))
1588 if (*p == '-' && left > 1) {
1592 if (*p < '0' || *p > '9')
1595 lval = simple_strtoul(p, &p, 0);
1598 if ((len < left) && *p && !isspace(*p))
1605 if (conv(&neg, &lval, i, 1, data))
1612 if (conv(&neg, &lval, i, 0, data))
1615 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1619 if(copy_to_user(s, buf, len))
1626 if (!write && !first && left) {
1627 if(put_user('\n', s))
1634 if (get_user(c, s++))
1650 * proc_dointvec - read a vector of integers
1651 * @table: the sysctl table
1652 * @write: %TRUE if this is a write to the sysctl file
1653 * @filp: the file structure
1654 * @buffer: the user buffer
1655 * @lenp: the size of the user buffer
1656 * @ppos: file position
1658 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1659 * values from/to the user buffer, treated as an ASCII string.
1661 * Returns 0 on success.
1663 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1664 void __user *buffer, size_t *lenp, loff_t *ppos)
1666 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1676 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1678 int write, void *data)
1680 int op = *(int *)data;
1682 int val = *negp ? -*lvalp : *lvalp;
1684 case OP_SET: *valp = val; break;
1685 case OP_AND: *valp &= val; break;
1686 case OP_OR: *valp |= val; break;
1687 case OP_MAX: if(*valp < val)
1690 case OP_MIN: if(*valp > val)
1698 *lvalp = (unsigned long)-val;
1701 *lvalp = (unsigned long)val;
1708 * init may raise the set.
1711 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1712 void __user *buffer, size_t *lenp, loff_t *ppos)
1716 if (!capable(CAP_SYS_MODULE)) {
1720 op = (current->pid == 1) ? OP_SET : OP_AND;
1721 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1722 do_proc_dointvec_bset_conv,&op);
1725 struct do_proc_dointvec_minmax_conv_param {
1730 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1732 int write, void *data)
1734 struct do_proc_dointvec_minmax_conv_param *param = data;
1736 int val = *negp ? -*lvalp : *lvalp;
1737 if ((param->min && *param->min > val) ||
1738 (param->max && *param->max < val))
1745 *lvalp = (unsigned long)-val;
1748 *lvalp = (unsigned long)val;
1755 * proc_dointvec_minmax - read a vector of integers with min/max values
1756 * @table: the sysctl table
1757 * @write: %TRUE if this is a write to the sysctl file
1758 * @filp: the file structure
1759 * @buffer: the user buffer
1760 * @lenp: the size of the user buffer
1761 * @ppos: file position
1763 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1764 * values from/to the user buffer, treated as an ASCII string.
1766 * This routine will ensure the values are within the range specified by
1767 * table->extra1 (min) and table->extra2 (max).
1769 * Returns 0 on success.
1771 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1772 void __user *buffer, size_t *lenp, loff_t *ppos)
1774 struct do_proc_dointvec_minmax_conv_param param = {
1775 .min = (int *) table->extra1,
1776 .max = (int *) table->extra2,
1778 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1779 do_proc_dointvec_minmax_conv, ¶m);
1782 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1784 void __user *buffer,
1785 size_t *lenp, loff_t *ppos,
1786 unsigned long convmul,
1787 unsigned long convdiv)
1789 #define TMPBUFLEN 21
1790 unsigned long *i, *min, *max, val;
1791 int vleft, first=1, neg;
1793 char buf[TMPBUFLEN], *p;
1794 char __user *s = buffer;
1796 if (!table->data || !table->maxlen || !*lenp ||
1797 (*ppos && !write)) {
1802 i = (unsigned long *) table->data;
1803 min = (unsigned long *) table->extra1;
1804 max = (unsigned long *) table->extra2;
1805 vleft = table->maxlen / sizeof(unsigned long);
1808 for (; left && vleft--; i++, min++, max++, first=0) {
1823 if (len > TMPBUFLEN-1)
1825 if (copy_from_user(buf, s, len))
1829 if (*p == '-' && left > 1) {
1833 if (*p < '0' || *p > '9')
1835 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1837 if ((len < left) && *p && !isspace(*p))
1846 if ((min && val < *min) || (max && val > *max))
1853 sprintf(p, "%lu", convdiv * (*i) / convmul);
1857 if(copy_to_user(s, buf, len))
1864 if (!write && !first && left) {
1865 if(put_user('\n', s))
1872 if (get_user(c, s++))
1888 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1889 * @table: the sysctl table
1890 * @write: %TRUE if this is a write to the sysctl file
1891 * @filp: the file structure
1892 * @buffer: the user buffer
1893 * @lenp: the size of the user buffer
1894 * @ppos: file position
1896 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1897 * values from/to the user buffer, treated as an ASCII string.
1899 * This routine will ensure the values are within the range specified by
1900 * table->extra1 (min) and table->extra2 (max).
1902 * Returns 0 on success.
1904 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1905 void __user *buffer, size_t *lenp, loff_t *ppos)
1907 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1911 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1912 * @table: the sysctl table
1913 * @write: %TRUE if this is a write to the sysctl file
1914 * @filp: the file structure
1915 * @buffer: the user buffer
1916 * @lenp: the size of the user buffer
1917 * @ppos: file position
1919 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1920 * values from/to the user buffer, treated as an ASCII string. The values
1921 * are treated as milliseconds, and converted to jiffies when they are stored.
1923 * This routine will ensure the values are within the range specified by
1924 * table->extra1 (min) and table->extra2 (max).
1926 * Returns 0 on success.
1928 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1930 void __user *buffer,
1931 size_t *lenp, loff_t *ppos)
1933 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1934 lenp, ppos, HZ, 1000l);
1938 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1940 int write, void *data)
1943 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1949 lval = (unsigned long)-val;
1952 lval = (unsigned long)val;
1959 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1961 int write, void *data)
1964 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1970 lval = (unsigned long)-val;
1973 lval = (unsigned long)val;
1975 *lvalp = jiffies_to_clock_t(lval);
1980 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1982 int write, void *data)
1985 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1991 lval = (unsigned long)-val;
1994 lval = (unsigned long)val;
1996 *lvalp = jiffies_to_msecs(lval);
2002 * proc_dointvec_jiffies - read a vector of integers as seconds
2003 * @table: the sysctl table
2004 * @write: %TRUE if this is a write to the sysctl file
2005 * @filp: the file structure
2006 * @buffer: the user buffer
2007 * @lenp: the size of the user buffer
2008 * @ppos: file position
2010 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2011 * values from/to the user buffer, treated as an ASCII string.
2012 * The values read are assumed to be in seconds, and are converted into
2015 * Returns 0 on success.
2017 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2018 void __user *buffer, size_t *lenp, loff_t *ppos)
2020 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2021 do_proc_dointvec_jiffies_conv,NULL);
2025 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2026 * @table: the sysctl table
2027 * @write: %TRUE if this is a write to the sysctl file
2028 * @filp: the file structure
2029 * @buffer: the user buffer
2030 * @lenp: the size of the user buffer
2032 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2033 * values from/to the user buffer, treated as an ASCII string.
2034 * The values read are assumed to be in 1/USER_HZ seconds, and
2035 * are converted into jiffies.
2037 * Returns 0 on success.
2039 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2040 void __user *buffer, size_t *lenp, loff_t *ppos)
2042 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2043 do_proc_dointvec_userhz_jiffies_conv,NULL);
2047 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2048 * @table: the sysctl table
2049 * @write: %TRUE if this is a write to the sysctl file
2050 * @filp: the file structure
2051 * @buffer: the user buffer
2052 * @lenp: the size of the user buffer
2053 * @ppos: file position
2054 * @ppos: the current position in the file
2056 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2057 * values from/to the user buffer, treated as an ASCII string.
2058 * The values read are assumed to be in 1/1000 seconds, and
2059 * are converted into jiffies.
2061 * Returns 0 on success.
2063 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2064 void __user *buffer, size_t *lenp, loff_t *ppos)
2066 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2067 do_proc_dointvec_ms_jiffies_conv, NULL);
2070 #else /* CONFIG_PROC_FS */
2072 int proc_dostring(ctl_table *table, int write, struct file *filp,
2073 void __user *buffer, size_t *lenp, loff_t *ppos)
2078 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2079 void __user *buffer, size_t *lenp, loff_t *ppos)
2084 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2085 void __user *buffer, size_t *lenp, loff_t *ppos)
2090 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2091 void __user *buffer, size_t *lenp, loff_t *ppos)
2096 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2097 void __user *buffer, size_t *lenp, loff_t *ppos)
2102 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2103 void __user *buffer, size_t *lenp, loff_t *ppos)
2108 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2109 void __user *buffer, size_t *lenp, loff_t *ppos)
2114 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2115 void __user *buffer, size_t *lenp, loff_t *ppos)
2120 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2121 void __user *buffer, size_t *lenp, loff_t *ppos)
2126 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2128 void __user *buffer,
2129 size_t *lenp, loff_t *ppos)
2135 #endif /* CONFIG_PROC_FS */
2139 * General sysctl support routines
2142 /* The generic string strategy routine: */
2143 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2144 void __user *oldval, size_t __user *oldlenp,
2145 void __user *newval, size_t newlen, void **context)
2149 if (!table->data || !table->maxlen)
2152 if (oldval && oldlenp) {
2153 if (get_user(len, oldlenp))
2156 l = strlen(table->data);
2157 if (len > l) len = l;
2158 if (len >= table->maxlen)
2159 len = table->maxlen;
2160 if(copy_to_user(oldval, table->data, len))
2162 if(put_user(0, ((char __user *) oldval) + len))
2164 if(put_user(len, oldlenp))
2168 if (newval && newlen) {
2170 if (len > table->maxlen)
2171 len = table->maxlen;
2172 if(copy_from_user(table->data, newval, len))
2174 if (len == table->maxlen)
2176 ((char *) table->data)[len] = 0;
2182 * This function makes sure that all of the integers in the vector
2183 * are between the minimum and maximum values given in the arrays
2184 * table->extra1 and table->extra2, respectively.
2186 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2187 void __user *oldval, size_t __user *oldlenp,
2188 void __user *newval, size_t newlen, void **context)
2191 if (newval && newlen) {
2192 int __user *vec = (int __user *) newval;
2193 int *min = (int *) table->extra1;
2194 int *max = (int *) table->extra2;
2198 if (newlen % sizeof(int) != 0)
2201 if (!table->extra1 && !table->extra2)
2204 if (newlen > table->maxlen)
2205 newlen = table->maxlen;
2206 length = newlen / sizeof(int);
2208 for (i = 0; i < length; i++) {
2210 if (get_user(value, vec + i))
2212 if (min && value < min[i])
2214 if (max && value > max[i])
2221 /* Strategy function to convert jiffies to seconds */
2222 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2223 void __user *oldval, size_t __user *oldlenp,
2224 void __user *newval, size_t newlen, void **context)
2229 if (get_user(olen, oldlenp))
2231 if (olen!=sizeof(int))
2234 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2235 (oldlenp && put_user(sizeof(int),oldlenp)))
2238 if (newval && newlen) {
2240 if (newlen != sizeof(int))
2242 if (get_user(new, (int __user *)newval))
2244 *(int *)(table->data) = new*HZ;
2249 /* Strategy function to convert jiffies to seconds */
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 if (get_user(olen, oldlenp))
2259 if (olen!=sizeof(int))
2262 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2263 (oldlenp && put_user(sizeof(int),oldlenp)))
2266 if (newval && newlen) {
2268 if (newlen != sizeof(int))
2270 if (get_user(new, (int __user *)newval))
2272 *(int *)(table->data) = msecs_to_jiffies(new);
2277 #else /* CONFIG_SYSCTL */
2280 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2285 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2286 void __user *oldval, size_t __user *oldlenp,
2287 void __user *newval, size_t newlen, void **context)
2292 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2293 void __user *oldval, size_t __user *oldlenp,
2294 void __user *newval, size_t newlen, void **context)
2299 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2300 void __user *oldval, size_t __user *oldlenp,
2301 void __user *newval, size_t newlen, void **context)
2306 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2307 void __user *oldval, size_t __user *oldlenp,
2308 void __user *newval, size_t newlen, void **context)
2313 int proc_dostring(ctl_table *table, int write, struct file *filp,
2314 void __user *buffer, size_t *lenp, loff_t *ppos)
2319 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2320 void __user *buffer, size_t *lenp, loff_t *ppos)
2325 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2326 void __user *buffer, size_t *lenp, loff_t *ppos)
2331 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2332 void __user *buffer, size_t *lenp, loff_t *ppos)
2337 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2338 void __user *buffer, size_t *lenp, loff_t *ppos)
2343 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2344 void __user *buffer, size_t *lenp, loff_t *ppos)
2349 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2350 void __user *buffer, size_t *lenp, loff_t *ppos)
2355 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2356 void __user *buffer, size_t *lenp, loff_t *ppos)
2361 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2363 void __user *buffer,
2364 size_t *lenp, loff_t *ppos)
2369 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2375 void unregister_sysctl_table(struct ctl_table_header * table)
2379 #endif /* CONFIG_SYSCTL */
2382 * No sense putting this after each symbol definition, twice,
2383 * exception granted :-)
2385 EXPORT_SYMBOL(proc_dointvec);
2386 EXPORT_SYMBOL(proc_dointvec_jiffies);
2387 EXPORT_SYMBOL(proc_dointvec_minmax);
2388 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2389 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2390 EXPORT_SYMBOL(proc_dostring);
2391 EXPORT_SYMBOL(proc_doulongvec_minmax);
2392 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2393 EXPORT_SYMBOL(register_sysctl_table);
2394 EXPORT_SYMBOL(sysctl_intvec);
2395 EXPORT_SYMBOL(sysctl_jiffies);
2396 EXPORT_SYMBOL(sysctl_ms_jiffies);
2397 EXPORT_SYMBOL(sysctl_string);
2398 EXPORT_SYMBOL(unregister_sysctl_table);