[PATCH] DVB: frontend updates
[linux-2.6/history.git] / kernel / sysctl.c
blob80bf15f035cde21fce001b19ac051c2f20aa11a4
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/config.h>
22 #include <linux/module.h>
23 #include <linux/mm.h>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/sysrq.h>
35 #include <linux/highuid.h>
36 #include <linux/writeback.h>
37 #include <linux/hugetlb.h>
38 #include <linux/security.h>
39 #include <linux/initrd.h>
40 #include <linux/times.h>
41 #include <linux/limits.h>
42 #include <linux/dcache.h>
43 #include <linux/syscalls.h>
45 #include <asm/uaccess.h>
46 #include <asm/processor.h>
48 #ifdef CONFIG_ROOT_NFS
49 #include <linux/nfs_fs.h>
50 #endif
52 #if defined(CONFIG_SYSCTL)
54 /* External variables not in a header file. */
55 extern int panic_timeout;
56 extern int C_A_D;
57 extern int sysctl_overcommit_memory;
58 extern int sysctl_overcommit_ratio;
59 extern int max_threads;
60 extern int sysrq_enabled;
61 extern int core_uses_pid;
62 extern char core_pattern[];
63 extern int cad_pid;
64 extern int pid_max;
65 extern int sysctl_lower_zone_protection;
66 extern int min_free_kbytes;
67 extern int printk_ratelimit_jiffies;
68 extern int printk_ratelimit_burst;
69 extern int pid_max_min, pid_max_max;
71 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
72 int unknown_nmi_panic;
73 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
74 void __user *, size_t *, loff_t *);
75 #endif
77 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
78 static int maxolduid = 65535;
79 static int minolduid;
81 static int ngroups_max = NGROUPS_MAX;
83 #ifdef CONFIG_KMOD
84 extern char modprobe_path[];
85 #endif
86 #ifdef CONFIG_HOTPLUG
87 extern char hotplug_path[];
88 #endif
89 #ifdef CONFIG_CHR_DEV_SG
90 extern int sg_big_buff;
91 #endif
92 #ifdef CONFIG_SYSVIPC
93 extern size_t shm_ctlmax;
94 extern size_t shm_ctlall;
95 extern int shm_ctlmni;
96 extern int msg_ctlmax;
97 extern int msg_ctlmnb;
98 extern int msg_ctlmni;
99 extern int sem_ctls[];
100 #endif
102 #ifdef __sparc__
103 extern char reboot_command [];
104 extern int stop_a_enabled;
105 extern int scons_pwroff;
106 #endif
108 #ifdef __hppa__
109 extern int pwrsw_enabled;
110 extern int unaligned_enabled;
111 #endif
113 #ifdef CONFIG_ARCH_S390
114 #ifdef CONFIG_MATHEMU
115 extern int sysctl_ieee_emulation_warnings;
116 #endif
117 extern int sysctl_userprocess_debug;
118 #endif
120 extern int sysctl_hz_timer;
122 #ifdef CONFIG_BSD_PROCESS_ACCT
123 extern int acct_parm[];
124 #endif
126 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
127 ctl_table *, void **);
128 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
129 void __user *buffer, size_t *lenp, loff_t *ppos);
131 static ctl_table root_table[];
132 static struct ctl_table_header root_table_header =
133 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
135 static ctl_table kern_table[];
136 static ctl_table vm_table[];
137 #ifdef CONFIG_NET
138 extern ctl_table net_table[];
139 #endif
140 static ctl_table proc_table[];
141 static ctl_table fs_table[];
142 static ctl_table debug_table[];
143 static ctl_table dev_table[];
144 extern ctl_table random_table[];
145 #ifdef CONFIG_UNIX98_PTYS
146 extern ctl_table pty_table[];
147 #endif
149 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
150 int sysctl_legacy_va_layout;
151 #endif
153 /* /proc declarations: */
155 #ifdef CONFIG_PROC_FS
157 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
158 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
159 static int proc_opensys(struct inode *, struct file *);
161 struct file_operations proc_sys_file_operations = {
162 .open = proc_opensys,
163 .read = proc_readsys,
164 .write = proc_writesys,
167 extern struct proc_dir_entry *proc_sys_root;
169 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
170 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
171 #endif
173 /* The default sysctl tables: */
175 static ctl_table root_table[] = {
177 .ctl_name = CTL_KERN,
178 .procname = "kernel",
179 .mode = 0555,
180 .child = kern_table,
183 .ctl_name = CTL_VM,
184 .procname = "vm",
185 .mode = 0555,
186 .child = vm_table,
188 #ifdef CONFIG_NET
190 .ctl_name = CTL_NET,
191 .procname = "net",
192 .mode = 0555,
193 .child = net_table,
195 #endif
197 .ctl_name = CTL_PROC,
198 .procname = "proc",
199 .mode = 0555,
200 .child = proc_table,
203 .ctl_name = CTL_FS,
204 .procname = "fs",
205 .mode = 0555,
206 .child = fs_table,
209 .ctl_name = CTL_DEBUG,
210 .procname = "debug",
211 .mode = 0555,
212 .child = debug_table,
215 .ctl_name = CTL_DEV,
216 .procname = "dev",
217 .mode = 0555,
218 .child = dev_table,
220 { .ctl_name = 0 }
223 static ctl_table kern_table[] = {
225 .ctl_name = KERN_OSTYPE,
226 .procname = "ostype",
227 .data = system_utsname.sysname,
228 .maxlen = sizeof(system_utsname.sysname),
229 .mode = 0444,
230 .proc_handler = &proc_doutsstring,
231 .strategy = &sysctl_string,
234 .ctl_name = KERN_OSRELEASE,
235 .procname = "osrelease",
236 .data = system_utsname.release,
237 .maxlen = sizeof(system_utsname.release),
238 .mode = 0444,
239 .proc_handler = &proc_doutsstring,
240 .strategy = &sysctl_string,
243 .ctl_name = KERN_VERSION,
244 .procname = "version",
245 .data = system_utsname.version,
246 .maxlen = sizeof(system_utsname.version),
247 .mode = 0444,
248 .proc_handler = &proc_doutsstring,
249 .strategy = &sysctl_string,
252 .ctl_name = KERN_NODENAME,
253 .procname = "hostname",
254 .data = system_utsname.nodename,
255 .maxlen = sizeof(system_utsname.nodename),
256 .mode = 0644,
257 .proc_handler = &proc_doutsstring,
258 .strategy = &sysctl_string,
261 .ctl_name = KERN_DOMAINNAME,
262 .procname = "domainname",
263 .data = system_utsname.domainname,
264 .maxlen = sizeof(system_utsname.domainname),
265 .mode = 0644,
266 .proc_handler = &proc_doutsstring,
267 .strategy = &sysctl_string,
270 .ctl_name = KERN_PANIC,
271 .procname = "panic",
272 .data = &panic_timeout,
273 .maxlen = sizeof(int),
274 .mode = 0644,
275 .proc_handler = &proc_dointvec,
278 .ctl_name = KERN_CORE_USES_PID,
279 .procname = "core_uses_pid",
280 .data = &core_uses_pid,
281 .maxlen = sizeof(int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec,
286 .ctl_name = KERN_CORE_PATTERN,
287 .procname = "core_pattern",
288 .data = core_pattern,
289 .maxlen = 64,
290 .mode = 0644,
291 .proc_handler = &proc_dostring,
292 .strategy = &sysctl_string,
295 .ctl_name = KERN_TAINTED,
296 .procname = "tainted",
297 .data = &tainted,
298 .maxlen = sizeof(int),
299 .mode = 0444,
300 .proc_handler = &proc_dointvec,
303 .ctl_name = KERN_CAP_BSET,
304 .procname = "cap-bound",
305 .data = &cap_bset,
306 .maxlen = sizeof(kernel_cap_t),
307 .mode = 0600,
308 .proc_handler = &proc_dointvec_bset,
310 #ifdef CONFIG_BLK_DEV_INITRD
312 .ctl_name = KERN_REALROOTDEV,
313 .procname = "real-root-dev",
314 .data = &real_root_dev,
315 .maxlen = sizeof(int),
316 .mode = 0644,
317 .proc_handler = &proc_dointvec,
319 #endif
320 #ifdef __sparc__
322 .ctl_name = KERN_SPARC_REBOOT,
323 .procname = "reboot-cmd",
324 .data = reboot_command,
325 .maxlen = 256,
326 .mode = 0644,
327 .proc_handler = &proc_dostring,
328 .strategy = &sysctl_string,
331 .ctl_name = KERN_SPARC_STOP_A,
332 .procname = "stop-a",
333 .data = &stop_a_enabled,
334 .maxlen = sizeof (int),
335 .mode = 0644,
336 .proc_handler = &proc_dointvec,
339 .ctl_name = KERN_SPARC_SCONS_PWROFF,
340 .procname = "scons-poweroff",
341 .data = &scons_pwroff,
342 .maxlen = sizeof (int),
343 .mode = 0644,
344 .proc_handler = &proc_dointvec,
346 #endif
347 #ifdef __hppa__
349 .ctl_name = KERN_HPPA_PWRSW,
350 .procname = "soft-power",
351 .data = &pwrsw_enabled,
352 .maxlen = sizeof (int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_HPPA_UNALIGNED,
358 .procname = "unaligned-trap",
359 .data = &unaligned_enabled,
360 .maxlen = sizeof (int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
364 #endif
366 .ctl_name = KERN_CTLALTDEL,
367 .procname = "ctrl-alt-del",
368 .data = &C_A_D,
369 .maxlen = sizeof(int),
370 .mode = 0644,
371 .proc_handler = &proc_dointvec,
374 .ctl_name = KERN_PRINTK,
375 .procname = "printk",
376 .data = &console_loglevel,
377 .maxlen = 4*sizeof(int),
378 .mode = 0644,
379 .proc_handler = &proc_dointvec,
381 #ifdef CONFIG_KMOD
383 .ctl_name = KERN_MODPROBE,
384 .procname = "modprobe",
385 .data = &modprobe_path,
386 .maxlen = KMOD_PATH_LEN,
387 .mode = 0644,
388 .proc_handler = &proc_dostring,
389 .strategy = &sysctl_string,
391 #endif
392 #ifdef CONFIG_HOTPLUG
394 .ctl_name = KERN_HOTPLUG,
395 .procname = "hotplug",
396 .data = &hotplug_path,
397 .maxlen = KMOD_PATH_LEN,
398 .mode = 0644,
399 .proc_handler = &proc_dostring,
400 .strategy = &sysctl_string,
402 #endif
403 #ifdef CONFIG_CHR_DEV_SG
405 .ctl_name = KERN_SG_BIG_BUFF,
406 .procname = "sg-big-buff",
407 .data = &sg_big_buff,
408 .maxlen = sizeof (int),
409 .mode = 0444,
410 .proc_handler = &proc_dointvec,
412 #endif
413 #ifdef CONFIG_BSD_PROCESS_ACCT
415 .ctl_name = KERN_ACCT,
416 .procname = "acct",
417 .data = &acct_parm,
418 .maxlen = 3*sizeof(int),
419 .mode = 0644,
420 .proc_handler = &proc_dointvec,
422 #endif
423 #ifdef CONFIG_SYSVIPC
425 .ctl_name = KERN_SHMMAX,
426 .procname = "shmmax",
427 .data = &shm_ctlmax,
428 .maxlen = sizeof (size_t),
429 .mode = 0644,
430 .proc_handler = &proc_doulongvec_minmax,
433 .ctl_name = KERN_SHMALL,
434 .procname = "shmall",
435 .data = &shm_ctlall,
436 .maxlen = sizeof (size_t),
437 .mode = 0644,
438 .proc_handler = &proc_doulongvec_minmax,
441 .ctl_name = KERN_SHMMNI,
442 .procname = "shmmni",
443 .data = &shm_ctlmni,
444 .maxlen = sizeof (int),
445 .mode = 0644,
446 .proc_handler = &proc_dointvec,
449 .ctl_name = KERN_MSGMAX,
450 .procname = "msgmax",
451 .data = &msg_ctlmax,
452 .maxlen = sizeof (int),
453 .mode = 0644,
454 .proc_handler = &proc_dointvec,
457 .ctl_name = KERN_MSGMNI,
458 .procname = "msgmni",
459 .data = &msg_ctlmni,
460 .maxlen = sizeof (int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
465 .ctl_name = KERN_MSGMNB,
466 .procname = "msgmnb",
467 .data = &msg_ctlmnb,
468 .maxlen = sizeof (int),
469 .mode = 0644,
470 .proc_handler = &proc_dointvec,
473 .ctl_name = KERN_SEM,
474 .procname = "sem",
475 .data = &sem_ctls,
476 .maxlen = 4*sizeof (int),
477 .mode = 0644,
478 .proc_handler = &proc_dointvec,
480 #endif
481 #ifdef CONFIG_MAGIC_SYSRQ
483 .ctl_name = KERN_SYSRQ,
484 .procname = "sysrq",
485 .data = &sysrq_enabled,
486 .maxlen = sizeof (int),
487 .mode = 0644,
488 .proc_handler = &proc_dointvec,
490 #endif
492 .ctl_name = KERN_CADPID,
493 .procname = "cad_pid",
494 .data = &cad_pid,
495 .maxlen = sizeof (int),
496 .mode = 0600,
497 .proc_handler = &proc_dointvec,
500 .ctl_name = KERN_MAX_THREADS,
501 .procname = "threads-max",
502 .data = &max_threads,
503 .maxlen = sizeof(int),
504 .mode = 0644,
505 .proc_handler = &proc_dointvec,
508 .ctl_name = KERN_RANDOM,
509 .procname = "random",
510 .mode = 0555,
511 .child = random_table,
513 #ifdef CONFIG_UNIX98_PTYS
515 .ctl_name = KERN_PTY,
516 .procname = "pty",
517 .mode = 0555,
518 .child = pty_table,
520 #endif
522 .ctl_name = KERN_OVERFLOWUID,
523 .procname = "overflowuid",
524 .data = &overflowuid,
525 .maxlen = sizeof(int),
526 .mode = 0644,
527 .proc_handler = &proc_dointvec_minmax,
528 .strategy = &sysctl_intvec,
529 .extra1 = &minolduid,
530 .extra2 = &maxolduid,
533 .ctl_name = KERN_OVERFLOWGID,
534 .procname = "overflowgid",
535 .data = &overflowgid,
536 .maxlen = sizeof(int),
537 .mode = 0644,
538 .proc_handler = &proc_dointvec_minmax,
539 .strategy = &sysctl_intvec,
540 .extra1 = &minolduid,
541 .extra2 = &maxolduid,
543 #ifdef CONFIG_ARCH_S390
544 #ifdef CONFIG_MATHEMU
546 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
547 .procname = "ieee_emulation_warnings",
548 .data = &sysctl_ieee_emulation_warnings,
549 .maxlen = sizeof(int),
550 .mode = 0644,
551 .proc_handler = &proc_dointvec,
553 #endif
554 #ifdef CONFIG_NO_IDLE_HZ
556 .ctl_name = KERN_HZ_TIMER,
557 .procname = "hz_timer",
558 .data = &sysctl_hz_timer,
559 .maxlen = sizeof(int),
560 .mode = 0644,
561 .proc_handler = &proc_dointvec,
563 #endif
565 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
566 .procname = "userprocess_debug",
567 .data = &sysctl_userprocess_debug,
568 .maxlen = sizeof(int),
569 .mode = 0644,
570 .proc_handler = &proc_dointvec,
572 #endif
574 .ctl_name = KERN_PIDMAX,
575 .procname = "pid_max",
576 .data = &pid_max,
577 .maxlen = sizeof (int),
578 .mode = 0644,
579 .proc_handler = &proc_dointvec_minmax,
580 .strategy = sysctl_intvec,
581 .extra1 = &pid_max_min,
582 .extra2 = &pid_max_max,
585 .ctl_name = KERN_PANIC_ON_OOPS,
586 .procname = "panic_on_oops",
587 .data = &panic_on_oops,
588 .maxlen = sizeof(int),
589 .mode = 0644,
590 .proc_handler = &proc_dointvec,
593 .ctl_name = KERN_PRINTK_RATELIMIT,
594 .procname = "printk_ratelimit",
595 .data = &printk_ratelimit_jiffies,
596 .maxlen = sizeof(int),
597 .mode = 0644,
598 .proc_handler = &proc_dointvec_jiffies,
599 .strategy = &sysctl_jiffies,
602 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
603 .procname = "printk_ratelimit_burst",
604 .data = &printk_ratelimit_burst,
605 .maxlen = sizeof(int),
606 .mode = 0644,
607 .proc_handler = &proc_dointvec,
610 .ctl_name = KERN_NGROUPS_MAX,
611 .procname = "ngroups_max",
612 .data = &ngroups_max,
613 .maxlen = sizeof (int),
614 .mode = 0444,
615 .proc_handler = &proc_dointvec,
617 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
619 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
620 .procname = "unknown_nmi_panic",
621 .data = &unknown_nmi_panic,
622 .maxlen = sizeof (int),
623 .mode = 0644,
624 .proc_handler = &proc_unknown_nmi_panic,
626 #endif
627 { .ctl_name = 0 }
630 /* Constants for minimum and maximum testing in vm_table.
631 We use these as one-element integer vectors. */
632 static int zero;
633 static int one_hundred = 100;
636 static ctl_table vm_table[] = {
638 .ctl_name = VM_OVERCOMMIT_MEMORY,
639 .procname = "overcommit_memory",
640 .data = &sysctl_overcommit_memory,
641 .maxlen = sizeof(sysctl_overcommit_memory),
642 .mode = 0644,
643 .proc_handler = &proc_dointvec,
646 .ctl_name = VM_OVERCOMMIT_RATIO,
647 .procname = "overcommit_ratio",
648 .data = &sysctl_overcommit_ratio,
649 .maxlen = sizeof(sysctl_overcommit_ratio),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec,
654 .ctl_name = VM_PAGE_CLUSTER,
655 .procname = "page-cluster",
656 .data = &page_cluster,
657 .maxlen = sizeof(int),
658 .mode = 0644,
659 .proc_handler = &proc_dointvec,
662 .ctl_name = VM_DIRTY_BACKGROUND,
663 .procname = "dirty_background_ratio",
664 .data = &dirty_background_ratio,
665 .maxlen = sizeof(dirty_background_ratio),
666 .mode = 0644,
667 .proc_handler = &proc_dointvec_minmax,
668 .strategy = &sysctl_intvec,
669 .extra1 = &zero,
670 .extra2 = &one_hundred,
673 .ctl_name = VM_DIRTY_RATIO,
674 .procname = "dirty_ratio",
675 .data = &vm_dirty_ratio,
676 .maxlen = sizeof(vm_dirty_ratio),
677 .mode = 0644,
678 .proc_handler = &proc_dointvec_minmax,
679 .strategy = &sysctl_intvec,
680 .extra1 = &zero,
681 .extra2 = &one_hundred,
684 .ctl_name = VM_DIRTY_WB_CS,
685 .procname = "dirty_writeback_centisecs",
686 .data = &dirty_writeback_centisecs,
687 .maxlen = sizeof(dirty_writeback_centisecs),
688 .mode = 0644,
689 .proc_handler = &dirty_writeback_centisecs_handler,
692 .ctl_name = VM_DIRTY_EXPIRE_CS,
693 .procname = "dirty_expire_centisecs",
694 .data = &dirty_expire_centisecs,
695 .maxlen = sizeof(dirty_expire_centisecs),
696 .mode = 0644,
697 .proc_handler = &proc_dointvec,
700 .ctl_name = VM_NR_PDFLUSH_THREADS,
701 .procname = "nr_pdflush_threads",
702 .data = &nr_pdflush_threads,
703 .maxlen = sizeof nr_pdflush_threads,
704 .mode = 0444 /* read-only*/,
705 .proc_handler = &proc_dointvec,
708 .ctl_name = VM_SWAPPINESS,
709 .procname = "swappiness",
710 .data = &vm_swappiness,
711 .maxlen = sizeof(vm_swappiness),
712 .mode = 0644,
713 .proc_handler = &proc_dointvec_minmax,
714 .strategy = &sysctl_intvec,
715 .extra1 = &zero,
716 .extra2 = &one_hundred,
718 #ifdef CONFIG_HUGETLB_PAGE
720 .ctl_name = VM_HUGETLB_PAGES,
721 .procname = "nr_hugepages",
722 .data = &max_huge_pages,
723 .maxlen = sizeof(unsigned long),
724 .mode = 0644,
725 .proc_handler = &hugetlb_sysctl_handler,
726 .extra1 = (void *)&hugetlb_zero,
727 .extra2 = (void *)&hugetlb_infinity,
730 .ctl_name = VM_HUGETLB_GROUP,
731 .procname = "hugetlb_shm_group",
732 .data = &sysctl_hugetlb_shm_group,
733 .maxlen = sizeof(gid_t),
734 .mode = 0644,
735 .proc_handler = &proc_dointvec,
737 #endif
739 .ctl_name = VM_LOWER_ZONE_PROTECTION,
740 .procname = "lower_zone_protection",
741 .data = &sysctl_lower_zone_protection,
742 .maxlen = sizeof(sysctl_lower_zone_protection),
743 .mode = 0644,
744 .proc_handler = &lower_zone_protection_sysctl_handler,
745 .strategy = &sysctl_intvec,
746 .extra1 = &zero,
749 .ctl_name = VM_MIN_FREE_KBYTES,
750 .procname = "min_free_kbytes",
751 .data = &min_free_kbytes,
752 .maxlen = sizeof(min_free_kbytes),
753 .mode = 0644,
754 .proc_handler = &min_free_kbytes_sysctl_handler,
755 .strategy = &sysctl_intvec,
756 .extra1 = &zero,
759 .ctl_name = VM_MAX_MAP_COUNT,
760 .procname = "max_map_count",
761 .data = &sysctl_max_map_count,
762 .maxlen = sizeof(sysctl_max_map_count),
763 .mode = 0644,
764 .proc_handler = &proc_dointvec
767 .ctl_name = VM_LAPTOP_MODE,
768 .procname = "laptop_mode",
769 .data = &laptop_mode,
770 .maxlen = sizeof(laptop_mode),
771 .mode = 0644,
772 .proc_handler = &proc_dointvec,
773 .strategy = &sysctl_intvec,
774 .extra1 = &zero,
777 .ctl_name = VM_BLOCK_DUMP,
778 .procname = "block_dump",
779 .data = &block_dump,
780 .maxlen = sizeof(block_dump),
781 .mode = 0644,
782 .proc_handler = &proc_dointvec,
783 .strategy = &sysctl_intvec,
784 .extra1 = &zero,
787 .ctl_name = VM_VFS_CACHE_PRESSURE,
788 .procname = "vfs_cache_pressure",
789 .data = &sysctl_vfs_cache_pressure,
790 .maxlen = sizeof(sysctl_vfs_cache_pressure),
791 .mode = 0644,
792 .proc_handler = &proc_dointvec,
793 .strategy = &sysctl_intvec,
794 .extra1 = &zero,
796 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
798 .ctl_name = VM_LEGACY_VA_LAYOUT,
799 .procname = "legacy_va_layout",
800 .data = &sysctl_legacy_va_layout,
801 .maxlen = sizeof(sysctl_legacy_va_layout),
802 .mode = 0644,
803 .proc_handler = &proc_dointvec,
804 .strategy = &sysctl_intvec,
805 .extra1 = &zero,
807 #endif
808 { .ctl_name = 0 }
811 static ctl_table proc_table[] = {
812 { .ctl_name = 0 }
815 static ctl_table fs_table[] = {
817 .ctl_name = FS_NRINODE,
818 .procname = "inode-nr",
819 .data = &inodes_stat,
820 .maxlen = 2*sizeof(int),
821 .mode = 0444,
822 .proc_handler = &proc_dointvec,
825 .ctl_name = FS_STATINODE,
826 .procname = "inode-state",
827 .data = &inodes_stat,
828 .maxlen = 7*sizeof(int),
829 .mode = 0444,
830 .proc_handler = &proc_dointvec,
833 .ctl_name = FS_NRFILE,
834 .procname = "file-nr",
835 .data = &files_stat,
836 .maxlen = 3*sizeof(int),
837 .mode = 0444,
838 .proc_handler = &proc_dointvec,
841 .ctl_name = FS_MAXFILE,
842 .procname = "file-max",
843 .data = &files_stat.max_files,
844 .maxlen = sizeof(int),
845 .mode = 0644,
846 .proc_handler = &proc_dointvec,
849 .ctl_name = FS_DENTRY,
850 .procname = "dentry-state",
851 .data = &dentry_stat,
852 .maxlen = 6*sizeof(int),
853 .mode = 0444,
854 .proc_handler = &proc_dointvec,
857 .ctl_name = FS_OVERFLOWUID,
858 .procname = "overflowuid",
859 .data = &fs_overflowuid,
860 .maxlen = sizeof(int),
861 .mode = 0644,
862 .proc_handler = &proc_dointvec_minmax,
863 .strategy = &sysctl_intvec,
864 .extra1 = &minolduid,
865 .extra2 = &maxolduid,
868 .ctl_name = FS_OVERFLOWGID,
869 .procname = "overflowgid",
870 .data = &fs_overflowgid,
871 .maxlen = sizeof(int),
872 .mode = 0644,
873 .proc_handler = &proc_dointvec_minmax,
874 .strategy = &sysctl_intvec,
875 .extra1 = &minolduid,
876 .extra2 = &maxolduid,
879 .ctl_name = FS_LEASES,
880 .procname = "leases-enable",
881 .data = &leases_enable,
882 .maxlen = sizeof(int),
883 .mode = 0644,
884 .proc_handler = &proc_dointvec,
887 .ctl_name = FS_DIR_NOTIFY,
888 .procname = "dir-notify-enable",
889 .data = &dir_notify_enable,
890 .maxlen = sizeof(int),
891 .mode = 0644,
892 .proc_handler = &proc_dointvec,
895 .ctl_name = FS_LEASE_TIME,
896 .procname = "lease-break-time",
897 .data = &lease_break_time,
898 .maxlen = sizeof(int),
899 .mode = 0644,
900 .proc_handler = &proc_dointvec,
903 .ctl_name = FS_AIO_NR,
904 .procname = "aio-nr",
905 .data = &aio_nr,
906 .maxlen = sizeof(aio_nr),
907 .mode = 0444,
908 .proc_handler = &proc_dointvec,
911 .ctl_name = FS_AIO_MAX_NR,
912 .procname = "aio-max-nr",
913 .data = &aio_max_nr,
914 .maxlen = sizeof(aio_max_nr),
915 .mode = 0644,
916 .proc_handler = &proc_dointvec,
918 { .ctl_name = 0 }
921 static ctl_table debug_table[] = {
922 { .ctl_name = 0 }
925 static ctl_table dev_table[] = {
926 { .ctl_name = 0 }
929 extern void init_irq_proc (void);
931 void __init sysctl_init(void)
933 #ifdef CONFIG_PROC_FS
934 register_proc_table(root_table, proc_sys_root);
935 init_irq_proc();
936 #endif
939 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
940 void __user *newval, size_t newlen)
942 struct list_head *tmp;
944 if (nlen <= 0 || nlen >= CTL_MAXNAME)
945 return -ENOTDIR;
946 if (oldval) {
947 int old_len;
948 if (!oldlenp || get_user(old_len, oldlenp))
949 return -EFAULT;
951 tmp = &root_table_header.ctl_entry;
952 do {
953 struct ctl_table_header *head =
954 list_entry(tmp, struct ctl_table_header, ctl_entry);
955 void *context = NULL;
956 int error = parse_table(name, nlen, oldval, oldlenp,
957 newval, newlen, head->ctl_table,
958 &context);
959 if (context)
960 kfree(context);
961 if (error != -ENOTDIR)
962 return error;
963 tmp = tmp->next;
964 } while (tmp != &root_table_header.ctl_entry);
965 return -ENOTDIR;
968 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
970 struct __sysctl_args tmp;
971 int error;
973 if (copy_from_user(&tmp, args, sizeof(tmp)))
974 return -EFAULT;
976 lock_kernel();
977 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
978 tmp.newval, tmp.newlen);
979 unlock_kernel();
980 return error;
984 * ctl_perm does NOT grant the superuser all rights automatically, because
985 * some sysctl variables are readonly even to root.
988 static int test_perm(int mode, int op)
990 if (!current->euid)
991 mode >>= 6;
992 else if (in_egroup_p(0))
993 mode >>= 3;
994 if ((mode & op & 0007) == op)
995 return 0;
996 return -EACCES;
999 static inline int ctl_perm(ctl_table *table, int op)
1001 int error;
1002 error = security_sysctl(table, op);
1003 if (error)
1004 return error;
1005 return test_perm(table->mode, op);
1008 static int parse_table(int __user *name, int nlen,
1009 void __user *oldval, size_t __user *oldlenp,
1010 void __user *newval, size_t newlen,
1011 ctl_table *table, void **context)
1013 int n;
1014 repeat:
1015 if (!nlen)
1016 return -ENOTDIR;
1017 if (get_user(n, name))
1018 return -EFAULT;
1019 for ( ; table->ctl_name; table++) {
1020 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1021 int error;
1022 if (table->child) {
1023 if (ctl_perm(table, 001))
1024 return -EPERM;
1025 if (table->strategy) {
1026 error = table->strategy(
1027 table, name, nlen,
1028 oldval, oldlenp,
1029 newval, newlen, context);
1030 if (error)
1031 return error;
1033 name++;
1034 nlen--;
1035 table = table->child;
1036 goto repeat;
1038 error = do_sysctl_strategy(table, name, nlen,
1039 oldval, oldlenp,
1040 newval, newlen, context);
1041 return error;
1044 return -ENOTDIR;
1047 /* Perform the actual read/write of a sysctl table entry. */
1048 int do_sysctl_strategy (ctl_table *table,
1049 int __user *name, int nlen,
1050 void __user *oldval, size_t __user *oldlenp,
1051 void __user *newval, size_t newlen, void **context)
1053 int op = 0, rc;
1054 size_t len;
1056 if (oldval)
1057 op |= 004;
1058 if (newval)
1059 op |= 002;
1060 if (ctl_perm(table, op))
1061 return -EPERM;
1063 if (table->strategy) {
1064 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1065 newval, newlen, context);
1066 if (rc < 0)
1067 return rc;
1068 if (rc > 0)
1069 return 0;
1072 /* If there is no strategy routine, or if the strategy returns
1073 * zero, proceed with automatic r/w */
1074 if (table->data && table->maxlen) {
1075 if (oldval && oldlenp) {
1076 if (get_user(len, oldlenp))
1077 return -EFAULT;
1078 if (len) {
1079 if (len > table->maxlen)
1080 len = table->maxlen;
1081 if(copy_to_user(oldval, table->data, len))
1082 return -EFAULT;
1083 if(put_user(len, oldlenp))
1084 return -EFAULT;
1087 if (newval && newlen) {
1088 len = newlen;
1089 if (len > table->maxlen)
1090 len = table->maxlen;
1091 if(copy_from_user(table->data, newval, len))
1092 return -EFAULT;
1095 return 0;
1099 * register_sysctl_table - register a sysctl hierarchy
1100 * @table: the top-level table structure
1101 * @insert_at_head: whether the entry should be inserted in front or at the end
1103 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1104 * array. An entry with a ctl_name of 0 terminates the table.
1106 * The members of the &ctl_table structure are used as follows:
1108 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1109 * must be unique within that level of sysctl
1111 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1112 * enter a sysctl file
1114 * data - a pointer to data for use by proc_handler
1116 * maxlen - the maximum size in bytes of the data
1118 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1120 * child - a pointer to the child sysctl table if this entry is a directory, or
1121 * %NULL.
1123 * proc_handler - the text handler routine (described below)
1125 * strategy - the strategy routine (described below)
1127 * de - for internal use by the sysctl routines
1129 * extra1, extra2 - extra pointers usable by the proc handler routines
1131 * Leaf nodes in the sysctl tree will be represented by a single file
1132 * under /proc; non-leaf nodes will be represented by directories.
1134 * sysctl(2) can automatically manage read and write requests through
1135 * the sysctl table. The data and maxlen fields of the ctl_table
1136 * struct enable minimal validation of the values being written to be
1137 * performed, and the mode field allows minimal authentication.
1139 * More sophisticated management can be enabled by the provision of a
1140 * strategy routine with the table entry. This will be called before
1141 * any automatic read or write of the data is performed.
1143 * The strategy routine may return
1145 * < 0 - Error occurred (error is passed to user process)
1147 * 0 - OK - proceed with automatic read or write.
1149 * > 0 - OK - read or write has been done by the strategy routine, so
1150 * return immediately.
1152 * There must be a proc_handler routine for any terminal nodes
1153 * mirrored under /proc/sys (non-terminals are handled by a built-in
1154 * directory handler). Several default handlers are available to
1155 * cover common cases -
1157 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1158 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1159 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1161 * It is the handler's job to read the input buffer from user memory
1162 * and process it. The handler should return 0 on success.
1164 * This routine returns %NULL on a failure to register, and a pointer
1165 * to the table header on success.
1167 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1168 int insert_at_head)
1170 struct ctl_table_header *tmp;
1171 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1172 if (!tmp)
1173 return NULL;
1174 tmp->ctl_table = table;
1175 INIT_LIST_HEAD(&tmp->ctl_entry);
1176 if (insert_at_head)
1177 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1178 else
1179 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1180 #ifdef CONFIG_PROC_FS
1181 register_proc_table(table, proc_sys_root);
1182 #endif
1183 return tmp;
1187 * unregister_sysctl_table - unregister a sysctl table hierarchy
1188 * @header: the header returned from register_sysctl_table
1190 * Unregisters the sysctl table and all children. proc entries may not
1191 * actually be removed until they are no longer used by anyone.
1193 void unregister_sysctl_table(struct ctl_table_header * header)
1195 list_del(&header->ctl_entry);
1196 #ifdef CONFIG_PROC_FS
1197 unregister_proc_table(header->ctl_table, proc_sys_root);
1198 #endif
1199 kfree(header);
1203 * /proc/sys support
1206 #ifdef CONFIG_PROC_FS
1208 /* Scan the sysctl entries in table and add them all into /proc */
1209 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1211 struct proc_dir_entry *de;
1212 int len;
1213 mode_t mode;
1215 for (; table->ctl_name; table++) {
1216 /* Can't do anything without a proc name. */
1217 if (!table->procname)
1218 continue;
1219 /* Maybe we can't do anything with it... */
1220 if (!table->proc_handler && !table->child) {
1221 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1222 table->procname);
1223 continue;
1226 len = strlen(table->procname);
1227 mode = table->mode;
1229 de = NULL;
1230 if (table->proc_handler)
1231 mode |= S_IFREG;
1232 else {
1233 mode |= S_IFDIR;
1234 for (de = root->subdir; de; de = de->next) {
1235 if (proc_match(len, table->procname, de))
1236 break;
1238 /* If the subdir exists already, de is non-NULL */
1241 if (!de) {
1242 de = create_proc_entry(table->procname, mode, root);
1243 if (!de)
1244 continue;
1245 de->data = (void *) table;
1246 if (table->proc_handler)
1247 de->proc_fops = &proc_sys_file_operations;
1249 table->de = de;
1250 if (de->mode & S_IFDIR)
1251 register_proc_table(table->child, de);
1256 * Unregister a /proc sysctl table and any subdirectories.
1258 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1260 struct proc_dir_entry *de;
1261 for (; table->ctl_name; table++) {
1262 if (!(de = table->de))
1263 continue;
1264 if (de->mode & S_IFDIR) {
1265 if (!table->child) {
1266 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1267 continue;
1269 unregister_proc_table(table->child, de);
1271 /* Don't unregister directories which still have entries.. */
1272 if (de->subdir)
1273 continue;
1276 /* Don't unregister proc entries that are still being used.. */
1277 if (atomic_read(&de->count))
1278 continue;
1280 table->de = NULL;
1281 remove_proc_entry(table->procname, root);
1285 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1286 size_t count, loff_t *ppos)
1288 int op;
1289 struct proc_dir_entry *de;
1290 struct ctl_table *table;
1291 size_t res;
1292 ssize_t error;
1294 de = PDE(file->f_dentry->d_inode);
1295 if (!de || !de->data)
1296 return -ENOTDIR;
1297 table = (struct ctl_table *) de->data;
1298 if (!table || !table->proc_handler)
1299 return -ENOTDIR;
1300 op = (write ? 002 : 004);
1301 if (ctl_perm(table, op))
1302 return -EPERM;
1304 res = count;
1306 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1307 if (error)
1308 return error;
1309 return res;
1312 static int proc_opensys(struct inode *inode, struct file *file)
1314 if (file->f_mode & FMODE_WRITE) {
1316 * sysctl entries that are not writable,
1317 * are _NOT_ writable, capabilities or not.
1319 if (!(inode->i_mode & S_IWUSR))
1320 return -EPERM;
1323 return 0;
1326 static ssize_t proc_readsys(struct file * file, char __user * buf,
1327 size_t count, loff_t *ppos)
1329 return do_rw_proc(0, file, buf, count, ppos);
1332 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1333 size_t count, loff_t *ppos)
1335 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1339 * proc_dostring - read a string sysctl
1340 * @table: the sysctl table
1341 * @write: %TRUE if this is a write to the sysctl file
1342 * @filp: the file structure
1343 * @buffer: the user buffer
1344 * @lenp: the size of the user buffer
1346 * Reads/writes a string from/to the user buffer. If the kernel
1347 * buffer provided is not large enough to hold the string, the
1348 * string is truncated. The copied string is %NULL-terminated.
1349 * If the string is being read by the user process, it is copied
1350 * and a newline '\n' is added. It is truncated if the buffer is
1351 * not large enough.
1353 * Returns 0 on success.
1355 int proc_dostring(ctl_table *table, int write, struct file *filp,
1356 void __user *buffer, size_t *lenp, loff_t *ppos)
1358 size_t len;
1359 char __user *p;
1360 char c;
1362 if (!table->data || !table->maxlen || !*lenp ||
1363 (*ppos && !write)) {
1364 *lenp = 0;
1365 return 0;
1368 if (write) {
1369 len = 0;
1370 p = buffer;
1371 while (len < *lenp) {
1372 if (get_user(c, p++))
1373 return -EFAULT;
1374 if (c == 0 || c == '\n')
1375 break;
1376 len++;
1378 if (len >= table->maxlen)
1379 len = table->maxlen-1;
1380 if(copy_from_user(table->data, buffer, len))
1381 return -EFAULT;
1382 ((char *) table->data)[len] = 0;
1383 *ppos += *lenp;
1384 } else {
1385 len = strlen(table->data);
1386 if (len > table->maxlen)
1387 len = table->maxlen;
1388 if (len > *lenp)
1389 len = *lenp;
1390 if (len)
1391 if(copy_to_user(buffer, table->data, len))
1392 return -EFAULT;
1393 if (len < *lenp) {
1394 if(put_user('\n', ((char __user *) buffer) + len))
1395 return -EFAULT;
1396 len++;
1398 *lenp = len;
1399 *ppos += len;
1401 return 0;
1405 * Special case of dostring for the UTS structure. This has locks
1406 * to observe. Should this be in kernel/sys.c ????
1409 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1410 void __user *buffer, size_t *lenp, loff_t *ppos)
1412 int r;
1414 if (!write) {
1415 down_read(&uts_sem);
1416 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1417 up_read(&uts_sem);
1418 } else {
1419 down_write(&uts_sem);
1420 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1421 up_write(&uts_sem);
1423 return r;
1426 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1427 int *valp,
1428 int write, void *data)
1430 if (write) {
1431 *valp = *negp ? -*lvalp : *lvalp;
1432 } else {
1433 int val = *valp;
1434 if (val < 0) {
1435 *negp = -1;
1436 *lvalp = (unsigned long)-val;
1437 } else {
1438 *negp = 0;
1439 *lvalp = (unsigned long)val;
1442 return 0;
1445 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1446 void __user *buffer, size_t *lenp, loff_t *ppos,
1447 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1448 int write, void *data),
1449 void *data)
1451 #define TMPBUFLEN 21
1452 int *i, vleft, first=1, neg, val;
1453 unsigned long lval;
1454 size_t left, len;
1456 char buf[TMPBUFLEN], *p;
1457 char __user *s = buffer;
1459 if (!table->data || !table->maxlen || !*lenp ||
1460 (*ppos && !write)) {
1461 *lenp = 0;
1462 return 0;
1465 i = (int *) table->data;
1466 vleft = table->maxlen / sizeof(*i);
1467 left = *lenp;
1469 if (!conv)
1470 conv = do_proc_dointvec_conv;
1472 for (; left && vleft--; i++, first=0) {
1473 if (write) {
1474 while (left) {
1475 char c;
1476 if (get_user(c, s))
1477 return -EFAULT;
1478 if (!isspace(c))
1479 break;
1480 left--;
1481 s++;
1483 if (!left)
1484 break;
1485 neg = 0;
1486 len = left;
1487 if (len > sizeof(buf) - 1)
1488 len = sizeof(buf) - 1;
1489 if (copy_from_user(buf, s, len))
1490 return -EFAULT;
1491 buf[len] = 0;
1492 p = buf;
1493 if (*p == '-' && left > 1) {
1494 neg = 1;
1495 left--, p++;
1497 if (*p < '0' || *p > '9')
1498 break;
1500 lval = simple_strtoul(p, &p, 0);
1502 len = p-buf;
1503 if ((len < left) && *p && !isspace(*p))
1504 break;
1505 if (neg)
1506 val = -val;
1507 s += len;
1508 left -= len;
1510 if (conv(&neg, &lval, i, 1, data))
1511 break;
1512 } else {
1513 p = buf;
1514 if (!first)
1515 *p++ = '\t';
1517 if (conv(&neg, &lval, i, 0, data))
1518 break;
1520 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1521 len = strlen(buf);
1522 if (len > left)
1523 len = left;
1524 if(copy_to_user(s, buf, len))
1525 return -EFAULT;
1526 left -= len;
1527 s += len;
1531 if (!write && !first && left) {
1532 if(put_user('\n', s))
1533 return -EFAULT;
1534 left--, s++;
1536 if (write) {
1537 while (left) {
1538 char c;
1539 if (get_user(c, s++))
1540 return -EFAULT;
1541 if (!isspace(c))
1542 break;
1543 left--;
1546 if (write && first)
1547 return -EINVAL;
1548 *lenp -= left;
1549 *ppos += *lenp;
1550 return 0;
1551 #undef TMPBUFLEN
1555 * proc_dointvec - read a vector of integers
1556 * @table: the sysctl table
1557 * @write: %TRUE if this is a write to the sysctl file
1558 * @filp: the file structure
1559 * @buffer: the user buffer
1560 * @lenp: the size of the user buffer
1562 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1563 * values from/to the user buffer, treated as an ASCII string.
1565 * Returns 0 on success.
1567 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1568 void __user *buffer, size_t *lenp, loff_t *ppos)
1570 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1571 NULL,NULL);
1574 #define OP_SET 0
1575 #define OP_AND 1
1576 #define OP_OR 2
1577 #define OP_MAX 3
1578 #define OP_MIN 4
1580 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1581 int *valp,
1582 int write, void *data)
1584 int op = *(int *)data;
1585 if (write) {
1586 int val = *negp ? -*lvalp : *lvalp;
1587 switch(op) {
1588 case OP_SET: *valp = val; break;
1589 case OP_AND: *valp &= val; break;
1590 case OP_OR: *valp |= val; break;
1591 case OP_MAX: if(*valp < val)
1592 *valp = val;
1593 break;
1594 case OP_MIN: if(*valp > val)
1595 *valp = val;
1596 break;
1598 } else {
1599 int val = *valp;
1600 if (val < 0) {
1601 *negp = -1;
1602 *lvalp = (unsigned long)-val;
1603 } else {
1604 *negp = 0;
1605 *lvalp = (unsigned long)val;
1608 return 0;
1612 * init may raise the set.
1615 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1616 void __user *buffer, size_t *lenp, loff_t *ppos)
1618 int op;
1620 if (!capable(CAP_SYS_MODULE)) {
1621 return -EPERM;
1624 op = (current->pid == 1) ? OP_SET : OP_AND;
1625 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1626 do_proc_dointvec_bset_conv,&op);
1629 struct do_proc_dointvec_minmax_conv_param {
1630 int *min;
1631 int *max;
1634 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1635 int *valp,
1636 int write, void *data)
1638 struct do_proc_dointvec_minmax_conv_param *param = data;
1639 if (write) {
1640 int val = *negp ? -*lvalp : *lvalp;
1641 if ((param->min && *param->min > val) ||
1642 (param->max && *param->max < val))
1643 return -EINVAL;
1644 *valp = val;
1645 } else {
1646 int val = *valp;
1647 if (val < 0) {
1648 *negp = -1;
1649 *lvalp = (unsigned long)-val;
1650 } else {
1651 *negp = 0;
1652 *lvalp = (unsigned long)val;
1655 return 0;
1659 * proc_dointvec_minmax - read a vector of integers with min/max values
1660 * @table: the sysctl table
1661 * @write: %TRUE if this is a write to the sysctl file
1662 * @filp: the file structure
1663 * @buffer: the user buffer
1664 * @lenp: the size of the user buffer
1666 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1667 * values from/to the user buffer, treated as an ASCII string.
1669 * This routine will ensure the values are within the range specified by
1670 * table->extra1 (min) and table->extra2 (max).
1672 * Returns 0 on success.
1674 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1675 void __user *buffer, size_t *lenp, loff_t *ppos)
1677 struct do_proc_dointvec_minmax_conv_param param = {
1678 .min = (int *) table->extra1,
1679 .max = (int *) table->extra2,
1681 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1682 do_proc_dointvec_minmax_conv, &param);
1685 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1686 struct file *filp,
1687 void __user *buffer,
1688 size_t *lenp, loff_t *ppos,
1689 unsigned long convmul,
1690 unsigned long convdiv)
1692 #define TMPBUFLEN 21
1693 unsigned long *i, *min, *max, val;
1694 int vleft, first=1, neg;
1695 size_t len, left;
1696 char buf[TMPBUFLEN], *p;
1697 char __user *s = buffer;
1699 if (!table->data || !table->maxlen || !*lenp ||
1700 (*ppos && !write)) {
1701 *lenp = 0;
1702 return 0;
1705 i = (unsigned long *) table->data;
1706 min = (unsigned long *) table->extra1;
1707 max = (unsigned long *) table->extra2;
1708 vleft = table->maxlen / sizeof(unsigned long);
1709 left = *lenp;
1711 for (; left && vleft--; i++, min++, max++, first=0) {
1712 if (write) {
1713 while (left) {
1714 char c;
1715 if (get_user(c, s))
1716 return -EFAULT;
1717 if (!isspace(c))
1718 break;
1719 left--;
1720 s++;
1722 if (!left)
1723 break;
1724 neg = 0;
1725 len = left;
1726 if (len > TMPBUFLEN-1)
1727 len = TMPBUFLEN-1;
1728 if (copy_from_user(buf, s, len))
1729 return -EFAULT;
1730 buf[len] = 0;
1731 p = buf;
1732 if (*p == '-' && left > 1) {
1733 neg = 1;
1734 left--, p++;
1736 if (*p < '0' || *p > '9')
1737 break;
1738 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1739 len = p-buf;
1740 if ((len < left) && *p && !isspace(*p))
1741 break;
1742 if (neg)
1743 val = -val;
1744 s += len;
1745 left -= len;
1747 if(neg)
1748 continue;
1749 if ((min && val < *min) || (max && val > *max))
1750 continue;
1751 *i = val;
1752 } else {
1753 p = buf;
1754 if (!first)
1755 *p++ = '\t';
1756 sprintf(p, "%lu", convdiv * (*i) / convmul);
1757 len = strlen(buf);
1758 if (len > left)
1759 len = left;
1760 if(copy_to_user(s, buf, len))
1761 return -EFAULT;
1762 left -= len;
1763 s += len;
1767 if (!write && !first && left) {
1768 if(put_user('\n', s))
1769 return -EFAULT;
1770 left--, s++;
1772 if (write) {
1773 while (left) {
1774 char c;
1775 if (get_user(c, s++))
1776 return -EFAULT;
1777 if (!isspace(c))
1778 break;
1779 left--;
1782 if (write && first)
1783 return -EINVAL;
1784 *lenp -= left;
1785 *ppos += *lenp;
1786 return 0;
1787 #undef TMPBUFLEN
1791 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1792 * @table: the sysctl table
1793 * @write: %TRUE if this is a write to the sysctl file
1794 * @filp: the file structure
1795 * @buffer: the user buffer
1796 * @lenp: the size of the user buffer
1798 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1799 * values from/to the user buffer, treated as an ASCII string.
1801 * This routine will ensure the values are within the range specified by
1802 * table->extra1 (min) and table->extra2 (max).
1804 * Returns 0 on success.
1806 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1807 void __user *buffer, size_t *lenp, loff_t *ppos)
1809 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1813 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1814 * @table: the sysctl table
1815 * @write: %TRUE if this is a write to the sysctl file
1816 * @filp: the file structure
1817 * @buffer: the user buffer
1818 * @lenp: the size of the user buffer
1820 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1821 * values from/to the user buffer, treated as an ASCII string. The values
1822 * are treated as milliseconds, and converted to jiffies when they are stored.
1824 * This routine will ensure the values are within the range specified by
1825 * table->extra1 (min) and table->extra2 (max).
1827 * Returns 0 on success.
1829 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1830 struct file *filp,
1831 void __user *buffer,
1832 size_t *lenp, loff_t *ppos)
1834 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1835 lenp, ppos, HZ, 1000l);
1839 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1840 int *valp,
1841 int write, void *data)
1843 if (write) {
1844 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1845 } else {
1846 int val = *valp;
1847 unsigned long lval;
1848 if (val < 0) {
1849 *negp = -1;
1850 lval = (unsigned long)-val;
1851 } else {
1852 *negp = 0;
1853 lval = (unsigned long)val;
1855 *lvalp = lval / HZ;
1857 return 0;
1860 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1861 int *valp,
1862 int write, void *data)
1864 if (write) {
1865 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1866 } else {
1867 int val = *valp;
1868 unsigned long lval;
1869 if (val < 0) {
1870 *negp = -1;
1871 lval = (unsigned long)-val;
1872 } else {
1873 *negp = 0;
1874 lval = (unsigned long)val;
1876 *lvalp = jiffies_to_clock_t(lval);
1878 return 0;
1882 * proc_dointvec_jiffies - read a vector of integers as seconds
1883 * @table: the sysctl table
1884 * @write: %TRUE if this is a write to the sysctl file
1885 * @filp: the file structure
1886 * @buffer: the user buffer
1887 * @lenp: the size of the user buffer
1889 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1890 * values from/to the user buffer, treated as an ASCII string.
1891 * The values read are assumed to be in seconds, and are converted into
1892 * jiffies.
1894 * Returns 0 on success.
1896 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1897 void __user *buffer, size_t *lenp, loff_t *ppos)
1899 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1900 do_proc_dointvec_jiffies_conv,NULL);
1904 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1905 * @table: the sysctl table
1906 * @write: %TRUE if this is a write to the sysctl file
1907 * @filp: the file structure
1908 * @buffer: the user buffer
1909 * @lenp: the size of the user buffer
1911 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1912 * values from/to the user buffer, treated as an ASCII string.
1913 * The values read are assumed to be in 1/USER_HZ seconds, and
1914 * are converted into jiffies.
1916 * Returns 0 on success.
1918 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1919 void __user *buffer, size_t *lenp, loff_t *ppos)
1921 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1922 do_proc_dointvec_userhz_jiffies_conv,NULL);
1925 #else /* CONFIG_PROC_FS */
1927 int proc_dostring(ctl_table *table, int write, struct file *filp,
1928 void __user *buffer, size_t *lenp, loff_t *ppos)
1930 return -ENOSYS;
1933 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1934 void __user *buffer, size_t *lenp, loff_t *ppos)
1936 return -ENOSYS;
1939 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1940 void __user *buffer, size_t *lenp, loff_t *ppos)
1942 return -ENOSYS;
1945 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1946 void __user *buffer, size_t *lenp, loff_t *ppos)
1948 return -ENOSYS;
1951 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1952 void __user *buffer, size_t *lenp, loff_t *ppos)
1954 return -ENOSYS;
1957 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1958 void __user *buffer, size_t *lenp, loff_t *ppos)
1960 return -ENOSYS;
1963 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1964 void __user *buffer, size_t *lenp, loff_t *ppos)
1966 return -ENOSYS;
1969 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1970 void __user *buffer, size_t *lenp, loff_t *ppos)
1972 return -ENOSYS;
1975 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1976 struct file *filp,
1977 void __user *buffer,
1978 size_t *lenp, loff_t *ppos)
1980 return -ENOSYS;
1984 #endif /* CONFIG_PROC_FS */
1988 * General sysctl support routines
1991 /* The generic string strategy routine: */
1992 int sysctl_string(ctl_table *table, int __user *name, int nlen,
1993 void __user *oldval, size_t __user *oldlenp,
1994 void __user *newval, size_t newlen, void **context)
1996 size_t l, len;
1998 if (!table->data || !table->maxlen)
1999 return -ENOTDIR;
2001 if (oldval && oldlenp) {
2002 if (get_user(len, oldlenp))
2003 return -EFAULT;
2004 if (len) {
2005 l = strlen(table->data);
2006 if (len > l) len = l;
2007 if (len >= table->maxlen)
2008 len = table->maxlen;
2009 if(copy_to_user(oldval, table->data, len))
2010 return -EFAULT;
2011 if(put_user(0, ((char __user *) oldval) + len))
2012 return -EFAULT;
2013 if(put_user(len, oldlenp))
2014 return -EFAULT;
2017 if (newval && newlen) {
2018 len = newlen;
2019 if (len > table->maxlen)
2020 len = table->maxlen;
2021 if(copy_from_user(table->data, newval, len))
2022 return -EFAULT;
2023 if (len == table->maxlen)
2024 len--;
2025 ((char *) table->data)[len] = 0;
2027 return 0;
2031 * This function makes sure that all of the integers in the vector
2032 * are between the minimum and maximum values given in the arrays
2033 * table->extra1 and table->extra2, respectively.
2035 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2036 void __user *oldval, size_t __user *oldlenp,
2037 void __user *newval, size_t newlen, void **context)
2040 if (newval && newlen) {
2041 int __user *vec = (int __user *) newval;
2042 int *min = (int *) table->extra1;
2043 int *max = (int *) table->extra2;
2044 size_t length;
2045 int i;
2047 if (newlen % sizeof(int) != 0)
2048 return -EINVAL;
2050 if (!table->extra1 && !table->extra2)
2051 return 0;
2053 if (newlen > table->maxlen)
2054 newlen = table->maxlen;
2055 length = newlen / sizeof(int);
2057 for (i = 0; i < length; i++) {
2058 int value;
2059 if (get_user(value, vec + i))
2060 return -EFAULT;
2061 if (min && value < min[i])
2062 return -EINVAL;
2063 if (max && value > max[i])
2064 return -EINVAL;
2067 return 0;
2070 /* Strategy function to convert jiffies to seconds */
2071 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2072 void __user *oldval, size_t __user *oldlenp,
2073 void __user *newval, size_t newlen, void **context)
2075 if (oldval) {
2076 size_t olen;
2077 if (oldlenp) {
2078 if (get_user(olen, oldlenp))
2079 return -EFAULT;
2080 if (olen!=sizeof(int))
2081 return -EINVAL;
2083 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2084 (oldlenp && put_user(sizeof(int),oldlenp)))
2085 return -EFAULT;
2087 if (newval && newlen) {
2088 int new;
2089 if (newlen != sizeof(int))
2090 return -EINVAL;
2091 if (get_user(new, (int __user *)newval))
2092 return -EFAULT;
2093 *(int *)(table->data) = new*HZ;
2095 return 1;
2099 #else /* CONFIG_SYSCTL */
2102 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2104 return -ENOSYS;
2107 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2108 void __user *oldval, size_t __user *oldlenp,
2109 void __user *newval, size_t newlen, void **context)
2111 return -ENOSYS;
2114 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2115 void __user *oldval, size_t __user *oldlenp,
2116 void __user *newval, size_t newlen, void **context)
2118 return -ENOSYS;
2121 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2122 void __user *oldval, size_t __user *oldlenp,
2123 void __user *newval, size_t newlen, void **context)
2125 return -ENOSYS;
2128 int proc_dostring(ctl_table *table, int write, struct file *filp,
2129 void __user *buffer, size_t *lenp, loff_t *ppos)
2131 return -ENOSYS;
2134 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2135 void __user *buffer, size_t *lenp, loff_t *ppos)
2137 return -ENOSYS;
2140 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2141 void __user *buffer, size_t *lenp, loff_t *ppos)
2143 return -ENOSYS;
2146 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2147 void __user *buffer, size_t *lenp, loff_t *ppos)
2149 return -ENOSYS;
2152 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2153 void __user *buffer, size_t *lenp, loff_t *ppos)
2155 return -ENOSYS;
2158 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2159 void __user *buffer, size_t *lenp, loff_t *ppos)
2161 return -ENOSYS;
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 -ENOSYS;
2170 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2171 struct file *filp,
2172 void __user *buffer,
2173 size_t *lenp, loff_t *ppos)
2175 return -ENOSYS;
2178 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2179 int insert_at_head)
2181 return NULL;
2184 void unregister_sysctl_table(struct ctl_table_header * table)
2188 #endif /* CONFIG_SYSCTL */
2191 * No sense putting this after each symbol definition, twice,
2192 * exception granted :-)
2194 EXPORT_SYMBOL(proc_dointvec);
2195 EXPORT_SYMBOL(proc_dointvec_jiffies);
2196 EXPORT_SYMBOL(proc_dointvec_minmax);
2197 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2198 EXPORT_SYMBOL(proc_dostring);
2199 EXPORT_SYMBOL(proc_doulongvec_minmax);
2200 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2201 EXPORT_SYMBOL(register_sysctl_table);
2202 EXPORT_SYMBOL(sysctl_intvec);
2203 EXPORT_SYMBOL(sysctl_jiffies);
2204 EXPORT_SYMBOL(sysctl_string);
2205 EXPORT_SYMBOL(unregister_sysctl_table);