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/module.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/signal.h>
27 #include <linux/proc_fs.h>
28 #include <linux/security.h>
29 #include <linux/ctype.h>
30 #include <linux/kmemcheck.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/kobject.h>
35 #include <linux/net.h>
36 #include <linux/sysrq.h>
37 #include <linux/highuid.h>
38 #include <linux/writeback.h>
39 #include <linux/ratelimit.h>
40 #include <linux/compaction.h>
41 #include <linux/hugetlb.h>
42 #include <linux/initrd.h>
43 #include <linux/key.h>
44 #include <linux/times.h>
45 #include <linux/limits.h>
46 #include <linux/dcache.h>
47 #include <linux/dnotify.h>
48 #include <linux/syscalls.h>
49 #include <linux/vmstat.h>
50 #include <linux/nfs_fs.h>
51 #include <linux/acpi.h>
52 #include <linux/reboot.h>
53 #include <linux/ftrace.h>
54 #include <linux/perf_event.h>
55 #include <linux/kprobes.h>
56 #include <linux/pipe_fs_i.h>
57 #include <linux/oom.h>
59 #include <asm/uaccess.h>
60 #include <asm/processor.h>
64 #include <asm/stacktrace.h>
67 #ifdef CONFIG_BSD_PROCESS_ACCT
68 #include <linux/acct.h>
70 #ifdef CONFIG_RT_MUTEXES
71 #include <linux/rtmutex.h>
73 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
74 #include <linux/lockdep.h>
76 #ifdef CONFIG_CHR_DEV_SG
80 #ifdef CONFIG_LOCKUP_DETECTOR
81 #include <linux/nmi.h>
85 #if defined(CONFIG_SYSCTL)
87 /* External variables not in a header file. */
88 extern int sysctl_overcommit_memory
;
89 extern int sysctl_overcommit_ratio
;
90 extern int max_threads
;
91 extern int core_uses_pid
;
92 extern int suid_dumpable
;
93 extern char core_pattern
[];
94 extern unsigned int core_pipe_limit
;
96 extern int min_free_kbytes
;
97 extern int pid_max_min
, pid_max_max
;
98 extern int sysctl_drop_caches
;
99 extern int percpu_pagelist_fraction
;
100 extern int compat_log
;
101 extern int latencytop_enabled
;
102 extern int sysctl_nr_open_min
, sysctl_nr_open_max
;
104 extern int sysctl_nr_trim_pages
;
107 extern int blk_iopoll_enabled
;
110 /* Constants used for minimum and maximum */
111 #ifdef CONFIG_LOCKUP_DETECTOR
112 static int sixty
= 60;
113 static int neg_one
= -1;
117 static int __maybe_unused one
= 1;
118 static int __maybe_unused two
= 2;
119 static unsigned long one_ul
= 1;
120 static int one_hundred
= 100;
122 static int ten_thousand
= 10000;
125 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
126 static unsigned long dirty_bytes_min
= 2 * PAGE_SIZE
;
128 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
129 static int maxolduid
= 65535;
130 static int minolduid
;
131 static int min_percpu_pagelist_fract
= 8;
133 static int ngroups_max
= NGROUPS_MAX
;
135 #ifdef CONFIG_INOTIFY_USER
136 #include <linux/inotify.h>
139 #include <asm/system.h>
142 #ifdef CONFIG_SPARC64
143 extern int sysctl_tsb_ratio
;
147 extern int pwrsw_enabled
;
148 extern int unaligned_enabled
;
152 #ifdef CONFIG_MATHEMU
153 extern int sysctl_ieee_emulation_warnings
;
155 extern int sysctl_userprocess_debug
;
156 extern int spin_retry
;
160 extern int no_unaligned_warning
;
161 extern int unaligned_dump_stack
;
164 #ifdef CONFIG_PROC_SYSCTL
165 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
166 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
167 static int proc_taint(struct ctl_table
*table
, int write
,
168 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
);
171 #ifdef CONFIG_MAGIC_SYSRQ
172 static int __sysrq_enabled
; /* Note: sysrq code ises it's own private copy */
174 static int sysrq_sysctl_handler(ctl_table
*table
, int write
,
175 void __user
*buffer
, size_t *lenp
,
180 error
= proc_dointvec(table
, write
, buffer
, lenp
, ppos
);
185 sysrq_toggle_support(__sysrq_enabled
);
192 static struct ctl_table root_table
[];
193 static struct ctl_table_root sysctl_table_root
;
194 static struct ctl_table_header root_table_header
= {
196 .ctl_table
= root_table
,
197 .ctl_entry
= LIST_HEAD_INIT(sysctl_table_root
.default_set
.list
),
198 .root
= &sysctl_table_root
,
199 .set
= &sysctl_table_root
.default_set
,
201 static struct ctl_table_root sysctl_table_root
= {
202 .root_list
= LIST_HEAD_INIT(sysctl_table_root
.root_list
),
203 .default_set
.list
= LIST_HEAD_INIT(root_table_header
.ctl_entry
),
206 static struct ctl_table kern_table
[];
207 static struct ctl_table vm_table
[];
208 static struct ctl_table fs_table
[];
209 static struct ctl_table debug_table
[];
210 static struct ctl_table dev_table
[];
211 extern struct ctl_table random_table
[];
213 extern struct ctl_table epoll_table
[];
216 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
217 int sysctl_legacy_va_layout
;
220 /* The default sysctl tables: */
222 static struct ctl_table root_table
[] = {
224 .procname
= "kernel",
241 .child
= debug_table
,
249 * NOTE: do not add new entries to this table unless you have read
250 * Documentation/sysctl/ctl_unnumbered.txt
255 #ifdef CONFIG_SCHED_DEBUG
256 static int min_sched_granularity_ns
= 100000; /* 100 usecs */
257 static int max_sched_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
258 static int min_wakeup_granularity_ns
; /* 0 usecs */
259 static int max_wakeup_granularity_ns
= NSEC_PER_SEC
; /* 1 second */
260 static int min_sched_tunable_scaling
= SCHED_TUNABLESCALING_NONE
;
261 static int max_sched_tunable_scaling
= SCHED_TUNABLESCALING_END
-1;
264 #ifdef CONFIG_COMPACTION
265 static int min_extfrag_threshold
;
266 static int max_extfrag_threshold
= 1000;
269 static struct ctl_table kern_table
[] = {
271 .procname
= "sched_child_runs_first",
272 .data
= &sysctl_sched_child_runs_first
,
273 .maxlen
= sizeof(unsigned int),
275 .proc_handler
= proc_dointvec
,
277 #ifdef CONFIG_SCHED_DEBUG
279 .procname
= "sched_min_granularity_ns",
280 .data
= &sysctl_sched_min_granularity
,
281 .maxlen
= sizeof(unsigned int),
283 .proc_handler
= sched_proc_update_handler
,
284 .extra1
= &min_sched_granularity_ns
,
285 .extra2
= &max_sched_granularity_ns
,
288 .procname
= "sched_latency_ns",
289 .data
= &sysctl_sched_latency
,
290 .maxlen
= sizeof(unsigned int),
292 .proc_handler
= sched_proc_update_handler
,
293 .extra1
= &min_sched_granularity_ns
,
294 .extra2
= &max_sched_granularity_ns
,
297 .procname
= "sched_wakeup_granularity_ns",
298 .data
= &sysctl_sched_wakeup_granularity
,
299 .maxlen
= sizeof(unsigned int),
301 .proc_handler
= sched_proc_update_handler
,
302 .extra1
= &min_wakeup_granularity_ns
,
303 .extra2
= &max_wakeup_granularity_ns
,
306 .procname
= "sched_tunable_scaling",
307 .data
= &sysctl_sched_tunable_scaling
,
308 .maxlen
= sizeof(enum sched_tunable_scaling
),
310 .proc_handler
= sched_proc_update_handler
,
311 .extra1
= &min_sched_tunable_scaling
,
312 .extra2
= &max_sched_tunable_scaling
,
315 .procname
= "sched_migration_cost",
316 .data
= &sysctl_sched_migration_cost
,
317 .maxlen
= sizeof(unsigned int),
319 .proc_handler
= proc_dointvec
,
322 .procname
= "sched_nr_migrate",
323 .data
= &sysctl_sched_nr_migrate
,
324 .maxlen
= sizeof(unsigned int),
326 .proc_handler
= proc_dointvec
,
329 .procname
= "sched_time_avg",
330 .data
= &sysctl_sched_time_avg
,
331 .maxlen
= sizeof(unsigned int),
333 .proc_handler
= proc_dointvec
,
336 .procname
= "sched_shares_window",
337 .data
= &sysctl_sched_shares_window
,
338 .maxlen
= sizeof(unsigned int),
340 .proc_handler
= proc_dointvec
,
343 .procname
= "timer_migration",
344 .data
= &sysctl_timer_migration
,
345 .maxlen
= sizeof(unsigned int),
347 .proc_handler
= proc_dointvec_minmax
,
353 .procname
= "sched_rt_period_us",
354 .data
= &sysctl_sched_rt_period
,
355 .maxlen
= sizeof(unsigned int),
357 .proc_handler
= sched_rt_handler
,
360 .procname
= "sched_rt_runtime_us",
361 .data
= &sysctl_sched_rt_runtime
,
362 .maxlen
= sizeof(int),
364 .proc_handler
= sched_rt_handler
,
367 .procname
= "sched_compat_yield",
368 .data
= &sysctl_sched_compat_yield
,
369 .maxlen
= sizeof(unsigned int),
371 .proc_handler
= proc_dointvec
,
373 #ifdef CONFIG_SCHED_AUTOGROUP
375 .procname
= "sched_autogroup_enabled",
376 .data
= &sysctl_sched_autogroup_enabled
,
377 .maxlen
= sizeof(unsigned int),
379 .proc_handler
= proc_dointvec
,
384 #ifdef CONFIG_PROVE_LOCKING
386 .procname
= "prove_locking",
387 .data
= &prove_locking
,
388 .maxlen
= sizeof(int),
390 .proc_handler
= proc_dointvec
,
393 #ifdef CONFIG_LOCK_STAT
395 .procname
= "lock_stat",
397 .maxlen
= sizeof(int),
399 .proc_handler
= proc_dointvec
,
404 .data
= &panic_timeout
,
405 .maxlen
= sizeof(int),
407 .proc_handler
= proc_dointvec
,
410 .procname
= "core_uses_pid",
411 .data
= &core_uses_pid
,
412 .maxlen
= sizeof(int),
414 .proc_handler
= proc_dointvec
,
417 .procname
= "core_pattern",
418 .data
= core_pattern
,
419 .maxlen
= CORENAME_MAX_SIZE
,
421 .proc_handler
= proc_dostring
,
424 .procname
= "core_pipe_limit",
425 .data
= &core_pipe_limit
,
426 .maxlen
= sizeof(unsigned int),
428 .proc_handler
= proc_dointvec
,
430 #ifdef CONFIG_PROC_SYSCTL
432 .procname
= "tainted",
433 .maxlen
= sizeof(long),
435 .proc_handler
= proc_taint
,
438 #ifdef CONFIG_LATENCYTOP
440 .procname
= "latencytop",
441 .data
= &latencytop_enabled
,
442 .maxlen
= sizeof(int),
444 .proc_handler
= proc_dointvec
,
447 #ifdef CONFIG_BLK_DEV_INITRD
449 .procname
= "real-root-dev",
450 .data
= &real_root_dev
,
451 .maxlen
= sizeof(int),
453 .proc_handler
= proc_dointvec
,
457 .procname
= "print-fatal-signals",
458 .data
= &print_fatal_signals
,
459 .maxlen
= sizeof(int),
461 .proc_handler
= proc_dointvec
,
465 .procname
= "reboot-cmd",
466 .data
= reboot_command
,
469 .proc_handler
= proc_dostring
,
472 .procname
= "stop-a",
473 .data
= &stop_a_enabled
,
474 .maxlen
= sizeof (int),
476 .proc_handler
= proc_dointvec
,
479 .procname
= "scons-poweroff",
480 .data
= &scons_pwroff
,
481 .maxlen
= sizeof (int),
483 .proc_handler
= proc_dointvec
,
486 #ifdef CONFIG_SPARC64
488 .procname
= "tsb-ratio",
489 .data
= &sysctl_tsb_ratio
,
490 .maxlen
= sizeof (int),
492 .proc_handler
= proc_dointvec
,
497 .procname
= "soft-power",
498 .data
= &pwrsw_enabled
,
499 .maxlen
= sizeof (int),
501 .proc_handler
= proc_dointvec
,
504 .procname
= "unaligned-trap",
505 .data
= &unaligned_enabled
,
506 .maxlen
= sizeof (int),
508 .proc_handler
= proc_dointvec
,
512 .procname
= "ctrl-alt-del",
514 .maxlen
= sizeof(int),
516 .proc_handler
= proc_dointvec
,
518 #ifdef CONFIG_FUNCTION_TRACER
520 .procname
= "ftrace_enabled",
521 .data
= &ftrace_enabled
,
522 .maxlen
= sizeof(int),
524 .proc_handler
= ftrace_enable_sysctl
,
527 #ifdef CONFIG_STACK_TRACER
529 .procname
= "stack_tracer_enabled",
530 .data
= &stack_tracer_enabled
,
531 .maxlen
= sizeof(int),
533 .proc_handler
= stack_trace_sysctl
,
536 #ifdef CONFIG_TRACING
538 .procname
= "ftrace_dump_on_oops",
539 .data
= &ftrace_dump_on_oops
,
540 .maxlen
= sizeof(int),
542 .proc_handler
= proc_dointvec
,
545 #ifdef CONFIG_MODULES
547 .procname
= "modprobe",
548 .data
= &modprobe_path
,
549 .maxlen
= KMOD_PATH_LEN
,
551 .proc_handler
= proc_dostring
,
554 .procname
= "modules_disabled",
555 .data
= &modules_disabled
,
556 .maxlen
= sizeof(int),
558 /* only handle a transition from default "0" to "1" */
559 .proc_handler
= proc_dointvec_minmax
,
564 #ifdef CONFIG_HOTPLUG
566 .procname
= "hotplug",
567 .data
= &uevent_helper
,
568 .maxlen
= UEVENT_HELPER_PATH_LEN
,
570 .proc_handler
= proc_dostring
,
573 #ifdef CONFIG_CHR_DEV_SG
575 .procname
= "sg-big-buff",
576 .data
= &sg_big_buff
,
577 .maxlen
= sizeof (int),
579 .proc_handler
= proc_dointvec
,
582 #ifdef CONFIG_BSD_PROCESS_ACCT
586 .maxlen
= 3*sizeof(int),
588 .proc_handler
= proc_dointvec
,
591 #ifdef CONFIG_MAGIC_SYSRQ
594 .data
= &__sysrq_enabled
,
595 .maxlen
= sizeof (int),
597 .proc_handler
= sysrq_sysctl_handler
,
600 #ifdef CONFIG_PROC_SYSCTL
602 .procname
= "cad_pid",
604 .maxlen
= sizeof (int),
606 .proc_handler
= proc_do_cad_pid
,
610 .procname
= "threads-max",
611 .data
= &max_threads
,
612 .maxlen
= sizeof(int),
614 .proc_handler
= proc_dointvec
,
617 .procname
= "random",
619 .child
= random_table
,
622 .procname
= "overflowuid",
623 .data
= &overflowuid
,
624 .maxlen
= sizeof(int),
626 .proc_handler
= proc_dointvec_minmax
,
627 .extra1
= &minolduid
,
628 .extra2
= &maxolduid
,
631 .procname
= "overflowgid",
632 .data
= &overflowgid
,
633 .maxlen
= sizeof(int),
635 .proc_handler
= proc_dointvec_minmax
,
636 .extra1
= &minolduid
,
637 .extra2
= &maxolduid
,
640 #ifdef CONFIG_MATHEMU
642 .procname
= "ieee_emulation_warnings",
643 .data
= &sysctl_ieee_emulation_warnings
,
644 .maxlen
= sizeof(int),
646 .proc_handler
= proc_dointvec
,
650 .procname
= "userprocess_debug",
651 .data
= &show_unhandled_signals
,
652 .maxlen
= sizeof(int),
654 .proc_handler
= proc_dointvec
,
658 .procname
= "pid_max",
660 .maxlen
= sizeof (int),
662 .proc_handler
= proc_dointvec_minmax
,
663 .extra1
= &pid_max_min
,
664 .extra2
= &pid_max_max
,
667 .procname
= "panic_on_oops",
668 .data
= &panic_on_oops
,
669 .maxlen
= sizeof(int),
671 .proc_handler
= proc_dointvec
,
673 #if defined CONFIG_PRINTK
675 .procname
= "printk",
676 .data
= &console_loglevel
,
677 .maxlen
= 4*sizeof(int),
679 .proc_handler
= proc_dointvec
,
682 .procname
= "printk_ratelimit",
683 .data
= &printk_ratelimit_state
.interval
,
684 .maxlen
= sizeof(int),
686 .proc_handler
= proc_dointvec_jiffies
,
689 .procname
= "printk_ratelimit_burst",
690 .data
= &printk_ratelimit_state
.burst
,
691 .maxlen
= sizeof(int),
693 .proc_handler
= proc_dointvec
,
696 .procname
= "printk_delay",
697 .data
= &printk_delay_msec
,
698 .maxlen
= sizeof(int),
700 .proc_handler
= proc_dointvec_minmax
,
702 .extra2
= &ten_thousand
,
705 .procname
= "dmesg_restrict",
706 .data
= &dmesg_restrict
,
707 .maxlen
= sizeof(int),
709 .proc_handler
= proc_dointvec_minmax
,
715 .procname
= "ngroups_max",
716 .data
= &ngroups_max
,
717 .maxlen
= sizeof (int),
719 .proc_handler
= proc_dointvec
,
721 #if defined(CONFIG_LOCKUP_DETECTOR)
723 .procname
= "watchdog",
724 .data
= &watchdog_enabled
,
725 .maxlen
= sizeof (int),
727 .proc_handler
= proc_dowatchdog_enabled
,
730 .procname
= "watchdog_thresh",
731 .data
= &softlockup_thresh
,
732 .maxlen
= sizeof(int),
734 .proc_handler
= proc_dowatchdog_thresh
,
739 .procname
= "softlockup_panic",
740 .data
= &softlockup_panic
,
741 .maxlen
= sizeof(int),
743 .proc_handler
= proc_dointvec_minmax
,
748 .procname
= "nmi_watchdog",
749 .data
= &watchdog_enabled
,
750 .maxlen
= sizeof (int),
752 .proc_handler
= proc_dowatchdog_enabled
,
755 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
757 .procname
= "unknown_nmi_panic",
758 .data
= &unknown_nmi_panic
,
759 .maxlen
= sizeof (int),
761 .proc_handler
= proc_dointvec
,
764 #if defined(CONFIG_X86)
766 .procname
= "panic_on_unrecovered_nmi",
767 .data
= &panic_on_unrecovered_nmi
,
768 .maxlen
= sizeof(int),
770 .proc_handler
= proc_dointvec
,
773 .procname
= "panic_on_io_nmi",
774 .data
= &panic_on_io_nmi
,
775 .maxlen
= sizeof(int),
777 .proc_handler
= proc_dointvec
,
780 .procname
= "bootloader_type",
781 .data
= &bootloader_type
,
782 .maxlen
= sizeof (int),
784 .proc_handler
= proc_dointvec
,
787 .procname
= "bootloader_version",
788 .data
= &bootloader_version
,
789 .maxlen
= sizeof (int),
791 .proc_handler
= proc_dointvec
,
794 .procname
= "kstack_depth_to_print",
795 .data
= &kstack_depth_to_print
,
796 .maxlen
= sizeof(int),
798 .proc_handler
= proc_dointvec
,
801 .procname
= "io_delay_type",
802 .data
= &io_delay_type
,
803 .maxlen
= sizeof(int),
805 .proc_handler
= proc_dointvec
,
808 #if defined(CONFIG_MMU)
810 .procname
= "randomize_va_space",
811 .data
= &randomize_va_space
,
812 .maxlen
= sizeof(int),
814 .proc_handler
= proc_dointvec
,
817 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
819 .procname
= "spin_retry",
821 .maxlen
= sizeof (int),
823 .proc_handler
= proc_dointvec
,
826 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
828 .procname
= "acpi_video_flags",
829 .data
= &acpi_realmode_flags
,
830 .maxlen
= sizeof (unsigned long),
832 .proc_handler
= proc_doulongvec_minmax
,
837 .procname
= "ignore-unaligned-usertrap",
838 .data
= &no_unaligned_warning
,
839 .maxlen
= sizeof (int),
841 .proc_handler
= proc_dointvec
,
844 .procname
= "unaligned-dump-stack",
845 .data
= &unaligned_dump_stack
,
846 .maxlen
= sizeof (int),
848 .proc_handler
= proc_dointvec
,
851 #ifdef CONFIG_DETECT_HUNG_TASK
853 .procname
= "hung_task_panic",
854 .data
= &sysctl_hung_task_panic
,
855 .maxlen
= sizeof(int),
857 .proc_handler
= proc_dointvec_minmax
,
862 .procname
= "hung_task_check_count",
863 .data
= &sysctl_hung_task_check_count
,
864 .maxlen
= sizeof(unsigned long),
866 .proc_handler
= proc_doulongvec_minmax
,
869 .procname
= "hung_task_timeout_secs",
870 .data
= &sysctl_hung_task_timeout_secs
,
871 .maxlen
= sizeof(unsigned long),
873 .proc_handler
= proc_dohung_task_timeout_secs
,
876 .procname
= "hung_task_warnings",
877 .data
= &sysctl_hung_task_warnings
,
878 .maxlen
= sizeof(unsigned long),
880 .proc_handler
= proc_doulongvec_minmax
,
885 .procname
= "compat-log",
887 .maxlen
= sizeof (int),
889 .proc_handler
= proc_dointvec
,
892 #ifdef CONFIG_RT_MUTEXES
894 .procname
= "max_lock_depth",
895 .data
= &max_lock_depth
,
896 .maxlen
= sizeof(int),
898 .proc_handler
= proc_dointvec
,
902 .procname
= "poweroff_cmd",
903 .data
= &poweroff_cmd
,
904 .maxlen
= POWEROFF_CMD_PATH_LEN
,
906 .proc_handler
= proc_dostring
,
912 .child
= key_sysctls
,
915 #ifdef CONFIG_RCU_TORTURE_TEST
917 .procname
= "rcutorture_runnable",
918 .data
= &rcutorture_runnable
,
919 .maxlen
= sizeof(int),
921 .proc_handler
= proc_dointvec
,
924 #ifdef CONFIG_PERF_EVENTS
926 .procname
= "perf_event_paranoid",
927 .data
= &sysctl_perf_event_paranoid
,
928 .maxlen
= sizeof(sysctl_perf_event_paranoid
),
930 .proc_handler
= proc_dointvec
,
933 .procname
= "perf_event_mlock_kb",
934 .data
= &sysctl_perf_event_mlock
,
935 .maxlen
= sizeof(sysctl_perf_event_mlock
),
937 .proc_handler
= proc_dointvec
,
940 .procname
= "perf_event_max_sample_rate",
941 .data
= &sysctl_perf_event_sample_rate
,
942 .maxlen
= sizeof(sysctl_perf_event_sample_rate
),
944 .proc_handler
= proc_dointvec
,
947 #ifdef CONFIG_KMEMCHECK
949 .procname
= "kmemcheck",
950 .data
= &kmemcheck_enabled
,
951 .maxlen
= sizeof(int),
953 .proc_handler
= proc_dointvec
,
958 .procname
= "blk_iopoll",
959 .data
= &blk_iopoll_enabled
,
960 .maxlen
= sizeof(int),
962 .proc_handler
= proc_dointvec
,
966 * NOTE: do not add new entries to this table unless you have read
967 * Documentation/sysctl/ctl_unnumbered.txt
972 static struct ctl_table vm_table
[] = {
974 .procname
= "overcommit_memory",
975 .data
= &sysctl_overcommit_memory
,
976 .maxlen
= sizeof(sysctl_overcommit_memory
),
978 .proc_handler
= proc_dointvec
,
981 .procname
= "panic_on_oom",
982 .data
= &sysctl_panic_on_oom
,
983 .maxlen
= sizeof(sysctl_panic_on_oom
),
985 .proc_handler
= proc_dointvec
,
988 .procname
= "oom_kill_allocating_task",
989 .data
= &sysctl_oom_kill_allocating_task
,
990 .maxlen
= sizeof(sysctl_oom_kill_allocating_task
),
992 .proc_handler
= proc_dointvec
,
995 .procname
= "oom_dump_tasks",
996 .data
= &sysctl_oom_dump_tasks
,
997 .maxlen
= sizeof(sysctl_oom_dump_tasks
),
999 .proc_handler
= proc_dointvec
,
1002 .procname
= "overcommit_ratio",
1003 .data
= &sysctl_overcommit_ratio
,
1004 .maxlen
= sizeof(sysctl_overcommit_ratio
),
1006 .proc_handler
= proc_dointvec
,
1009 .procname
= "page-cluster",
1010 .data
= &page_cluster
,
1011 .maxlen
= sizeof(int),
1013 .proc_handler
= proc_dointvec
,
1016 .procname
= "dirty_background_ratio",
1017 .data
= &dirty_background_ratio
,
1018 .maxlen
= sizeof(dirty_background_ratio
),
1020 .proc_handler
= dirty_background_ratio_handler
,
1022 .extra2
= &one_hundred
,
1025 .procname
= "dirty_background_bytes",
1026 .data
= &dirty_background_bytes
,
1027 .maxlen
= sizeof(dirty_background_bytes
),
1029 .proc_handler
= dirty_background_bytes_handler
,
1033 .procname
= "dirty_ratio",
1034 .data
= &vm_dirty_ratio
,
1035 .maxlen
= sizeof(vm_dirty_ratio
),
1037 .proc_handler
= dirty_ratio_handler
,
1039 .extra2
= &one_hundred
,
1042 .procname
= "dirty_bytes",
1043 .data
= &vm_dirty_bytes
,
1044 .maxlen
= sizeof(vm_dirty_bytes
),
1046 .proc_handler
= dirty_bytes_handler
,
1047 .extra1
= &dirty_bytes_min
,
1050 .procname
= "dirty_writeback_centisecs",
1051 .data
= &dirty_writeback_interval
,
1052 .maxlen
= sizeof(dirty_writeback_interval
),
1054 .proc_handler
= dirty_writeback_centisecs_handler
,
1057 .procname
= "dirty_expire_centisecs",
1058 .data
= &dirty_expire_interval
,
1059 .maxlen
= sizeof(dirty_expire_interval
),
1061 .proc_handler
= proc_dointvec
,
1064 .procname
= "nr_pdflush_threads",
1065 .data
= &nr_pdflush_threads
,
1066 .maxlen
= sizeof nr_pdflush_threads
,
1067 .mode
= 0444 /* read-only*/,
1068 .proc_handler
= proc_dointvec
,
1071 .procname
= "swappiness",
1072 .data
= &vm_swappiness
,
1073 .maxlen
= sizeof(vm_swappiness
),
1075 .proc_handler
= proc_dointvec_minmax
,
1077 .extra2
= &one_hundred
,
1079 #ifdef CONFIG_HUGETLB_PAGE
1081 .procname
= "nr_hugepages",
1083 .maxlen
= sizeof(unsigned long),
1085 .proc_handler
= hugetlb_sysctl_handler
,
1086 .extra1
= (void *)&hugetlb_zero
,
1087 .extra2
= (void *)&hugetlb_infinity
,
1091 .procname
= "nr_hugepages_mempolicy",
1093 .maxlen
= sizeof(unsigned long),
1095 .proc_handler
= &hugetlb_mempolicy_sysctl_handler
,
1096 .extra1
= (void *)&hugetlb_zero
,
1097 .extra2
= (void *)&hugetlb_infinity
,
1101 .procname
= "hugetlb_shm_group",
1102 .data
= &sysctl_hugetlb_shm_group
,
1103 .maxlen
= sizeof(gid_t
),
1105 .proc_handler
= proc_dointvec
,
1108 .procname
= "hugepages_treat_as_movable",
1109 .data
= &hugepages_treat_as_movable
,
1110 .maxlen
= sizeof(int),
1112 .proc_handler
= hugetlb_treat_movable_handler
,
1115 .procname
= "nr_overcommit_hugepages",
1117 .maxlen
= sizeof(unsigned long),
1119 .proc_handler
= hugetlb_overcommit_handler
,
1120 .extra1
= (void *)&hugetlb_zero
,
1121 .extra2
= (void *)&hugetlb_infinity
,
1125 .procname
= "lowmem_reserve_ratio",
1126 .data
= &sysctl_lowmem_reserve_ratio
,
1127 .maxlen
= sizeof(sysctl_lowmem_reserve_ratio
),
1129 .proc_handler
= lowmem_reserve_ratio_sysctl_handler
,
1132 .procname
= "drop_caches",
1133 .data
= &sysctl_drop_caches
,
1134 .maxlen
= sizeof(int),
1136 .proc_handler
= drop_caches_sysctl_handler
,
1138 #ifdef CONFIG_COMPACTION
1140 .procname
= "compact_memory",
1141 .data
= &sysctl_compact_memory
,
1142 .maxlen
= sizeof(int),
1144 .proc_handler
= sysctl_compaction_handler
,
1147 .procname
= "extfrag_threshold",
1148 .data
= &sysctl_extfrag_threshold
,
1149 .maxlen
= sizeof(int),
1151 .proc_handler
= sysctl_extfrag_handler
,
1152 .extra1
= &min_extfrag_threshold
,
1153 .extra2
= &max_extfrag_threshold
,
1156 #endif /* CONFIG_COMPACTION */
1158 .procname
= "min_free_kbytes",
1159 .data
= &min_free_kbytes
,
1160 .maxlen
= sizeof(min_free_kbytes
),
1162 .proc_handler
= min_free_kbytes_sysctl_handler
,
1166 .procname
= "percpu_pagelist_fraction",
1167 .data
= &percpu_pagelist_fraction
,
1168 .maxlen
= sizeof(percpu_pagelist_fraction
),
1170 .proc_handler
= percpu_pagelist_fraction_sysctl_handler
,
1171 .extra1
= &min_percpu_pagelist_fract
,
1175 .procname
= "max_map_count",
1176 .data
= &sysctl_max_map_count
,
1177 .maxlen
= sizeof(sysctl_max_map_count
),
1179 .proc_handler
= proc_dointvec_minmax
,
1184 .procname
= "nr_trim_pages",
1185 .data
= &sysctl_nr_trim_pages
,
1186 .maxlen
= sizeof(sysctl_nr_trim_pages
),
1188 .proc_handler
= proc_dointvec_minmax
,
1193 .procname
= "laptop_mode",
1194 .data
= &laptop_mode
,
1195 .maxlen
= sizeof(laptop_mode
),
1197 .proc_handler
= proc_dointvec_jiffies
,
1200 .procname
= "block_dump",
1201 .data
= &block_dump
,
1202 .maxlen
= sizeof(block_dump
),
1204 .proc_handler
= proc_dointvec
,
1208 .procname
= "vfs_cache_pressure",
1209 .data
= &sysctl_vfs_cache_pressure
,
1210 .maxlen
= sizeof(sysctl_vfs_cache_pressure
),
1212 .proc_handler
= proc_dointvec
,
1215 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1217 .procname
= "legacy_va_layout",
1218 .data
= &sysctl_legacy_va_layout
,
1219 .maxlen
= sizeof(sysctl_legacy_va_layout
),
1221 .proc_handler
= proc_dointvec
,
1227 .procname
= "zone_reclaim_mode",
1228 .data
= &zone_reclaim_mode
,
1229 .maxlen
= sizeof(zone_reclaim_mode
),
1231 .proc_handler
= proc_dointvec
,
1235 .procname
= "min_unmapped_ratio",
1236 .data
= &sysctl_min_unmapped_ratio
,
1237 .maxlen
= sizeof(sysctl_min_unmapped_ratio
),
1239 .proc_handler
= sysctl_min_unmapped_ratio_sysctl_handler
,
1241 .extra2
= &one_hundred
,
1244 .procname
= "min_slab_ratio",
1245 .data
= &sysctl_min_slab_ratio
,
1246 .maxlen
= sizeof(sysctl_min_slab_ratio
),
1248 .proc_handler
= sysctl_min_slab_ratio_sysctl_handler
,
1250 .extra2
= &one_hundred
,
1255 .procname
= "stat_interval",
1256 .data
= &sysctl_stat_interval
,
1257 .maxlen
= sizeof(sysctl_stat_interval
),
1259 .proc_handler
= proc_dointvec_jiffies
,
1264 .procname
= "mmap_min_addr",
1265 .data
= &dac_mmap_min_addr
,
1266 .maxlen
= sizeof(unsigned long),
1268 .proc_handler
= mmap_min_addr_handler
,
1273 .procname
= "numa_zonelist_order",
1274 .data
= &numa_zonelist_order
,
1275 .maxlen
= NUMA_ZONELIST_ORDER_LEN
,
1277 .proc_handler
= numa_zonelist_order_handler
,
1280 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1281 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1283 .procname
= "vdso_enabled",
1284 .data
= &vdso_enabled
,
1285 .maxlen
= sizeof(vdso_enabled
),
1287 .proc_handler
= proc_dointvec
,
1291 #ifdef CONFIG_HIGHMEM
1293 .procname
= "highmem_is_dirtyable",
1294 .data
= &vm_highmem_is_dirtyable
,
1295 .maxlen
= sizeof(vm_highmem_is_dirtyable
),
1297 .proc_handler
= proc_dointvec_minmax
,
1303 .procname
= "scan_unevictable_pages",
1304 .data
= &scan_unevictable_pages
,
1305 .maxlen
= sizeof(scan_unevictable_pages
),
1307 .proc_handler
= scan_unevictable_handler
,
1309 #ifdef CONFIG_MEMORY_FAILURE
1311 .procname
= "memory_failure_early_kill",
1312 .data
= &sysctl_memory_failure_early_kill
,
1313 .maxlen
= sizeof(sysctl_memory_failure_early_kill
),
1315 .proc_handler
= proc_dointvec_minmax
,
1320 .procname
= "memory_failure_recovery",
1321 .data
= &sysctl_memory_failure_recovery
,
1322 .maxlen
= sizeof(sysctl_memory_failure_recovery
),
1324 .proc_handler
= proc_dointvec_minmax
,
1331 * NOTE: do not add new entries to this table unless you have read
1332 * Documentation/sysctl/ctl_unnumbered.txt
1337 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1338 static struct ctl_table binfmt_misc_table
[] = {
1343 static struct ctl_table fs_table
[] = {
1345 .procname
= "inode-nr",
1346 .data
= &inodes_stat
,
1347 .maxlen
= 2*sizeof(int),
1349 .proc_handler
= proc_nr_inodes
,
1352 .procname
= "inode-state",
1353 .data
= &inodes_stat
,
1354 .maxlen
= 7*sizeof(int),
1356 .proc_handler
= proc_nr_inodes
,
1359 .procname
= "file-nr",
1360 .data
= &files_stat
,
1361 .maxlen
= sizeof(files_stat
),
1363 .proc_handler
= proc_nr_files
,
1366 .procname
= "file-max",
1367 .data
= &files_stat
.max_files
,
1368 .maxlen
= sizeof(files_stat
.max_files
),
1370 .proc_handler
= proc_doulongvec_minmax
,
1373 .procname
= "nr_open",
1374 .data
= &sysctl_nr_open
,
1375 .maxlen
= sizeof(int),
1377 .proc_handler
= proc_dointvec_minmax
,
1378 .extra1
= &sysctl_nr_open_min
,
1379 .extra2
= &sysctl_nr_open_max
,
1382 .procname
= "dentry-state",
1383 .data
= &dentry_stat
,
1384 .maxlen
= 6*sizeof(int),
1386 .proc_handler
= proc_nr_dentry
,
1389 .procname
= "overflowuid",
1390 .data
= &fs_overflowuid
,
1391 .maxlen
= sizeof(int),
1393 .proc_handler
= proc_dointvec_minmax
,
1394 .extra1
= &minolduid
,
1395 .extra2
= &maxolduid
,
1398 .procname
= "overflowgid",
1399 .data
= &fs_overflowgid
,
1400 .maxlen
= sizeof(int),
1402 .proc_handler
= proc_dointvec_minmax
,
1403 .extra1
= &minolduid
,
1404 .extra2
= &maxolduid
,
1406 #ifdef CONFIG_FILE_LOCKING
1408 .procname
= "leases-enable",
1409 .data
= &leases_enable
,
1410 .maxlen
= sizeof(int),
1412 .proc_handler
= proc_dointvec
,
1415 #ifdef CONFIG_DNOTIFY
1417 .procname
= "dir-notify-enable",
1418 .data
= &dir_notify_enable
,
1419 .maxlen
= sizeof(int),
1421 .proc_handler
= proc_dointvec
,
1425 #ifdef CONFIG_FILE_LOCKING
1427 .procname
= "lease-break-time",
1428 .data
= &lease_break_time
,
1429 .maxlen
= sizeof(int),
1431 .proc_handler
= proc_dointvec
,
1436 .procname
= "aio-nr",
1438 .maxlen
= sizeof(aio_nr
),
1440 .proc_handler
= proc_doulongvec_minmax
,
1443 .procname
= "aio-max-nr",
1444 .data
= &aio_max_nr
,
1445 .maxlen
= sizeof(aio_max_nr
),
1447 .proc_handler
= proc_doulongvec_minmax
,
1449 #endif /* CONFIG_AIO */
1450 #ifdef CONFIG_INOTIFY_USER
1452 .procname
= "inotify",
1454 .child
= inotify_table
,
1459 .procname
= "epoll",
1461 .child
= epoll_table
,
1466 .procname
= "suid_dumpable",
1467 .data
= &suid_dumpable
,
1468 .maxlen
= sizeof(int),
1470 .proc_handler
= proc_dointvec_minmax
,
1474 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1476 .procname
= "binfmt_misc",
1478 .child
= binfmt_misc_table
,
1482 .procname
= "pipe-max-size",
1483 .data
= &pipe_max_size
,
1484 .maxlen
= sizeof(int),
1486 .proc_handler
= &pipe_proc_fn
,
1487 .extra1
= &pipe_min_size
,
1490 * NOTE: do not add new entries to this table unless you have read
1491 * Documentation/sysctl/ctl_unnumbered.txt
1496 static struct ctl_table debug_table
[] = {
1497 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1498 defined(CONFIG_S390)
1500 .procname
= "exception-trace",
1501 .data
= &show_unhandled_signals
,
1502 .maxlen
= sizeof(int),
1504 .proc_handler
= proc_dointvec
1507 #if defined(CONFIG_OPTPROBES)
1509 .procname
= "kprobes-optimization",
1510 .data
= &sysctl_kprobes_optimization
,
1511 .maxlen
= sizeof(int),
1513 .proc_handler
= proc_kprobes_optimization_handler
,
1521 static struct ctl_table dev_table
[] = {
1525 static DEFINE_SPINLOCK(sysctl_lock
);
1527 /* called under sysctl_lock */
1528 static int use_table(struct ctl_table_header
*p
)
1530 if (unlikely(p
->unregistering
))
1536 /* called under sysctl_lock */
1537 static void unuse_table(struct ctl_table_header
*p
)
1540 if (unlikely(p
->unregistering
))
1541 complete(p
->unregistering
);
1544 /* called under sysctl_lock, will reacquire if has to wait */
1545 static void start_unregistering(struct ctl_table_header
*p
)
1548 * if p->used is 0, nobody will ever touch that entry again;
1549 * we'll eliminate all paths to it before dropping sysctl_lock
1551 if (unlikely(p
->used
)) {
1552 struct completion wait
;
1553 init_completion(&wait
);
1554 p
->unregistering
= &wait
;
1555 spin_unlock(&sysctl_lock
);
1556 wait_for_completion(&wait
);
1557 spin_lock(&sysctl_lock
);
1559 /* anything non-NULL; we'll never dereference it */
1560 p
->unregistering
= ERR_PTR(-EINVAL
);
1563 * do not remove from the list until nobody holds it; walking the
1564 * list in do_sysctl() relies on that.
1566 list_del_init(&p
->ctl_entry
);
1569 void sysctl_head_get(struct ctl_table_header
*head
)
1571 spin_lock(&sysctl_lock
);
1573 spin_unlock(&sysctl_lock
);
1576 void sysctl_head_put(struct ctl_table_header
*head
)
1578 spin_lock(&sysctl_lock
);
1581 spin_unlock(&sysctl_lock
);
1584 struct ctl_table_header
*sysctl_head_grab(struct ctl_table_header
*head
)
1588 spin_lock(&sysctl_lock
);
1589 if (!use_table(head
))
1590 head
= ERR_PTR(-ENOENT
);
1591 spin_unlock(&sysctl_lock
);
1595 void sysctl_head_finish(struct ctl_table_header
*head
)
1599 spin_lock(&sysctl_lock
);
1601 spin_unlock(&sysctl_lock
);
1604 static struct ctl_table_set
*
1605 lookup_header_set(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1607 struct ctl_table_set
*set
= &root
->default_set
;
1609 set
= root
->lookup(root
, namespaces
);
1613 static struct list_head
*
1614 lookup_header_list(struct ctl_table_root
*root
, struct nsproxy
*namespaces
)
1616 struct ctl_table_set
*set
= lookup_header_set(root
, namespaces
);
1620 struct ctl_table_header
*__sysctl_head_next(struct nsproxy
*namespaces
,
1621 struct ctl_table_header
*prev
)
1623 struct ctl_table_root
*root
;
1624 struct list_head
*header_list
;
1625 struct ctl_table_header
*head
;
1626 struct list_head
*tmp
;
1628 spin_lock(&sysctl_lock
);
1631 tmp
= &prev
->ctl_entry
;
1635 tmp
= &root_table_header
.ctl_entry
;
1637 head
= list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
1639 if (!use_table(head
))
1641 spin_unlock(&sysctl_lock
);
1646 header_list
= lookup_header_list(root
, namespaces
);
1647 if (tmp
!= header_list
)
1651 root
= list_entry(root
->root_list
.next
,
1652 struct ctl_table_root
, root_list
);
1653 if (root
== &sysctl_table_root
)
1655 header_list
= lookup_header_list(root
, namespaces
);
1656 } while (list_empty(header_list
));
1657 tmp
= header_list
->next
;
1660 spin_unlock(&sysctl_lock
);
1664 struct ctl_table_header
*sysctl_head_next(struct ctl_table_header
*prev
)
1666 return __sysctl_head_next(current
->nsproxy
, prev
);
1669 void register_sysctl_root(struct ctl_table_root
*root
)
1671 spin_lock(&sysctl_lock
);
1672 list_add_tail(&root
->root_list
, &sysctl_table_root
.root_list
);
1673 spin_unlock(&sysctl_lock
);
1677 * sysctl_perm does NOT grant the superuser all rights automatically, because
1678 * some sysctl variables are readonly even to root.
1681 static int test_perm(int mode
, int op
)
1683 if (!current_euid())
1685 else if (in_egroup_p(0))
1687 if ((op
& ~mode
& (MAY_READ
|MAY_WRITE
|MAY_EXEC
)) == 0)
1692 int sysctl_perm(struct ctl_table_root
*root
, struct ctl_table
*table
, int op
)
1696 if (root
->permissions
)
1697 mode
= root
->permissions(root
, current
->nsproxy
, table
);
1701 return test_perm(mode
, op
);
1704 static void sysctl_set_parent(struct ctl_table
*parent
, struct ctl_table
*table
)
1706 for (; table
->procname
; table
++) {
1707 table
->parent
= parent
;
1709 sysctl_set_parent(table
, table
->child
);
1713 static __init
int sysctl_init(void)
1715 sysctl_set_parent(NULL
, root_table
);
1716 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1717 sysctl_check_table(current
->nsproxy
, root_table
);
1722 core_initcall(sysctl_init
);
1724 static struct ctl_table
*is_branch_in(struct ctl_table
*branch
,
1725 struct ctl_table
*table
)
1727 struct ctl_table
*p
;
1728 const char *s
= branch
->procname
;
1730 /* branch should have named subdirectory as its first element */
1731 if (!s
|| !branch
->child
)
1734 /* ... and nothing else */
1735 if (branch
[1].procname
)
1738 /* table should contain subdirectory with the same name */
1739 for (p
= table
; p
->procname
; p
++) {
1742 if (p
->procname
&& strcmp(p
->procname
, s
) == 0)
1748 /* see if attaching q to p would be an improvement */
1749 static void try_attach(struct ctl_table_header
*p
, struct ctl_table_header
*q
)
1751 struct ctl_table
*to
= p
->ctl_table
, *by
= q
->ctl_table
;
1752 struct ctl_table
*next
;
1754 int not_in_parent
= !p
->attached_by
;
1756 while ((next
= is_branch_in(by
, to
)) != NULL
) {
1757 if (by
== q
->attached_by
)
1759 if (to
== p
->attached_by
)
1765 if (is_better
&& not_in_parent
) {
1766 q
->attached_by
= by
;
1767 q
->attached_to
= to
;
1773 * __register_sysctl_paths - register a sysctl hierarchy
1774 * @root: List of sysctl headers to register on
1775 * @namespaces: Data to compute which lists of sysctl entries are visible
1776 * @path: The path to the directory the sysctl table is in.
1777 * @table: the top-level table structure
1779 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1780 * array. A completely 0 filled entry terminates the table.
1782 * The members of the &struct ctl_table structure are used as follows:
1784 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1785 * enter a sysctl file
1787 * data - a pointer to data for use by proc_handler
1789 * maxlen - the maximum size in bytes of the data
1791 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1793 * child - a pointer to the child sysctl table if this entry is a directory, or
1796 * proc_handler - the text handler routine (described below)
1798 * de - for internal use by the sysctl routines
1800 * extra1, extra2 - extra pointers usable by the proc handler routines
1802 * Leaf nodes in the sysctl tree will be represented by a single file
1803 * under /proc; non-leaf nodes will be represented by directories.
1805 * sysctl(2) can automatically manage read and write requests through
1806 * the sysctl table. The data and maxlen fields of the ctl_table
1807 * struct enable minimal validation of the values being written to be
1808 * performed, and the mode field allows minimal authentication.
1810 * There must be a proc_handler routine for any terminal nodes
1811 * mirrored under /proc/sys (non-terminals are handled by a built-in
1812 * directory handler). Several default handlers are available to
1813 * cover common cases -
1815 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1816 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1817 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1819 * It is the handler's job to read the input buffer from user memory
1820 * and process it. The handler should return 0 on success.
1822 * This routine returns %NULL on a failure to register, and a pointer
1823 * to the table header on success.
1825 struct ctl_table_header
*__register_sysctl_paths(
1826 struct ctl_table_root
*root
,
1827 struct nsproxy
*namespaces
,
1828 const struct ctl_path
*path
, struct ctl_table
*table
)
1830 struct ctl_table_header
*header
;
1831 struct ctl_table
*new, **prevp
;
1832 unsigned int n
, npath
;
1833 struct ctl_table_set
*set
;
1835 /* Count the path components */
1836 for (npath
= 0; path
[npath
].procname
; ++npath
)
1840 * For each path component, allocate a 2-element ctl_table array.
1841 * The first array element will be filled with the sysctl entry
1842 * for this, the second will be the sentinel (procname == 0).
1844 * We allocate everything in one go so that we don't have to
1845 * worry about freeing additional memory in unregister_sysctl_table.
1847 header
= kzalloc(sizeof(struct ctl_table_header
) +
1848 (2 * npath
* sizeof(struct ctl_table
)), GFP_KERNEL
);
1852 new = (struct ctl_table
*) (header
+ 1);
1854 /* Now connect the dots */
1855 prevp
= &header
->ctl_table
;
1856 for (n
= 0; n
< npath
; ++n
, ++path
) {
1857 /* Copy the procname */
1858 new->procname
= path
->procname
;
1862 prevp
= &new->child
;
1867 header
->ctl_table_arg
= table
;
1869 INIT_LIST_HEAD(&header
->ctl_entry
);
1871 header
->unregistering
= NULL
;
1872 header
->root
= root
;
1873 sysctl_set_parent(NULL
, header
->ctl_table
);
1875 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1876 if (sysctl_check_table(namespaces
, header
->ctl_table
)) {
1881 spin_lock(&sysctl_lock
);
1882 header
->set
= lookup_header_set(root
, namespaces
);
1883 header
->attached_by
= header
->ctl_table
;
1884 header
->attached_to
= root_table
;
1885 header
->parent
= &root_table_header
;
1886 for (set
= header
->set
; set
; set
= set
->parent
) {
1887 struct ctl_table_header
*p
;
1888 list_for_each_entry(p
, &set
->list
, ctl_entry
) {
1889 if (p
->unregistering
)
1891 try_attach(p
, header
);
1894 header
->parent
->count
++;
1895 list_add_tail(&header
->ctl_entry
, &header
->set
->list
);
1896 spin_unlock(&sysctl_lock
);
1902 * register_sysctl_table_path - register a sysctl table hierarchy
1903 * @path: The path to the directory the sysctl table is in.
1904 * @table: the top-level table structure
1906 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1907 * array. A completely 0 filled entry terminates the table.
1909 * See __register_sysctl_paths for more details.
1911 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1912 struct ctl_table
*table
)
1914 return __register_sysctl_paths(&sysctl_table_root
, current
->nsproxy
,
1919 * register_sysctl_table - register a sysctl table hierarchy
1920 * @table: the top-level table structure
1922 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1923 * array. A completely 0 filled entry terminates the table.
1925 * See register_sysctl_paths for more details.
1927 struct ctl_table_header
*register_sysctl_table(struct ctl_table
*table
)
1929 static const struct ctl_path null_path
[] = { {} };
1931 return register_sysctl_paths(null_path
, table
);
1935 * unregister_sysctl_table - unregister a sysctl table hierarchy
1936 * @header: the header returned from register_sysctl_table
1938 * Unregisters the sysctl table and all children. proc entries may not
1939 * actually be removed until they are no longer used by anyone.
1941 void unregister_sysctl_table(struct ctl_table_header
* header
)
1948 spin_lock(&sysctl_lock
);
1949 start_unregistering(header
);
1950 if (!--header
->parent
->count
) {
1952 kfree(header
->parent
);
1954 if (!--header
->count
)
1956 spin_unlock(&sysctl_lock
);
1959 int sysctl_is_seen(struct ctl_table_header
*p
)
1961 struct ctl_table_set
*set
= p
->set
;
1963 spin_lock(&sysctl_lock
);
1964 if (p
->unregistering
)
1966 else if (!set
->is_seen
)
1969 res
= set
->is_seen(set
);
1970 spin_unlock(&sysctl_lock
);
1974 void setup_sysctl_set(struct ctl_table_set
*p
,
1975 struct ctl_table_set
*parent
,
1976 int (*is_seen
)(struct ctl_table_set
*))
1978 INIT_LIST_HEAD(&p
->list
);
1979 p
->parent
= parent
? parent
: &sysctl_table_root
.default_set
;
1980 p
->is_seen
= is_seen
;
1983 #else /* !CONFIG_SYSCTL */
1984 struct ctl_table_header
*register_sysctl_table(struct ctl_table
* table
)
1989 struct ctl_table_header
*register_sysctl_paths(const struct ctl_path
*path
,
1990 struct ctl_table
*table
)
1995 void unregister_sysctl_table(struct ctl_table_header
* table
)
1999 void setup_sysctl_set(struct ctl_table_set
*p
,
2000 struct ctl_table_set
*parent
,
2001 int (*is_seen
)(struct ctl_table_set
*))
2005 void sysctl_head_put(struct ctl_table_header
*head
)
2009 #endif /* CONFIG_SYSCTL */
2015 #ifdef CONFIG_PROC_SYSCTL
2017 static int _proc_do_string(void* data
, int maxlen
, int write
,
2018 void __user
*buffer
,
2019 size_t *lenp
, loff_t
*ppos
)
2025 if (!data
|| !maxlen
|| !*lenp
) {
2033 while (len
< *lenp
) {
2034 if (get_user(c
, p
++))
2036 if (c
== 0 || c
== '\n')
2042 if(copy_from_user(data
, buffer
, len
))
2044 ((char *) data
)[len
] = 0;
2062 if(copy_to_user(buffer
, data
, len
))
2065 if(put_user('\n', ((char __user
*) buffer
) + len
))
2076 * proc_dostring - read a string sysctl
2077 * @table: the sysctl table
2078 * @write: %TRUE if this is a write to the sysctl file
2079 * @buffer: the user buffer
2080 * @lenp: the size of the user buffer
2081 * @ppos: file position
2083 * Reads/writes a string from/to the user buffer. If the kernel
2084 * buffer provided is not large enough to hold the string, the
2085 * string is truncated. The copied string is %NULL-terminated.
2086 * If the string is being read by the user process, it is copied
2087 * and a newline '\n' is added. It is truncated if the buffer is
2090 * Returns 0 on success.
2092 int proc_dostring(struct ctl_table
*table
, int write
,
2093 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2095 return _proc_do_string(table
->data
, table
->maxlen
, write
,
2096 buffer
, lenp
, ppos
);
2099 static size_t proc_skip_spaces(char **buf
)
2102 char *tmp
= skip_spaces(*buf
);
2108 static void proc_skip_char(char **buf
, size_t *size
, const char v
)
2118 #define TMPBUFLEN 22
2120 * proc_get_long - reads an ASCII formatted integer from a user buffer
2122 * @buf: a kernel buffer
2123 * @size: size of the kernel buffer
2124 * @val: this is where the number will be stored
2125 * @neg: set to %TRUE if number is negative
2126 * @perm_tr: a vector which contains the allowed trailers
2127 * @perm_tr_len: size of the perm_tr vector
2128 * @tr: pointer to store the trailer character
2130 * In case of success %0 is returned and @buf and @size are updated with
2131 * the amount of bytes read. If @tr is non-NULL and a trailing
2132 * character exists (size is non-zero after returning from this
2133 * function), @tr is updated with the trailing character.
2135 static int proc_get_long(char **buf
, size_t *size
,
2136 unsigned long *val
, bool *neg
,
2137 const char *perm_tr
, unsigned perm_tr_len
, char *tr
)
2140 char *p
, tmp
[TMPBUFLEN
];
2146 if (len
> TMPBUFLEN
- 1)
2147 len
= TMPBUFLEN
- 1;
2149 memcpy(tmp
, *buf
, len
);
2153 if (*p
== '-' && *size
> 1) {
2161 *val
= simple_strtoul(p
, &p
, 0);
2165 /* We don't know if the next char is whitespace thus we may accept
2166 * invalid integers (e.g. 1234...a) or two integers instead of one
2167 * (e.g. 123...1). So lets not allow such large numbers. */
2168 if (len
== TMPBUFLEN
- 1)
2171 if (len
< *size
&& perm_tr_len
&& !memchr(perm_tr
, *p
, perm_tr_len
))
2174 if (tr
&& (len
< *size
))
2184 * proc_put_long - converts an integer to a decimal ASCII formatted string
2186 * @buf: the user buffer
2187 * @size: the size of the user buffer
2188 * @val: the integer to be converted
2189 * @neg: sign of the number, %TRUE for negative
2191 * In case of success %0 is returned and @buf and @size are updated with
2192 * the amount of bytes written.
2194 static int proc_put_long(void __user
**buf
, size_t *size
, unsigned long val
,
2198 char tmp
[TMPBUFLEN
], *p
= tmp
;
2200 sprintf(p
, "%s%lu", neg
? "-" : "", val
);
2204 if (copy_to_user(*buf
, tmp
, len
))
2212 static int proc_put_char(void __user
**buf
, size_t *size
, char c
)
2215 char __user
**buffer
= (char __user
**)buf
;
2216 if (put_user(c
, *buffer
))
2218 (*size
)--, (*buffer
)++;
2224 static int do_proc_dointvec_conv(bool *negp
, unsigned long *lvalp
,
2226 int write
, void *data
)
2229 *valp
= *negp
? -*lvalp
: *lvalp
;
2234 *lvalp
= (unsigned long)-val
;
2237 *lvalp
= (unsigned long)val
;
2243 static const char proc_wspace_sep
[] = { ' ', '\t', '\n' };
2245 static int __do_proc_dointvec(void *tbl_data
, struct ctl_table
*table
,
2246 int write
, void __user
*buffer
,
2247 size_t *lenp
, loff_t
*ppos
,
2248 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2249 int write
, void *data
),
2252 int *i
, vleft
, first
= 1, err
= 0;
2253 unsigned long page
= 0;
2257 if (!tbl_data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2262 i
= (int *) tbl_data
;
2263 vleft
= table
->maxlen
/ sizeof(*i
);
2267 conv
= do_proc_dointvec_conv
;
2270 if (left
> PAGE_SIZE
- 1)
2271 left
= PAGE_SIZE
- 1;
2272 page
= __get_free_page(GFP_TEMPORARY
);
2273 kbuf
= (char *) page
;
2276 if (copy_from_user(kbuf
, buffer
, left
)) {
2283 for (; left
&& vleft
--; i
++, first
=0) {
2288 left
-= proc_skip_spaces(&kbuf
);
2292 err
= proc_get_long(&kbuf
, &left
, &lval
, &neg
,
2294 sizeof(proc_wspace_sep
), NULL
);
2297 if (conv(&neg
, &lval
, i
, 1, data
)) {
2302 if (conv(&neg
, &lval
, i
, 0, data
)) {
2307 err
= proc_put_char(&buffer
, &left
, '\t');
2310 err
= proc_put_long(&buffer
, &left
, lval
, neg
);
2316 if (!write
&& !first
&& left
&& !err
)
2317 err
= proc_put_char(&buffer
, &left
, '\n');
2318 if (write
&& !err
&& left
)
2319 left
-= proc_skip_spaces(&kbuf
);
2324 return err
? : -EINVAL
;
2331 static int do_proc_dointvec(struct ctl_table
*table
, int write
,
2332 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
,
2333 int (*conv
)(bool *negp
, unsigned long *lvalp
, int *valp
,
2334 int write
, void *data
),
2337 return __do_proc_dointvec(table
->data
, table
, write
,
2338 buffer
, lenp
, ppos
, conv
, data
);
2342 * proc_dointvec - read a vector of integers
2343 * @table: the sysctl table
2344 * @write: %TRUE if this is a write to the sysctl file
2345 * @buffer: the user buffer
2346 * @lenp: the size of the user buffer
2347 * @ppos: file position
2349 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2350 * values from/to the user buffer, treated as an ASCII string.
2352 * Returns 0 on success.
2354 int proc_dointvec(struct ctl_table
*table
, int write
,
2355 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2357 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2362 * Taint values can only be increased
2363 * This means we can safely use a temporary.
2365 static int proc_taint(struct ctl_table
*table
, int write
,
2366 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2369 unsigned long tmptaint
= get_taint();
2372 if (write
&& !capable(CAP_SYS_ADMIN
))
2377 err
= proc_doulongvec_minmax(&t
, write
, buffer
, lenp
, ppos
);
2383 * Poor man's atomic or. Not worth adding a primitive
2384 * to everyone's atomic.h for this
2387 for (i
= 0; i
< BITS_PER_LONG
&& tmptaint
>> i
; i
++) {
2388 if ((tmptaint
>> i
) & 1)
2396 struct do_proc_dointvec_minmax_conv_param
{
2401 static int do_proc_dointvec_minmax_conv(bool *negp
, unsigned long *lvalp
,
2403 int write
, void *data
)
2405 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
2407 int val
= *negp
? -*lvalp
: *lvalp
;
2408 if ((param
->min
&& *param
->min
> val
) ||
2409 (param
->max
&& *param
->max
< val
))
2416 *lvalp
= (unsigned long)-val
;
2419 *lvalp
= (unsigned long)val
;
2426 * proc_dointvec_minmax - read a vector of integers with min/max values
2427 * @table: the sysctl table
2428 * @write: %TRUE if this is a write to the sysctl file
2429 * @buffer: the user buffer
2430 * @lenp: the size of the user buffer
2431 * @ppos: file position
2433 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2434 * values from/to the user buffer, treated as an ASCII string.
2436 * This routine will ensure the values are within the range specified by
2437 * table->extra1 (min) and table->extra2 (max).
2439 * Returns 0 on success.
2441 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2442 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2444 struct do_proc_dointvec_minmax_conv_param param
= {
2445 .min
= (int *) table
->extra1
,
2446 .max
= (int *) table
->extra2
,
2448 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2449 do_proc_dointvec_minmax_conv
, ¶m
);
2452 static int __do_proc_doulongvec_minmax(void *data
, struct ctl_table
*table
, int write
,
2453 void __user
*buffer
,
2454 size_t *lenp
, loff_t
*ppos
,
2455 unsigned long convmul
,
2456 unsigned long convdiv
)
2458 unsigned long *i
, *min
, *max
;
2459 int vleft
, first
= 1, err
= 0;
2460 unsigned long page
= 0;
2464 if (!data
|| !table
->maxlen
|| !*lenp
|| (*ppos
&& !write
)) {
2469 i
= (unsigned long *) data
;
2470 min
= (unsigned long *) table
->extra1
;
2471 max
= (unsigned long *) table
->extra2
;
2472 vleft
= table
->maxlen
/ sizeof(unsigned long);
2476 if (left
> PAGE_SIZE
- 1)
2477 left
= PAGE_SIZE
- 1;
2478 page
= __get_free_page(GFP_TEMPORARY
);
2479 kbuf
= (char *) page
;
2482 if (copy_from_user(kbuf
, buffer
, left
)) {
2489 for (; left
&& vleft
--; i
++, first
= 0) {
2495 left
-= proc_skip_spaces(&kbuf
);
2497 err
= proc_get_long(&kbuf
, &left
, &val
, &neg
,
2499 sizeof(proc_wspace_sep
), NULL
);
2504 if ((min
&& val
< *min
) || (max
&& val
> *max
))
2508 val
= convdiv
* (*i
) / convmul
;
2510 err
= proc_put_char(&buffer
, &left
, '\t');
2511 err
= proc_put_long(&buffer
, &left
, val
, false);
2517 if (!write
&& !first
&& left
&& !err
)
2518 err
= proc_put_char(&buffer
, &left
, '\n');
2520 left
-= proc_skip_spaces(&kbuf
);
2525 return err
? : -EINVAL
;
2532 static int do_proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2533 void __user
*buffer
,
2534 size_t *lenp
, loff_t
*ppos
,
2535 unsigned long convmul
,
2536 unsigned long convdiv
)
2538 return __do_proc_doulongvec_minmax(table
->data
, table
, write
,
2539 buffer
, lenp
, ppos
, convmul
, convdiv
);
2543 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2544 * @table: the sysctl table
2545 * @write: %TRUE if this is a write to the sysctl file
2546 * @buffer: the user buffer
2547 * @lenp: the size of the user buffer
2548 * @ppos: file position
2550 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2551 * values from/to the user buffer, treated as an ASCII string.
2553 * This routine will ensure the values are within the range specified by
2554 * table->extra1 (min) and table->extra2 (max).
2556 * Returns 0 on success.
2558 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2559 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2561 return do_proc_doulongvec_minmax(table
, write
, buffer
, lenp
, ppos
, 1l, 1l);
2565 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2566 * @table: the sysctl table
2567 * @write: %TRUE if this is a write to the sysctl file
2568 * @buffer: the user buffer
2569 * @lenp: the size of the user buffer
2570 * @ppos: file position
2572 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2573 * values from/to the user buffer, treated as an ASCII string. The values
2574 * are treated as milliseconds, and converted to jiffies when they are stored.
2576 * This routine will ensure the values are within the range specified by
2577 * table->extra1 (min) and table->extra2 (max).
2579 * Returns 0 on success.
2581 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2582 void __user
*buffer
,
2583 size_t *lenp
, loff_t
*ppos
)
2585 return do_proc_doulongvec_minmax(table
, write
, buffer
,
2586 lenp
, ppos
, HZ
, 1000l);
2590 static int do_proc_dointvec_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2592 int write
, void *data
)
2595 if (*lvalp
> LONG_MAX
/ HZ
)
2597 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
2603 lval
= (unsigned long)-val
;
2606 lval
= (unsigned long)val
;
2613 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2615 int write
, void *data
)
2618 if (USER_HZ
< HZ
&& *lvalp
> (LONG_MAX
/ HZ
) * USER_HZ
)
2620 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2626 lval
= (unsigned long)-val
;
2629 lval
= (unsigned long)val
;
2631 *lvalp
= jiffies_to_clock_t(lval
);
2636 static int do_proc_dointvec_ms_jiffies_conv(bool *negp
, unsigned long *lvalp
,
2638 int write
, void *data
)
2641 *valp
= msecs_to_jiffies(*negp
? -*lvalp
: *lvalp
);
2647 lval
= (unsigned long)-val
;
2650 lval
= (unsigned long)val
;
2652 *lvalp
= jiffies_to_msecs(lval
);
2658 * proc_dointvec_jiffies - read a vector of integers as seconds
2659 * @table: the sysctl table
2660 * @write: %TRUE if this is a write to the sysctl file
2661 * @buffer: the user buffer
2662 * @lenp: the size of the user buffer
2663 * @ppos: file position
2665 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2666 * values from/to the user buffer, treated as an ASCII string.
2667 * The values read are assumed to be in seconds, and are converted into
2670 * Returns 0 on success.
2672 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2673 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2675 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2676 do_proc_dointvec_jiffies_conv
,NULL
);
2680 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2681 * @table: the sysctl table
2682 * @write: %TRUE if this is a write to the sysctl file
2683 * @buffer: the user buffer
2684 * @lenp: the size of the user buffer
2685 * @ppos: pointer to the file position
2687 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2688 * values from/to the user buffer, treated as an ASCII string.
2689 * The values read are assumed to be in 1/USER_HZ seconds, and
2690 * are converted into jiffies.
2692 * Returns 0 on success.
2694 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2695 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2697 return do_proc_dointvec(table
,write
,buffer
,lenp
,ppos
,
2698 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
2702 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2703 * @table: the sysctl table
2704 * @write: %TRUE if this is a write to the sysctl file
2705 * @buffer: the user buffer
2706 * @lenp: the size of the user buffer
2707 * @ppos: file position
2708 * @ppos: the current position in the file
2710 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2711 * values from/to the user buffer, treated as an ASCII string.
2712 * The values read are assumed to be in 1/1000 seconds, and
2713 * are converted into jiffies.
2715 * Returns 0 on success.
2717 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2718 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2720 return do_proc_dointvec(table
, write
, buffer
, lenp
, ppos
,
2721 do_proc_dointvec_ms_jiffies_conv
, NULL
);
2724 static int proc_do_cad_pid(struct ctl_table
*table
, int write
,
2725 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2727 struct pid
*new_pid
;
2731 tmp
= pid_vnr(cad_pid
);
2733 r
= __do_proc_dointvec(&tmp
, table
, write
, buffer
,
2734 lenp
, ppos
, NULL
, NULL
);
2738 new_pid
= find_get_pid(tmp
);
2742 put_pid(xchg(&cad_pid
, new_pid
));
2747 * proc_do_large_bitmap - read/write from/to a large bitmap
2748 * @table: the sysctl table
2749 * @write: %TRUE if this is a write to the sysctl file
2750 * @buffer: the user buffer
2751 * @lenp: the size of the user buffer
2752 * @ppos: file position
2754 * The bitmap is stored at table->data and the bitmap length (in bits)
2757 * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2758 * large bitmaps may be represented in a compact manner. Writing into
2759 * the file will clear the bitmap then update it with the given input.
2761 * Returns 0 on success.
2763 int proc_do_large_bitmap(struct ctl_table
*table
, int write
,
2764 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2768 size_t left
= *lenp
;
2769 unsigned long bitmap_len
= table
->maxlen
;
2770 unsigned long *bitmap
= (unsigned long *) table
->data
;
2771 unsigned long *tmp_bitmap
= NULL
;
2772 char tr_a
[] = { '-', ',', '\n' }, tr_b
[] = { ',', '\n', 0 }, c
;
2774 if (!bitmap_len
|| !left
|| (*ppos
&& !write
)) {
2780 unsigned long page
= 0;
2783 if (left
> PAGE_SIZE
- 1)
2784 left
= PAGE_SIZE
- 1;
2786 page
= __get_free_page(GFP_TEMPORARY
);
2787 kbuf
= (char *) page
;
2790 if (copy_from_user(kbuf
, buffer
, left
)) {
2796 tmp_bitmap
= kzalloc(BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long),
2802 proc_skip_char(&kbuf
, &left
, '\n');
2803 while (!err
&& left
) {
2804 unsigned long val_a
, val_b
;
2807 err
= proc_get_long(&kbuf
, &left
, &val_a
, &neg
, tr_a
,
2811 if (val_a
>= bitmap_len
|| neg
) {
2823 err
= proc_get_long(&kbuf
, &left
, &val_b
,
2824 &neg
, tr_b
, sizeof(tr_b
),
2828 if (val_b
>= bitmap_len
|| neg
||
2839 while (val_a
<= val_b
)
2840 set_bit(val_a
++, tmp_bitmap
);
2843 proc_skip_char(&kbuf
, &left
, '\n');
2847 unsigned long bit_a
, bit_b
= 0;
2850 bit_a
= find_next_bit(bitmap
, bitmap_len
, bit_b
);
2851 if (bit_a
>= bitmap_len
)
2853 bit_b
= find_next_zero_bit(bitmap
, bitmap_len
,
2857 err
= proc_put_char(&buffer
, &left
, ',');
2861 err
= proc_put_long(&buffer
, &left
, bit_a
, false);
2864 if (bit_a
!= bit_b
) {
2865 err
= proc_put_char(&buffer
, &left
, '-');
2868 err
= proc_put_long(&buffer
, &left
, bit_b
, false);
2876 err
= proc_put_char(&buffer
, &left
, '\n');
2882 bitmap_or(bitmap
, bitmap
, tmp_bitmap
, bitmap_len
);
2884 memcpy(bitmap
, tmp_bitmap
,
2885 BITS_TO_LONGS(bitmap_len
) * sizeof(unsigned long));
2897 #else /* CONFIG_PROC_FS */
2899 int proc_dostring(struct ctl_table
*table
, int write
,
2900 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2905 int proc_dointvec(struct ctl_table
*table
, int write
,
2906 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2911 int proc_dointvec_minmax(struct ctl_table
*table
, int write
,
2912 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2917 int proc_dointvec_jiffies(struct ctl_table
*table
, int write
,
2918 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2923 int proc_dointvec_userhz_jiffies(struct ctl_table
*table
, int write
,
2924 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2929 int proc_dointvec_ms_jiffies(struct ctl_table
*table
, int write
,
2930 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2935 int proc_doulongvec_minmax(struct ctl_table
*table
, int write
,
2936 void __user
*buffer
, size_t *lenp
, loff_t
*ppos
)
2941 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table
*table
, int write
,
2942 void __user
*buffer
,
2943 size_t *lenp
, loff_t
*ppos
)
2949 #endif /* CONFIG_PROC_FS */
2952 * No sense putting this after each symbol definition, twice,
2953 * exception granted :-)
2955 EXPORT_SYMBOL(proc_dointvec
);
2956 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2957 EXPORT_SYMBOL(proc_dointvec_minmax
);
2958 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2959 EXPORT_SYMBOL(proc_dointvec_ms_jiffies
);
2960 EXPORT_SYMBOL(proc_dostring
);
2961 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2962 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2963 EXPORT_SYMBOL(register_sysctl_table
);
2964 EXPORT_SYMBOL(register_sysctl_paths
);
2965 EXPORT_SYMBOL(unregister_sysctl_table
);