[PATCH] fix saa7146 compilation
[linux-2.6/history.git] / kernel / sysctl.c
blob0df0748d56bd39a3787e554c1c3c6b1a2696a60f
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>
46 #ifdef CONFIG_ROOT_NFS
47 #include <linux/nfs_fs.h>
48 #endif
50 #if defined(CONFIG_SYSCTL)
52 /* External variables not in a header file. */
53 extern int panic_timeout;
54 extern int C_A_D;
55 extern int sysctl_overcommit_memory;
56 extern int sysctl_overcommit_ratio;
57 extern int max_threads;
58 extern int sysrq_enabled;
59 extern int core_uses_pid;
60 extern char core_pattern[];
61 extern int cad_pid;
62 extern int pid_max;
63 extern int sysctl_lower_zone_protection;
64 extern int min_free_kbytes;
65 extern int printk_ratelimit_jiffies;
66 extern int printk_ratelimit_burst;
68 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
69 static int maxolduid = 65535;
70 static int minolduid;
72 static int ngroups_max = NGROUPS_MAX;
74 #ifdef CONFIG_KMOD
75 extern char modprobe_path[];
76 #endif
77 #ifdef CONFIG_HOTPLUG
78 extern char hotplug_path[];
79 #endif
80 #ifdef CONFIG_CHR_DEV_SG
81 extern int sg_big_buff;
82 #endif
83 #ifdef CONFIG_SYSVIPC
84 extern size_t shm_ctlmax;
85 extern size_t shm_ctlall;
86 extern int shm_ctlmni;
87 extern int msg_ctlmax;
88 extern int msg_ctlmnb;
89 extern int msg_ctlmni;
90 extern int sem_ctls[];
91 #endif
93 #ifdef __sparc__
94 extern char reboot_command [];
95 extern int stop_a_enabled;
96 extern int scons_pwroff;
97 #endif
99 #ifdef __hppa__
100 extern int pwrsw_enabled;
101 extern int unaligned_enabled;
102 #endif
104 #ifdef CONFIG_ARCH_S390
105 #ifdef CONFIG_MATHEMU
106 extern int sysctl_ieee_emulation_warnings;
107 #endif
108 extern int sysctl_userprocess_debug;
109 #endif
111 extern int sysctl_hz_timer;
113 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
114 extern unsigned long powersave_nap;
115 int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
116 void *buffer, size_t *lenp);
117 #endif
119 #ifdef CONFIG_BSD_PROCESS_ACCT
120 extern int acct_parm[];
121 #endif
123 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
124 ctl_table *, void **);
125 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
126 void __user *buffer, size_t *lenp);
128 static ctl_table root_table[];
129 static struct ctl_table_header root_table_header =
130 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
132 static ctl_table kern_table[];
133 static ctl_table vm_table[];
134 #ifdef CONFIG_NET
135 extern ctl_table net_table[];
136 #endif
137 static ctl_table proc_table[];
138 static ctl_table fs_table[];
139 static ctl_table debug_table[];
140 static ctl_table dev_table[];
141 extern ctl_table random_table[];
142 #ifdef CONFIG_UNIX98_PTYS
143 extern ctl_table pty_table[];
144 #endif
146 /* /proc declarations: */
148 #ifdef CONFIG_PROC_FS
150 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
151 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
152 static int proc_opensys(struct inode *, struct file *);
154 struct file_operations proc_sys_file_operations = {
155 .open = proc_opensys,
156 .read = proc_readsys,
157 .write = proc_writesys,
160 extern struct proc_dir_entry *proc_sys_root;
162 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
163 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
164 #endif
166 /* The default sysctl tables: */
168 static ctl_table root_table[] = {
170 .ctl_name = CTL_KERN,
171 .procname = "kernel",
172 .mode = 0555,
173 .child = kern_table,
176 .ctl_name = CTL_VM,
177 .procname = "vm",
178 .mode = 0555,
179 .child = vm_table,
181 #ifdef CONFIG_NET
183 .ctl_name = CTL_NET,
184 .procname = "net",
185 .mode = 0555,
186 .child = net_table,
188 #endif
190 .ctl_name = CTL_PROC,
191 .procname = "proc",
192 .mode = 0555,
193 .child = proc_table,
196 .ctl_name = CTL_FS,
197 .procname = "fs",
198 .mode = 0555,
199 .child = fs_table,
202 .ctl_name = CTL_DEBUG,
203 .procname = "debug",
204 .mode = 0555,
205 .child = debug_table,
208 .ctl_name = CTL_DEV,
209 .procname = "dev",
210 .mode = 0555,
211 .child = dev_table,
213 { .ctl_name = 0 }
216 static ctl_table kern_table[] = {
218 .ctl_name = KERN_OSTYPE,
219 .procname = "ostype",
220 .data = system_utsname.sysname,
221 .maxlen = sizeof(system_utsname.sysname),
222 .mode = 0444,
223 .proc_handler = &proc_doutsstring,
224 .strategy = &sysctl_string,
227 .ctl_name = KERN_OSRELEASE,
228 .procname = "osrelease",
229 .data = system_utsname.release,
230 .maxlen = sizeof(system_utsname.release),
231 .mode = 0444,
232 .proc_handler = &proc_doutsstring,
233 .strategy = &sysctl_string,
236 .ctl_name = KERN_VERSION,
237 .procname = "version",
238 .data = system_utsname.version,
239 .maxlen = sizeof(system_utsname.version),
240 .mode = 0444,
241 .proc_handler = &proc_doutsstring,
242 .strategy = &sysctl_string,
245 .ctl_name = KERN_NODENAME,
246 .procname = "hostname",
247 .data = system_utsname.nodename,
248 .maxlen = sizeof(system_utsname.nodename),
249 .mode = 0644,
250 .proc_handler = &proc_doutsstring,
251 .strategy = &sysctl_string,
254 .ctl_name = KERN_DOMAINNAME,
255 .procname = "domainname",
256 .data = system_utsname.domainname,
257 .maxlen = sizeof(system_utsname.domainname),
258 .mode = 0644,
259 .proc_handler = &proc_doutsstring,
260 .strategy = &sysctl_string,
263 .ctl_name = KERN_PANIC,
264 .procname = "panic",
265 .data = &panic_timeout,
266 .maxlen = sizeof(int),
267 .mode = 0644,
268 .proc_handler = &proc_dointvec,
271 .ctl_name = KERN_CORE_USES_PID,
272 .procname = "core_uses_pid",
273 .data = &core_uses_pid,
274 .maxlen = sizeof(int),
275 .mode = 0644,
276 .proc_handler = &proc_dointvec,
279 .ctl_name = KERN_CORE_PATTERN,
280 .procname = "core_pattern",
281 .data = core_pattern,
282 .maxlen = 64,
283 .mode = 0644,
284 .proc_handler = &proc_dostring,
285 .strategy = &sysctl_string,
288 .ctl_name = KERN_TAINTED,
289 .procname = "tainted",
290 .data = &tainted,
291 .maxlen = sizeof(int),
292 .mode = 0644,
293 .proc_handler = &proc_dointvec,
296 .ctl_name = KERN_CAP_BSET,
297 .procname = "cap-bound",
298 .data = &cap_bset,
299 .maxlen = sizeof(kernel_cap_t),
300 .mode = 0600,
301 .proc_handler = &proc_dointvec_bset,
303 #ifdef CONFIG_BLK_DEV_INITRD
305 .ctl_name = KERN_REALROOTDEV,
306 .procname = "real-root-dev",
307 .data = &real_root_dev,
308 .maxlen = sizeof(int),
309 .mode = 0644,
310 .proc_handler = &proc_dointvec,
312 #endif
313 #ifdef __sparc__
315 .ctl_name = KERN_SPARC_REBOOT,
316 .procname = "reboot-cmd",
317 .data = reboot_command,
318 .maxlen = 256,
319 .mode = 0644,
320 .proc_handler = &proc_dostring,
321 .strategy = &sysctl_string,
324 .ctl_name = KERN_SPARC_STOP_A,
325 .procname = "stop-a",
326 .data = &stop_a_enabled,
327 .maxlen = sizeof (int),
328 .mode = 0644,
329 .proc_handler = &proc_dointvec,
332 .ctl_name = KERN_SPARC_SCONS_PWROFF,
333 .procname = "scons-poweroff",
334 .data = &scons_pwroff,
335 .maxlen = sizeof (int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
339 #endif
340 #ifdef __hppa__
342 .ctl_name = KERN_HPPA_PWRSW,
343 .procname = "soft-power",
344 .data = &pwrsw_enabled,
345 .maxlen = sizeof (int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
350 .ctl_name = KERN_HPPA_UNALIGNED,
351 .procname = "unaligned-trap",
352 .data = &unaligned_enabled,
353 .maxlen = sizeof (int),
354 .mode = 0644,
355 .proc_handler = &proc_dointvec,
357 #endif
358 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
360 .ctl_name = KERN_PPC_POWERSAVE_NAP,
361 .procname = "powersave-nap",
362 .data = &powersave_nap,
363 .maxlen = sizeof(int),
364 .mode = 0644,
365 .proc_handler = &proc_dointvec,
368 .ctl_name = KERN_PPC_L2CR,
369 .procname = "l2cr",
370 .mode = 0644,
371 .proc_handler = &proc_dol2crvec,
373 #endif
375 .ctl_name = KERN_CTLALTDEL,
376 .procname = "ctrl-alt-del",
377 .data = &C_A_D,
378 .maxlen = sizeof(int),
379 .mode = 0644,
380 .proc_handler = &proc_dointvec,
383 .ctl_name = KERN_PRINTK,
384 .procname = "printk",
385 .data = &console_loglevel,
386 .maxlen = 4*sizeof(int),
387 .mode = 0644,
388 .proc_handler = &proc_dointvec,
390 #ifdef CONFIG_KMOD
392 .ctl_name = KERN_MODPROBE,
393 .procname = "modprobe",
394 .data = &modprobe_path,
395 .maxlen = KMOD_PATH_LEN,
396 .mode = 0644,
397 .proc_handler = &proc_dostring,
398 .strategy = &sysctl_string,
400 #endif
401 #ifdef CONFIG_HOTPLUG
403 .ctl_name = KERN_HOTPLUG,
404 .procname = "hotplug",
405 .data = &hotplug_path,
406 .maxlen = KMOD_PATH_LEN,
407 .mode = 0644,
408 .proc_handler = &proc_dostring,
409 .strategy = &sysctl_string,
411 #endif
412 #ifdef CONFIG_CHR_DEV_SG
414 .ctl_name = KERN_SG_BIG_BUFF,
415 .procname = "sg-big-buff",
416 .data = &sg_big_buff,
417 .maxlen = sizeof (int),
418 .mode = 0444,
419 .proc_handler = &proc_dointvec,
421 #endif
422 #ifdef CONFIG_BSD_PROCESS_ACCT
424 .ctl_name = KERN_ACCT,
425 .procname = "acct",
426 .data = &acct_parm,
427 .maxlen = 3*sizeof(int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
431 #endif
432 #ifdef CONFIG_SYSVIPC
434 .ctl_name = KERN_SHMMAX,
435 .procname = "shmmax",
436 .data = &shm_ctlmax,
437 .maxlen = sizeof (size_t),
438 .mode = 0644,
439 .proc_handler = &proc_doulongvec_minmax,
442 .ctl_name = KERN_SHMALL,
443 .procname = "shmall",
444 .data = &shm_ctlall,
445 .maxlen = sizeof (size_t),
446 .mode = 0644,
447 .proc_handler = &proc_doulongvec_minmax,
450 .ctl_name = KERN_SHMMNI,
451 .procname = "shmmni",
452 .data = &shm_ctlmni,
453 .maxlen = sizeof (int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
458 .ctl_name = KERN_MSGMAX,
459 .procname = "msgmax",
460 .data = &msg_ctlmax,
461 .maxlen = sizeof (int),
462 .mode = 0644,
463 .proc_handler = &proc_dointvec,
466 .ctl_name = KERN_MSGMNI,
467 .procname = "msgmni",
468 .data = &msg_ctlmni,
469 .maxlen = sizeof (int),
470 .mode = 0644,
471 .proc_handler = &proc_dointvec,
474 .ctl_name = KERN_MSGMNB,
475 .procname = "msgmnb",
476 .data = &msg_ctlmnb,
477 .maxlen = sizeof (int),
478 .mode = 0644,
479 .proc_handler = &proc_dointvec,
482 .ctl_name = KERN_SEM,
483 .procname = "sem",
484 .data = &sem_ctls,
485 .maxlen = 4*sizeof (int),
486 .mode = 0644,
487 .proc_handler = &proc_dointvec,
489 #endif
490 #ifdef CONFIG_MAGIC_SYSRQ
492 .ctl_name = KERN_SYSRQ,
493 .procname = "sysrq",
494 .data = &sysrq_enabled,
495 .maxlen = sizeof (int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
499 #endif
501 .ctl_name = KERN_CADPID,
502 .procname = "cad_pid",
503 .data = &cad_pid,
504 .maxlen = sizeof (int),
505 .mode = 0600,
506 .proc_handler = &proc_dointvec,
509 .ctl_name = KERN_MAX_THREADS,
510 .procname = "threads-max",
511 .data = &max_threads,
512 .maxlen = sizeof(int),
513 .mode = 0644,
514 .proc_handler = &proc_dointvec,
517 .ctl_name = KERN_RANDOM,
518 .procname = "random",
519 .mode = 0555,
520 .child = random_table,
522 #ifdef CONFIG_UNIX98_PTYS
524 .ctl_name = KERN_PTY,
525 .procname = "pty",
526 .mode = 0555,
527 .child = pty_table,
529 #endif
531 .ctl_name = KERN_OVERFLOWUID,
532 .procname = "overflowuid",
533 .data = &overflowuid,
534 .maxlen = sizeof(int),
535 .mode = 0644,
536 .proc_handler = &proc_dointvec_minmax,
537 .strategy = &sysctl_intvec,
538 .extra1 = &minolduid,
539 .extra2 = &maxolduid,
542 .ctl_name = KERN_OVERFLOWGID,
543 .procname = "overflowgid",
544 .data = &overflowgid,
545 .maxlen = sizeof(int),
546 .mode = 0644,
547 .proc_handler = &proc_dointvec_minmax,
548 .strategy = &sysctl_intvec,
549 .extra1 = &minolduid,
550 .extra2 = &maxolduid,
552 #ifdef CONFIG_ARCH_S390
553 #ifdef CONFIG_MATHEMU
555 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
556 .procname = "ieee_emulation_warnings",
557 .data = &sysctl_ieee_emulation_warnings,
558 .maxlen = sizeof(int),
559 .mode = 0644,
560 .proc_handler = &proc_dointvec,
562 #endif
563 #ifdef CONFIG_NO_IDLE_HZ
565 .ctl_name = KERN_HZ_TIMER,
566 .procname = "hz_timer",
567 .data = &sysctl_hz_timer,
568 .maxlen = sizeof(int),
569 .mode = 0644,
570 .proc_handler = &proc_dointvec,
572 #endif
574 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
575 .procname = "userprocess_debug",
576 .data = &sysctl_userprocess_debug,
577 .maxlen = sizeof(int),
578 .mode = 0644,
579 .proc_handler = &proc_dointvec,
581 #endif
583 .ctl_name = KERN_PIDMAX,
584 .procname = "pid_max",
585 .data = &pid_max,
586 .maxlen = sizeof (int),
587 .mode = 0644,
588 .proc_handler = &proc_dointvec,
591 .ctl_name = KERN_PANIC_ON_OOPS,
592 .procname = "panic_on_oops",
593 .data = &panic_on_oops,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec,
599 .ctl_name = KERN_PRINTK_RATELIMIT,
600 .procname = "printk_ratelimit",
601 .data = &printk_ratelimit_jiffies,
602 .maxlen = sizeof(int),
603 .mode = 0644,
604 .proc_handler = &proc_dointvec_jiffies,
605 .strategy = &sysctl_jiffies,
608 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
609 .procname = "printk_ratelimit_burst",
610 .data = &printk_ratelimit_burst,
611 .maxlen = sizeof(int),
612 .mode = 0644,
613 .proc_handler = &proc_dointvec,
616 .ctl_name = KERN_NGROUPS_MAX,
617 .procname = "ngroups_max",
618 .data = &ngroups_max,
619 .maxlen = sizeof (int),
620 .mode = 0444,
621 .proc_handler = &proc_dointvec,
623 { .ctl_name = 0 }
626 /* Constants for minimum and maximum testing in vm_table.
627 We use these as one-element integer vectors. */
628 static int zero;
629 static int one_hundred = 100;
632 static ctl_table vm_table[] = {
634 .ctl_name = VM_OVERCOMMIT_MEMORY,
635 .procname = "overcommit_memory",
636 .data = &sysctl_overcommit_memory,
637 .maxlen = sizeof(sysctl_overcommit_memory),
638 .mode = 0644,
639 .proc_handler = &proc_dointvec,
642 .ctl_name = VM_OVERCOMMIT_RATIO,
643 .procname = "overcommit_ratio",
644 .data = &sysctl_overcommit_ratio,
645 .maxlen = sizeof(sysctl_overcommit_ratio),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec,
650 .ctl_name = VM_PAGE_CLUSTER,
651 .procname = "page-cluster",
652 .data = &page_cluster,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec,
658 .ctl_name = VM_DIRTY_BACKGROUND,
659 .procname = "dirty_background_ratio",
660 .data = &dirty_background_ratio,
661 .maxlen = sizeof(dirty_background_ratio),
662 .mode = 0644,
663 .proc_handler = &proc_dointvec_minmax,
664 .strategy = &sysctl_intvec,
665 .extra1 = &zero,
666 .extra2 = &one_hundred,
669 .ctl_name = VM_DIRTY_RATIO,
670 .procname = "dirty_ratio",
671 .data = &vm_dirty_ratio,
672 .maxlen = sizeof(vm_dirty_ratio),
673 .mode = 0644,
674 .proc_handler = &proc_dointvec_minmax,
675 .strategy = &sysctl_intvec,
676 .extra1 = &zero,
677 .extra2 = &one_hundred,
680 .ctl_name = VM_DIRTY_WB_CS,
681 .procname = "dirty_writeback_centisecs",
682 .data = &dirty_writeback_centisecs,
683 .maxlen = sizeof(dirty_writeback_centisecs),
684 .mode = 0644,
685 .proc_handler = &dirty_writeback_centisecs_handler,
688 .ctl_name = VM_DIRTY_EXPIRE_CS,
689 .procname = "dirty_expire_centisecs",
690 .data = &dirty_expire_centisecs,
691 .maxlen = sizeof(dirty_expire_centisecs),
692 .mode = 0644,
693 .proc_handler = &proc_dointvec,
696 .ctl_name = VM_NR_PDFLUSH_THREADS,
697 .procname = "nr_pdflush_threads",
698 .data = &nr_pdflush_threads,
699 .maxlen = sizeof nr_pdflush_threads,
700 .mode = 0444 /* read-only*/,
701 .proc_handler = &proc_dointvec,
704 .ctl_name = VM_SWAPPINESS,
705 .procname = "swappiness",
706 .data = &vm_swappiness,
707 .maxlen = sizeof(vm_swappiness),
708 .mode = 0644,
709 .proc_handler = &proc_dointvec_minmax,
710 .strategy = &sysctl_intvec,
711 .extra1 = &zero,
712 .extra2 = &one_hundred,
714 #ifdef CONFIG_HUGETLB_PAGE
716 .ctl_name = VM_HUGETLB_PAGES,
717 .procname = "nr_hugepages",
718 .data = &max_huge_pages,
719 .maxlen = sizeof(unsigned long),
720 .mode = 0644,
721 .proc_handler = &hugetlb_sysctl_handler,
722 .extra1 = (void *)&hugetlb_zero,
723 .extra2 = (void *)&hugetlb_infinity,
726 .ctl_name = VM_HUGETLB_GROUP,
727 .procname = "hugetlb_shm_group",
728 .data = &sysctl_hugetlb_shm_group,
729 .maxlen = sizeof(gid_t),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec,
733 #endif
735 .ctl_name = VM_LOWER_ZONE_PROTECTION,
736 .procname = "lower_zone_protection",
737 .data = &sysctl_lower_zone_protection,
738 .maxlen = sizeof(sysctl_lower_zone_protection),
739 .mode = 0644,
740 .proc_handler = &lower_zone_protection_sysctl_handler,
741 .strategy = &sysctl_intvec,
742 .extra1 = &zero,
745 .ctl_name = VM_MIN_FREE_KBYTES,
746 .procname = "min_free_kbytes",
747 .data = &min_free_kbytes,
748 .maxlen = sizeof(min_free_kbytes),
749 .mode = 0644,
750 .proc_handler = &min_free_kbytes_sysctl_handler,
751 .strategy = &sysctl_intvec,
752 .extra1 = &zero,
755 .ctl_name = VM_MAX_MAP_COUNT,
756 .procname = "max_map_count",
757 .data = &sysctl_max_map_count,
758 .maxlen = sizeof(sysctl_max_map_count),
759 .mode = 0644,
760 .proc_handler = &proc_dointvec
763 .ctl_name = VM_LAPTOP_MODE,
764 .procname = "laptop_mode",
765 .data = &laptop_mode,
766 .maxlen = sizeof(laptop_mode),
767 .mode = 0644,
768 .proc_handler = &proc_dointvec,
769 .strategy = &sysctl_intvec,
770 .extra1 = &zero,
773 .ctl_name = VM_BLOCK_DUMP,
774 .procname = "block_dump",
775 .data = &block_dump,
776 .maxlen = sizeof(block_dump),
777 .mode = 0644,
778 .proc_handler = &proc_dointvec,
779 .strategy = &sysctl_intvec,
780 .extra1 = &zero,
783 .ctl_name = VM_VFS_CACHE_PRESSURE,
784 .procname = "vfs_cache_pressure",
785 .data = &sysctl_vfs_cache_pressure,
786 .maxlen = sizeof(sysctl_vfs_cache_pressure),
787 .mode = 0644,
788 .proc_handler = &proc_dointvec,
789 .strategy = &sysctl_intvec,
790 .extra1 = &zero,
792 { .ctl_name = 0 }
795 static ctl_table proc_table[] = {
796 { .ctl_name = 0 }
799 static ctl_table fs_table[] = {
801 .ctl_name = FS_NRINODE,
802 .procname = "inode-nr",
803 .data = &inodes_stat,
804 .maxlen = 2*sizeof(int),
805 .mode = 0444,
806 .proc_handler = &proc_dointvec,
809 .ctl_name = FS_STATINODE,
810 .procname = "inode-state",
811 .data = &inodes_stat,
812 .maxlen = 7*sizeof(int),
813 .mode = 0444,
814 .proc_handler = &proc_dointvec,
817 .ctl_name = FS_NRFILE,
818 .procname = "file-nr",
819 .data = &files_stat,
820 .maxlen = 3*sizeof(int),
821 .mode = 0444,
822 .proc_handler = &proc_dointvec,
825 .ctl_name = FS_MAXFILE,
826 .procname = "file-max",
827 .data = &files_stat.max_files,
828 .maxlen = sizeof(int),
829 .mode = 0644,
830 .proc_handler = &proc_dointvec,
833 .ctl_name = FS_DENTRY,
834 .procname = "dentry-state",
835 .data = &dentry_stat,
836 .maxlen = 6*sizeof(int),
837 .mode = 0444,
838 .proc_handler = &proc_dointvec,
841 .ctl_name = FS_OVERFLOWUID,
842 .procname = "overflowuid",
843 .data = &fs_overflowuid,
844 .maxlen = sizeof(int),
845 .mode = 0644,
846 .proc_handler = &proc_dointvec_minmax,
847 .strategy = &sysctl_intvec,
848 .extra1 = &minolduid,
849 .extra2 = &maxolduid,
852 .ctl_name = FS_OVERFLOWGID,
853 .procname = "overflowgid",
854 .data = &fs_overflowgid,
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_LEASES,
864 .procname = "leases-enable",
865 .data = &leases_enable,
866 .maxlen = sizeof(int),
867 .mode = 0644,
868 .proc_handler = &proc_dointvec,
871 .ctl_name = FS_DIR_NOTIFY,
872 .procname = "dir-notify-enable",
873 .data = &dir_notify_enable,
874 .maxlen = sizeof(int),
875 .mode = 0644,
876 .proc_handler = &proc_dointvec,
879 .ctl_name = FS_LEASE_TIME,
880 .procname = "lease-break-time",
881 .data = &lease_break_time,
882 .maxlen = sizeof(int),
883 .mode = 0644,
884 .proc_handler = &proc_dointvec,
887 .ctl_name = FS_AIO_NR,
888 .procname = "aio-nr",
889 .data = &aio_nr,
890 .maxlen = sizeof(aio_nr),
891 .mode = 0444,
892 .proc_handler = &proc_dointvec,
895 .ctl_name = FS_AIO_MAX_NR,
896 .procname = "aio-max-nr",
897 .data = &aio_max_nr,
898 .maxlen = sizeof(aio_max_nr),
899 .mode = 0644,
900 .proc_handler = &proc_dointvec,
902 { .ctl_name = 0 }
905 static ctl_table debug_table[] = {
906 { .ctl_name = 0 }
909 static ctl_table dev_table[] = {
910 { .ctl_name = 0 }
913 extern void init_irq_proc (void);
915 void __init sysctl_init(void)
917 #ifdef CONFIG_PROC_FS
918 register_proc_table(root_table, proc_sys_root);
919 init_irq_proc();
920 #endif
923 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
924 void __user *newval, size_t newlen)
926 struct list_head *tmp;
928 if (nlen <= 0 || nlen >= CTL_MAXNAME)
929 return -ENOTDIR;
930 if (oldval) {
931 int old_len;
932 if (!oldlenp || get_user(old_len, oldlenp))
933 return -EFAULT;
935 tmp = &root_table_header.ctl_entry;
936 do {
937 struct ctl_table_header *head =
938 list_entry(tmp, struct ctl_table_header, ctl_entry);
939 void *context = NULL;
940 int error = parse_table(name, nlen, oldval, oldlenp,
941 newval, newlen, head->ctl_table,
942 &context);
943 if (context)
944 kfree(context);
945 if (error != -ENOTDIR)
946 return error;
947 tmp = tmp->next;
948 } while (tmp != &root_table_header.ctl_entry);
949 return -ENOTDIR;
952 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
954 struct __sysctl_args tmp;
955 int error;
957 if (copy_from_user(&tmp, args, sizeof(tmp)))
958 return -EFAULT;
960 lock_kernel();
961 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
962 tmp.newval, tmp.newlen);
963 unlock_kernel();
964 return error;
968 * ctl_perm does NOT grant the superuser all rights automatically, because
969 * some sysctl variables are readonly even to root.
972 static int test_perm(int mode, int op)
974 if (!current->euid)
975 mode >>= 6;
976 else if (in_egroup_p(0))
977 mode >>= 3;
978 if ((mode & op & 0007) == op)
979 return 0;
980 return -EACCES;
983 static inline int ctl_perm(ctl_table *table, int op)
985 int error;
986 error = security_sysctl(table, op);
987 if (error)
988 return error;
989 return test_perm(table->mode, op);
992 static int parse_table(int __user *name, int nlen,
993 void __user *oldval, size_t __user *oldlenp,
994 void __user *newval, size_t newlen,
995 ctl_table *table, void **context)
997 int n;
998 repeat:
999 if (!nlen)
1000 return -ENOTDIR;
1001 if (get_user(n, name))
1002 return -EFAULT;
1003 for ( ; table->ctl_name; table++) {
1004 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1005 int error;
1006 if (table->child) {
1007 if (ctl_perm(table, 001))
1008 return -EPERM;
1009 if (table->strategy) {
1010 error = table->strategy(
1011 table, name, nlen,
1012 oldval, oldlenp,
1013 newval, newlen, context);
1014 if (error)
1015 return error;
1017 name++;
1018 nlen--;
1019 table = table->child;
1020 goto repeat;
1022 error = do_sysctl_strategy(table, name, nlen,
1023 oldval, oldlenp,
1024 newval, newlen, context);
1025 return error;
1028 return -ENOTDIR;
1031 /* Perform the actual read/write of a sysctl table entry. */
1032 int do_sysctl_strategy (ctl_table *table,
1033 int __user *name, int nlen,
1034 void __user *oldval, size_t __user *oldlenp,
1035 void __user *newval, size_t newlen, void **context)
1037 int op = 0, rc;
1038 size_t len;
1040 if (oldval)
1041 op |= 004;
1042 if (newval)
1043 op |= 002;
1044 if (ctl_perm(table, op))
1045 return -EPERM;
1047 if (table->strategy) {
1048 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1049 newval, newlen, context);
1050 if (rc < 0)
1051 return rc;
1052 if (rc > 0)
1053 return 0;
1056 /* If there is no strategy routine, or if the strategy returns
1057 * zero, proceed with automatic r/w */
1058 if (table->data && table->maxlen) {
1059 if (oldval && oldlenp) {
1060 if (get_user(len, oldlenp))
1061 return -EFAULT;
1062 if (len) {
1063 if (len > table->maxlen)
1064 len = table->maxlen;
1065 if(copy_to_user(oldval, table->data, len))
1066 return -EFAULT;
1067 if(put_user(len, oldlenp))
1068 return -EFAULT;
1071 if (newval && newlen) {
1072 len = newlen;
1073 if (len > table->maxlen)
1074 len = table->maxlen;
1075 if(copy_from_user(table->data, newval, len))
1076 return -EFAULT;
1079 return 0;
1083 * register_sysctl_table - register a sysctl hierarchy
1084 * @table: the top-level table structure
1085 * @insert_at_head: whether the entry should be inserted in front or at the end
1087 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1088 * array. An entry with a ctl_name of 0 terminates the table.
1090 * The members of the &ctl_table structure are used as follows:
1092 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1093 * must be unique within that level of sysctl
1095 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1096 * enter a sysctl file
1098 * data - a pointer to data for use by proc_handler
1100 * maxlen - the maximum size in bytes of the data
1102 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1104 * child - a pointer to the child sysctl table if this entry is a directory, or
1105 * %NULL.
1107 * proc_handler - the text handler routine (described below)
1109 * strategy - the strategy routine (described below)
1111 * de - for internal use by the sysctl routines
1113 * extra1, extra2 - extra pointers usable by the proc handler routines
1115 * Leaf nodes in the sysctl tree will be represented by a single file
1116 * under /proc; non-leaf nodes will be represented by directories.
1118 * sysctl(2) can automatically manage read and write requests through
1119 * the sysctl table. The data and maxlen fields of the ctl_table
1120 * struct enable minimal validation of the values being written to be
1121 * performed, and the mode field allows minimal authentication.
1123 * More sophisticated management can be enabled by the provision of a
1124 * strategy routine with the table entry. This will be called before
1125 * any automatic read or write of the data is performed.
1127 * The strategy routine may return
1129 * < 0 - Error occurred (error is passed to user process)
1131 * 0 - OK - proceed with automatic read or write.
1133 * > 0 - OK - read or write has been done by the strategy routine, so
1134 * return immediately.
1136 * There must be a proc_handler routine for any terminal nodes
1137 * mirrored under /proc/sys (non-terminals are handled by a built-in
1138 * directory handler). Several default handlers are available to
1139 * cover common cases -
1141 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1142 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1143 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1145 * It is the handler's job to read the input buffer from user memory
1146 * and process it. The handler should return 0 on success.
1148 * This routine returns %NULL on a failure to register, and a pointer
1149 * to the table header on success.
1151 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1152 int insert_at_head)
1154 struct ctl_table_header *tmp;
1155 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1156 if (!tmp)
1157 return NULL;
1158 tmp->ctl_table = table;
1159 INIT_LIST_HEAD(&tmp->ctl_entry);
1160 if (insert_at_head)
1161 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1162 else
1163 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1164 #ifdef CONFIG_PROC_FS
1165 register_proc_table(table, proc_sys_root);
1166 #endif
1167 return tmp;
1171 * unregister_sysctl_table - unregister a sysctl table hierarchy
1172 * @header: the header returned from register_sysctl_table
1174 * Unregisters the sysctl table and all children. proc entries may not
1175 * actually be removed until they are no longer used by anyone.
1177 void unregister_sysctl_table(struct ctl_table_header * header)
1179 list_del(&header->ctl_entry);
1180 #ifdef CONFIG_PROC_FS
1181 unregister_proc_table(header->ctl_table, proc_sys_root);
1182 #endif
1183 kfree(header);
1187 * /proc/sys support
1190 #ifdef CONFIG_PROC_FS
1192 /* Scan the sysctl entries in table and add them all into /proc */
1193 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1195 struct proc_dir_entry *de;
1196 int len;
1197 mode_t mode;
1199 for (; table->ctl_name; table++) {
1200 /* Can't do anything without a proc name. */
1201 if (!table->procname)
1202 continue;
1203 /* Maybe we can't do anything with it... */
1204 if (!table->proc_handler && !table->child) {
1205 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1206 table->procname);
1207 continue;
1210 len = strlen(table->procname);
1211 mode = table->mode;
1213 de = NULL;
1214 if (table->proc_handler)
1215 mode |= S_IFREG;
1216 else {
1217 mode |= S_IFDIR;
1218 for (de = root->subdir; de; de = de->next) {
1219 if (proc_match(len, table->procname, de))
1220 break;
1222 /* If the subdir exists already, de is non-NULL */
1225 if (!de) {
1226 de = create_proc_entry(table->procname, mode, root);
1227 if (!de)
1228 continue;
1229 de->data = (void *) table;
1230 if (table->proc_handler)
1231 de->proc_fops = &proc_sys_file_operations;
1233 table->de = de;
1234 if (de->mode & S_IFDIR)
1235 register_proc_table(table->child, de);
1240 * Unregister a /proc sysctl table and any subdirectories.
1242 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1244 struct proc_dir_entry *de;
1245 for (; table->ctl_name; table++) {
1246 if (!(de = table->de))
1247 continue;
1248 if (de->mode & S_IFDIR) {
1249 if (!table->child) {
1250 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1251 continue;
1253 unregister_proc_table(table->child, de);
1255 /* Don't unregister directories which still have entries.. */
1256 if (de->subdir)
1257 continue;
1260 /* Don't unregister proc entries that are still being used.. */
1261 if (atomic_read(&de->count))
1262 continue;
1264 table->de = NULL;
1265 remove_proc_entry(table->procname, root);
1269 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1270 size_t count, loff_t *ppos)
1272 int op;
1273 struct proc_dir_entry *de;
1274 struct ctl_table *table;
1275 size_t res;
1276 ssize_t error;
1278 de = PDE(file->f_dentry->d_inode);
1279 if (!de || !de->data)
1280 return -ENOTDIR;
1281 table = (struct ctl_table *) de->data;
1282 if (!table || !table->proc_handler)
1283 return -ENOTDIR;
1284 op = (write ? 002 : 004);
1285 if (ctl_perm(table, op))
1286 return -EPERM;
1288 res = count;
1291 * FIXME: we need to pass on ppos to the handler.
1294 error = (*table->proc_handler) (table, write, file, buf, &res);
1295 if (error)
1296 return error;
1297 return res;
1300 static int proc_opensys(struct inode *inode, struct file *file)
1302 if (file->f_mode & FMODE_WRITE) {
1304 * sysctl entries that are not writable,
1305 * are _NOT_ writable, capabilities or not.
1307 if (!(inode->i_mode & S_IWUSR))
1308 return -EPERM;
1311 return 0;
1314 static ssize_t proc_readsys(struct file * file, char __user * buf,
1315 size_t count, loff_t *ppos)
1317 return do_rw_proc(0, file, buf, count, ppos);
1320 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1321 size_t count, loff_t *ppos)
1323 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1327 * proc_dostring - read a string sysctl
1328 * @table: the sysctl table
1329 * @write: %TRUE if this is a write to the sysctl file
1330 * @filp: the file structure
1331 * @buffer: the user buffer
1332 * @lenp: the size of the user buffer
1334 * Reads/writes a string from/to the user buffer. If the kernel
1335 * buffer provided is not large enough to hold the string, the
1336 * string is truncated. The copied string is %NULL-terminated.
1337 * If the string is being read by the user process, it is copied
1338 * and a newline '\n' is added. It is truncated if the buffer is
1339 * not large enough.
1341 * Returns 0 on success.
1343 int proc_dostring(ctl_table *table, int write, struct file *filp,
1344 void __user *buffer, size_t *lenp)
1346 size_t len;
1347 char __user *p;
1348 char c;
1350 if (!table->data || !table->maxlen || !*lenp ||
1351 (filp->f_pos && !write)) {
1352 *lenp = 0;
1353 return 0;
1356 if (write) {
1357 len = 0;
1358 p = buffer;
1359 while (len < *lenp) {
1360 if (get_user(c, p++))
1361 return -EFAULT;
1362 if (c == 0 || c == '\n')
1363 break;
1364 len++;
1366 if (len >= table->maxlen)
1367 len = table->maxlen-1;
1368 if(copy_from_user(table->data, buffer, len))
1369 return -EFAULT;
1370 ((char *) table->data)[len] = 0;
1371 filp->f_pos += *lenp;
1372 } else {
1373 len = strlen(table->data);
1374 if (len > table->maxlen)
1375 len = table->maxlen;
1376 if (len > *lenp)
1377 len = *lenp;
1378 if (len)
1379 if(copy_to_user(buffer, table->data, len))
1380 return -EFAULT;
1381 if (len < *lenp) {
1382 if(put_user('\n', ((char __user *) buffer) + len))
1383 return -EFAULT;
1384 len++;
1386 *lenp = len;
1387 filp->f_pos += len;
1389 return 0;
1393 * Special case of dostring for the UTS structure. This has locks
1394 * to observe. Should this be in kernel/sys.c ????
1397 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1398 void __user *buffer, size_t *lenp)
1400 int r;
1402 if (!write) {
1403 down_read(&uts_sem);
1404 r=proc_dostring(table,0,filp,buffer,lenp);
1405 up_read(&uts_sem);
1406 } else {
1407 down_write(&uts_sem);
1408 r=proc_dostring(table,1,filp,buffer,lenp);
1409 up_write(&uts_sem);
1411 return r;
1414 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1415 int *valp,
1416 int write, void *data)
1418 if (write) {
1419 *valp = *negp ? -*lvalp : *lvalp;
1420 } else {
1421 int val = *valp;
1422 if (val < 0) {
1423 *negp = -1;
1424 *lvalp = (unsigned long)-val;
1425 } else {
1426 *negp = 0;
1427 *lvalp = (unsigned long)val;
1430 return 0;
1433 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1434 void __user *buffer, size_t *lenp,
1435 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1436 int write, void *data),
1437 void *data)
1439 #define TMPBUFLEN 20
1440 int *i, vleft, first=1, neg, val;
1441 unsigned long lval;
1442 size_t left, len;
1444 char buf[TMPBUFLEN], *p;
1445 char __user *s = buffer;
1447 if (!table->data || !table->maxlen || !*lenp ||
1448 (filp->f_pos && !write)) {
1449 *lenp = 0;
1450 return 0;
1453 i = (int *) table->data;
1454 vleft = table->maxlen / sizeof(*i);
1455 left = *lenp;
1457 if (!conv)
1458 conv = do_proc_dointvec_conv;
1460 for (; left && vleft--; i++, first=0) {
1461 if (write) {
1462 while (left) {
1463 char c;
1464 if (get_user(c, s))
1465 return -EFAULT;
1466 if (!isspace(c))
1467 break;
1468 left--;
1469 s++;
1471 if (!left)
1472 break;
1473 neg = 0;
1474 len = left;
1475 if (len > sizeof(buf) - 1)
1476 len = sizeof(buf) - 1;
1477 if (copy_from_user(buf, s, len))
1478 return -EFAULT;
1479 buf[len] = 0;
1480 p = buf;
1481 if (*p == '-' && left > 1) {
1482 neg = 1;
1483 left--, p++;
1485 if (*p < '0' || *p > '9')
1486 break;
1488 lval = simple_strtoul(p, &p, 0);
1490 len = p-buf;
1491 if ((len < left) && *p && !isspace(*p))
1492 break;
1493 if (neg)
1494 val = -val;
1495 s += len;
1496 left -= len;
1498 if (conv(&neg, &lval, i, 1, data))
1499 break;
1500 } else {
1501 p = buf;
1502 if (!first)
1503 *p++ = '\t';
1505 if (conv(&neg, &lval, i, 0, data))
1506 break;
1508 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1509 len = strlen(buf);
1510 if (len > left)
1511 len = left;
1512 if(copy_to_user(s, buf, len))
1513 return -EFAULT;
1514 left -= len;
1515 s += len;
1519 if (!write && !first && left) {
1520 if(put_user('\n', s))
1521 return -EFAULT;
1522 left--, s++;
1524 if (write) {
1525 while (left) {
1526 char c;
1527 if (get_user(c, s++))
1528 return -EFAULT;
1529 if (!isspace(c))
1530 break;
1531 left--;
1534 if (write && first)
1535 return -EINVAL;
1536 *lenp -= left;
1537 filp->f_pos += *lenp;
1538 return 0;
1539 #undef TMPBUFLEN
1543 * proc_dointvec - read a vector of integers
1544 * @table: the sysctl table
1545 * @write: %TRUE if this is a write to the sysctl file
1546 * @filp: the file structure
1547 * @buffer: the user buffer
1548 * @lenp: the size of the user buffer
1550 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1551 * values from/to the user buffer, treated as an ASCII string.
1553 * Returns 0 on success.
1555 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1556 void __user *buffer, size_t *lenp)
1558 return do_proc_dointvec(table,write,filp,buffer,lenp,
1559 NULL,NULL);
1562 #define OP_SET 0
1563 #define OP_AND 1
1564 #define OP_OR 2
1565 #define OP_MAX 3
1566 #define OP_MIN 4
1568 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1569 int *valp,
1570 int write, void *data)
1572 int op = *(int *)data;
1573 if (write) {
1574 int val = *negp ? -*lvalp : *lvalp;
1575 switch(op) {
1576 case OP_SET: *valp = val; break;
1577 case OP_AND: *valp &= val; break;
1578 case OP_OR: *valp |= val; break;
1579 case OP_MAX: if(*valp < val)
1580 *valp = val;
1581 break;
1582 case OP_MIN: if(*valp > val)
1583 *valp = val;
1584 break;
1586 } else {
1587 int val = *valp;
1588 if (val < 0) {
1589 *negp = -1;
1590 *lvalp = (unsigned long)-val;
1591 } else {
1592 *negp = 0;
1593 *lvalp = (unsigned long)val;
1596 return 0;
1600 * init may raise the set.
1603 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1604 void __user *buffer, size_t *lenp)
1606 int op;
1608 if (!capable(CAP_SYS_MODULE)) {
1609 return -EPERM;
1612 op = (current->pid == 1) ? OP_SET : OP_AND;
1613 return do_proc_dointvec(table,write,filp,buffer,lenp,
1614 do_proc_dointvec_bset_conv,&op);
1617 struct do_proc_dointvec_minmax_conv_param {
1618 int *min;
1619 int *max;
1622 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1623 int *valp,
1624 int write, void *data)
1626 struct do_proc_dointvec_minmax_conv_param *param = data;
1627 if (write) {
1628 int val = *negp ? -*lvalp : *lvalp;
1629 if ((param->min && *param->min > val) ||
1630 (param->max && *param->max < val))
1631 return -EINVAL;
1632 *valp = val;
1633 } else {
1634 int val = *valp;
1635 if (val < 0) {
1636 *negp = -1;
1637 *lvalp = (unsigned long)-val;
1638 } else {
1639 *negp = 0;
1640 *lvalp = (unsigned long)val;
1643 return 0;
1647 * proc_dointvec_minmax - read a vector of integers with min/max values
1648 * @table: the sysctl table
1649 * @write: %TRUE if this is a write to the sysctl file
1650 * @filp: the file structure
1651 * @buffer: the user buffer
1652 * @lenp: the size of the user buffer
1654 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1655 * values from/to the user buffer, treated as an ASCII string.
1657 * This routine will ensure the values are within the range specified by
1658 * table->extra1 (min) and table->extra2 (max).
1660 * Returns 0 on success.
1662 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1663 void __user *buffer, size_t *lenp)
1665 struct do_proc_dointvec_minmax_conv_param param = {
1666 .min = (int *) table->extra1,
1667 .max = (int *) table->extra2,
1669 return do_proc_dointvec(table, write, filp, buffer, lenp,
1670 do_proc_dointvec_minmax_conv, &param);
1673 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1674 struct file *filp,
1675 void __user *buffer, size_t *lenp,
1676 unsigned long convmul,
1677 unsigned long convdiv)
1679 #define TMPBUFLEN 20
1680 unsigned long *i, *min, *max, val;
1681 int vleft, first=1, neg;
1682 size_t len, left;
1683 char buf[TMPBUFLEN], *p;
1684 char __user *s = buffer;
1686 if (!table->data || !table->maxlen || !*lenp ||
1687 (filp->f_pos && !write)) {
1688 *lenp = 0;
1689 return 0;
1692 i = (unsigned long *) table->data;
1693 min = (unsigned long *) table->extra1;
1694 max = (unsigned long *) table->extra2;
1695 vleft = table->maxlen / sizeof(unsigned long);
1696 left = *lenp;
1698 for (; left && vleft--; i++, min++, max++, first=0) {
1699 if (write) {
1700 while (left) {
1701 char c;
1702 if (get_user(c, s))
1703 return -EFAULT;
1704 if (!isspace(c))
1705 break;
1706 left--;
1707 s++;
1709 if (!left)
1710 break;
1711 neg = 0;
1712 len = left;
1713 if (len > TMPBUFLEN-1)
1714 len = TMPBUFLEN-1;
1715 if (copy_from_user(buf, s, len))
1716 return -EFAULT;
1717 buf[len] = 0;
1718 p = buf;
1719 if (*p == '-' && left > 1) {
1720 neg = 1;
1721 left--, p++;
1723 if (*p < '0' || *p > '9')
1724 break;
1725 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1726 len = p-buf;
1727 if ((len < left) && *p && !isspace(*p))
1728 break;
1729 if (neg)
1730 val = -val;
1731 s += len;
1732 left -= len;
1734 if(neg)
1735 continue;
1736 if ((min && val < *min) || (max && val > *max))
1737 continue;
1738 *i = val;
1739 } else {
1740 p = buf;
1741 if (!first)
1742 *p++ = '\t';
1743 sprintf(p, "%lu", convdiv * (*i) / convmul);
1744 len = strlen(buf);
1745 if (len > left)
1746 len = left;
1747 if(copy_to_user(s, buf, len))
1748 return -EFAULT;
1749 left -= len;
1750 s += len;
1754 if (!write && !first && left) {
1755 if(put_user('\n', s))
1756 return -EFAULT;
1757 left--, s++;
1759 if (write) {
1760 while (left) {
1761 char c;
1762 if (get_user(c, s++))
1763 return -EFAULT;
1764 if (!isspace(c))
1765 break;
1766 left--;
1769 if (write && first)
1770 return -EINVAL;
1771 *lenp -= left;
1772 filp->f_pos += *lenp;
1773 return 0;
1774 #undef TMPBUFLEN
1778 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1779 * @table: the sysctl table
1780 * @write: %TRUE if this is a write to the sysctl file
1781 * @filp: the file structure
1782 * @buffer: the user buffer
1783 * @lenp: the size of the user buffer
1785 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1786 * values from/to the user buffer, treated as an ASCII string.
1788 * This routine will ensure the values are within the range specified by
1789 * table->extra1 (min) and table->extra2 (max).
1791 * Returns 0 on success.
1793 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1794 void __user *buffer, size_t *lenp)
1796 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, 1l, 1l);
1800 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1801 * @table: the sysctl table
1802 * @write: %TRUE if this is a write to the sysctl file
1803 * @filp: the file structure
1804 * @buffer: the user buffer
1805 * @lenp: the size of the user buffer
1807 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1808 * values from/to the user buffer, treated as an ASCII string. The values
1809 * are treated as milliseconds, and converted to jiffies when they are stored.
1811 * This routine will ensure the values are within the range specified by
1812 * table->extra1 (min) and table->extra2 (max).
1814 * Returns 0 on success.
1816 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1817 struct file *filp,
1818 void __user *buffer, size_t *lenp)
1820 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1821 lenp, HZ, 1000l);
1825 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1826 int *valp,
1827 int write, void *data)
1829 if (write) {
1830 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1831 } else {
1832 int val = *valp;
1833 unsigned long lval;
1834 if (val < 0) {
1835 *negp = -1;
1836 lval = (unsigned long)-val;
1837 } else {
1838 *negp = 0;
1839 lval = (unsigned long)val;
1841 *lvalp = lval / HZ;
1843 return 0;
1846 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1847 int *valp,
1848 int write, void *data)
1850 if (write) {
1851 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1852 } else {
1853 int val = *valp;
1854 unsigned long lval;
1855 if (val < 0) {
1856 *negp = -1;
1857 lval = (unsigned long)-val;
1858 } else {
1859 *negp = 0;
1860 lval = (unsigned long)val;
1862 *lvalp = jiffies_to_clock_t(lval);
1864 return 0;
1868 * proc_dointvec_jiffies - read a vector of integers as seconds
1869 * @table: the sysctl table
1870 * @write: %TRUE if this is a write to the sysctl file
1871 * @filp: the file structure
1872 * @buffer: the user buffer
1873 * @lenp: the size of the user buffer
1875 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1876 * values from/to the user buffer, treated as an ASCII string.
1877 * The values read are assumed to be in seconds, and are converted into
1878 * jiffies.
1880 * Returns 0 on success.
1882 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1883 void __user *buffer, size_t *lenp)
1885 return do_proc_dointvec(table,write,filp,buffer,lenp,
1886 do_proc_dointvec_jiffies_conv,NULL);
1890 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1891 * @table: the sysctl table
1892 * @write: %TRUE if this is a write to the sysctl file
1893 * @filp: the file structure
1894 * @buffer: the user buffer
1895 * @lenp: the size of the user buffer
1897 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1898 * values from/to the user buffer, treated as an ASCII string.
1899 * The values read are assumed to be in 1/USER_HZ seconds, and
1900 * are converted into jiffies.
1902 * Returns 0 on success.
1904 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1905 void __user *buffer, size_t *lenp)
1907 return do_proc_dointvec(table,write,filp,buffer,lenp,
1908 do_proc_dointvec_userhz_jiffies_conv,NULL);
1911 #else /* CONFIG_PROC_FS */
1913 int proc_dostring(ctl_table *table, int write, struct file *filp,
1914 void __user *buffer, size_t *lenp)
1916 return -ENOSYS;
1919 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1920 void __user *buffer, size_t *lenp)
1922 return -ENOSYS;
1925 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1926 void __user *buffer, size_t *lenp)
1928 return -ENOSYS;
1931 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1932 void __user *buffer, size_t *lenp)
1934 return -ENOSYS;
1937 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1938 void __user *buffer, size_t *lenp)
1940 return -ENOSYS;
1943 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1944 void __user *buffer, size_t *lenp)
1946 return -ENOSYS;
1949 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1950 void __user *buffer, size_t *lenp)
1952 return -ENOSYS;
1955 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1956 void __user *buffer, size_t *lenp)
1958 return -ENOSYS;
1961 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1962 struct file *filp,
1963 void __user *buffer, size_t *lenp)
1965 return -ENOSYS;
1969 #endif /* CONFIG_PROC_FS */
1973 * General sysctl support routines
1976 /* The generic string strategy routine: */
1977 int sysctl_string(ctl_table *table, int __user *name, int nlen,
1978 void __user *oldval, size_t __user *oldlenp,
1979 void __user *newval, size_t newlen, void **context)
1981 size_t l, len;
1983 if (!table->data || !table->maxlen)
1984 return -ENOTDIR;
1986 if (oldval && oldlenp) {
1987 if (get_user(len, oldlenp))
1988 return -EFAULT;
1989 if (len) {
1990 l = strlen(table->data);
1991 if (len > l) len = l;
1992 if (len >= table->maxlen)
1993 len = table->maxlen;
1994 if(copy_to_user(oldval, table->data, len))
1995 return -EFAULT;
1996 if(put_user(0, ((char __user *) oldval) + len))
1997 return -EFAULT;
1998 if(put_user(len, oldlenp))
1999 return -EFAULT;
2002 if (newval && newlen) {
2003 len = newlen;
2004 if (len > table->maxlen)
2005 len = table->maxlen;
2006 if(copy_from_user(table->data, newval, len))
2007 return -EFAULT;
2008 if (len == table->maxlen)
2009 len--;
2010 ((char *) table->data)[len] = 0;
2012 return 0;
2016 * This function makes sure that all of the integers in the vector
2017 * are between the minimum and maximum values given in the arrays
2018 * table->extra1 and table->extra2, respectively.
2020 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2021 void __user *oldval, size_t __user *oldlenp,
2022 void __user *newval, size_t newlen, void **context)
2025 if (newval && newlen) {
2026 int __user *vec = (int __user *) newval;
2027 int *min = (int *) table->extra1;
2028 int *max = (int *) table->extra2;
2029 size_t length;
2030 int i;
2032 if (newlen % sizeof(int) != 0)
2033 return -EINVAL;
2035 if (!table->extra1 && !table->extra2)
2036 return 0;
2038 if (newlen > table->maxlen)
2039 newlen = table->maxlen;
2040 length = newlen / sizeof(int);
2042 for (i = 0; i < length; i++) {
2043 int value;
2044 if (get_user(value, vec + i))
2045 return -EFAULT;
2046 if (min && value < min[i])
2047 return -EINVAL;
2048 if (max && value > max[i])
2049 return -EINVAL;
2052 return 0;
2055 /* Strategy function to convert jiffies to seconds */
2056 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2057 void __user *oldval, size_t __user *oldlenp,
2058 void __user *newval, size_t newlen, void **context)
2060 if (oldval) {
2061 size_t olen;
2062 if (oldlenp) {
2063 if (get_user(olen, oldlenp))
2064 return -EFAULT;
2065 if (olen!=sizeof(int))
2066 return -EINVAL;
2068 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2069 (oldlenp && put_user(sizeof(int),oldlenp)))
2070 return -EFAULT;
2072 if (newval && newlen) {
2073 int new;
2074 if (newlen != sizeof(int))
2075 return -EINVAL;
2076 if (get_user(new, (int __user *)newval))
2077 return -EFAULT;
2078 *(int *)(table->data) = new*HZ;
2080 return 1;
2084 #else /* CONFIG_SYSCTL */
2087 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2089 return -ENOSYS;
2092 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2093 void __user *oldval, size_t __user *oldlenp,
2094 void __user *newval, size_t newlen, void **context)
2096 return -ENOSYS;
2099 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2100 void __user *oldval, size_t __user *oldlenp,
2101 void __user *newval, size_t newlen, void **context)
2103 return -ENOSYS;
2106 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2107 void __user *oldval, size_t __user *oldlenp,
2108 void __user *newval, size_t newlen, void **context)
2110 return -ENOSYS;
2113 int proc_dostring(ctl_table *table, int write, struct file *filp,
2114 void __user *buffer, size_t *lenp)
2116 return -ENOSYS;
2119 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2120 void __user *buffer, size_t *lenp)
2122 return -ENOSYS;
2125 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2126 void __user *buffer, size_t *lenp)
2128 return -ENOSYS;
2131 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2132 void __user *buffer, size_t *lenp)
2134 return -ENOSYS;
2137 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2138 void __user *buffer, size_t *lenp)
2140 return -ENOSYS;
2143 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2144 void __user *buffer, size_t *lenp)
2146 return -ENOSYS;
2149 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2150 void __user *buffer, size_t *lenp)
2152 return -ENOSYS;
2155 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2156 struct file *filp,
2157 void __user *buffer, size_t *lenp)
2159 return -ENOSYS;
2162 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2163 int insert_at_head)
2165 return NULL;
2168 void unregister_sysctl_table(struct ctl_table_header * table)
2172 #endif /* CONFIG_SYSCTL */
2175 * No sense putting this after each symbol definition, twice,
2176 * exception granted :-)
2178 EXPORT_SYMBOL(proc_dointvec);
2179 EXPORT_SYMBOL(proc_dointvec_jiffies);
2180 EXPORT_SYMBOL(proc_dointvec_minmax);
2181 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2182 EXPORT_SYMBOL(proc_dostring);
2183 EXPORT_SYMBOL(proc_doulongvec_minmax);
2184 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2185 EXPORT_SYMBOL(register_sysctl_table);
2186 EXPORT_SYMBOL(sysctl_intvec);
2187 EXPORT_SYMBOL(sysctl_jiffies);
2188 EXPORT_SYMBOL(sysctl_string);
2189 EXPORT_SYMBOL(unregister_sysctl_table);