[PATCH] Fix up 'linux-dvb' maintainers entry
[linux-2.6/history.git] / kernel / sysctl.c
blob059bd643f39fd383d6392bccf42459f2175912c2
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 <asm/uaccess.h>
43 #ifdef CONFIG_ROOT_NFS
44 #include <linux/nfs_fs.h>
45 #endif
47 #if defined(CONFIG_SYSCTL)
49 /* External variables not in a header file. */
50 extern int panic_timeout;
51 extern int C_A_D;
52 extern int sysctl_overcommit_memory;
53 extern int sysctl_overcommit_ratio;
54 extern int max_threads;
55 extern atomic_t nr_queued_signals;
56 extern int max_queued_signals;
57 extern int sysrq_enabled;
58 extern int core_uses_pid;
59 extern char core_pattern[];
60 extern int cad_pid;
61 extern int pid_max;
62 extern int sysctl_lower_zone_protection;
63 extern int min_free_kbytes;
64 extern int printk_ratelimit_jiffies;
65 extern int printk_ratelimit_burst;
67 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
68 static int maxolduid = 65535;
69 static int minolduid;
71 #ifdef CONFIG_KMOD
72 extern char modprobe_path[];
73 #endif
74 #ifdef CONFIG_HOTPLUG
75 extern char hotplug_path[];
76 #endif
77 #ifdef CONFIG_CHR_DEV_SG
78 extern int sg_big_buff;
79 #endif
80 #ifdef CONFIG_SYSVIPC
81 extern size_t shm_ctlmax;
82 extern size_t shm_ctlall;
83 extern int shm_ctlmni;
84 extern int msg_ctlmax;
85 extern int msg_ctlmnb;
86 extern int msg_ctlmni;
87 extern int sem_ctls[];
88 #endif
90 #ifdef __sparc__
91 extern char reboot_command [];
92 extern int stop_a_enabled;
93 #endif
95 #ifdef __hppa__
96 extern int pwrsw_enabled;
97 extern int unaligned_enabled;
98 #endif
100 #ifdef CONFIG_ARCH_S390
101 #ifdef CONFIG_MATHEMU
102 extern int sysctl_ieee_emulation_warnings;
103 #endif
104 extern int sysctl_userprocess_debug;
105 #endif
107 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
108 extern unsigned long powersave_nap;
109 int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
110 void *buffer, size_t *lenp);
111 #endif
113 #ifdef CONFIG_BSD_PROCESS_ACCT
114 extern int acct_parm[];
115 #endif
117 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
118 ctl_table *, void **);
119 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
120 void __user *buffer, size_t *lenp);
122 static ctl_table root_table[];
123 static struct ctl_table_header root_table_header =
124 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
126 static ctl_table kern_table[];
127 static ctl_table vm_table[];
128 #ifdef CONFIG_NET
129 extern ctl_table net_table[];
130 #endif
131 static ctl_table proc_table[];
132 static ctl_table fs_table[];
133 static ctl_table debug_table[];
134 static ctl_table dev_table[];
135 extern ctl_table random_table[];
137 /* /proc declarations: */
139 #ifdef CONFIG_PROC_FS
141 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
142 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
143 static int proc_opensys(struct inode *, struct file *);
145 struct file_operations proc_sys_file_operations = {
146 .open = proc_opensys,
147 .read = proc_readsys,
148 .write = proc_writesys,
151 extern struct proc_dir_entry *proc_sys_root;
153 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
154 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
155 #endif
157 /* The default sysctl tables: */
159 static ctl_table root_table[] = {
161 .ctl_name = CTL_KERN,
162 .procname = "kernel",
163 .mode = 0555,
164 .child = kern_table,
167 .ctl_name = CTL_VM,
168 .procname = "vm",
169 .mode = 0555,
170 .child = vm_table,
172 #ifdef CONFIG_NET
174 .ctl_name = CTL_NET,
175 .procname = "net",
176 .mode = 0555,
177 .child = net_table,
179 #endif
181 .ctl_name = CTL_PROC,
182 .procname = "proc",
183 .mode = 0555,
184 .child = proc_table,
187 .ctl_name = CTL_FS,
188 .procname = "fs",
189 .mode = 0555,
190 .child = fs_table,
193 .ctl_name = CTL_DEBUG,
194 .procname = "debug",
195 .mode = 0555,
196 .child = debug_table,
199 .ctl_name = CTL_DEV,
200 .procname = "dev",
201 .mode = 0555,
202 .child = dev_table,
204 { .ctl_name = 0 }
207 static ctl_table kern_table[] = {
209 .ctl_name = KERN_OSTYPE,
210 .procname = "ostype",
211 .data = system_utsname.sysname,
212 .maxlen = 64,
213 .mode = 0444,
214 .proc_handler = &proc_doutsstring,
215 .strategy = &sysctl_string,
218 .ctl_name = KERN_OSRELEASE,
219 .procname = "osrelease",
220 .data = system_utsname.release,
221 .maxlen = 64,
222 .mode = 0444,
223 .proc_handler = &proc_doutsstring,
224 .strategy = &sysctl_string,
227 .ctl_name = KERN_VERSION,
228 .procname = "version",
229 .data = system_utsname.version,
230 .maxlen = 64,
231 .mode = 0444,
232 .proc_handler = &proc_doutsstring,
233 .strategy = &sysctl_string,
236 .ctl_name = KERN_NODENAME,
237 .procname = "hostname",
238 .data = system_utsname.nodename,
239 .maxlen = 64,
240 .mode = 0644,
241 .proc_handler = &proc_doutsstring,
242 .strategy = &sysctl_string,
245 .ctl_name = KERN_DOMAINNAME,
246 .procname = "domainname",
247 .data = system_utsname.domainname,
248 .maxlen = 64,
249 .mode = 0644,
250 .proc_handler = &proc_doutsstring,
251 .strategy = &sysctl_string,
254 .ctl_name = KERN_PANIC,
255 .procname = "panic",
256 .data = &panic_timeout,
257 .maxlen = sizeof(int),
258 .mode = 0644,
259 .proc_handler = &proc_dointvec,
262 .ctl_name = KERN_CORE_USES_PID,
263 .procname = "core_uses_pid",
264 .data = &core_uses_pid,
265 .maxlen = sizeof(int),
266 .mode = 0644,
267 .proc_handler = &proc_dointvec,
270 .ctl_name = KERN_CORE_PATTERN,
271 .procname = "core_pattern",
272 .data = core_pattern,
273 .maxlen = 64,
274 .mode = 0644,
275 .proc_handler = &proc_dostring,
276 .strategy = &sysctl_string,
279 .ctl_name = KERN_TAINTED,
280 .procname = "tainted",
281 .data = &tainted,
282 .maxlen = sizeof(int),
283 .mode = 0644,
284 .proc_handler = &proc_dointvec,
287 .ctl_name = KERN_CAP_BSET,
288 .procname = "cap-bound",
289 .data = &cap_bset,
290 .maxlen = sizeof(kernel_cap_t),
291 .mode = 0600,
292 .proc_handler = &proc_dointvec_bset,
294 #ifdef CONFIG_BLK_DEV_INITRD
296 .ctl_name = KERN_REALROOTDEV,
297 .procname = "real-root-dev",
298 .data = &real_root_dev,
299 .maxlen = sizeof(int),
300 .mode = 0644,
301 .proc_handler = &proc_dointvec,
303 #endif
304 #ifdef __sparc__
306 .ctl_name = KERN_SPARC_REBOOT,
307 .procname = "reboot-cmd",
308 .data = reboot_command,
309 .maxlen = 256,
310 .mode = 0644,
311 .proc_handler = &proc_dostring,
312 .strategy = &sysctl_string,
315 .ctl_name = KERN_SPARC_STOP_A,
316 .procname = "stop-a",
317 .data = &stop_a_enabled,
318 .maxlen = sizeof (int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
322 #endif
323 #ifdef __hppa__
325 .ctl_name = KERN_HPPA_PWRSW,
326 .procname = "soft-power",
327 .data = &pwrsw_enabled,
328 .maxlen = sizeof (int),
329 .mode = 0644,
330 .proc_handler = &proc_dointvec,
333 .ctl_name = KERN_HPPA_UNALIGNED,
334 .procname = "unaligned-trap",
335 .data = &unaligned_enabled,
336 .maxlen = sizeof (int),
337 .mode = 0644,
338 .proc_handler = &proc_dointvec,
340 #endif
341 #ifdef __hppa__
342 {KERN_HPPA_PWRSW, "soft-power", &pwrsw_enabled, sizeof (int),
343 0644, NULL, &proc_dointvec},
344 {KERN_HPPA_UNALIGNED, "unaligned-trap", &unaligned_enabled, sizeof (int),
345 0644, NULL, &proc_dointvec},
346 #endif
347 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
349 .ctl_name = KERN_PPC_POWERSAVE_NAP,
350 .procname = "powersave-nap",
351 .data = &powersave_nap,
352 .maxlen = sizeof(int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_PPC_L2CR,
358 .procname = "l2cr",
359 .mode = 0644,
360 .proc_handler = &proc_dol2crvec,
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 = 256,
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 = 256,
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
422 .ctl_name = KERN_RTSIGNR,
423 .procname = "rtsig-nr",
424 .data = &nr_queued_signals,
425 .maxlen = sizeof(int),
426 .mode = 0444,
427 .proc_handler = &proc_dointvec,
430 .ctl_name = KERN_RTSIGMAX,
431 .procname = "rtsig-max",
432 .data = &max_queued_signals,
433 .maxlen = sizeof(int),
434 .mode = 0644,
435 .proc_handler = &proc_dointvec,
437 #ifdef CONFIG_SYSVIPC
439 .ctl_name = KERN_SHMMAX,
440 .procname = "shmmax",
441 .data = &shm_ctlmax,
442 .maxlen = sizeof (size_t),
443 .mode = 0644,
444 .proc_handler = &proc_doulongvec_minmax,
447 .ctl_name = KERN_SHMALL,
448 .procname = "shmall",
449 .data = &shm_ctlall,
450 .maxlen = sizeof (size_t),
451 .mode = 0644,
452 .proc_handler = &proc_doulongvec_minmax,
455 .ctl_name = KERN_SHMMNI,
456 .procname = "shmmni",
457 .data = &shm_ctlmni,
458 .maxlen = sizeof (int),
459 .mode = 0644,
460 .proc_handler = &proc_dointvec,
463 .ctl_name = KERN_MSGMAX,
464 .procname = "msgmax",
465 .data = &msg_ctlmax,
466 .maxlen = sizeof (int),
467 .mode = 0644,
468 .proc_handler = &proc_dointvec,
471 .ctl_name = KERN_MSGMNI,
472 .procname = "msgmni",
473 .data = &msg_ctlmni,
474 .maxlen = sizeof (int),
475 .mode = 0644,
476 .proc_handler = &proc_dointvec,
479 .ctl_name = KERN_MSGMNB,
480 .procname = "msgmnb",
481 .data = &msg_ctlmnb,
482 .maxlen = sizeof (int),
483 .mode = 0644,
484 .proc_handler = &proc_dointvec,
487 .ctl_name = KERN_SEM,
488 .procname = "sem",
489 .data = &sem_ctls,
490 .maxlen = 4*sizeof (int),
491 .mode = 0644,
492 .proc_handler = &proc_dointvec,
494 #endif
495 #ifdef CONFIG_MAGIC_SYSRQ
497 .ctl_name = KERN_SYSRQ,
498 .procname = "sysrq",
499 .data = &sysrq_enabled,
500 .maxlen = sizeof (int),
501 .mode = 0644,
502 .proc_handler = &proc_dointvec,
504 #endif
506 .ctl_name = KERN_CADPID,
507 .procname = "cad_pid",
508 .data = &cad_pid,
509 .maxlen = sizeof (int),
510 .mode = 0600,
511 .proc_handler = &proc_dointvec,
514 .ctl_name = KERN_MAX_THREADS,
515 .procname = "threads-max",
516 .data = &max_threads,
517 .maxlen = sizeof(int),
518 .mode = 0644,
519 .proc_handler = &proc_dointvec,
522 .ctl_name = KERN_RANDOM,
523 .procname = "random",
524 .mode = 0555,
525 .child = random_table,
528 .ctl_name = KERN_OVERFLOWUID,
529 .procname = "overflowuid",
530 .data = &overflowuid,
531 .maxlen = sizeof(int),
532 .mode = 0644,
533 .proc_handler = &proc_dointvec_minmax,
534 .strategy = &sysctl_intvec,
535 .extra1 = &minolduid,
536 .extra2 = &maxolduid,
539 .ctl_name = KERN_OVERFLOWGID,
540 .procname = "overflowgid",
541 .data = &overflowgid,
542 .maxlen = sizeof(int),
543 .mode = 0644,
544 .proc_handler = &proc_dointvec_minmax,
545 .strategy = &sysctl_intvec,
546 .extra1 = &minolduid,
547 .extra2 = &maxolduid,
549 #ifdef CONFIG_ARCH_S390
550 #ifdef CONFIG_MATHEMU
552 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
553 .procname = "ieee_emulation_warnings",
554 .data = &sysctl_ieee_emulation_warnings,
555 .maxlen = sizeof(int),
556 .mode = 0644,
557 .proc_handler = &proc_dointvec,
559 #endif
561 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
562 .procname = "userprocess_debug",
563 .data = &sysctl_userprocess_debug,
564 .maxlen = sizeof(int),
565 .mode = 0644,
566 .proc_handler = &proc_dointvec,
568 #endif
570 .ctl_name = KERN_PIDMAX,
571 .procname = "pid_max",
572 .data = &pid_max,
573 .maxlen = sizeof (int),
574 .mode = 0644,
575 .proc_handler = &proc_dointvec,
578 .ctl_name = KERN_PANIC_ON_OOPS,
579 .procname = "panic_on_oops",
580 .data = &panic_on_oops,
581 .maxlen = sizeof(int),
582 .mode = 0644,
583 .proc_handler = &proc_dointvec,
586 .ctl_name = KERN_PRINTK_RATELIMIT,
587 .procname = "printk_ratelimit",
588 .data = &printk_ratelimit_jiffies,
589 .maxlen = sizeof(int),
590 .mode = 0644,
591 .proc_handler = &proc_dointvec_jiffies,
592 .strategy = &sysctl_jiffies,
595 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
596 .procname = "printk_ratelimit_burst",
597 .data = &printk_ratelimit_burst,
598 .maxlen = sizeof(int),
599 .mode = 0644,
600 .proc_handler = &proc_dointvec,
601 .strategy = &sysctl_jiffies,
603 { .ctl_name = 0 }
606 /* Constants for minimum and maximum testing in vm_table.
607 We use these as one-element integer vectors. */
608 static int zero;
609 static int one_hundred = 100;
612 static ctl_table vm_table[] = {
614 .ctl_name = VM_OVERCOMMIT_MEMORY,
615 .procname = "overcommit_memory",
616 .data = &sysctl_overcommit_memory,
617 .maxlen = sizeof(sysctl_overcommit_memory),
618 .mode = 0644,
619 .proc_handler = &proc_dointvec,
622 .ctl_name = VM_OVERCOMMIT_RATIO,
623 .procname = "overcommit_ratio",
624 .data = &sysctl_overcommit_ratio,
625 .maxlen = sizeof(sysctl_overcommit_ratio),
626 .mode = 0644,
627 .proc_handler = &proc_dointvec,
630 .ctl_name = VM_PAGE_CLUSTER,
631 .procname = "page-cluster",
632 .data = &page_cluster,
633 .maxlen = sizeof(int),
634 .mode = 0644,
635 .proc_handler = &proc_dointvec,
638 .ctl_name = VM_DIRTY_BACKGROUND,
639 .procname = "dirty_background_ratio",
640 .data = &dirty_background_ratio,
641 .maxlen = sizeof(dirty_background_ratio),
642 .mode = 0644,
643 .proc_handler = &proc_dointvec_minmax,
644 .strategy = &sysctl_intvec,
645 .extra1 = &zero,
646 .extra2 = &one_hundred,
649 .ctl_name = VM_DIRTY_RATIO,
650 .procname = "dirty_ratio",
651 .data = &vm_dirty_ratio,
652 .maxlen = sizeof(vm_dirty_ratio),
653 .mode = 0644,
654 .proc_handler = &proc_dointvec_minmax,
655 .strategy = &sysctl_intvec,
656 .extra1 = &zero,
657 .extra2 = &one_hundred,
660 .ctl_name = VM_DIRTY_WB_CS,
661 .procname = "dirty_writeback_centisecs",
662 .data = &dirty_writeback_centisecs,
663 .maxlen = sizeof(dirty_writeback_centisecs),
664 .mode = 0644,
665 .proc_handler = &dirty_writeback_centisecs_handler,
668 .ctl_name = VM_DIRTY_EXPIRE_CS,
669 .procname = "dirty_expire_centisecs",
670 .data = &dirty_expire_centisecs,
671 .maxlen = sizeof(dirty_expire_centisecs),
672 .mode = 0644,
673 .proc_handler = &proc_dointvec,
676 .ctl_name = VM_NR_PDFLUSH_THREADS,
677 .procname = "nr_pdflush_threads",
678 .data = &nr_pdflush_threads,
679 .maxlen = sizeof nr_pdflush_threads,
680 .mode = 0444 /* read-only*/,
681 .proc_handler = &proc_dointvec,
684 .ctl_name = VM_SWAPPINESS,
685 .procname = "swappiness",
686 .data = &vm_swappiness,
687 .maxlen = sizeof(vm_swappiness),
688 .mode = 0644,
689 .proc_handler = &proc_dointvec_minmax,
690 .strategy = &sysctl_intvec,
691 .extra1 = &zero,
692 .extra2 = &one_hundred,
694 #ifdef CONFIG_HUGETLB_PAGE
696 .ctl_name = VM_HUGETLB_PAGES,
697 .procname = "nr_hugepages",
698 .data = &htlbpage_max,
699 .maxlen = sizeof(int),
700 .mode = 0644,
701 .proc_handler = &hugetlb_sysctl_handler,
703 #endif
705 .ctl_name = VM_LOWER_ZONE_PROTECTION,
706 .procname = "lower_zone_protection",
707 .data = &sysctl_lower_zone_protection,
708 .maxlen = sizeof(sysctl_lower_zone_protection),
709 .mode = 0644,
710 .proc_handler = &proc_dointvec_minmax,
711 .strategy = &sysctl_intvec,
712 .extra1 = &zero,
715 .ctl_name = VM_MIN_FREE_KBYTES,
716 .procname = "min_free_kbytes",
717 .data = &min_free_kbytes,
718 .maxlen = sizeof(min_free_kbytes),
719 .mode = 0644,
720 .proc_handler = &min_free_kbytes_sysctl_handler,
721 .strategy = &sysctl_intvec,
722 .extra1 = &zero,
724 { .ctl_name = 0 }
727 static ctl_table proc_table[] = {
728 { .ctl_name = 0 }
731 static ctl_table fs_table[] = {
733 .ctl_name = FS_NRINODE,
734 .procname = "inode-nr",
735 .data = &inodes_stat,
736 .maxlen = 2*sizeof(int),
737 .mode = 0444,
738 .proc_handler = &proc_dointvec,
741 .ctl_name = FS_STATINODE,
742 .procname = "inode-state",
743 .data = &inodes_stat,
744 .maxlen = 7*sizeof(int),
745 .mode = 0444,
746 .proc_handler = &proc_dointvec,
749 .ctl_name = FS_NRFILE,
750 .procname = "file-nr",
751 .data = &files_stat,
752 .maxlen = 3*sizeof(int),
753 .mode = 0444,
754 .proc_handler = &proc_dointvec,
757 .ctl_name = FS_MAXFILE,
758 .procname = "file-max",
759 .data = &files_stat.max_files,
760 .maxlen = sizeof(int),
761 .mode = 0644,
762 .proc_handler = &proc_dointvec,
765 .ctl_name = FS_DENTRY,
766 .procname = "dentry-state",
767 .data = &dentry_stat,
768 .maxlen = 6*sizeof(int),
769 .mode = 0444,
770 .proc_handler = &proc_dointvec,
773 .ctl_name = FS_OVERFLOWUID,
774 .procname = "overflowuid",
775 .data = &fs_overflowuid,
776 .maxlen = sizeof(int),
777 .mode = 0644,
778 .proc_handler = &proc_dointvec_minmax,
779 .strategy = &sysctl_intvec,
780 .extra1 = &minolduid,
781 .extra2 = &maxolduid,
784 .ctl_name = FS_OVERFLOWGID,
785 .procname = "overflowgid",
786 .data = &fs_overflowgid,
787 .maxlen = sizeof(int),
788 .mode = 0644,
789 .proc_handler = &proc_dointvec_minmax,
790 .strategy = &sysctl_intvec,
791 .extra1 = &minolduid,
792 .extra2 = &maxolduid,
795 .ctl_name = FS_LEASES,
796 .procname = "leases-enable",
797 .data = &leases_enable,
798 .maxlen = sizeof(int),
799 .mode = 0644,
800 .proc_handler = &proc_dointvec,
803 .ctl_name = FS_DIR_NOTIFY,
804 .procname = "dir-notify-enable",
805 .data = &dir_notify_enable,
806 .maxlen = sizeof(int),
807 .mode = 0644,
808 .proc_handler = &proc_dointvec,
811 .ctl_name = FS_LEASE_TIME,
812 .procname = "lease-break-time",
813 .data = &lease_break_time,
814 .maxlen = sizeof(int),
815 .mode = 0644,
816 .proc_handler = &proc_dointvec,
818 { .ctl_name = 0 }
821 static ctl_table debug_table[] = {
822 { .ctl_name = 0 }
825 static ctl_table dev_table[] = {
826 { .ctl_name = 0 }
829 extern void init_irq_proc (void);
831 void __init sysctl_init(void)
833 #ifdef CONFIG_PROC_FS
834 register_proc_table(root_table, proc_sys_root);
835 init_irq_proc();
836 #endif
839 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
840 void __user *newval, size_t newlen)
842 struct list_head *tmp;
844 if (nlen <= 0 || nlen >= CTL_MAXNAME)
845 return -ENOTDIR;
846 if (oldval) {
847 int old_len;
848 if (!oldlenp || get_user(old_len, oldlenp))
849 return -EFAULT;
851 tmp = &root_table_header.ctl_entry;
852 do {
853 struct ctl_table_header *head =
854 list_entry(tmp, struct ctl_table_header, ctl_entry);
855 void *context = NULL;
856 int error = parse_table(name, nlen, oldval, oldlenp,
857 newval, newlen, head->ctl_table,
858 &context);
859 if (context)
860 kfree(context);
861 if (error != -ENOTDIR)
862 return error;
863 tmp = tmp->next;
864 } while (tmp != &root_table_header.ctl_entry);
865 return -ENOTDIR;
868 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
870 struct __sysctl_args tmp;
871 int name[2];
872 int error;
874 if (copy_from_user(&tmp, args, sizeof(tmp)))
875 return -EFAULT;
877 if (tmp.nlen != 2 || copy_from_user(name, tmp.name, sizeof(name)) ||
878 name[0] != CTL_KERN || name[1] != KERN_VERSION) {
879 int i;
880 printk(KERN_INFO "%s: numerical sysctl ", current->comm);
881 for (i = 0; i < tmp.nlen; i++) {
882 int n;
884 if (get_user(n, tmp.name+i)) {
885 printk("? ");
886 } else {
887 printk("%d ", n);
890 printk("is obsolete.\n");
893 lock_kernel();
894 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
895 tmp.newval, tmp.newlen);
896 unlock_kernel();
897 return error;
901 * ctl_perm does NOT grant the superuser all rights automatically, because
902 * some sysctl variables are readonly even to root.
905 static int test_perm(int mode, int op)
907 if (!current->euid)
908 mode >>= 6;
909 else if (in_egroup_p(0))
910 mode >>= 3;
911 if ((mode & op & 0007) == op)
912 return 0;
913 return -EACCES;
916 static inline int ctl_perm(ctl_table *table, int op)
918 int error;
919 error = security_sysctl(table, op);
920 if (error)
921 return error;
922 return test_perm(table->mode, op);
925 static int parse_table(int __user *name, int nlen,
926 void __user *oldval, size_t __user *oldlenp,
927 void __user *newval, size_t newlen,
928 ctl_table *table, void **context)
930 int n;
931 repeat:
932 if (!nlen)
933 return -ENOTDIR;
934 if (get_user(n, name))
935 return -EFAULT;
936 for ( ; table->ctl_name; table++) {
937 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
938 int error;
939 if (table->child) {
940 if (ctl_perm(table, 001))
941 return -EPERM;
942 if (table->strategy) {
943 error = table->strategy(
944 table, name, nlen,
945 oldval, oldlenp,
946 newval, newlen, context);
947 if (error)
948 return error;
950 name++;
951 nlen--;
952 table = table->child;
953 goto repeat;
955 error = do_sysctl_strategy(table, name, nlen,
956 oldval, oldlenp,
957 newval, newlen, context);
958 return error;
961 return -ENOTDIR;
964 /* Perform the actual read/write of a sysctl table entry. */
965 int do_sysctl_strategy (ctl_table *table,
966 int __user *name, int nlen,
967 void __user *oldval, size_t __user *oldlenp,
968 void __user *newval, size_t newlen, void **context)
970 int op = 0, rc;
971 size_t len;
973 if (oldval)
974 op |= 004;
975 if (newval)
976 op |= 002;
977 if (ctl_perm(table, op))
978 return -EPERM;
980 if (table->strategy) {
981 rc = table->strategy(table, name, nlen, oldval, oldlenp,
982 newval, newlen, context);
983 if (rc < 0)
984 return rc;
985 if (rc > 0)
986 return 0;
989 /* If there is no strategy routine, or if the strategy returns
990 * zero, proceed with automatic r/w */
991 if (table->data && table->maxlen) {
992 if (oldval && oldlenp) {
993 get_user(len, oldlenp);
994 if (len) {
995 if (len > table->maxlen)
996 len = table->maxlen;
997 if(copy_to_user(oldval, table->data, len))
998 return -EFAULT;
999 if(put_user(len, oldlenp))
1000 return -EFAULT;
1003 if (newval && newlen) {
1004 len = newlen;
1005 if (len > table->maxlen)
1006 len = table->maxlen;
1007 if(copy_from_user(table->data, newval, len))
1008 return -EFAULT;
1011 return 0;
1015 * register_sysctl_table - register a sysctl hierarchy
1016 * @table: the top-level table structure
1017 * @insert_at_head: whether the entry should be inserted in front or at the end
1019 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1020 * array. An entry with a ctl_name of 0 terminates the table.
1022 * The members of the &ctl_table structure are used as follows:
1024 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1025 * must be unique within that level of sysctl
1027 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1028 * enter a sysctl file
1030 * data - a pointer to data for use by proc_handler
1032 * maxlen - the maximum size in bytes of the data
1034 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1036 * child - a pointer to the child sysctl table if this entry is a directory, or
1037 * %NULL.
1039 * proc_handler - the text handler routine (described below)
1041 * strategy - the strategy routine (described below)
1043 * de - for internal use by the sysctl routines
1045 * extra1, extra2 - extra pointers usable by the proc handler routines
1047 * Leaf nodes in the sysctl tree will be represented by a single file
1048 * under /proc; non-leaf nodes will be represented by directories.
1050 * sysctl(2) can automatically manage read and write requests through
1051 * the sysctl table. The data and maxlen fields of the ctl_table
1052 * struct enable minimal validation of the values being written to be
1053 * performed, and the mode field allows minimal authentication.
1055 * More sophisticated management can be enabled by the provision of a
1056 * strategy routine with the table entry. This will be called before
1057 * any automatic read or write of the data is performed.
1059 * The strategy routine may return
1061 * < 0 - Error occurred (error is passed to user process)
1063 * 0 - OK - proceed with automatic read or write.
1065 * > 0 - OK - read or write has been done by the strategy routine, so
1066 * return immediately.
1068 * There must be a proc_handler routine for any terminal nodes
1069 * mirrored under /proc/sys (non-terminals are handled by a built-in
1070 * directory handler). Several default handlers are available to
1071 * cover common cases -
1073 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1074 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1075 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1077 * It is the handler's job to read the input buffer from user memory
1078 * and process it. The handler should return 0 on success.
1080 * This routine returns %NULL on a failure to register, and a pointer
1081 * to the table header on success.
1083 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1084 int insert_at_head)
1086 struct ctl_table_header *tmp;
1087 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1088 if (!tmp)
1089 return NULL;
1090 tmp->ctl_table = table;
1091 INIT_LIST_HEAD(&tmp->ctl_entry);
1092 if (insert_at_head)
1093 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1094 else
1095 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1096 #ifdef CONFIG_PROC_FS
1097 register_proc_table(table, proc_sys_root);
1098 #endif
1099 return tmp;
1103 * unregister_sysctl_table - unregister a sysctl table hierarchy
1104 * @header: the header returned from register_sysctl_table
1106 * Unregisters the sysctl table and all children. proc entries may not
1107 * actually be removed until they are no longer used by anyone.
1109 void unregister_sysctl_table(struct ctl_table_header * header)
1111 list_del(&header->ctl_entry);
1112 #ifdef CONFIG_PROC_FS
1113 unregister_proc_table(header->ctl_table, proc_sys_root);
1114 #endif
1115 kfree(header);
1119 * /proc/sys support
1122 #ifdef CONFIG_PROC_FS
1124 /* Scan the sysctl entries in table and add them all into /proc */
1125 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1127 struct proc_dir_entry *de;
1128 int len;
1129 mode_t mode;
1131 for (; table->ctl_name; table++) {
1132 /* Can't do anything without a proc name. */
1133 if (!table->procname)
1134 continue;
1135 /* Maybe we can't do anything with it... */
1136 if (!table->proc_handler && !table->child) {
1137 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1138 table->procname);
1139 continue;
1142 len = strlen(table->procname);
1143 mode = table->mode;
1145 de = NULL;
1146 if (table->proc_handler)
1147 mode |= S_IFREG;
1148 else {
1149 mode |= S_IFDIR;
1150 for (de = root->subdir; de; de = de->next) {
1151 if (proc_match(len, table->procname, de))
1152 break;
1154 /* If the subdir exists already, de is non-NULL */
1157 if (!de) {
1158 de = create_proc_entry(table->procname, mode, root);
1159 if (!de)
1160 continue;
1161 de->data = (void *) table;
1162 if (table->proc_handler)
1163 de->proc_fops = &proc_sys_file_operations;
1165 table->de = de;
1166 if (de->mode & S_IFDIR)
1167 register_proc_table(table->child, de);
1172 * Unregister a /proc sysctl table and any subdirectories.
1174 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1176 struct proc_dir_entry *de;
1177 for (; table->ctl_name; table++) {
1178 if (!(de = table->de))
1179 continue;
1180 if (de->mode & S_IFDIR) {
1181 if (!table->child) {
1182 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1183 continue;
1185 unregister_proc_table(table->child, de);
1187 /* Don't unregister directories which still have entries.. */
1188 if (de->subdir)
1189 continue;
1192 /* Don't unregister proc entries that are still being used.. */
1193 if (atomic_read(&de->count))
1194 continue;
1196 table->de = NULL;
1197 remove_proc_entry(table->procname, root);
1201 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1202 size_t count, loff_t *ppos)
1204 int op;
1205 struct proc_dir_entry *de;
1206 struct ctl_table *table;
1207 size_t res;
1208 ssize_t error;
1210 de = PDE(file->f_dentry->d_inode);
1211 if (!de || !de->data)
1212 return -ENOTDIR;
1213 table = (struct ctl_table *) de->data;
1214 if (!table || !table->proc_handler)
1215 return -ENOTDIR;
1216 op = (write ? 002 : 004);
1217 if (ctl_perm(table, op))
1218 return -EPERM;
1220 res = count;
1223 * FIXME: we need to pass on ppos to the handler.
1226 error = (*table->proc_handler) (table, write, file, buf, &res);
1227 if (error)
1228 return error;
1229 return res;
1232 static int proc_opensys(struct inode *inode, struct file *file)
1234 if (file->f_mode & FMODE_WRITE) {
1236 * sysctl entries that are not writable,
1237 * are _NOT_ writable, capabilities or not.
1239 if (!(inode->i_mode & S_IWUSR))
1240 return -EPERM;
1243 return 0;
1246 static ssize_t proc_readsys(struct file * file, char __user * buf,
1247 size_t count, loff_t *ppos)
1249 return do_rw_proc(0, file, buf, count, ppos);
1252 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1253 size_t count, loff_t *ppos)
1255 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1259 * proc_dostring - read a string sysctl
1260 * @table: the sysctl table
1261 * @write: %TRUE if this is a write to the sysctl file
1262 * @filp: the file structure
1263 * @buffer: the user buffer
1264 * @lenp: the size of the user buffer
1266 * Reads/writes a string from/to the user buffer. If the kernel
1267 * buffer provided is not large enough to hold the string, the
1268 * string is truncated. The copied string is %NULL-terminated.
1269 * If the string is being read by the user process, it is copied
1270 * and a newline '\n' is added. It is truncated if the buffer is
1271 * not large enough.
1273 * Returns 0 on success.
1275 int proc_dostring(ctl_table *table, int write, struct file *filp,
1276 void __user *buffer, size_t *lenp)
1278 size_t len;
1279 char __user *p;
1280 char c;
1282 if (!table->data || !table->maxlen || !*lenp ||
1283 (filp->f_pos && !write)) {
1284 *lenp = 0;
1285 return 0;
1288 if (write) {
1289 len = 0;
1290 p = buffer;
1291 while (len < *lenp) {
1292 if(get_user(c, p++))
1293 return -EFAULT;
1294 if (c == 0 || c == '\n')
1295 break;
1296 len++;
1298 if (len >= table->maxlen)
1299 len = table->maxlen-1;
1300 if(copy_from_user(table->data, buffer, len))
1301 return -EFAULT;
1302 ((char *) table->data)[len] = 0;
1303 filp->f_pos += *lenp;
1304 } else {
1305 len = strlen(table->data);
1306 if (len > table->maxlen)
1307 len = table->maxlen;
1308 if (len > *lenp)
1309 len = *lenp;
1310 if (len)
1311 if(copy_to_user(buffer, table->data, len))
1312 return -EFAULT;
1313 if (len < *lenp) {
1314 if(put_user('\n', ((char *) buffer) + len))
1315 return -EFAULT;
1316 len++;
1318 *lenp = len;
1319 filp->f_pos += len;
1321 return 0;
1325 * Special case of dostring for the UTS structure. This has locks
1326 * to observe. Should this be in kernel/sys.c ????
1329 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1330 void __user *buffer, size_t *lenp)
1332 int r;
1334 if (!write) {
1335 down_read(&uts_sem);
1336 r=proc_dostring(table,0,filp,buffer,lenp);
1337 up_read(&uts_sem);
1338 } else {
1339 down_write(&uts_sem);
1340 r=proc_dostring(table,1,filp,buffer,lenp);
1341 up_write(&uts_sem);
1343 return r;
1346 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1347 int *valp,
1348 int write, void *data)
1350 if (write) {
1351 *valp = *negp ? -*lvalp : *lvalp;
1352 } else {
1353 int val = *valp;
1354 if (val < 0) {
1355 *negp = -1;
1356 *lvalp = (unsigned long)-val;
1357 } else {
1358 *negp = 0;
1359 *lvalp = (unsigned long)val;
1362 return 0;
1365 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1366 void __user *buffer, size_t *lenp,
1367 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1368 int write, void *data),
1369 void *data)
1371 #define TMPBUFLEN 20
1372 int *i, vleft, first=1, neg, val;
1373 unsigned long lval;
1374 size_t left, len;
1376 char buf[TMPBUFLEN], *p;
1378 if (!table->data || !table->maxlen || !*lenp ||
1379 (filp->f_pos && !write)) {
1380 *lenp = 0;
1381 return 0;
1384 i = (int *) table->data;
1385 vleft = table->maxlen / sizeof(*i);
1386 left = *lenp;
1388 if (!conv)
1389 conv = do_proc_dointvec_conv;
1391 for (; left && vleft--; i++, first=0) {
1392 if (write) {
1393 while (left) {
1394 char c;
1395 if (get_user(c,(char __user *) buffer))
1396 return -EFAULT;
1397 if (!isspace(c))
1398 break;
1399 left--;
1400 buffer++;
1402 if (!left)
1403 break;
1404 neg = 0;
1405 len = left;
1406 if (len > sizeof(buf) - 1)
1407 len = sizeof(buf) - 1;
1408 if(copy_from_user(buf, buffer, len))
1409 return -EFAULT;
1410 buf[len] = 0;
1411 p = buf;
1412 if (*p == '-' && left > 1) {
1413 neg = 1;
1414 left--, p++;
1416 if (*p < '0' || *p > '9')
1417 break;
1419 lval = simple_strtoul(p, &p, 0);
1421 len = p-buf;
1422 if ((len < left) && *p && !isspace(*p))
1423 break;
1424 if (neg)
1425 val = -val;
1426 buffer += len;
1427 left -= len;
1429 if (conv(&neg, &lval, i, 1, data))
1430 break;
1431 } else {
1432 p = buf;
1433 if (!first)
1434 *p++ = '\t';
1436 if (conv(&neg, &lval, i, 0, data))
1437 break;
1439 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1440 len = strlen(buf);
1441 if (len > left)
1442 len = left;
1443 if(copy_to_user(buffer, buf, len))
1444 return -EFAULT;
1445 left -= len;
1446 buffer += len;
1450 if (!write && !first && left) {
1451 if(put_user('\n', (char *) buffer))
1452 return -EFAULT;
1453 left--, buffer++;
1455 if (write) {
1456 p = (char *) buffer;
1457 while (left) {
1458 char c;
1459 if(get_user(c, p++))
1460 return -EFAULT;
1461 if (!isspace(c))
1462 break;
1463 left--;
1466 if (write && first)
1467 return -EINVAL;
1468 *lenp -= left;
1469 filp->f_pos += *lenp;
1470 return 0;
1471 #undef TMPBUFLEN
1475 * proc_dointvec - read a vector of integers
1476 * @table: the sysctl table
1477 * @write: %TRUE if this is a write to the sysctl file
1478 * @filp: the file structure
1479 * @buffer: the user buffer
1480 * @lenp: the size of the user buffer
1482 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1483 * values from/to the user buffer, treated as an ASCII string.
1485 * Returns 0 on success.
1487 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1488 void __user *buffer, size_t *lenp)
1490 return do_proc_dointvec(table,write,filp,buffer,lenp,
1491 NULL,NULL);
1494 #define OP_SET 0
1495 #define OP_AND 1
1496 #define OP_OR 2
1497 #define OP_MAX 3
1498 #define OP_MIN 4
1500 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1501 int *valp,
1502 int write, void *data)
1504 int op = *(int *)data;
1505 if (write) {
1506 int val = *negp ? -*lvalp : *lvalp;
1507 switch(op) {
1508 case OP_SET: *valp = val; break;
1509 case OP_AND: *valp &= val; break;
1510 case OP_OR: *valp |= val; break;
1511 case OP_MAX: if(*valp < val)
1512 *valp = val;
1513 break;
1514 case OP_MIN: if(*valp > val)
1515 *valp = val;
1516 break;
1518 } else {
1519 int val = *valp;
1520 if (val < 0) {
1521 *negp = -1;
1522 *lvalp = (unsigned long)-val;
1523 } else {
1524 *negp = 0;
1525 *lvalp = (unsigned long)val;
1528 return 0;
1532 * init may raise the set.
1535 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1536 void __user *buffer, size_t *lenp)
1538 int op;
1540 if (!capable(CAP_SYS_MODULE)) {
1541 return -EPERM;
1544 op = (current->pid == 1) ? OP_SET : OP_AND;
1545 return do_proc_dointvec(table,write,filp,buffer,lenp,
1546 do_proc_dointvec_bset_conv,&op);
1549 struct do_proc_dointvec_minmax_conv_param {
1550 int *min;
1551 int *max;
1554 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1555 int *valp,
1556 int write, void *data)
1558 struct do_proc_dointvec_minmax_conv_param *param = data;
1559 if (write) {
1560 int val = *negp ? -*lvalp : *lvalp;
1561 if ((param->min && *param->min > val) ||
1562 (param->max && *param->max < val))
1563 return -EINVAL;
1564 *valp = val;
1565 } else {
1566 int val = *valp;
1567 if (val < 0) {
1568 *negp = -1;
1569 *lvalp = (unsigned long)-val;
1570 } else {
1571 *negp = 0;
1572 *lvalp = (unsigned long)val;
1575 return 0;
1579 * proc_dointvec_minmax - read a vector of integers with min/max values
1580 * @table: the sysctl table
1581 * @write: %TRUE if this is a write to the sysctl file
1582 * @filp: the file structure
1583 * @buffer: the user buffer
1584 * @lenp: the size of the user buffer
1586 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1587 * values from/to the user buffer, treated as an ASCII string.
1589 * This routine will ensure the values are within the range specified by
1590 * table->extra1 (min) and table->extra2 (max).
1592 * Returns 0 on success.
1594 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1595 void __user *buffer, size_t *lenp)
1597 struct do_proc_dointvec_minmax_conv_param param = {
1598 .min = (int *) table->extra1,
1599 .max = (int *) table->extra2,
1601 return do_proc_dointvec(table, write, filp, buffer, lenp,
1602 do_proc_dointvec_minmax_conv, &param);
1605 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1606 struct file *filp,
1607 void __user *buffer, size_t *lenp,
1608 unsigned long convmul,
1609 unsigned long convdiv)
1611 #define TMPBUFLEN 20
1612 unsigned long *i, *min, *max, val;
1613 int vleft, first=1, neg;
1614 size_t len, left;
1615 char buf[TMPBUFLEN], *p;
1617 if (!table->data || !table->maxlen || !*lenp ||
1618 (filp->f_pos && !write)) {
1619 *lenp = 0;
1620 return 0;
1623 i = (unsigned long *) table->data;
1624 min = (unsigned long *) table->extra1;
1625 max = (unsigned long *) table->extra2;
1626 vleft = table->maxlen / sizeof(unsigned long);
1627 left = *lenp;
1629 for (; left && vleft--; i++, min++, max++, first=0) {
1630 if (write) {
1631 while (left) {
1632 char c;
1633 if (get_user(c, (char __user *) buffer))
1634 return -EFAULT;
1635 if (!isspace(c))
1636 break;
1637 left--;
1638 buffer++;
1640 if (!left)
1641 break;
1642 neg = 0;
1643 len = left;
1644 if (len > TMPBUFLEN-1)
1645 len = TMPBUFLEN-1;
1646 if (copy_from_user(buf, buffer, len))
1647 return -EFAULT;
1648 buf[len] = 0;
1649 p = buf;
1650 if (*p == '-' && left > 1) {
1651 neg = 1;
1652 left--, p++;
1654 if (*p < '0' || *p > '9')
1655 break;
1656 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1657 len = p-buf;
1658 if ((len < left) && *p && !isspace(*p))
1659 break;
1660 if (neg)
1661 val = -val;
1662 buffer += len;
1663 left -= len;
1665 if(neg)
1666 continue;
1667 if ((min && val < *min) || (max && val > *max))
1668 continue;
1669 *i = val;
1670 } else {
1671 p = buf;
1672 if (!first)
1673 *p++ = '\t';
1674 sprintf(p, "%lu", convdiv * (*i) / convmul);
1675 len = strlen(buf);
1676 if (len > left)
1677 len = left;
1678 if(copy_to_user(buffer, buf, len))
1679 return -EFAULT;
1680 left -= len;
1681 buffer += len;
1685 if (!write && !first && left) {
1686 if(put_user('\n', (char *) buffer))
1687 return -EFAULT;
1688 left--, buffer++;
1690 if (write) {
1691 p = (char *) buffer;
1692 while (left) {
1693 char c;
1694 if(get_user(c, p++))
1695 return -EFAULT;
1696 if (!isspace(c))
1697 break;
1698 left--;
1701 if (write && first)
1702 return -EINVAL;
1703 *lenp -= left;
1704 filp->f_pos += *lenp;
1705 return 0;
1706 #undef TMPBUFLEN
1710 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1711 * @table: the sysctl table
1712 * @write: %TRUE if this is a write to the sysctl file
1713 * @filp: the file structure
1714 * @buffer: the user buffer
1715 * @lenp: the size of the user buffer
1717 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1718 * values from/to the user buffer, treated as an ASCII string.
1720 * This routine will ensure the values are within the range specified by
1721 * table->extra1 (min) and table->extra2 (max).
1723 * Returns 0 on success.
1725 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1726 void __user *buffer, size_t *lenp)
1728 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, 1l, 1l);
1732 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1733 * @table: the sysctl table
1734 * @write: %TRUE if this is a write to the sysctl file
1735 * @filp: the file structure
1736 * @buffer: the user buffer
1737 * @lenp: the size of the user buffer
1739 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1740 * values from/to the user buffer, treated as an ASCII string. The values
1741 * are treated as milliseconds, and converted to jiffies when they are stored.
1743 * This routine will ensure the values are within the range specified by
1744 * table->extra1 (min) and table->extra2 (max).
1746 * Returns 0 on success.
1748 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1749 struct file *filp,
1750 void __user *buffer, size_t *lenp)
1752 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1753 lenp, HZ, 1000l);
1757 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1758 int *valp,
1759 int write, void *data)
1761 if (write) {
1762 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1763 } else {
1764 int val = *valp;
1765 unsigned long lval;
1766 if (val < 0) {
1767 *negp = -1;
1768 lval = (unsigned long)-val;
1769 } else {
1770 *negp = 0;
1771 lval = (unsigned long)val;
1773 *lvalp = lval / HZ;
1775 return 0;
1778 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1779 int *valp,
1780 int write, void *data)
1782 if (write) {
1783 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1784 } else {
1785 int val = *valp;
1786 unsigned long lval;
1787 if (val < 0) {
1788 *negp = -1;
1789 lval = (unsigned long)-val;
1790 } else {
1791 *negp = 0;
1792 lval = (unsigned long)val;
1794 *lvalp = jiffies_to_clock_t(lval);
1796 return 0;
1800 * proc_dointvec_jiffies - read a vector of integers as seconds
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 int) integer
1808 * values from/to the user buffer, treated as an ASCII string.
1809 * The values read are assumed to be in seconds, and are converted into
1810 * jiffies.
1812 * Returns 0 on success.
1814 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1815 void __user *buffer, size_t *lenp)
1817 return do_proc_dointvec(table,write,filp,buffer,lenp,
1818 do_proc_dointvec_jiffies_conv,NULL);
1822 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1823 * @table: the sysctl table
1824 * @write: %TRUE if this is a write to the sysctl file
1825 * @filp: the file structure
1826 * @buffer: the user buffer
1827 * @lenp: the size of the user buffer
1829 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1830 * values from/to the user buffer, treated as an ASCII string.
1831 * The values read are assumed to be in 1/USER_HZ seconds, and
1832 * are converted into jiffies.
1834 * Returns 0 on success.
1836 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1837 void __user *buffer, size_t *lenp)
1839 return do_proc_dointvec(table,write,filp,buffer,lenp,
1840 do_proc_dointvec_userhz_jiffies_conv,NULL);
1843 #else /* CONFIG_PROC_FS */
1845 int proc_dostring(ctl_table *table, int write, struct file *filp,
1846 void *buffer, size_t *lenp)
1848 return -ENOSYS;
1851 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1852 void *buffer, size_t *lenp)
1854 return -ENOSYS;
1857 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1858 void *buffer, size_t *lenp)
1860 return -ENOSYS;
1863 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1864 void *buffer, size_t *lenp)
1866 return -ENOSYS;
1869 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1870 void *buffer, size_t *lenp)
1872 return -ENOSYS;
1875 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1876 void *buffer, size_t *lenp)
1878 return -ENOSYS;
1881 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
1882 void *buffer, size_t *lenp)
1884 return -ENOSYS;
1887 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1888 void *buffer, size_t *lenp)
1890 return -ENOSYS;
1893 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1894 struct file *filp,
1895 void *buffer, size_t *lenp)
1897 return -ENOSYS;
1901 #endif /* CONFIG_PROC_FS */
1905 * General sysctl support routines
1908 /* The generic string strategy routine: */
1909 int sysctl_string(ctl_table *table, int __user *name, int nlen,
1910 void __user *oldval, size_t __user *oldlenp,
1911 void __user *newval, size_t newlen, void **context)
1913 size_t l, len;
1915 if (!table->data || !table->maxlen)
1916 return -ENOTDIR;
1918 if (oldval && oldlenp) {
1919 if(get_user(len, oldlenp))
1920 return -EFAULT;
1921 if (len) {
1922 l = strlen(table->data);
1923 if (len > l) len = l;
1924 if (len >= table->maxlen)
1925 len = table->maxlen;
1926 if(copy_to_user(oldval, table->data, len))
1927 return -EFAULT;
1928 if(put_user(0, ((char *) oldval) + len))
1929 return -EFAULT;
1930 if(put_user(len, oldlenp))
1931 return -EFAULT;
1934 if (newval && newlen) {
1935 len = newlen;
1936 if (len > table->maxlen)
1937 len = table->maxlen;
1938 if(copy_from_user(table->data, newval, len))
1939 return -EFAULT;
1940 if (len == table->maxlen)
1941 len--;
1942 ((char *) table->data)[len] = 0;
1944 return 0;
1948 * This function makes sure that all of the integers in the vector
1949 * are between the minimum and maximum values given in the arrays
1950 * table->extra1 and table->extra2, respectively.
1952 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
1953 void __user *oldval, size_t __user *oldlenp,
1954 void __user *newval, size_t newlen, void **context)
1956 int i, *vec, *min, *max;
1957 size_t length;
1959 if (newval && newlen) {
1960 if (newlen % sizeof(int) != 0)
1961 return -EINVAL;
1963 if (!table->extra1 && !table->extra2)
1964 return 0;
1966 if (newlen > table->maxlen)
1967 newlen = table->maxlen;
1968 length = newlen / sizeof(int);
1970 vec = (int *) newval;
1971 min = (int *) table->extra1;
1972 max = (int *) table->extra2;
1974 for (i = 0; i < length; i++) {
1975 int value;
1976 get_user(value, vec + i);
1977 if (min && value < min[i])
1978 return -EINVAL;
1979 if (max && value > max[i])
1980 return -EINVAL;
1983 return 0;
1986 /* Strategy function to convert jiffies to seconds */
1987 int sysctl_jiffies(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 if (oldval) {
1992 size_t olen;
1993 if (oldlenp) {
1994 if (get_user(olen, oldlenp))
1995 return -EFAULT;
1996 if (olen!=sizeof(int))
1997 return -EINVAL;
1999 if (put_user(*(int *)(table->data) / HZ, (int *)oldval) ||
2000 (oldlenp && put_user(sizeof(int),oldlenp)))
2001 return -EFAULT;
2003 if (newval && newlen) {
2004 int new;
2005 if (newlen != sizeof(int))
2006 return -EINVAL;
2007 if (get_user(new, (int *)newval))
2008 return -EFAULT;
2009 *(int *)(table->data) = new*HZ;
2011 return 1;
2015 #else /* CONFIG_SYSCTL */
2018 extern asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2020 return -ENOSYS;
2023 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2024 void __user *oldval, size_t __user *oldlenp,
2025 void __user *newval, size_t newlen, void **context)
2027 return -ENOSYS;
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)
2034 return -ENOSYS;
2037 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2038 void __user *oldval, size_t __user *oldlenp,
2039 void __user *newval, size_t newlen, void **context)
2041 return -ENOSYS;
2044 int proc_dostring(ctl_table *table, int write, struct file *filp,
2045 void __user *buffer, size_t *lenp)
2047 return -ENOSYS;
2050 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2051 void __user *buffer, size_t *lenp)
2053 return -ENOSYS;
2056 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2057 void __user *buffer, size_t *lenp)
2059 return -ENOSYS;
2062 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2063 void __user *buffer, size_t *lenp)
2065 return -ENOSYS;
2068 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2069 void *buffer, size_t *lenp)
2071 return -ENOSYS;
2074 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2075 void *buffer, size_t *lenp)
2077 return -ENOSYS;
2080 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2081 void __user *buffer, size_t *lenp)
2083 return -ENOSYS;
2086 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2087 struct file *filp,
2088 void __user *buffer, size_t *lenp)
2090 return -ENOSYS;
2093 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2094 int insert_at_head)
2096 return 0;
2099 void unregister_sysctl_table(struct ctl_table_header * table)
2103 #endif /* CONFIG_SYSCTL */
2106 * No sense putting this after each symbol definition, twice,
2107 * exception granted :-)
2109 EXPORT_SYMBOL(proc_dointvec);
2110 EXPORT_SYMBOL(proc_dointvec_jiffies);
2111 EXPORT_SYMBOL(proc_dointvec_minmax);
2112 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2113 EXPORT_SYMBOL(proc_dostring);
2114 EXPORT_SYMBOL(proc_doulongvec_minmax);
2115 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2116 EXPORT_SYMBOL(register_sysctl_table);
2117 EXPORT_SYMBOL(sysctl_intvec);
2118 EXPORT_SYMBOL(sysctl_jiffies);
2119 EXPORT_SYMBOL(sysctl_string);
2120 EXPORT_SYMBOL(unregister_sysctl_table);