[PATCH] kthread: move kernel-doc and put it into DocBook
[linux-2.6/openmoko-kernel/knife-kernel.git] / kernel / sysctl.c
blob2c0e6581944804eee1391161224afd89972b34e1
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/capability.h>
29 #include <linux/ctype.h>
30 #include <linux/utsname.h>
31 #include <linux/capability.h>
32 #include <linux/smp_lock.h>
33 #include <linux/init.h>
34 #include <linux/kernel.h>
35 #include <linux/kobject.h>
36 #include <linux/net.h>
37 #include <linux/sysrq.h>
38 #include <linux/highuid.h>
39 #include <linux/writeback.h>
40 #include <linux/hugetlb.h>
41 #include <linux/security.h>
42 #include <linux/initrd.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/nfs_fs.h>
48 #include <linux/acpi.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
53 extern int proc_nr_files(ctl_table *table, int write, struct file *filp,
54 void __user *buffer, size_t *lenp, loff_t *ppos);
56 #if defined(CONFIG_SYSCTL)
58 /* External variables not in a header file. */
59 extern int C_A_D;
60 extern int sysctl_overcommit_memory;
61 extern int sysctl_overcommit_ratio;
62 extern int sysctl_panic_on_oom;
63 extern int max_threads;
64 extern int sysrq_enabled;
65 extern int core_uses_pid;
66 extern int suid_dumpable;
67 extern char core_pattern[];
68 extern int cad_pid;
69 extern int pid_max;
70 extern int min_free_kbytes;
71 extern int printk_ratelimit_jiffies;
72 extern int printk_ratelimit_burst;
73 extern int pid_max_min, pid_max_max;
74 extern int sysctl_drop_caches;
75 extern int percpu_pagelist_fraction;
77 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
78 int unknown_nmi_panic;
79 extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
80 void __user *, size_t *, loff_t *);
81 #endif
83 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
84 static int maxolduid = 65535;
85 static int minolduid;
86 static int min_percpu_pagelist_fract = 8;
88 static int ngroups_max = NGROUPS_MAX;
90 #ifdef CONFIG_KMOD
91 extern char modprobe_path[];
92 #endif
93 #ifdef CONFIG_CHR_DEV_SG
94 extern int sg_big_buff;
95 #endif
96 #ifdef CONFIG_SYSVIPC
97 extern size_t shm_ctlmax;
98 extern size_t shm_ctlall;
99 extern int shm_ctlmni;
100 extern int msg_ctlmax;
101 extern int msg_ctlmnb;
102 extern int msg_ctlmni;
103 extern int sem_ctls[];
104 #endif
106 #ifdef __sparc__
107 extern char reboot_command [];
108 extern int stop_a_enabled;
109 extern int scons_pwroff;
110 #endif
112 #ifdef __hppa__
113 extern int pwrsw_enabled;
114 extern int unaligned_enabled;
115 #endif
117 #ifdef CONFIG_S390
118 #ifdef CONFIG_MATHEMU
119 extern int sysctl_ieee_emulation_warnings;
120 #endif
121 extern int sysctl_userprocess_debug;
122 extern int spin_retry;
123 #endif
125 extern int sysctl_hz_timer;
127 #ifdef CONFIG_BSD_PROCESS_ACCT
128 extern int acct_parm[];
129 #endif
131 #ifdef CONFIG_IA64
132 extern int no_unaligned_warning;
133 #endif
135 static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
136 ctl_table *, void **);
137 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
138 void __user *buffer, size_t *lenp, loff_t *ppos);
140 static ctl_table root_table[];
141 static struct ctl_table_header root_table_header =
142 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
144 static ctl_table kern_table[];
145 static ctl_table vm_table[];
146 static ctl_table fs_table[];
147 static ctl_table debug_table[];
148 static ctl_table dev_table[];
149 extern ctl_table random_table[];
150 #ifdef CONFIG_UNIX98_PTYS
151 extern ctl_table pty_table[];
152 #endif
153 #ifdef CONFIG_INOTIFY_USER
154 extern ctl_table inotify_table[];
155 #endif
157 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
158 int sysctl_legacy_va_layout;
159 #endif
161 /* /proc declarations: */
163 #ifdef CONFIG_PROC_FS
165 static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
166 static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
167 static int proc_opensys(struct inode *, struct file *);
169 struct file_operations proc_sys_file_operations = {
170 .open = proc_opensys,
171 .read = proc_readsys,
172 .write = proc_writesys,
175 extern struct proc_dir_entry *proc_sys_root;
177 static void register_proc_table(ctl_table *, struct proc_dir_entry *, void *);
178 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
179 #endif
181 /* The default sysctl tables: */
183 static ctl_table root_table[] = {
185 .ctl_name = CTL_KERN,
186 .procname = "kernel",
187 .mode = 0555,
188 .child = kern_table,
191 .ctl_name = CTL_VM,
192 .procname = "vm",
193 .mode = 0555,
194 .child = vm_table,
196 #ifdef CONFIG_NET
198 .ctl_name = CTL_NET,
199 .procname = "net",
200 .mode = 0555,
201 .child = net_table,
203 #endif
205 .ctl_name = CTL_FS,
206 .procname = "fs",
207 .mode = 0555,
208 .child = fs_table,
211 .ctl_name = CTL_DEBUG,
212 .procname = "debug",
213 .mode = 0555,
214 .child = debug_table,
217 .ctl_name = CTL_DEV,
218 .procname = "dev",
219 .mode = 0555,
220 .child = dev_table,
223 { .ctl_name = 0 }
226 static ctl_table kern_table[] = {
228 .ctl_name = KERN_OSTYPE,
229 .procname = "ostype",
230 .data = system_utsname.sysname,
231 .maxlen = sizeof(system_utsname.sysname),
232 .mode = 0444,
233 .proc_handler = &proc_doutsstring,
234 .strategy = &sysctl_string,
237 .ctl_name = KERN_OSRELEASE,
238 .procname = "osrelease",
239 .data = system_utsname.release,
240 .maxlen = sizeof(system_utsname.release),
241 .mode = 0444,
242 .proc_handler = &proc_doutsstring,
243 .strategy = &sysctl_string,
246 .ctl_name = KERN_VERSION,
247 .procname = "version",
248 .data = system_utsname.version,
249 .maxlen = sizeof(system_utsname.version),
250 .mode = 0444,
251 .proc_handler = &proc_doutsstring,
252 .strategy = &sysctl_string,
255 .ctl_name = KERN_NODENAME,
256 .procname = "hostname",
257 .data = system_utsname.nodename,
258 .maxlen = sizeof(system_utsname.nodename),
259 .mode = 0644,
260 .proc_handler = &proc_doutsstring,
261 .strategy = &sysctl_string,
264 .ctl_name = KERN_DOMAINNAME,
265 .procname = "domainname",
266 .data = system_utsname.domainname,
267 .maxlen = sizeof(system_utsname.domainname),
268 .mode = 0644,
269 .proc_handler = &proc_doutsstring,
270 .strategy = &sysctl_string,
273 .ctl_name = KERN_PANIC,
274 .procname = "panic",
275 .data = &panic_timeout,
276 .maxlen = sizeof(int),
277 .mode = 0644,
278 .proc_handler = &proc_dointvec,
281 .ctl_name = KERN_CORE_USES_PID,
282 .procname = "core_uses_pid",
283 .data = &core_uses_pid,
284 .maxlen = sizeof(int),
285 .mode = 0644,
286 .proc_handler = &proc_dointvec,
289 .ctl_name = KERN_CORE_PATTERN,
290 .procname = "core_pattern",
291 .data = core_pattern,
292 .maxlen = 64,
293 .mode = 0644,
294 .proc_handler = &proc_dostring,
295 .strategy = &sysctl_string,
298 .ctl_name = KERN_TAINTED,
299 .procname = "tainted",
300 .data = &tainted,
301 .maxlen = sizeof(int),
302 .mode = 0444,
303 .proc_handler = &proc_dointvec,
306 .ctl_name = KERN_CAP_BSET,
307 .procname = "cap-bound",
308 .data = &cap_bset,
309 .maxlen = sizeof(kernel_cap_t),
310 .mode = 0600,
311 .proc_handler = &proc_dointvec_bset,
313 #ifdef CONFIG_BLK_DEV_INITRD
315 .ctl_name = KERN_REALROOTDEV,
316 .procname = "real-root-dev",
317 .data = &real_root_dev,
318 .maxlen = sizeof(int),
319 .mode = 0644,
320 .proc_handler = &proc_dointvec,
322 #endif
323 #ifdef __sparc__
325 .ctl_name = KERN_SPARC_REBOOT,
326 .procname = "reboot-cmd",
327 .data = reboot_command,
328 .maxlen = 256,
329 .mode = 0644,
330 .proc_handler = &proc_dostring,
331 .strategy = &sysctl_string,
334 .ctl_name = KERN_SPARC_STOP_A,
335 .procname = "stop-a",
336 .data = &stop_a_enabled,
337 .maxlen = sizeof (int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
342 .ctl_name = KERN_SPARC_SCONS_PWROFF,
343 .procname = "scons-poweroff",
344 .data = &scons_pwroff,
345 .maxlen = sizeof (int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
349 #endif
350 #ifdef __hppa__
352 .ctl_name = KERN_HPPA_PWRSW,
353 .procname = "soft-power",
354 .data = &pwrsw_enabled,
355 .maxlen = sizeof (int),
356 .mode = 0644,
357 .proc_handler = &proc_dointvec,
360 .ctl_name = KERN_HPPA_UNALIGNED,
361 .procname = "unaligned-trap",
362 .data = &unaligned_enabled,
363 .maxlen = sizeof (int),
364 .mode = 0644,
365 .proc_handler = &proc_dointvec,
367 #endif
369 .ctl_name = KERN_CTLALTDEL,
370 .procname = "ctrl-alt-del",
371 .data = &C_A_D,
372 .maxlen = sizeof(int),
373 .mode = 0644,
374 .proc_handler = &proc_dointvec,
377 .ctl_name = KERN_PRINTK,
378 .procname = "printk",
379 .data = &console_loglevel,
380 .maxlen = 4*sizeof(int),
381 .mode = 0644,
382 .proc_handler = &proc_dointvec,
384 #ifdef CONFIG_KMOD
386 .ctl_name = KERN_MODPROBE,
387 .procname = "modprobe",
388 .data = &modprobe_path,
389 .maxlen = KMOD_PATH_LEN,
390 .mode = 0644,
391 .proc_handler = &proc_dostring,
392 .strategy = &sysctl_string,
394 #endif
395 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
397 .ctl_name = KERN_HOTPLUG,
398 .procname = "hotplug",
399 .data = &uevent_helper,
400 .maxlen = UEVENT_HELPER_PATH_LEN,
401 .mode = 0644,
402 .proc_handler = &proc_dostring,
403 .strategy = &sysctl_string,
405 #endif
406 #ifdef CONFIG_CHR_DEV_SG
408 .ctl_name = KERN_SG_BIG_BUFF,
409 .procname = "sg-big-buff",
410 .data = &sg_big_buff,
411 .maxlen = sizeof (int),
412 .mode = 0444,
413 .proc_handler = &proc_dointvec,
415 #endif
416 #ifdef CONFIG_BSD_PROCESS_ACCT
418 .ctl_name = KERN_ACCT,
419 .procname = "acct",
420 .data = &acct_parm,
421 .maxlen = 3*sizeof(int),
422 .mode = 0644,
423 .proc_handler = &proc_dointvec,
425 #endif
426 #ifdef CONFIG_SYSVIPC
428 .ctl_name = KERN_SHMMAX,
429 .procname = "shmmax",
430 .data = &shm_ctlmax,
431 .maxlen = sizeof (size_t),
432 .mode = 0644,
433 .proc_handler = &proc_doulongvec_minmax,
436 .ctl_name = KERN_SHMALL,
437 .procname = "shmall",
438 .data = &shm_ctlall,
439 .maxlen = sizeof (size_t),
440 .mode = 0644,
441 .proc_handler = &proc_doulongvec_minmax,
444 .ctl_name = KERN_SHMMNI,
445 .procname = "shmmni",
446 .data = &shm_ctlmni,
447 .maxlen = sizeof (int),
448 .mode = 0644,
449 .proc_handler = &proc_dointvec,
452 .ctl_name = KERN_MSGMAX,
453 .procname = "msgmax",
454 .data = &msg_ctlmax,
455 .maxlen = sizeof (int),
456 .mode = 0644,
457 .proc_handler = &proc_dointvec,
460 .ctl_name = KERN_MSGMNI,
461 .procname = "msgmni",
462 .data = &msg_ctlmni,
463 .maxlen = sizeof (int),
464 .mode = 0644,
465 .proc_handler = &proc_dointvec,
468 .ctl_name = KERN_MSGMNB,
469 .procname = "msgmnb",
470 .data = &msg_ctlmnb,
471 .maxlen = sizeof (int),
472 .mode = 0644,
473 .proc_handler = &proc_dointvec,
476 .ctl_name = KERN_SEM,
477 .procname = "sem",
478 .data = &sem_ctls,
479 .maxlen = 4*sizeof (int),
480 .mode = 0644,
481 .proc_handler = &proc_dointvec,
483 #endif
484 #ifdef CONFIG_MAGIC_SYSRQ
486 .ctl_name = KERN_SYSRQ,
487 .procname = "sysrq",
488 .data = &sysrq_enabled,
489 .maxlen = sizeof (int),
490 .mode = 0644,
491 .proc_handler = &proc_dointvec,
493 #endif
495 .ctl_name = KERN_CADPID,
496 .procname = "cad_pid",
497 .data = &cad_pid,
498 .maxlen = sizeof (int),
499 .mode = 0600,
500 .proc_handler = &proc_dointvec,
503 .ctl_name = KERN_MAX_THREADS,
504 .procname = "threads-max",
505 .data = &max_threads,
506 .maxlen = sizeof(int),
507 .mode = 0644,
508 .proc_handler = &proc_dointvec,
511 .ctl_name = KERN_RANDOM,
512 .procname = "random",
513 .mode = 0555,
514 .child = random_table,
516 #ifdef CONFIG_UNIX98_PTYS
518 .ctl_name = KERN_PTY,
519 .procname = "pty",
520 .mode = 0555,
521 .child = pty_table,
523 #endif
525 .ctl_name = KERN_OVERFLOWUID,
526 .procname = "overflowuid",
527 .data = &overflowuid,
528 .maxlen = sizeof(int),
529 .mode = 0644,
530 .proc_handler = &proc_dointvec_minmax,
531 .strategy = &sysctl_intvec,
532 .extra1 = &minolduid,
533 .extra2 = &maxolduid,
536 .ctl_name = KERN_OVERFLOWGID,
537 .procname = "overflowgid",
538 .data = &overflowgid,
539 .maxlen = sizeof(int),
540 .mode = 0644,
541 .proc_handler = &proc_dointvec_minmax,
542 .strategy = &sysctl_intvec,
543 .extra1 = &minolduid,
544 .extra2 = &maxolduid,
546 #ifdef CONFIG_S390
547 #ifdef CONFIG_MATHEMU
549 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
550 .procname = "ieee_emulation_warnings",
551 .data = &sysctl_ieee_emulation_warnings,
552 .maxlen = sizeof(int),
553 .mode = 0644,
554 .proc_handler = &proc_dointvec,
556 #endif
557 #ifdef CONFIG_NO_IDLE_HZ
559 .ctl_name = KERN_HZ_TIMER,
560 .procname = "hz_timer",
561 .data = &sysctl_hz_timer,
562 .maxlen = sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec,
566 #endif
568 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
569 .procname = "userprocess_debug",
570 .data = &sysctl_userprocess_debug,
571 .maxlen = sizeof(int),
572 .mode = 0644,
573 .proc_handler = &proc_dointvec,
575 #endif
577 .ctl_name = KERN_PIDMAX,
578 .procname = "pid_max",
579 .data = &pid_max,
580 .maxlen = sizeof (int),
581 .mode = 0644,
582 .proc_handler = &proc_dointvec_minmax,
583 .strategy = sysctl_intvec,
584 .extra1 = &pid_max_min,
585 .extra2 = &pid_max_max,
588 .ctl_name = KERN_PANIC_ON_OOPS,
589 .procname = "panic_on_oops",
590 .data = &panic_on_oops,
591 .maxlen = sizeof(int),
592 .mode = 0644,
593 .proc_handler = &proc_dointvec,
596 .ctl_name = KERN_PRINTK_RATELIMIT,
597 .procname = "printk_ratelimit",
598 .data = &printk_ratelimit_jiffies,
599 .maxlen = sizeof(int),
600 .mode = 0644,
601 .proc_handler = &proc_dointvec_jiffies,
602 .strategy = &sysctl_jiffies,
605 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
606 .procname = "printk_ratelimit_burst",
607 .data = &printk_ratelimit_burst,
608 .maxlen = sizeof(int),
609 .mode = 0644,
610 .proc_handler = &proc_dointvec,
613 .ctl_name = KERN_NGROUPS_MAX,
614 .procname = "ngroups_max",
615 .data = &ngroups_max,
616 .maxlen = sizeof (int),
617 .mode = 0444,
618 .proc_handler = &proc_dointvec,
620 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
622 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
623 .procname = "unknown_nmi_panic",
624 .data = &unknown_nmi_panic,
625 .maxlen = sizeof (int),
626 .mode = 0644,
627 .proc_handler = &proc_unknown_nmi_panic,
629 #endif
630 #if defined(CONFIG_X86)
632 .ctl_name = KERN_BOOTLOADER_TYPE,
633 .procname = "bootloader_type",
634 .data = &bootloader_type,
635 .maxlen = sizeof (int),
636 .mode = 0444,
637 .proc_handler = &proc_dointvec,
639 #endif
640 #if defined(CONFIG_MMU)
642 .ctl_name = KERN_RANDOMIZE,
643 .procname = "randomize_va_space",
644 .data = &randomize_va_space,
645 .maxlen = sizeof(int),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec,
649 #endif
650 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
652 .ctl_name = KERN_SPIN_RETRY,
653 .procname = "spin_retry",
654 .data = &spin_retry,
655 .maxlen = sizeof (int),
656 .mode = 0644,
657 .proc_handler = &proc_dointvec,
659 #endif
660 #ifdef CONFIG_ACPI_SLEEP
662 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
663 .procname = "acpi_video_flags",
664 .data = &acpi_video_flags,
665 .maxlen = sizeof (unsigned long),
666 .mode = 0644,
667 .proc_handler = &proc_doulongvec_minmax,
669 #endif
670 #ifdef CONFIG_IA64
672 .ctl_name = KERN_IA64_UNALIGNED,
673 .procname = "ignore-unaligned-usertrap",
674 .data = &no_unaligned_warning,
675 .maxlen = sizeof (int),
676 .mode = 0644,
677 .proc_handler = &proc_dointvec,
679 #endif
680 { .ctl_name = 0 }
683 /* Constants for minimum and maximum testing in vm_table.
684 We use these as one-element integer vectors. */
685 static int zero;
686 static int one_hundred = 100;
689 static ctl_table vm_table[] = {
691 .ctl_name = VM_OVERCOMMIT_MEMORY,
692 .procname = "overcommit_memory",
693 .data = &sysctl_overcommit_memory,
694 .maxlen = sizeof(sysctl_overcommit_memory),
695 .mode = 0644,
696 .proc_handler = &proc_dointvec,
699 .ctl_name = VM_PANIC_ON_OOM,
700 .procname = "panic_on_oom",
701 .data = &sysctl_panic_on_oom,
702 .maxlen = sizeof(sysctl_panic_on_oom),
703 .mode = 0644,
704 .proc_handler = &proc_dointvec,
707 .ctl_name = VM_OVERCOMMIT_RATIO,
708 .procname = "overcommit_ratio",
709 .data = &sysctl_overcommit_ratio,
710 .maxlen = sizeof(sysctl_overcommit_ratio),
711 .mode = 0644,
712 .proc_handler = &proc_dointvec,
715 .ctl_name = VM_PAGE_CLUSTER,
716 .procname = "page-cluster",
717 .data = &page_cluster,
718 .maxlen = sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
723 .ctl_name = VM_DIRTY_BACKGROUND,
724 .procname = "dirty_background_ratio",
725 .data = &dirty_background_ratio,
726 .maxlen = sizeof(dirty_background_ratio),
727 .mode = 0644,
728 .proc_handler = &proc_dointvec_minmax,
729 .strategy = &sysctl_intvec,
730 .extra1 = &zero,
731 .extra2 = &one_hundred,
734 .ctl_name = VM_DIRTY_RATIO,
735 .procname = "dirty_ratio",
736 .data = &vm_dirty_ratio,
737 .maxlen = sizeof(vm_dirty_ratio),
738 .mode = 0644,
739 .proc_handler = &proc_dointvec_minmax,
740 .strategy = &sysctl_intvec,
741 .extra1 = &zero,
742 .extra2 = &one_hundred,
745 .ctl_name = VM_DIRTY_WB_CS,
746 .procname = "dirty_writeback_centisecs",
747 .data = &dirty_writeback_interval,
748 .maxlen = sizeof(dirty_writeback_interval),
749 .mode = 0644,
750 .proc_handler = &dirty_writeback_centisecs_handler,
753 .ctl_name = VM_DIRTY_EXPIRE_CS,
754 .procname = "dirty_expire_centisecs",
755 .data = &dirty_expire_interval,
756 .maxlen = sizeof(dirty_expire_interval),
757 .mode = 0644,
758 .proc_handler = &proc_dointvec_userhz_jiffies,
761 .ctl_name = VM_NR_PDFLUSH_THREADS,
762 .procname = "nr_pdflush_threads",
763 .data = &nr_pdflush_threads,
764 .maxlen = sizeof nr_pdflush_threads,
765 .mode = 0444 /* read-only*/,
766 .proc_handler = &proc_dointvec,
769 .ctl_name = VM_SWAPPINESS,
770 .procname = "swappiness",
771 .data = &vm_swappiness,
772 .maxlen = sizeof(vm_swappiness),
773 .mode = 0644,
774 .proc_handler = &proc_dointvec_minmax,
775 .strategy = &sysctl_intvec,
776 .extra1 = &zero,
777 .extra2 = &one_hundred,
779 #ifdef CONFIG_HUGETLB_PAGE
781 .ctl_name = VM_HUGETLB_PAGES,
782 .procname = "nr_hugepages",
783 .data = &max_huge_pages,
784 .maxlen = sizeof(unsigned long),
785 .mode = 0644,
786 .proc_handler = &hugetlb_sysctl_handler,
787 .extra1 = (void *)&hugetlb_zero,
788 .extra2 = (void *)&hugetlb_infinity,
791 .ctl_name = VM_HUGETLB_GROUP,
792 .procname = "hugetlb_shm_group",
793 .data = &sysctl_hugetlb_shm_group,
794 .maxlen = sizeof(gid_t),
795 .mode = 0644,
796 .proc_handler = &proc_dointvec,
798 #endif
800 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
801 .procname = "lowmem_reserve_ratio",
802 .data = &sysctl_lowmem_reserve_ratio,
803 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
804 .mode = 0644,
805 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
806 .strategy = &sysctl_intvec,
809 .ctl_name = VM_DROP_PAGECACHE,
810 .procname = "drop_caches",
811 .data = &sysctl_drop_caches,
812 .maxlen = sizeof(int),
813 .mode = 0644,
814 .proc_handler = drop_caches_sysctl_handler,
815 .strategy = &sysctl_intvec,
818 .ctl_name = VM_MIN_FREE_KBYTES,
819 .procname = "min_free_kbytes",
820 .data = &min_free_kbytes,
821 .maxlen = sizeof(min_free_kbytes),
822 .mode = 0644,
823 .proc_handler = &min_free_kbytes_sysctl_handler,
824 .strategy = &sysctl_intvec,
825 .extra1 = &zero,
828 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
829 .procname = "percpu_pagelist_fraction",
830 .data = &percpu_pagelist_fraction,
831 .maxlen = sizeof(percpu_pagelist_fraction),
832 .mode = 0644,
833 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
834 .strategy = &sysctl_intvec,
835 .extra1 = &min_percpu_pagelist_fract,
837 #ifdef CONFIG_MMU
839 .ctl_name = VM_MAX_MAP_COUNT,
840 .procname = "max_map_count",
841 .data = &sysctl_max_map_count,
842 .maxlen = sizeof(sysctl_max_map_count),
843 .mode = 0644,
844 .proc_handler = &proc_dointvec
846 #endif
848 .ctl_name = VM_LAPTOP_MODE,
849 .procname = "laptop_mode",
850 .data = &laptop_mode,
851 .maxlen = sizeof(laptop_mode),
852 .mode = 0644,
853 .proc_handler = &proc_dointvec_jiffies,
854 .strategy = &sysctl_jiffies,
857 .ctl_name = VM_BLOCK_DUMP,
858 .procname = "block_dump",
859 .data = &block_dump,
860 .maxlen = sizeof(block_dump),
861 .mode = 0644,
862 .proc_handler = &proc_dointvec,
863 .strategy = &sysctl_intvec,
864 .extra1 = &zero,
867 .ctl_name = VM_VFS_CACHE_PRESSURE,
868 .procname = "vfs_cache_pressure",
869 .data = &sysctl_vfs_cache_pressure,
870 .maxlen = sizeof(sysctl_vfs_cache_pressure),
871 .mode = 0644,
872 .proc_handler = &proc_dointvec,
873 .strategy = &sysctl_intvec,
874 .extra1 = &zero,
876 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
878 .ctl_name = VM_LEGACY_VA_LAYOUT,
879 .procname = "legacy_va_layout",
880 .data = &sysctl_legacy_va_layout,
881 .maxlen = sizeof(sysctl_legacy_va_layout),
882 .mode = 0644,
883 .proc_handler = &proc_dointvec,
884 .strategy = &sysctl_intvec,
885 .extra1 = &zero,
887 #endif
888 #ifdef CONFIG_SWAP
890 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
891 .procname = "swap_token_timeout",
892 .data = &swap_token_default_timeout,
893 .maxlen = sizeof(swap_token_default_timeout),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec_jiffies,
896 .strategy = &sysctl_jiffies,
898 #endif
899 #ifdef CONFIG_NUMA
901 .ctl_name = VM_ZONE_RECLAIM_MODE,
902 .procname = "zone_reclaim_mode",
903 .data = &zone_reclaim_mode,
904 .maxlen = sizeof(zone_reclaim_mode),
905 .mode = 0644,
906 .proc_handler = &proc_dointvec,
907 .strategy = &sysctl_intvec,
908 .extra1 = &zero,
911 .ctl_name = VM_ZONE_RECLAIM_INTERVAL,
912 .procname = "zone_reclaim_interval",
913 .data = &zone_reclaim_interval,
914 .maxlen = sizeof(zone_reclaim_interval),
915 .mode = 0644,
916 .proc_handler = &proc_dointvec_jiffies,
917 .strategy = &sysctl_jiffies,
919 #endif
920 { .ctl_name = 0 }
923 static ctl_table fs_table[] = {
925 .ctl_name = FS_NRINODE,
926 .procname = "inode-nr",
927 .data = &inodes_stat,
928 .maxlen = 2*sizeof(int),
929 .mode = 0444,
930 .proc_handler = &proc_dointvec,
933 .ctl_name = FS_STATINODE,
934 .procname = "inode-state",
935 .data = &inodes_stat,
936 .maxlen = 7*sizeof(int),
937 .mode = 0444,
938 .proc_handler = &proc_dointvec,
941 .ctl_name = FS_NRFILE,
942 .procname = "file-nr",
943 .data = &files_stat,
944 .maxlen = 3*sizeof(int),
945 .mode = 0444,
946 .proc_handler = &proc_nr_files,
949 .ctl_name = FS_MAXFILE,
950 .procname = "file-max",
951 .data = &files_stat.max_files,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
957 .ctl_name = FS_DENTRY,
958 .procname = "dentry-state",
959 .data = &dentry_stat,
960 .maxlen = 6*sizeof(int),
961 .mode = 0444,
962 .proc_handler = &proc_dointvec,
965 .ctl_name = FS_OVERFLOWUID,
966 .procname = "overflowuid",
967 .data = &fs_overflowuid,
968 .maxlen = sizeof(int),
969 .mode = 0644,
970 .proc_handler = &proc_dointvec_minmax,
971 .strategy = &sysctl_intvec,
972 .extra1 = &minolduid,
973 .extra2 = &maxolduid,
976 .ctl_name = FS_OVERFLOWGID,
977 .procname = "overflowgid",
978 .data = &fs_overflowgid,
979 .maxlen = sizeof(int),
980 .mode = 0644,
981 .proc_handler = &proc_dointvec_minmax,
982 .strategy = &sysctl_intvec,
983 .extra1 = &minolduid,
984 .extra2 = &maxolduid,
987 .ctl_name = FS_LEASES,
988 .procname = "leases-enable",
989 .data = &leases_enable,
990 .maxlen = sizeof(int),
991 .mode = 0644,
992 .proc_handler = &proc_dointvec,
994 #ifdef CONFIG_DNOTIFY
996 .ctl_name = FS_DIR_NOTIFY,
997 .procname = "dir-notify-enable",
998 .data = &dir_notify_enable,
999 .maxlen = sizeof(int),
1000 .mode = 0644,
1001 .proc_handler = &proc_dointvec,
1003 #endif
1004 #ifdef CONFIG_MMU
1006 .ctl_name = FS_LEASE_TIME,
1007 .procname = "lease-break-time",
1008 .data = &lease_break_time,
1009 .maxlen = sizeof(int),
1010 .mode = 0644,
1011 .proc_handler = &proc_dointvec,
1014 .ctl_name = FS_AIO_NR,
1015 .procname = "aio-nr",
1016 .data = &aio_nr,
1017 .maxlen = sizeof(aio_nr),
1018 .mode = 0444,
1019 .proc_handler = &proc_doulongvec_minmax,
1022 .ctl_name = FS_AIO_MAX_NR,
1023 .procname = "aio-max-nr",
1024 .data = &aio_max_nr,
1025 .maxlen = sizeof(aio_max_nr),
1026 .mode = 0644,
1027 .proc_handler = &proc_doulongvec_minmax,
1029 #ifdef CONFIG_INOTIFY_USER
1031 .ctl_name = FS_INOTIFY,
1032 .procname = "inotify",
1033 .mode = 0555,
1034 .child = inotify_table,
1036 #endif
1037 #endif
1039 .ctl_name = KERN_SETUID_DUMPABLE,
1040 .procname = "suid_dumpable",
1041 .data = &suid_dumpable,
1042 .maxlen = sizeof(int),
1043 .mode = 0644,
1044 .proc_handler = &proc_dointvec,
1046 { .ctl_name = 0 }
1049 static ctl_table debug_table[] = {
1050 { .ctl_name = 0 }
1053 static ctl_table dev_table[] = {
1054 { .ctl_name = 0 }
1057 extern void init_irq_proc (void);
1059 static DEFINE_SPINLOCK(sysctl_lock);
1061 /* called under sysctl_lock */
1062 static int use_table(struct ctl_table_header *p)
1064 if (unlikely(p->unregistering))
1065 return 0;
1066 p->used++;
1067 return 1;
1070 /* called under sysctl_lock */
1071 static void unuse_table(struct ctl_table_header *p)
1073 if (!--p->used)
1074 if (unlikely(p->unregistering))
1075 complete(p->unregistering);
1078 /* called under sysctl_lock, will reacquire if has to wait */
1079 static void start_unregistering(struct ctl_table_header *p)
1082 * if p->used is 0, nobody will ever touch that entry again;
1083 * we'll eliminate all paths to it before dropping sysctl_lock
1085 if (unlikely(p->used)) {
1086 struct completion wait;
1087 init_completion(&wait);
1088 p->unregistering = &wait;
1089 spin_unlock(&sysctl_lock);
1090 wait_for_completion(&wait);
1091 spin_lock(&sysctl_lock);
1094 * do not remove from the list until nobody holds it; walking the
1095 * list in do_sysctl() relies on that.
1097 list_del_init(&p->ctl_entry);
1100 void __init sysctl_init(void)
1102 #ifdef CONFIG_PROC_FS
1103 register_proc_table(root_table, proc_sys_root, &root_table_header);
1104 init_irq_proc();
1105 #endif
1108 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1109 void __user *newval, size_t newlen)
1111 struct list_head *tmp;
1112 int error = -ENOTDIR;
1114 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1115 return -ENOTDIR;
1116 if (oldval) {
1117 int old_len;
1118 if (!oldlenp || get_user(old_len, oldlenp))
1119 return -EFAULT;
1121 spin_lock(&sysctl_lock);
1122 tmp = &root_table_header.ctl_entry;
1123 do {
1124 struct ctl_table_header *head =
1125 list_entry(tmp, struct ctl_table_header, ctl_entry);
1126 void *context = NULL;
1128 if (!use_table(head))
1129 continue;
1131 spin_unlock(&sysctl_lock);
1133 error = parse_table(name, nlen, oldval, oldlenp,
1134 newval, newlen, head->ctl_table,
1135 &context);
1136 kfree(context);
1138 spin_lock(&sysctl_lock);
1139 unuse_table(head);
1140 if (error != -ENOTDIR)
1141 break;
1142 } while ((tmp = tmp->next) != &root_table_header.ctl_entry);
1143 spin_unlock(&sysctl_lock);
1144 return error;
1147 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1149 struct __sysctl_args tmp;
1150 int error;
1152 if (copy_from_user(&tmp, args, sizeof(tmp)))
1153 return -EFAULT;
1155 lock_kernel();
1156 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1157 tmp.newval, tmp.newlen);
1158 unlock_kernel();
1159 return error;
1163 * ctl_perm does NOT grant the superuser all rights automatically, because
1164 * some sysctl variables are readonly even to root.
1167 static int test_perm(int mode, int op)
1169 if (!current->euid)
1170 mode >>= 6;
1171 else if (in_egroup_p(0))
1172 mode >>= 3;
1173 if ((mode & op & 0007) == op)
1174 return 0;
1175 return -EACCES;
1178 static inline int ctl_perm(ctl_table *table, int op)
1180 int error;
1181 error = security_sysctl(table, op);
1182 if (error)
1183 return error;
1184 return test_perm(table->mode, op);
1187 static int parse_table(int __user *name, int nlen,
1188 void __user *oldval, size_t __user *oldlenp,
1189 void __user *newval, size_t newlen,
1190 ctl_table *table, void **context)
1192 int n;
1193 repeat:
1194 if (!nlen)
1195 return -ENOTDIR;
1196 if (get_user(n, name))
1197 return -EFAULT;
1198 for ( ; table->ctl_name; table++) {
1199 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1200 int error;
1201 if (table->child) {
1202 if (ctl_perm(table, 001))
1203 return -EPERM;
1204 if (table->strategy) {
1205 error = table->strategy(
1206 table, name, nlen,
1207 oldval, oldlenp,
1208 newval, newlen, context);
1209 if (error)
1210 return error;
1212 name++;
1213 nlen--;
1214 table = table->child;
1215 goto repeat;
1217 error = do_sysctl_strategy(table, name, nlen,
1218 oldval, oldlenp,
1219 newval, newlen, context);
1220 return error;
1223 return -ENOTDIR;
1226 /* Perform the actual read/write of a sysctl table entry. */
1227 int do_sysctl_strategy (ctl_table *table,
1228 int __user *name, int nlen,
1229 void __user *oldval, size_t __user *oldlenp,
1230 void __user *newval, size_t newlen, void **context)
1232 int op = 0, rc;
1233 size_t len;
1235 if (oldval)
1236 op |= 004;
1237 if (newval)
1238 op |= 002;
1239 if (ctl_perm(table, op))
1240 return -EPERM;
1242 if (table->strategy) {
1243 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1244 newval, newlen, context);
1245 if (rc < 0)
1246 return rc;
1247 if (rc > 0)
1248 return 0;
1251 /* If there is no strategy routine, or if the strategy returns
1252 * zero, proceed with automatic r/w */
1253 if (table->data && table->maxlen) {
1254 if (oldval && oldlenp) {
1255 if (get_user(len, oldlenp))
1256 return -EFAULT;
1257 if (len) {
1258 if (len > table->maxlen)
1259 len = table->maxlen;
1260 if(copy_to_user(oldval, table->data, len))
1261 return -EFAULT;
1262 if(put_user(len, oldlenp))
1263 return -EFAULT;
1266 if (newval && newlen) {
1267 len = newlen;
1268 if (len > table->maxlen)
1269 len = table->maxlen;
1270 if(copy_from_user(table->data, newval, len))
1271 return -EFAULT;
1274 return 0;
1278 * register_sysctl_table - register a sysctl hierarchy
1279 * @table: the top-level table structure
1280 * @insert_at_head: whether the entry should be inserted in front or at the end
1282 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1283 * array. An entry with a ctl_name of 0 terminates the table.
1285 * The members of the &ctl_table structure are used as follows:
1287 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1288 * must be unique within that level of sysctl
1290 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1291 * enter a sysctl file
1293 * data - a pointer to data for use by proc_handler
1295 * maxlen - the maximum size in bytes of the data
1297 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1299 * child - a pointer to the child sysctl table if this entry is a directory, or
1300 * %NULL.
1302 * proc_handler - the text handler routine (described below)
1304 * strategy - the strategy routine (described below)
1306 * de - for internal use by the sysctl routines
1308 * extra1, extra2 - extra pointers usable by the proc handler routines
1310 * Leaf nodes in the sysctl tree will be represented by a single file
1311 * under /proc; non-leaf nodes will be represented by directories.
1313 * sysctl(2) can automatically manage read and write requests through
1314 * the sysctl table. The data and maxlen fields of the ctl_table
1315 * struct enable minimal validation of the values being written to be
1316 * performed, and the mode field allows minimal authentication.
1318 * More sophisticated management can be enabled by the provision of a
1319 * strategy routine with the table entry. This will be called before
1320 * any automatic read or write of the data is performed.
1322 * The strategy routine may return
1324 * < 0 - Error occurred (error is passed to user process)
1326 * 0 - OK - proceed with automatic read or write.
1328 * > 0 - OK - read or write has been done by the strategy routine, so
1329 * return immediately.
1331 * There must be a proc_handler routine for any terminal nodes
1332 * mirrored under /proc/sys (non-terminals are handled by a built-in
1333 * directory handler). Several default handlers are available to
1334 * cover common cases -
1336 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1337 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1338 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1340 * It is the handler's job to read the input buffer from user memory
1341 * and process it. The handler should return 0 on success.
1343 * This routine returns %NULL on a failure to register, and a pointer
1344 * to the table header on success.
1346 struct ctl_table_header *register_sysctl_table(ctl_table * table,
1347 int insert_at_head)
1349 struct ctl_table_header *tmp;
1350 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1351 if (!tmp)
1352 return NULL;
1353 tmp->ctl_table = table;
1354 INIT_LIST_HEAD(&tmp->ctl_entry);
1355 tmp->used = 0;
1356 tmp->unregistering = NULL;
1357 spin_lock(&sysctl_lock);
1358 if (insert_at_head)
1359 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1360 else
1361 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1362 spin_unlock(&sysctl_lock);
1363 #ifdef CONFIG_PROC_FS
1364 register_proc_table(table, proc_sys_root, tmp);
1365 #endif
1366 return tmp;
1370 * unregister_sysctl_table - unregister a sysctl table hierarchy
1371 * @header: the header returned from register_sysctl_table
1373 * Unregisters the sysctl table and all children. proc entries may not
1374 * actually be removed until they are no longer used by anyone.
1376 void unregister_sysctl_table(struct ctl_table_header * header)
1378 might_sleep();
1379 spin_lock(&sysctl_lock);
1380 start_unregistering(header);
1381 #ifdef CONFIG_PROC_FS
1382 unregister_proc_table(header->ctl_table, proc_sys_root);
1383 #endif
1384 spin_unlock(&sysctl_lock);
1385 kfree(header);
1389 * /proc/sys support
1392 #ifdef CONFIG_PROC_FS
1394 /* Scan the sysctl entries in table and add them all into /proc */
1395 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root, void *set)
1397 struct proc_dir_entry *de;
1398 int len;
1399 mode_t mode;
1401 for (; table->ctl_name; table++) {
1402 /* Can't do anything without a proc name. */
1403 if (!table->procname)
1404 continue;
1405 /* Maybe we can't do anything with it... */
1406 if (!table->proc_handler && !table->child) {
1407 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1408 table->procname);
1409 continue;
1412 len = strlen(table->procname);
1413 mode = table->mode;
1415 de = NULL;
1416 if (table->proc_handler)
1417 mode |= S_IFREG;
1418 else {
1419 mode |= S_IFDIR;
1420 for (de = root->subdir; de; de = de->next) {
1421 if (proc_match(len, table->procname, de))
1422 break;
1424 /* If the subdir exists already, de is non-NULL */
1427 if (!de) {
1428 de = create_proc_entry(table->procname, mode, root);
1429 if (!de)
1430 continue;
1431 de->set = set;
1432 de->data = (void *) table;
1433 if (table->proc_handler)
1434 de->proc_fops = &proc_sys_file_operations;
1436 table->de = de;
1437 if (de->mode & S_IFDIR)
1438 register_proc_table(table->child, de, set);
1443 * Unregister a /proc sysctl table and any subdirectories.
1445 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1447 struct proc_dir_entry *de;
1448 for (; table->ctl_name; table++) {
1449 if (!(de = table->de))
1450 continue;
1451 if (de->mode & S_IFDIR) {
1452 if (!table->child) {
1453 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1454 continue;
1456 unregister_proc_table(table->child, de);
1458 /* Don't unregister directories which still have entries.. */
1459 if (de->subdir)
1460 continue;
1464 * In any case, mark the entry as goner; we'll keep it
1465 * around if it's busy, but we'll know to do nothing with
1466 * its fields. We are under sysctl_lock here.
1468 de->data = NULL;
1470 /* Don't unregister proc entries that are still being used.. */
1471 if (atomic_read(&de->count))
1472 continue;
1474 table->de = NULL;
1475 remove_proc_entry(table->procname, root);
1479 static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1480 size_t count, loff_t *ppos)
1482 int op;
1483 struct proc_dir_entry *de = PDE(file->f_dentry->d_inode);
1484 struct ctl_table *table;
1485 size_t res;
1486 ssize_t error = -ENOTDIR;
1488 spin_lock(&sysctl_lock);
1489 if (de && de->data && use_table(de->set)) {
1491 * at that point we know that sysctl was not unregistered
1492 * and won't be until we finish
1494 spin_unlock(&sysctl_lock);
1495 table = (struct ctl_table *) de->data;
1496 if (!table || !table->proc_handler)
1497 goto out;
1498 error = -EPERM;
1499 op = (write ? 002 : 004);
1500 if (ctl_perm(table, op))
1501 goto out;
1503 /* careful: calling conventions are nasty here */
1504 res = count;
1505 error = (*table->proc_handler)(table, write, file,
1506 buf, &res, ppos);
1507 if (!error)
1508 error = res;
1509 out:
1510 spin_lock(&sysctl_lock);
1511 unuse_table(de->set);
1513 spin_unlock(&sysctl_lock);
1514 return error;
1517 static int proc_opensys(struct inode *inode, struct file *file)
1519 if (file->f_mode & FMODE_WRITE) {
1521 * sysctl entries that are not writable,
1522 * are _NOT_ writable, capabilities or not.
1524 if (!(inode->i_mode & S_IWUSR))
1525 return -EPERM;
1528 return 0;
1531 static ssize_t proc_readsys(struct file * file, char __user * buf,
1532 size_t count, loff_t *ppos)
1534 return do_rw_proc(0, file, buf, count, ppos);
1537 static ssize_t proc_writesys(struct file * file, const char __user * buf,
1538 size_t count, loff_t *ppos)
1540 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1544 * proc_dostring - read a string sysctl
1545 * @table: the sysctl table
1546 * @write: %TRUE if this is a write to the sysctl file
1547 * @filp: the file structure
1548 * @buffer: the user buffer
1549 * @lenp: the size of the user buffer
1550 * @ppos: file position
1552 * Reads/writes a string from/to the user buffer. If the kernel
1553 * buffer provided is not large enough to hold the string, the
1554 * string is truncated. The copied string is %NULL-terminated.
1555 * If the string is being read by the user process, it is copied
1556 * and a newline '\n' is added. It is truncated if the buffer is
1557 * not large enough.
1559 * Returns 0 on success.
1561 int proc_dostring(ctl_table *table, int write, struct file *filp,
1562 void __user *buffer, size_t *lenp, loff_t *ppos)
1564 size_t len;
1565 char __user *p;
1566 char c;
1568 if (!table->data || !table->maxlen || !*lenp ||
1569 (*ppos && !write)) {
1570 *lenp = 0;
1571 return 0;
1574 if (write) {
1575 len = 0;
1576 p = buffer;
1577 while (len < *lenp) {
1578 if (get_user(c, p++))
1579 return -EFAULT;
1580 if (c == 0 || c == '\n')
1581 break;
1582 len++;
1584 if (len >= table->maxlen)
1585 len = table->maxlen-1;
1586 if(copy_from_user(table->data, buffer, len))
1587 return -EFAULT;
1588 ((char *) table->data)[len] = 0;
1589 *ppos += *lenp;
1590 } else {
1591 len = strlen(table->data);
1592 if (len > table->maxlen)
1593 len = table->maxlen;
1594 if (len > *lenp)
1595 len = *lenp;
1596 if (len)
1597 if(copy_to_user(buffer, table->data, len))
1598 return -EFAULT;
1599 if (len < *lenp) {
1600 if(put_user('\n', ((char __user *) buffer) + len))
1601 return -EFAULT;
1602 len++;
1604 *lenp = len;
1605 *ppos += len;
1607 return 0;
1611 * Special case of dostring for the UTS structure. This has locks
1612 * to observe. Should this be in kernel/sys.c ????
1615 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1616 void __user *buffer, size_t *lenp, loff_t *ppos)
1618 int r;
1620 if (!write) {
1621 down_read(&uts_sem);
1622 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1623 up_read(&uts_sem);
1624 } else {
1625 down_write(&uts_sem);
1626 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1627 up_write(&uts_sem);
1629 return r;
1632 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1633 int *valp,
1634 int write, void *data)
1636 if (write) {
1637 *valp = *negp ? -*lvalp : *lvalp;
1638 } else {
1639 int val = *valp;
1640 if (val < 0) {
1641 *negp = -1;
1642 *lvalp = (unsigned long)-val;
1643 } else {
1644 *negp = 0;
1645 *lvalp = (unsigned long)val;
1648 return 0;
1651 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1652 void __user *buffer, size_t *lenp, loff_t *ppos,
1653 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1654 int write, void *data),
1655 void *data)
1657 #define TMPBUFLEN 21
1658 int *i, vleft, first=1, neg, val;
1659 unsigned long lval;
1660 size_t left, len;
1662 char buf[TMPBUFLEN], *p;
1663 char __user *s = buffer;
1665 if (!table->data || !table->maxlen || !*lenp ||
1666 (*ppos && !write)) {
1667 *lenp = 0;
1668 return 0;
1671 i = (int *) table->data;
1672 vleft = table->maxlen / sizeof(*i);
1673 left = *lenp;
1675 if (!conv)
1676 conv = do_proc_dointvec_conv;
1678 for (; left && vleft--; i++, first=0) {
1679 if (write) {
1680 while (left) {
1681 char c;
1682 if (get_user(c, s))
1683 return -EFAULT;
1684 if (!isspace(c))
1685 break;
1686 left--;
1687 s++;
1689 if (!left)
1690 break;
1691 neg = 0;
1692 len = left;
1693 if (len > sizeof(buf) - 1)
1694 len = sizeof(buf) - 1;
1695 if (copy_from_user(buf, s, len))
1696 return -EFAULT;
1697 buf[len] = 0;
1698 p = buf;
1699 if (*p == '-' && left > 1) {
1700 neg = 1;
1701 left--, p++;
1703 if (*p < '0' || *p > '9')
1704 break;
1706 lval = simple_strtoul(p, &p, 0);
1708 len = p-buf;
1709 if ((len < left) && *p && !isspace(*p))
1710 break;
1711 if (neg)
1712 val = -val;
1713 s += len;
1714 left -= len;
1716 if (conv(&neg, &lval, i, 1, data))
1717 break;
1718 } else {
1719 p = buf;
1720 if (!first)
1721 *p++ = '\t';
1723 if (conv(&neg, &lval, i, 0, data))
1724 break;
1726 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1727 len = strlen(buf);
1728 if (len > left)
1729 len = left;
1730 if(copy_to_user(s, buf, len))
1731 return -EFAULT;
1732 left -= len;
1733 s += len;
1737 if (!write && !first && left) {
1738 if(put_user('\n', s))
1739 return -EFAULT;
1740 left--, s++;
1742 if (write) {
1743 while (left) {
1744 char c;
1745 if (get_user(c, s++))
1746 return -EFAULT;
1747 if (!isspace(c))
1748 break;
1749 left--;
1752 if (write && first)
1753 return -EINVAL;
1754 *lenp -= left;
1755 *ppos += *lenp;
1756 return 0;
1757 #undef TMPBUFLEN
1761 * proc_dointvec - read a vector of integers
1762 * @table: the sysctl table
1763 * @write: %TRUE if this is a write to the sysctl file
1764 * @filp: the file structure
1765 * @buffer: the user buffer
1766 * @lenp: the size of the user buffer
1767 * @ppos: file position
1769 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1770 * values from/to the user buffer, treated as an ASCII string.
1772 * Returns 0 on success.
1774 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1775 void __user *buffer, size_t *lenp, loff_t *ppos)
1777 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1778 NULL,NULL);
1781 #define OP_SET 0
1782 #define OP_AND 1
1783 #define OP_OR 2
1784 #define OP_MAX 3
1785 #define OP_MIN 4
1787 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1788 int *valp,
1789 int write, void *data)
1791 int op = *(int *)data;
1792 if (write) {
1793 int val = *negp ? -*lvalp : *lvalp;
1794 switch(op) {
1795 case OP_SET: *valp = val; break;
1796 case OP_AND: *valp &= val; break;
1797 case OP_OR: *valp |= val; break;
1798 case OP_MAX: if(*valp < val)
1799 *valp = val;
1800 break;
1801 case OP_MIN: if(*valp > val)
1802 *valp = val;
1803 break;
1805 } else {
1806 int val = *valp;
1807 if (val < 0) {
1808 *negp = -1;
1809 *lvalp = (unsigned long)-val;
1810 } else {
1811 *negp = 0;
1812 *lvalp = (unsigned long)val;
1815 return 0;
1819 * init may raise the set.
1822 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1823 void __user *buffer, size_t *lenp, loff_t *ppos)
1825 int op;
1827 if (!capable(CAP_SYS_MODULE)) {
1828 return -EPERM;
1831 op = (current->pid == 1) ? OP_SET : OP_AND;
1832 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1833 do_proc_dointvec_bset_conv,&op);
1836 struct do_proc_dointvec_minmax_conv_param {
1837 int *min;
1838 int *max;
1841 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1842 int *valp,
1843 int write, void *data)
1845 struct do_proc_dointvec_minmax_conv_param *param = data;
1846 if (write) {
1847 int val = *negp ? -*lvalp : *lvalp;
1848 if ((param->min && *param->min > val) ||
1849 (param->max && *param->max < val))
1850 return -EINVAL;
1851 *valp = val;
1852 } else {
1853 int val = *valp;
1854 if (val < 0) {
1855 *negp = -1;
1856 *lvalp = (unsigned long)-val;
1857 } else {
1858 *negp = 0;
1859 *lvalp = (unsigned long)val;
1862 return 0;
1866 * proc_dointvec_minmax - read a vector of integers with min/max values
1867 * @table: the sysctl table
1868 * @write: %TRUE if this is a write to the sysctl file
1869 * @filp: the file structure
1870 * @buffer: the user buffer
1871 * @lenp: the size of the user buffer
1872 * @ppos: file position
1874 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1875 * values from/to the user buffer, treated as an ASCII string.
1877 * This routine will ensure the values are within the range specified by
1878 * table->extra1 (min) and table->extra2 (max).
1880 * Returns 0 on success.
1882 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1883 void __user *buffer, size_t *lenp, loff_t *ppos)
1885 struct do_proc_dointvec_minmax_conv_param param = {
1886 .min = (int *) table->extra1,
1887 .max = (int *) table->extra2,
1889 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1890 do_proc_dointvec_minmax_conv, &param);
1893 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1894 struct file *filp,
1895 void __user *buffer,
1896 size_t *lenp, loff_t *ppos,
1897 unsigned long convmul,
1898 unsigned long convdiv)
1900 #define TMPBUFLEN 21
1901 unsigned long *i, *min, *max, val;
1902 int vleft, first=1, neg;
1903 size_t len, left;
1904 char buf[TMPBUFLEN], *p;
1905 char __user *s = buffer;
1907 if (!table->data || !table->maxlen || !*lenp ||
1908 (*ppos && !write)) {
1909 *lenp = 0;
1910 return 0;
1913 i = (unsigned long *) table->data;
1914 min = (unsigned long *) table->extra1;
1915 max = (unsigned long *) table->extra2;
1916 vleft = table->maxlen / sizeof(unsigned long);
1917 left = *lenp;
1919 for (; left && vleft--; i++, min++, max++, first=0) {
1920 if (write) {
1921 while (left) {
1922 char c;
1923 if (get_user(c, s))
1924 return -EFAULT;
1925 if (!isspace(c))
1926 break;
1927 left--;
1928 s++;
1930 if (!left)
1931 break;
1932 neg = 0;
1933 len = left;
1934 if (len > TMPBUFLEN-1)
1935 len = TMPBUFLEN-1;
1936 if (copy_from_user(buf, s, len))
1937 return -EFAULT;
1938 buf[len] = 0;
1939 p = buf;
1940 if (*p == '-' && left > 1) {
1941 neg = 1;
1942 left--, p++;
1944 if (*p < '0' || *p > '9')
1945 break;
1946 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1947 len = p-buf;
1948 if ((len < left) && *p && !isspace(*p))
1949 break;
1950 if (neg)
1951 val = -val;
1952 s += len;
1953 left -= len;
1955 if(neg)
1956 continue;
1957 if ((min && val < *min) || (max && val > *max))
1958 continue;
1959 *i = val;
1960 } else {
1961 p = buf;
1962 if (!first)
1963 *p++ = '\t';
1964 sprintf(p, "%lu", convdiv * (*i) / convmul);
1965 len = strlen(buf);
1966 if (len > left)
1967 len = left;
1968 if(copy_to_user(s, buf, len))
1969 return -EFAULT;
1970 left -= len;
1971 s += len;
1975 if (!write && !first && left) {
1976 if(put_user('\n', s))
1977 return -EFAULT;
1978 left--, s++;
1980 if (write) {
1981 while (left) {
1982 char c;
1983 if (get_user(c, s++))
1984 return -EFAULT;
1985 if (!isspace(c))
1986 break;
1987 left--;
1990 if (write && first)
1991 return -EINVAL;
1992 *lenp -= left;
1993 *ppos += *lenp;
1994 return 0;
1995 #undef TMPBUFLEN
1999 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2000 * @table: the sysctl table
2001 * @write: %TRUE if this is a write to the sysctl file
2002 * @filp: the file structure
2003 * @buffer: the user buffer
2004 * @lenp: the size of the user buffer
2005 * @ppos: file position
2007 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2008 * values from/to the user buffer, treated as an ASCII string.
2010 * This routine will ensure the values are within the range specified by
2011 * table->extra1 (min) and table->extra2 (max).
2013 * Returns 0 on success.
2015 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2016 void __user *buffer, size_t *lenp, loff_t *ppos)
2018 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2022 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2023 * @table: the sysctl table
2024 * @write: %TRUE if this is a write to the sysctl file
2025 * @filp: the file structure
2026 * @buffer: the user buffer
2027 * @lenp: the size of the user buffer
2028 * @ppos: file position
2030 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2031 * values from/to the user buffer, treated as an ASCII string. The values
2032 * are treated as milliseconds, and converted to jiffies when they are stored.
2034 * This routine will ensure the values are within the range specified by
2035 * table->extra1 (min) and table->extra2 (max).
2037 * Returns 0 on success.
2039 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2040 struct file *filp,
2041 void __user *buffer,
2042 size_t *lenp, loff_t *ppos)
2044 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2045 lenp, ppos, HZ, 1000l);
2049 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2050 int *valp,
2051 int write, void *data)
2053 if (write) {
2054 if (*lvalp > LONG_MAX / HZ)
2055 return 1;
2056 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2057 } else {
2058 int val = *valp;
2059 unsigned long lval;
2060 if (val < 0) {
2061 *negp = -1;
2062 lval = (unsigned long)-val;
2063 } else {
2064 *negp = 0;
2065 lval = (unsigned long)val;
2067 *lvalp = lval / HZ;
2069 return 0;
2072 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2073 int *valp,
2074 int write, void *data)
2076 if (write) {
2077 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2078 return 1;
2079 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2080 } else {
2081 int val = *valp;
2082 unsigned long lval;
2083 if (val < 0) {
2084 *negp = -1;
2085 lval = (unsigned long)-val;
2086 } else {
2087 *negp = 0;
2088 lval = (unsigned long)val;
2090 *lvalp = jiffies_to_clock_t(lval);
2092 return 0;
2095 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2096 int *valp,
2097 int write, void *data)
2099 if (write) {
2100 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2101 } else {
2102 int val = *valp;
2103 unsigned long lval;
2104 if (val < 0) {
2105 *negp = -1;
2106 lval = (unsigned long)-val;
2107 } else {
2108 *negp = 0;
2109 lval = (unsigned long)val;
2111 *lvalp = jiffies_to_msecs(lval);
2113 return 0;
2117 * proc_dointvec_jiffies - read a vector of integers as seconds
2118 * @table: the sysctl table
2119 * @write: %TRUE if this is a write to the sysctl file
2120 * @filp: the file structure
2121 * @buffer: the user buffer
2122 * @lenp: the size of the user buffer
2123 * @ppos: file position
2125 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2126 * values from/to the user buffer, treated as an ASCII string.
2127 * The values read are assumed to be in seconds, and are converted into
2128 * jiffies.
2130 * Returns 0 on success.
2132 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2133 void __user *buffer, size_t *lenp, loff_t *ppos)
2135 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2136 do_proc_dointvec_jiffies_conv,NULL);
2140 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2141 * @table: the sysctl table
2142 * @write: %TRUE if this is a write to the sysctl file
2143 * @filp: the file structure
2144 * @buffer: the user buffer
2145 * @lenp: the size of the user buffer
2146 * @ppos: pointer to the file position
2148 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2149 * values from/to the user buffer, treated as an ASCII string.
2150 * The values read are assumed to be in 1/USER_HZ seconds, and
2151 * are converted into jiffies.
2153 * Returns 0 on success.
2155 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2156 void __user *buffer, size_t *lenp, loff_t *ppos)
2158 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2159 do_proc_dointvec_userhz_jiffies_conv,NULL);
2163 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2164 * @table: the sysctl table
2165 * @write: %TRUE if this is a write to the sysctl file
2166 * @filp: the file structure
2167 * @buffer: the user buffer
2168 * @lenp: the size of the user buffer
2169 * @ppos: file position
2170 * @ppos: the current position in the file
2172 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2173 * values from/to the user buffer, treated as an ASCII string.
2174 * The values read are assumed to be in 1/1000 seconds, and
2175 * are converted into jiffies.
2177 * Returns 0 on success.
2179 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2180 void __user *buffer, size_t *lenp, loff_t *ppos)
2182 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2183 do_proc_dointvec_ms_jiffies_conv, NULL);
2186 #else /* CONFIG_PROC_FS */
2188 int proc_dostring(ctl_table *table, int write, struct file *filp,
2189 void __user *buffer, size_t *lenp, loff_t *ppos)
2191 return -ENOSYS;
2194 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2195 void __user *buffer, size_t *lenp, loff_t *ppos)
2197 return -ENOSYS;
2200 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2201 void __user *buffer, size_t *lenp, loff_t *ppos)
2203 return -ENOSYS;
2206 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2207 void __user *buffer, size_t *lenp, loff_t *ppos)
2209 return -ENOSYS;
2212 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2213 void __user *buffer, size_t *lenp, loff_t *ppos)
2215 return -ENOSYS;
2218 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2219 void __user *buffer, size_t *lenp, loff_t *ppos)
2221 return -ENOSYS;
2224 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2225 void __user *buffer, size_t *lenp, loff_t *ppos)
2227 return -ENOSYS;
2230 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2231 void __user *buffer, size_t *lenp, loff_t *ppos)
2233 return -ENOSYS;
2236 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2237 void __user *buffer, size_t *lenp, loff_t *ppos)
2239 return -ENOSYS;
2242 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2243 struct file *filp,
2244 void __user *buffer,
2245 size_t *lenp, loff_t *ppos)
2247 return -ENOSYS;
2251 #endif /* CONFIG_PROC_FS */
2255 * General sysctl support routines
2258 /* The generic string strategy routine: */
2259 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2260 void __user *oldval, size_t __user *oldlenp,
2261 void __user *newval, size_t newlen, void **context)
2263 if (!table->data || !table->maxlen)
2264 return -ENOTDIR;
2266 if (oldval && oldlenp) {
2267 size_t bufsize;
2268 if (get_user(bufsize, oldlenp))
2269 return -EFAULT;
2270 if (bufsize) {
2271 size_t len = strlen(table->data), copied;
2273 /* This shouldn't trigger for a well-formed sysctl */
2274 if (len > table->maxlen)
2275 len = table->maxlen;
2277 /* Copy up to a max of bufsize-1 bytes of the string */
2278 copied = (len >= bufsize) ? bufsize - 1 : len;
2280 if (copy_to_user(oldval, table->data, copied) ||
2281 put_user(0, (char __user *)(oldval + copied)))
2282 return -EFAULT;
2283 if (put_user(len, oldlenp))
2284 return -EFAULT;
2287 if (newval && newlen) {
2288 size_t len = newlen;
2289 if (len > table->maxlen)
2290 len = table->maxlen;
2291 if(copy_from_user(table->data, newval, len))
2292 return -EFAULT;
2293 if (len == table->maxlen)
2294 len--;
2295 ((char *) table->data)[len] = 0;
2297 return 1;
2301 * This function makes sure that all of the integers in the vector
2302 * are between the minimum and maximum values given in the arrays
2303 * table->extra1 and table->extra2, respectively.
2305 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2306 void __user *oldval, size_t __user *oldlenp,
2307 void __user *newval, size_t newlen, void **context)
2310 if (newval && newlen) {
2311 int __user *vec = (int __user *) newval;
2312 int *min = (int *) table->extra1;
2313 int *max = (int *) table->extra2;
2314 size_t length;
2315 int i;
2317 if (newlen % sizeof(int) != 0)
2318 return -EINVAL;
2320 if (!table->extra1 && !table->extra2)
2321 return 0;
2323 if (newlen > table->maxlen)
2324 newlen = table->maxlen;
2325 length = newlen / sizeof(int);
2327 for (i = 0; i < length; i++) {
2328 int value;
2329 if (get_user(value, vec + i))
2330 return -EFAULT;
2331 if (min && value < min[i])
2332 return -EINVAL;
2333 if (max && value > max[i])
2334 return -EINVAL;
2337 return 0;
2340 /* Strategy function to convert jiffies to seconds */
2341 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2342 void __user *oldval, size_t __user *oldlenp,
2343 void __user *newval, size_t newlen, void **context)
2345 if (oldval) {
2346 size_t olen;
2347 if (oldlenp) {
2348 if (get_user(olen, oldlenp))
2349 return -EFAULT;
2350 if (olen!=sizeof(int))
2351 return -EINVAL;
2353 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2354 (oldlenp && put_user(sizeof(int),oldlenp)))
2355 return -EFAULT;
2357 if (newval && newlen) {
2358 int new;
2359 if (newlen != sizeof(int))
2360 return -EINVAL;
2361 if (get_user(new, (int __user *)newval))
2362 return -EFAULT;
2363 *(int *)(table->data) = new*HZ;
2365 return 1;
2368 /* Strategy function to convert jiffies to seconds */
2369 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2370 void __user *oldval, size_t __user *oldlenp,
2371 void __user *newval, size_t newlen, void **context)
2373 if (oldval) {
2374 size_t olen;
2375 if (oldlenp) {
2376 if (get_user(olen, oldlenp))
2377 return -EFAULT;
2378 if (olen!=sizeof(int))
2379 return -EINVAL;
2381 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2382 (oldlenp && put_user(sizeof(int),oldlenp)))
2383 return -EFAULT;
2385 if (newval && newlen) {
2386 int new;
2387 if (newlen != sizeof(int))
2388 return -EINVAL;
2389 if (get_user(new, (int __user *)newval))
2390 return -EFAULT;
2391 *(int *)(table->data) = msecs_to_jiffies(new);
2393 return 1;
2396 #else /* CONFIG_SYSCTL */
2399 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2401 return -ENOSYS;
2404 int sysctl_string(ctl_table *table, int __user *name, int nlen,
2405 void __user *oldval, size_t __user *oldlenp,
2406 void __user *newval, size_t newlen, void **context)
2408 return -ENOSYS;
2411 int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2412 void __user *oldval, size_t __user *oldlenp,
2413 void __user *newval, size_t newlen, void **context)
2415 return -ENOSYS;
2418 int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2419 void __user *oldval, size_t __user *oldlenp,
2420 void __user *newval, size_t newlen, void **context)
2422 return -ENOSYS;
2425 int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2426 void __user *oldval, size_t __user *oldlenp,
2427 void __user *newval, size_t newlen, void **context)
2429 return -ENOSYS;
2432 int proc_dostring(ctl_table *table, int write, struct file *filp,
2433 void __user *buffer, size_t *lenp, loff_t *ppos)
2435 return -ENOSYS;
2438 int proc_dointvec(ctl_table *table, int write, struct file *filp,
2439 void __user *buffer, size_t *lenp, loff_t *ppos)
2441 return -ENOSYS;
2444 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2445 void __user *buffer, size_t *lenp, loff_t *ppos)
2447 return -ENOSYS;
2450 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2451 void __user *buffer, size_t *lenp, loff_t *ppos)
2453 return -ENOSYS;
2456 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2457 void __user *buffer, size_t *lenp, loff_t *ppos)
2459 return -ENOSYS;
2462 int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2463 void __user *buffer, size_t *lenp, loff_t *ppos)
2465 return -ENOSYS;
2468 int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2469 void __user *buffer, size_t *lenp, loff_t *ppos)
2471 return -ENOSYS;
2474 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2475 void __user *buffer, size_t *lenp, loff_t *ppos)
2477 return -ENOSYS;
2480 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2481 struct file *filp,
2482 void __user *buffer,
2483 size_t *lenp, loff_t *ppos)
2485 return -ENOSYS;
2488 struct ctl_table_header * register_sysctl_table(ctl_table * table,
2489 int insert_at_head)
2491 return NULL;
2494 void unregister_sysctl_table(struct ctl_table_header * table)
2498 #endif /* CONFIG_SYSCTL */
2501 * No sense putting this after each symbol definition, twice,
2502 * exception granted :-)
2504 EXPORT_SYMBOL(proc_dointvec);
2505 EXPORT_SYMBOL(proc_dointvec_jiffies);
2506 EXPORT_SYMBOL(proc_dointvec_minmax);
2507 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2508 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2509 EXPORT_SYMBOL(proc_dostring);
2510 EXPORT_SYMBOL(proc_doulongvec_minmax);
2511 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2512 EXPORT_SYMBOL(register_sysctl_table);
2513 EXPORT_SYMBOL(sysctl_intvec);
2514 EXPORT_SYMBOL(sysctl_jiffies);
2515 EXPORT_SYMBOL(sysctl_ms_jiffies);
2516 EXPORT_SYMBOL(sysctl_string);
2517 EXPORT_SYMBOL(unregister_sysctl_table);