[PATCH] tty_io.c: keep davej sane
[usb.git] / kernel / sysctl.c
blob8bfa7d117c54fb8ef2b0e5e458caf3303e17b366
1 /*
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
12 * Horn.
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
16 * Wendling.
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>
22 #include <linux/mm.h>
23 #include <linux/swap.h>
24 #include <linux/slab.h>
25 #include <linux/sysctl.h>
26 #include <linux/proc_fs.h>
27 #include <linux/capability.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/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/hugetlb.h>
40 #include <linux/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
52 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
53 void __user *buffer, size_t *lenp, loff_t *ppos);
55 #if defined(CONFIG_SYSCTL)
57 /* External variables not in a header file. */
58 extern int C_A_D;
59 extern int sysctl_overcommit_memory;
60 extern int sysctl_overcommit_ratio;
61 extern int sysctl_panic_on_oom;
62 extern int max_threads;
63 extern int sysrq_enabled;
64 extern int core_uses_pid;
65 extern int suid_dumpable;
66 extern char core_pattern[];
67 extern int cad_pid;
68 extern int pid_max;
69 extern int min_free_kbytes;
70 extern int printk_ratelimit_jiffies;
71 extern int printk_ratelimit_burst;
72 extern int pid_max_min, pid_max_max;
73 extern int sysctl_drop_caches;
74 extern int percpu_pagelist_fraction;
75 extern int compat_log;
77 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
78 int unknown_nmi_panic;
79 int nmi_watchdog_enabled;
80 extern int proc_nmi_enabled(struct ctl_table *, int , struct file *,
81 void __user *, size_t *, loff_t *);
82 #endif
84 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
85 static int maxolduid = 65535;
86 static int minolduid;
87 static int min_percpu_pagelist_fract = 8;
89 static int ngroups_max = NGROUPS_MAX;
91 #ifdef CONFIG_KMOD
92 extern char modprobe_path[];
93 #endif
94 #ifdef CONFIG_CHR_DEV_SG
95 extern int sg_big_buff;
96 #endif
97 #ifdef CONFIG_SYSVIPC
98 extern size_t shm_ctlmax;
99 extern size_t shm_ctlall;
100 extern int shm_ctlmni;
101 extern int msg_ctlmax;
102 extern int msg_ctlmnb;
103 extern int msg_ctlmni;
104 extern int sem_ctls[];
105 #endif
107 #ifdef __sparc__
108 extern char reboot_command [];
109 extern int stop_a_enabled;
110 extern int scons_pwroff;
111 #endif
113 #ifdef __hppa__
114 extern int pwrsw_enabled;
115 extern int unaligned_enabled;
116 #endif
118 #ifdef CONFIG_S390
119 #ifdef CONFIG_MATHEMU
120 extern int sysctl_ieee_emulation_warnings;
121 #endif
122 extern int sysctl_userprocess_debug;
123 extern int spin_retry;
124 #endif
126 extern int sysctl_hz_timer;
128 #ifdef CONFIG_BSD_PROCESS_ACCT
129 extern int acct_parm[];
130 #endif
132 #ifdef CONFIG_IA64
133 extern int no_unaligned_warning;
134 #endif
136 #ifdef CONFIG_RT_MUTEXES
137 extern int max_lock_depth;
138 #endif
140 #ifdef CONFIG_SYSCTL_SYSCALL
141 static int parse_table(int __user *, int, void __user *, size_t __user *,
142 void __user *, size_t, ctl_table *, void **);
143 #endif
145 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
146 void __user *buffer, size_t *lenp, loff_t *ppos);
148 static ctl_table root_table[];
149 static struct ctl_table_header root_table_header =
150 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
152 static ctl_table kern_table[];
153 static ctl_table vm_table[];
154 static ctl_table fs_table[];
155 static ctl_table debug_table[];
156 static ctl_table dev_table[];
157 extern ctl_table random_table[];
158 #ifdef CONFIG_UNIX98_PTYS
159 extern ctl_table pty_table[];
160 #endif
161 #ifdef CONFIG_INOTIFY_USER
162 extern ctl_table inotify_table[];
163 #endif
165 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
166 int sysctl_legacy_va_layout;
167 #endif
169 /* /proc declarations: */
171 #ifdef CONFIG_PROC_SYSCTL
173 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
174 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
175 static int proc_opensys(struct inode *, struct file *);
177 struct file_operations proc_sys_file_operations = {
178 .open = proc_opensys,
179 .read = proc_readsys,
180 .write = proc_writesys,
183 extern struct proc_dir_entry *proc_sys_root;
185 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
186 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
187 #endif
189 /* The default sysctl tables: */
191 static ctl_table root_table[] = {
193 .ctl_name = CTL_KERN,
194 .procname = "kernel",
195 .mode = 0555,
196 .child = kern_table,
199 .ctl_name = CTL_VM,
200 .procname = "vm",
201 .mode = 0555,
202 .child = vm_table,
204 #ifdef CONFIG_NET
206 .ctl_name = CTL_NET,
207 .procname = "net",
208 .mode = 0555,
209 .child = net_table,
211 #endif
213 .ctl_name = CTL_FS,
214 .procname = "fs",
215 .mode = 0555,
216 .child = fs_table,
219 .ctl_name = CTL_DEBUG,
220 .procname = "debug",
221 .mode = 0555,
222 .child = debug_table,
225 .ctl_name = CTL_DEV,
226 .procname = "dev",
227 .mode = 0555,
228 .child = dev_table,
231 { .ctl_name = 0 }
234 static ctl_table kern_table[] = {
236 .ctl_name = KERN_OSTYPE,
237 .procname = "ostype",
238 .data = system_utsname.sysname,
239 .maxlen = sizeof(system_utsname.sysname),
240 .mode = 0444,
241 .proc_handler = &proc_doutsstring,
242 .strategy = &sysctl_string,
245 .ctl_name = KERN_OSRELEASE,
246 .procname = "osrelease",
247 .data = system_utsname.release,
248 .maxlen = sizeof(system_utsname.release),
249 .mode = 0444,
250 .proc_handler = &proc_doutsstring,
251 .strategy = &sysctl_string,
254 .ctl_name = KERN_VERSION,
255 .procname = "version",
256 .data = system_utsname.version,
257 .maxlen = sizeof(system_utsname.version),
258 .mode = 0444,
259 .proc_handler = &proc_doutsstring,
260 .strategy = &sysctl_string,
263 .ctl_name = KERN_NODENAME,
264 .procname = "hostname",
265 .data = system_utsname.nodename,
266 .maxlen = sizeof(system_utsname.nodename),
267 .mode = 0644,
268 .proc_handler = &proc_doutsstring,
269 .strategy = &sysctl_string,
272 .ctl_name = KERN_DOMAINNAME,
273 .procname = "domainname",
274 .data = system_utsname.domainname,
275 .maxlen = sizeof(system_utsname.domainname),
276 .mode = 0644,
277 .proc_handler = &proc_doutsstring,
278 .strategy = &sysctl_string,
281 .ctl_name = KERN_PANIC,
282 .procname = "panic",
283 .data = &panic_timeout,
284 .maxlen = sizeof(int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
289 .ctl_name = KERN_CORE_USES_PID,
290 .procname = "core_uses_pid",
291 .data = &core_uses_pid,
292 .maxlen = sizeof(int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec,
297 .ctl_name = KERN_CORE_PATTERN,
298 .procname = "core_pattern",
299 .data = core_pattern,
300 .maxlen = 64,
301 .mode = 0644,
302 .proc_handler = &proc_dostring,
303 .strategy = &sysctl_string,
306 .ctl_name = KERN_TAINTED,
307 .procname = "tainted",
308 .data = &tainted,
309 .maxlen = sizeof(int),
310 .mode = 0444,
311 .proc_handler = &proc_dointvec,
314 .ctl_name = KERN_CAP_BSET,
315 .procname = "cap-bound",
316 .data = &cap_bset,
317 .maxlen = sizeof(kernel_cap_t),
318 .mode = 0600,
319 .proc_handler = &proc_dointvec_bset,
321 #ifdef CONFIG_BLK_DEV_INITRD
323 .ctl_name = KERN_REALROOTDEV,
324 .procname = "real-root-dev",
325 .data = &real_root_dev,
326 .maxlen = sizeof(int),
327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
330 #endif
331 #ifdef __sparc__
333 .ctl_name = KERN_SPARC_REBOOT,
334 .procname = "reboot-cmd",
335 .data = reboot_command,
336 .maxlen = 256,
337 .mode = 0644,
338 .proc_handler = &proc_dostring,
339 .strategy = &sysctl_string,
342 .ctl_name = KERN_SPARC_STOP_A,
343 .procname = "stop-a",
344 .data = &stop_a_enabled,
345 .maxlen = sizeof (int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
350 .ctl_name = KERN_SPARC_SCONS_PWROFF,
351 .procname = "scons-poweroff",
352 .data = &scons_pwroff,
353 .maxlen = sizeof (int),
354 .mode = 0644,
355 .proc_handler = &proc_dointvec,
357 #endif
358 #ifdef __hppa__
360 .ctl_name = KERN_HPPA_PWRSW,
361 .procname = "soft-power",
362 .data = &pwrsw_enabled,
363 .maxlen = sizeof (int),
364 .mode = 0644,
365 .proc_handler = &proc_dointvec,
368 .ctl_name = KERN_HPPA_UNALIGNED,
369 .procname = "unaligned-trap",
370 .data = &unaligned_enabled,
371 .maxlen = sizeof (int),
372 .mode = 0644,
373 .proc_handler = &proc_dointvec,
375 #endif
377 .ctl_name = KERN_CTLALTDEL,
378 .procname = "ctrl-alt-del",
379 .data = &C_A_D,
380 .maxlen = sizeof(int),
381 .mode = 0644,
382 .proc_handler = &proc_dointvec,
385 .ctl_name = KERN_PRINTK,
386 .procname = "printk",
387 .data = &console_loglevel,
388 .maxlen = 4*sizeof(int),
389 .mode = 0644,
390 .proc_handler = &proc_dointvec,
392 #ifdef CONFIG_KMOD
394 .ctl_name = KERN_MODPROBE,
395 .procname = "modprobe",
396 .data = &modprobe_path,
397 .maxlen = KMOD_PATH_LEN,
398 .mode = 0644,
399 .proc_handler = &proc_dostring,
400 .strategy = &sysctl_string,
402 #endif
403 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
405 .ctl_name = KERN_HOTPLUG,
406 .procname = "hotplug",
407 .data = &uevent_helper,
408 .maxlen = UEVENT_HELPER_PATH_LEN,
409 .mode = 0644,
410 .proc_handler = &proc_dostring,
411 .strategy = &sysctl_string,
413 #endif
414 #ifdef CONFIG_CHR_DEV_SG
416 .ctl_name = KERN_SG_BIG_BUFF,
417 .procname = "sg-big-buff",
418 .data = &sg_big_buff,
419 .maxlen = sizeof (int),
420 .mode = 0444,
421 .proc_handler = &proc_dointvec,
423 #endif
424 #ifdef CONFIG_BSD_PROCESS_ACCT
426 .ctl_name = KERN_ACCT,
427 .procname = "acct",
428 .data = &acct_parm,
429 .maxlen = 3*sizeof(int),
430 .mode = 0644,
431 .proc_handler = &proc_dointvec,
433 #endif
434 #ifdef CONFIG_SYSVIPC
436 .ctl_name = KERN_SHMMAX,
437 .procname = "shmmax",
438 .data = &shm_ctlmax,
439 .maxlen = sizeof (size_t),
440 .mode = 0644,
441 .proc_handler = &proc_doulongvec_minmax,
444 .ctl_name = KERN_SHMALL,
445 .procname = "shmall",
446 .data = &shm_ctlall,
447 .maxlen = sizeof (size_t),
448 .mode = 0644,
449 .proc_handler = &proc_doulongvec_minmax,
452 .ctl_name = KERN_SHMMNI,
453 .procname = "shmmni",
454 .data = &shm_ctlmni,
455 .maxlen = sizeof (int),
456 .mode = 0644,
457 .proc_handler = &proc_dointvec,
460 .ctl_name = KERN_MSGMAX,
461 .procname = "msgmax",
462 .data = &msg_ctlmax,
463 .maxlen = sizeof (int),
464 .mode = 0644,
465 .proc_handler = &proc_dointvec,
468 .ctl_name = KERN_MSGMNI,
469 .procname = "msgmni",
470 .data = &msg_ctlmni,
471 .maxlen = sizeof (int),
472 .mode = 0644,
473 .proc_handler = &proc_dointvec,
476 .ctl_name = KERN_MSGMNB,
477 .procname = "msgmnb",
478 .data = &msg_ctlmnb,
479 .maxlen = sizeof (int),
480 .mode = 0644,
481 .proc_handler = &proc_dointvec,
484 .ctl_name = KERN_SEM,
485 .procname = "sem",
486 .data = &sem_ctls,
487 .maxlen = 4*sizeof (int),
488 .mode = 0644,
489 .proc_handler = &proc_dointvec,
491 #endif
492 #ifdef CONFIG_MAGIC_SYSRQ
494 .ctl_name = KERN_SYSRQ,
495 .procname = "sysrq",
496 .data = &sysrq_enabled,
497 .maxlen = sizeof (int),
498 .mode = 0644,
499 .proc_handler = &proc_dointvec,
501 #endif
503 .ctl_name = KERN_CADPID,
504 .procname = "cad_pid",
505 .data = &cad_pid,
506 .maxlen = sizeof (int),
507 .mode = 0600,
508 .proc_handler = &proc_dointvec,
511 .ctl_name = KERN_MAX_THREADS,
512 .procname = "threads-max",
513 .data = &max_threads,
514 .maxlen = sizeof(int),
515 .mode = 0644,
516 .proc_handler = &proc_dointvec,
519 .ctl_name = KERN_RANDOM,
520 .procname = "random",
521 .mode = 0555,
522 .child = random_table,
524 #ifdef CONFIG_UNIX98_PTYS
526 .ctl_name = KERN_PTY,
527 .procname = "pty",
528 .mode = 0555,
529 .child = pty_table,
531 #endif
533 .ctl_name = KERN_OVERFLOWUID,
534 .procname = "overflowuid",
535 .data = &overflowuid,
536 .maxlen = sizeof(int),
537 .mode = 0644,
538 .proc_handler = &proc_dointvec_minmax,
539 .strategy = &sysctl_intvec,
540 .extra1 = &minolduid,
541 .extra2 = &maxolduid,
544 .ctl_name = KERN_OVERFLOWGID,
545 .procname = "overflowgid",
546 .data = &overflowgid,
547 .maxlen = sizeof(int),
548 .mode = 0644,
549 .proc_handler = &proc_dointvec_minmax,
550 .strategy = &sysctl_intvec,
551 .extra1 = &minolduid,
552 .extra2 = &maxolduid,
554 #ifdef CONFIG_S390
555 #ifdef CONFIG_MATHEMU
557 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
558 .procname = "ieee_emulation_warnings",
559 .data = &sysctl_ieee_emulation_warnings,
560 .maxlen = sizeof(int),
561 .mode = 0644,
562 .proc_handler = &proc_dointvec,
564 #endif
565 #ifdef CONFIG_NO_IDLE_HZ
567 .ctl_name = KERN_HZ_TIMER,
568 .procname = "hz_timer",
569 .data = &sysctl_hz_timer,
570 .maxlen = sizeof(int),
571 .mode = 0644,
572 .proc_handler = &proc_dointvec,
574 #endif
576 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
577 .procname = "userprocess_debug",
578 .data = &sysctl_userprocess_debug,
579 .maxlen = sizeof(int),
580 .mode = 0644,
581 .proc_handler = &proc_dointvec,
583 #endif
585 .ctl_name = KERN_PIDMAX,
586 .procname = "pid_max",
587 .data = &pid_max,
588 .maxlen = sizeof (int),
589 .mode = 0644,
590 .proc_handler = &proc_dointvec_minmax,
591 .strategy = sysctl_intvec,
592 .extra1 = &pid_max_min,
593 .extra2 = &pid_max_max,
596 .ctl_name = KERN_PANIC_ON_OOPS,
597 .procname = "panic_on_oops",
598 .data = &panic_on_oops,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = &proc_dointvec,
604 .ctl_name = KERN_PRINTK_RATELIMIT,
605 .procname = "printk_ratelimit",
606 .data = &printk_ratelimit_jiffies,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec_jiffies,
610 .strategy = &sysctl_jiffies,
613 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
614 .procname = "printk_ratelimit_burst",
615 .data = &printk_ratelimit_burst,
616 .maxlen = sizeof(int),
617 .mode = 0644,
618 .proc_handler = &proc_dointvec,
621 .ctl_name = KERN_NGROUPS_MAX,
622 .procname = "ngroups_max",
623 .data = &ngroups_max,
624 .maxlen = sizeof (int),
625 .mode = 0444,
626 .proc_handler = &proc_dointvec,
628 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
630 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
631 .procname = "unknown_nmi_panic",
632 .data = &unknown_nmi_panic,
633 .maxlen = sizeof (int),
634 .mode = 0644,
635 .proc_handler = &proc_dointvec,
638 .ctl_name = KERN_NMI_WATCHDOG,
639 .procname = "nmi_watchdog",
640 .data = &nmi_watchdog_enabled,
641 .maxlen = sizeof (int),
642 .mode = 0644,
643 .proc_handler = &proc_nmi_enabled,
645 #endif
646 #if defined(CONFIG_X86)
648 .ctl_name = KERN_PANIC_ON_NMI,
649 .procname = "panic_on_unrecovered_nmi",
650 .data = &panic_on_unrecovered_nmi,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec,
656 .ctl_name = KERN_BOOTLOADER_TYPE,
657 .procname = "bootloader_type",
658 .data = &bootloader_type,
659 .maxlen = sizeof (int),
660 .mode = 0444,
661 .proc_handler = &proc_dointvec,
663 #endif
664 #if defined(CONFIG_MMU)
666 .ctl_name = KERN_RANDOMIZE,
667 .procname = "randomize_va_space",
668 .data = &randomize_va_space,
669 .maxlen = sizeof(int),
670 .mode = 0644,
671 .proc_handler = &proc_dointvec,
673 #endif
674 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
676 .ctl_name = KERN_SPIN_RETRY,
677 .procname = "spin_retry",
678 .data = &spin_retry,
679 .maxlen = sizeof (int),
680 .mode = 0644,
681 .proc_handler = &proc_dointvec,
683 #endif
684 #ifdef CONFIG_ACPI_SLEEP
686 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
687 .procname = "acpi_video_flags",
688 .data = &acpi_video_flags,
689 .maxlen = sizeof (unsigned long),
690 .mode = 0644,
691 .proc_handler = &proc_doulongvec_minmax,
693 #endif
694 #ifdef CONFIG_IA64
696 .ctl_name = KERN_IA64_UNALIGNED,
697 .procname = "ignore-unaligned-usertrap",
698 .data = &no_unaligned_warning,
699 .maxlen = sizeof (int),
700 .mode = 0644,
701 .proc_handler = &proc_dointvec,
703 #endif
704 #ifdef CONFIG_COMPAT
706 .ctl_name = KERN_COMPAT_LOG,
707 .procname = "compat-log",
708 .data = &compat_log,
709 .maxlen = sizeof (int),
710 .mode = 0644,
711 .proc_handler = &proc_dointvec,
713 #endif
714 #ifdef CONFIG_RT_MUTEXES
716 .ctl_name = KERN_MAX_LOCK_DEPTH,
717 .procname = "max_lock_depth",
718 .data = &max_lock_depth,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec,
723 #endif
725 { .ctl_name = 0 }
728 /* Constants for minimum and maximum testing in vm_table.
729 We use these as one-element integer vectors. */
730 static int zero;
731 static int one_hundred = 100;
734 static ctl_table vm_table[] = {
736 .ctl_name = VM_OVERCOMMIT_MEMORY,
737 .procname = "overcommit_memory",
738 .data = &sysctl_overcommit_memory,
739 .maxlen = sizeof(sysctl_overcommit_memory),
740 .mode = 0644,
741 .proc_handler = &proc_dointvec,
744 .ctl_name = VM_PANIC_ON_OOM,
745 .procname = "panic_on_oom",
746 .data = &sysctl_panic_on_oom,
747 .maxlen = sizeof(sysctl_panic_on_oom),
748 .mode = 0644,
749 .proc_handler = &proc_dointvec,
752 .ctl_name = VM_OVERCOMMIT_RATIO,
753 .procname = "overcommit_ratio",
754 .data = &sysctl_overcommit_ratio,
755 .maxlen = sizeof(sysctl_overcommit_ratio),
756 .mode = 0644,
757 .proc_handler = &proc_dointvec,
760 .ctl_name = VM_PAGE_CLUSTER,
761 .procname = "page-cluster",
762 .data = &page_cluster,
763 .maxlen = sizeof(int),
764 .mode = 0644,
765 .proc_handler = &proc_dointvec,
768 .ctl_name = VM_DIRTY_BACKGROUND,
769 .procname = "dirty_background_ratio",
770 .data = &dirty_background_ratio,
771 .maxlen = sizeof(dirty_background_ratio),
772 .mode = 0644,
773 .proc_handler = &proc_dointvec_minmax,
774 .strategy = &sysctl_intvec,
775 .extra1 = &zero,
776 .extra2 = &one_hundred,
779 .ctl_name = VM_DIRTY_RATIO,
780 .procname = "dirty_ratio",
781 .data = &vm_dirty_ratio,
782 .maxlen = sizeof(vm_dirty_ratio),
783 .mode = 0644,
784 .proc_handler = &proc_dointvec_minmax,
785 .strategy = &sysctl_intvec,
786 .extra1 = &zero,
787 .extra2 = &one_hundred,
790 .ctl_name = VM_DIRTY_WB_CS,
791 .procname = "dirty_writeback_centisecs",
792 .data = &dirty_writeback_interval,
793 .maxlen = sizeof(dirty_writeback_interval),
794 .mode = 0644,
795 .proc_handler = &dirty_writeback_centisecs_handler,
798 .ctl_name = VM_DIRTY_EXPIRE_CS,
799 .procname = "dirty_expire_centisecs",
800 .data = &dirty_expire_interval,
801 .maxlen = sizeof(dirty_expire_interval),
802 .mode = 0644,
803 .proc_handler = &proc_dointvec_userhz_jiffies,
806 .ctl_name = VM_NR_PDFLUSH_THREADS,
807 .procname = "nr_pdflush_threads",
808 .data = &nr_pdflush_threads,
809 .maxlen = sizeof nr_pdflush_threads,
810 .mode = 0444 /* read-only*/,
811 .proc_handler = &proc_dointvec,
814 .ctl_name = VM_SWAPPINESS,
815 .procname = "swappiness",
816 .data = &vm_swappiness,
817 .maxlen = sizeof(vm_swappiness),
818 .mode = 0644,
819 .proc_handler = &proc_dointvec_minmax,
820 .strategy = &sysctl_intvec,
821 .extra1 = &zero,
822 .extra2 = &one_hundred,
824 #ifdef CONFIG_HUGETLB_PAGE
826 .ctl_name = VM_HUGETLB_PAGES,
827 .procname = "nr_hugepages",
828 .data = &max_huge_pages,
829 .maxlen = sizeof(unsigned long),
830 .mode = 0644,
831 .proc_handler = &hugetlb_sysctl_handler,
832 .extra1 = (void *)&hugetlb_zero,
833 .extra2 = (void *)&hugetlb_infinity,
836 .ctl_name = VM_HUGETLB_GROUP,
837 .procname = "hugetlb_shm_group",
838 .data = &sysctl_hugetlb_shm_group,
839 .maxlen = sizeof(gid_t),
840 .mode = 0644,
841 .proc_handler = &proc_dointvec,
843 #endif
845 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
846 .procname = "lowmem_reserve_ratio",
847 .data = &sysctl_lowmem_reserve_ratio,
848 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
849 .mode = 0644,
850 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
851 .strategy = &sysctl_intvec,
854 .ctl_name = VM_DROP_PAGECACHE,
855 .procname = "drop_caches",
856 .data = &sysctl_drop_caches,
857 .maxlen = sizeof(int),
858 .mode = 0644,
859 .proc_handler = drop_caches_sysctl_handler,
860 .strategy = &sysctl_intvec,
863 .ctl_name = VM_MIN_FREE_KBYTES,
864 .procname = "min_free_kbytes",
865 .data = &min_free_kbytes,
866 .maxlen = sizeof(min_free_kbytes),
867 .mode = 0644,
868 .proc_handler = &min_free_kbytes_sysctl_handler,
869 .strategy = &sysctl_intvec,
870 .extra1 = &zero,
873 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
874 .procname = "percpu_pagelist_fraction",
875 .data = &percpu_pagelist_fraction,
876 .maxlen = sizeof(percpu_pagelist_fraction),
877 .mode = 0644,
878 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
879 .strategy = &sysctl_intvec,
880 .extra1 = &min_percpu_pagelist_fract,
882 #ifdef CONFIG_MMU
884 .ctl_name = VM_MAX_MAP_COUNT,
885 .procname = "max_map_count",
886 .data = &sysctl_max_map_count,
887 .maxlen = sizeof(sysctl_max_map_count),
888 .mode = 0644,
889 .proc_handler = &proc_dointvec
891 #endif
893 .ctl_name = VM_LAPTOP_MODE,
894 .procname = "laptop_mode",
895 .data = &laptop_mode,
896 .maxlen = sizeof(laptop_mode),
897 .mode = 0644,
898 .proc_handler = &proc_dointvec_jiffies,
899 .strategy = &sysctl_jiffies,
902 .ctl_name = VM_BLOCK_DUMP,
903 .procname = "block_dump",
904 .data = &block_dump,
905 .maxlen = sizeof(block_dump),
906 .mode = 0644,
907 .proc_handler = &proc_dointvec,
908 .strategy = &sysctl_intvec,
909 .extra1 = &zero,
912 .ctl_name = VM_VFS_CACHE_PRESSURE,
913 .procname = "vfs_cache_pressure",
914 .data = &sysctl_vfs_cache_pressure,
915 .maxlen = sizeof(sysctl_vfs_cache_pressure),
916 .mode = 0644,
917 .proc_handler = &proc_dointvec,
918 .strategy = &sysctl_intvec,
919 .extra1 = &zero,
921 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
923 .ctl_name = VM_LEGACY_VA_LAYOUT,
924 .procname = "legacy_va_layout",
925 .data = &sysctl_legacy_va_layout,
926 .maxlen = sizeof(sysctl_legacy_va_layout),
927 .mode = 0644,
928 .proc_handler = &proc_dointvec,
929 .strategy = &sysctl_intvec,
930 .extra1 = &zero,
932 #endif
933 #ifdef CONFIG_SWAP
935 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
936 .procname = "swap_token_timeout",
937 .data = &swap_token_default_timeout,
938 .maxlen = sizeof(swap_token_default_timeout),
939 .mode = 0644,
940 .proc_handler = &proc_dointvec_jiffies,
941 .strategy = &sysctl_jiffies,
943 #endif
944 #ifdef CONFIG_NUMA
946 .ctl_name = VM_ZONE_RECLAIM_MODE,
947 .procname = "zone_reclaim_mode",
948 .data = &zone_reclaim_mode,
949 .maxlen = sizeof(zone_reclaim_mode),
950 .mode = 0644,
951 .proc_handler = &proc_dointvec,
952 .strategy = &sysctl_intvec,
953 .extra1 = &zero,
956 .ctl_name = VM_MIN_UNMAPPED,
957 .procname = "min_unmapped_ratio",
958 .data = &sysctl_min_unmapped_ratio,
959 .maxlen = sizeof(sysctl_min_unmapped_ratio),
960 .mode = 0644,
961 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
962 .strategy = &sysctl_intvec,
963 .extra1 = &zero,
964 .extra2 = &one_hundred,
967 .ctl_name = VM_MIN_SLAB,
968 .procname = "min_slab_ratio",
969 .data = &sysctl_min_slab_ratio,
970 .maxlen = sizeof(sysctl_min_slab_ratio),
971 .mode = 0644,
972 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
973 .strategy = &sysctl_intvec,
974 .extra1 = &zero,
975 .extra2 = &one_hundred,
977 #endif
978 #ifdef CONFIG_X86_32
980 .ctl_name = VM_VDSO_ENABLED,
981 .procname = "vdso_enabled",
982 .data = &vdso_enabled,
983 .maxlen = sizeof(vdso_enabled),
984 .mode = 0644,
985 .proc_handler = &proc_dointvec,
986 .strategy = &sysctl_intvec,
987 .extra1 = &zero,
989 #endif
990 { .ctl_name = 0 }
993 static ctl_table fs_table[] = {
995 .ctl_name = FS_NRINODE,
996 .procname = "inode-nr",
997 .data = &inodes_stat,
998 .maxlen = 2*sizeof(int),
999 .mode = 0444,
1000 .proc_handler = &proc_dointvec,
1003 .ctl_name = FS_STATINODE,
1004 .procname = "inode-state",
1005 .data = &inodes_stat,
1006 .maxlen = 7*sizeof(int),
1007 .mode = 0444,
1008 .proc_handler = &proc_dointvec,
1011 .ctl_name = FS_NRFILE,
1012 .procname = "file-nr",
1013 .data = &files_stat,
1014 .maxlen = 3*sizeof(int),
1015 .mode = 0444,
1016 .proc_handler = &proc_nr_files,
1019 .ctl_name = FS_MAXFILE,
1020 .procname = "file-max",
1021 .data = &files_stat.max_files,
1022 .maxlen = sizeof(int),
1023 .mode = 0644,
1024 .proc_handler = &proc_dointvec,
1027 .ctl_name = FS_DENTRY,
1028 .procname = "dentry-state",
1029 .data = &dentry_stat,
1030 .maxlen = 6*sizeof(int),
1031 .mode = 0444,
1032 .proc_handler = &proc_dointvec,
1035 .ctl_name = FS_OVERFLOWUID,
1036 .procname = "overflowuid",
1037 .data = &fs_overflowuid,
1038 .maxlen = sizeof(int),
1039 .mode = 0644,
1040 .proc_handler = &proc_dointvec_minmax,
1041 .strategy = &sysctl_intvec,
1042 .extra1 = &minolduid,
1043 .extra2 = &maxolduid,
1046 .ctl_name = FS_OVERFLOWGID,
1047 .procname = "overflowgid",
1048 .data = &fs_overflowgid,
1049 .maxlen = sizeof(int),
1050 .mode = 0644,
1051 .proc_handler = &proc_dointvec_minmax,
1052 .strategy = &sysctl_intvec,
1053 .extra1 = &minolduid,
1054 .extra2 = &maxolduid,
1057 .ctl_name = FS_LEASES,
1058 .procname = "leases-enable",
1059 .data = &leases_enable,
1060 .maxlen = sizeof(int),
1061 .mode = 0644,
1062 .proc_handler = &proc_dointvec,
1064 #ifdef CONFIG_DNOTIFY
1066 .ctl_name = FS_DIR_NOTIFY,
1067 .procname = "dir-notify-enable",
1068 .data = &dir_notify_enable,
1069 .maxlen = sizeof(int),
1070 .mode = 0644,
1071 .proc_handler = &proc_dointvec,
1073 #endif
1074 #ifdef CONFIG_MMU
1076 .ctl_name = FS_LEASE_TIME,
1077 .procname = "lease-break-time",
1078 .data = &lease_break_time,
1079 .maxlen = sizeof(int),
1080 .mode = 0644,
1081 .proc_handler = &proc_dointvec,
1084 .ctl_name = FS_AIO_NR,
1085 .procname = "aio-nr",
1086 .data = &aio_nr,
1087 .maxlen = sizeof(aio_nr),
1088 .mode = 0444,
1089 .proc_handler = &proc_doulongvec_minmax,
1092 .ctl_name = FS_AIO_MAX_NR,
1093 .procname = "aio-max-nr",
1094 .data = &aio_max_nr,
1095 .maxlen = sizeof(aio_max_nr),
1096 .mode = 0644,
1097 .proc_handler = &proc_doulongvec_minmax,
1099 #ifdef CONFIG_INOTIFY_USER
1101 .ctl_name = FS_INOTIFY,
1102 .procname = "inotify",
1103 .mode = 0555,
1104 .child = inotify_table,
1106 #endif
1107 #endif
1109 .ctl_name = KERN_SETUID_DUMPABLE,
1110 .procname = "suid_dumpable",
1111 .data = &suid_dumpable,
1112 .maxlen = sizeof(int),
1113 .mode = 0644,
1114 .proc_handler = &proc_dointvec,
1116 { .ctl_name = 0 }
1119 static ctl_table debug_table[] = {
1120 { .ctl_name = 0 }
1123 static ctl_table dev_table[] = {
1124 { .ctl_name = 0 }
1127 extern void init_irq_proc (void);
1129 static DEFINE_SPINLOCK(sysctl_lock);
1131 /* called under sysctl_lock */
1132 static int use_table(struct ctl_table_header *p)
1134 if (unlikely(p->unregistering))
1135 return 0;
1136 p->used++;
1137 return 1;
1140 /* called under sysctl_lock */
1141 static void unuse_table(struct ctl_table_header *p)
1143 if (!--p->used)
1144 if (unlikely(p->unregistering))
1145 complete(p->unregistering);
1148 /* called under sysctl_lock, will reacquire if has to wait */
1149 static void start_unregistering(struct ctl_table_header *p)
1152 * if p->used is 0, nobody will ever touch that entry again;
1153 * we'll eliminate all paths to it before dropping sysctl_lock
1155 if (unlikely(p->used)) {
1156 struct completion wait;
1157 init_completion(&wait);
1158 p->unregistering = &wait;
1159 spin_unlock(&sysctl_lock);
1160 wait_for_completion(&wait);
1161 spin_lock(&sysctl_lock);
1164 * do not remove from the list until nobody holds it; walking the
1165 * list in do_sysctl() relies on that.
1167 list_del_init(&p->ctl_entry);
1170 void __init sysctl_init(void)
1172 #ifdef CONFIG_PROC_SYSCTL
1173 register_proc_table(root_table, proc_sys_root, &root_table_header);
1174 init_irq_proc();
1175 #endif
1178 #ifdef CONFIG_SYSCTL_SYSCALL
1179 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1180 void __user *newval, size_t newlen)
1182 struct list_head *tmp;
1183 int error = -ENOTDIR;
1185 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1186 return -ENOTDIR;
1187 if (oldval) {
1188 int old_len;
1189 if (!oldlenp || get_user(old_len, oldlenp))
1190 return -EFAULT;
1192 spin_lock(&sysctl_lock);
1193 tmp = &root_table_header.ctl_entry;
1194 do {
1195 struct ctl_table_header *head =
1196 list_entry(tmp, struct ctl_table_header, ctl_entry);
1197 void *context = NULL;
1199 if (!use_table(head))
1200 continue;
1202 spin_unlock(&sysctl_lock);
1204 error = parse_table(name, nlen, oldval, oldlenp,
1205 newval, newlen, head->ctl_table,
1206 &context);
1207 kfree(context);
1209 spin_lock(&sysctl_lock);
1210 unuse_table(head);
1211 if (error != -ENOTDIR)
1212 break;
1213 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1214 spin_unlock(&sysctl_lock);
1215 return error;
1218 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1220 struct __sysctl_args tmp;
1221 int error;
1223 if (copy_from_user(&tmp, args, sizeof(tmp)))
1224 return -EFAULT;
1226 lock_kernel();
1227 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1228 tmp.newval, tmp.newlen);
1229 unlock_kernel();
1230 return error;
1232 #endif /* CONFIG_SYSCTL_SYSCALL */
1235 * ctl_perm does NOT grant the superuser all rights automatically, because
1236 * some sysctl variables are readonly even to root.
1239 static int test_perm(int mode, int op)
1241 if (!current->euid)
1242 mode >>= 6;
1243 else if (in_egroup_p(0))
1244 mode >>= 3;
1245 if ((mode & op & 0007) == op)
1246 return 0;
1247 return -EACCES;
1250 static inline int ctl_perm(ctl_table *table, int op)
1252 int error;
1253 error = security_sysctl(table, op);
1254 if (error)
1255 return error;
1256 return test_perm(table->mode, op);
1259 #ifdef CONFIG_SYSCTL_SYSCALL
1260 static int parse_table(int __user *name, int nlen,
1261 void __user *oldval, size_t __user *oldlenp,
1262 void __user *newval, size_t newlen,
1263 ctl_table *table, void **context)
1265 int n;
1266 repeat:
1267 if (!nlen)
1268 return -ENOTDIR;
1269 if (get_user(n, name))
1270 return -EFAULT;
1271 for ( ; table->ctl_name; table++) {
1272 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1273 int error;
1274 if (table->child) {
1275 if (ctl_perm(table, 001))
1276 return -EPERM;
1277 if (table->strategy) {
1278 error = table->strategy(
1279 table, name, nlen,
1280 oldval, oldlenp,
1281 newval, newlen, context);
1282 if (error)
1283 return error;
1285 name++;
1286 nlen--;
1287 table = table->child;
1288 goto repeat;
1290 error = do_sysctl_strategy(table, name, nlen,
1291 oldval, oldlenp,
1292 newval, newlen, context);
1293 return error;
1296 return -ENOTDIR;
1299 /* Perform the actual read/write of a sysctl table entry. */
1300 int do_sysctl_strategy (ctl_table *table,
1301 int __user *name, int nlen,
1302 void __user *oldval, size_t __user *oldlenp,
1303 void __user *newval, size_t newlen, void **context)
1305 int op = 0, rc;
1306 size_t len;
1308 if (oldval)
1309 op |= 004;
1310 if (newval)
1311 op |= 002;
1312 if (ctl_perm(table, op))
1313 return -EPERM;
1315 if (table->strategy) {
1316 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1317 newval, newlen, context);
1318 if (rc < 0)
1319 return rc;
1320 if (rc > 0)
1321 return 0;
1324 /* If there is no strategy routine, or if the strategy returns
1325 * zero, proceed with automatic r/w */
1326 if (table->data && table->maxlen) {
1327 if (oldval && oldlenp) {
1328 if (get_user(len, oldlenp))
1329 return -EFAULT;
1330 if (len) {
1331 if (len > table->maxlen)
1332 len = table->maxlen;
1333 if(copy_to_user(oldval, table->data, len))
1334 return -EFAULT;
1335 if(put_user(len, oldlenp))
1336 return -EFAULT;
1339 if (newval && newlen) {
1340 len = newlen;
1341 if (len > table->maxlen)
1342 len = table->maxlen;
1343 if(copy_from_user(table->data, newval, len))
1344 return -EFAULT;
1347 return 0;
1349 #endif /* CONFIG_SYSCTL_SYSCALL */
1352 * register_sysctl_table - register a sysctl hierarchy
1353 * @table: the top-level table structure
1354 * @insert_at_head: whether the entry should be inserted in front or at the end
1356 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1357 * array. An entry with a ctl_name of 0 terminates the table.
1359 * The members of the &ctl_table structure are used as follows:
1361 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1362 * must be unique within that level of sysctl
1364 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1365 * enter a sysctl file
1367 * data - a pointer to data for use by proc_handler
1369 * maxlen - the maximum size in bytes of the data
1371 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1373 * child - a pointer to the child sysctl table if this entry is a directory, or
1374 * %NULL.
1376 * proc_handler - the text handler routine (described below)
1378 * strategy - the strategy routine (described below)
1380 * de - for internal use by the sysctl routines
1382 * extra1, extra2 - extra pointers usable by the proc handler routines
1384 * Leaf nodes in the sysctl tree will be represented by a single file
1385 * under /proc; non-leaf nodes will be represented by directories.
1387 * sysctl(2) can automatically manage read and write requests through
1388 * the sysctl table. The data and maxlen fields of the ctl_table
1389 * struct enable minimal validation of the values being written to be
1390 * performed, and the mode field allows minimal authentication.
1392 * More sophisticated management can be enabled by the provision of a
1393 * strategy routine with the table entry. This will be called before
1394 * any automatic read or write of the data is performed.
1396 * The strategy routine may return
1398 * < 0 - Error occurred (error is passed to user process)
1400 * 0 - OK - proceed with automatic read or write.
1402 * > 0 - OK - read or write has been done by the strategy routine, so
1403 * return immediately.
1405 * There must be a proc_handler routine for any terminal nodes
1406 * mirrored under /proc/sys (non-terminals are handled by a built-in
1407 * directory handler). Several default handlers are available to
1408 * cover common cases -
1410 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1411 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1412 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1414 * It is the handler's job to read the input buffer from user memory
1415 * and process it. The handler should return 0 on success.
1417 * This routine returns %NULL on a failure to register, and a pointer
1418 * to the table header on success.
1420 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1421 int insert_at_head)
1423 struct ctl_table_header *tmp;
1424 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1425 if (!tmp)
1426 return NULL;
1427 tmp->ctl_table = table;
1428 INIT_LIST_HEAD(&tmp->ctl_entry);
1429 tmp->used = 0;
1430 tmp->unregistering = NULL;
1431 spin_lock(&sysctl_lock);
1432 if (insert_at_head)
1433 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1434 else
1435 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1436 spin_unlock(&sysctl_lock);
1437 #ifdef CONFIG_PROC_SYSCTL
1438 register_proc_table(table, proc_sys_root, tmp);
1439 #endif
1440 return tmp;
1444 * unregister_sysctl_table - unregister a sysctl table hierarchy
1445 * @header: the header returned from register_sysctl_table
1447 * Unregisters the sysctl table and all children. proc entries may not
1448 * actually be removed until they are no longer used by anyone.
1450 void unregister_sysctl_table(struct ctl_table_header * header)
1452 might_sleep();
1453 spin_lock(&sysctl_lock);
1454 start_unregistering(header);
1455 #ifdef CONFIG_PROC_SYSCTL
1456 unregister_proc_table(header->ctl_table, proc_sys_root);
1457 #endif
1458 spin_unlock(&sysctl_lock);
1459 kfree(header);
1462 #else /* !CONFIG_SYSCTL */
1463 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1464 int insert_at_head)
1466 return NULL;
1469 void unregister_sysctl_table(struct ctl_table_header * table)
1473 #endif /* CONFIG_SYSCTL */
1476 * /proc/sys support
1479 #ifdef CONFIG_PROC_SYSCTL
1481 /* Scan the sysctl entries in table and add them all into /proc */
1482 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1484 struct proc_dir_entry *de;
1485 int len;
1486 mode_t mode;
1488 for (; table->ctl_name; table++) {
1489 /* Can't do anything without a proc name. */
1490 if (!table->procname)
1491 continue;
1492 /* Maybe we can't do anything with it... */
1493 if (!table->proc_handler && !table->child) {
1494 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1495 table->procname);
1496 continue;
1499 len = strlen(table->procname);
1500 mode = table->mode;
1502 de = NULL;
1503 if (table->proc_handler)
1504 mode |= S_IFREG;
1505 else {
1506 mode |= S_IFDIR;
1507 for (de = root->subdir; de; de = de->next) {
1508 if (proc_match(len, table->procname, de))
1509 break;
1511 /* If the subdir exists already, de is non-NULL */
1514 if (!de) {
1515 de = create_proc_entry(table->procname, mode, root);
1516 if (!de)
1517 continue;
1518 de->set = set;
1519 de->data = (void *) table;
1520 if (table->proc_handler)
1521 de->proc_fops = &proc_sys_file_operations;
1523 table->de = de;
1524 if (de->mode & S_IFDIR)
1525 register_proc_table(table->child, de, set);
1530 * Unregister a /proc sysctl table and any subdirectories.
1532 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1534 struct proc_dir_entry *de;
1535 for (; table->ctl_name; table++) {
1536 if (!(de = table->de))
1537 continue;
1538 if (de->mode & S_IFDIR) {
1539 if (!table->child) {
1540 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1541 continue;
1543 unregister_proc_table(table->child, de);
1545 /* Don't unregister directories which still have entries.. */
1546 if (de->subdir)
1547 continue;
1551 * In any case, mark the entry as goner; we'll keep it
1552 * around if it's busy, but we'll know to do nothing with
1553 * its fields. We are under sysctl_lock here.
1555 de->data = NULL;
1557 /* Don't unregister proc entries that are still being used.. */
1558 if (atomic_read(&de->count))
1559 continue;
1561 table->de = NULL;
1562 remove_proc_entry(table->procname, root);
1566 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1567 size_t count, loff_t *ppos)
1569 int op;
1570 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1571 struct ctl_table *table;
1572 size_t res;
1573 ssize_t error = -ENOTDIR;
1575 spin_lock(&sysctl_lock);
1576 if (de && de->data && use_table(de->set)) {
1578 * at that point we know that sysctl was not unregistered
1579 * and won't be until we finish
1581 spin_unlock(&sysctl_lock);
1582 table = (struct ctl_table *) de->data;
1583 if (!table || !table->proc_handler)
1584 goto out;
1585 error = -EPERM;
1586 op = (write ? 002 : 004);
1587 if (ctl_perm(table, op))
1588 goto out;
1590 /* careful: calling conventions are nasty here */
1591 res = count;
1592 error = (*table->proc_handler)(table, write, file,
1593 buf, &res, ppos);
1594 if (!error)
1595 error = res;
1596 out:
1597 spin_lock(&sysctl_lock);
1598 unuse_table(de->set);
1600 spin_unlock(&sysctl_lock);
1601 return error;
1604 static int proc_opensys(struct inode *inode, struct file *file)
1606 if (file->f_mode & FMODE_WRITE) {
1608 * sysctl entries that are not writable,
1609 * are _NOT_ writable, capabilities or not.
1611 if (!(inode->i_mode & S_IWUSR))
1612 return -EPERM;
1615 return 0;
1618 static ssize_t proc_readsys(struct file * file, char __user * buf,
1619 size_t count, loff_t *ppos)
1621 return do_rw_proc(0, file, buf, count, ppos);
1624 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1625 size_t count, loff_t *ppos)
1627 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1631 * proc_dostring - read a string sysctl
1632 * @table: the sysctl table
1633 * @write: %TRUE if this is a write to the sysctl file
1634 * @filp: the file structure
1635 * @buffer: the user buffer
1636 * @lenp: the size of the user buffer
1637 * @ppos: file position
1639 * Reads/writes a string from/to the user buffer. If the kernel
1640 * buffer provided is not large enough to hold the string, the
1641 * string is truncated. The copied string is %NULL-terminated.
1642 * If the string is being read by the user process, it is copied
1643 * and a newline '\n' is added. It is truncated if the buffer is
1644 * not large enough.
1646 * Returns 0 on success.
1648 int proc_dostring(ctl_table *table, int write, struct file *filp,
1649 void __user *buffer, size_t *lenp, loff_t *ppos)
1651 size_t len;
1652 char __user *p;
1653 char c;
1655 if (!table->data || !table->maxlen || !*lenp ||
1656 (*ppos && !write)) {
1657 *lenp = 0;
1658 return 0;
1661 if (write) {
1662 len = 0;
1663 p = buffer;
1664 while (len < *lenp) {
1665 if (get_user(c, p++))
1666 return -EFAULT;
1667 if (c == 0 || c == '\n')
1668 break;
1669 len++;
1671 if (len >= table->maxlen)
1672 len = table->maxlen-1;
1673 if(copy_from_user(table->data, buffer, len))
1674 return -EFAULT;
1675 ((char *) table->data)[len] = 0;
1676 *ppos += *lenp;
1677 } else {
1678 len = strlen(table->data);
1679 if (len > table->maxlen)
1680 len = table->maxlen;
1681 if (len > *lenp)
1682 len = *lenp;
1683 if (len)
1684 if(copy_to_user(buffer, table->data, len))
1685 return -EFAULT;
1686 if (len < *lenp) {
1687 if(put_user('\n', ((char __user *) buffer) + len))
1688 return -EFAULT;
1689 len++;
1691 *lenp = len;
1692 *ppos += len;
1694 return 0;
1698 * Special case of dostring for the UTS structure. This has locks
1699 * to observe. Should this be in kernel/sys.c ????
1702 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1703 void __user *buffer, size_t *lenp, loff_t *ppos)
1705 int r;
1707 if (!write) {
1708 down_read(&uts_sem);
1709 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1710 up_read(&uts_sem);
1711 } else {
1712 down_write(&uts_sem);
1713 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1714 up_write(&uts_sem);
1716 return r;
1719 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1720 int *valp,
1721 int write, void *data)
1723 if (write) {
1724 *valp = *negp ? -*lvalp : *lvalp;
1725 } else {
1726 int val = *valp;
1727 if (val < 0) {
1728 *negp = -1;
1729 *lvalp = (unsigned long)-val;
1730 } else {
1731 *negp = 0;
1732 *lvalp = (unsigned long)val;
1735 return 0;
1738 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1739 void __user *buffer, size_t *lenp, loff_t *ppos,
1740 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1741 int write, void *data),
1742 void *data)
1744 #define TMPBUFLEN 21
1745 int *i, vleft, first=1, neg, val;
1746 unsigned long lval;
1747 size_t left, len;
1749 char buf[TMPBUFLEN], *p;
1750 char __user *s = buffer;
1752 if (!table->data || !table->maxlen || !*lenp ||
1753 (*ppos && !write)) {
1754 *lenp = 0;
1755 return 0;
1758 i = (int *) table->data;
1759 vleft = table->maxlen / sizeof(*i);
1760 left = *lenp;
1762 if (!conv)
1763 conv = do_proc_dointvec_conv;
1765 for (; left && vleft--; i++, first=0) {
1766 if (write) {
1767 while (left) {
1768 char c;
1769 if (get_user(c, s))
1770 return -EFAULT;
1771 if (!isspace(c))
1772 break;
1773 left--;
1774 s++;
1776 if (!left)
1777 break;
1778 neg = 0;
1779 len = left;
1780 if (len > sizeof(buf) - 1)
1781 len = sizeof(buf) - 1;
1782 if (copy_from_user(buf, s, len))
1783 return -EFAULT;
1784 buf[len] = 0;
1785 p = buf;
1786 if (*p == '-' && left > 1) {
1787 neg = 1;
1788 left--, p++;
1790 if (*p < '0' || *p > '9')
1791 break;
1793 lval = simple_strtoul(p, &p, 0);
1795 len = p-buf;
1796 if ((len < left) && *p && !isspace(*p))
1797 break;
1798 if (neg)
1799 val = -val;
1800 s += len;
1801 left -= len;
1803 if (conv(&neg, &lval, i, 1, data))
1804 break;
1805 } else {
1806 p = buf;
1807 if (!first)
1808 *p++ = '\t';
1810 if (conv(&neg, &lval, i, 0, data))
1811 break;
1813 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1814 len = strlen(buf);
1815 if (len > left)
1816 len = left;
1817 if(copy_to_user(s, buf, len))
1818 return -EFAULT;
1819 left -= len;
1820 s += len;
1824 if (!write && !first && left) {
1825 if(put_user('\n', s))
1826 return -EFAULT;
1827 left--, s++;
1829 if (write) {
1830 while (left) {
1831 char c;
1832 if (get_user(c, s++))
1833 return -EFAULT;
1834 if (!isspace(c))
1835 break;
1836 left--;
1839 if (write && first)
1840 return -EINVAL;
1841 *lenp -= left;
1842 *ppos += *lenp;
1843 return 0;
1844 #undef TMPBUFLEN
1848 * proc_dointvec - read a vector of integers
1849 * @table: the sysctl table
1850 * @write: %TRUE if this is a write to the sysctl file
1851 * @filp: the file structure
1852 * @buffer: the user buffer
1853 * @lenp: the size of the user buffer
1854 * @ppos: file position
1856 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1857 * values from/to the user buffer, treated as an ASCII string.
1859 * Returns 0 on success.
1861 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1862 void __user *buffer, size_t *lenp, loff_t *ppos)
1864 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1865 NULL,NULL);
1868 #define OP_SET 0
1869 #define OP_AND 1
1870 #define OP_OR 2
1871 #define OP_MAX 3
1872 #define OP_MIN 4
1874 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1875 int *valp,
1876 int write, void *data)
1878 int op = *(int *)data;
1879 if (write) {
1880 int val = *negp ? -*lvalp : *lvalp;
1881 switch(op) {
1882 case OP_SET: *valp = val; break;
1883 case OP_AND: *valp &= val; break;
1884 case OP_OR: *valp |= val; break;
1885 case OP_MAX: if(*valp < val)
1886 *valp = val;
1887 break;
1888 case OP_MIN: if(*valp > val)
1889 *valp = val;
1890 break;
1892 } else {
1893 int val = *valp;
1894 if (val < 0) {
1895 *negp = -1;
1896 *lvalp = (unsigned long)-val;
1897 } else {
1898 *negp = 0;
1899 *lvalp = (unsigned long)val;
1902 return 0;
1906 * init may raise the set.
1909 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1910 void __user *buffer, size_t *lenp, loff_t *ppos)
1912 int op;
1914 if (!capable(CAP_SYS_MODULE)) {
1915 return -EPERM;
1918 op = (current->pid == 1) ? OP_SET : OP_AND;
1919 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1920 do_proc_dointvec_bset_conv,&op);
1923 struct do_proc_dointvec_minmax_conv_param {
1924 int *min;
1925 int *max;
1928 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1929 int *valp,
1930 int write, void *data)
1932 struct do_proc_dointvec_minmax_conv_param *param = data;
1933 if (write) {
1934 int val = *negp ? -*lvalp : *lvalp;
1935 if ((param->min && *param->min > val) ||
1936 (param->max && *param->max < val))
1937 return -EINVAL;
1938 *valp = val;
1939 } else {
1940 int val = *valp;
1941 if (val < 0) {
1942 *negp = -1;
1943 *lvalp = (unsigned long)-val;
1944 } else {
1945 *negp = 0;
1946 *lvalp = (unsigned long)val;
1949 return 0;
1953 * proc_dointvec_minmax - read a vector of integers with min/max values
1954 * @table: the sysctl table
1955 * @write: %TRUE if this is a write to the sysctl file
1956 * @filp: the file structure
1957 * @buffer: the user buffer
1958 * @lenp: the size of the user buffer
1959 * @ppos: file position
1961 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1962 * values from/to the user buffer, treated as an ASCII string.
1964 * This routine will ensure the values are within the range specified by
1965 * table->extra1 (min) and table->extra2 (max).
1967 * Returns 0 on success.
1969 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1970 void __user *buffer, size_t *lenp, loff_t *ppos)
1972 struct do_proc_dointvec_minmax_conv_param param = {
1973 .min = (int *) table->extra1,
1974 .max = (int *) table->extra2,
1976 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1977 do_proc_dointvec_minmax_conv, &param);
1980 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1981 struct file *filp,
1982 void __user *buffer,
1983 size_t *lenp, loff_t *ppos,
1984 unsigned long convmul,
1985 unsigned long convdiv)
1987 #define TMPBUFLEN 21
1988 unsigned long *i, *min, *max, val;
1989 int vleft, first=1, neg;
1990 size_t len, left;
1991 char buf[TMPBUFLEN], *p;
1992 char __user *s = buffer;
1994 if (!table->data || !table->maxlen || !*lenp ||
1995 (*ppos && !write)) {
1996 *lenp = 0;
1997 return 0;
2000 i = (unsigned long *) table->data;
2001 min = (unsigned long *) table->extra1;
2002 max = (unsigned long *) table->extra2;
2003 vleft = table->maxlen / sizeof(unsigned long);
2004 left = *lenp;
2006 for (; left && vleft--; i++, min++, max++, first=0) {
2007 if (write) {
2008 while (left) {
2009 char c;
2010 if (get_user(c, s))
2011 return -EFAULT;
2012 if (!isspace(c))
2013 break;
2014 left--;
2015 s++;
2017 if (!left)
2018 break;
2019 neg = 0;
2020 len = left;
2021 if (len > TMPBUFLEN-1)
2022 len = TMPBUFLEN-1;
2023 if (copy_from_user(buf, s, len))
2024 return -EFAULT;
2025 buf[len] = 0;
2026 p = buf;
2027 if (*p == '-' && left > 1) {
2028 neg = 1;
2029 left--, p++;
2031 if (*p < '0' || *p > '9')
2032 break;
2033 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2034 len = p-buf;
2035 if ((len < left) && *p && !isspace(*p))
2036 break;
2037 if (neg)
2038 val = -val;
2039 s += len;
2040 left -= len;
2042 if(neg)
2043 continue;
2044 if ((min && val < *min) || (max && val > *max))
2045 continue;
2046 *i = val;
2047 } else {
2048 p = buf;
2049 if (!first)
2050 *p++ = '\t';
2051 sprintf(p, "%lu", convdiv * (*i) / convmul);
2052 len = strlen(buf);
2053 if (len > left)
2054 len = left;
2055 if(copy_to_user(s, buf, len))
2056 return -EFAULT;
2057 left -= len;
2058 s += len;
2062 if (!write && !first && left) {
2063 if(put_user('\n', s))
2064 return -EFAULT;
2065 left--, s++;
2067 if (write) {
2068 while (left) {
2069 char c;
2070 if (get_user(c, s++))
2071 return -EFAULT;
2072 if (!isspace(c))
2073 break;
2074 left--;
2077 if (write && first)
2078 return -EINVAL;
2079 *lenp -= left;
2080 *ppos += *lenp;
2081 return 0;
2082 #undef TMPBUFLEN
2086 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2087 * @table: the sysctl table
2088 * @write: %TRUE if this is a write to the sysctl file
2089 * @filp: the file structure
2090 * @buffer: the user buffer
2091 * @lenp: the size of the user buffer
2092 * @ppos: file position
2094 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2095 * values from/to the user buffer, treated as an ASCII string.
2097 * This routine will ensure the values are within the range specified by
2098 * table->extra1 (min) and table->extra2 (max).
2100 * Returns 0 on success.
2102 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2103 void __user *buffer, size_t *lenp, loff_t *ppos)
2105 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2109 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2110 * @table: the sysctl table
2111 * @write: %TRUE if this is a write to the sysctl file
2112 * @filp: the file structure
2113 * @buffer: the user buffer
2114 * @lenp: the size of the user buffer
2115 * @ppos: file position
2117 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2118 * values from/to the user buffer, treated as an ASCII string. The values
2119 * are treated as milliseconds, and converted to jiffies when they are stored.
2121 * This routine will ensure the values are within the range specified by
2122 * table->extra1 (min) and table->extra2 (max).
2124 * Returns 0 on success.
2126 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2127 struct file *filp,
2128 void __user *buffer,
2129 size_t *lenp, loff_t *ppos)
2131 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2132 lenp, ppos, HZ, 1000l);
2136 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2137 int *valp,
2138 int write, void *data)
2140 if (write) {
2141 if (*lvalp > LONG_MAX / HZ)
2142 return 1;
2143 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2144 } else {
2145 int val = *valp;
2146 unsigned long lval;
2147 if (val < 0) {
2148 *negp = -1;
2149 lval = (unsigned long)-val;
2150 } else {
2151 *negp = 0;
2152 lval = (unsigned long)val;
2154 *lvalp = lval / HZ;
2156 return 0;
2159 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2160 int *valp,
2161 int write, void *data)
2163 if (write) {
2164 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2165 return 1;
2166 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2167 } else {
2168 int val = *valp;
2169 unsigned long lval;
2170 if (val < 0) {
2171 *negp = -1;
2172 lval = (unsigned long)-val;
2173 } else {
2174 *negp = 0;
2175 lval = (unsigned long)val;
2177 *lvalp = jiffies_to_clock_t(lval);
2179 return 0;
2182 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2183 int *valp,
2184 int write, void *data)
2186 if (write) {
2187 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2188 } else {
2189 int val = *valp;
2190 unsigned long lval;
2191 if (val < 0) {
2192 *negp = -1;
2193 lval = (unsigned long)-val;
2194 } else {
2195 *negp = 0;
2196 lval = (unsigned long)val;
2198 *lvalp = jiffies_to_msecs(lval);
2200 return 0;
2204 * proc_dointvec_jiffies - read a vector of integers as seconds
2205 * @table: the sysctl table
2206 * @write: %TRUE if this is a write to the sysctl file
2207 * @filp: the file structure
2208 * @buffer: the user buffer
2209 * @lenp: the size of the user buffer
2210 * @ppos: file position
2212 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2213 * values from/to the user buffer, treated as an ASCII string.
2214 * The values read are assumed to be in seconds, and are converted into
2215 * jiffies.
2217 * Returns 0 on success.
2219 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2220 void __user *buffer, size_t *lenp, loff_t *ppos)
2222 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2223 do_proc_dointvec_jiffies_conv,NULL);
2227 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2228 * @table: the sysctl table
2229 * @write: %TRUE if this is a write to the sysctl file
2230 * @filp: the file structure
2231 * @buffer: the user buffer
2232 * @lenp: the size of the user buffer
2233 * @ppos: pointer to the file position
2235 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2236 * values from/to the user buffer, treated as an ASCII string.
2237 * The values read are assumed to be in 1/USER_HZ seconds, and
2238 * are converted into jiffies.
2240 * Returns 0 on success.
2242 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2243 void __user *buffer, size_t *lenp, loff_t *ppos)
2245 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2246 do_proc_dointvec_userhz_jiffies_conv,NULL);
2250 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2251 * @table: the sysctl table
2252 * @write: %TRUE if this is a write to the sysctl file
2253 * @filp: the file structure
2254 * @buffer: the user buffer
2255 * @lenp: the size of the user buffer
2256 * @ppos: file position
2257 * @ppos: the current position in the file
2259 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2260 * values from/to the user buffer, treated as an ASCII string.
2261 * The values read are assumed to be in 1/1000 seconds, and
2262 * are converted into jiffies.
2264 * Returns 0 on success.
2266 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2267 void __user *buffer, size_t *lenp, loff_t *ppos)
2269 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2270 do_proc_dointvec_ms_jiffies_conv, NULL);
2273 #else /* CONFIG_PROC_FS */
2275 int proc_dostring(ctl_table *table, int write, struct file *filp,
2276 void __user *buffer, size_t *lenp, loff_t *ppos)
2278 return -ENOSYS;
2281 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2284 return -ENOSYS;
2287 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2288 void __user *buffer, size_t *lenp, loff_t *ppos)
2290 return -ENOSYS;
2293 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2294 void __user *buffer, size_t *lenp, loff_t *ppos)
2296 return -ENOSYS;
2299 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2300 void __user *buffer, size_t *lenp, loff_t *ppos)
2302 return -ENOSYS;
2305 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2306 void __user *buffer, size_t *lenp, loff_t *ppos)
2308 return -ENOSYS;
2311 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2312 void __user *buffer, size_t *lenp, loff_t *ppos)
2314 return -ENOSYS;
2317 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2318 void __user *buffer, size_t *lenp, loff_t *ppos)
2320 return -ENOSYS;
2323 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2324 void __user *buffer, size_t *lenp, loff_t *ppos)
2326 return -ENOSYS;
2329 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2330 struct file *filp,
2331 void __user *buffer,
2332 size_t *lenp, loff_t *ppos)
2334 return -ENOSYS;
2338 #endif /* CONFIG_PROC_FS */
2341 #ifdef CONFIG_SYSCTL_SYSCALL
2343 * General sysctl support routines
2346 /* The generic string strategy routine: */
2347 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2348 void __user *oldval, size_t __user *oldlenp,
2349 void __user *newval, size_t newlen, void **context)
2351 if (!table->data || !table->maxlen)
2352 return -ENOTDIR;
2354 if (oldval && oldlenp) {
2355 size_t bufsize;
2356 if (get_user(bufsize, oldlenp))
2357 return -EFAULT;
2358 if (bufsize) {
2359 size_t len = strlen(table->data), copied;
2361 /* This shouldn't trigger for a well-formed sysctl */
2362 if (len > table->maxlen)
2363 len = table->maxlen;
2365 /* Copy up to a max of bufsize-1 bytes of the string */
2366 copied = (len >= bufsize) ? bufsize - 1 : len;
2368 if (copy_to_user(oldval, table->data, copied) ||
2369 put_user(0, (char __user *)(oldval + copied)))
2370 return -EFAULT;
2371 if (put_user(len, oldlenp))
2372 return -EFAULT;
2375 if (newval && newlen) {
2376 size_t len = newlen;
2377 if (len > table->maxlen)
2378 len = table->maxlen;
2379 if(copy_from_user(table->data, newval, len))
2380 return -EFAULT;
2381 if (len == table->maxlen)
2382 len--;
2383 ((char *) table->data)[len] = 0;
2385 return 1;
2389 * This function makes sure that all of the integers in the vector
2390 * are between the minimum and maximum values given in the arrays
2391 * table->extra1 and table->extra2, respectively.
2393 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2394 void __user *oldval, size_t __user *oldlenp,
2395 void __user *newval, size_t newlen, void **context)
2398 if (newval && newlen) {
2399 int __user *vec = (int __user *) newval;
2400 int *min = (int *) table->extra1;
2401 int *max = (int *) table->extra2;
2402 size_t length;
2403 int i;
2405 if (newlen % sizeof(int) != 0)
2406 return -EINVAL;
2408 if (!table->extra1 && !table->extra2)
2409 return 0;
2411 if (newlen > table->maxlen)
2412 newlen = table->maxlen;
2413 length = newlen / sizeof(int);
2415 for (i = 0; i < length; i++) {
2416 int value;
2417 if (get_user(value, vec + i))
2418 return -EFAULT;
2419 if (min && value < min[i])
2420 return -EINVAL;
2421 if (max && value > max[i])
2422 return -EINVAL;
2425 return 0;
2428 /* Strategy function to convert jiffies to seconds */
2429 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2430 void __user *oldval, size_t __user *oldlenp,
2431 void __user *newval, size_t newlen, void **context)
2433 if (oldval) {
2434 size_t olen;
2435 if (oldlenp) {
2436 if (get_user(olen, oldlenp))
2437 return -EFAULT;
2438 if (olen!=sizeof(int))
2439 return -EINVAL;
2441 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2442 (oldlenp && put_user(sizeof(int),oldlenp)))
2443 return -EFAULT;
2445 if (newval && newlen) {
2446 int new;
2447 if (newlen != sizeof(int))
2448 return -EINVAL;
2449 if (get_user(new, (int __user *)newval))
2450 return -EFAULT;
2451 *(int *)(table->data) = new*HZ;
2453 return 1;
2456 /* Strategy function to convert jiffies to seconds */
2457 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2458 void __user *oldval, size_t __user *oldlenp,
2459 void __user *newval, size_t newlen, void **context)
2461 if (oldval) {
2462 size_t olen;
2463 if (oldlenp) {
2464 if (get_user(olen, oldlenp))
2465 return -EFAULT;
2466 if (olen!=sizeof(int))
2467 return -EINVAL;
2469 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2470 (oldlenp && put_user(sizeof(int),oldlenp)))
2471 return -EFAULT;
2473 if (newval && newlen) {
2474 int new;
2475 if (newlen != sizeof(int))
2476 return -EINVAL;
2477 if (get_user(new, (int __user *)newval))
2478 return -EFAULT;
2479 *(int *)(table->data) = msecs_to_jiffies(new);
2481 return 1;
2484 #else /* CONFIG_SYSCTL_SYSCALL */
2487 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2489 static int msg_count;
2491 if (msg_count < 5) {
2492 msg_count++;
2493 printk(KERN_INFO
2494 "warning: process `%s' used the removed sysctl "
2495 "system call\n", current->comm);
2497 return -ENOSYS;
2500 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2501 void __user *oldval, size_t __user *oldlenp,
2502 void __user *newval, size_t newlen, void **context)
2504 return -ENOSYS;
2507 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2508 void __user *oldval, size_t __user *oldlenp,
2509 void __user *newval, size_t newlen, void **context)
2511 return -ENOSYS;
2514 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2515 void __user *oldval, size_t __user *oldlenp,
2516 void __user *newval, size_t newlen, void **context)
2518 return -ENOSYS;
2521 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2522 void __user *oldval, size_t __user *oldlenp,
2523 void __user *newval, size_t newlen, void **context)
2525 return -ENOSYS;
2528 #endif /* CONFIG_SYSCTL_SYSCALL */
2531 * No sense putting this after each symbol definition, twice,
2532 * exception granted :-)
2534 EXPORT_SYMBOL(proc_dointvec);
2535 EXPORT_SYMBOL(proc_dointvec_jiffies);
2536 EXPORT_SYMBOL(proc_dointvec_minmax);
2537 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2538 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2539 EXPORT_SYMBOL(proc_dostring);
2540 EXPORT_SYMBOL(proc_doulongvec_minmax);
2541 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2542 EXPORT_SYMBOL(register_sysctl_table);
2543 EXPORT_SYMBOL(sysctl_intvec);
2544 EXPORT_SYMBOL(sysctl_jiffies);
2545 EXPORT_SYMBOL(sysctl_ms_jiffies);
2546 EXPORT_SYMBOL(sysctl_string);
2547 EXPORT_SYMBOL(unregister_sysctl_table);