]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - kernel/sysctl.c
[PATCH] fix voyager subarchitecture EXPORT_SYMBOL breakage caused by i386_ksym reduction
[mirror_ubuntu-zesty-kernel.git] / kernel / sysctl.c
CommitLineData
1da177e4
LT
1/*
2 * sysctl.c: General linux system control interface
3 *
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
19 */
20
21#include <linux/config.h>
22#include <linux/module.h>
23#include <linux/mm.h>
24#include <linux/swap.h>
25#include <linux/slab.h>
26#include <linux/sysctl.h>
27#include <linux/proc_fs.h>
28#include <linux/ctype.h>
29#include <linux/utsname.h>
30#include <linux/capability.h>
31#include <linux/smp_lock.h>
32#include <linux/init.h>
33#include <linux/kernel.h>
34#include <linux/sysrq.h>
35#include <linux/highuid.h>
36#include <linux/writeback.h>
37#include <linux/hugetlb.h>
38#include <linux/security.h>
39#include <linux/initrd.h>
40#include <linux/times.h>
41#include <linux/limits.h>
42#include <linux/dcache.h>
43#include <linux/syscalls.h>
44
45#include <asm/uaccess.h>
46#include <asm/processor.h>
47
48#ifdef CONFIG_ROOT_NFS
49#include <linux/nfs_fs.h>
50#endif
51
52#if defined(CONFIG_SYSCTL)
53
54/* External variables not in a header file. */
55extern int C_A_D;
56extern int sysctl_overcommit_memory;
57extern int sysctl_overcommit_ratio;
58extern int max_threads;
59extern int sysrq_enabled;
60extern int core_uses_pid;
d6e71144 61extern int suid_dumpable;
1da177e4
LT
62extern char core_pattern[];
63extern int cad_pid;
64extern int pid_max;
65extern int min_free_kbytes;
66extern int printk_ratelimit_jiffies;
67extern int printk_ratelimit_burst;
68extern int pid_max_min, pid_max_max;
69
0eeca283
RL
70#ifdef CONFIG_INOTIFY
71extern int inotify_max_user_devices;
72extern int inotify_max_user_watches;
73extern int inotify_max_queued_events;
74#endif
75
1da177e4
LT
76#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
77int unknown_nmi_panic;
78extern int proc_unknown_nmi_panic(ctl_table *, int, struct file *,
79 void __user *, size_t *, loff_t *);
80#endif
81
82/* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
83static int maxolduid = 65535;
84static int minolduid;
85
86static int ngroups_max = NGROUPS_MAX;
87
88#ifdef CONFIG_KMOD
89extern char modprobe_path[];
90#endif
91#ifdef CONFIG_HOTPLUG
92extern char hotplug_path[];
93#endif
94#ifdef CONFIG_CHR_DEV_SG
95extern int sg_big_buff;
96#endif
97#ifdef CONFIG_SYSVIPC
98extern size_t shm_ctlmax;
99extern size_t shm_ctlall;
100extern int shm_ctlmni;
101extern int msg_ctlmax;
102extern int msg_ctlmnb;
103extern int msg_ctlmni;
104extern int sem_ctls[];
105#endif
106
107#ifdef __sparc__
108extern char reboot_command [];
109extern int stop_a_enabled;
110extern int scons_pwroff;
111#endif
112
113#ifdef __hppa__
114extern int pwrsw_enabled;
115extern int unaligned_enabled;
116#endif
117
118#ifdef CONFIG_ARCH_S390
119#ifdef CONFIG_MATHEMU
120extern int sysctl_ieee_emulation_warnings;
121#endif
122extern int sysctl_userprocess_debug;
123#endif
124
125extern int sysctl_hz_timer;
126
127#ifdef CONFIG_BSD_PROCESS_ACCT
128extern int acct_parm[];
129#endif
130
131int randomize_va_space = 1;
132
133static int parse_table(int __user *, int, void __user *, size_t __user *, void __user *, size_t,
134 ctl_table *, void **);
135static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
136 void __user *buffer, size_t *lenp, loff_t *ppos);
137
138static ctl_table root_table[];
139static struct ctl_table_header root_table_header =
140 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
141
142static ctl_table kern_table[];
143static ctl_table vm_table[];
144#ifdef CONFIG_NET
145extern ctl_table net_table[];
146#endif
147static ctl_table proc_table[];
148static ctl_table fs_table[];
149static ctl_table debug_table[];
150static ctl_table dev_table[];
151extern ctl_table random_table[];
152#ifdef CONFIG_UNIX98_PTYS
153extern ctl_table pty_table[];
154#endif
155
156#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
157int sysctl_legacy_va_layout;
158#endif
159
160/* /proc declarations: */
161
162#ifdef CONFIG_PROC_FS
163
164static ssize_t proc_readsys(struct file *, char __user *, size_t, loff_t *);
165static ssize_t proc_writesys(struct file *, const char __user *, size_t, loff_t *);
166static int proc_opensys(struct inode *, struct file *);
167
168struct file_operations proc_sys_file_operations = {
169 .open = proc_opensys,
170 .read = proc_readsys,
171 .write = proc_writesys,
172};
173
174extern struct proc_dir_entry *proc_sys_root;
175
176static void register_proc_table(ctl_table *, struct proc_dir_entry *);
177static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
178#endif
179
180/* The default sysctl tables: */
181
182static ctl_table root_table[] = {
183 {
184 .ctl_name = CTL_KERN,
185 .procname = "kernel",
186 .mode = 0555,
187 .child = kern_table,
188 },
189 {
190 .ctl_name = CTL_VM,
191 .procname = "vm",
192 .mode = 0555,
193 .child = vm_table,
194 },
195#ifdef CONFIG_NET
196 {
197 .ctl_name = CTL_NET,
198 .procname = "net",
199 .mode = 0555,
200 .child = net_table,
201 },
202#endif
203 {
204 .ctl_name = CTL_PROC,
205 .procname = "proc",
206 .mode = 0555,
207 .child = proc_table,
208 },
209 {
210 .ctl_name = CTL_FS,
211 .procname = "fs",
212 .mode = 0555,
213 .child = fs_table,
214 },
215 {
216 .ctl_name = CTL_DEBUG,
217 .procname = "debug",
218 .mode = 0555,
219 .child = debug_table,
220 },
221 {
222 .ctl_name = CTL_DEV,
223 .procname = "dev",
224 .mode = 0555,
225 .child = dev_table,
226 },
0eeca283 227
1da177e4
LT
228 { .ctl_name = 0 }
229};
230
231static ctl_table kern_table[] = {
232 {
233 .ctl_name = KERN_OSTYPE,
234 .procname = "ostype",
235 .data = system_utsname.sysname,
236 .maxlen = sizeof(system_utsname.sysname),
237 .mode = 0444,
238 .proc_handler = &proc_doutsstring,
239 .strategy = &sysctl_string,
240 },
241 {
242 .ctl_name = KERN_OSRELEASE,
243 .procname = "osrelease",
244 .data = system_utsname.release,
245 .maxlen = sizeof(system_utsname.release),
246 .mode = 0444,
247 .proc_handler = &proc_doutsstring,
248 .strategy = &sysctl_string,
249 },
250 {
251 .ctl_name = KERN_VERSION,
252 .procname = "version",
253 .data = system_utsname.version,
254 .maxlen = sizeof(system_utsname.version),
255 .mode = 0444,
256 .proc_handler = &proc_doutsstring,
257 .strategy = &sysctl_string,
258 },
259 {
260 .ctl_name = KERN_NODENAME,
261 .procname = "hostname",
262 .data = system_utsname.nodename,
263 .maxlen = sizeof(system_utsname.nodename),
264 .mode = 0644,
265 .proc_handler = &proc_doutsstring,
266 .strategy = &sysctl_string,
267 },
268 {
269 .ctl_name = KERN_DOMAINNAME,
270 .procname = "domainname",
271 .data = system_utsname.domainname,
272 .maxlen = sizeof(system_utsname.domainname),
273 .mode = 0644,
274 .proc_handler = &proc_doutsstring,
275 .strategy = &sysctl_string,
276 },
277 {
278 .ctl_name = KERN_PANIC,
279 .procname = "panic",
280 .data = &panic_timeout,
281 .maxlen = sizeof(int),
282 .mode = 0644,
283 .proc_handler = &proc_dointvec,
284 },
285 {
286 .ctl_name = KERN_CORE_USES_PID,
287 .procname = "core_uses_pid",
288 .data = &core_uses_pid,
289 .maxlen = sizeof(int),
290 .mode = 0644,
291 .proc_handler = &proc_dointvec,
292 },
293 {
294 .ctl_name = KERN_CORE_PATTERN,
295 .procname = "core_pattern",
296 .data = core_pattern,
297 .maxlen = 64,
298 .mode = 0644,
299 .proc_handler = &proc_dostring,
300 .strategy = &sysctl_string,
301 },
302 {
303 .ctl_name = KERN_TAINTED,
304 .procname = "tainted",
305 .data = &tainted,
306 .maxlen = sizeof(int),
307 .mode = 0444,
308 .proc_handler = &proc_dointvec,
309 },
310 {
311 .ctl_name = KERN_CAP_BSET,
312 .procname = "cap-bound",
313 .data = &cap_bset,
314 .maxlen = sizeof(kernel_cap_t),
315 .mode = 0600,
316 .proc_handler = &proc_dointvec_bset,
317 },
318#ifdef CONFIG_BLK_DEV_INITRD
319 {
320 .ctl_name = KERN_REALROOTDEV,
321 .procname = "real-root-dev",
322 .data = &real_root_dev,
323 .maxlen = sizeof(int),
324 .mode = 0644,
325 .proc_handler = &proc_dointvec,
326 },
327#endif
328#ifdef __sparc__
329 {
330 .ctl_name = KERN_SPARC_REBOOT,
331 .procname = "reboot-cmd",
332 .data = reboot_command,
333 .maxlen = 256,
334 .mode = 0644,
335 .proc_handler = &proc_dostring,
336 .strategy = &sysctl_string,
337 },
338 {
339 .ctl_name = KERN_SPARC_STOP_A,
340 .procname = "stop-a",
341 .data = &stop_a_enabled,
342 .maxlen = sizeof (int),
343 .mode = 0644,
344 .proc_handler = &proc_dointvec,
345 },
346 {
347 .ctl_name = KERN_SPARC_SCONS_PWROFF,
348 .procname = "scons-poweroff",
349 .data = &scons_pwroff,
350 .maxlen = sizeof (int),
351 .mode = 0644,
352 .proc_handler = &proc_dointvec,
353 },
354#endif
355#ifdef __hppa__
356 {
357 .ctl_name = KERN_HPPA_PWRSW,
358 .procname = "soft-power",
359 .data = &pwrsw_enabled,
360 .maxlen = sizeof (int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
363 },
364 {
365 .ctl_name = KERN_HPPA_UNALIGNED,
366 .procname = "unaligned-trap",
367 .data = &unaligned_enabled,
368 .maxlen = sizeof (int),
369 .mode = 0644,
370 .proc_handler = &proc_dointvec,
371 },
372#endif
373 {
374 .ctl_name = KERN_CTLALTDEL,
375 .procname = "ctrl-alt-del",
376 .data = &C_A_D,
377 .maxlen = sizeof(int),
378 .mode = 0644,
379 .proc_handler = &proc_dointvec,
380 },
381 {
382 .ctl_name = KERN_PRINTK,
383 .procname = "printk",
384 .data = &console_loglevel,
385 .maxlen = 4*sizeof(int),
386 .mode = 0644,
387 .proc_handler = &proc_dointvec,
388 },
389#ifdef CONFIG_KMOD
390 {
391 .ctl_name = KERN_MODPROBE,
392 .procname = "modprobe",
393 .data = &modprobe_path,
394 .maxlen = KMOD_PATH_LEN,
395 .mode = 0644,
396 .proc_handler = &proc_dostring,
397 .strategy = &sysctl_string,
398 },
399#endif
400#ifdef CONFIG_HOTPLUG
401 {
402 .ctl_name = KERN_HOTPLUG,
403 .procname = "hotplug",
404 .data = &hotplug_path,
405 .maxlen = HOTPLUG_PATH_LEN,
406 .mode = 0644,
407 .proc_handler = &proc_dostring,
408 .strategy = &sysctl_string,
409 },
410#endif
411#ifdef CONFIG_CHR_DEV_SG
412 {
413 .ctl_name = KERN_SG_BIG_BUFF,
414 .procname = "sg-big-buff",
415 .data = &sg_big_buff,
416 .maxlen = sizeof (int),
417 .mode = 0444,
418 .proc_handler = &proc_dointvec,
419 },
420#endif
421#ifdef CONFIG_BSD_PROCESS_ACCT
422 {
423 .ctl_name = KERN_ACCT,
424 .procname = "acct",
425 .data = &acct_parm,
426 .maxlen = 3*sizeof(int),
427 .mode = 0644,
428 .proc_handler = &proc_dointvec,
429 },
430#endif
431#ifdef CONFIG_SYSVIPC
432 {
433 .ctl_name = KERN_SHMMAX,
434 .procname = "shmmax",
435 .data = &shm_ctlmax,
436 .maxlen = sizeof (size_t),
437 .mode = 0644,
438 .proc_handler = &proc_doulongvec_minmax,
439 },
440 {
441 .ctl_name = KERN_SHMALL,
442 .procname = "shmall",
443 .data = &shm_ctlall,
444 .maxlen = sizeof (size_t),
445 .mode = 0644,
446 .proc_handler = &proc_doulongvec_minmax,
447 },
448 {
449 .ctl_name = KERN_SHMMNI,
450 .procname = "shmmni",
451 .data = &shm_ctlmni,
452 .maxlen = sizeof (int),
453 .mode = 0644,
454 .proc_handler = &proc_dointvec,
455 },
456 {
457 .ctl_name = KERN_MSGMAX,
458 .procname = "msgmax",
459 .data = &msg_ctlmax,
460 .maxlen = sizeof (int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
463 },
464 {
465 .ctl_name = KERN_MSGMNI,
466 .procname = "msgmni",
467 .data = &msg_ctlmni,
468 .maxlen = sizeof (int),
469 .mode = 0644,
470 .proc_handler = &proc_dointvec,
471 },
472 {
473 .ctl_name = KERN_MSGMNB,
474 .procname = "msgmnb",
475 .data = &msg_ctlmnb,
476 .maxlen = sizeof (int),
477 .mode = 0644,
478 .proc_handler = &proc_dointvec,
479 },
480 {
481 .ctl_name = KERN_SEM,
482 .procname = "sem",
483 .data = &sem_ctls,
484 .maxlen = 4*sizeof (int),
485 .mode = 0644,
486 .proc_handler = &proc_dointvec,
487 },
488#endif
489#ifdef CONFIG_MAGIC_SYSRQ
490 {
491 .ctl_name = KERN_SYSRQ,
492 .procname = "sysrq",
493 .data = &sysrq_enabled,
494 .maxlen = sizeof (int),
495 .mode = 0644,
496 .proc_handler = &proc_dointvec,
497 },
498#endif
499 {
500 .ctl_name = KERN_CADPID,
501 .procname = "cad_pid",
502 .data = &cad_pid,
503 .maxlen = sizeof (int),
504 .mode = 0600,
505 .proc_handler = &proc_dointvec,
506 },
507 {
508 .ctl_name = KERN_MAX_THREADS,
509 .procname = "threads-max",
510 .data = &max_threads,
511 .maxlen = sizeof(int),
512 .mode = 0644,
513 .proc_handler = &proc_dointvec,
514 },
515 {
516 .ctl_name = KERN_RANDOM,
517 .procname = "random",
518 .mode = 0555,
519 .child = random_table,
520 },
521#ifdef CONFIG_UNIX98_PTYS
522 {
523 .ctl_name = KERN_PTY,
524 .procname = "pty",
525 .mode = 0555,
526 .child = pty_table,
527 },
528#endif
529 {
530 .ctl_name = KERN_OVERFLOWUID,
531 .procname = "overflowuid",
532 .data = &overflowuid,
533 .maxlen = sizeof(int),
534 .mode = 0644,
535 .proc_handler = &proc_dointvec_minmax,
536 .strategy = &sysctl_intvec,
537 .extra1 = &minolduid,
538 .extra2 = &maxolduid,
539 },
540 {
541 .ctl_name = KERN_OVERFLOWGID,
542 .procname = "overflowgid",
543 .data = &overflowgid,
544 .maxlen = sizeof(int),
545 .mode = 0644,
546 .proc_handler = &proc_dointvec_minmax,
547 .strategy = &sysctl_intvec,
548 .extra1 = &minolduid,
549 .extra2 = &maxolduid,
550 },
551#ifdef CONFIG_ARCH_S390
552#ifdef CONFIG_MATHEMU
553 {
554 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
555 .procname = "ieee_emulation_warnings",
556 .data = &sysctl_ieee_emulation_warnings,
557 .maxlen = sizeof(int),
558 .mode = 0644,
559 .proc_handler = &proc_dointvec,
560 },
561#endif
562#ifdef CONFIG_NO_IDLE_HZ
563 {
564 .ctl_name = KERN_HZ_TIMER,
565 .procname = "hz_timer",
566 .data = &sysctl_hz_timer,
567 .maxlen = sizeof(int),
568 .mode = 0644,
569 .proc_handler = &proc_dointvec,
570 },
571#endif
572 {
573 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
574 .procname = "userprocess_debug",
575 .data = &sysctl_userprocess_debug,
576 .maxlen = sizeof(int),
577 .mode = 0644,
578 .proc_handler = &proc_dointvec,
579 },
580#endif
581 {
582 .ctl_name = KERN_PIDMAX,
583 .procname = "pid_max",
584 .data = &pid_max,
585 .maxlen = sizeof (int),
586 .mode = 0644,
587 .proc_handler = &proc_dointvec_minmax,
588 .strategy = sysctl_intvec,
589 .extra1 = &pid_max_min,
590 .extra2 = &pid_max_max,
591 },
592 {
593 .ctl_name = KERN_PANIC_ON_OOPS,
594 .procname = "panic_on_oops",
595 .data = &panic_on_oops,
596 .maxlen = sizeof(int),
597 .mode = 0644,
598 .proc_handler = &proc_dointvec,
599 },
600 {
601 .ctl_name = KERN_PRINTK_RATELIMIT,
602 .procname = "printk_ratelimit",
603 .data = &printk_ratelimit_jiffies,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec_jiffies,
607 .strategy = &sysctl_jiffies,
608 },
609 {
610 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
611 .procname = "printk_ratelimit_burst",
612 .data = &printk_ratelimit_burst,
613 .maxlen = sizeof(int),
614 .mode = 0644,
615 .proc_handler = &proc_dointvec,
616 },
617 {
618 .ctl_name = KERN_NGROUPS_MAX,
619 .procname = "ngroups_max",
620 .data = &ngroups_max,
621 .maxlen = sizeof (int),
622 .mode = 0444,
623 .proc_handler = &proc_dointvec,
624 },
625#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
626 {
627 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
628 .procname = "unknown_nmi_panic",
629 .data = &unknown_nmi_panic,
630 .maxlen = sizeof (int),
631 .mode = 0644,
632 .proc_handler = &proc_unknown_nmi_panic,
633 },
634#endif
635#if defined(CONFIG_X86)
636 {
637 .ctl_name = KERN_BOOTLOADER_TYPE,
638 .procname = "bootloader_type",
639 .data = &bootloader_type,
640 .maxlen = sizeof (int),
641 .mode = 0444,
642 .proc_handler = &proc_dointvec,
643 },
644#endif
645 {
646 .ctl_name = KERN_RANDOMIZE,
647 .procname = "randomize_va_space",
648 .data = &randomize_va_space,
649 .maxlen = sizeof(int),
650 .mode = 0644,
651 .proc_handler = &proc_dointvec,
652 },
653
654 { .ctl_name = 0 }
655};
656
657/* Constants for minimum and maximum testing in vm_table.
658 We use these as one-element integer vectors. */
659static int zero;
660static int one_hundred = 100;
661
662
663static ctl_table vm_table[] = {
664 {
665 .ctl_name = VM_OVERCOMMIT_MEMORY,
666 .procname = "overcommit_memory",
667 .data = &sysctl_overcommit_memory,
668 .maxlen = sizeof(sysctl_overcommit_memory),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec,
671 },
672 {
673 .ctl_name = VM_OVERCOMMIT_RATIO,
674 .procname = "overcommit_ratio",
675 .data = &sysctl_overcommit_ratio,
676 .maxlen = sizeof(sysctl_overcommit_ratio),
677 .mode = 0644,
678 .proc_handler = &proc_dointvec,
679 },
680 {
681 .ctl_name = VM_PAGE_CLUSTER,
682 .procname = "page-cluster",
683 .data = &page_cluster,
684 .maxlen = sizeof(int),
685 .mode = 0644,
686 .proc_handler = &proc_dointvec,
687 },
688 {
689 .ctl_name = VM_DIRTY_BACKGROUND,
690 .procname = "dirty_background_ratio",
691 .data = &dirty_background_ratio,
692 .maxlen = sizeof(dirty_background_ratio),
693 .mode = 0644,
694 .proc_handler = &proc_dointvec_minmax,
695 .strategy = &sysctl_intvec,
696 .extra1 = &zero,
697 .extra2 = &one_hundred,
698 },
699 {
700 .ctl_name = VM_DIRTY_RATIO,
701 .procname = "dirty_ratio",
702 .data = &vm_dirty_ratio,
703 .maxlen = sizeof(vm_dirty_ratio),
704 .mode = 0644,
705 .proc_handler = &proc_dointvec_minmax,
706 .strategy = &sysctl_intvec,
707 .extra1 = &zero,
708 .extra2 = &one_hundred,
709 },
710 {
711 .ctl_name = VM_DIRTY_WB_CS,
712 .procname = "dirty_writeback_centisecs",
713 .data = &dirty_writeback_centisecs,
714 .maxlen = sizeof(dirty_writeback_centisecs),
715 .mode = 0644,
716 .proc_handler = &dirty_writeback_centisecs_handler,
717 },
718 {
719 .ctl_name = VM_DIRTY_EXPIRE_CS,
720 .procname = "dirty_expire_centisecs",
721 .data = &dirty_expire_centisecs,
722 .maxlen = sizeof(dirty_expire_centisecs),
723 .mode = 0644,
724 .proc_handler = &proc_dointvec,
725 },
726 {
727 .ctl_name = VM_NR_PDFLUSH_THREADS,
728 .procname = "nr_pdflush_threads",
729 .data = &nr_pdflush_threads,
730 .maxlen = sizeof nr_pdflush_threads,
731 .mode = 0444 /* read-only*/,
732 .proc_handler = &proc_dointvec,
733 },
734 {
735 .ctl_name = VM_SWAPPINESS,
736 .procname = "swappiness",
737 .data = &vm_swappiness,
738 .maxlen = sizeof(vm_swappiness),
739 .mode = 0644,
740 .proc_handler = &proc_dointvec_minmax,
741 .strategy = &sysctl_intvec,
742 .extra1 = &zero,
743 .extra2 = &one_hundred,
744 },
745#ifdef CONFIG_HUGETLB_PAGE
746 {
747 .ctl_name = VM_HUGETLB_PAGES,
748 .procname = "nr_hugepages",
749 .data = &max_huge_pages,
750 .maxlen = sizeof(unsigned long),
751 .mode = 0644,
752 .proc_handler = &hugetlb_sysctl_handler,
753 .extra1 = (void *)&hugetlb_zero,
754 .extra2 = (void *)&hugetlb_infinity,
755 },
756 {
757 .ctl_name = VM_HUGETLB_GROUP,
758 .procname = "hugetlb_shm_group",
759 .data = &sysctl_hugetlb_shm_group,
760 .maxlen = sizeof(gid_t),
761 .mode = 0644,
762 .proc_handler = &proc_dointvec,
763 },
764#endif
765 {
766 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
767 .procname = "lowmem_reserve_ratio",
768 .data = &sysctl_lowmem_reserve_ratio,
769 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
770 .mode = 0644,
771 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
772 .strategy = &sysctl_intvec,
773 },
774 {
775 .ctl_name = VM_MIN_FREE_KBYTES,
776 .procname = "min_free_kbytes",
777 .data = &min_free_kbytes,
778 .maxlen = sizeof(min_free_kbytes),
779 .mode = 0644,
780 .proc_handler = &min_free_kbytes_sysctl_handler,
781 .strategy = &sysctl_intvec,
782 .extra1 = &zero,
783 },
784#ifdef CONFIG_MMU
785 {
786 .ctl_name = VM_MAX_MAP_COUNT,
787 .procname = "max_map_count",
788 .data = &sysctl_max_map_count,
789 .maxlen = sizeof(sysctl_max_map_count),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec
792 },
793#endif
794 {
795 .ctl_name = VM_LAPTOP_MODE,
796 .procname = "laptop_mode",
797 .data = &laptop_mode,
798 .maxlen = sizeof(laptop_mode),
799 .mode = 0644,
800 .proc_handler = &proc_dointvec,
801 .strategy = &sysctl_intvec,
802 .extra1 = &zero,
803 },
804 {
805 .ctl_name = VM_BLOCK_DUMP,
806 .procname = "block_dump",
807 .data = &block_dump,
808 .maxlen = sizeof(block_dump),
809 .mode = 0644,
810 .proc_handler = &proc_dointvec,
811 .strategy = &sysctl_intvec,
812 .extra1 = &zero,
813 },
814 {
815 .ctl_name = VM_VFS_CACHE_PRESSURE,
816 .procname = "vfs_cache_pressure",
817 .data = &sysctl_vfs_cache_pressure,
818 .maxlen = sizeof(sysctl_vfs_cache_pressure),
819 .mode = 0644,
820 .proc_handler = &proc_dointvec,
821 .strategy = &sysctl_intvec,
822 .extra1 = &zero,
823 },
824#ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
825 {
826 .ctl_name = VM_LEGACY_VA_LAYOUT,
827 .procname = "legacy_va_layout",
828 .data = &sysctl_legacy_va_layout,
829 .maxlen = sizeof(sysctl_legacy_va_layout),
830 .mode = 0644,
831 .proc_handler = &proc_dointvec,
832 .strategy = &sysctl_intvec,
833 .extra1 = &zero,
834 },
835#endif
836#ifdef CONFIG_SWAP
837 {
838 .ctl_name = VM_SWAP_TOKEN_TIMEOUT,
839 .procname = "swap_token_timeout",
840 .data = &swap_token_default_timeout,
841 .maxlen = sizeof(swap_token_default_timeout),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec_jiffies,
844 .strategy = &sysctl_jiffies,
845 },
846#endif
847 { .ctl_name = 0 }
848};
849
850static ctl_table proc_table[] = {
851 { .ctl_name = 0 }
852};
853
854static ctl_table fs_table[] = {
855 {
856 .ctl_name = FS_NRINODE,
857 .procname = "inode-nr",
858 .data = &inodes_stat,
859 .maxlen = 2*sizeof(int),
860 .mode = 0444,
861 .proc_handler = &proc_dointvec,
862 },
863 {
864 .ctl_name = FS_STATINODE,
865 .procname = "inode-state",
866 .data = &inodes_stat,
867 .maxlen = 7*sizeof(int),
868 .mode = 0444,
869 .proc_handler = &proc_dointvec,
870 },
871 {
872 .ctl_name = FS_NRFILE,
873 .procname = "file-nr",
874 .data = &files_stat,
875 .maxlen = 3*sizeof(int),
876 .mode = 0444,
877 .proc_handler = &proc_dointvec,
878 },
879 {
880 .ctl_name = FS_MAXFILE,
881 .procname = "file-max",
882 .data = &files_stat.max_files,
883 .maxlen = sizeof(int),
884 .mode = 0644,
885 .proc_handler = &proc_dointvec,
886 },
887 {
888 .ctl_name = FS_DENTRY,
889 .procname = "dentry-state",
890 .data = &dentry_stat,
891 .maxlen = 6*sizeof(int),
892 .mode = 0444,
893 .proc_handler = &proc_dointvec,
894 },
895 {
896 .ctl_name = FS_OVERFLOWUID,
897 .procname = "overflowuid",
898 .data = &fs_overflowuid,
899 .maxlen = sizeof(int),
900 .mode = 0644,
901 .proc_handler = &proc_dointvec_minmax,
902 .strategy = &sysctl_intvec,
903 .extra1 = &minolduid,
904 .extra2 = &maxolduid,
905 },
906 {
907 .ctl_name = FS_OVERFLOWGID,
908 .procname = "overflowgid",
909 .data = &fs_overflowgid,
910 .maxlen = sizeof(int),
911 .mode = 0644,
912 .proc_handler = &proc_dointvec_minmax,
913 .strategy = &sysctl_intvec,
914 .extra1 = &minolduid,
915 .extra2 = &maxolduid,
916 },
917 {
918 .ctl_name = FS_LEASES,
919 .procname = "leases-enable",
920 .data = &leases_enable,
921 .maxlen = sizeof(int),
922 .mode = 0644,
923 .proc_handler = &proc_dointvec,
924 },
925#ifdef CONFIG_DNOTIFY
926 {
927 .ctl_name = FS_DIR_NOTIFY,
928 .procname = "dir-notify-enable",
929 .data = &dir_notify_enable,
930 .maxlen = sizeof(int),
931 .mode = 0644,
932 .proc_handler = &proc_dointvec,
933 },
934#endif
935#ifdef CONFIG_MMU
936 {
937 .ctl_name = FS_LEASE_TIME,
938 .procname = "lease-break-time",
939 .data = &lease_break_time,
940 .maxlen = sizeof(int),
941 .mode = 0644,
942 .proc_handler = &proc_dointvec,
943 },
944 {
945 .ctl_name = FS_AIO_NR,
946 .procname = "aio-nr",
947 .data = &aio_nr,
948 .maxlen = sizeof(aio_nr),
949 .mode = 0444,
950 .proc_handler = &proc_dointvec,
951 },
952 {
953 .ctl_name = FS_AIO_MAX_NR,
954 .procname = "aio-max-nr",
955 .data = &aio_max_nr,
956 .maxlen = sizeof(aio_max_nr),
957 .mode = 0644,
958 .proc_handler = &proc_dointvec,
959 },
960#endif
d6e71144
AC
961 {
962 .ctl_name = KERN_SETUID_DUMPABLE,
963 .procname = "suid_dumpable",
964 .data = &suid_dumpable,
965 .maxlen = sizeof(int),
966 .mode = 0644,
967 .proc_handler = &proc_dointvec,
968 },
0eeca283
RL
969#ifdef CONFIG_INOTIFY
970 {
971 .ctl_name = INOTIFY_MAX_USER_DEVICES,
972 .procname = "max_user_devices",
973 .data = &inotify_max_user_devices,
974 .maxlen = sizeof(int),
975 .mode = 0644,
976 .proc_handler = &proc_dointvec_minmax,
977 .strategy = &sysctl_intvec,
978 .extra1 = &zero,
979 },
980
981 {
982 .ctl_name = INOTIFY_MAX_USER_WATCHES,
983 .procname = "max_user_watches",
984 .data = &inotify_max_user_watches,
985 .maxlen = sizeof(int),
986 .mode = 0644,
987 .proc_handler = &proc_dointvec_minmax,
988 .strategy = &sysctl_intvec,
989 .extra1 = &zero,
990 },
991
992 {
993 .ctl_name = INOTIFY_MAX_QUEUED_EVENTS,
994 .procname = "max_queued_events",
995 .data = &inotify_max_queued_events,
996 .maxlen = sizeof(int),
997 .mode = 0644,
998 .proc_handler = &proc_dointvec_minmax,
999 .strategy = &sysctl_intvec,
1000 .extra1 = &zero
1001 },
1002#endif
1da177e4
LT
1003 { .ctl_name = 0 }
1004};
1005
1006static ctl_table debug_table[] = {
1007 { .ctl_name = 0 }
1008};
1009
1010static ctl_table dev_table[] = {
1011 { .ctl_name = 0 }
0eeca283 1012};
1da177e4
LT
1013
1014extern void init_irq_proc (void);
1015
1016void __init sysctl_init(void)
1017{
1018#ifdef CONFIG_PROC_FS
1019 register_proc_table(root_table, proc_sys_root);
1020 init_irq_proc();
1021#endif
1022}
1023
1024int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1025 void __user *newval, size_t newlen)
1026{
1027 struct list_head *tmp;
1028
1029 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1030 return -ENOTDIR;
1031 if (oldval) {
1032 int old_len;
1033 if (!oldlenp || get_user(old_len, oldlenp))
1034 return -EFAULT;
1035 }
1036 tmp = &root_table_header.ctl_entry;
1037 do {
1038 struct ctl_table_header *head =
1039 list_entry(tmp, struct ctl_table_header, ctl_entry);
1040 void *context = NULL;
1041 int error = parse_table(name, nlen, oldval, oldlenp,
1042 newval, newlen, head->ctl_table,
1043 &context);
5a6b454f 1044 kfree(context);
1da177e4
LT
1045 if (error != -ENOTDIR)
1046 return error;
1047 tmp = tmp->next;
1048 } while (tmp != &root_table_header.ctl_entry);
1049 return -ENOTDIR;
1050}
1051
1052asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1053{
1054 struct __sysctl_args tmp;
1055 int error;
1056
1057 if (copy_from_user(&tmp, args, sizeof(tmp)))
1058 return -EFAULT;
1059
1060 lock_kernel();
1061 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1062 tmp.newval, tmp.newlen);
1063 unlock_kernel();
1064 return error;
1065}
1066
1067/*
1068 * ctl_perm does NOT grant the superuser all rights automatically, because
1069 * some sysctl variables are readonly even to root.
1070 */
1071
1072static int test_perm(int mode, int op)
1073{
1074 if (!current->euid)
1075 mode >>= 6;
1076 else if (in_egroup_p(0))
1077 mode >>= 3;
1078 if ((mode & op & 0007) == op)
1079 return 0;
1080 return -EACCES;
1081}
1082
1083static inline int ctl_perm(ctl_table *table, int op)
1084{
1085 int error;
1086 error = security_sysctl(table, op);
1087 if (error)
1088 return error;
1089 return test_perm(table->mode, op);
1090}
1091
1092static int parse_table(int __user *name, int nlen,
1093 void __user *oldval, size_t __user *oldlenp,
1094 void __user *newval, size_t newlen,
1095 ctl_table *table, void **context)
1096{
1097 int n;
1098repeat:
1099 if (!nlen)
1100 return -ENOTDIR;
1101 if (get_user(n, name))
1102 return -EFAULT;
1103 for ( ; table->ctl_name; table++) {
1104 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
1105 int error;
1106 if (table->child) {
1107 if (ctl_perm(table, 001))
1108 return -EPERM;
1109 if (table->strategy) {
1110 error = table->strategy(
1111 table, name, nlen,
1112 oldval, oldlenp,
1113 newval, newlen, context);
1114 if (error)
1115 return error;
1116 }
1117 name++;
1118 nlen--;
1119 table = table->child;
1120 goto repeat;
1121 }
1122 error = do_sysctl_strategy(table, name, nlen,
1123 oldval, oldlenp,
1124 newval, newlen, context);
1125 return error;
1126 }
1127 }
1128 return -ENOTDIR;
1129}
1130
1131/* Perform the actual read/write of a sysctl table entry. */
1132int do_sysctl_strategy (ctl_table *table,
1133 int __user *name, int nlen,
1134 void __user *oldval, size_t __user *oldlenp,
1135 void __user *newval, size_t newlen, void **context)
1136{
1137 int op = 0, rc;
1138 size_t len;
1139
1140 if (oldval)
1141 op |= 004;
1142 if (newval)
1143 op |= 002;
1144 if (ctl_perm(table, op))
1145 return -EPERM;
1146
1147 if (table->strategy) {
1148 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1149 newval, newlen, context);
1150 if (rc < 0)
1151 return rc;
1152 if (rc > 0)
1153 return 0;
1154 }
1155
1156 /* If there is no strategy routine, or if the strategy returns
1157 * zero, proceed with automatic r/w */
1158 if (table->data && table->maxlen) {
1159 if (oldval && oldlenp) {
1160 if (get_user(len, oldlenp))
1161 return -EFAULT;
1162 if (len) {
1163 if (len > table->maxlen)
1164 len = table->maxlen;
1165 if(copy_to_user(oldval, table->data, len))
1166 return -EFAULT;
1167 if(put_user(len, oldlenp))
1168 return -EFAULT;
1169 }
1170 }
1171 if (newval && newlen) {
1172 len = newlen;
1173 if (len > table->maxlen)
1174 len = table->maxlen;
1175 if(copy_from_user(table->data, newval, len))
1176 return -EFAULT;
1177 }
1178 }
1179 return 0;
1180}
1181
1182/**
1183 * register_sysctl_table - register a sysctl hierarchy
1184 * @table: the top-level table structure
1185 * @insert_at_head: whether the entry should be inserted in front or at the end
1186 *
1187 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1188 * array. An entry with a ctl_name of 0 terminates the table.
1189 *
1190 * The members of the &ctl_table structure are used as follows:
1191 *
1192 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1193 * must be unique within that level of sysctl
1194 *
1195 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1196 * enter a sysctl file
1197 *
1198 * data - a pointer to data for use by proc_handler
1199 *
1200 * maxlen - the maximum size in bytes of the data
1201 *
1202 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1203 *
1204 * child - a pointer to the child sysctl table if this entry is a directory, or
1205 * %NULL.
1206 *
1207 * proc_handler - the text handler routine (described below)
1208 *
1209 * strategy - the strategy routine (described below)
1210 *
1211 * de - for internal use by the sysctl routines
1212 *
1213 * extra1, extra2 - extra pointers usable by the proc handler routines
1214 *
1215 * Leaf nodes in the sysctl tree will be represented by a single file
1216 * under /proc; non-leaf nodes will be represented by directories.
1217 *
1218 * sysctl(2) can automatically manage read and write requests through
1219 * the sysctl table. The data and maxlen fields of the ctl_table
1220 * struct enable minimal validation of the values being written to be
1221 * performed, and the mode field allows minimal authentication.
1222 *
1223 * More sophisticated management can be enabled by the provision of a
1224 * strategy routine with the table entry. This will be called before
1225 * any automatic read or write of the data is performed.
1226 *
1227 * The strategy routine may return
1228 *
1229 * < 0 - Error occurred (error is passed to user process)
1230 *
1231 * 0 - OK - proceed with automatic read or write.
1232 *
1233 * > 0 - OK - read or write has been done by the strategy routine, so
1234 * return immediately.
1235 *
1236 * There must be a proc_handler routine for any terminal nodes
1237 * mirrored under /proc/sys (non-terminals are handled by a built-in
1238 * directory handler). Several default handlers are available to
1239 * cover common cases -
1240 *
1241 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1242 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1243 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1244 *
1245 * It is the handler's job to read the input buffer from user memory
1246 * and process it. The handler should return 0 on success.
1247 *
1248 * This routine returns %NULL on a failure to register, and a pointer
1249 * to the table header on success.
1250 */
1251struct ctl_table_header *register_sysctl_table(ctl_table * table,
1252 int insert_at_head)
1253{
1254 struct ctl_table_header *tmp;
1255 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1256 if (!tmp)
1257 return NULL;
1258 tmp->ctl_table = table;
1259 INIT_LIST_HEAD(&tmp->ctl_entry);
1260 if (insert_at_head)
1261 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
1262 else
1263 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1264#ifdef CONFIG_PROC_FS
1265 register_proc_table(table, proc_sys_root);
1266#endif
1267 return tmp;
1268}
1269
1270/**
1271 * unregister_sysctl_table - unregister a sysctl table hierarchy
1272 * @header: the header returned from register_sysctl_table
1273 *
1274 * Unregisters the sysctl table and all children. proc entries may not
1275 * actually be removed until they are no longer used by anyone.
1276 */
1277void unregister_sysctl_table(struct ctl_table_header * header)
1278{
1279 list_del(&header->ctl_entry);
1280#ifdef CONFIG_PROC_FS
1281 unregister_proc_table(header->ctl_table, proc_sys_root);
1282#endif
1283 kfree(header);
1284}
1285
1286/*
1287 * /proc/sys support
1288 */
1289
1290#ifdef CONFIG_PROC_FS
1291
1292/* Scan the sysctl entries in table and add them all into /proc */
1293static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
1294{
1295 struct proc_dir_entry *de;
1296 int len;
1297 mode_t mode;
1298
1299 for (; table->ctl_name; table++) {
1300 /* Can't do anything without a proc name. */
1301 if (!table->procname)
1302 continue;
1303 /* Maybe we can't do anything with it... */
1304 if (!table->proc_handler && !table->child) {
1305 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
1306 table->procname);
1307 continue;
1308 }
1309
1310 len = strlen(table->procname);
1311 mode = table->mode;
1312
1313 de = NULL;
1314 if (table->proc_handler)
1315 mode |= S_IFREG;
1316 else {
1317 mode |= S_IFDIR;
1318 for (de = root->subdir; de; de = de->next) {
1319 if (proc_match(len, table->procname, de))
1320 break;
1321 }
1322 /* If the subdir exists already, de is non-NULL */
1323 }
1324
1325 if (!de) {
1326 de = create_proc_entry(table->procname, mode, root);
1327 if (!de)
1328 continue;
1329 de->data = (void *) table;
1330 if (table->proc_handler)
1331 de->proc_fops = &proc_sys_file_operations;
1332 }
1333 table->de = de;
1334 if (de->mode & S_IFDIR)
1335 register_proc_table(table->child, de);
1336 }
1337}
1338
1339/*
1340 * Unregister a /proc sysctl table and any subdirectories.
1341 */
1342static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
1343{
1344 struct proc_dir_entry *de;
1345 for (; table->ctl_name; table++) {
1346 if (!(de = table->de))
1347 continue;
1348 if (de->mode & S_IFDIR) {
1349 if (!table->child) {
1350 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
1351 continue;
1352 }
1353 unregister_proc_table(table->child, de);
1354
1355 /* Don't unregister directories which still have entries.. */
1356 if (de->subdir)
1357 continue;
1358 }
1359
1360 /* Don't unregister proc entries that are still being used.. */
1361 if (atomic_read(&de->count))
1362 continue;
1363
1364 table->de = NULL;
1365 remove_proc_entry(table->procname, root);
1366 }
1367}
1368
1369static ssize_t do_rw_proc(int write, struct file * file, char __user * buf,
1370 size_t count, loff_t *ppos)
1371{
1372 int op;
1373 struct proc_dir_entry *de;
1374 struct ctl_table *table;
1375 size_t res;
1376 ssize_t error;
1377
1378 de = PDE(file->f_dentry->d_inode);
1379 if (!de || !de->data)
1380 return -ENOTDIR;
1381 table = (struct ctl_table *) de->data;
1382 if (!table || !table->proc_handler)
1383 return -ENOTDIR;
1384 op = (write ? 002 : 004);
1385 if (ctl_perm(table, op))
1386 return -EPERM;
1387
1388 res = count;
1389
1390 error = (*table->proc_handler) (table, write, file, buf, &res, ppos);
1391 if (error)
1392 return error;
1393 return res;
1394}
1395
1396static int proc_opensys(struct inode *inode, struct file *file)
1397{
1398 if (file->f_mode & FMODE_WRITE) {
1399 /*
1400 * sysctl entries that are not writable,
1401 * are _NOT_ writable, capabilities or not.
1402 */
1403 if (!(inode->i_mode & S_IWUSR))
1404 return -EPERM;
1405 }
1406
1407 return 0;
1408}
1409
1410static ssize_t proc_readsys(struct file * file, char __user * buf,
1411 size_t count, loff_t *ppos)
1412{
1413 return do_rw_proc(0, file, buf, count, ppos);
1414}
1415
1416static ssize_t proc_writesys(struct file * file, const char __user * buf,
1417 size_t count, loff_t *ppos)
1418{
1419 return do_rw_proc(1, file, (char __user *) buf, count, ppos);
1420}
1421
1422/**
1423 * proc_dostring - read a string sysctl
1424 * @table: the sysctl table
1425 * @write: %TRUE if this is a write to the sysctl file
1426 * @filp: the file structure
1427 * @buffer: the user buffer
1428 * @lenp: the size of the user buffer
1429 * @ppos: file position
1430 *
1431 * Reads/writes a string from/to the user buffer. If the kernel
1432 * buffer provided is not large enough to hold the string, the
1433 * string is truncated. The copied string is %NULL-terminated.
1434 * If the string is being read by the user process, it is copied
1435 * and a newline '\n' is added. It is truncated if the buffer is
1436 * not large enough.
1437 *
1438 * Returns 0 on success.
1439 */
1440int proc_dostring(ctl_table *table, int write, struct file *filp,
1441 void __user *buffer, size_t *lenp, loff_t *ppos)
1442{
1443 size_t len;
1444 char __user *p;
1445 char c;
1446
1447 if (!table->data || !table->maxlen || !*lenp ||
1448 (*ppos && !write)) {
1449 *lenp = 0;
1450 return 0;
1451 }
1452
1453 if (write) {
1454 len = 0;
1455 p = buffer;
1456 while (len < *lenp) {
1457 if (get_user(c, p++))
1458 return -EFAULT;
1459 if (c == 0 || c == '\n')
1460 break;
1461 len++;
1462 }
1463 if (len >= table->maxlen)
1464 len = table->maxlen-1;
1465 if(copy_from_user(table->data, buffer, len))
1466 return -EFAULT;
1467 ((char *) table->data)[len] = 0;
1468 *ppos += *lenp;
1469 } else {
1470 len = strlen(table->data);
1471 if (len > table->maxlen)
1472 len = table->maxlen;
1473 if (len > *lenp)
1474 len = *lenp;
1475 if (len)
1476 if(copy_to_user(buffer, table->data, len))
1477 return -EFAULT;
1478 if (len < *lenp) {
1479 if(put_user('\n', ((char __user *) buffer) + len))
1480 return -EFAULT;
1481 len++;
1482 }
1483 *lenp = len;
1484 *ppos += len;
1485 }
1486 return 0;
1487}
1488
1489/*
1490 * Special case of dostring for the UTS structure. This has locks
1491 * to observe. Should this be in kernel/sys.c ????
1492 */
1493
1494static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
1495 void __user *buffer, size_t *lenp, loff_t *ppos)
1496{
1497 int r;
1498
1499 if (!write) {
1500 down_read(&uts_sem);
1501 r=proc_dostring(table,0,filp,buffer,lenp, ppos);
1502 up_read(&uts_sem);
1503 } else {
1504 down_write(&uts_sem);
1505 r=proc_dostring(table,1,filp,buffer,lenp, ppos);
1506 up_write(&uts_sem);
1507 }
1508 return r;
1509}
1510
1511static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1512 int *valp,
1513 int write, void *data)
1514{
1515 if (write) {
1516 *valp = *negp ? -*lvalp : *lvalp;
1517 } else {
1518 int val = *valp;
1519 if (val < 0) {
1520 *negp = -1;
1521 *lvalp = (unsigned long)-val;
1522 } else {
1523 *negp = 0;
1524 *lvalp = (unsigned long)val;
1525 }
1526 }
1527 return 0;
1528}
1529
1530static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
1531 void __user *buffer, size_t *lenp, loff_t *ppos,
1532 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1533 int write, void *data),
1534 void *data)
1535{
1536#define TMPBUFLEN 21
1537 int *i, vleft, first=1, neg, val;
1538 unsigned long lval;
1539 size_t left, len;
1540
1541 char buf[TMPBUFLEN], *p;
1542 char __user *s = buffer;
1543
1544 if (!table->data || !table->maxlen || !*lenp ||
1545 (*ppos && !write)) {
1546 *lenp = 0;
1547 return 0;
1548 }
1549
1550 i = (int *) table->data;
1551 vleft = table->maxlen / sizeof(*i);
1552 left = *lenp;
1553
1554 if (!conv)
1555 conv = do_proc_dointvec_conv;
1556
1557 for (; left && vleft--; i++, first=0) {
1558 if (write) {
1559 while (left) {
1560 char c;
1561 if (get_user(c, s))
1562 return -EFAULT;
1563 if (!isspace(c))
1564 break;
1565 left--;
1566 s++;
1567 }
1568 if (!left)
1569 break;
1570 neg = 0;
1571 len = left;
1572 if (len > sizeof(buf) - 1)
1573 len = sizeof(buf) - 1;
1574 if (copy_from_user(buf, s, len))
1575 return -EFAULT;
1576 buf[len] = 0;
1577 p = buf;
1578 if (*p == '-' && left > 1) {
1579 neg = 1;
1580 left--, p++;
1581 }
1582 if (*p < '0' || *p > '9')
1583 break;
1584
1585 lval = simple_strtoul(p, &p, 0);
1586
1587 len = p-buf;
1588 if ((len < left) && *p && !isspace(*p))
1589 break;
1590 if (neg)
1591 val = -val;
1592 s += len;
1593 left -= len;
1594
1595 if (conv(&neg, &lval, i, 1, data))
1596 break;
1597 } else {
1598 p = buf;
1599 if (!first)
1600 *p++ = '\t';
1601
1602 if (conv(&neg, &lval, i, 0, data))
1603 break;
1604
1605 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1606 len = strlen(buf);
1607 if (len > left)
1608 len = left;
1609 if(copy_to_user(s, buf, len))
1610 return -EFAULT;
1611 left -= len;
1612 s += len;
1613 }
1614 }
1615
1616 if (!write && !first && left) {
1617 if(put_user('\n', s))
1618 return -EFAULT;
1619 left--, s++;
1620 }
1621 if (write) {
1622 while (left) {
1623 char c;
1624 if (get_user(c, s++))
1625 return -EFAULT;
1626 if (!isspace(c))
1627 break;
1628 left--;
1629 }
1630 }
1631 if (write && first)
1632 return -EINVAL;
1633 *lenp -= left;
1634 *ppos += *lenp;
1635 return 0;
1636#undef TMPBUFLEN
1637}
1638
1639/**
1640 * proc_dointvec - read a vector of integers
1641 * @table: the sysctl table
1642 * @write: %TRUE if this is a write to the sysctl file
1643 * @filp: the file structure
1644 * @buffer: the user buffer
1645 * @lenp: the size of the user buffer
1646 * @ppos: file position
1647 *
1648 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1649 * values from/to the user buffer, treated as an ASCII string.
1650 *
1651 * Returns 0 on success.
1652 */
1653int proc_dointvec(ctl_table *table, int write, struct file *filp,
1654 void __user *buffer, size_t *lenp, loff_t *ppos)
1655{
1656 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1657 NULL,NULL);
1658}
1659
1660#define OP_SET 0
1661#define OP_AND 1
1662#define OP_OR 2
1663#define OP_MAX 3
1664#define OP_MIN 4
1665
1666static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1667 int *valp,
1668 int write, void *data)
1669{
1670 int op = *(int *)data;
1671 if (write) {
1672 int val = *negp ? -*lvalp : *lvalp;
1673 switch(op) {
1674 case OP_SET: *valp = val; break;
1675 case OP_AND: *valp &= val; break;
1676 case OP_OR: *valp |= val; break;
1677 case OP_MAX: if(*valp < val)
1678 *valp = val;
1679 break;
1680 case OP_MIN: if(*valp > val)
1681 *valp = val;
1682 break;
1683 }
1684 } else {
1685 int val = *valp;
1686 if (val < 0) {
1687 *negp = -1;
1688 *lvalp = (unsigned long)-val;
1689 } else {
1690 *negp = 0;
1691 *lvalp = (unsigned long)val;
1692 }
1693 }
1694 return 0;
1695}
1696
1697/*
1698 * init may raise the set.
1699 */
1700
1701int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1702 void __user *buffer, size_t *lenp, loff_t *ppos)
1703{
1704 int op;
1705
1706 if (!capable(CAP_SYS_MODULE)) {
1707 return -EPERM;
1708 }
1709
1710 op = (current->pid == 1) ? OP_SET : OP_AND;
1711 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1712 do_proc_dointvec_bset_conv,&op);
1713}
1714
1715struct do_proc_dointvec_minmax_conv_param {
1716 int *min;
1717 int *max;
1718};
1719
1720static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1721 int *valp,
1722 int write, void *data)
1723{
1724 struct do_proc_dointvec_minmax_conv_param *param = data;
1725 if (write) {
1726 int val = *negp ? -*lvalp : *lvalp;
1727 if ((param->min && *param->min > val) ||
1728 (param->max && *param->max < val))
1729 return -EINVAL;
1730 *valp = val;
1731 } else {
1732 int val = *valp;
1733 if (val < 0) {
1734 *negp = -1;
1735 *lvalp = (unsigned long)-val;
1736 } else {
1737 *negp = 0;
1738 *lvalp = (unsigned long)val;
1739 }
1740 }
1741 return 0;
1742}
1743
1744/**
1745 * proc_dointvec_minmax - read a vector of integers with min/max values
1746 * @table: the sysctl table
1747 * @write: %TRUE if this is a write to the sysctl file
1748 * @filp: the file structure
1749 * @buffer: the user buffer
1750 * @lenp: the size of the user buffer
1751 * @ppos: file position
1752 *
1753 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1754 * values from/to the user buffer, treated as an ASCII string.
1755 *
1756 * This routine will ensure the values are within the range specified by
1757 * table->extra1 (min) and table->extra2 (max).
1758 *
1759 * Returns 0 on success.
1760 */
1761int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1762 void __user *buffer, size_t *lenp, loff_t *ppos)
1763{
1764 struct do_proc_dointvec_minmax_conv_param param = {
1765 .min = (int *) table->extra1,
1766 .max = (int *) table->extra2,
1767 };
1768 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1769 do_proc_dointvec_minmax_conv, &param);
1770}
1771
1772static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1773 struct file *filp,
1774 void __user *buffer,
1775 size_t *lenp, loff_t *ppos,
1776 unsigned long convmul,
1777 unsigned long convdiv)
1778{
1779#define TMPBUFLEN 21
1780 unsigned long *i, *min, *max, val;
1781 int vleft, first=1, neg;
1782 size_t len, left;
1783 char buf[TMPBUFLEN], *p;
1784 char __user *s = buffer;
1785
1786 if (!table->data || !table->maxlen || !*lenp ||
1787 (*ppos && !write)) {
1788 *lenp = 0;
1789 return 0;
1790 }
1791
1792 i = (unsigned long *) table->data;
1793 min = (unsigned long *) table->extra1;
1794 max = (unsigned long *) table->extra2;
1795 vleft = table->maxlen / sizeof(unsigned long);
1796 left = *lenp;
1797
1798 for (; left && vleft--; i++, min++, max++, first=0) {
1799 if (write) {
1800 while (left) {
1801 char c;
1802 if (get_user(c, s))
1803 return -EFAULT;
1804 if (!isspace(c))
1805 break;
1806 left--;
1807 s++;
1808 }
1809 if (!left)
1810 break;
1811 neg = 0;
1812 len = left;
1813 if (len > TMPBUFLEN-1)
1814 len = TMPBUFLEN-1;
1815 if (copy_from_user(buf, s, len))
1816 return -EFAULT;
1817 buf[len] = 0;
1818 p = buf;
1819 if (*p == '-' && left > 1) {
1820 neg = 1;
1821 left--, p++;
1822 }
1823 if (*p < '0' || *p > '9')
1824 break;
1825 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1826 len = p-buf;
1827 if ((len < left) && *p && !isspace(*p))
1828 break;
1829 if (neg)
1830 val = -val;
1831 s += len;
1832 left -= len;
1833
1834 if(neg)
1835 continue;
1836 if ((min && val < *min) || (max && val > *max))
1837 continue;
1838 *i = val;
1839 } else {
1840 p = buf;
1841 if (!first)
1842 *p++ = '\t';
1843 sprintf(p, "%lu", convdiv * (*i) / convmul);
1844 len = strlen(buf);
1845 if (len > left)
1846 len = left;
1847 if(copy_to_user(s, buf, len))
1848 return -EFAULT;
1849 left -= len;
1850 s += len;
1851 }
1852 }
1853
1854 if (!write && !first && left) {
1855 if(put_user('\n', s))
1856 return -EFAULT;
1857 left--, s++;
1858 }
1859 if (write) {
1860 while (left) {
1861 char c;
1862 if (get_user(c, s++))
1863 return -EFAULT;
1864 if (!isspace(c))
1865 break;
1866 left--;
1867 }
1868 }
1869 if (write && first)
1870 return -EINVAL;
1871 *lenp -= left;
1872 *ppos += *lenp;
1873 return 0;
1874#undef TMPBUFLEN
1875}
1876
1877/**
1878 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1879 * @table: the sysctl table
1880 * @write: %TRUE if this is a write to the sysctl file
1881 * @filp: the file structure
1882 * @buffer: the user buffer
1883 * @lenp: the size of the user buffer
1884 * @ppos: file position
1885 *
1886 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1887 * values from/to the user buffer, treated as an ASCII string.
1888 *
1889 * This routine will ensure the values are within the range specified by
1890 * table->extra1 (min) and table->extra2 (max).
1891 *
1892 * Returns 0 on success.
1893 */
1894int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1895 void __user *buffer, size_t *lenp, loff_t *ppos)
1896{
1897 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
1898}
1899
1900/**
1901 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1902 * @table: the sysctl table
1903 * @write: %TRUE if this is a write to the sysctl file
1904 * @filp: the file structure
1905 * @buffer: the user buffer
1906 * @lenp: the size of the user buffer
1907 * @ppos: file position
1908 *
1909 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1910 * values from/to the user buffer, treated as an ASCII string. The values
1911 * are treated as milliseconds, and converted to jiffies when they are stored.
1912 *
1913 * This routine will ensure the values are within the range specified by
1914 * table->extra1 (min) and table->extra2 (max).
1915 *
1916 * Returns 0 on success.
1917 */
1918int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1919 struct file *filp,
1920 void __user *buffer,
1921 size_t *lenp, loff_t *ppos)
1922{
1923 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1924 lenp, ppos, HZ, 1000l);
1925}
1926
1927
1928static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
1929 int *valp,
1930 int write, void *data)
1931{
1932 if (write) {
1933 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
1934 } else {
1935 int val = *valp;
1936 unsigned long lval;
1937 if (val < 0) {
1938 *negp = -1;
1939 lval = (unsigned long)-val;
1940 } else {
1941 *negp = 0;
1942 lval = (unsigned long)val;
1943 }
1944 *lvalp = lval / HZ;
1945 }
1946 return 0;
1947}
1948
1949static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
1950 int *valp,
1951 int write, void *data)
1952{
1953 if (write) {
1954 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
1955 } else {
1956 int val = *valp;
1957 unsigned long lval;
1958 if (val < 0) {
1959 *negp = -1;
1960 lval = (unsigned long)-val;
1961 } else {
1962 *negp = 0;
1963 lval = (unsigned long)val;
1964 }
1965 *lvalp = jiffies_to_clock_t(lval);
1966 }
1967 return 0;
1968}
1969
1970static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
1971 int *valp,
1972 int write, void *data)
1973{
1974 if (write) {
1975 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
1976 } else {
1977 int val = *valp;
1978 unsigned long lval;
1979 if (val < 0) {
1980 *negp = -1;
1981 lval = (unsigned long)-val;
1982 } else {
1983 *negp = 0;
1984 lval = (unsigned long)val;
1985 }
1986 *lvalp = jiffies_to_msecs(lval);
1987 }
1988 return 0;
1989}
1990
1991/**
1992 * proc_dointvec_jiffies - read a vector of integers as seconds
1993 * @table: the sysctl table
1994 * @write: %TRUE if this is a write to the sysctl file
1995 * @filp: the file structure
1996 * @buffer: the user buffer
1997 * @lenp: the size of the user buffer
1998 * @ppos: file position
1999 *
2000 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2001 * values from/to the user buffer, treated as an ASCII string.
2002 * The values read are assumed to be in seconds, and are converted into
2003 * jiffies.
2004 *
2005 * Returns 0 on success.
2006 */
2007int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2008 void __user *buffer, size_t *lenp, loff_t *ppos)
2009{
2010 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2011 do_proc_dointvec_jiffies_conv,NULL);
2012}
2013
2014/**
2015 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2016 * @table: the sysctl table
2017 * @write: %TRUE if this is a write to the sysctl file
2018 * @filp: the file structure
2019 * @buffer: the user buffer
2020 * @lenp: the size of the user buffer
2021 *
2022 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2023 * values from/to the user buffer, treated as an ASCII string.
2024 * The values read are assumed to be in 1/USER_HZ seconds, and
2025 * are converted into jiffies.
2026 *
2027 * Returns 0 on success.
2028 */
2029int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2030 void __user *buffer, size_t *lenp, loff_t *ppos)
2031{
2032 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2033 do_proc_dointvec_userhz_jiffies_conv,NULL);
2034}
2035
2036/**
2037 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2038 * @table: the sysctl table
2039 * @write: %TRUE if this is a write to the sysctl file
2040 * @filp: the file structure
2041 * @buffer: the user buffer
2042 * @lenp: the size of the user buffer
67be2dd1
MW
2043 * @ppos: file position
2044 * @ppos: the current position in the file
1da177e4
LT
2045 *
2046 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2047 * values from/to the user buffer, treated as an ASCII string.
2048 * The values read are assumed to be in 1/1000 seconds, and
2049 * are converted into jiffies.
2050 *
2051 * Returns 0 on success.
2052 */
2053int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2054 void __user *buffer, size_t *lenp, loff_t *ppos)
2055{
2056 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2057 do_proc_dointvec_ms_jiffies_conv, NULL);
2058}
2059
2060#else /* CONFIG_PROC_FS */
2061
2062int proc_dostring(ctl_table *table, int write, struct file *filp,
2063 void __user *buffer, size_t *lenp, loff_t *ppos)
2064{
2065 return -ENOSYS;
2066}
2067
2068static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
2069 void __user *buffer, size_t *lenp, loff_t *ppos)
2070{
2071 return -ENOSYS;
2072}
2073
2074int proc_dointvec(ctl_table *table, int write, struct file *filp,
2075 void __user *buffer, size_t *lenp, loff_t *ppos)
2076{
2077 return -ENOSYS;
2078}
2079
2080int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2081 void __user *buffer, size_t *lenp, loff_t *ppos)
2082{
2083 return -ENOSYS;
2084}
2085
2086int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2087 void __user *buffer, size_t *lenp, loff_t *ppos)
2088{
2089 return -ENOSYS;
2090}
2091
2092int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2093 void __user *buffer, size_t *lenp, loff_t *ppos)
2094{
2095 return -ENOSYS;
2096}
2097
2098int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2099 void __user *buffer, size_t *lenp, loff_t *ppos)
2100{
2101 return -ENOSYS;
2102}
2103
2104int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2105 void __user *buffer, size_t *lenp, loff_t *ppos)
2106{
2107 return -ENOSYS;
2108}
2109
2110int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2111 void __user *buffer, size_t *lenp, loff_t *ppos)
2112{
2113 return -ENOSYS;
2114}
2115
2116int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2117 struct file *filp,
2118 void __user *buffer,
2119 size_t *lenp, loff_t *ppos)
2120{
2121 return -ENOSYS;
2122}
2123
2124
2125#endif /* CONFIG_PROC_FS */
2126
2127
2128/*
2129 * General sysctl support routines
2130 */
2131
2132/* The generic string strategy routine: */
2133int sysctl_string(ctl_table *table, int __user *name, int nlen,
2134 void __user *oldval, size_t __user *oldlenp,
2135 void __user *newval, size_t newlen, void **context)
2136{
2137 size_t l, len;
2138
2139 if (!table->data || !table->maxlen)
2140 return -ENOTDIR;
2141
2142 if (oldval && oldlenp) {
2143 if (get_user(len, oldlenp))
2144 return -EFAULT;
2145 if (len) {
2146 l = strlen(table->data);
2147 if (len > l) len = l;
2148 if (len >= table->maxlen)
2149 len = table->maxlen;
2150 if(copy_to_user(oldval, table->data, len))
2151 return -EFAULT;
2152 if(put_user(0, ((char __user *) oldval) + len))
2153 return -EFAULT;
2154 if(put_user(len, oldlenp))
2155 return -EFAULT;
2156 }
2157 }
2158 if (newval && newlen) {
2159 len = newlen;
2160 if (len > table->maxlen)
2161 len = table->maxlen;
2162 if(copy_from_user(table->data, newval, len))
2163 return -EFAULT;
2164 if (len == table->maxlen)
2165 len--;
2166 ((char *) table->data)[len] = 0;
2167 }
2168 return 0;
2169}
2170
2171/*
2172 * This function makes sure that all of the integers in the vector
2173 * are between the minimum and maximum values given in the arrays
2174 * table->extra1 and table->extra2, respectively.
2175 */
2176int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2177 void __user *oldval, size_t __user *oldlenp,
2178 void __user *newval, size_t newlen, void **context)
2179{
2180
2181 if (newval && newlen) {
2182 int __user *vec = (int __user *) newval;
2183 int *min = (int *) table->extra1;
2184 int *max = (int *) table->extra2;
2185 size_t length;
2186 int i;
2187
2188 if (newlen % sizeof(int) != 0)
2189 return -EINVAL;
2190
2191 if (!table->extra1 && !table->extra2)
2192 return 0;
2193
2194 if (newlen > table->maxlen)
2195 newlen = table->maxlen;
2196 length = newlen / sizeof(int);
2197
2198 for (i = 0; i < length; i++) {
2199 int value;
2200 if (get_user(value, vec + i))
2201 return -EFAULT;
2202 if (min && value < min[i])
2203 return -EINVAL;
2204 if (max && value > max[i])
2205 return -EINVAL;
2206 }
2207 }
2208 return 0;
2209}
2210
2211/* Strategy function to convert jiffies to seconds */
2212int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2213 void __user *oldval, size_t __user *oldlenp,
2214 void __user *newval, size_t newlen, void **context)
2215{
2216 if (oldval) {
2217 size_t olen;
2218 if (oldlenp) {
2219 if (get_user(olen, oldlenp))
2220 return -EFAULT;
2221 if (olen!=sizeof(int))
2222 return -EINVAL;
2223 }
2224 if (put_user(*(int *)(table->data)/HZ, (int __user *)oldval) ||
2225 (oldlenp && put_user(sizeof(int),oldlenp)))
2226 return -EFAULT;
2227 }
2228 if (newval && newlen) {
2229 int new;
2230 if (newlen != sizeof(int))
2231 return -EINVAL;
2232 if (get_user(new, (int __user *)newval))
2233 return -EFAULT;
2234 *(int *)(table->data) = new*HZ;
2235 }
2236 return 1;
2237}
2238
2239/* Strategy function to convert jiffies to seconds */
2240int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2241 void __user *oldval, size_t __user *oldlenp,
2242 void __user *newval, size_t newlen, void **context)
2243{
2244 if (oldval) {
2245 size_t olen;
2246 if (oldlenp) {
2247 if (get_user(olen, oldlenp))
2248 return -EFAULT;
2249 if (olen!=sizeof(int))
2250 return -EINVAL;
2251 }
2252 if (put_user(jiffies_to_msecs(*(int *)(table->data)), (int __user *)oldval) ||
2253 (oldlenp && put_user(sizeof(int),oldlenp)))
2254 return -EFAULT;
2255 }
2256 if (newval && newlen) {
2257 int new;
2258 if (newlen != sizeof(int))
2259 return -EINVAL;
2260 if (get_user(new, (int __user *)newval))
2261 return -EFAULT;
2262 *(int *)(table->data) = msecs_to_jiffies(new);
2263 }
2264 return 1;
2265}
2266
2267#else /* CONFIG_SYSCTL */
2268
2269
2270asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2271{
2272 return -ENOSYS;
2273}
2274
2275int sysctl_string(ctl_table *table, int __user *name, int nlen,
2276 void __user *oldval, size_t __user *oldlenp,
2277 void __user *newval, size_t newlen, void **context)
2278{
2279 return -ENOSYS;
2280}
2281
2282int sysctl_intvec(ctl_table *table, int __user *name, int nlen,
2283 void __user *oldval, size_t __user *oldlenp,
2284 void __user *newval, size_t newlen, void **context)
2285{
2286 return -ENOSYS;
2287}
2288
2289int sysctl_jiffies(ctl_table *table, int __user *name, int nlen,
2290 void __user *oldval, size_t __user *oldlenp,
2291 void __user *newval, size_t newlen, void **context)
2292{
2293 return -ENOSYS;
2294}
2295
2296int sysctl_ms_jiffies(ctl_table *table, int __user *name, int nlen,
2297 void __user *oldval, size_t __user *oldlenp,
2298 void __user *newval, size_t newlen, void **context)
2299{
2300 return -ENOSYS;
2301}
2302
2303int proc_dostring(ctl_table *table, int write, struct file *filp,
2304 void __user *buffer, size_t *lenp, loff_t *ppos)
2305{
2306 return -ENOSYS;
2307}
2308
2309int proc_dointvec(ctl_table *table, int write, struct file *filp,
2310 void __user *buffer, size_t *lenp, loff_t *ppos)
2311{
2312 return -ENOSYS;
2313}
2314
2315int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
2316 void __user *buffer, size_t *lenp, loff_t *ppos)
2317{
2318 return -ENOSYS;
2319}
2320
2321int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
2322 void __user *buffer, size_t *lenp, loff_t *ppos)
2323{
2324 return -ENOSYS;
2325}
2326
2327int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
2328 void __user *buffer, size_t *lenp, loff_t *ppos)
2329{
2330 return -ENOSYS;
2331}
2332
2333int proc_dointvec_userhz_jiffies(ctl_table *table, int write, struct file *filp,
2334 void __user *buffer, size_t *lenp, loff_t *ppos)
2335{
2336 return -ENOSYS;
2337}
2338
2339int proc_dointvec_ms_jiffies(ctl_table *table, int write, struct file *filp,
2340 void __user *buffer, size_t *lenp, loff_t *ppos)
2341{
2342 return -ENOSYS;
2343}
2344
2345int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
2346 void __user *buffer, size_t *lenp, loff_t *ppos)
2347{
2348 return -ENOSYS;
2349}
2350
2351int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
2352 struct file *filp,
2353 void __user *buffer,
2354 size_t *lenp, loff_t *ppos)
2355{
2356 return -ENOSYS;
2357}
2358
2359struct ctl_table_header * register_sysctl_table(ctl_table * table,
2360 int insert_at_head)
2361{
2362 return NULL;
2363}
2364
2365void unregister_sysctl_table(struct ctl_table_header * table)
2366{
2367}
2368
2369#endif /* CONFIG_SYSCTL */
2370
2371/*
2372 * No sense putting this after each symbol definition, twice,
2373 * exception granted :-)
2374 */
2375EXPORT_SYMBOL(proc_dointvec);
2376EXPORT_SYMBOL(proc_dointvec_jiffies);
2377EXPORT_SYMBOL(proc_dointvec_minmax);
2378EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2379EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2380EXPORT_SYMBOL(proc_dostring);
2381EXPORT_SYMBOL(proc_doulongvec_minmax);
2382EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2383EXPORT_SYMBOL(register_sysctl_table);
2384EXPORT_SYMBOL(sysctl_intvec);
2385EXPORT_SYMBOL(sysctl_jiffies);
2386EXPORT_SYMBOL(sysctl_ms_jiffies);
2387EXPORT_SYMBOL(sysctl_string);
2388EXPORT_SYMBOL(unregister_sysctl_table);