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/malloc.h>
23 #include <linux/sysctl.h>
24 #include <linux/swapctl.h>
25 #include <linux/proc_fs.h>
26 #include <linux/ctype.h>
27 #include <linux/utsname.h>
28 #include <linux/capability.h>
29 #include <linux/smp_lock.h>
30 #include <linux/init.h>
31 #include <linux/sysrq.h>
32 #include <linux/highuid.h>
34 #include <asm/uaccess.h>
36 #ifdef CONFIG_ROOT_NFS
37 #include <linux/nfs_fs.h>
40 #if defined(CONFIG_SYSCTL)
42 /* External variables not in a header file. */
43 extern int panic_timeout
;
45 extern int bdf_prm
[], bdflush_min
[], bdflush_max
[];
46 extern int sysctl_overcommit_memory
;
47 extern int max_threads
;
48 extern int nr_queued_signals
, max_queued_signals
;
49 extern int sysrq_enabled
;
51 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
52 static int maxolduid
= 65535;
56 extern char modprobe_path
[];
59 extern char hotplug_path
[];
61 #ifdef CONFIG_CHR_DEV_SG
62 extern int sg_big_buff
;
65 extern size_t shm_ctlmax
;
66 extern int msg_ctlmax
;
67 extern int msg_ctlmnb
;
68 extern int msg_ctlmni
;
69 extern int sem_ctls
[];
73 extern char reboot_command
[];
74 extern int stop_a_enabled
;
77 extern unsigned long htab_reclaim_on
, zero_paged_on
, powersave_nap
;
78 int proc_dol2crvec(ctl_table
*table
, int write
, struct file
*filp
,
79 void *buffer
, size_t *lenp
);
82 #ifdef CONFIG_BSD_PROCESS_ACCT
83 extern int acct_parm
[];
86 extern int pgt_cache_water
[];
88 static int parse_table(int *, int, void *, size_t *, void *, size_t,
89 ctl_table
*, void **);
90 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
91 void *buffer
, size_t *lenp
);
93 static ctl_table root_table
[];
94 static struct ctl_table_header root_table_header
=
95 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
97 static ctl_table kern_table
[];
98 static ctl_table vm_table
[];
100 extern ctl_table net_table
[];
102 static ctl_table proc_table
[];
103 static ctl_table fs_table
[];
104 static ctl_table debug_table
[];
105 static ctl_table dev_table
[];
106 extern ctl_table random_table
[];
108 /* /proc declarations: */
110 #ifdef CONFIG_PROC_FS
112 static ssize_t
proc_readsys(struct file
*, char *, size_t, loff_t
*);
113 static ssize_t
proc_writesys(struct file
*, const char *, size_t, loff_t
*);
114 static int proc_sys_permission(struct inode
*, int);
116 struct file_operations proc_sys_file_operations
= {
118 write
: proc_writesys
,
121 static struct inode_operations proc_sys_inode_operations
= {
122 permission
: proc_sys_permission
,
125 extern struct proc_dir_entry
*proc_sys_root
;
127 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*);
128 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
131 extern int inodes_stat
[];
132 extern int dentry_stat
[];
134 /* The default sysctl tables: */
136 static ctl_table root_table
[] = {
137 {CTL_KERN
, "kernel", NULL
, 0, 0555, kern_table
},
138 {CTL_VM
, "vm", NULL
, 0, 0555, vm_table
},
140 {CTL_NET
, "net", NULL
, 0, 0555, net_table
},
142 {CTL_PROC
, "proc", NULL
, 0, 0555, proc_table
},
143 {CTL_FS
, "fs", NULL
, 0, 0555, fs_table
},
144 {CTL_DEBUG
, "debug", NULL
, 0, 0555, debug_table
},
145 {CTL_DEV
, "dev", NULL
, 0, 0555, dev_table
},
149 static ctl_table kern_table
[] = {
150 {KERN_OSTYPE
, "ostype", system_utsname
.sysname
, 64,
151 0444, NULL
, &proc_doutsstring
, &sysctl_string
},
152 {KERN_OSRELEASE
, "osrelease", system_utsname
.release
, 64,
153 0444, NULL
, &proc_doutsstring
, &sysctl_string
},
154 {KERN_VERSION
, "version", system_utsname
.version
, 64,
155 0444, NULL
, &proc_doutsstring
, &sysctl_string
},
156 {KERN_NODENAME
, "hostname", system_utsname
.nodename
, 64,
157 0644, NULL
, &proc_doutsstring
, &sysctl_string
},
158 {KERN_DOMAINNAME
, "domainname", system_utsname
.domainname
, 64,
159 0644, NULL
, &proc_doutsstring
, &sysctl_string
},
160 {KERN_PANIC
, "panic", &panic_timeout
, sizeof(int),
161 0644, NULL
, &proc_dointvec
},
162 {KERN_CAP_BSET
, "cap-bound", &cap_bset
, sizeof(kernel_cap_t
),
163 0600, NULL
, &proc_dointvec_bset
},
164 #ifdef CONFIG_BLK_DEV_INITRD
165 {KERN_REALROOTDEV
, "real-root-dev", &real_root_dev
, sizeof(int),
166 0644, NULL
, &proc_dointvec
},
169 {KERN_SPARC_REBOOT
, "reboot-cmd", reboot_command
,
170 256, 0644, NULL
, &proc_dostring
, &sysctl_string
},
171 {KERN_SPARC_STOP_A
, "stop-a", &stop_a_enabled
, sizeof (int),
172 0644, NULL
, &proc_dointvec
},
175 {KERN_PPC_HTABRECLAIM
, "htab-reclaim", &htab_reclaim_on
, sizeof(int),
176 0644, NULL
, &proc_dointvec
},
177 {KERN_PPC_ZEROPAGED
, "zero-paged", &zero_paged_on
, sizeof(int),
178 0644, NULL
, &proc_dointvec
},
179 {KERN_PPC_POWERSAVE_NAP
, "powersave-nap", &powersave_nap
, sizeof(int),
180 0644, NULL
, &proc_dointvec
},
181 {KERN_PPC_L2CR
, "l2cr", NULL
, 0,
182 0644, NULL
, &proc_dol2crvec
},
184 {KERN_CTLALTDEL
, "ctrl-alt-del", &C_A_D
, sizeof(int),
185 0644, NULL
, &proc_dointvec
},
186 {KERN_PRINTK
, "printk", &console_loglevel
, 4*sizeof(int),
187 0644, NULL
, &proc_dointvec
},
189 {KERN_MODPROBE
, "modprobe", &modprobe_path
, 256,
190 0644, NULL
, &proc_dostring
, &sysctl_string
},
192 #ifdef CONFIG_HOTPLUG
193 {KERN_HOTPLUG
, "hotplug", &hotplug_path
, 256,
194 0644, NULL
, &proc_dostring
, &sysctl_string
},
196 #ifdef CONFIG_CHR_DEV_SG
197 {KERN_SG_BIG_BUFF
, "sg-big-buff", &sg_big_buff
, sizeof (int),
198 0444, NULL
, &proc_dointvec
},
200 #ifdef CONFIG_BSD_PROCESS_ACCT
201 {KERN_ACCT
, "acct", &acct_parm
, 3*sizeof(int),
202 0644, NULL
, &proc_dointvec
},
204 {KERN_RTSIGNR
, "rtsig-nr", &nr_queued_signals
, sizeof(int),
205 0444, NULL
, &proc_dointvec
},
206 {KERN_RTSIGMAX
, "rtsig-max", &max_queued_signals
, sizeof(int),
207 0644, NULL
, &proc_dointvec
},
208 #ifdef CONFIG_SYSVIPC
209 {KERN_SHMMAX
, "shmmax", &shm_ctlmax
, sizeof (size_t),
210 0644, NULL
, &proc_doulongvec_minmax
},
211 {KERN_MSGMAX
, "msgmax", &msg_ctlmax
, sizeof (int),
212 0644, NULL
, &proc_dointvec
},
213 {KERN_MSGMNI
, "msgmni", &msg_ctlmni
, sizeof (int),
214 0644, NULL
, &proc_dointvec
},
215 {KERN_MSGMNB
, "msgmnb", &msg_ctlmnb
, sizeof (int),
216 0644, NULL
, &proc_dointvec
},
217 {KERN_SEM
, "sem", &sem_ctls
, 4*sizeof (int),
218 0644, NULL
, &proc_dointvec
},
220 #ifdef CONFIG_MAGIC_SYSRQ
221 {KERN_SYSRQ
, "sysrq", &sysrq_enabled
, sizeof (int),
222 0644, NULL
, &proc_dointvec
},
224 {KERN_MAX_THREADS
, "threads-max", &max_threads
, sizeof(int),
225 0644, NULL
, &proc_dointvec
},
226 {KERN_RANDOM
, "random", NULL
, 0, 0555, random_table
},
227 {KERN_OVERFLOWUID
, "overflowuid", &overflowuid
, sizeof(int), 0644, NULL
,
228 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
229 &minolduid
, &maxolduid
},
230 {KERN_OVERFLOWGID
, "overflowgid", &overflowgid
, sizeof(int), 0644, NULL
,
231 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
232 &minolduid
, &maxolduid
},
236 static ctl_table vm_table
[] = {
237 {VM_FREEPG
, "freepages",
238 &freepages
, sizeof(freepages_t
), 0444, NULL
, &proc_dointvec
},
239 {VM_BDFLUSH
, "bdflush", &bdf_prm
, 9*sizeof(int), 0644, NULL
,
240 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
241 &bdflush_min
, &bdflush_max
},
242 {VM_OVERCOMMIT_MEMORY
, "overcommit_memory", &sysctl_overcommit_memory
,
243 sizeof(sysctl_overcommit_memory
), 0644, NULL
, &proc_dointvec
},
244 {VM_BUFFERMEM
, "buffermem",
245 &buffer_mem
, sizeof(buffer_mem_t
), 0644, NULL
, &proc_dointvec
},
246 {VM_PAGECACHE
, "pagecache",
247 &page_cache
, sizeof(buffer_mem_t
), 0644, NULL
, &proc_dointvec
},
248 {VM_PAGERDAEMON
, "kswapd",
249 &pager_daemon
, sizeof(pager_daemon_t
), 0644, NULL
, &proc_dointvec
},
250 {VM_PGT_CACHE
, "pagetable_cache",
251 &pgt_cache_water
, 2*sizeof(int), 0644, NULL
, &proc_dointvec
},
252 {VM_PAGE_CLUSTER
, "page-cluster",
253 &page_cluster
, sizeof(int), 0644, NULL
, &proc_dointvec
},
257 static ctl_table proc_table
[] = {
261 static ctl_table fs_table
[] = {
262 {FS_NRINODE
, "inode-nr", &inodes_stat
, 2*sizeof(int),
263 0444, NULL
, &proc_dointvec
},
264 {FS_STATINODE
, "inode-state", &inodes_stat
, 7*sizeof(int),
265 0444, NULL
, &proc_dointvec
},
266 {FS_NRFILE
, "file-nr", &files_stat
, 3*sizeof(int),
267 0444, NULL
, &proc_dointvec
},
268 {FS_MAXFILE
, "file-max", &files_stat
.max_files
, sizeof(int),
269 0644, NULL
, &proc_dointvec
},
270 {FS_NRSUPER
, "super-nr", &nr_super_blocks
, sizeof(int),
271 0444, NULL
, &proc_dointvec
},
272 {FS_MAXSUPER
, "super-max", &max_super_blocks
, sizeof(int),
273 0644, NULL
, &proc_dointvec
},
274 {FS_NRDQUOT
, "dquot-nr", &nr_dquots
, 2*sizeof(int),
275 0444, NULL
, &proc_dointvec
},
276 {FS_MAXDQUOT
, "dquot-max", &max_dquots
, sizeof(int),
277 0644, NULL
, &proc_dointvec
},
278 {FS_DENTRY
, "dentry-state", &dentry_stat
, 6*sizeof(int),
279 0444, NULL
, &proc_dointvec
},
280 {FS_OVERFLOWUID
, "overflowuid", &fs_overflowuid
, sizeof(int), 0644, NULL
,
281 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
282 &minolduid
, &maxolduid
},
283 {FS_OVERFLOWGID
, "overflowgid", &fs_overflowgid
, sizeof(int), 0644, NULL
,
284 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
285 &minolduid
, &maxolduid
},
286 {FS_LEASES
, "leases-enable", &leases_enable
, sizeof(int),
287 0644, NULL
, &proc_dointvec
},
288 {FS_DIR_NOTIFY
, "dir-notify-enable", &dir_notify_enable
,
289 sizeof(int), 0644, NULL
, &proc_dointvec
},
290 {FS_LEASE_TIME
, "lease-break-time", &lease_break_time
, sizeof(int),
291 0644, NULL
, &proc_dointvec
},
295 static ctl_table debug_table
[] = {
299 static ctl_table dev_table
[] = {
303 extern void init_irq_proc (void);
305 void __init
sysctl_init(void)
307 #ifdef CONFIG_PROC_FS
308 register_proc_table(root_table
, proc_sys_root
);
313 int do_sysctl(int *name
, int nlen
, void *oldval
, size_t *oldlenp
,
314 void *newval
, size_t newlen
)
316 struct list_head
*tmp
;
318 if (nlen
== 0 || nlen
>= CTL_MAXNAME
)
322 if (!oldlenp
|| get_user(old_len
, oldlenp
))
325 tmp
= &root_table_header
.ctl_entry
;
327 struct ctl_table_header
*head
=
328 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
329 void *context
= NULL
;
330 int error
= parse_table(name
, nlen
, oldval
, oldlenp
,
331 newval
, newlen
, head
->ctl_table
,
335 if (error
!= -ENOTDIR
)
338 } while (tmp
!= &root_table_header
.ctl_entry
);
342 extern asmlinkage
long sys_sysctl(struct __sysctl_args
*args
)
344 struct __sysctl_args tmp
;
347 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
351 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
352 tmp
.newval
, tmp
.newlen
);
358 * ctl_perm does NOT grant the superuser all rights automatically, because
359 * some sysctl variables are readonly even to root.
362 static int test_perm(int mode
, int op
)
366 else if (in_egroup_p(0))
368 if ((mode
& op
& 0007) == op
)
373 static inline int ctl_perm(ctl_table
*table
, int op
)
375 return test_perm(table
->mode
, op
);
378 static int parse_table(int *name
, int nlen
,
379 void *oldval
, size_t *oldlenp
,
380 void *newval
, size_t newlen
,
381 ctl_table
*table
, void **context
)
387 if (get_user(n
, name
))
389 for ( ; table
->ctl_name
; table
++) {
390 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
393 if (ctl_perm(table
, 001))
395 if (table
->strategy
) {
396 error
= table
->strategy(
399 newval
, newlen
, context
);
405 table
= table
->child
;
408 error
= do_sysctl_strategy(table
, name
, nlen
,
410 newval
, newlen
, context
);
417 /* Perform the actual read/write of a sysctl table entry. */
418 int do_sysctl_strategy (ctl_table
*table
,
420 void *oldval
, size_t *oldlenp
,
421 void *newval
, size_t newlen
, void **context
)
429 if (ctl_perm(table
, op
))
432 if (table
->strategy
) {
433 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
434 newval
, newlen
, context
);
441 /* If there is no strategy routine, or if the strategy returns
442 * zero, proceed with automatic r/w */
443 if (table
->data
&& table
->maxlen
) {
444 if (oldval
&& oldlenp
) {
445 get_user(len
, oldlenp
);
447 if (len
> table
->maxlen
)
449 if(copy_to_user(oldval
, table
->data
, len
))
451 if(put_user(len
, oldlenp
))
455 if (newval
&& newlen
) {
457 if (len
> table
->maxlen
)
459 if(copy_from_user(table
->data
, newval
, len
))
466 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
469 struct ctl_table_header
*tmp
;
470 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
473 tmp
->ctl_table
= table
;
474 INIT_LIST_HEAD(&tmp
->ctl_entry
);
476 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
478 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
479 #ifdef CONFIG_PROC_FS
480 register_proc_table(table
, proc_sys_root
);
486 * Unlink and free a ctl_table.
488 void unregister_sysctl_table(struct ctl_table_header
* header
)
490 list_del(&header
->ctl_entry
);
491 #ifdef CONFIG_PROC_FS
492 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
501 #ifdef CONFIG_PROC_FS
503 /* Scan the sysctl entries in table and add them all into /proc */
504 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
506 struct proc_dir_entry
*de
;
510 for (; table
->ctl_name
; table
++) {
511 /* Can't do anything without a proc name. */
512 if (!table
->procname
)
514 /* Maybe we can't do anything with it... */
515 if (!table
->proc_handler
&& !table
->child
) {
516 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
521 len
= strlen(table
->procname
);
525 if (table
->proc_handler
)
529 for (de
= root
->subdir
; de
; de
= de
->next
) {
530 if (proc_match(len
, table
->procname
, de
))
533 /* If the subdir exists already, de is non-NULL */
537 de
= create_proc_entry(table
->procname
, mode
, root
);
540 de
->data
= (void *) table
;
541 if (table
->proc_handler
) {
542 de
->proc_fops
= &proc_sys_file_operations
;
543 de
->proc_iops
= &proc_sys_inode_operations
;
547 if (de
->mode
& S_IFDIR
)
548 register_proc_table(table
->child
, de
);
553 * Unregister a /proc sysctl table and any subdirectories.
555 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
557 struct proc_dir_entry
*de
;
558 for (; table
->ctl_name
; table
++) {
559 if (!(de
= table
->de
))
561 if (de
->mode
& S_IFDIR
) {
563 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
566 unregister_proc_table(table
->child
, de
);
568 /* Don't unregister directories which still have entries.. */
573 /* Don't unregister proc entries that are still being used.. */
574 if (atomic_read(&de
->count
))
578 remove_proc_entry(table
->procname
, root
);
582 static ssize_t
do_rw_proc(int write
, struct file
* file
, char * buf
,
583 size_t count
, loff_t
*ppos
)
586 struct proc_dir_entry
*de
;
587 struct ctl_table
*table
;
591 de
= (struct proc_dir_entry
*) file
->f_dentry
->d_inode
->u
.generic_ip
;
592 if (!de
|| !de
->data
)
594 table
= (struct ctl_table
*) de
->data
;
595 if (!table
|| !table
->proc_handler
)
597 op
= (write
? 002 : 004);
598 if (ctl_perm(table
, op
))
604 * FIXME: we need to pass on ppos to the handler.
607 error
= (*table
->proc_handler
) (table
, write
, file
, buf
, &res
);
613 static ssize_t
proc_readsys(struct file
* file
, char * buf
,
614 size_t count
, loff_t
*ppos
)
616 return do_rw_proc(0, file
, buf
, count
, ppos
);
619 static ssize_t
proc_writesys(struct file
* file
, const char * buf
,
620 size_t count
, loff_t
*ppos
)
622 return do_rw_proc(1, file
, (char *) buf
, count
, ppos
);
625 static int proc_sys_permission(struct inode
*inode
, int op
)
627 return test_perm(inode
->i_mode
, op
);
630 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
631 void *buffer
, size_t *lenp
)
636 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
637 (filp
->f_pos
&& !write
)) {
645 while (len
< *lenp
) {
648 if (c
== 0 || c
== '\n')
652 if (len
>= table
->maxlen
)
653 len
= table
->maxlen
-1;
654 if(copy_from_user(table
->data
, buffer
, len
))
656 ((char *) table
->data
)[len
] = 0;
657 filp
->f_pos
+= *lenp
;
659 len
= strlen(table
->data
);
660 if (len
> table
->maxlen
)
665 if(copy_to_user(buffer
, table
->data
, len
))
668 if(put_user('\n', ((char *) buffer
) + len
))
679 * Special case of dostring for the UTS structure. This has locks
680 * to observe. Should this be in kernel/sys.c ????
683 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
684 void *buffer
, size_t *lenp
)
690 r
=proc_dostring(table
,0,filp
,buffer
,lenp
);
693 down_write(&uts_sem
);
694 r
=proc_dostring(table
,1,filp
,buffer
,lenp
);
706 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
707 void *buffer
, size_t *lenp
, int conv
, int op
)
709 int *i
, vleft
, first
=1, len
, left
, neg
, val
;
711 char buf
[TMPBUFLEN
], *p
;
713 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
714 (filp
->f_pos
&& !write
)) {
719 i
= (int *) table
->data
;
720 vleft
= table
->maxlen
/ sizeof(int);
723 for (; left
&& vleft
--; i
++, first
=0) {
727 if(get_user(c
,(char *) buffer
))
738 if (len
> TMPBUFLEN
-1)
740 if(copy_from_user(buf
, buffer
, len
))
744 if (*p
== '-' && left
> 1) {
748 if (*p
< '0' || *p
> '9')
750 val
= simple_strtoul(p
, &p
, 0) * conv
;
752 if ((len
< left
) && *p
&& !isspace(*p
))
759 case OP_SET
: *i
= val
; break;
760 case OP_AND
: *i
&= val
; break;
761 case OP_OR
: *i
|= val
; break;
762 case OP_MAX
: if(*i
< val
)
765 case OP_MIN
: if(*i
> val
)
773 sprintf(p
, "%d", (*i
) / conv
);
777 if(copy_to_user(buffer
, buf
, len
))
784 if (!write
&& !first
&& left
) {
785 if(put_user('\n', (char *) buffer
))
803 filp
->f_pos
+= *lenp
;
807 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
808 void *buffer
, size_t *lenp
)
810 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,1,OP_SET
);
814 * init may raise the set.
817 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
818 void *buffer
, size_t *lenp
)
820 if (!capable(CAP_SYS_MODULE
)) {
823 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,1,
824 (current
->pid
== 1) ? OP_SET
: OP_AND
);
827 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
828 void *buffer
, size_t *lenp
)
830 int *i
, *min
, *max
, vleft
, first
=1, len
, left
, neg
, val
;
832 char buf
[TMPBUFLEN
], *p
;
834 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
835 (filp
->f_pos
&& !write
)) {
840 i
= (int *) table
->data
;
841 min
= (int *) table
->extra1
;
842 max
= (int *) table
->extra2
;
843 vleft
= table
->maxlen
/ sizeof(int);
846 for (; left
&& vleft
--; i
++, first
=0) {
850 if(get_user(c
, (char *) buffer
))
861 if (len
> TMPBUFLEN
-1)
863 if(copy_from_user(buf
, buffer
, len
))
867 if (*p
== '-' && left
> 1) {
871 if (*p
< '0' || *p
> '9')
873 val
= simple_strtoul(p
, &p
, 0);
875 if ((len
< left
) && *p
&& !isspace(*p
))
882 if (min
&& val
< *min
++)
884 if (max
&& val
> *max
++)
891 sprintf(p
, "%d", *i
);
895 if(copy_to_user(buffer
, buf
, len
))
902 if (!write
&& !first
&& left
) {
903 if(put_user('\n', (char *) buffer
))
921 filp
->f_pos
+= *lenp
;
926 * an unsigned long function version
929 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
931 void *buffer
, size_t *lenp
,
932 unsigned long convmul
,
933 unsigned long convdiv
)
936 unsigned long *i
, *min
, *max
, val
;
937 int vleft
, first
=1, len
, left
, neg
;
938 char buf
[TMPBUFLEN
], *p
;
940 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
941 (filp
->f_pos
&& !write
)) {
946 i
= (unsigned long *) table
->data
;
947 min
= (unsigned long *) table
->extra1
;
948 max
= (unsigned long *) table
->extra2
;
949 vleft
= table
->maxlen
/ sizeof(unsigned long);
952 for (; left
&& vleft
--; i
++, first
=0) {
956 if(get_user(c
, (char *) buffer
))
967 if (len
> TMPBUFLEN
-1)
969 if(copy_from_user(buf
, buffer
, len
))
973 if (*p
== '-' && left
> 1) {
977 if (*p
< '0' || *p
> '9')
979 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
981 if ((len
< left
) && *p
&& !isspace(*p
))
990 if (min
&& val
< *min
++)
992 if (max
&& val
> *max
++)
999 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
1003 if(copy_to_user(buffer
, buf
, len
))
1010 if (!write
&& !first
&& left
) {
1011 if(put_user('\n', (char *) buffer
))
1016 p
= (char *) buffer
;
1019 if(get_user(c
, p
++))
1029 filp
->f_pos
+= *lenp
;
1034 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1035 void *buffer
, size_t *lenp
)
1037 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, 1l, 1l);
1040 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1042 void *buffer
, size_t *lenp
)
1044 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1049 /* Like proc_dointvec, but converts seconds to jiffies */
1050 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1051 void *buffer
, size_t *lenp
)
1053 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,HZ
,OP_SET
);
1056 #else /* CONFIG_PROC_FS */
1058 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1059 void *buffer
, size_t *lenp
)
1064 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1065 void *buffer
, size_t *lenp
)
1070 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1071 void *buffer
, size_t *lenp
)
1076 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1077 void *buffer
, size_t *lenp
)
1082 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1083 void *buffer
, size_t *lenp
)
1088 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1089 void *buffer
, size_t *lenp
)
1094 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1095 void *buffer
, size_t *lenp
)
1100 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1102 void *buffer
, size_t *lenp
)
1108 #endif /* CONFIG_PROC_FS */
1112 * General sysctl support routines
1115 /* The generic string strategy routine: */
1116 int sysctl_string(ctl_table
*table
, int *name
, int nlen
,
1117 void *oldval
, size_t *oldlenp
,
1118 void *newval
, size_t newlen
, void **context
)
1122 if (!table
->data
|| !table
->maxlen
)
1125 if (oldval
&& oldlenp
) {
1126 if(get_user(len
, oldlenp
))
1129 l
= strlen(table
->data
);
1130 if (len
> l
) len
= l
;
1131 if (len
>= table
->maxlen
)
1132 len
= table
->maxlen
;
1133 if(copy_to_user(oldval
, table
->data
, len
))
1135 if(put_user(0, ((char *) oldval
) + len
))
1137 if(put_user(len
, oldlenp
))
1141 if (newval
&& newlen
) {
1143 if (len
> table
->maxlen
)
1144 len
= table
->maxlen
;
1145 if(copy_from_user(table
->data
, newval
, len
))
1147 if (len
== table
->maxlen
)
1149 ((char *) table
->data
)[len
] = 0;
1155 * This function makes sure that all of the integers in the vector
1156 * are between the minimum and maximum values given in the arrays
1157 * table->extra1 and table->extra2, respectively.
1159 int sysctl_intvec(ctl_table
*table
, int *name
, int nlen
,
1160 void *oldval
, size_t *oldlenp
,
1161 void *newval
, size_t newlen
, void **context
)
1163 int i
, length
, *vec
, *min
, *max
;
1165 if (newval
&& newlen
) {
1166 if (newlen
% sizeof(int) != 0)
1169 if (!table
->extra1
&& !table
->extra2
)
1172 if (newlen
> table
->maxlen
)
1173 newlen
= table
->maxlen
;
1174 length
= newlen
/ sizeof(int);
1176 vec
= (int *) newval
;
1177 min
= (int *) table
->extra1
;
1178 max
= (int *) table
->extra2
;
1180 for (i
= 0; i
< length
; i
++) {
1182 get_user(value
, vec
+ i
);
1183 if (min
&& value
< min
[i
])
1185 if (max
&& value
> max
[i
])
1192 /* Strategy function to convert jiffies to seconds */
1193 int sysctl_jiffies(ctl_table
*table
, int *name
, int nlen
,
1194 void *oldval
, size_t *oldlenp
,
1195 void *newval
, size_t newlen
, void **context
)
1200 if (get_user(olen
, oldlenp
))
1202 if (olen
!=sizeof(int))
1205 if (put_user(*(int *)(table
->data
) / HZ
, (int *)oldval
) ||
1206 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
1209 if (newval
&& newlen
) {
1211 if (newlen
!= sizeof(int))
1213 if (get_user(new, (int *)newval
))
1215 *(int *)(table
->data
) = new*HZ
;
1221 #else /* CONFIG_SYSCTL */
1224 extern asmlinkage
long sys_sysctl(struct __sysctl_args
*args
)
1229 int sysctl_string(ctl_table
*table
, int *name
, int nlen
,
1230 void *oldval
, size_t *oldlenp
,
1231 void *newval
, size_t newlen
, void **context
)
1236 int sysctl_intvec(ctl_table
*table
, int *name
, int nlen
,
1237 void *oldval
, size_t *oldlenp
,
1238 void *newval
, size_t newlen
, void **context
)
1243 int sysctl_jiffies(ctl_table
*table
, int *name
, int nlen
,
1244 void *oldval
, size_t *oldlenp
,
1245 void *newval
, size_t newlen
, void **context
)
1250 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1251 void *buffer
, size_t *lenp
)
1256 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1257 void *buffer
, size_t *lenp
)
1262 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1263 void *buffer
, size_t *lenp
)
1268 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1269 void *buffer
, size_t *lenp
)
1274 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1275 void *buffer
, size_t *lenp
)
1280 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1281 void *buffer
, size_t *lenp
)
1286 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1288 void *buffer
, size_t *lenp
)
1293 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
1299 void unregister_sysctl_table(struct ctl_table_header
* table
)
1303 #endif /* CONFIG_SYSCTL */