initial commit with v2.6.9
[linux-2.6.9-moxart.git] / kernel / sysctl.c
blob99a0af0ed9a8a38934dcfe69a1c0eb0b6eb6970f
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>
44 #include <asm/uaccess.h>
45 #include <asm/processor.h>
47 #ifdef CONFIG_ROOT_NFS
48 #include <linux/nfs_fs.h>
49 #endif
51 #if defined(CONFIG_SYSCTL)
53 /* External variables not in a header file. */
54 extern int panic_timeout;
55 extern int C_A_D;
56 extern int sysctl_overcommit_memory;
57 extern int sysctl_overcommit_ratio;
58 extern int max_threads;
59 extern int sysrq_enabled;
60 extern int core_uses_pid;
61 extern char core_pattern[];
62 extern int cad_pid;
63 extern int pid_max;
64 extern int sysctl_lower_zone_protection;
65 extern int min_free_kbytes;
66 extern int printk_ratelimit_jiffies;
67 extern int printk_ratelimit_burst;
69 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
70 int unknown_nmi_panic;
71 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
72 void __user *, size_t *, loff_t *);
73 #endif
75 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
76 static int maxolduid = 65535;
77 static int minolduid;
79 static int ngroups_max = NGROUPS_MAX;
81 #ifdef CONFIG_KMOD
82 extern char modprobe_path[];
83 #endif
84 #ifdef CONFIG_HOTPLUG
85 extern char hotplug_path[];
86 #endif
87 #ifdef CONFIG_CHR_DEV_SG
88 extern int sg_big_buff;
89 #endif
90 #ifdef CONFIG_SYSVIPC
91 extern size_t shm_ctlmax;
92 extern size_t shm_ctlall;
93 extern int shm_ctlmni;
94 extern int msg_ctlmax;
95 extern int msg_ctlmnb;
96 extern int msg_ctlmni;
97 extern int sem_ctls[];
98 #endif
100 #ifdef __sparc__
101 extern char reboot_command [];
102 extern int stop_a_enabled;
103 extern int scons_pwroff;
104 #endif
106 #ifdef __hppa__
107 extern int pwrsw_enabled;
108 extern int unaligned_enabled;
109 #endif
111 #ifdef CONFIG_ARCH_S390
112 #ifdef CONFIG_MATHEMU
113 extern int sysctl_ieee_emulation_warnings;
114 #endif
115 extern int sysctl_userprocess_debug;
116 #endif
118 extern int sysctl_hz_timer;
120 #ifdef CONFIG_BSD_PROCESS_ACCT
121 extern int acct_parm[];
122 #endif
124 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
125 ctl_table *, void **);
126 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
127 void __user *buffer, size_t *lenp, loff_t *ppos);
129 static ctl_table root_table[];
130 static struct ctl_table_header root_table_header =
131 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
133 static ctl_table kern_table[];
134 static ctl_table vm_table[];
135 #ifdef CONFIG_NET
136 extern ctl_table net_table[];
137 #endif
138 static ctl_table proc_table[];
139 static ctl_table fs_table[];
140 static ctl_table debug_table[];
141 static ctl_table dev_table[];
142 extern ctl_table random_table[];
143 #ifdef CONFIG_UNIX98_PTYS
144 extern ctl_table pty_table[];
145 #endif
147 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
148 int sysctl_legacy_va_layout;
149 #endif
151 /* /proc declarations: */
153 #ifdef CONFIG_PROC_FS
155 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
156 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
157 static int proc_opensys(struct inode *, struct file *);
159 struct file_operations proc_sys_file_operations = {
160 .open = proc_opensys,
161 .read = proc_readsys,
162 .write = proc_writesys,
165 extern struct proc_dir_entry *proc_sys_root;
167 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
168 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
169 #endif
171 /* The default sysctl tables: */
173 static ctl_table root_table[] = {
175 .ctl_name = CTL_KERN,
176 .procname = "kernel",
177 .mode = 0555,
178 .child = kern_table,
181 .ctl_name = CTL_VM,
182 .procname = "vm",
183 .mode = 0555,
184 .child = vm_table,
186 #ifdef CONFIG_NET
188 .ctl_name = CTL_NET,
189 .procname = "net",
190 .mode = 0555,
191 .child = net_table,
193 #endif
195 .ctl_name = CTL_PROC,
196 .procname = "proc",
197 .mode = 0555,
198 .child = proc_table,
201 .ctl_name = CTL_FS,
202 .procname = "fs",
203 .mode = 0555,
204 .child = fs_table,
207 .ctl_name = CTL_DEBUG,
208 .procname = "debug",
209 .mode = 0555,
210 .child = debug_table,
213 .ctl_name = CTL_DEV,
214 .procname = "dev",
215 .mode = 0555,
216 .child = dev_table,
218 { .ctl_name = 0 }
221 static ctl_table kern_table[] = {
223 .ctl_name = KERN_OSTYPE,
224 .procname = "ostype",
225 .data = system_utsname.sysname,
226 .maxlen = sizeof(system_utsname.sysname),
227 .mode = 0444,
228 .proc_handler = &proc_doutsstring,
229 .strategy = &sysctl_string,
232 .ctl_name = KERN_OSRELEASE,
233 .procname = "osrelease",
234 .data = system_utsname.release,
235 .maxlen = sizeof(system_utsname.release),
236 .mode = 0444,
237 .proc_handler = &proc_doutsstring,
238 .strategy = &sysctl_string,
241 .ctl_name = KERN_VERSION,
242 .procname = "version",
243 .data = system_utsname.version,
244 .maxlen = sizeof(system_utsname.version),
245 .mode = 0444,
246 .proc_handler = &proc_doutsstring,
247 .strategy = &sysctl_string,
250 .ctl_name = KERN_NODENAME,
251 .procname = "hostname",
252 .data = system_utsname.nodename,
253 .maxlen = sizeof(system_utsname.nodename),
254 .mode = 0644,
255 .proc_handler = &proc_doutsstring,
256 .strategy = &sysctl_string,
259 .ctl_name = KERN_DOMAINNAME,
260 .procname = "domainname",
261 .data = system_utsname.domainname,
262 .maxlen = sizeof(system_utsname.domainname),
263 .mode = 0644,
264 .proc_handler = &proc_doutsstring,
265 .strategy = &sysctl_string,
268 .ctl_name = KERN_PANIC,
269 .procname = "panic",
270 .data = &panic_timeout,
271 .maxlen = sizeof(int),
272 .mode = 0644,
273 .proc_handler = &proc_dointvec,
276 .ctl_name = KERN_CORE_USES_PID,
277 .procname = "core_uses_pid",
278 .data = &core_uses_pid,
279 .maxlen = sizeof(int),
280 .mode = 0644,
281 .proc_handler = &proc_dointvec,
284 .ctl_name = KERN_CORE_PATTERN,
285 .procname = "core_pattern",
286 .data = core_pattern,
287 .maxlen = 64,
288 .mode = 0644,
289 .proc_handler = &proc_dostring,
290 .strategy = &sysctl_string,
293 .ctl_name = KERN_TAINTED,
294 .procname = "tainted",
295 .data = &tainted,
296 .maxlen = sizeof(int),
297 .mode = 0444,
298 .proc_handler = &proc_dointvec,
301 .ctl_name = KERN_CAP_BSET,
302 .procname = "cap-bound",
303 .data = &cap_bset,
304 .maxlen = sizeof(kernel_cap_t),
305 .mode = 0600,
306 .proc_handler = &proc_dointvec_bset,
308 #ifdef CONFIG_BLK_DEV_INITRD
310 .ctl_name = KERN_REALROOTDEV,
311 .procname = "real-root-dev",
312 .data = &real_root_dev,
313 .maxlen = sizeof(int),
314 .mode = 0644,
315 .proc_handler = &proc_dointvec,
317 #endif
318 #ifdef __sparc__
320 .ctl_name = KERN_SPARC_REBOOT,
321 .procname = "reboot-cmd",
322 .data = reboot_command,
323 .maxlen = 256,
324 .mode = 0644,
325 .proc_handler = &proc_dostring,
326 .strategy = &sysctl_string,
329 .ctl_name = KERN_SPARC_STOP_A,
330 .procname = "stop-a",
331 .data = &stop_a_enabled,
332 .maxlen = sizeof (int),
333 .mode = 0644,
334 .proc_handler = &proc_dointvec,
337 .ctl_name = KERN_SPARC_SCONS_PWROFF,
338 .procname = "scons-poweroff",
339 .data = &scons_pwroff,
340 .maxlen = sizeof (int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
344 #endif
345 #ifdef __hppa__
347 .ctl_name = KERN_HPPA_PWRSW,
348 .procname = "soft-power",
349 .data = &pwrsw_enabled,
350 .maxlen = sizeof (int),
351 .mode = 0644,
352 .proc_handler = &proc_dointvec,
355 .ctl_name = KERN_HPPA_UNALIGNED,
356 .procname = "unaligned-trap",
357 .data = &unaligned_enabled,
358 .maxlen = sizeof (int),
359 .mode = 0644,
360 .proc_handler = &proc_dointvec,
362 #endif
364 .ctl_name = KERN_CTLALTDEL,
365 .procname = "ctrl-alt-del",
366 .data = &C_A_D,
367 .maxlen = sizeof(int),
368 .mode = 0644,
369 .proc_handler = &proc_dointvec,
372 .ctl_name = KERN_PRINTK,
373 .procname = "printk",
374 .data = &console_loglevel,
375 .maxlen = 4*sizeof(int),
376 .mode = 0644,
377 .proc_handler = &proc_dointvec,
379 #ifdef CONFIG_KMOD
381 .ctl_name = KERN_MODPROBE,
382 .procname = "modprobe",
383 .data = &modprobe_path,
384 .maxlen = KMOD_PATH_LEN,
385 .mode = 0644,
386 .proc_handler = &proc_dostring,
387 .strategy = &sysctl_string,
389 #endif
390 #ifdef CONFIG_HOTPLUG
392 .ctl_name = KERN_HOTPLUG,
393 .procname = "hotplug",
394 .data = &hotplug_path,
395 .maxlen = KMOD_PATH_LEN,
396 .mode = 0644,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
400 #endif
401 #ifdef CONFIG_CHR_DEV_SG
403 .ctl_name = KERN_SG_BIG_BUFF,
404 .procname = "sg-big-buff",
405 .data = &sg_big_buff,
406 .maxlen = sizeof (int),
407 .mode = 0444,
408 .proc_handler = &proc_dointvec,
410 #endif
411 #ifdef CONFIG_BSD_PROCESS_ACCT
413 .ctl_name = KERN_ACCT,
414 .procname = "acct",
415 .data = &acct_parm,
416 .maxlen = 3*sizeof(int),
417 .mode = 0644,
418 .proc_handler = &proc_dointvec,
420 #endif
421 #ifdef CONFIG_SYSVIPC
423 .ctl_name = KERN_SHMMAX,
424 .procname = "shmmax",
425 .data = &shm_ctlmax,
426 .maxlen = sizeof (size_t),
427 .mode = 0644,
428 .proc_handler = &proc_doulongvec_minmax,
431 .ctl_name = KERN_SHMALL,
432 .procname = "shmall",
433 .data = &shm_ctlall,
434 .maxlen = sizeof (size_t),
435 .mode = 0644,
436 .proc_handler = &proc_doulongvec_minmax,
439 .ctl_name = KERN_SHMMNI,
440 .procname = "shmmni",
441 .data = &shm_ctlmni,
442 .maxlen = sizeof (int),
443 .mode = 0644,
444 .proc_handler = &proc_dointvec,
447 .ctl_name = KERN_MSGMAX,
448 .procname = "msgmax",
449 .data = &msg_ctlmax,
450 .maxlen = sizeof (int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
455 .ctl_name = KERN_MSGMNI,
456 .procname = "msgmni",
457 .data = &msg_ctlmni,
458 .maxlen = sizeof (int),
459 .mode = 0644,
460 .proc_handler = &proc_dointvec,
463 .ctl_name = KERN_MSGMNB,
464 .procname = "msgmnb",
465 .data = &msg_ctlmnb,
466 .maxlen = sizeof (int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
471 .ctl_name = KERN_SEM,
472 .procname = "sem",
473 .data = &sem_ctls,
474 .maxlen = 4*sizeof (int),
475 .mode = 0644,
476 .proc_handler = &proc_dointvec,
478 #endif
479 #ifdef CONFIG_MAGIC_SYSRQ
481 .ctl_name = KERN_SYSRQ,
482 .procname = "sysrq",
483 .data = &sysrq_enabled,
484 .maxlen = sizeof (int),
485 .mode = 0644,
486 .proc_handler = &proc_dointvec,
488 #endif
490 .ctl_name = KERN_CADPID,
491 .procname = "cad_pid",
492 .data = &cad_pid,
493 .maxlen = sizeof (int),
494 .mode = 0600,
495 .proc_handler = &proc_dointvec,
498 .ctl_name = KERN_MAX_THREADS,
499 .procname = "threads-max",
500 .data = &max_threads,
501 .maxlen = sizeof(int),
502 .mode = 0644,
503 .proc_handler = &proc_dointvec,
506 .ctl_name = KERN_RANDOM,
507 .procname = "random",
508 .mode = 0555,
509 .child = random_table,
511 #ifdef CONFIG_UNIX98_PTYS
513 .ctl_name = KERN_PTY,
514 .procname = "pty",
515 .mode = 0555,
516 .child = pty_table,
518 #endif
520 .ctl_name = KERN_OVERFLOWUID,
521 .procname = "overflowuid",
522 .data = &overflowuid,
523 .maxlen = sizeof(int),
524 .mode = 0644,
525 .proc_handler = &proc_dointvec_minmax,
526 .strategy = &sysctl_intvec,
527 .extra1 = &minolduid,
528 .extra2 = &maxolduid,
531 .ctl_name = KERN_OVERFLOWGID,
532 .procname = "overflowgid",
533 .data = &overflowgid,
534 .maxlen = sizeof(int),
535 .mode = 0644,
536 .proc_handler = &proc_dointvec_minmax,
537 .strategy = &sysctl_intvec,
538 .extra1 = &minolduid,
539 .extra2 = &maxolduid,
541 #ifdef CONFIG_ARCH_S390
542 #ifdef CONFIG_MATHEMU
544 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
545 .procname = "ieee_emulation_warnings",
546 .data = &sysctl_ieee_emulation_warnings,
547 .maxlen = sizeof(int),
548 .mode = 0644,
549 .proc_handler = &proc_dointvec,
551 #endif
552 #ifdef CONFIG_NO_IDLE_HZ
554 .ctl_name = KERN_HZ_TIMER,
555 .procname = "hz_timer",
556 .data = &sysctl_hz_timer,
557 .maxlen = sizeof(int),
558 .mode = 0644,
559 .proc_handler = &proc_dointvec,
561 #endif
563 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
564 .procname = "userprocess_debug",
565 .data = &sysctl_userprocess_debug,
566 .maxlen = sizeof(int),
567 .mode = 0644,
568 .proc_handler = &proc_dointvec,
570 #endif
572 .ctl_name = KERN_PIDMAX,
573 .procname = "pid_max",
574 .data = &pid_max,
575 .maxlen = sizeof (int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec,
580 .ctl_name = KERN_PANIC_ON_OOPS,
581 .procname = "panic_on_oops",
582 .data = &panic_on_oops,
583 .maxlen = sizeof(int),
584 .mode = 0644,
585 .proc_handler = &proc_dointvec,
588 .ctl_name = KERN_PRINTK_RATELIMIT,
589 .procname = "printk_ratelimit",
590 .data = &printk_ratelimit_jiffies,
591 .maxlen = sizeof(int),
592 .mode = 0644,
593 .proc_handler = &proc_dointvec_jiffies,
594 .strategy = &sysctl_jiffies,
597 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
598 .procname = "printk_ratelimit_burst",
599 .data = &printk_ratelimit_burst,
600 .maxlen = sizeof(int),
601 .mode = 0644,
602 .proc_handler = &proc_dointvec,
605 .ctl_name = KERN_NGROUPS_MAX,
606 .procname = "ngroups_max",
607 .data = &ngroups_max,
608 .maxlen = sizeof (int),
609 .mode = 0444,
610 .proc_handler = &proc_dointvec,
612 #if defined(CONFIG_X86_LOCAL_APIC) && defined(__i386__)
614 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
615 .procname = "unknown_nmi_panic",
616 .data = &unknown_nmi_panic,
617 .maxlen = sizeof (int),
618 .mode = 0644,
619 .proc_handler = &proc_unknown_nmi_panic,
621 #endif
622 { .ctl_name = 0 }
625 /* Constants for minimum and maximum testing in vm_table.
626 We use these as one-element integer vectors. */
627 static int zero;
628 static int one_hundred = 100;
631 static ctl_table vm_table[] = {
633 .ctl_name = VM_OVERCOMMIT_MEMORY,
634 .procname = "overcommit_memory",
635 .data = &sysctl_overcommit_memory,
636 .maxlen = sizeof(sysctl_overcommit_memory),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec,
641 .ctl_name = VM_OVERCOMMIT_RATIO,
642 .procname = "overcommit_ratio",
643 .data = &sysctl_overcommit_ratio,
644 .maxlen = sizeof(sysctl_overcommit_ratio),
645 .mode = 0644,
646 .proc_handler = &proc_dointvec,
649 .ctl_name = VM_PAGE_CLUSTER,
650 .procname = "page-cluster",
651 .data = &page_cluster,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 .proc_handler = &proc_dointvec,
657 .ctl_name = VM_DIRTY_BACKGROUND,
658 .procname = "dirty_background_ratio",
659 .data = &dirty_background_ratio,
660 .maxlen = sizeof(dirty_background_ratio),
661 .mode = 0644,
662 .proc_handler = &proc_dointvec_minmax,
663 .strategy = &sysctl_intvec,
664 .extra1 = &zero,
665 .extra2 = &one_hundred,
668 .ctl_name = VM_DIRTY_RATIO,
669 .procname = "dirty_ratio",
670 .data = &vm_dirty_ratio,
671 .maxlen = sizeof(vm_dirty_ratio),
672 .mode = 0644,
673 .proc_handler = &proc_dointvec_minmax,
674 .strategy = &sysctl_intvec,
675 .extra1 = &zero,
676 .extra2 = &one_hundred,
679 .ctl_name = VM_DIRTY_WB_CS,
680 .procname = "dirty_writeback_centisecs",
681 .data = &dirty_writeback_centisecs,
682 .maxlen = sizeof(dirty_writeback_centisecs),
683 .mode = 0644,
684 .proc_handler = &dirty_writeback_centisecs_handler,
687 .ctl_name = VM_DIRTY_EXPIRE_CS,
688 .procname = "dirty_expire_centisecs",
689 .data = &dirty_expire_centisecs,
690 .maxlen = sizeof(dirty_expire_centisecs),
691 .mode = 0644,
692 .proc_handler = &proc_dointvec,
695 .ctl_name = VM_NR_PDFLUSH_THREADS,
696 .procname = "nr_pdflush_threads",
697 .data = &nr_pdflush_threads,
698 .maxlen = sizeof nr_pdflush_threads,
699 .mode = 0444 /* read-only*/,
700 .proc_handler = &proc_dointvec,
703 .ctl_name = VM_SWAPPINESS,
704 .procname = "swappiness",
705 .data = &vm_swappiness,
706 .maxlen = sizeof(vm_swappiness),
707 .mode = 0644,
708 .proc_handler = &proc_dointvec_minmax,
709 .strategy = &sysctl_intvec,
710 .extra1 = &zero,
711 .extra2 = &one_hundred,
713 #ifdef CONFIG_HUGETLB_PAGE
715 .ctl_name = VM_HUGETLB_PAGES,
716 .procname = "nr_hugepages",
717 .data = &max_huge_pages,
718 .maxlen = sizeof(unsigned long),
719 .mode = 0644,
720 .proc_handler = &hugetlb_sysctl_handler,
721 .extra1 = (void *)&hugetlb_zero,
722 .extra2 = (void *)&hugetlb_infinity,
725 .ctl_name = VM_HUGETLB_GROUP,
726 .procname = "hugetlb_shm_group",
727 .data = &sysctl_hugetlb_shm_group,
728 .maxlen = sizeof(gid_t),
729 .mode = 0644,
730 .proc_handler = &proc_dointvec,
732 #endif
734 .ctl_name = VM_LOWER_ZONE_PROTECTION,
735 .procname = "lower_zone_protection",
736 .data = &sysctl_lower_zone_protection,
737 .maxlen = sizeof(sysctl_lower_zone_protection),
738 .mode = 0644,
739 .proc_handler = &lower_zone_protection_sysctl_handler,
740 .strategy = &sysctl_intvec,
741 .extra1 = &zero,
744 .ctl_name = VM_MIN_FREE_KBYTES,
745 .procname = "min_free_kbytes",
746 .data = &min_free_kbytes,
747 .maxlen = sizeof(min_free_kbytes),
748 .mode = 0644,
749 .proc_handler = &min_free_kbytes_sysctl_handler,
750 .strategy = &sysctl_intvec,
751 .extra1 = &zero,
754 .ctl_name = VM_MAX_MAP_COUNT,
755 .procname = "max_map_count",
756 .data = &sysctl_max_map_count,
757 .maxlen = sizeof(sysctl_max_map_count),
758 .mode = 0644,
759 .proc_handler = &proc_dointvec
762 .ctl_name = VM_LAPTOP_MODE,
763 .procname = "laptop_mode",
764 .data = &laptop_mode,
765 .maxlen = sizeof(laptop_mode),
766 .mode = 0644,
767 .proc_handler = &proc_dointvec,
768 .strategy = &sysctl_intvec,
769 .extra1 = &zero,
772 .ctl_name = VM_BLOCK_DUMP,
773 .procname = "block_dump",
774 .data = &block_dump,
775 .maxlen = sizeof(block_dump),
776 .mode = 0644,
777 .proc_handler = &proc_dointvec,
778 .strategy = &sysctl_intvec,
779 .extra1 = &zero,
782 .ctl_name = VM_VFS_CACHE_PRESSURE,
783 .procname = "vfs_cache_pressure",
784 .data = &sysctl_vfs_cache_pressure,
785 .maxlen = sizeof(sysctl_vfs_cache_pressure),
786 .mode = 0644,
787 .proc_handler = &proc_dointvec,
788 .strategy = &sysctl_intvec,
789 .extra1 = &zero,
791 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
793 .ctl_name = VM_LEGACY_VA_LAYOUT,
794 .procname = "legacy_va_layout",
795 .data = &sysctl_legacy_va_layout,
796 .maxlen = sizeof(sysctl_legacy_va_layout),
797 .mode = 0644,
798 .proc_handler = &proc_dointvec,
799 .strategy = &sysctl_intvec,
800 .extra1 = &zero,
802 #endif
803 { .ctl_name = 0 }
806 static ctl_table proc_table[] = {
807 { .ctl_name = 0 }
810 static ctl_table fs_table[] = {
812 .ctl_name = FS_NRINODE,
813 .procname = "inode-nr",
814 .data = &inodes_stat,
815 .maxlen = 2*sizeof(int),
816 .mode = 0444,
817 .proc_handler = &proc_dointvec,
820 .ctl_name = FS_STATINODE,
821 .procname = "inode-state",
822 .data = &inodes_stat,
823 .maxlen = 7*sizeof(int),
824 .mode = 0444,
825 .proc_handler = &proc_dointvec,
828 .ctl_name = FS_NRFILE,
829 .procname = "file-nr",
830 .data = &files_stat,
831 .maxlen = 3*sizeof(int),
832 .mode = 0444,
833 .proc_handler = &proc_dointvec,
836 .ctl_name = FS_MAXFILE,
837 .procname = "file-max",
838 .data = &files_stat.max_files,
839 .maxlen = sizeof(int),
840 .mode = 0644,
841 .proc_handler = &proc_dointvec,
844 .ctl_name = FS_DENTRY,
845 .procname = "dentry-state",
846 .data = &dentry_stat,
847 .maxlen = 6*sizeof(int),
848 .mode = 0444,
849 .proc_handler = &proc_dointvec,
852 .ctl_name = FS_OVERFLOWUID,
853 .procname = "overflowuid",
854 .data = &fs_overflowuid,
855 .maxlen = sizeof(int),
856 .mode = 0644,
857 .proc_handler = &proc_dointvec_minmax,
858 .strategy = &sysctl_intvec,
859 .extra1 = &minolduid,
860 .extra2 = &maxolduid,
863 .ctl_name = FS_OVERFLOWGID,
864 .procname = "overflowgid",
865 .data = &fs_overflowgid,
866 .maxlen = sizeof(int),
867 .mode = 0644,
868 .proc_handler = &proc_dointvec_minmax,
869 .strategy = &sysctl_intvec,
870 .extra1 = &minolduid,
871 .extra2 = &maxolduid,
874 .ctl_name = FS_LEASES,
875 .procname = "leases-enable",
876 .data = &leases_enable,
877 .maxlen = sizeof(int),
878 .mode = 0644,
879 .proc_handler = &proc_dointvec,
882 .ctl_name = FS_DIR_NOTIFY,
883 .procname = "dir-notify-enable",
884 .data = &dir_notify_enable,
885 .maxlen = sizeof(int),
886 .mode = 0644,
887 .proc_handler = &proc_dointvec,
890 .ctl_name = FS_LEASE_TIME,
891 .procname = "lease-break-time",
892 .data = &lease_break_time,
893 .maxlen = sizeof(int),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec,
898 .ctl_name = FS_AIO_NR,
899 .procname = "aio-nr",
900 .data = &aio_nr,
901 .maxlen = sizeof(aio_nr),
902 .mode = 0444,
903 .proc_handler = &proc_dointvec,
906 .ctl_name = FS_AIO_MAX_NR,
907 .procname = "aio-max-nr",
908 .data = &aio_max_nr,
909 .maxlen = sizeof(aio_max_nr),
910 .mode = 0644,
911 .proc_handler = &proc_dointvec,
913 { .ctl_name = 0 }
916 static ctl_table debug_table[] = {
917 { .ctl_name = 0 }
920 static ctl_table dev_table[] = {
921 { .ctl_name = 0 }
924 extern void init_irq_proc (void);
926 void __init sysctl_init(void)
928 #ifdef CONFIG_PROC_FS
929 register_proc_table(root_table, proc_sys_root);
930 init_irq_proc();
931 #endif
934 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
935 void __user *newval, size_t newlen)
937 struct list_head *tmp;
939 if (nlen <= 0 || nlen >= CTL_MAXNAME)
940 return -ENOTDIR;
941 if (oldval) {
942 int old_len;
943 if (!oldlenp || get_user(old_len, oldlenp))
944 return -EFAULT;
946 tmp = &root_table_header.ctl_entry;
947 do {
948 struct ctl_table_header *head =
949 list_entry(tmp, struct ctl_table_header, ctl_entry);
950 void *context = NULL;
951 int error = parse_table(name, nlen, oldval, oldlenp,
952 newval, newlen, head->ctl_table,
953 &context);
954 if (context)
955 kfree(context);
956 if (error != -ENOTDIR)
957 return error;
958 tmp = tmp->next;
959 } while (tmp != &root_table_header.ctl_entry);
960 return -ENOTDIR;
963 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
965 struct __sysctl_args tmp;
966 int error;
968 if (copy_from_user(&tmp, args, sizeof(tmp)))
969 return -EFAULT;
971 lock_kernel();
972 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
973 tmp.newval, tmp.newlen);
974 unlock_kernel();
975 return error;
979 * ctl_perm does NOT grant the superuser all rights automatically, because
980 * some sysctl variables are readonly even to root.
983 static int test_perm(int mode, int op)
985 if (!current->euid)
986 mode >>= 6;
987 else if (in_egroup_p(0))
988 mode >>= 3;
989 if ((mode & op & 0007) == op)
990 return 0;
991 return -EACCES;
994 static inline int ctl_perm(ctl_table *table, int op)
996 int error;
997 error = security_sysctl(table, op);
998 if (error)
999 return error;
1000 return test_perm(table->mode, op);
1003 static int parse_table(int __user *name, int nlen,
1004 void __user *oldval, size_t __user *oldlenp,
1005 void __user *newval, size_t newlen,
1006 ctl_table *table, void **context)
1008 int n;
1009 repeat:
1010 if (!nlen)
1011 return -ENOTDIR;
1012 if (get_user(n, name))
1013 return -EFAULT;
1014 for ( ; table->ctl_name; table++) {
1015 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1016 int error;
1017 if (table->child) {
1018 if (ctl_perm(table, 001))
1019 return -EPERM;
1020 if (table->strategy) {
1021 error = table->strategy(
1022 table, name, nlen,
1023 oldval, oldlenp,
1024 newval, newlen, context);
1025 if (error)
1026 return error;
1028 name++;
1029 nlen--;
1030 table = table->child;
1031 goto repeat;
1033 error = do_sysctl_strategy(table, name, nlen,
1034 oldval, oldlenp,
1035 newval, newlen, context);
1036 return error;
1039 return -ENOTDIR;
1042 /* Perform the actual read/write of a sysctl table entry. */
1043 int do_sysctl_strategy (ctl_table *table,
1044 int __user *name, int nlen,
1045 void __user *oldval, size_t __user *oldlenp,
1046 void __user *newval, size_t newlen, void **context)
1048 int op = 0, rc;
1049 size_t len;
1051 if (oldval)
1052 op |= 004;
1053 if (newval)
1054 op |= 002;
1055 if (ctl_perm(table, op))
1056 return -EPERM;
1058 if (table->strategy) {
1059 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1060 newval, newlen, context);
1061 if (rc < 0)
1062 return rc;
1063 if (rc > 0)
1064 return 0;
1067 /* If there is no strategy routine, or if the strategy returns
1068 * zero, proceed with automatic r/w */
1069 if (table->data && table->maxlen) {
1070 if (oldval && oldlenp) {
1071 if (get_user(len, oldlenp))
1072 return -EFAULT;
1073 if (len) {
1074 if (len > table->maxlen)
1075 len = table->maxlen;
1076 if(copy_to_user(oldval, table->data, len))
1077 return -EFAULT;
1078 if(put_user(len, oldlenp))
1079 return -EFAULT;
1082 if (newval && newlen) {
1083 len = newlen;
1084 if (len > table->maxlen)
1085 len = table->maxlen;
1086 if(copy_from_user(table->data, newval, len))
1087 return -EFAULT;
1090 return 0;
1094 * register_sysctl_table - register a sysctl hierarchy
1095 * @table: the top-level table structure
1096 * @insert_at_head: whether the entry should be inserted in front or at the end
1098 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1099 * array. An entry with a ctl_name of 0 terminates the table.
1101 * The members of the &ctl_table structure are used as follows:
1103 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1104 * must be unique within that level of sysctl
1106 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1107 * enter a sysctl file
1109 * data - a pointer to data for use by proc_handler
1111 * maxlen - the maximum size in bytes of the data
1113 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1115 * child - a pointer to the child sysctl table if this entry is a directory, or
1116 * %NULL.
1118 * proc_handler - the text handler routine (described below)
1120 * strategy - the strategy routine (described below)
1122 * de - for internal use by the sysctl routines
1124 * extra1, extra2 - extra pointers usable by the proc handler routines
1126 * Leaf nodes in the sysctl tree will be represented by a single file
1127 * under /proc; non-leaf nodes will be represented by directories.
1129 * sysctl(2) can automatically manage read and write requests through
1130 * the sysctl table. The data and maxlen fields of the ctl_table
1131 * struct enable minimal validation of the values being written to be
1132 * performed, and the mode field allows minimal authentication.
1134 * More sophisticated management can be enabled by the provision of a
1135 * strategy routine with the table entry. This will be called before
1136 * any automatic read or write of the data is performed.
1138 * The strategy routine may return
1140 * < 0 - Error occurred (error is passed to user process)
1142 * 0 - OK - proceed with automatic read or write.
1144 * > 0 - OK - read or write has been done by the strategy routine, so
1145 * return immediately.
1147 * There must be a proc_handler routine for any terminal nodes
1148 * mirrored under /proc/sys (non-terminals are handled by a built-in
1149 * directory handler). Several default handlers are available to
1150 * cover common cases -
1152 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1153 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1154 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1156 * It is the handler's job to read the input buffer from user memory
1157 * and process it. The handler should return 0 on success.
1159 * This routine returns %NULL on a failure to register, and a pointer
1160 * to the table header on success.
1162 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1163 int insert_at_head)
1165 struct ctl_table_header *tmp;
1166 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1167 if (!tmp)
1168 return NULL;
1169 tmp->ctl_table = table;
1170 INIT_LIST_HEAD(&tmp->ctl_entry);
1171 if (insert_at_head)
1172 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1173 else
1174 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1175 #ifdef CONFIG_PROC_FS
1176 register_proc_table(table, proc_sys_root);
1177 #endif
1178 return tmp;
1182 * unregister_sysctl_table - unregister a sysctl table hierarchy
1183 * @header: the header returned from register_sysctl_table
1185 * Unregisters the sysctl table and all children. proc entries may not
1186 * actually be removed until they are no longer used by anyone.
1188 void unregister_sysctl_table(struct ctl_table_header * header)
1190 list_del(&header->ctl_entry);
1191 #ifdef CONFIG_PROC_FS
1192 unregister_proc_table(header->ctl_table, proc_sys_root);
1193 #endif
1194 kfree(header);
1198 * /proc/sys support
1201 #ifdef CONFIG_PROC_FS
1203 /* Scan the sysctl entries in table and add them all into /proc */
1204 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1206 struct proc_dir_entry *de;
1207 int len;
1208 mode_t mode;
1210 for (; table->ctl_name; table++) {
1211 /* Can't do anything without a proc name. */
1212 if (!table->procname)
1213 continue;
1214 /* Maybe we can't do anything with it... */
1215 if (!table->proc_handler && !table->child) {
1216 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1217 table->procname);
1218 continue;
1221 len = strlen(table->procname);
1222 mode = table->mode;
1224 de = NULL;
1225 if (table->proc_handler)
1226 mode |= S_IFREG;
1227 else {
1228 mode |= S_IFDIR;
1229 for (de = root->subdir; de; de = de->next) {
1230 if (proc_match(len, table->procname, de))
1231 break;
1233 /* If the subdir exists already, de is non-NULL */
1236 if (!de) {
1237 de = create_proc_entry(table->procname, mode, root);
1238 if (!de)
1239 continue;
1240 de->data = (void *) table;
1241 if (table->proc_handler)
1242 de->proc_fops = &proc_sys_file_operations;
1244 table->de = de;
1245 if (de->mode & S_IFDIR)
1246 register_proc_table(table->child, de);
1251 * Unregister a /proc sysctl table and any subdirectories.
1253 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1255 struct proc_dir_entry *de;
1256 for (; table->ctl_name; table++) {
1257 if (!(de = table->de))
1258 continue;
1259 if (de->mode & S_IFDIR) {
1260 if (!table->child) {
1261 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1262 continue;
1264 unregister_proc_table(table->child, de);
1266 /* Don't unregister directories which still have entries.. */
1267 if (de->subdir)
1268 continue;
1271 /* Don't unregister proc entries that are still being used.. */
1272 if (atomic_read(&de->count))
1273 continue;
1275 table->de = NULL;
1276 remove_proc_entry(table->procname, root);
1280 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1281 size_t count, loff_t *ppos)
1283 int op;
1284 struct proc_dir_entry *de;
1285 struct ctl_table *table;
1286 size_t res;
1287 ssize_t error;
1289 de = PDE(file->f_dentry->d_inode);
1290 if (!de || !de->data)
1291 return -ENOTDIR;
1292 table = (struct ctl_table *) de->data;
1293 if (!table || !table->proc_handler)
1294 return -ENOTDIR;
1295 op = (write ? 002 : 004);
1296 if (ctl_perm(table, op))
1297 return -EPERM;
1299 res = count;
1301 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1302 if (error)
1303 return error;
1304 return res;
1307 static int proc_opensys(struct inode *inode, struct file *file)
1309 if (file->f_mode & FMODE_WRITE) {
1311 * sysctl entries that are not writable,
1312 * are _NOT_ writable, capabilities or not.
1314 if (!(inode->i_mode & S_IWUSR))
1315 return -EPERM;
1318 return 0;
1321 static ssize_t proc_readsys(struct file * file, char __user * buf,
1322 size_t count, loff_t *ppos)
1324 return do_rw_proc(0, file, buf, count, ppos);
1327 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1328 size_t count, loff_t *ppos)
1330 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1334 * proc_dostring - read a string sysctl
1335 * @table: the sysctl table
1336 * @write: %TRUE if this is a write to the sysctl file
1337 * @filp: the file structure
1338 * @buffer: the user buffer
1339 * @lenp: the size of the user buffer
1341 * Reads/writes a string from/to the user buffer. If the kernel
1342 * buffer provided is not large enough to hold the string, the
1343 * string is truncated. The copied string is %NULL-terminated.
1344 * If the string is being read by the user process, it is copied
1345 * and a newline '\n' is added. It is truncated if the buffer is
1346 * not large enough.
1348 * Returns 0 on success.
1350 int proc_dostring(ctl_table *table, int write, struct file *filp,
1351 void __user *buffer, size_t *lenp, loff_t *ppos)
1353 size_t len;
1354 char __user *p;
1355 char c;
1357 if (!table->data || !table->maxlen || !*lenp ||
1358 (*ppos && !write)) {
1359 *lenp = 0;
1360 return 0;
1363 if (write) {
1364 len = 0;
1365 p = buffer;
1366 while (len < *lenp) {
1367 if (get_user(c, p++))
1368 return -EFAULT;
1369 if (c == 0 || c == '\n')
1370 break;
1371 len++;
1373 if (len >= table->maxlen)
1374 len = table->maxlen-1;
1375 if(copy_from_user(table->data, buffer, len))
1376 return -EFAULT;
1377 ((char *) table->data)[len] = 0;
1378 *ppos += *lenp;
1379 } else {
1380 len = strlen(table->data);
1381 if (len > table->maxlen)
1382 len = table->maxlen;
1383 if (len > *lenp)
1384 len = *lenp;
1385 if (len)
1386 if(copy_to_user(buffer, table->data, len))
1387 return -EFAULT;
1388 if (len < *lenp) {
1389 if(put_user('\n', ((char __user *) buffer) + len))
1390 return -EFAULT;
1391 len++;
1393 *lenp = len;
1394 *ppos += len;
1396 return 0;
1400 * Special case of dostring for the UTS structure. This has locks
1401 * to observe. Should this be in kernel/sys.c ????
1404 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1405 void __user *buffer, size_t *lenp, loff_t *ppos)
1407 int r;
1409 if (!write) {
1410 down_read(&uts_sem);
1411 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1412 up_read(&uts_sem);
1413 } else {
1414 down_write(&uts_sem);
1415 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1416 up_write(&uts_sem);
1418 return r;
1421 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1422 int *valp,
1423 int write, void *data)
1425 if (write) {
1426 *valp = *negp ? -*lvalp : *lvalp;
1427 } else {
1428 int val = *valp;
1429 if (val < 0) {
1430 *negp = -1;
1431 *lvalp = (unsigned long)-val;
1432 } else {
1433 *negp = 0;
1434 *lvalp = (unsigned long)val;
1437 return 0;
1440 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1441 void __user *buffer, size_t *lenp, loff_t *ppos,
1442 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1443 int write, void *data),
1444 void *data)
1446 #define TMPBUFLEN 21
1447 int *i, vleft, first=1, neg, val;
1448 unsigned long lval;
1449 size_t left, len;
1451 char buf[TMPBUFLEN], *p;
1452 char __user *s = buffer;
1454 if (!table->data || !table->maxlen || !*lenp ||
1455 (*ppos && !write)) {
1456 *lenp = 0;
1457 return 0;
1460 i = (int *) table->data;
1461 vleft = table->maxlen / sizeof(*i);
1462 left = *lenp;
1464 if (!conv)
1465 conv = do_proc_dointvec_conv;
1467 for (; left && vleft--; i++, first=0) {
1468 if (write) {
1469 while (left) {
1470 char c;
1471 if (get_user(c, s))
1472 return -EFAULT;
1473 if (!isspace(c))
1474 break;
1475 left--;
1476 s++;
1478 if (!left)
1479 break;
1480 neg = 0;
1481 len = left;
1482 if (len > sizeof(buf) - 1)
1483 len = sizeof(buf) - 1;
1484 if (copy_from_user(buf, s, len))
1485 return -EFAULT;
1486 buf[len] = 0;
1487 p = buf;
1488 if (*p == '-' && left > 1) {
1489 neg = 1;
1490 left--, p++;
1492 if (*p < '0' || *p > '9')
1493 break;
1495 lval = simple_strtoul(p, &p, 0);
1497 len = p-buf;
1498 if ((len < left) && *p && !isspace(*p))
1499 break;
1500 if (neg)
1501 val = -val;
1502 s += len;
1503 left -= len;
1505 if (conv(&neg, &lval, i, 1, data))
1506 break;
1507 } else {
1508 p = buf;
1509 if (!first)
1510 *p++ = '\t';
1512 if (conv(&neg, &lval, i, 0, data))
1513 break;
1515 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1516 len = strlen(buf);
1517 if (len > left)
1518 len = left;
1519 if(copy_to_user(s, buf, len))
1520 return -EFAULT;
1521 left -= len;
1522 s += len;
1526 if (!write && !first && left) {
1527 if(put_user('\n', s))
1528 return -EFAULT;
1529 left--, s++;
1531 if (write) {
1532 while (left) {
1533 char c;
1534 if (get_user(c, s++))
1535 return -EFAULT;
1536 if (!isspace(c))
1537 break;
1538 left--;
1541 if (write && first)
1542 return -EINVAL;
1543 *lenp -= left;
1544 *ppos += *lenp;
1545 return 0;
1546 #undef TMPBUFLEN
1550 * proc_dointvec - read a vector of integers
1551 * @table: the sysctl table
1552 * @write: %TRUE if this is a write to the sysctl file
1553 * @filp: the file structure
1554 * @buffer: the user buffer
1555 * @lenp: the size of the user buffer
1557 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1558 * values from/to the user buffer, treated as an ASCII string.
1560 * Returns 0 on success.
1562 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1563 void __user *buffer, size_t *lenp, loff_t *ppos)
1565 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1566 NULL,NULL);
1569 #define OP_SET 0
1570 #define OP_AND 1
1571 #define OP_OR 2
1572 #define OP_MAX 3
1573 #define OP_MIN 4
1575 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1576 int *valp,
1577 int write, void *data)
1579 int op = *(int *)data;
1580 if (write) {
1581 int val = *negp ? -*lvalp : *lvalp;
1582 switch(op) {
1583 case OP_SET: *valp = val; break;
1584 case OP_AND: *valp &= val; break;
1585 case OP_OR: *valp |= val; break;
1586 case OP_MAX: if(*valp < val)
1587 *valp = val;
1588 break;
1589 case OP_MIN: if(*valp > val)
1590 *valp = val;
1591 break;
1593 } else {
1594 int val = *valp;
1595 if (val < 0) {
1596 *negp = -1;
1597 *lvalp = (unsigned long)-val;
1598 } else {
1599 *negp = 0;
1600 *lvalp = (unsigned long)val;
1603 return 0;
1607 * init may raise the set.
1610 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1611 void __user *buffer, size_t *lenp, loff_t *ppos)
1613 int op;
1615 if (!capable(CAP_SYS_MODULE)) {
1616 return -EPERM;
1619 op = (current->pid == 1) ? OP_SET : OP_AND;
1620 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1621 do_proc_dointvec_bset_conv,&op);
1624 struct do_proc_dointvec_minmax_conv_param {
1625 int *min;
1626 int *max;
1629 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1630 int *valp,
1631 int write, void *data)
1633 struct do_proc_dointvec_minmax_conv_param *param = data;
1634 if (write) {
1635 int val = *negp ? -*lvalp : *lvalp;
1636 if ((param->min && *param->min > val) ||
1637 (param->max && *param->max < val))
1638 return -EINVAL;
1639 *valp = val;
1640 } else {
1641 int val = *valp;
1642 if (val < 0) {
1643 *negp = -1;
1644 *lvalp = (unsigned long)-val;
1645 } else {
1646 *negp = 0;
1647 *lvalp = (unsigned long)val;
1650 return 0;
1654 * proc_dointvec_minmax - read a vector of integers with min/max values
1655 * @table: the sysctl table
1656 * @write: %TRUE if this is a write to the sysctl file
1657 * @filp: the file structure
1658 * @buffer: the user buffer
1659 * @lenp: the size of the user buffer
1661 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1662 * values from/to the user buffer, treated as an ASCII string.
1664 * This routine will ensure the values are within the range specified by
1665 * table->extra1 (min) and table->extra2 (max).
1667 * Returns 0 on success.
1669 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1670 void __user *buffer, size_t *lenp, loff_t *ppos)
1672 struct do_proc_dointvec_minmax_conv_param param = {
1673 .min = (int *) table->extra1,
1674 .max = (int *) table->extra2,
1676 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1677 do_proc_dointvec_minmax_conv, &param);
1680 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1681 struct file *filp,
1682 void __user *buffer,
1683 size_t *lenp, loff_t *ppos,
1684 unsigned long convmul,
1685 unsigned long convdiv)
1687 #define TMPBUFLEN 21
1688 unsigned long *i, *min, *max, val;
1689 int vleft, first=1, neg;
1690 size_t len, left;
1691 char buf[TMPBUFLEN], *p;
1692 char __user *s = buffer;
1694 if (!table->data || !table->maxlen || !*lenp ||
1695 (*ppos && !write)) {
1696 *lenp = 0;
1697 return 0;
1700 i = (unsigned long *) table->data;
1701 min = (unsigned long *) table->extra1;
1702 max = (unsigned long *) table->extra2;
1703 vleft = table->maxlen / sizeof(unsigned long);
1704 left = *lenp;
1706 for (; left && vleft--; i++, min++, max++, first=0) {
1707 if (write) {
1708 while (left) {
1709 char c;
1710 if (get_user(c, s))
1711 return -EFAULT;
1712 if (!isspace(c))
1713 break;
1714 left--;
1715 s++;
1717 if (!left)
1718 break;
1719 neg = 0;
1720 len = left;
1721 if (len > TMPBUFLEN-1)
1722 len = TMPBUFLEN-1;
1723 if (copy_from_user(buf, s, len))
1724 return -EFAULT;
1725 buf[len] = 0;
1726 p = buf;
1727 if (*p == '-' && left > 1) {
1728 neg = 1;
1729 left--, p++;
1731 if (*p < '0' || *p > '9')
1732 break;
1733 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1734 len = p-buf;
1735 if ((len < left) && *p && !isspace(*p))
1736 break;
1737 if (neg)
1738 val = -val;
1739 s += len;
1740 left -= len;
1742 if(neg)
1743 continue;
1744 if ((min && val < *min) || (max && val > *max))
1745 continue;
1746 *i = val;
1747 } else {
1748 p = buf;
1749 if (!first)
1750 *p++ = '\t';
1751 sprintf(p, "%lu", convdiv * (*i) / convmul);
1752 len = strlen(buf);
1753 if (len > left)
1754 len = left;
1755 if(copy_to_user(s, buf, len))
1756 return -EFAULT;
1757 left -= len;
1758 s += len;
1762 if (!write && !first && left) {
1763 if(put_user('\n', s))
1764 return -EFAULT;
1765 left--, s++;
1767 if (write) {
1768 while (left) {
1769 char c;
1770 if (get_user(c, s++))
1771 return -EFAULT;
1772 if (!isspace(c))
1773 break;
1774 left--;
1777 if (write && first)
1778 return -EINVAL;
1779 *lenp -= left;
1780 *ppos += *lenp;
1781 return 0;
1782 #undef TMPBUFLEN
1786 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1787 * @table: the sysctl table
1788 * @write: %TRUE if this is a write to the sysctl file
1789 * @filp: the file structure
1790 * @buffer: the user buffer
1791 * @lenp: the size of the user buffer
1793 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1794 * values from/to the user buffer, treated as an ASCII string.
1796 * This routine will ensure the values are within the range specified by
1797 * table->extra1 (min) and table->extra2 (max).
1799 * Returns 0 on success.
1801 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1802 void __user *buffer, size_t *lenp, loff_t *ppos)
1804 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1808 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1809 * @table: the sysctl table
1810 * @write: %TRUE if this is a write to the sysctl file
1811 * @filp: the file structure
1812 * @buffer: the user buffer
1813 * @lenp: the size of the user buffer
1815 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1816 * values from/to the user buffer, treated as an ASCII string. The values
1817 * are treated as milliseconds, and converted to jiffies when they are stored.
1819 * This routine will ensure the values are within the range specified by
1820 * table->extra1 (min) and table->extra2 (max).
1822 * Returns 0 on success.
1824 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1825 struct file *filp,
1826 void __user *buffer,
1827 size_t *lenp, loff_t *ppos)
1829 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1830 lenp, ppos, HZ, 1000l);
1834 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1835 int *valp,
1836 int write, void *data)
1838 if (write) {
1839 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1840 } else {
1841 int val = *valp;
1842 unsigned long lval;
1843 if (val < 0) {
1844 *negp = -1;
1845 lval = (unsigned long)-val;
1846 } else {
1847 *negp = 0;
1848 lval = (unsigned long)val;
1850 *lvalp = lval / HZ;
1852 return 0;
1855 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1856 int *valp,
1857 int write, void *data)
1859 if (write) {
1860 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1861 } else {
1862 int val = *valp;
1863 unsigned long lval;
1864 if (val < 0) {
1865 *negp = -1;
1866 lval = (unsigned long)-val;
1867 } else {
1868 *negp = 0;
1869 lval = (unsigned long)val;
1871 *lvalp = jiffies_to_clock_t(lval);
1873 return 0;
1877 * proc_dointvec_jiffies - read a vector of integers as seconds
1878 * @table: the sysctl table
1879 * @write: %TRUE if this is a write to the sysctl file
1880 * @filp: the file structure
1881 * @buffer: the user buffer
1882 * @lenp: the size of the user buffer
1884 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1885 * values from/to the user buffer, treated as an ASCII string.
1886 * The values read are assumed to be in seconds, and are converted into
1887 * jiffies.
1889 * Returns 0 on success.
1891 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1892 void __user *buffer, size_t *lenp, loff_t *ppos)
1894 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1895 do_proc_dointvec_jiffies_conv,NULL);
1899 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1900 * @table: the sysctl table
1901 * @write: %TRUE if this is a write to the sysctl file
1902 * @filp: the file structure
1903 * @buffer: the user buffer
1904 * @lenp: the size of the user buffer
1906 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1907 * values from/to the user buffer, treated as an ASCII string.
1908 * The values read are assumed to be in 1/USER_HZ seconds, and
1909 * are converted into jiffies.
1911 * Returns 0 on success.
1913 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1914 void __user *buffer, size_t *lenp, loff_t *ppos)
1916 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1917 do_proc_dointvec_userhz_jiffies_conv,NULL);
1920 #else /* CONFIG_PROC_FS */
1922 int proc_dostring(ctl_table *table, int write, struct file *filp,
1923 void __user *buffer, size_t *lenp, loff_t *ppos)
1925 return -ENOSYS;
1928 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1929 void __user *buffer, size_t *lenp, loff_t *ppos)
1931 return -ENOSYS;
1934 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1935 void __user *buffer, size_t *lenp, loff_t *ppos)
1937 return -ENOSYS;
1940 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1941 void __user *buffer, size_t *lenp, loff_t *ppos)
1943 return -ENOSYS;
1946 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1947 void __user *buffer, size_t *lenp, loff_t *ppos)
1949 return -ENOSYS;
1952 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1953 void __user *buffer, size_t *lenp, loff_t *ppos)
1955 return -ENOSYS;
1958 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1959 void __user *buffer, size_t *lenp, loff_t *ppos)
1961 return -ENOSYS;
1964 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1965 void __user *buffer, size_t *lenp, loff_t *ppos)
1967 return -ENOSYS;
1970 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1971 struct file *filp,
1972 void __user *buffer,
1973 size_t *lenp, loff_t *ppos)
1975 return -ENOSYS;
1979 #endif /* CONFIG_PROC_FS */
1983 * General sysctl support routines
1986 /* The generic string strategy routine: */
1987 int sysctl_string(ctl_table *table, int __user *name, int nlen,
1988 void __user *oldval, size_t __user *oldlenp,
1989 void __user *newval, size_t newlen, void **context)
1991 size_t l, len;
1993 if (!table->data || !table->maxlen)
1994 return -ENOTDIR;
1996 if (oldval && oldlenp) {
1997 if (get_user(len, oldlenp))
1998 return -EFAULT;
1999 if (len) {
2000 l = strlen(table->data);
2001 if (len > l) len = l;
2002 if (len >= table->maxlen)
2003 len = table->maxlen;
2004 if(copy_to_user(oldval, table->data, len))
2005 return -EFAULT;
2006 if(put_user(0, ((char __user *) oldval) + len))
2007 return -EFAULT;
2008 if(put_user(len, oldlenp))
2009 return -EFAULT;
2012 if (newval && newlen) {
2013 len = newlen;
2014 if (len > table->maxlen)
2015 len = table->maxlen;
2016 if(copy_from_user(table->data, newval, len))
2017 return -EFAULT;
2018 if (len == table->maxlen)
2019 len--;
2020 ((char *) table->data)[len] = 0;
2022 return 0;
2026 * This function makes sure that all of the integers in the vector
2027 * are between the minimum and maximum values given in the arrays
2028 * table->extra1 and table->extra2, respectively.
2030 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2031 void __user *oldval, size_t __user *oldlenp,
2032 void __user *newval, size_t newlen, void **context)
2035 if (newval && newlen) {
2036 int __user *vec = (int __user *) newval;
2037 int *min = (int *) table->extra1;
2038 int *max = (int *) table->extra2;
2039 size_t length;
2040 int i;
2042 if (newlen % sizeof(int) != 0)
2043 return -EINVAL;
2045 if (!table->extra1 && !table->extra2)
2046 return 0;
2048 if (newlen > table->maxlen)
2049 newlen = table->maxlen;
2050 length = newlen / sizeof(int);
2052 for (i = 0; i < length; i++) {
2053 int value;
2054 if (get_user(value, vec + i))
2055 return -EFAULT;
2056 if (min && value < min[i])
2057 return -EINVAL;
2058 if (max && value > max[i])
2059 return -EINVAL;
2062 return 0;
2065 /* Strategy function to convert jiffies to seconds */
2066 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2067 void __user *oldval, size_t __user *oldlenp,
2068 void __user *newval, size_t newlen, void **context)
2070 if (oldval) {
2071 size_t olen;
2072 if (oldlenp) {
2073 if (get_user(olen, oldlenp))
2074 return -EFAULT;
2075 if (olen!=sizeof(int))
2076 return -EINVAL;
2078 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2079 (oldlenp && put_user(sizeof(int),oldlenp)))
2080 return -EFAULT;
2082 if (newval && newlen) {
2083 int new;
2084 if (newlen != sizeof(int))
2085 return -EINVAL;
2086 if (get_user(new, (int __user *)newval))
2087 return -EFAULT;
2088 *(int *)(table->data) = new*HZ;
2090 return 1;
2094 #else /* CONFIG_SYSCTL */
2097 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2099 return -ENOSYS;
2102 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2103 void __user *oldval, size_t __user *oldlenp,
2104 void __user *newval, size_t newlen, void **context)
2106 return -ENOSYS;
2109 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2110 void __user *oldval, size_t __user *oldlenp,
2111 void __user *newval, size_t newlen, void **context)
2113 return -ENOSYS;
2116 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2117 void __user *oldval, size_t __user *oldlenp,
2118 void __user *newval, size_t newlen, void **context)
2120 return -ENOSYS;
2123 int proc_dostring(ctl_table *table, int write, struct file *filp,
2124 void __user *buffer, size_t *lenp, loff_t *ppos)
2126 return -ENOSYS;
2129 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2130 void __user *buffer, size_t *lenp, loff_t *ppos)
2132 return -ENOSYS;
2135 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2136 void __user *buffer, size_t *lenp, loff_t *ppos)
2138 return -ENOSYS;
2141 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2142 void __user *buffer, size_t *lenp, loff_t *ppos)
2144 return -ENOSYS;
2147 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2148 void __user *buffer, size_t *lenp, loff_t *ppos)
2150 return -ENOSYS;
2153 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2154 void __user *buffer, size_t *lenp, loff_t *ppos)
2156 return -ENOSYS;
2159 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2160 void __user *buffer, size_t *lenp, loff_t *ppos)
2162 return -ENOSYS;
2165 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2166 struct file *filp,
2167 void __user *buffer,
2168 size_t *lenp, loff_t *ppos)
2170 return -ENOSYS;
2173 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2174 int insert_at_head)
2176 return NULL;
2179 void unregister_sysctl_table(struct ctl_table_header * table)
2183 #endif /* CONFIG_SYSCTL */
2186 * No sense putting this after each symbol definition, twice,
2187 * exception granted :-)
2189 EXPORT_SYMBOL(proc_dointvec);
2190 EXPORT_SYMBOL(proc_dointvec_jiffies);
2191 EXPORT_SYMBOL(proc_dointvec_minmax);
2192 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2193 EXPORT_SYMBOL(proc_dostring);
2194 EXPORT_SYMBOL(proc_doulongvec_minmax);
2195 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2196 EXPORT_SYMBOL(register_sysctl_table);
2197 EXPORT_SYMBOL(sysctl_intvec);
2198 EXPORT_SYMBOL(sysctl_jiffies);
2199 EXPORT_SYMBOL(sysctl_string);
2200 EXPORT_SYMBOL(unregister_sysctl_table);