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
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
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>
24 #include <linux/swap.h>
25 #include <linux/slab.h>
26 #include <linux/sysctl.h>
27 #include <linux/proc_fs.h>
28 #include <linux/ctype.h>
29 #include <linux/utsname.h>
30 #include <linux/capability.h>
31 #include <linux/smp_lock.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/sysrq.h>
35 #include <linux/highuid.h>
36 #include <linux/writeback.h>
37 #include <linux/hugetlb.h>
38 #include <linux/security.h>
39 #include <linux/initrd.h>
40 #include <linux/times.h>
41 #include <asm/uaccess.h>
43 #ifdef CONFIG_ROOT_NFS
44 #include <linux/nfs_fs.h>
47 #if defined(CONFIG_SYSCTL)
49 /* External variables not in a header file. */
50 extern int panic_timeout
;
52 extern int sysctl_overcommit_memory
;
53 extern int sysctl_overcommit_ratio
;
54 extern int max_threads
;
55 extern atomic_t nr_queued_signals
;
56 extern int max_queued_signals
;
57 extern int sysrq_enabled
;
58 extern int core_uses_pid
;
59 extern char core_pattern
[];
62 extern int sysctl_lower_zone_protection
;
63 extern int min_free_kbytes
;
64 extern int printk_ratelimit_jiffies
;
65 extern int printk_ratelimit_burst
;
67 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
68 static int maxolduid
= 65535;
72 extern char modprobe_path
[];
75 extern char hotplug_path
[];
77 #ifdef CONFIG_CHR_DEV_SG
78 extern int sg_big_buff
;
81 extern size_t shm_ctlmax
;
82 extern size_t shm_ctlall
;
83 extern int shm_ctlmni
;
84 extern int msg_ctlmax
;
85 extern int msg_ctlmnb
;
86 extern int msg_ctlmni
;
87 extern int sem_ctls
[];
91 extern char reboot_command
[];
92 extern int stop_a_enabled
;
96 extern int pwrsw_enabled
;
97 extern int unaligned_enabled
;
100 #ifdef CONFIG_ARCH_S390
101 #ifdef CONFIG_MATHEMU
102 extern int sysctl_ieee_emulation_warnings
;
104 extern int sysctl_userprocess_debug
;
107 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
108 extern unsigned long powersave_nap
;
109 int proc_dol2crvec(ctl_table
*table
, int write
, struct file
*filp
,
110 void *buffer
, size_t *lenp
);
113 #ifdef CONFIG_BSD_PROCESS_ACCT
114 extern int acct_parm
[];
117 static int parse_table(int __user
*, int, void __user
*, size_t __user
*, void __user
*, size_t,
118 ctl_table
*, void **);
119 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
120 void __user
*buffer
, size_t *lenp
);
122 static ctl_table root_table
[];
123 static struct ctl_table_header root_table_header
=
124 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
126 static ctl_table kern_table
[];
127 static ctl_table vm_table
[];
129 extern ctl_table net_table
[];
131 static ctl_table proc_table
[];
132 static ctl_table fs_table
[];
133 static ctl_table debug_table
[];
134 static ctl_table dev_table
[];
135 extern ctl_table random_table
[];
137 /* /proc declarations: */
139 #ifdef CONFIG_PROC_FS
141 static ssize_t
proc_readsys(struct file
*, char __user
*, size_t, loff_t
*);
142 static ssize_t
proc_writesys(struct file
*, const char __user
*, size_t, loff_t
*);
143 static int proc_opensys(struct inode
*, struct file
*);
145 struct file_operations proc_sys_file_operations
= {
146 .open
= proc_opensys
,
147 .read
= proc_readsys
,
148 .write
= proc_writesys
,
151 extern struct proc_dir_entry
*proc_sys_root
;
153 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*);
154 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
157 /* The default sysctl tables: */
159 static ctl_table root_table
[] = {
161 .ctl_name
= CTL_KERN
,
162 .procname
= "kernel",
181 .ctl_name
= CTL_PROC
,
193 .ctl_name
= CTL_DEBUG
,
196 .child
= debug_table
,
207 static ctl_table kern_table
[] = {
209 .ctl_name
= KERN_OSTYPE
,
210 .procname
= "ostype",
211 .data
= system_utsname
.sysname
,
214 .proc_handler
= &proc_doutsstring
,
215 .strategy
= &sysctl_string
,
218 .ctl_name
= KERN_OSRELEASE
,
219 .procname
= "osrelease",
220 .data
= system_utsname
.release
,
223 .proc_handler
= &proc_doutsstring
,
224 .strategy
= &sysctl_string
,
227 .ctl_name
= KERN_VERSION
,
228 .procname
= "version",
229 .data
= system_utsname
.version
,
232 .proc_handler
= &proc_doutsstring
,
233 .strategy
= &sysctl_string
,
236 .ctl_name
= KERN_NODENAME
,
237 .procname
= "hostname",
238 .data
= system_utsname
.nodename
,
241 .proc_handler
= &proc_doutsstring
,
242 .strategy
= &sysctl_string
,
245 .ctl_name
= KERN_DOMAINNAME
,
246 .procname
= "domainname",
247 .data
= system_utsname
.domainname
,
250 .proc_handler
= &proc_doutsstring
,
251 .strategy
= &sysctl_string
,
254 .ctl_name
= KERN_PANIC
,
256 .data
= &panic_timeout
,
257 .maxlen
= sizeof(int),
259 .proc_handler
= &proc_dointvec
,
262 .ctl_name
= KERN_CORE_USES_PID
,
263 .procname
= "core_uses_pid",
264 .data
= &core_uses_pid
,
265 .maxlen
= sizeof(int),
267 .proc_handler
= &proc_dointvec
,
270 .ctl_name
= KERN_CORE_PATTERN
,
271 .procname
= "core_pattern",
272 .data
= core_pattern
,
275 .proc_handler
= &proc_dostring
,
276 .strategy
= &sysctl_string
,
279 .ctl_name
= KERN_TAINTED
,
280 .procname
= "tainted",
282 .maxlen
= sizeof(int),
284 .proc_handler
= &proc_dointvec
,
287 .ctl_name
= KERN_CAP_BSET
,
288 .procname
= "cap-bound",
290 .maxlen
= sizeof(kernel_cap_t
),
292 .proc_handler
= &proc_dointvec_bset
,
294 #ifdef CONFIG_BLK_DEV_INITRD
296 .ctl_name
= KERN_REALROOTDEV
,
297 .procname
= "real-root-dev",
298 .data
= &real_root_dev
,
299 .maxlen
= sizeof(int),
301 .proc_handler
= &proc_dointvec
,
306 .ctl_name
= KERN_SPARC_REBOOT
,
307 .procname
= "reboot-cmd",
308 .data
= reboot_command
,
311 .proc_handler
= &proc_dostring
,
312 .strategy
= &sysctl_string
,
315 .ctl_name
= KERN_SPARC_STOP_A
,
316 .procname
= "stop-a",
317 .data
= &stop_a_enabled
,
318 .maxlen
= sizeof (int),
320 .proc_handler
= &proc_dointvec
,
325 .ctl_name
= KERN_HPPA_PWRSW
,
326 .procname
= "soft-power",
327 .data
= &pwrsw_enabled
,
328 .maxlen
= sizeof (int),
330 .proc_handler
= &proc_dointvec
,
333 .ctl_name
= KERN_HPPA_UNALIGNED
,
334 .procname
= "unaligned-trap",
335 .data
= &unaligned_enabled
,
336 .maxlen
= sizeof (int),
338 .proc_handler
= &proc_dointvec
,
342 {KERN_HPPA_PWRSW
, "soft-power", &pwrsw_enabled
, sizeof (int),
343 0644, NULL
, &proc_dointvec
},
344 {KERN_HPPA_UNALIGNED
, "unaligned-trap", &unaligned_enabled
, sizeof (int),
345 0644, NULL
, &proc_dointvec
},
347 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
349 .ctl_name
= KERN_PPC_POWERSAVE_NAP
,
350 .procname
= "powersave-nap",
351 .data
= &powersave_nap
,
352 .maxlen
= sizeof(int),
354 .proc_handler
= &proc_dointvec
,
357 .ctl_name
= KERN_PPC_L2CR
,
360 .proc_handler
= &proc_dol2crvec
,
364 .ctl_name
= KERN_CTLALTDEL
,
365 .procname
= "ctrl-alt-del",
367 .maxlen
= sizeof(int),
369 .proc_handler
= &proc_dointvec
,
372 .ctl_name
= KERN_PRINTK
,
373 .procname
= "printk",
374 .data
= &console_loglevel
,
375 .maxlen
= 4*sizeof(int),
377 .proc_handler
= &proc_dointvec
,
381 .ctl_name
= KERN_MODPROBE
,
382 .procname
= "modprobe",
383 .data
= &modprobe_path
,
386 .proc_handler
= &proc_dostring
,
387 .strategy
= &sysctl_string
,
390 #ifdef CONFIG_HOTPLUG
392 .ctl_name
= KERN_HOTPLUG
,
393 .procname
= "hotplug",
394 .data
= &hotplug_path
,
397 .proc_handler
= &proc_dostring
,
398 .strategy
= &sysctl_string
,
401 #ifdef CONFIG_CHR_DEV_SG
403 .ctl_name
= KERN_SG_BIG_BUFF
,
404 .procname
= "sg-big-buff",
405 .data
= &sg_big_buff
,
406 .maxlen
= sizeof (int),
408 .proc_handler
= &proc_dointvec
,
411 #ifdef CONFIG_BSD_PROCESS_ACCT
413 .ctl_name
= KERN_ACCT
,
416 .maxlen
= 3*sizeof(int),
418 .proc_handler
= &proc_dointvec
,
422 .ctl_name
= KERN_RTSIGNR
,
423 .procname
= "rtsig-nr",
424 .data
= &nr_queued_signals
,
425 .maxlen
= sizeof(int),
427 .proc_handler
= &proc_dointvec
,
430 .ctl_name
= KERN_RTSIGMAX
,
431 .procname
= "rtsig-max",
432 .data
= &max_queued_signals
,
433 .maxlen
= sizeof(int),
435 .proc_handler
= &proc_dointvec
,
437 #ifdef CONFIG_SYSVIPC
439 .ctl_name
= KERN_SHMMAX
,
440 .procname
= "shmmax",
442 .maxlen
= sizeof (size_t),
444 .proc_handler
= &proc_doulongvec_minmax
,
447 .ctl_name
= KERN_SHMALL
,
448 .procname
= "shmall",
450 .maxlen
= sizeof (size_t),
452 .proc_handler
= &proc_doulongvec_minmax
,
455 .ctl_name
= KERN_SHMMNI
,
456 .procname
= "shmmni",
458 .maxlen
= sizeof (int),
460 .proc_handler
= &proc_dointvec
,
463 .ctl_name
= KERN_MSGMAX
,
464 .procname
= "msgmax",
466 .maxlen
= sizeof (int),
468 .proc_handler
= &proc_dointvec
,
471 .ctl_name
= KERN_MSGMNI
,
472 .procname
= "msgmni",
474 .maxlen
= sizeof (int),
476 .proc_handler
= &proc_dointvec
,
479 .ctl_name
= KERN_MSGMNB
,
480 .procname
= "msgmnb",
482 .maxlen
= sizeof (int),
484 .proc_handler
= &proc_dointvec
,
487 .ctl_name
= KERN_SEM
,
490 .maxlen
= 4*sizeof (int),
492 .proc_handler
= &proc_dointvec
,
495 #ifdef CONFIG_MAGIC_SYSRQ
497 .ctl_name
= KERN_SYSRQ
,
499 .data
= &sysrq_enabled
,
500 .maxlen
= sizeof (int),
502 .proc_handler
= &proc_dointvec
,
506 .ctl_name
= KERN_CADPID
,
507 .procname
= "cad_pid",
509 .maxlen
= sizeof (int),
511 .proc_handler
= &proc_dointvec
,
514 .ctl_name
= KERN_MAX_THREADS
,
515 .procname
= "threads-max",
516 .data
= &max_threads
,
517 .maxlen
= sizeof(int),
519 .proc_handler
= &proc_dointvec
,
522 .ctl_name
= KERN_RANDOM
,
523 .procname
= "random",
525 .child
= random_table
,
528 .ctl_name
= KERN_OVERFLOWUID
,
529 .procname
= "overflowuid",
530 .data
= &overflowuid
,
531 .maxlen
= sizeof(int),
533 .proc_handler
= &proc_dointvec_minmax
,
534 .strategy
= &sysctl_intvec
,
535 .extra1
= &minolduid
,
536 .extra2
= &maxolduid
,
539 .ctl_name
= KERN_OVERFLOWGID
,
540 .procname
= "overflowgid",
541 .data
= &overflowgid
,
542 .maxlen
= sizeof(int),
544 .proc_handler
= &proc_dointvec_minmax
,
545 .strategy
= &sysctl_intvec
,
546 .extra1
= &minolduid
,
547 .extra2
= &maxolduid
,
549 #ifdef CONFIG_ARCH_S390
550 #ifdef CONFIG_MATHEMU
552 .ctl_name
= KERN_IEEE_EMULATION_WARNINGS
,
553 .procname
= "ieee_emulation_warnings",
554 .data
= &sysctl_ieee_emulation_warnings
,
555 .maxlen
= sizeof(int),
557 .proc_handler
= &proc_dointvec
,
561 .ctl_name
= KERN_S390_USER_DEBUG_LOGGING
,
562 .procname
= "userprocess_debug",
563 .data
= &sysctl_userprocess_debug
,
564 .maxlen
= sizeof(int),
566 .proc_handler
= &proc_dointvec
,
570 .ctl_name
= KERN_PIDMAX
,
571 .procname
= "pid_max",
573 .maxlen
= sizeof (int),
575 .proc_handler
= &proc_dointvec
,
578 .ctl_name
= KERN_PANIC_ON_OOPS
,
579 .procname
= "panic_on_oops",
580 .data
= &panic_on_oops
,
581 .maxlen
= sizeof(int),
583 .proc_handler
= &proc_dointvec
,
586 .ctl_name
= KERN_PRINTK_RATELIMIT
,
587 .procname
= "printk_ratelimit",
588 .data
= &printk_ratelimit_jiffies
,
589 .maxlen
= sizeof(int),
591 .proc_handler
= &proc_dointvec_jiffies
,
592 .strategy
= &sysctl_jiffies
,
595 .ctl_name
= KERN_PRINTK_RATELIMIT_BURST
,
596 .procname
= "printk_ratelimit_burst",
597 .data
= &printk_ratelimit_burst
,
598 .maxlen
= sizeof(int),
600 .proc_handler
= &proc_dointvec
,
601 .strategy
= &sysctl_jiffies
,
606 /* Constants for minimum and maximum testing in vm_table.
607 We use these as one-element integer vectors. */
609 static int one_hundred
= 100;
612 static ctl_table vm_table
[] = {
614 .ctl_name
= VM_OVERCOMMIT_MEMORY
,
615 .procname
= "overcommit_memory",
616 .data
= &sysctl_overcommit_memory
,
617 .maxlen
= sizeof(sysctl_overcommit_memory
),
619 .proc_handler
= &proc_dointvec
,
622 .ctl_name
= VM_OVERCOMMIT_RATIO
,
623 .procname
= "overcommit_ratio",
624 .data
= &sysctl_overcommit_ratio
,
625 .maxlen
= sizeof(sysctl_overcommit_ratio
),
627 .proc_handler
= &proc_dointvec
,
630 .ctl_name
= VM_PAGE_CLUSTER
,
631 .procname
= "page-cluster",
632 .data
= &page_cluster
,
633 .maxlen
= sizeof(int),
635 .proc_handler
= &proc_dointvec
,
638 .ctl_name
= VM_DIRTY_BACKGROUND
,
639 .procname
= "dirty_background_ratio",
640 .data
= &dirty_background_ratio
,
641 .maxlen
= sizeof(dirty_background_ratio
),
643 .proc_handler
= &proc_dointvec_minmax
,
644 .strategy
= &sysctl_intvec
,
646 .extra2
= &one_hundred
,
649 .ctl_name
= VM_DIRTY_RATIO
,
650 .procname
= "dirty_ratio",
651 .data
= &vm_dirty_ratio
,
652 .maxlen
= sizeof(vm_dirty_ratio
),
654 .proc_handler
= &proc_dointvec_minmax
,
655 .strategy
= &sysctl_intvec
,
657 .extra2
= &one_hundred
,
660 .ctl_name
= VM_DIRTY_WB_CS
,
661 .procname
= "dirty_writeback_centisecs",
662 .data
= &dirty_writeback_centisecs
,
663 .maxlen
= sizeof(dirty_writeback_centisecs
),
665 .proc_handler
= &dirty_writeback_centisecs_handler
,
668 .ctl_name
= VM_DIRTY_EXPIRE_CS
,
669 .procname
= "dirty_expire_centisecs",
670 .data
= &dirty_expire_centisecs
,
671 .maxlen
= sizeof(dirty_expire_centisecs
),
673 .proc_handler
= &proc_dointvec
,
676 .ctl_name
= VM_NR_PDFLUSH_THREADS
,
677 .procname
= "nr_pdflush_threads",
678 .data
= &nr_pdflush_threads
,
679 .maxlen
= sizeof nr_pdflush_threads
,
680 .mode
= 0444 /* read-only*/,
681 .proc_handler
= &proc_dointvec
,
684 .ctl_name
= VM_SWAPPINESS
,
685 .procname
= "swappiness",
686 .data
= &vm_swappiness
,
687 .maxlen
= sizeof(vm_swappiness
),
689 .proc_handler
= &proc_dointvec_minmax
,
690 .strategy
= &sysctl_intvec
,
692 .extra2
= &one_hundred
,
694 #ifdef CONFIG_HUGETLB_PAGE
696 .ctl_name
= VM_HUGETLB_PAGES
,
697 .procname
= "nr_hugepages",
698 .data
= &htlbpage_max
,
699 .maxlen
= sizeof(int),
701 .proc_handler
= &hugetlb_sysctl_handler
,
705 .ctl_name
= VM_LOWER_ZONE_PROTECTION
,
706 .procname
= "lower_zone_protection",
707 .data
= &sysctl_lower_zone_protection
,
708 .maxlen
= sizeof(sysctl_lower_zone_protection
),
710 .proc_handler
= &proc_dointvec_minmax
,
711 .strategy
= &sysctl_intvec
,
715 .ctl_name
= VM_MIN_FREE_KBYTES
,
716 .procname
= "min_free_kbytes",
717 .data
= &min_free_kbytes
,
718 .maxlen
= sizeof(min_free_kbytes
),
720 .proc_handler
= &min_free_kbytes_sysctl_handler
,
721 .strategy
= &sysctl_intvec
,
727 static ctl_table proc_table
[] = {
731 static ctl_table fs_table
[] = {
733 .ctl_name
= FS_NRINODE
,
734 .procname
= "inode-nr",
735 .data
= &inodes_stat
,
736 .maxlen
= 2*sizeof(int),
738 .proc_handler
= &proc_dointvec
,
741 .ctl_name
= FS_STATINODE
,
742 .procname
= "inode-state",
743 .data
= &inodes_stat
,
744 .maxlen
= 7*sizeof(int),
746 .proc_handler
= &proc_dointvec
,
749 .ctl_name
= FS_NRFILE
,
750 .procname
= "file-nr",
752 .maxlen
= 3*sizeof(int),
754 .proc_handler
= &proc_dointvec
,
757 .ctl_name
= FS_MAXFILE
,
758 .procname
= "file-max",
759 .data
= &files_stat
.max_files
,
760 .maxlen
= sizeof(int),
762 .proc_handler
= &proc_dointvec
,
765 .ctl_name
= FS_DENTRY
,
766 .procname
= "dentry-state",
767 .data
= &dentry_stat
,
768 .maxlen
= 6*sizeof(int),
770 .proc_handler
= &proc_dointvec
,
773 .ctl_name
= FS_OVERFLOWUID
,
774 .procname
= "overflowuid",
775 .data
= &fs_overflowuid
,
776 .maxlen
= sizeof(int),
778 .proc_handler
= &proc_dointvec_minmax
,
779 .strategy
= &sysctl_intvec
,
780 .extra1
= &minolduid
,
781 .extra2
= &maxolduid
,
784 .ctl_name
= FS_OVERFLOWGID
,
785 .procname
= "overflowgid",
786 .data
= &fs_overflowgid
,
787 .maxlen
= sizeof(int),
789 .proc_handler
= &proc_dointvec_minmax
,
790 .strategy
= &sysctl_intvec
,
791 .extra1
= &minolduid
,
792 .extra2
= &maxolduid
,
795 .ctl_name
= FS_LEASES
,
796 .procname
= "leases-enable",
797 .data
= &leases_enable
,
798 .maxlen
= sizeof(int),
800 .proc_handler
= &proc_dointvec
,
803 .ctl_name
= FS_DIR_NOTIFY
,
804 .procname
= "dir-notify-enable",
805 .data
= &dir_notify_enable
,
806 .maxlen
= sizeof(int),
808 .proc_handler
= &proc_dointvec
,
811 .ctl_name
= FS_LEASE_TIME
,
812 .procname
= "lease-break-time",
813 .data
= &lease_break_time
,
814 .maxlen
= sizeof(int),
816 .proc_handler
= &proc_dointvec
,
821 static ctl_table debug_table
[] = {
825 static ctl_table dev_table
[] = {
829 extern void init_irq_proc (void);
831 void __init
sysctl_init(void)
833 #ifdef CONFIG_PROC_FS
834 register_proc_table(root_table
, proc_sys_root
);
839 int do_sysctl(int __user
*name
, int nlen
, void __user
*oldval
, size_t __user
*oldlenp
,
840 void __user
*newval
, size_t newlen
)
842 struct list_head
*tmp
;
844 if (nlen
<= 0 || nlen
>= CTL_MAXNAME
)
848 if (!oldlenp
|| get_user(old_len
, oldlenp
))
851 tmp
= &root_table_header
.ctl_entry
;
853 struct ctl_table_header
*head
=
854 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
855 void *context
= NULL
;
856 int error
= parse_table(name
, nlen
, oldval
, oldlenp
,
857 newval
, newlen
, head
->ctl_table
,
861 if (error
!= -ENOTDIR
)
864 } while (tmp
!= &root_table_header
.ctl_entry
);
868 asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
870 struct __sysctl_args tmp
;
874 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
877 if (tmp
.nlen
!= 2 || copy_from_user(name
, tmp
.name
, sizeof(name
)) ||
878 name
[0] != CTL_KERN
|| name
[1] != KERN_VERSION
) {
880 printk(KERN_INFO
"%s: numerical sysctl ", current
->comm
);
881 for (i
= 0; i
< tmp
.nlen
; i
++) {
884 if (get_user(n
, tmp
.name
+i
)) {
890 printk("is obsolete.\n");
894 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
895 tmp
.newval
, tmp
.newlen
);
901 * ctl_perm does NOT grant the superuser all rights automatically, because
902 * some sysctl variables are readonly even to root.
905 static int test_perm(int mode
, int op
)
909 else if (in_egroup_p(0))
911 if ((mode
& op
& 0007) == op
)
916 static inline int ctl_perm(ctl_table
*table
, int op
)
919 error
= security_sysctl(table
, op
);
922 return test_perm(table
->mode
, op
);
925 static int parse_table(int __user
*name
, int nlen
,
926 void __user
*oldval
, size_t __user
*oldlenp
,
927 void __user
*newval
, size_t newlen
,
928 ctl_table
*table
, void **context
)
934 if (get_user(n
, name
))
936 for ( ; table
->ctl_name
; table
++) {
937 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
940 if (ctl_perm(table
, 001))
942 if (table
->strategy
) {
943 error
= table
->strategy(
946 newval
, newlen
, context
);
952 table
= table
->child
;
955 error
= do_sysctl_strategy(table
, name
, nlen
,
957 newval
, newlen
, context
);
964 /* Perform the actual read/write of a sysctl table entry. */
965 int do_sysctl_strategy (ctl_table
*table
,
966 int __user
*name
, int nlen
,
967 void __user
*oldval
, size_t __user
*oldlenp
,
968 void __user
*newval
, size_t newlen
, void **context
)
977 if (ctl_perm(table
, op
))
980 if (table
->strategy
) {
981 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
982 newval
, newlen
, context
);
989 /* If there is no strategy routine, or if the strategy returns
990 * zero, proceed with automatic r/w */
991 if (table
->data
&& table
->maxlen
) {
992 if (oldval
&& oldlenp
) {
993 get_user(len
, oldlenp
);
995 if (len
> table
->maxlen
)
997 if(copy_to_user(oldval
, table
->data
, len
))
999 if(put_user(len
, oldlenp
))
1003 if (newval
&& newlen
) {
1005 if (len
> table
->maxlen
)
1006 len
= table
->maxlen
;
1007 if(copy_from_user(table
->data
, newval
, len
))
1015 * register_sysctl_table - register a sysctl hierarchy
1016 * @table: the top-level table structure
1017 * @insert_at_head: whether the entry should be inserted in front or at the end
1019 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1020 * array. An entry with a ctl_name of 0 terminates the table.
1022 * The members of the &ctl_table structure are used as follows:
1024 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1025 * must be unique within that level of sysctl
1027 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1028 * enter a sysctl file
1030 * data - a pointer to data for use by proc_handler
1032 * maxlen - the maximum size in bytes of the data
1034 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1036 * child - a pointer to the child sysctl table if this entry is a directory, or
1039 * proc_handler - the text handler routine (described below)
1041 * strategy - the strategy routine (described below)
1043 * de - for internal use by the sysctl routines
1045 * extra1, extra2 - extra pointers usable by the proc handler routines
1047 * Leaf nodes in the sysctl tree will be represented by a single file
1048 * under /proc; non-leaf nodes will be represented by directories.
1050 * sysctl(2) can automatically manage read and write requests through
1051 * the sysctl table. The data and maxlen fields of the ctl_table
1052 * struct enable minimal validation of the values being written to be
1053 * performed, and the mode field allows minimal authentication.
1055 * More sophisticated management can be enabled by the provision of a
1056 * strategy routine with the table entry. This will be called before
1057 * any automatic read or write of the data is performed.
1059 * The strategy routine may return
1061 * < 0 - Error occurred (error is passed to user process)
1063 * 0 - OK - proceed with automatic read or write.
1065 * > 0 - OK - read or write has been done by the strategy routine, so
1066 * return immediately.
1068 * There must be a proc_handler routine for any terminal nodes
1069 * mirrored under /proc/sys (non-terminals are handled by a built-in
1070 * directory handler). Several default handlers are available to
1071 * cover common cases -
1073 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1074 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1075 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1077 * It is the handler's job to read the input buffer from user memory
1078 * and process it. The handler should return 0 on success.
1080 * This routine returns %NULL on a failure to register, and a pointer
1081 * to the table header on success.
1083 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
1086 struct ctl_table_header
*tmp
;
1087 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
1090 tmp
->ctl_table
= table
;
1091 INIT_LIST_HEAD(&tmp
->ctl_entry
);
1093 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1095 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
1096 #ifdef CONFIG_PROC_FS
1097 register_proc_table(table
, proc_sys_root
);
1103 * unregister_sysctl_table - unregister a sysctl table hierarchy
1104 * @header: the header returned from register_sysctl_table
1106 * Unregisters the sysctl table and all children. proc entries may not
1107 * actually be removed until they are no longer used by anyone.
1109 void unregister_sysctl_table(struct ctl_table_header
* header
)
1111 list_del(&header
->ctl_entry
);
1112 #ifdef CONFIG_PROC_FS
1113 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
1122 #ifdef CONFIG_PROC_FS
1124 /* Scan the sysctl entries in table and add them all into /proc */
1125 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1127 struct proc_dir_entry
*de
;
1131 for (; table
->ctl_name
; table
++) {
1132 /* Can't do anything without a proc name. */
1133 if (!table
->procname
)
1135 /* Maybe we can't do anything with it... */
1136 if (!table
->proc_handler
&& !table
->child
) {
1137 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
1142 len
= strlen(table
->procname
);
1146 if (table
->proc_handler
)
1150 for (de
= root
->subdir
; de
; de
= de
->next
) {
1151 if (proc_match(len
, table
->procname
, de
))
1154 /* If the subdir exists already, de is non-NULL */
1158 de
= create_proc_entry(table
->procname
, mode
, root
);
1161 de
->data
= (void *) table
;
1162 if (table
->proc_handler
)
1163 de
->proc_fops
= &proc_sys_file_operations
;
1166 if (de
->mode
& S_IFDIR
)
1167 register_proc_table(table
->child
, de
);
1172 * Unregister a /proc sysctl table and any subdirectories.
1174 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
1176 struct proc_dir_entry
*de
;
1177 for (; table
->ctl_name
; table
++) {
1178 if (!(de
= table
->de
))
1180 if (de
->mode
& S_IFDIR
) {
1181 if (!table
->child
) {
1182 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
1185 unregister_proc_table(table
->child
, de
);
1187 /* Don't unregister directories which still have entries.. */
1192 /* Don't unregister proc entries that are still being used.. */
1193 if (atomic_read(&de
->count
))
1197 remove_proc_entry(table
->procname
, root
);
1201 static ssize_t
do_rw_proc(int write
, struct file
* file
, char __user
* buf
,
1202 size_t count
, loff_t
*ppos
)
1205 struct proc_dir_entry
*de
;
1206 struct ctl_table
*table
;
1210 de
= PDE(file
->f_dentry
->d_inode
);
1211 if (!de
|| !de
->data
)
1213 table
= (struct ctl_table
*) de
->data
;
1214 if (!table
|| !table
->proc_handler
)
1216 op
= (write
? 002 : 004);
1217 if (ctl_perm(table
, op
))
1223 * FIXME: we need to pass on ppos to the handler.
1226 error
= (*table
->proc_handler
) (table
, write
, file
, buf
, &res
);
1232 static int proc_opensys(struct inode
*inode
, struct file
*file
)
1234 if (file
->f_mode
& FMODE_WRITE
) {
1236 * sysctl entries that are not writable,
1237 * are _NOT_ writable, capabilities or not.
1239 if (!(inode
->i_mode
& S_IWUSR
))
1246 static ssize_t
proc_readsys(struct file
* file
, char __user
* buf
,
1247 size_t count
, loff_t
*ppos
)
1249 return do_rw_proc(0, file
, buf
, count
, ppos
);
1252 static ssize_t
proc_writesys(struct file
* file
, const char __user
* buf
,
1253 size_t count
, loff_t
*ppos
)
1255 return do_rw_proc(1, file
, (char __user
*) buf
, count
, ppos
);
1259 * proc_dostring - read a string sysctl
1260 * @table: the sysctl table
1261 * @write: %TRUE if this is a write to the sysctl file
1262 * @filp: the file structure
1263 * @buffer: the user buffer
1264 * @lenp: the size of the user buffer
1266 * Reads/writes a string from/to the user buffer. If the kernel
1267 * buffer provided is not large enough to hold the string, the
1268 * string is truncated. The copied string is %NULL-terminated.
1269 * If the string is being read by the user process, it is copied
1270 * and a newline '\n' is added. It is truncated if the buffer is
1273 * Returns 0 on success.
1275 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1276 void __user
*buffer
, size_t *lenp
)
1282 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1283 (filp
->f_pos
&& !write
)) {
1291 while (len
< *lenp
) {
1292 if(get_user(c
, p
++))
1294 if (c
== 0 || c
== '\n')
1298 if (len
>= table
->maxlen
)
1299 len
= table
->maxlen
-1;
1300 if(copy_from_user(table
->data
, buffer
, len
))
1302 ((char *) table
->data
)[len
] = 0;
1303 filp
->f_pos
+= *lenp
;
1305 len
= strlen(table
->data
);
1306 if (len
> table
->maxlen
)
1307 len
= table
->maxlen
;
1311 if(copy_to_user(buffer
, table
->data
, len
))
1314 if(put_user('\n', ((char *) buffer
) + len
))
1325 * Special case of dostring for the UTS structure. This has locks
1326 * to observe. Should this be in kernel/sys.c ????
1329 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1330 void __user
*buffer
, size_t *lenp
)
1335 down_read(&uts_sem
);
1336 r
=proc_dostring(table
,0,filp
,buffer
,lenp
);
1339 down_write(&uts_sem
);
1340 r
=proc_dostring(table
,1,filp
,buffer
,lenp
);
1346 static int do_proc_dointvec_conv(int *negp
, unsigned long *lvalp
,
1348 int write
, void *data
)
1351 *valp
= *negp
? -*lvalp
: *lvalp
;
1356 *lvalp
= (unsigned long)-val
;
1359 *lvalp
= (unsigned long)val
;
1365 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1366 void __user
*buffer
, size_t *lenp
,
1367 int (*conv
)(int *negp
, unsigned long *lvalp
, int *valp
,
1368 int write
, void *data
),
1371 #define TMPBUFLEN 20
1372 int *i
, vleft
, first
=1, neg
, val
;
1376 char buf
[TMPBUFLEN
], *p
;
1378 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1379 (filp
->f_pos
&& !write
)) {
1384 i
= (int *) table
->data
;
1385 vleft
= table
->maxlen
/ sizeof(*i
);
1389 conv
= do_proc_dointvec_conv
;
1391 for (; left
&& vleft
--; i
++, first
=0) {
1395 if (get_user(c
,(char __user
*) buffer
))
1406 if (len
> sizeof(buf
) - 1)
1407 len
= sizeof(buf
) - 1;
1408 if(copy_from_user(buf
, buffer
, len
))
1412 if (*p
== '-' && left
> 1) {
1416 if (*p
< '0' || *p
> '9')
1419 lval
= simple_strtoul(p
, &p
, 0);
1422 if ((len
< left
) && *p
&& !isspace(*p
))
1429 if (conv(&neg
, &lval
, i
, 1, data
))
1436 if (conv(&neg
, &lval
, i
, 0, data
))
1439 sprintf(p
, "%s%lu", neg
? "-" : "", lval
);
1443 if(copy_to_user(buffer
, buf
, len
))
1450 if (!write
&& !first
&& left
) {
1451 if(put_user('\n', (char *) buffer
))
1456 p
= (char *) buffer
;
1459 if(get_user(c
, p
++))
1469 filp
->f_pos
+= *lenp
;
1475 * proc_dointvec - read a vector of integers
1476 * @table: the sysctl table
1477 * @write: %TRUE if this is a write to the sysctl file
1478 * @filp: the file structure
1479 * @buffer: the user buffer
1480 * @lenp: the size of the user buffer
1482 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1483 * values from/to the user buffer, treated as an ASCII string.
1485 * Returns 0 on success.
1487 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1488 void __user
*buffer
, size_t *lenp
)
1490 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,
1500 static int do_proc_dointvec_bset_conv(int *negp
, unsigned long *lvalp
,
1502 int write
, void *data
)
1504 int op
= *(int *)data
;
1506 int val
= *negp
? -*lvalp
: *lvalp
;
1508 case OP_SET
: *valp
= val
; break;
1509 case OP_AND
: *valp
&= val
; break;
1510 case OP_OR
: *valp
|= val
; break;
1511 case OP_MAX
: if(*valp
< val
)
1514 case OP_MIN
: if(*valp
> val
)
1522 *lvalp
= (unsigned long)-val
;
1525 *lvalp
= (unsigned long)val
;
1532 * init may raise the set.
1535 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1536 void __user
*buffer
, size_t *lenp
)
1540 if (!capable(CAP_SYS_MODULE
)) {
1544 op
= (current
->pid
== 1) ? OP_SET
: OP_AND
;
1545 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,
1546 do_proc_dointvec_bset_conv
,&op
);
1549 struct do_proc_dointvec_minmax_conv_param
{
1554 static int do_proc_dointvec_minmax_conv(int *negp
, unsigned long *lvalp
,
1556 int write
, void *data
)
1558 struct do_proc_dointvec_minmax_conv_param
*param
= data
;
1560 int val
= *negp
? -*lvalp
: *lvalp
;
1561 if ((param
->min
&& *param
->min
> val
) ||
1562 (param
->max
&& *param
->max
< val
))
1569 *lvalp
= (unsigned long)-val
;
1572 *lvalp
= (unsigned long)val
;
1579 * proc_dointvec_minmax - read a vector of integers with min/max values
1580 * @table: the sysctl table
1581 * @write: %TRUE if this is a write to the sysctl file
1582 * @filp: the file structure
1583 * @buffer: the user buffer
1584 * @lenp: the size of the user buffer
1586 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1587 * values from/to the user buffer, treated as an ASCII string.
1589 * This routine will ensure the values are within the range specified by
1590 * table->extra1 (min) and table->extra2 (max).
1592 * Returns 0 on success.
1594 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1595 void __user
*buffer
, size_t *lenp
)
1597 struct do_proc_dointvec_minmax_conv_param param
= {
1598 .min
= (int *) table
->extra1
,
1599 .max
= (int *) table
->extra2
,
1601 return do_proc_dointvec(table
, write
, filp
, buffer
, lenp
,
1602 do_proc_dointvec_minmax_conv
, ¶m
);
1605 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
1607 void __user
*buffer
, size_t *lenp
,
1608 unsigned long convmul
,
1609 unsigned long convdiv
)
1611 #define TMPBUFLEN 20
1612 unsigned long *i
, *min
, *max
, val
;
1613 int vleft
, first
=1, neg
;
1615 char buf
[TMPBUFLEN
], *p
;
1617 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
1618 (filp
->f_pos
&& !write
)) {
1623 i
= (unsigned long *) table
->data
;
1624 min
= (unsigned long *) table
->extra1
;
1625 max
= (unsigned long *) table
->extra2
;
1626 vleft
= table
->maxlen
/ sizeof(unsigned long);
1629 for (; left
&& vleft
--; i
++, min
++, max
++, first
=0) {
1633 if (get_user(c
, (char __user
*) buffer
))
1644 if (len
> TMPBUFLEN
-1)
1646 if (copy_from_user(buf
, buffer
, len
))
1650 if (*p
== '-' && left
> 1) {
1654 if (*p
< '0' || *p
> '9')
1656 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
1658 if ((len
< left
) && *p
&& !isspace(*p
))
1667 if ((min
&& val
< *min
) || (max
&& val
> *max
))
1674 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1678 if(copy_to_user(buffer
, buf
, len
))
1685 if (!write
&& !first
&& left
) {
1686 if(put_user('\n', (char *) buffer
))
1691 p
= (char *) buffer
;
1694 if(get_user(c
, p
++))
1704 filp
->f_pos
+= *lenp
;
1710 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1711 * @table: the sysctl table
1712 * @write: %TRUE if this is a write to the sysctl file
1713 * @filp: the file structure
1714 * @buffer: the user buffer
1715 * @lenp: the size of the user buffer
1717 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1718 * values from/to the user buffer, treated as an ASCII string.
1720 * This routine will ensure the values are within the range specified by
1721 * table->extra1 (min) and table->extra2 (max).
1723 * Returns 0 on success.
1725 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1726 void __user
*buffer
, size_t *lenp
)
1728 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, 1l, 1l);
1732 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1733 * @table: the sysctl table
1734 * @write: %TRUE if this is a write to the sysctl file
1735 * @filp: the file structure
1736 * @buffer: the user buffer
1737 * @lenp: the size of the user buffer
1739 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1740 * values from/to the user buffer, treated as an ASCII string. The values
1741 * are treated as milliseconds, and converted to jiffies when they are stored.
1743 * This routine will ensure the values are within the range specified by
1744 * table->extra1 (min) and table->extra2 (max).
1746 * Returns 0 on success.
1748 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1750 void __user
*buffer
, size_t *lenp
)
1752 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1757 static int do_proc_dointvec_jiffies_conv(int *negp
, unsigned long *lvalp
,
1759 int write
, void *data
)
1762 *valp
= *negp
? -(*lvalp
*HZ
) : (*lvalp
*HZ
);
1768 lval
= (unsigned long)-val
;
1771 lval
= (unsigned long)val
;
1778 static int do_proc_dointvec_userhz_jiffies_conv(int *negp
, unsigned long *lvalp
,
1780 int write
, void *data
)
1783 *valp
= clock_t_to_jiffies(*negp
? -*lvalp
: *lvalp
);
1789 lval
= (unsigned long)-val
;
1792 lval
= (unsigned long)val
;
1794 *lvalp
= jiffies_to_clock_t(lval
);
1800 * proc_dointvec_jiffies - read a vector of integers as seconds
1801 * @table: the sysctl table
1802 * @write: %TRUE if this is a write to the sysctl file
1803 * @filp: the file structure
1804 * @buffer: the user buffer
1805 * @lenp: the size of the user buffer
1807 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1808 * values from/to the user buffer, treated as an ASCII string.
1809 * The values read are assumed to be in seconds, and are converted into
1812 * Returns 0 on success.
1814 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1815 void __user
*buffer
, size_t *lenp
)
1817 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,
1818 do_proc_dointvec_jiffies_conv
,NULL
);
1822 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
1823 * @table: the sysctl table
1824 * @write: %TRUE if this is a write to the sysctl file
1825 * @filp: the file structure
1826 * @buffer: the user buffer
1827 * @lenp: the size of the user buffer
1829 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1830 * values from/to the user buffer, treated as an ASCII string.
1831 * The values read are assumed to be in 1/USER_HZ seconds, and
1832 * are converted into jiffies.
1834 * Returns 0 on success.
1836 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1837 void __user
*buffer
, size_t *lenp
)
1839 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,
1840 do_proc_dointvec_userhz_jiffies_conv
,NULL
);
1843 #else /* CONFIG_PROC_FS */
1845 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1846 void *buffer
, size_t *lenp
)
1851 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1852 void *buffer
, size_t *lenp
)
1857 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1858 void *buffer
, size_t *lenp
)
1863 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1864 void *buffer
, size_t *lenp
)
1869 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1870 void *buffer
, size_t *lenp
)
1875 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1876 void *buffer
, size_t *lenp
)
1881 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1882 void *buffer
, size_t *lenp
)
1887 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1888 void *buffer
, size_t *lenp
)
1893 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1895 void *buffer
, size_t *lenp
)
1901 #endif /* CONFIG_PROC_FS */
1905 * General sysctl support routines
1908 /* The generic string strategy routine: */
1909 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
1910 void __user
*oldval
, size_t __user
*oldlenp
,
1911 void __user
*newval
, size_t newlen
, void **context
)
1915 if (!table
->data
|| !table
->maxlen
)
1918 if (oldval
&& oldlenp
) {
1919 if(get_user(len
, oldlenp
))
1922 l
= strlen(table
->data
);
1923 if (len
> l
) len
= l
;
1924 if (len
>= table
->maxlen
)
1925 len
= table
->maxlen
;
1926 if(copy_to_user(oldval
, table
->data
, len
))
1928 if(put_user(0, ((char *) oldval
) + len
))
1930 if(put_user(len
, oldlenp
))
1934 if (newval
&& newlen
) {
1936 if (len
> table
->maxlen
)
1937 len
= table
->maxlen
;
1938 if(copy_from_user(table
->data
, newval
, len
))
1940 if (len
== table
->maxlen
)
1942 ((char *) table
->data
)[len
] = 0;
1948 * This function makes sure that all of the integers in the vector
1949 * are between the minimum and maximum values given in the arrays
1950 * table->extra1 and table->extra2, respectively.
1952 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
1953 void __user
*oldval
, size_t __user
*oldlenp
,
1954 void __user
*newval
, size_t newlen
, void **context
)
1956 int i
, *vec
, *min
, *max
;
1959 if (newval
&& newlen
) {
1960 if (newlen
% sizeof(int) != 0)
1963 if (!table
->extra1
&& !table
->extra2
)
1966 if (newlen
> table
->maxlen
)
1967 newlen
= table
->maxlen
;
1968 length
= newlen
/ sizeof(int);
1970 vec
= (int *) newval
;
1971 min
= (int *) table
->extra1
;
1972 max
= (int *) table
->extra2
;
1974 for (i
= 0; i
< length
; i
++) {
1976 get_user(value
, vec
+ i
);
1977 if (min
&& value
< min
[i
])
1979 if (max
&& value
> max
[i
])
1986 /* Strategy function to convert jiffies to seconds */
1987 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
1988 void __user
*oldval
, size_t __user
*oldlenp
,
1989 void __user
*newval
, size_t newlen
, void **context
)
1994 if (get_user(olen
, oldlenp
))
1996 if (olen
!=sizeof(int))
1999 if (put_user(*(int *)(table
->data
) / HZ
, (int *)oldval
) ||
2000 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
2003 if (newval
&& newlen
) {
2005 if (newlen
!= sizeof(int))
2007 if (get_user(new, (int *)newval
))
2009 *(int *)(table
->data
) = new*HZ
;
2015 #else /* CONFIG_SYSCTL */
2018 extern asmlinkage
long sys_sysctl(struct __sysctl_args __user
*args
)
2023 int sysctl_string(ctl_table
*table
, int __user
*name
, int nlen
,
2024 void __user
*oldval
, size_t __user
*oldlenp
,
2025 void __user
*newval
, size_t newlen
, void **context
)
2030 int sysctl_intvec(ctl_table
*table
, int __user
*name
, int nlen
,
2031 void __user
*oldval
, size_t __user
*oldlenp
,
2032 void __user
*newval
, size_t newlen
, void **context
)
2037 int sysctl_jiffies(ctl_table
*table
, int __user
*name
, int nlen
,
2038 void __user
*oldval
, size_t __user
*oldlenp
,
2039 void __user
*newval
, size_t newlen
, void **context
)
2044 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
2045 void __user
*buffer
, size_t *lenp
)
2050 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
2051 void __user
*buffer
, size_t *lenp
)
2056 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
2057 void __user
*buffer
, size_t *lenp
)
2062 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2063 void __user
*buffer
, size_t *lenp
)
2068 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2069 void *buffer
, size_t *lenp
)
2074 int proc_dointvec_userhz_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
2075 void *buffer
, size_t *lenp
)
2080 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
2081 void __user
*buffer
, size_t *lenp
)
2086 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
2088 void __user
*buffer
, size_t *lenp
)
2093 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
2099 void unregister_sysctl_table(struct ctl_table_header
* table
)
2103 #endif /* CONFIG_SYSCTL */
2106 * No sense putting this after each symbol definition, twice,
2107 * exception granted :-)
2109 EXPORT_SYMBOL(proc_dointvec
);
2110 EXPORT_SYMBOL(proc_dointvec_jiffies
);
2111 EXPORT_SYMBOL(proc_dointvec_minmax
);
2112 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies
);
2113 EXPORT_SYMBOL(proc_dostring
);
2114 EXPORT_SYMBOL(proc_doulongvec_minmax
);
2115 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax
);
2116 EXPORT_SYMBOL(register_sysctl_table
);
2117 EXPORT_SYMBOL(sysctl_intvec
);
2118 EXPORT_SYMBOL(sysctl_jiffies
);
2119 EXPORT_SYMBOL(sysctl_string
);
2120 EXPORT_SYMBOL(unregister_sysctl_table
);