[PATCH] md: allow reads that have bypassed the cache to be retried on failure
[linux-2.6/btrfs-unstable.git] / kernel / sysctl.c
blob130c5ec9ee0b3f699c3da72617db844154ce5910
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 #ifdef CONFIG_X86
56 #include <asm/nmi.h>
57 #include <asm/stacktrace.h>
58 #endif
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
63 extern int C_A_D;
64 extern int sysctl_overcommit_memory;
65 extern int sysctl_overcommit_ratio;
66 extern int sysctl_panic_on_oom;
67 extern int max_threads;
68 extern int sysrq_enabled;
69 extern int core_uses_pid;
70 extern int suid_dumpable;
71 extern char core_pattern[];
72 extern int pid_max;
73 extern int min_free_kbytes;
74 extern int printk_ratelimit_jiffies;
75 extern int printk_ratelimit_burst;
76 extern int pid_max_min, pid_max_max;
77 extern int sysctl_drop_caches;
78 extern int percpu_pagelist_fraction;
79 extern int compat_log;
81 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
82 static int maxolduid = 65535;
83 static int minolduid;
84 static int min_percpu_pagelist_fract = 8;
86 static int ngroups_max = NGROUPS_MAX;
88 #ifdef CONFIG_KMOD
89 extern char modprobe_path[];
90 #endif
91 #ifdef CONFIG_CHR_DEV_SG
92 extern int sg_big_buff;
93 #endif
94 #ifdef CONFIG_SYSVIPC
95 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
96 void __user *buffer, size_t *lenp, loff_t *ppos);
97 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
98 void __user *buffer, size_t *lenp, loff_t *ppos);
99 #endif
101 #ifdef __sparc__
102 extern char reboot_command [];
103 extern int stop_a_enabled;
104 extern int scons_pwroff;
105 #endif
107 #ifdef __hppa__
108 extern int pwrsw_enabled;
109 extern int unaligned_enabled;
110 #endif
112 #ifdef CONFIG_S390
113 #ifdef CONFIG_MATHEMU
114 extern int sysctl_ieee_emulation_warnings;
115 #endif
116 extern int sysctl_userprocess_debug;
117 extern int spin_retry;
118 #endif
120 extern int sysctl_hz_timer;
122 #ifdef CONFIG_BSD_PROCESS_ACCT
123 extern int acct_parm[];
124 #endif
126 #ifdef CONFIG_IA64
127 extern int no_unaligned_warning;
128 #endif
130 #ifdef CONFIG_RT_MUTEXES
131 extern int max_lock_depth;
132 #endif
134 #ifdef CONFIG_SYSCTL_SYSCALL
135 static int parse_table(int __user *, int, void __user *, size_t __user *,
136 void __user *, size_t, ctl_table *);
137 #endif
139 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
140 void __user *buffer, size_t *lenp, loff_t *ppos);
142 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
143 void __user *oldval, size_t __user *oldlenp,
144 void __user *newval, size_t newlen);
146 #ifdef CONFIG_SYSVIPC
147 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
148 void __user *oldval, size_t __user *oldlenp,
149 void __user *newval, size_t newlen);
150 #endif
152 #ifdef CONFIG_PROC_SYSCTL
153 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
154 void __user *buffer, size_t *lenp, loff_t *ppos);
155 #endif
157 static ctl_table root_table[];
158 static struct ctl_table_header root_table_header =
159 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
161 static ctl_table kern_table[];
162 static ctl_table vm_table[];
163 static ctl_table fs_table[];
164 static ctl_table debug_table[];
165 static ctl_table dev_table[];
166 extern ctl_table random_table[];
167 #ifdef CONFIG_UNIX98_PTYS
168 extern ctl_table pty_table[];
169 #endif
170 #ifdef CONFIG_INOTIFY_USER
171 extern ctl_table inotify_table[];
172 #endif
174 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
175 int sysctl_legacy_va_layout;
176 #endif
178 static void *get_uts(ctl_table *table, int write)
180 char *which = table->data;
181 #ifdef CONFIG_UTS_NS
182 struct uts_namespace *uts_ns = current->nsproxy->uts_ns;
183 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
184 #endif
185 if (!write)
186 down_read(&uts_sem);
187 else
188 down_write(&uts_sem);
189 return which;
192 static void put_uts(ctl_table *table, int write, void *which)
194 if (!write)
195 up_read(&uts_sem);
196 else
197 up_write(&uts_sem);
200 #ifdef CONFIG_SYSVIPC
201 static void *get_ipc(ctl_table *table, int write)
203 char *which = table->data;
204 struct ipc_namespace *ipc_ns = current->nsproxy->ipc_ns;
205 which = (which - (char *)&init_ipc_ns) + (char *)ipc_ns;
206 return which;
208 #else
209 #define get_ipc(T,W) ((T)->data)
210 #endif
212 /* /proc declarations: */
214 #ifdef CONFIG_PROC_SYSCTL
216 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
217 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
218 static int proc_opensys(struct inode *, struct file *);
220 const struct file_operations proc_sys_file_operations = {
221 .open = proc_opensys,
222 .read = proc_readsys,
223 .write = proc_writesys,
226 extern struct proc_dir_entry *proc_sys_root;
228 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
229 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
230 #endif
232 /* The default sysctl tables: */
234 static ctl_table root_table[] = {
236 .ctl_name = CTL_KERN,
237 .procname = "kernel",
238 .mode = 0555,
239 .child = kern_table,
242 .ctl_name = CTL_VM,
243 .procname = "vm",
244 .mode = 0555,
245 .child = vm_table,
247 #ifdef CONFIG_NET
249 .ctl_name = CTL_NET,
250 .procname = "net",
251 .mode = 0555,
252 .child = net_table,
254 #endif
256 .ctl_name = CTL_FS,
257 .procname = "fs",
258 .mode = 0555,
259 .child = fs_table,
262 .ctl_name = CTL_DEBUG,
263 .procname = "debug",
264 .mode = 0555,
265 .child = debug_table,
268 .ctl_name = CTL_DEV,
269 .procname = "dev",
270 .mode = 0555,
271 .child = dev_table,
274 { .ctl_name = 0 }
277 static ctl_table kern_table[] = {
279 .ctl_name = KERN_OSTYPE,
280 .procname = "ostype",
281 .data = init_uts_ns.name.sysname,
282 .maxlen = sizeof(init_uts_ns.name.sysname),
283 .mode = 0444,
284 .proc_handler = &proc_do_uts_string,
285 .strategy = &sysctl_uts_string,
288 .ctl_name = KERN_OSRELEASE,
289 .procname = "osrelease",
290 .data = init_uts_ns.name.release,
291 .maxlen = sizeof(init_uts_ns.name.release),
292 .mode = 0444,
293 .proc_handler = &proc_do_uts_string,
294 .strategy = &sysctl_uts_string,
297 .ctl_name = KERN_VERSION,
298 .procname = "version",
299 .data = init_uts_ns.name.version,
300 .maxlen = sizeof(init_uts_ns.name.version),
301 .mode = 0444,
302 .proc_handler = &proc_do_uts_string,
303 .strategy = &sysctl_uts_string,
306 .ctl_name = KERN_NODENAME,
307 .procname = "hostname",
308 .data = init_uts_ns.name.nodename,
309 .maxlen = sizeof(init_uts_ns.name.nodename),
310 .mode = 0644,
311 .proc_handler = &proc_do_uts_string,
312 .strategy = &sysctl_uts_string,
315 .ctl_name = KERN_DOMAINNAME,
316 .procname = "domainname",
317 .data = init_uts_ns.name.domainname,
318 .maxlen = sizeof(init_uts_ns.name.domainname),
319 .mode = 0644,
320 .proc_handler = &proc_do_uts_string,
321 .strategy = &sysctl_uts_string,
324 .ctl_name = KERN_PANIC,
325 .procname = "panic",
326 .data = &panic_timeout,
327 .maxlen = sizeof(int),
328 .mode = 0644,
329 .proc_handler = &proc_dointvec,
332 .ctl_name = KERN_CORE_USES_PID,
333 .procname = "core_uses_pid",
334 .data = &core_uses_pid,
335 .maxlen = sizeof(int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
340 .ctl_name = KERN_CORE_PATTERN,
341 .procname = "core_pattern",
342 .data = core_pattern,
343 .maxlen = 128,
344 .mode = 0644,
345 .proc_handler = &proc_dostring,
346 .strategy = &sysctl_string,
349 .ctl_name = KERN_TAINTED,
350 .procname = "tainted",
351 .data = &tainted,
352 .maxlen = sizeof(int),
353 .mode = 0444,
354 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_CAP_BSET,
358 .procname = "cap-bound",
359 .data = &cap_bset,
360 .maxlen = sizeof(kernel_cap_t),
361 .mode = 0600,
362 .proc_handler = &proc_dointvec_bset,
364 #ifdef CONFIG_BLK_DEV_INITRD
366 .ctl_name = KERN_REALROOTDEV,
367 .procname = "real-root-dev",
368 .data = &real_root_dev,
369 .maxlen = sizeof(int),
370 .mode = 0644,
371 .proc_handler = &proc_dointvec,
373 #endif
374 #ifdef __sparc__
376 .ctl_name = KERN_SPARC_REBOOT,
377 .procname = "reboot-cmd",
378 .data = reboot_command,
379 .maxlen = 256,
380 .mode = 0644,
381 .proc_handler = &proc_dostring,
382 .strategy = &sysctl_string,
385 .ctl_name = KERN_SPARC_STOP_A,
386 .procname = "stop-a",
387 .data = &stop_a_enabled,
388 .maxlen = sizeof (int),
389 .mode = 0644,
390 .proc_handler = &proc_dointvec,
393 .ctl_name = KERN_SPARC_SCONS_PWROFF,
394 .procname = "scons-poweroff",
395 .data = &scons_pwroff,
396 .maxlen = sizeof (int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
400 #endif
401 #ifdef __hppa__
403 .ctl_name = KERN_HPPA_PWRSW,
404 .procname = "soft-power",
405 .data = &pwrsw_enabled,
406 .maxlen = sizeof (int),
407 .mode = 0644,
408 .proc_handler = &proc_dointvec,
411 .ctl_name = KERN_HPPA_UNALIGNED,
412 .procname = "unaligned-trap",
413 .data = &unaligned_enabled,
414 .maxlen = sizeof (int),
415 .mode = 0644,
416 .proc_handler = &proc_dointvec,
418 #endif
420 .ctl_name = KERN_CTLALTDEL,
421 .procname = "ctrl-alt-del",
422 .data = &C_A_D,
423 .maxlen = sizeof(int),
424 .mode = 0644,
425 .proc_handler = &proc_dointvec,
428 .ctl_name = KERN_PRINTK,
429 .procname = "printk",
430 .data = &console_loglevel,
431 .maxlen = 4*sizeof(int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
435 #ifdef CONFIG_KMOD
437 .ctl_name = KERN_MODPROBE,
438 .procname = "modprobe",
439 .data = &modprobe_path,
440 .maxlen = KMOD_PATH_LEN,
441 .mode = 0644,
442 .proc_handler = &proc_dostring,
443 .strategy = &sysctl_string,
445 #endif
446 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
448 .ctl_name = KERN_HOTPLUG,
449 .procname = "hotplug",
450 .data = &uevent_helper,
451 .maxlen = UEVENT_HELPER_PATH_LEN,
452 .mode = 0644,
453 .proc_handler = &proc_dostring,
454 .strategy = &sysctl_string,
456 #endif
457 #ifdef CONFIG_CHR_DEV_SG
459 .ctl_name = KERN_SG_BIG_BUFF,
460 .procname = "sg-big-buff",
461 .data = &sg_big_buff,
462 .maxlen = sizeof (int),
463 .mode = 0444,
464 .proc_handler = &proc_dointvec,
466 #endif
467 #ifdef CONFIG_BSD_PROCESS_ACCT
469 .ctl_name = KERN_ACCT,
470 .procname = "acct",
471 .data = &acct_parm,
472 .maxlen = 3*sizeof(int),
473 .mode = 0644,
474 .proc_handler = &proc_dointvec,
476 #endif
477 #ifdef CONFIG_SYSVIPC
479 .ctl_name = KERN_SHMMAX,
480 .procname = "shmmax",
481 .data = &init_ipc_ns.shm_ctlmax,
482 .maxlen = sizeof (init_ipc_ns.shm_ctlmax),
483 .mode = 0644,
484 .proc_handler = &proc_ipc_doulongvec_minmax,
485 .strategy = sysctl_ipc_data,
488 .ctl_name = KERN_SHMALL,
489 .procname = "shmall",
490 .data = &init_ipc_ns.shm_ctlall,
491 .maxlen = sizeof (init_ipc_ns.shm_ctlall),
492 .mode = 0644,
493 .proc_handler = &proc_ipc_doulongvec_minmax,
494 .strategy = sysctl_ipc_data,
497 .ctl_name = KERN_SHMMNI,
498 .procname = "shmmni",
499 .data = &init_ipc_ns.shm_ctlmni,
500 .maxlen = sizeof (init_ipc_ns.shm_ctlmni),
501 .mode = 0644,
502 .proc_handler = &proc_ipc_dointvec,
503 .strategy = sysctl_ipc_data,
506 .ctl_name = KERN_MSGMAX,
507 .procname = "msgmax",
508 .data = &init_ipc_ns.msg_ctlmax,
509 .maxlen = sizeof (init_ipc_ns.msg_ctlmax),
510 .mode = 0644,
511 .proc_handler = &proc_ipc_dointvec,
512 .strategy = sysctl_ipc_data,
515 .ctl_name = KERN_MSGMNI,
516 .procname = "msgmni",
517 .data = &init_ipc_ns.msg_ctlmni,
518 .maxlen = sizeof (init_ipc_ns.msg_ctlmni),
519 .mode = 0644,
520 .proc_handler = &proc_ipc_dointvec,
521 .strategy = sysctl_ipc_data,
524 .ctl_name = KERN_MSGMNB,
525 .procname = "msgmnb",
526 .data = &init_ipc_ns.msg_ctlmnb,
527 .maxlen = sizeof (init_ipc_ns.msg_ctlmnb),
528 .mode = 0644,
529 .proc_handler = &proc_ipc_dointvec,
530 .strategy = sysctl_ipc_data,
533 .ctl_name = KERN_SEM,
534 .procname = "sem",
535 .data = &init_ipc_ns.sem_ctls,
536 .maxlen = 4*sizeof (int),
537 .mode = 0644,
538 .proc_handler = &proc_ipc_dointvec,
539 .strategy = sysctl_ipc_data,
541 #endif
542 #ifdef CONFIG_MAGIC_SYSRQ
544 .ctl_name = KERN_SYSRQ,
545 .procname = "sysrq",
546 .data = &sysrq_enabled,
547 .maxlen = sizeof (int),
548 .mode = 0644,
549 .proc_handler = &proc_dointvec,
551 #endif
552 #ifdef CONFIG_PROC_SYSCTL
554 .ctl_name = KERN_CADPID,
555 .procname = "cad_pid",
556 .data = NULL,
557 .maxlen = sizeof (int),
558 .mode = 0600,
559 .proc_handler = &proc_do_cad_pid,
561 #endif
563 .ctl_name = KERN_MAX_THREADS,
564 .procname = "threads-max",
565 .data = &max_threads,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec,
571 .ctl_name = KERN_RANDOM,
572 .procname = "random",
573 .mode = 0555,
574 .child = random_table,
576 #ifdef CONFIG_UNIX98_PTYS
578 .ctl_name = KERN_PTY,
579 .procname = "pty",
580 .mode = 0555,
581 .child = pty_table,
583 #endif
585 .ctl_name = KERN_OVERFLOWUID,
586 .procname = "overflowuid",
587 .data = &overflowuid,
588 .maxlen = sizeof(int),
589 .mode = 0644,
590 .proc_handler = &proc_dointvec_minmax,
591 .strategy = &sysctl_intvec,
592 .extra1 = &minolduid,
593 .extra2 = &maxolduid,
596 .ctl_name = KERN_OVERFLOWGID,
597 .procname = "overflowgid",
598 .data = &overflowgid,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = &proc_dointvec_minmax,
602 .strategy = &sysctl_intvec,
603 .extra1 = &minolduid,
604 .extra2 = &maxolduid,
606 #ifdef CONFIG_S390
607 #ifdef CONFIG_MATHEMU
609 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
610 .procname = "ieee_emulation_warnings",
611 .data = &sysctl_ieee_emulation_warnings,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec,
616 #endif
617 #ifdef CONFIG_NO_IDLE_HZ
619 .ctl_name = KERN_HZ_TIMER,
620 .procname = "hz_timer",
621 .data = &sysctl_hz_timer,
622 .maxlen = sizeof(int),
623 .mode = 0644,
624 .proc_handler = &proc_dointvec,
626 #endif
628 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
629 .procname = "userprocess_debug",
630 .data = &sysctl_userprocess_debug,
631 .maxlen = sizeof(int),
632 .mode = 0644,
633 .proc_handler = &proc_dointvec,
635 #endif
637 .ctl_name = KERN_PIDMAX,
638 .procname = "pid_max",
639 .data = &pid_max,
640 .maxlen = sizeof (int),
641 .mode = 0644,
642 .proc_handler = &proc_dointvec_minmax,
643 .strategy = sysctl_intvec,
644 .extra1 = &pid_max_min,
645 .extra2 = &pid_max_max,
648 .ctl_name = KERN_PANIC_ON_OOPS,
649 .procname = "panic_on_oops",
650 .data = &panic_on_oops,
651 .maxlen = sizeof(int),
652 .mode = 0644,
653 .proc_handler = &proc_dointvec,
656 .ctl_name = KERN_PRINTK_RATELIMIT,
657 .procname = "printk_ratelimit",
658 .data = &printk_ratelimit_jiffies,
659 .maxlen = sizeof(int),
660 .mode = 0644,
661 .proc_handler = &proc_dointvec_jiffies,
662 .strategy = &sysctl_jiffies,
665 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
666 .procname = "printk_ratelimit_burst",
667 .data = &printk_ratelimit_burst,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec,
673 .ctl_name = KERN_NGROUPS_MAX,
674 .procname = "ngroups_max",
675 .data = &ngroups_max,
676 .maxlen = sizeof (int),
677 .mode = 0444,
678 .proc_handler = &proc_dointvec,
680 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
682 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
683 .procname = "unknown_nmi_panic",
684 .data = &unknown_nmi_panic,
685 .maxlen = sizeof (int),
686 .mode = 0644,
687 .proc_handler = &proc_dointvec,
690 .ctl_name = KERN_NMI_WATCHDOG,
691 .procname = "nmi_watchdog",
692 .data = &nmi_watchdog_enabled,
693 .maxlen = sizeof (int),
694 .mode = 0644,
695 .proc_handler = &proc_nmi_enabled,
697 #endif
698 #if defined(CONFIG_X86)
700 .ctl_name = KERN_PANIC_ON_NMI,
701 .procname = "panic_on_unrecovered_nmi",
702 .data = &panic_on_unrecovered_nmi,
703 .maxlen = sizeof(int),
704 .mode = 0644,
705 .proc_handler = &proc_dointvec,
708 .ctl_name = KERN_BOOTLOADER_TYPE,
709 .procname = "bootloader_type",
710 .data = &bootloader_type,
711 .maxlen = sizeof (int),
712 .mode = 0444,
713 .proc_handler = &proc_dointvec,
716 .ctl_name = CTL_UNNUMBERED,
717 .procname = "kstack_depth_to_print",
718 .data = &kstack_depth_to_print,
719 .maxlen = sizeof(int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec,
723 #endif
724 #if defined(CONFIG_MMU)
726 .ctl_name = KERN_RANDOMIZE,
727 .procname = "randomize_va_space",
728 .data = &randomize_va_space,
729 .maxlen = sizeof(int),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec,
733 #endif
734 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
736 .ctl_name = KERN_SPIN_RETRY,
737 .procname = "spin_retry",
738 .data = &spin_retry,
739 .maxlen = sizeof (int),
740 .mode = 0644,
741 .proc_handler = &proc_dointvec,
743 #endif
744 #ifdef CONFIG_ACPI_SLEEP
746 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
747 .procname = "acpi_video_flags",
748 .data = &acpi_video_flags,
749 .maxlen = sizeof (unsigned long),
750 .mode = 0644,
751 .proc_handler = &proc_doulongvec_minmax,
753 #endif
754 #ifdef CONFIG_IA64
756 .ctl_name = KERN_IA64_UNALIGNED,
757 .procname = "ignore-unaligned-usertrap",
758 .data = &no_unaligned_warning,
759 .maxlen = sizeof (int),
760 .mode = 0644,
761 .proc_handler = &proc_dointvec,
763 #endif
764 #ifdef CONFIG_COMPAT
766 .ctl_name = KERN_COMPAT_LOG,
767 .procname = "compat-log",
768 .data = &compat_log,
769 .maxlen = sizeof (int),
770 .mode = 0644,
771 .proc_handler = &proc_dointvec,
773 #endif
774 #ifdef CONFIG_RT_MUTEXES
776 .ctl_name = KERN_MAX_LOCK_DEPTH,
777 .procname = "max_lock_depth",
778 .data = &max_lock_depth,
779 .maxlen = sizeof(int),
780 .mode = 0644,
781 .proc_handler = &proc_dointvec,
783 #endif
785 { .ctl_name = 0 }
788 /* Constants for minimum and maximum testing in vm_table.
789 We use these as one-element integer vectors. */
790 static int zero;
791 static int one_hundred = 100;
794 static ctl_table vm_table[] = {
796 .ctl_name = VM_OVERCOMMIT_MEMORY,
797 .procname = "overcommit_memory",
798 .data = &sysctl_overcommit_memory,
799 .maxlen = sizeof(sysctl_overcommit_memory),
800 .mode = 0644,
801 .proc_handler = &proc_dointvec,
804 .ctl_name = VM_PANIC_ON_OOM,
805 .procname = "panic_on_oom",
806 .data = &sysctl_panic_on_oom,
807 .maxlen = sizeof(sysctl_panic_on_oom),
808 .mode = 0644,
809 .proc_handler = &proc_dointvec,
812 .ctl_name = VM_OVERCOMMIT_RATIO,
813 .procname = "overcommit_ratio",
814 .data = &sysctl_overcommit_ratio,
815 .maxlen = sizeof(sysctl_overcommit_ratio),
816 .mode = 0644,
817 .proc_handler = &proc_dointvec,
820 .ctl_name = VM_PAGE_CLUSTER,
821 .procname = "page-cluster",
822 .data = &page_cluster,
823 .maxlen = sizeof(int),
824 .mode = 0644,
825 .proc_handler = &proc_dointvec,
828 .ctl_name = VM_DIRTY_BACKGROUND,
829 .procname = "dirty_background_ratio",
830 .data = &dirty_background_ratio,
831 .maxlen = sizeof(dirty_background_ratio),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec_minmax,
834 .strategy = &sysctl_intvec,
835 .extra1 = &zero,
836 .extra2 = &one_hundred,
839 .ctl_name = VM_DIRTY_RATIO,
840 .procname = "dirty_ratio",
841 .data = &vm_dirty_ratio,
842 .maxlen = sizeof(vm_dirty_ratio),
843 .mode = 0644,
844 .proc_handler = &proc_dointvec_minmax,
845 .strategy = &sysctl_intvec,
846 .extra1 = &zero,
847 .extra2 = &one_hundred,
850 .ctl_name = VM_DIRTY_WB_CS,
851 .procname = "dirty_writeback_centisecs",
852 .data = &dirty_writeback_interval,
853 .maxlen = sizeof(dirty_writeback_interval),
854 .mode = 0644,
855 .proc_handler = &dirty_writeback_centisecs_handler,
858 .ctl_name = VM_DIRTY_EXPIRE_CS,
859 .procname = "dirty_expire_centisecs",
860 .data = &dirty_expire_interval,
861 .maxlen = sizeof(dirty_expire_interval),
862 .mode = 0644,
863 .proc_handler = &proc_dointvec_userhz_jiffies,
866 .ctl_name = VM_NR_PDFLUSH_THREADS,
867 .procname = "nr_pdflush_threads",
868 .data = &nr_pdflush_threads,
869 .maxlen = sizeof nr_pdflush_threads,
870 .mode = 0444 /* read-only*/,
871 .proc_handler = &proc_dointvec,
874 .ctl_name = VM_SWAPPINESS,
875 .procname = "swappiness",
876 .data = &vm_swappiness,
877 .maxlen = sizeof(vm_swappiness),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec_minmax,
880 .strategy = &sysctl_intvec,
881 .extra1 = &zero,
882 .extra2 = &one_hundred,
884 #ifdef CONFIG_HUGETLB_PAGE
886 .ctl_name = VM_HUGETLB_PAGES,
887 .procname = "nr_hugepages",
888 .data = &max_huge_pages,
889 .maxlen = sizeof(unsigned long),
890 .mode = 0644,
891 .proc_handler = &hugetlb_sysctl_handler,
892 .extra1 = (void *)&hugetlb_zero,
893 .extra2 = (void *)&hugetlb_infinity,
896 .ctl_name = VM_HUGETLB_GROUP,
897 .procname = "hugetlb_shm_group",
898 .data = &sysctl_hugetlb_shm_group,
899 .maxlen = sizeof(gid_t),
900 .mode = 0644,
901 .proc_handler = &proc_dointvec,
903 #endif
905 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
906 .procname = "lowmem_reserve_ratio",
907 .data = &sysctl_lowmem_reserve_ratio,
908 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
909 .mode = 0644,
910 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
911 .strategy = &sysctl_intvec,
914 .ctl_name = VM_DROP_PAGECACHE,
915 .procname = "drop_caches",
916 .data = &sysctl_drop_caches,
917 .maxlen = sizeof(int),
918 .mode = 0644,
919 .proc_handler = drop_caches_sysctl_handler,
920 .strategy = &sysctl_intvec,
923 .ctl_name = VM_MIN_FREE_KBYTES,
924 .procname = "min_free_kbytes",
925 .data = &min_free_kbytes,
926 .maxlen = sizeof(min_free_kbytes),
927 .mode = 0644,
928 .proc_handler = &min_free_kbytes_sysctl_handler,
929 .strategy = &sysctl_intvec,
930 .extra1 = &zero,
933 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
934 .procname = "percpu_pagelist_fraction",
935 .data = &percpu_pagelist_fraction,
936 .maxlen = sizeof(percpu_pagelist_fraction),
937 .mode = 0644,
938 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
939 .strategy = &sysctl_intvec,
940 .extra1 = &min_percpu_pagelist_fract,
942 #ifdef CONFIG_MMU
944 .ctl_name = VM_MAX_MAP_COUNT,
945 .procname = "max_map_count",
946 .data = &sysctl_max_map_count,
947 .maxlen = sizeof(sysctl_max_map_count),
948 .mode = 0644,
949 .proc_handler = &proc_dointvec
951 #endif
953 .ctl_name = VM_LAPTOP_MODE,
954 .procname = "laptop_mode",
955 .data = &laptop_mode,
956 .maxlen = sizeof(laptop_mode),
957 .mode = 0644,
958 .proc_handler = &proc_dointvec_jiffies,
959 .strategy = &sysctl_jiffies,
962 .ctl_name = VM_BLOCK_DUMP,
963 .procname = "block_dump",
964 .data = &block_dump,
965 .maxlen = sizeof(block_dump),
966 .mode = 0644,
967 .proc_handler = &proc_dointvec,
968 .strategy = &sysctl_intvec,
969 .extra1 = &zero,
972 .ctl_name = VM_VFS_CACHE_PRESSURE,
973 .procname = "vfs_cache_pressure",
974 .data = &sysctl_vfs_cache_pressure,
975 .maxlen = sizeof(sysctl_vfs_cache_pressure),
976 .mode = 0644,
977 .proc_handler = &proc_dointvec,
978 .strategy = &sysctl_intvec,
979 .extra1 = &zero,
981 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
983 .ctl_name = VM_LEGACY_VA_LAYOUT,
984 .procname = "legacy_va_layout",
985 .data = &sysctl_legacy_va_layout,
986 .maxlen = sizeof(sysctl_legacy_va_layout),
987 .mode = 0644,
988 .proc_handler = &proc_dointvec,
989 .strategy = &sysctl_intvec,
990 .extra1 = &zero,
992 #endif
993 #ifdef CONFIG_NUMA
995 .ctl_name = VM_ZONE_RECLAIM_MODE,
996 .procname = "zone_reclaim_mode",
997 .data = &zone_reclaim_mode,
998 .maxlen = sizeof(zone_reclaim_mode),
999 .mode = 0644,
1000 .proc_handler = &proc_dointvec,
1001 .strategy = &sysctl_intvec,
1002 .extra1 = &zero,
1005 .ctl_name = VM_MIN_UNMAPPED,
1006 .procname = "min_unmapped_ratio",
1007 .data = &sysctl_min_unmapped_ratio,
1008 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1009 .mode = 0644,
1010 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1011 .strategy = &sysctl_intvec,
1012 .extra1 = &zero,
1013 .extra2 = &one_hundred,
1016 .ctl_name = VM_MIN_SLAB,
1017 .procname = "min_slab_ratio",
1018 .data = &sysctl_min_slab_ratio,
1019 .maxlen = sizeof(sysctl_min_slab_ratio),
1020 .mode = 0644,
1021 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1022 .strategy = &sysctl_intvec,
1023 .extra1 = &zero,
1024 .extra2 = &one_hundred,
1026 #endif
1027 #ifdef CONFIG_X86_32
1029 .ctl_name = VM_VDSO_ENABLED,
1030 .procname = "vdso_enabled",
1031 .data = &vdso_enabled,
1032 .maxlen = sizeof(vdso_enabled),
1033 .mode = 0644,
1034 .proc_handler = &proc_dointvec,
1035 .strategy = &sysctl_intvec,
1036 .extra1 = &zero,
1038 #endif
1039 { .ctl_name = 0 }
1042 static ctl_table fs_table[] = {
1044 .ctl_name = FS_NRINODE,
1045 .procname = "inode-nr",
1046 .data = &inodes_stat,
1047 .maxlen = 2*sizeof(int),
1048 .mode = 0444,
1049 .proc_handler = &proc_dointvec,
1052 .ctl_name = FS_STATINODE,
1053 .procname = "inode-state",
1054 .data = &inodes_stat,
1055 .maxlen = 7*sizeof(int),
1056 .mode = 0444,
1057 .proc_handler = &proc_dointvec,
1060 .ctl_name = FS_NRFILE,
1061 .procname = "file-nr",
1062 .data = &files_stat,
1063 .maxlen = 3*sizeof(int),
1064 .mode = 0444,
1065 .proc_handler = &proc_nr_files,
1068 .ctl_name = FS_MAXFILE,
1069 .procname = "file-max",
1070 .data = &files_stat.max_files,
1071 .maxlen = sizeof(int),
1072 .mode = 0644,
1073 .proc_handler = &proc_dointvec,
1076 .ctl_name = FS_DENTRY,
1077 .procname = "dentry-state",
1078 .data = &dentry_stat,
1079 .maxlen = 6*sizeof(int),
1080 .mode = 0444,
1081 .proc_handler = &proc_dointvec,
1084 .ctl_name = FS_OVERFLOWUID,
1085 .procname = "overflowuid",
1086 .data = &fs_overflowuid,
1087 .maxlen = sizeof(int),
1088 .mode = 0644,
1089 .proc_handler = &proc_dointvec_minmax,
1090 .strategy = &sysctl_intvec,
1091 .extra1 = &minolduid,
1092 .extra2 = &maxolduid,
1095 .ctl_name = FS_OVERFLOWGID,
1096 .procname = "overflowgid",
1097 .data = &fs_overflowgid,
1098 .maxlen = sizeof(int),
1099 .mode = 0644,
1100 .proc_handler = &proc_dointvec_minmax,
1101 .strategy = &sysctl_intvec,
1102 .extra1 = &minolduid,
1103 .extra2 = &maxolduid,
1106 .ctl_name = FS_LEASES,
1107 .procname = "leases-enable",
1108 .data = &leases_enable,
1109 .maxlen = sizeof(int),
1110 .mode = 0644,
1111 .proc_handler = &proc_dointvec,
1113 #ifdef CONFIG_DNOTIFY
1115 .ctl_name = FS_DIR_NOTIFY,
1116 .procname = "dir-notify-enable",
1117 .data = &dir_notify_enable,
1118 .maxlen = sizeof(int),
1119 .mode = 0644,
1120 .proc_handler = &proc_dointvec,
1122 #endif
1123 #ifdef CONFIG_MMU
1125 .ctl_name = FS_LEASE_TIME,
1126 .procname = "lease-break-time",
1127 .data = &lease_break_time,
1128 .maxlen = sizeof(int),
1129 .mode = 0644,
1130 .proc_handler = &proc_dointvec,
1133 .ctl_name = FS_AIO_NR,
1134 .procname = "aio-nr",
1135 .data = &aio_nr,
1136 .maxlen = sizeof(aio_nr),
1137 .mode = 0444,
1138 .proc_handler = &proc_doulongvec_minmax,
1141 .ctl_name = FS_AIO_MAX_NR,
1142 .procname = "aio-max-nr",
1143 .data = &aio_max_nr,
1144 .maxlen = sizeof(aio_max_nr),
1145 .mode = 0644,
1146 .proc_handler = &proc_doulongvec_minmax,
1148 #ifdef CONFIG_INOTIFY_USER
1150 .ctl_name = FS_INOTIFY,
1151 .procname = "inotify",
1152 .mode = 0555,
1153 .child = inotify_table,
1155 #endif
1156 #endif
1158 .ctl_name = KERN_SETUID_DUMPABLE,
1159 .procname = "suid_dumpable",
1160 .data = &suid_dumpable,
1161 .maxlen = sizeof(int),
1162 .mode = 0644,
1163 .proc_handler = &proc_dointvec,
1165 { .ctl_name = 0 }
1168 static ctl_table debug_table[] = {
1169 { .ctl_name = 0 }
1172 static ctl_table dev_table[] = {
1173 { .ctl_name = 0 }
1176 extern void init_irq_proc (void);
1178 static DEFINE_SPINLOCK(sysctl_lock);
1180 /* called under sysctl_lock */
1181 static int use_table(struct ctl_table_header *p)
1183 if (unlikely(p->unregistering))
1184 return 0;
1185 p->used++;
1186 return 1;
1189 /* called under sysctl_lock */
1190 static void unuse_table(struct ctl_table_header *p)
1192 if (!--p->used)
1193 if (unlikely(p->unregistering))
1194 complete(p->unregistering);
1197 /* called under sysctl_lock, will reacquire if has to wait */
1198 static void start_unregistering(struct ctl_table_header *p)
1201 * if p->used is 0, nobody will ever touch that entry again;
1202 * we'll eliminate all paths to it before dropping sysctl_lock
1204 if (unlikely(p->used)) {
1205 struct completion wait;
1206 init_completion(&wait);
1207 p->unregistering = &wait;
1208 spin_unlock(&sysctl_lock);
1209 wait_for_completion(&wait);
1210 spin_lock(&sysctl_lock);
1213 * do not remove from the list until nobody holds it; walking the
1214 * list in do_sysctl() relies on that.
1216 list_del_init(&p->ctl_entry);
1219 void __init sysctl_init(void)
1221 #ifdef CONFIG_PROC_SYSCTL
1222 register_proc_table(root_table, proc_sys_root, &root_table_header);
1223 init_irq_proc();
1224 #endif
1227 #ifdef CONFIG_SYSCTL_SYSCALL
1228 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1229 void __user *newval, size_t newlen)
1231 struct list_head *tmp;
1232 int error = -ENOTDIR;
1234 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1235 return -ENOTDIR;
1236 if (oldval) {
1237 int old_len;
1238 if (!oldlenp || get_user(old_len, oldlenp))
1239 return -EFAULT;
1241 spin_lock(&sysctl_lock);
1242 tmp = &root_table_header.ctl_entry;
1243 do {
1244 struct ctl_table_header *head =
1245 list_entry(tmp, struct ctl_table_header, ctl_entry);
1247 if (!use_table(head))
1248 continue;
1250 spin_unlock(&sysctl_lock);
1252 error = parse_table(name, nlen, oldval, oldlenp,
1253 newval, newlen, head->ctl_table);
1255 spin_lock(&sysctl_lock);
1256 unuse_table(head);
1257 if (error != -ENOTDIR)
1258 break;
1259 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1260 spin_unlock(&sysctl_lock);
1261 return error;
1264 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1266 struct __sysctl_args tmp;
1267 int error;
1269 if (copy_from_user(&tmp, args, sizeof(tmp)))
1270 return -EFAULT;
1272 lock_kernel();
1273 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1274 tmp.newval, tmp.newlen);
1275 unlock_kernel();
1276 return error;
1278 #endif /* CONFIG_SYSCTL_SYSCALL */
1281 * ctl_perm does NOT grant the superuser all rights automatically, because
1282 * some sysctl variables are readonly even to root.
1285 static int test_perm(int mode, int op)
1287 if (!current->euid)
1288 mode >>= 6;
1289 else if (in_egroup_p(0))
1290 mode >>= 3;
1291 if ((mode & op & 0007) == op)
1292 return 0;
1293 return -EACCES;
1296 static inline int ctl_perm(ctl_table *table, int op)
1298 int error;
1299 error = security_sysctl(table, op);
1300 if (error)
1301 return error;
1302 return test_perm(table->mode, op);
1305 #ifdef CONFIG_SYSCTL_SYSCALL
1306 static int parse_table(int __user *name, int nlen,
1307 void __user *oldval, size_t __user *oldlenp,
1308 void __user *newval, size_t newlen,
1309 ctl_table *table)
1311 int n;
1312 repeat:
1313 if (!nlen)
1314 return -ENOTDIR;
1315 if (get_user(n, name))
1316 return -EFAULT;
1317 for ( ; table->ctl_name || table->procname; table++) {
1318 if (!table->ctl_name)
1319 continue;
1320 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1321 int error;
1322 if (table->child) {
1323 if (ctl_perm(table, 001))
1324 return -EPERM;
1325 if (table->strategy) {
1326 error = table->strategy(
1327 table, name, nlen,
1328 oldval, oldlenp,
1329 newval, newlen);
1330 if (error)
1331 return error;
1333 name++;
1334 nlen--;
1335 table = table->child;
1336 goto repeat;
1338 error = do_sysctl_strategy(table, name, nlen,
1339 oldval, oldlenp,
1340 newval, newlen);
1341 return error;
1344 return -ENOTDIR;
1347 /* Perform the actual read/write of a sysctl table entry. */
1348 int do_sysctl_strategy (ctl_table *table,
1349 int __user *name, int nlen,
1350 void __user *oldval, size_t __user *oldlenp,
1351 void __user *newval, size_t newlen)
1353 int op = 0, rc;
1354 size_t len;
1356 if (oldval)
1357 op |= 004;
1358 if (newval)
1359 op |= 002;
1360 if (ctl_perm(table, op))
1361 return -EPERM;
1363 if (table->strategy) {
1364 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1365 newval, newlen);
1366 if (rc < 0)
1367 return rc;
1368 if (rc > 0)
1369 return 0;
1372 /* If there is no strategy routine, or if the strategy returns
1373 * zero, proceed with automatic r/w */
1374 if (table->data && table->maxlen) {
1375 if (oldval && oldlenp) {
1376 if (get_user(len, oldlenp))
1377 return -EFAULT;
1378 if (len) {
1379 if (len > table->maxlen)
1380 len = table->maxlen;
1381 if(copy_to_user(oldval, table->data, len))
1382 return -EFAULT;
1383 if(put_user(len, oldlenp))
1384 return -EFAULT;
1387 if (newval && newlen) {
1388 len = newlen;
1389 if (len > table->maxlen)
1390 len = table->maxlen;
1391 if(copy_from_user(table->data, newval, len))
1392 return -EFAULT;
1395 return 0;
1397 #endif /* CONFIG_SYSCTL_SYSCALL */
1400 * register_sysctl_table - register a sysctl hierarchy
1401 * @table: the top-level table structure
1402 * @insert_at_head: whether the entry should be inserted in front or at the end
1404 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1405 * array. An entry with a ctl_name of 0 terminates the table.
1407 * The members of the &ctl_table structure are used as follows:
1409 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1410 * must be unique within that level of sysctl
1412 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1413 * enter a sysctl file
1415 * data - a pointer to data for use by proc_handler
1417 * maxlen - the maximum size in bytes of the data
1419 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1421 * child - a pointer to the child sysctl table if this entry is a directory, or
1422 * %NULL.
1424 * proc_handler - the text handler routine (described below)
1426 * strategy - the strategy routine (described below)
1428 * de - for internal use by the sysctl routines
1430 * extra1, extra2 - extra pointers usable by the proc handler routines
1432 * Leaf nodes in the sysctl tree will be represented by a single file
1433 * under /proc; non-leaf nodes will be represented by directories.
1435 * sysctl(2) can automatically manage read and write requests through
1436 * the sysctl table. The data and maxlen fields of the ctl_table
1437 * struct enable minimal validation of the values being written to be
1438 * performed, and the mode field allows minimal authentication.
1440 * More sophisticated management can be enabled by the provision of a
1441 * strategy routine with the table entry. This will be called before
1442 * any automatic read or write of the data is performed.
1444 * The strategy routine may return
1446 * < 0 - Error occurred (error is passed to user process)
1448 * 0 - OK - proceed with automatic read or write.
1450 * > 0 - OK - read or write has been done by the strategy routine, so
1451 * return immediately.
1453 * There must be a proc_handler routine for any terminal nodes
1454 * mirrored under /proc/sys (non-terminals are handled by a built-in
1455 * directory handler). Several default handlers are available to
1456 * cover common cases -
1458 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1459 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1460 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1462 * It is the handler's job to read the input buffer from user memory
1463 * and process it. The handler should return 0 on success.
1465 * This routine returns %NULL on a failure to register, and a pointer
1466 * to the table header on success.
1468 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1469 int insert_at_head)
1471 struct ctl_table_header *tmp;
1472 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1473 if (!tmp)
1474 return NULL;
1475 tmp->ctl_table = table;
1476 INIT_LIST_HEAD(&tmp->ctl_entry);
1477 tmp->used = 0;
1478 tmp->unregistering = NULL;
1479 spin_lock(&sysctl_lock);
1480 if (insert_at_head)
1481 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1482 else
1483 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1484 spin_unlock(&sysctl_lock);
1485 #ifdef CONFIG_PROC_SYSCTL
1486 register_proc_table(table, proc_sys_root, tmp);
1487 #endif
1488 return tmp;
1492 * unregister_sysctl_table - unregister a sysctl table hierarchy
1493 * @header: the header returned from register_sysctl_table
1495 * Unregisters the sysctl table and all children. proc entries may not
1496 * actually be removed until they are no longer used by anyone.
1498 void unregister_sysctl_table(struct ctl_table_header * header)
1500 might_sleep();
1501 spin_lock(&sysctl_lock);
1502 start_unregistering(header);
1503 #ifdef CONFIG_PROC_SYSCTL
1504 unregister_proc_table(header->ctl_table, proc_sys_root);
1505 #endif
1506 spin_unlock(&sysctl_lock);
1507 kfree(header);
1510 #else /* !CONFIG_SYSCTL */
1511 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1512 int insert_at_head)
1514 return NULL;
1517 void unregister_sysctl_table(struct ctl_table_header * table)
1521 #endif /* CONFIG_SYSCTL */
1524 * /proc/sys support
1527 #ifdef CONFIG_PROC_SYSCTL
1529 /* Scan the sysctl entries in table and add them all into /proc */
1530 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1532 struct proc_dir_entry *de;
1533 int len;
1534 mode_t mode;
1536 for (; table->ctl_name || table->procname; table++) {
1537 /* Can't do anything without a proc name. */
1538 if (!table->procname)
1539 continue;
1540 /* Maybe we can't do anything with it... */
1541 if (!table->proc_handler && !table->child) {
1542 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1543 table->procname);
1544 continue;
1547 len = strlen(table->procname);
1548 mode = table->mode;
1550 de = NULL;
1551 if (table->proc_handler)
1552 mode |= S_IFREG;
1553 else {
1554 mode |= S_IFDIR;
1555 for (de = root->subdir; de; de = de->next) {
1556 if (proc_match(len, table->procname, de))
1557 break;
1559 /* If the subdir exists already, de is non-NULL */
1562 if (!de) {
1563 de = create_proc_entry(table->procname, mode, root);
1564 if (!de)
1565 continue;
1566 de->set = set;
1567 de->data = (void *) table;
1568 if (table->proc_handler)
1569 de->proc_fops = &proc_sys_file_operations;
1571 table->de = de;
1572 if (de->mode & S_IFDIR)
1573 register_proc_table(table->child, de, set);
1578 * Unregister a /proc sysctl table and any subdirectories.
1580 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1582 struct proc_dir_entry *de;
1583 for (; table->ctl_name || table->procname; table++) {
1584 if (!(de = table->de))
1585 continue;
1586 if (de->mode & S_IFDIR) {
1587 if (!table->child) {
1588 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1589 continue;
1591 unregister_proc_table(table->child, de);
1593 /* Don't unregister directories which still have entries.. */
1594 if (de->subdir)
1595 continue;
1599 * In any case, mark the entry as goner; we'll keep it
1600 * around if it's busy, but we'll know to do nothing with
1601 * its fields. We are under sysctl_lock here.
1603 de->data = NULL;
1605 /* Don't unregister proc entries that are still being used.. */
1606 if (atomic_read(&de->count))
1607 continue;
1609 table->de = NULL;
1610 remove_proc_entry(table->procname, root);
1614 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1615 size_t count, loff_t *ppos)
1617 int op;
1618 struct proc_dir_entry *de = PDE(file->f_path.dentry->d_inode);
1619 struct ctl_table *table;
1620 size_t res;
1621 ssize_t error = -ENOTDIR;
1623 spin_lock(&sysctl_lock);
1624 if (de && de->data && use_table(de->set)) {
1626 * at that point we know that sysctl was not unregistered
1627 * and won't be until we finish
1629 spin_unlock(&sysctl_lock);
1630 table = (struct ctl_table *) de->data;
1631 if (!table || !table->proc_handler)
1632 goto out;
1633 error = -EPERM;
1634 op = (write ? 002 : 004);
1635 if (ctl_perm(table, op))
1636 goto out;
1638 /* careful: calling conventions are nasty here */
1639 res = count;
1640 error = (*table->proc_handler)(table, write, file,
1641 buf, &res, ppos);
1642 if (!error)
1643 error = res;
1644 out:
1645 spin_lock(&sysctl_lock);
1646 unuse_table(de->set);
1648 spin_unlock(&sysctl_lock);
1649 return error;
1652 static int proc_opensys(struct inode *inode, struct file *file)
1654 if (file->f_mode & FMODE_WRITE) {
1656 * sysctl entries that are not writable,
1657 * are _NOT_ writable, capabilities or not.
1659 if (!(inode->i_mode & S_IWUSR))
1660 return -EPERM;
1663 return 0;
1666 static ssize_t proc_readsys(struct file * file, char __user * buf,
1667 size_t count, loff_t *ppos)
1669 return do_rw_proc(0, file, buf, count, ppos);
1672 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1673 size_t count, loff_t *ppos)
1675 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1678 static int _proc_do_string(void* data, int maxlen, int write,
1679 struct file *filp, void __user *buffer,
1680 size_t *lenp, loff_t *ppos)
1682 size_t len;
1683 char __user *p;
1684 char c;
1686 if (!data || !maxlen || !*lenp ||
1687 (*ppos && !write)) {
1688 *lenp = 0;
1689 return 0;
1692 if (write) {
1693 len = 0;
1694 p = buffer;
1695 while (len < *lenp) {
1696 if (get_user(c, p++))
1697 return -EFAULT;
1698 if (c == 0 || c == '\n')
1699 break;
1700 len++;
1702 if (len >= maxlen)
1703 len = maxlen-1;
1704 if(copy_from_user(data, buffer, len))
1705 return -EFAULT;
1706 ((char *) data)[len] = 0;
1707 *ppos += *lenp;
1708 } else {
1709 len = strlen(data);
1710 if (len > maxlen)
1711 len = maxlen;
1712 if (len > *lenp)
1713 len = *lenp;
1714 if (len)
1715 if(copy_to_user(buffer, data, len))
1716 return -EFAULT;
1717 if (len < *lenp) {
1718 if(put_user('\n', ((char __user *) buffer) + len))
1719 return -EFAULT;
1720 len++;
1722 *lenp = len;
1723 *ppos += len;
1725 return 0;
1729 * proc_dostring - read a string sysctl
1730 * @table: the sysctl table
1731 * @write: %TRUE if this is a write to the sysctl file
1732 * @filp: the file structure
1733 * @buffer: the user buffer
1734 * @lenp: the size of the user buffer
1735 * @ppos: file position
1737 * Reads/writes a string from/to the user buffer. If the kernel
1738 * buffer provided is not large enough to hold the string, the
1739 * string is truncated. The copied string is %NULL-terminated.
1740 * If the string is being read by the user process, it is copied
1741 * and a newline '\n' is added. It is truncated if the buffer is
1742 * not large enough.
1744 * Returns 0 on success.
1746 int proc_dostring(ctl_table *table, int write, struct file *filp,
1747 void __user *buffer, size_t *lenp, loff_t *ppos)
1749 return _proc_do_string(table->data, table->maxlen, write, filp,
1750 buffer, lenp, ppos);
1754 * Special case of dostring for the UTS structure. This has locks
1755 * to observe. Should this be in kernel/sys.c ????
1758 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
1759 void __user *buffer, size_t *lenp, loff_t *ppos)
1761 int r;
1762 void *which;
1763 which = get_uts(table, write);
1764 r = _proc_do_string(which, table->maxlen,write,filp,buffer,lenp, ppos);
1765 put_uts(table, write, which);
1766 return r;
1769 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1770 int *valp,
1771 int write, void *data)
1773 if (write) {
1774 *valp = *negp ? -*lvalp : *lvalp;
1775 } else {
1776 int val = *valp;
1777 if (val < 0) {
1778 *negp = -1;
1779 *lvalp = (unsigned long)-val;
1780 } else {
1781 *negp = 0;
1782 *lvalp = (unsigned long)val;
1785 return 0;
1788 static int __do_proc_dointvec(void *tbl_data, ctl_table *table,
1789 int write, struct file *filp, void __user *buffer,
1790 size_t *lenp, loff_t *ppos,
1791 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1792 int write, void *data),
1793 void *data)
1795 #define TMPBUFLEN 21
1796 int *i, vleft, first=1, neg, val;
1797 unsigned long lval;
1798 size_t left, len;
1800 char buf[TMPBUFLEN], *p;
1801 char __user *s = buffer;
1803 if (!tbl_data || !table->maxlen || !*lenp ||
1804 (*ppos && !write)) {
1805 *lenp = 0;
1806 return 0;
1809 i = (int *) tbl_data;
1810 vleft = table->maxlen / sizeof(*i);
1811 left = *lenp;
1813 if (!conv)
1814 conv = do_proc_dointvec_conv;
1816 for (; left && vleft--; i++, first=0) {
1817 if (write) {
1818 while (left) {
1819 char c;
1820 if (get_user(c, s))
1821 return -EFAULT;
1822 if (!isspace(c))
1823 break;
1824 left--;
1825 s++;
1827 if (!left)
1828 break;
1829 neg = 0;
1830 len = left;
1831 if (len > sizeof(buf) - 1)
1832 len = sizeof(buf) - 1;
1833 if (copy_from_user(buf, s, len))
1834 return -EFAULT;
1835 buf[len] = 0;
1836 p = buf;
1837 if (*p == '-' && left > 1) {
1838 neg = 1;
1839 p++;
1841 if (*p < '0' || *p > '9')
1842 break;
1844 lval = simple_strtoul(p, &p, 0);
1846 len = p-buf;
1847 if ((len < left) && *p && !isspace(*p))
1848 break;
1849 if (neg)
1850 val = -val;
1851 s += len;
1852 left -= len;
1854 if (conv(&neg, &lval, i, 1, data))
1855 break;
1856 } else {
1857 p = buf;
1858 if (!first)
1859 *p++ = '\t';
1861 if (conv(&neg, &lval, i, 0, data))
1862 break;
1864 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1865 len = strlen(buf);
1866 if (len > left)
1867 len = left;
1868 if(copy_to_user(s, buf, len))
1869 return -EFAULT;
1870 left -= len;
1871 s += len;
1875 if (!write && !first && left) {
1876 if(put_user('\n', s))
1877 return -EFAULT;
1878 left--, s++;
1880 if (write) {
1881 while (left) {
1882 char c;
1883 if (get_user(c, s++))
1884 return -EFAULT;
1885 if (!isspace(c))
1886 break;
1887 left--;
1890 if (write && first)
1891 return -EINVAL;
1892 *lenp -= left;
1893 *ppos += *lenp;
1894 return 0;
1895 #undef TMPBUFLEN
1898 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1899 void __user *buffer, size_t *lenp, loff_t *ppos,
1900 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1901 int write, void *data),
1902 void *data)
1904 return __do_proc_dointvec(table->data, table, write, filp,
1905 buffer, lenp, ppos, conv, data);
1909 * proc_dointvec - read a vector of integers
1910 * @table: the sysctl table
1911 * @write: %TRUE if this is a write to the sysctl file
1912 * @filp: the file structure
1913 * @buffer: the user buffer
1914 * @lenp: the size of the user buffer
1915 * @ppos: file position
1917 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1918 * values from/to the user buffer, treated as an ASCII string.
1920 * Returns 0 on success.
1922 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1923 void __user *buffer, size_t *lenp, loff_t *ppos)
1925 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1926 NULL,NULL);
1929 #define OP_SET 0
1930 #define OP_AND 1
1932 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1933 int *valp,
1934 int write, void *data)
1936 int op = *(int *)data;
1937 if (write) {
1938 int val = *negp ? -*lvalp : *lvalp;
1939 switch(op) {
1940 case OP_SET: *valp = val; break;
1941 case OP_AND: *valp &= val; break;
1943 } else {
1944 int val = *valp;
1945 if (val < 0) {
1946 *negp = -1;
1947 *lvalp = (unsigned long)-val;
1948 } else {
1949 *negp = 0;
1950 *lvalp = (unsigned long)val;
1953 return 0;
1957 * init may raise the set.
1960 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1961 void __user *buffer, size_t *lenp, loff_t *ppos)
1963 int op;
1965 if (!capable(CAP_SYS_MODULE)) {
1966 return -EPERM;
1969 op = is_init(current) ? OP_SET : OP_AND;
1970 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1971 do_proc_dointvec_bset_conv,&op);
1974 struct do_proc_dointvec_minmax_conv_param {
1975 int *min;
1976 int *max;
1979 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1980 int *valp,
1981 int write, void *data)
1983 struct do_proc_dointvec_minmax_conv_param *param = data;
1984 if (write) {
1985 int val = *negp ? -*lvalp : *lvalp;
1986 if ((param->min && *param->min > val) ||
1987 (param->max && *param->max < val))
1988 return -EINVAL;
1989 *valp = val;
1990 } else {
1991 int val = *valp;
1992 if (val < 0) {
1993 *negp = -1;
1994 *lvalp = (unsigned long)-val;
1995 } else {
1996 *negp = 0;
1997 *lvalp = (unsigned long)val;
2000 return 0;
2004 * proc_dointvec_minmax - read a vector of integers with min/max values
2005 * @table: the sysctl table
2006 * @write: %TRUE if this is a write to the sysctl file
2007 * @filp: the file structure
2008 * @buffer: the user buffer
2009 * @lenp: the size of the user buffer
2010 * @ppos: file position
2012 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2013 * values from/to the user buffer, treated as an ASCII string.
2015 * This routine will ensure the values are within the range specified by
2016 * table->extra1 (min) and table->extra2 (max).
2018 * Returns 0 on success.
2020 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2021 void __user *buffer, size_t *lenp, loff_t *ppos)
2023 struct do_proc_dointvec_minmax_conv_param param = {
2024 .min = (int *) table->extra1,
2025 .max = (int *) table->extra2,
2027 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2028 do_proc_dointvec_minmax_conv, &param);
2031 static int __do_proc_doulongvec_minmax(void *data, ctl_table *table, int write,
2032 struct file *filp,
2033 void __user *buffer,
2034 size_t *lenp, loff_t *ppos,
2035 unsigned long convmul,
2036 unsigned long convdiv)
2038 #define TMPBUFLEN 21
2039 unsigned long *i, *min, *max, val;
2040 int vleft, first=1, neg;
2041 size_t len, left;
2042 char buf[TMPBUFLEN], *p;
2043 char __user *s = buffer;
2045 if (!data || !table->maxlen || !*lenp ||
2046 (*ppos && !write)) {
2047 *lenp = 0;
2048 return 0;
2051 i = (unsigned long *) data;
2052 min = (unsigned long *) table->extra1;
2053 max = (unsigned long *) table->extra2;
2054 vleft = table->maxlen / sizeof(unsigned long);
2055 left = *lenp;
2057 for (; left && vleft--; i++, min++, max++, first=0) {
2058 if (write) {
2059 while (left) {
2060 char c;
2061 if (get_user(c, s))
2062 return -EFAULT;
2063 if (!isspace(c))
2064 break;
2065 left--;
2066 s++;
2068 if (!left)
2069 break;
2070 neg = 0;
2071 len = left;
2072 if (len > TMPBUFLEN-1)
2073 len = TMPBUFLEN-1;
2074 if (copy_from_user(buf, s, len))
2075 return -EFAULT;
2076 buf[len] = 0;
2077 p = buf;
2078 if (*p == '-' && left > 1) {
2079 neg = 1;
2080 p++;
2082 if (*p < '0' || *p > '9')
2083 break;
2084 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2085 len = p-buf;
2086 if ((len < left) && *p && !isspace(*p))
2087 break;
2088 if (neg)
2089 val = -val;
2090 s += len;
2091 left -= len;
2093 if(neg)
2094 continue;
2095 if ((min && val < *min) || (max && val > *max))
2096 continue;
2097 *i = val;
2098 } else {
2099 p = buf;
2100 if (!first)
2101 *p++ = '\t';
2102 sprintf(p, "%lu", convdiv * (*i) / convmul);
2103 len = strlen(buf);
2104 if (len > left)
2105 len = left;
2106 if(copy_to_user(s, buf, len))
2107 return -EFAULT;
2108 left -= len;
2109 s += len;
2113 if (!write && !first && left) {
2114 if(put_user('\n', s))
2115 return -EFAULT;
2116 left--, s++;
2118 if (write) {
2119 while (left) {
2120 char c;
2121 if (get_user(c, s++))
2122 return -EFAULT;
2123 if (!isspace(c))
2124 break;
2125 left--;
2128 if (write && first)
2129 return -EINVAL;
2130 *lenp -= left;
2131 *ppos += *lenp;
2132 return 0;
2133 #undef TMPBUFLEN
2136 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
2137 struct file *filp,
2138 void __user *buffer,
2139 size_t *lenp, loff_t *ppos,
2140 unsigned long convmul,
2141 unsigned long convdiv)
2143 return __do_proc_doulongvec_minmax(table->data, table, write,
2144 filp, buffer, lenp, ppos, convmul, convdiv);
2148 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2149 * @table: the sysctl table
2150 * @write: %TRUE if this is a write to the sysctl file
2151 * @filp: the file structure
2152 * @buffer: the user buffer
2153 * @lenp: the size of the user buffer
2154 * @ppos: file position
2156 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2157 * values from/to the user buffer, treated as an ASCII string.
2159 * This routine will ensure the values are within the range specified by
2160 * table->extra1 (min) and table->extra2 (max).
2162 * Returns 0 on success.
2164 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2165 void __user *buffer, size_t *lenp, loff_t *ppos)
2167 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2171 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2172 * @table: the sysctl table
2173 * @write: %TRUE if this is a write to the sysctl file
2174 * @filp: the file structure
2175 * @buffer: the user buffer
2176 * @lenp: the size of the user buffer
2177 * @ppos: file position
2179 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2180 * values from/to the user buffer, treated as an ASCII string. The values
2181 * are treated as milliseconds, and converted to jiffies when they are stored.
2183 * This routine will ensure the values are within the range specified by
2184 * table->extra1 (min) and table->extra2 (max).
2186 * Returns 0 on success.
2188 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2189 struct file *filp,
2190 void __user *buffer,
2191 size_t *lenp, loff_t *ppos)
2193 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2194 lenp, ppos, HZ, 1000l);
2198 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2199 int *valp,
2200 int write, void *data)
2202 if (write) {
2203 if (*lvalp > LONG_MAX / HZ)
2204 return 1;
2205 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2206 } else {
2207 int val = *valp;
2208 unsigned long lval;
2209 if (val < 0) {
2210 *negp = -1;
2211 lval = (unsigned long)-val;
2212 } else {
2213 *negp = 0;
2214 lval = (unsigned long)val;
2216 *lvalp = lval / HZ;
2218 return 0;
2221 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2222 int *valp,
2223 int write, void *data)
2225 if (write) {
2226 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2227 return 1;
2228 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2229 } else {
2230 int val = *valp;
2231 unsigned long lval;
2232 if (val < 0) {
2233 *negp = -1;
2234 lval = (unsigned long)-val;
2235 } else {
2236 *negp = 0;
2237 lval = (unsigned long)val;
2239 *lvalp = jiffies_to_clock_t(lval);
2241 return 0;
2244 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2245 int *valp,
2246 int write, void *data)
2248 if (write) {
2249 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2250 } else {
2251 int val = *valp;
2252 unsigned long lval;
2253 if (val < 0) {
2254 *negp = -1;
2255 lval = (unsigned long)-val;
2256 } else {
2257 *negp = 0;
2258 lval = (unsigned long)val;
2260 *lvalp = jiffies_to_msecs(lval);
2262 return 0;
2266 * proc_dointvec_jiffies - read a vector of integers as seconds
2267 * @table: the sysctl table
2268 * @write: %TRUE if this is a write to the sysctl file
2269 * @filp: the file structure
2270 * @buffer: the user buffer
2271 * @lenp: the size of the user buffer
2272 * @ppos: file position
2274 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2275 * values from/to the user buffer, treated as an ASCII string.
2276 * The values read are assumed to be in seconds, and are converted into
2277 * jiffies.
2279 * Returns 0 on success.
2281 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2282 void __user *buffer, size_t *lenp, loff_t *ppos)
2284 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2285 do_proc_dointvec_jiffies_conv,NULL);
2289 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2290 * @table: the sysctl table
2291 * @write: %TRUE if this is a write to the sysctl file
2292 * @filp: the file structure
2293 * @buffer: the user buffer
2294 * @lenp: the size of the user buffer
2295 * @ppos: pointer to the file position
2297 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2298 * values from/to the user buffer, treated as an ASCII string.
2299 * The values read are assumed to be in 1/USER_HZ seconds, and
2300 * are converted into jiffies.
2302 * Returns 0 on success.
2304 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2305 void __user *buffer, size_t *lenp, loff_t *ppos)
2307 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2308 do_proc_dointvec_userhz_jiffies_conv,NULL);
2312 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2313 * @table: the sysctl table
2314 * @write: %TRUE if this is a write to the sysctl file
2315 * @filp: the file structure
2316 * @buffer: the user buffer
2317 * @lenp: the size of the user buffer
2318 * @ppos: file position
2319 * @ppos: the current position in the file
2321 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2322 * values from/to the user buffer, treated as an ASCII string.
2323 * The values read are assumed to be in 1/1000 seconds, and
2324 * are converted into jiffies.
2326 * Returns 0 on success.
2328 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2329 void __user *buffer, size_t *lenp, loff_t *ppos)
2331 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2332 do_proc_dointvec_ms_jiffies_conv, NULL);
2335 #ifdef CONFIG_SYSVIPC
2336 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2337 void __user *buffer, size_t *lenp, loff_t *ppos)
2339 void *which;
2340 which = get_ipc(table, write);
2341 return __do_proc_dointvec(which, table, write, filp, buffer,
2342 lenp, ppos, NULL, NULL);
2345 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2346 struct file *filp, void __user *buffer, size_t *lenp, loff_t *ppos)
2348 void *which;
2349 which = get_ipc(table, write);
2350 return __do_proc_doulongvec_minmax(which, table, write, filp, buffer,
2351 lenp, ppos, 1l, 1l);
2354 #endif
2356 static int proc_do_cad_pid(ctl_table *table, int write, struct file *filp,
2357 void __user *buffer, size_t *lenp, loff_t *ppos)
2359 struct pid *new_pid;
2360 pid_t tmp;
2361 int r;
2363 tmp = pid_nr(cad_pid);
2365 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2366 lenp, ppos, NULL, NULL);
2367 if (r || !write)
2368 return r;
2370 new_pid = find_get_pid(tmp);
2371 if (!new_pid)
2372 return -ESRCH;
2374 put_pid(xchg(&cad_pid, new_pid));
2375 return 0;
2378 #else /* CONFIG_PROC_FS */
2380 int proc_dostring(ctl_table *table, int write, struct file *filp,
2381 void __user *buffer, size_t *lenp, loff_t *ppos)
2383 return -ENOSYS;
2386 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
2387 void __user *buffer, size_t *lenp, loff_t *ppos)
2389 return -ENOSYS;
2392 #ifdef CONFIG_SYSVIPC
2393 static int proc_do_ipc_string(ctl_table *table, int write, struct file *filp,
2394 void __user *buffer, size_t *lenp, loff_t *ppos)
2396 return -ENOSYS;
2398 static int proc_ipc_dointvec(ctl_table *table, int write, struct file *filp,
2399 void __user *buffer, size_t *lenp, loff_t *ppos)
2401 return -ENOSYS;
2403 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
2404 struct file *filp, void __user *buffer,
2405 size_t *lenp, loff_t *ppos)
2407 return -ENOSYS;
2409 #endif
2411 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2412 void __user *buffer, size_t *lenp, loff_t *ppos)
2414 return -ENOSYS;
2417 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2418 void __user *buffer, size_t *lenp, loff_t *ppos)
2420 return -ENOSYS;
2423 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2424 void __user *buffer, size_t *lenp, loff_t *ppos)
2426 return -ENOSYS;
2429 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2430 void __user *buffer, size_t *lenp, loff_t *ppos)
2432 return -ENOSYS;
2435 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2436 void __user *buffer, size_t *lenp, loff_t *ppos)
2438 return -ENOSYS;
2441 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2442 void __user *buffer, size_t *lenp, loff_t *ppos)
2444 return -ENOSYS;
2447 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2448 void __user *buffer, size_t *lenp, loff_t *ppos)
2450 return -ENOSYS;
2453 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2454 struct file *filp,
2455 void __user *buffer,
2456 size_t *lenp, loff_t *ppos)
2458 return -ENOSYS;
2462 #endif /* CONFIG_PROC_FS */
2465 #ifdef CONFIG_SYSCTL_SYSCALL
2467 * General sysctl support routines
2470 /* The generic string strategy routine: */
2471 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2472 void __user *oldval, size_t __user *oldlenp,
2473 void __user *newval, size_t newlen)
2475 if (!table->data || !table->maxlen)
2476 return -ENOTDIR;
2478 if (oldval && oldlenp) {
2479 size_t bufsize;
2480 if (get_user(bufsize, oldlenp))
2481 return -EFAULT;
2482 if (bufsize) {
2483 size_t len = strlen(table->data), copied;
2485 /* This shouldn't trigger for a well-formed sysctl */
2486 if (len > table->maxlen)
2487 len = table->maxlen;
2489 /* Copy up to a max of bufsize-1 bytes of the string */
2490 copied = (len >= bufsize) ? bufsize - 1 : len;
2492 if (copy_to_user(oldval, table->data, copied) ||
2493 put_user(0, (char __user *)(oldval + copied)))
2494 return -EFAULT;
2495 if (put_user(len, oldlenp))
2496 return -EFAULT;
2499 if (newval && newlen) {
2500 size_t len = newlen;
2501 if (len > table->maxlen)
2502 len = table->maxlen;
2503 if(copy_from_user(table->data, newval, len))
2504 return -EFAULT;
2505 if (len == table->maxlen)
2506 len--;
2507 ((char *) table->data)[len] = 0;
2509 return 1;
2513 * This function makes sure that all of the integers in the vector
2514 * are between the minimum and maximum values given in the arrays
2515 * table->extra1 and table->extra2, respectively.
2517 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2518 void __user *oldval, size_t __user *oldlenp,
2519 void __user *newval, size_t newlen)
2522 if (newval && newlen) {
2523 int __user *vec = (int __user *) newval;
2524 int *min = (int *) table->extra1;
2525 int *max = (int *) table->extra2;
2526 size_t length;
2527 int i;
2529 if (newlen % sizeof(int) != 0)
2530 return -EINVAL;
2532 if (!table->extra1 && !table->extra2)
2533 return 0;
2535 if (newlen > table->maxlen)
2536 newlen = table->maxlen;
2537 length = newlen / sizeof(int);
2539 for (i = 0; i < length; i++) {
2540 int value;
2541 if (get_user(value, vec + i))
2542 return -EFAULT;
2543 if (min && value < min[i])
2544 return -EINVAL;
2545 if (max && value > max[i])
2546 return -EINVAL;
2549 return 0;
2552 /* Strategy function to convert jiffies to seconds */
2553 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2554 void __user *oldval, size_t __user *oldlenp,
2555 void __user *newval, size_t newlen)
2557 if (oldval) {
2558 size_t olen;
2559 if (oldlenp) {
2560 if (get_user(olen, oldlenp))
2561 return -EFAULT;
2562 if (olen!=sizeof(int))
2563 return -EINVAL;
2565 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2566 (oldlenp && put_user(sizeof(int),oldlenp)))
2567 return -EFAULT;
2569 if (newval && newlen) {
2570 int new;
2571 if (newlen != sizeof(int))
2572 return -EINVAL;
2573 if (get_user(new, (int __user *)newval))
2574 return -EFAULT;
2575 *(int *)(table->data) = new*HZ;
2577 return 1;
2580 /* Strategy function to convert jiffies to seconds */
2581 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2582 void __user *oldval, size_t __user *oldlenp,
2583 void __user *newval, size_t newlen)
2585 if (oldval) {
2586 size_t olen;
2587 if (oldlenp) {
2588 if (get_user(olen, oldlenp))
2589 return -EFAULT;
2590 if (olen!=sizeof(int))
2591 return -EINVAL;
2593 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2594 (oldlenp && put_user(sizeof(int),oldlenp)))
2595 return -EFAULT;
2597 if (newval && newlen) {
2598 int new;
2599 if (newlen != sizeof(int))
2600 return -EINVAL;
2601 if (get_user(new, (int __user *)newval))
2602 return -EFAULT;
2603 *(int *)(table->data) = msecs_to_jiffies(new);
2605 return 1;
2609 /* The generic string strategy routine: */
2610 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2611 void __user *oldval, size_t __user *oldlenp,
2612 void __user *newval, size_t newlen)
2614 struct ctl_table uts_table;
2615 int r, write;
2616 write = newval && newlen;
2617 memcpy(&uts_table, table, sizeof(uts_table));
2618 uts_table.data = get_uts(table, write);
2619 r = sysctl_string(&uts_table, name, nlen,
2620 oldval, oldlenp, newval, newlen);
2621 put_uts(table, write, uts_table.data);
2622 return r;
2625 #ifdef CONFIG_SYSVIPC
2626 /* The generic sysctl ipc data routine. */
2627 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2628 void __user *oldval, size_t __user *oldlenp,
2629 void __user *newval, size_t newlen)
2631 size_t len;
2632 void *data;
2634 /* Get out of I don't have a variable */
2635 if (!table->data || !table->maxlen)
2636 return -ENOTDIR;
2638 data = get_ipc(table, 1);
2639 if (!data)
2640 return -ENOTDIR;
2642 if (oldval && oldlenp) {
2643 if (get_user(len, oldlenp))
2644 return -EFAULT;
2645 if (len) {
2646 if (len > table->maxlen)
2647 len = table->maxlen;
2648 if (copy_to_user(oldval, data, len))
2649 return -EFAULT;
2650 if (put_user(len, oldlenp))
2651 return -EFAULT;
2655 if (newval && newlen) {
2656 if (newlen > table->maxlen)
2657 newlen = table->maxlen;
2659 if (copy_from_user(data, newval, newlen))
2660 return -EFAULT;
2662 return 1;
2664 #endif
2666 #else /* CONFIG_SYSCTL_SYSCALL */
2669 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2671 static int msg_count;
2672 struct __sysctl_args tmp;
2673 int name[CTL_MAXNAME];
2674 int i;
2676 /* Read in the sysctl name for better debug message logging */
2677 if (copy_from_user(&tmp, args, sizeof(tmp)))
2678 return -EFAULT;
2679 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2680 return -ENOTDIR;
2681 for (i = 0; i < tmp.nlen; i++)
2682 if (get_user(name[i], tmp.name + i))
2683 return -EFAULT;
2685 /* Ignore accesses to kernel.version */
2686 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2687 goto out;
2689 if (msg_count < 5) {
2690 msg_count++;
2691 printk(KERN_INFO
2692 "warning: process `%s' used the removed sysctl "
2693 "system call with ", current->comm);
2694 for (i = 0; i < tmp.nlen; i++)
2695 printk("%d.", name[i]);
2696 printk("\n");
2698 out:
2699 return -ENOSYS;
2702 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2703 void __user *oldval, size_t __user *oldlenp,
2704 void __user *newval, size_t newlen)
2706 return -ENOSYS;
2709 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2710 void __user *oldval, size_t __user *oldlenp,
2711 void __user *newval, size_t newlen)
2713 return -ENOSYS;
2716 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2717 void __user *oldval, size_t __user *oldlenp,
2718 void __user *newval, size_t newlen)
2720 return -ENOSYS;
2723 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2724 void __user *oldval, size_t __user *oldlenp,
2725 void __user *newval, size_t newlen)
2727 return -ENOSYS;
2730 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
2731 void __user *oldval, size_t __user *oldlenp,
2732 void __user *newval, size_t newlen)
2734 return -ENOSYS;
2736 static int sysctl_ipc_data(ctl_table *table, int __user *name, int nlen,
2737 void __user *oldval, size_t __user *oldlenp,
2738 void __user *newval, size_t newlen)
2740 return -ENOSYS;
2742 #endif /* CONFIG_SYSCTL_SYSCALL */
2745 * No sense putting this after each symbol definition, twice,
2746 * exception granted :-)
2748 EXPORT_SYMBOL(proc_dointvec);
2749 EXPORT_SYMBOL(proc_dointvec_jiffies);
2750 EXPORT_SYMBOL(proc_dointvec_minmax);
2751 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2752 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2753 EXPORT_SYMBOL(proc_dostring);
2754 EXPORT_SYMBOL(proc_doulongvec_minmax);
2755 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2756 EXPORT_SYMBOL(register_sysctl_table);
2757 EXPORT_SYMBOL(sysctl_intvec);
2758 EXPORT_SYMBOL(sysctl_jiffies);
2759 EXPORT_SYMBOL(sysctl_ms_jiffies);
2760 EXPORT_SYMBOL(sysctl_string);
2761 EXPORT_SYMBOL(unregister_sysctl_table);