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
;
44 extern int console_loglevel
, C_A_D
;
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
;
50 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
51 static int maxolduid
= 65535;
55 extern char modprobe_path
[];
57 #ifdef CONFIG_CHR_DEV_SG
58 extern int sg_big_buff
;
61 extern size_t shm_ctlmax
;
62 extern int msg_ctlmax
;
63 extern int msg_ctlmnb
;
64 extern int msg_ctlmni
;
65 extern int sem_ctls
[];
69 extern char reboot_command
[];
70 extern int stop_a_enabled
;
73 extern unsigned long htab_reclaim_on
, zero_paged_on
, powersave_nap
;
74 int proc_dol2crvec(ctl_table
*table
, int write
, struct file
*filp
,
75 void *buffer
, size_t *lenp
);
78 #ifdef CONFIG_BSD_PROCESS_ACCT
79 extern int acct_parm
[];
82 extern int pgt_cache_water
[];
84 static int parse_table(int *, int, void *, size_t *, void *, size_t,
85 ctl_table
*, void **);
86 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
87 void *buffer
, size_t *lenp
);
89 static ctl_table root_table
[];
90 static struct ctl_table_header root_table_header
=
91 { root_table
, LIST_HEAD_INIT(root_table_header
.ctl_entry
) };
93 static ctl_table kern_table
[];
94 static ctl_table vm_table
[];
96 extern ctl_table net_table
[];
98 static ctl_table proc_table
[];
99 static ctl_table fs_table
[];
100 static ctl_table debug_table
[];
101 static ctl_table dev_table
[];
102 extern ctl_table random_table
[];
104 /* /proc declarations: */
106 #ifdef CONFIG_PROC_FS
108 static ssize_t
proc_readsys(struct file
*, char *, size_t, loff_t
*);
109 static ssize_t
proc_writesys(struct file
*, const char *, size_t, loff_t
*);
110 static int proc_sys_permission(struct inode
*, int);
112 struct file_operations proc_sys_file_operations
= {
114 write
: proc_writesys
,
117 static struct inode_operations proc_sys_inode_operations
= {
118 permission
: proc_sys_permission
,
121 extern struct proc_dir_entry
*proc_sys_root
;
123 static void register_proc_table(ctl_table
*, struct proc_dir_entry
*);
124 static void unregister_proc_table(ctl_table
*, struct proc_dir_entry
*);
127 extern int inodes_stat
[];
128 extern int dentry_stat
[];
130 /* The default sysctl tables: */
132 static ctl_table root_table
[] = {
133 {CTL_KERN
, "kernel", NULL
, 0, 0555, kern_table
},
134 {CTL_VM
, "vm", NULL
, 0, 0555, vm_table
},
136 {CTL_NET
, "net", NULL
, 0, 0555, net_table
},
138 {CTL_PROC
, "proc", NULL
, 0, 0555, proc_table
},
139 {CTL_FS
, "fs", NULL
, 0, 0555, fs_table
},
140 {CTL_DEBUG
, "debug", NULL
, 0, 0555, debug_table
},
141 {CTL_DEV
, "dev", NULL
, 0, 0555, dev_table
},
145 static ctl_table kern_table
[] = {
146 {KERN_OSTYPE
, "ostype", system_utsname
.sysname
, 64,
147 0444, NULL
, &proc_doutsstring
, &sysctl_string
},
148 {KERN_OSRELEASE
, "osrelease", system_utsname
.release
, 64,
149 0444, NULL
, &proc_doutsstring
, &sysctl_string
},
150 {KERN_VERSION
, "version", system_utsname
.version
, 64,
151 0444, NULL
, &proc_doutsstring
, &sysctl_string
},
152 {KERN_NODENAME
, "hostname", system_utsname
.nodename
, 64,
153 0644, NULL
, &proc_doutsstring
, &sysctl_string
},
154 {KERN_DOMAINNAME
, "domainname", system_utsname
.domainname
, 64,
155 0644, NULL
, &proc_doutsstring
, &sysctl_string
},
156 {KERN_PANIC
, "panic", &panic_timeout
, sizeof(int),
157 0644, NULL
, &proc_dointvec
},
158 {KERN_CAP_BSET
, "cap-bound", &cap_bset
, sizeof(kernel_cap_t
),
159 0600, NULL
, &proc_dointvec_bset
},
160 #ifdef CONFIG_BLK_DEV_INITRD
161 {KERN_REALROOTDEV
, "real-root-dev", &real_root_dev
, sizeof(int),
162 0644, NULL
, &proc_dointvec
},
165 {KERN_SPARC_REBOOT
, "reboot-cmd", reboot_command
,
166 256, 0644, NULL
, &proc_dostring
, &sysctl_string
},
167 {KERN_SPARC_STOP_A
, "stop-a", &stop_a_enabled
, sizeof (int),
168 0644, NULL
, &proc_dointvec
},
171 {KERN_PPC_HTABRECLAIM
, "htab-reclaim", &htab_reclaim_on
, sizeof(int),
172 0644, NULL
, &proc_dointvec
},
173 {KERN_PPC_ZEROPAGED
, "zero-paged", &zero_paged_on
, sizeof(int),
174 0644, NULL
, &proc_dointvec
},
175 {KERN_PPC_POWERSAVE_NAP
, "powersave-nap", &powersave_nap
, sizeof(int),
176 0644, NULL
, &proc_dointvec
},
177 {KERN_PPC_L2CR
, "l2cr", NULL
, 0,
178 0644, NULL
, &proc_dol2crvec
},
180 {KERN_CTLALTDEL
, "ctrl-alt-del", &C_A_D
, sizeof(int),
181 0644, NULL
, &proc_dointvec
},
182 {KERN_PRINTK
, "printk", &console_loglevel
, 4*sizeof(int),
183 0644, NULL
, &proc_dointvec
},
185 {KERN_MODPROBE
, "modprobe", &modprobe_path
, 256,
186 0644, NULL
, &proc_dostring
, &sysctl_string
},
188 #ifdef CONFIG_CHR_DEV_SG
189 {KERN_SG_BIG_BUFF
, "sg-big-buff", &sg_big_buff
, sizeof (int),
190 0444, NULL
, &proc_dointvec
},
192 #ifdef CONFIG_BSD_PROCESS_ACCT
193 {KERN_ACCT
, "acct", &acct_parm
, 3*sizeof(int),
194 0644, NULL
, &proc_dointvec
},
196 {KERN_RTSIGNR
, "rtsig-nr", &nr_queued_signals
, sizeof(int),
197 0444, NULL
, &proc_dointvec
},
198 {KERN_RTSIGMAX
, "rtsig-max", &max_queued_signals
, sizeof(int),
199 0644, NULL
, &proc_dointvec
},
200 #ifdef CONFIG_SYSVIPC
201 {KERN_SHMMAX
, "shmmax", &shm_ctlmax
, sizeof (size_t),
202 0644, NULL
, &proc_doulongvec_minmax
},
203 {KERN_MSGMAX
, "msgmax", &msg_ctlmax
, sizeof (int),
204 0644, NULL
, &proc_dointvec
},
205 {KERN_MSGMNI
, "msgmni", &msg_ctlmni
, sizeof (int),
206 0644, NULL
, &proc_dointvec
},
207 {KERN_MSGMNB
, "msgmnb", &msg_ctlmnb
, sizeof (int),
208 0644, NULL
, &proc_dointvec
},
209 {KERN_SEM
, "sem", &sem_ctls
, 4*sizeof (int),
210 0644, NULL
, &proc_dointvec
},
212 #ifdef CONFIG_MAGIC_SYSRQ
213 {KERN_SYSRQ
, "sysrq", &sysrq_enabled
, sizeof (int),
214 0644, NULL
, &proc_dointvec
},
216 {KERN_MAX_THREADS
, "threads-max", &max_threads
, sizeof(int),
217 0644, NULL
, &proc_dointvec
},
218 {KERN_RANDOM
, "random", NULL
, 0, 0555, random_table
},
219 {KERN_OVERFLOWUID
, "overflowuid", &overflowuid
, sizeof(int), 0644, NULL
,
220 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
221 &minolduid
, &maxolduid
},
222 {KERN_OVERFLOWGID
, "overflowgid", &overflowgid
, sizeof(int), 0644, NULL
,
223 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
224 &minolduid
, &maxolduid
},
228 static ctl_table vm_table
[] = {
229 {VM_FREEPG
, "freepages",
230 &freepages
, sizeof(freepages_t
), 0644, NULL
, &proc_dointvec
},
231 {VM_BDFLUSH
, "bdflush", &bdf_prm
, 9*sizeof(int), 0644, NULL
,
232 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
233 &bdflush_min
, &bdflush_max
},
234 {VM_OVERCOMMIT_MEMORY
, "overcommit_memory", &sysctl_overcommit_memory
,
235 sizeof(sysctl_overcommit_memory
), 0644, NULL
, &proc_dointvec
},
236 {VM_BUFFERMEM
, "buffermem",
237 &buffer_mem
, sizeof(buffer_mem_t
), 0644, NULL
, &proc_dointvec
},
238 {VM_PAGECACHE
, "pagecache",
239 &page_cache
, sizeof(buffer_mem_t
), 0644, NULL
, &proc_dointvec
},
240 {VM_PAGERDAEMON
, "kswapd",
241 &pager_daemon
, sizeof(pager_daemon_t
), 0644, NULL
, &proc_dointvec
},
242 {VM_PGT_CACHE
, "pagetable_cache",
243 &pgt_cache_water
, 2*sizeof(int), 0644, NULL
, &proc_dointvec
},
244 {VM_PAGE_CLUSTER
, "page-cluster",
245 &page_cluster
, sizeof(int), 0644, NULL
, &proc_dointvec
},
249 static ctl_table proc_table
[] = {
253 static ctl_table fs_table
[] = {
254 {FS_NRINODE
, "inode-nr", &inodes_stat
, 2*sizeof(int),
255 0444, NULL
, &proc_dointvec
},
256 {FS_STATINODE
, "inode-state", &inodes_stat
, 7*sizeof(int),
257 0444, NULL
, &proc_dointvec
},
258 {FS_NRFILE
, "file-nr", &files_stat
, 3*sizeof(int),
259 0444, NULL
, &proc_dointvec
},
260 {FS_MAXFILE
, "file-max", &files_stat
.max_files
, sizeof(int),
261 0644, NULL
, &proc_dointvec
},
262 {FS_NRSUPER
, "super-nr", &nr_super_blocks
, sizeof(int),
263 0444, NULL
, &proc_dointvec
},
264 {FS_MAXSUPER
, "super-max", &max_super_blocks
, sizeof(int),
265 0644, NULL
, &proc_dointvec
},
266 {FS_NRDQUOT
, "dquot-nr", &nr_dquots
, 2*sizeof(int),
267 0444, NULL
, &proc_dointvec
},
268 {FS_MAXDQUOT
, "dquot-max", &max_dquots
, sizeof(int),
269 0644, NULL
, &proc_dointvec
},
270 {FS_DENTRY
, "dentry-state", &dentry_stat
, 6*sizeof(int),
271 0444, NULL
, &proc_dointvec
},
272 {FS_OVERFLOWUID
, "overflowuid", &fs_overflowuid
, sizeof(int), 0644, NULL
,
273 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
274 &minolduid
, &maxolduid
},
275 {FS_OVERFLOWGID
, "overflowgid", &fs_overflowgid
, sizeof(int), 0644, NULL
,
276 &proc_dointvec_minmax
, &sysctl_intvec
, NULL
,
277 &minolduid
, &maxolduid
},
281 static ctl_table debug_table
[] = {
285 static ctl_table dev_table
[] = {
289 extern void init_irq_proc (void);
291 void __init
sysctl_init(void)
293 #ifdef CONFIG_PROC_FS
294 register_proc_table(root_table
, proc_sys_root
);
299 int do_sysctl(int *name
, int nlen
, void *oldval
, size_t *oldlenp
,
300 void *newval
, size_t newlen
)
302 struct list_head
*tmp
;
304 if (nlen
== 0 || nlen
>= CTL_MAXNAME
)
308 if (!oldlenp
|| get_user(old_len
, oldlenp
))
311 tmp
= &root_table_header
.ctl_entry
;
313 struct ctl_table_header
*head
=
314 list_entry(tmp
, struct ctl_table_header
, ctl_entry
);
315 void *context
= NULL
;
316 int error
= parse_table(name
, nlen
, oldval
, oldlenp
,
317 newval
, newlen
, head
->ctl_table
,
321 if (error
!= -ENOTDIR
)
324 } while (tmp
!= &root_table_header
.ctl_entry
);
328 extern asmlinkage
long sys_sysctl(struct __sysctl_args
*args
)
330 struct __sysctl_args tmp
;
333 if (copy_from_user(&tmp
, args
, sizeof(tmp
)))
337 error
= do_sysctl(tmp
.name
, tmp
.nlen
, tmp
.oldval
, tmp
.oldlenp
,
338 tmp
.newval
, tmp
.newlen
);
344 * ctl_perm does NOT grant the superuser all rights automatically, because
345 * some sysctl variables are readonly even to root.
348 static int test_perm(int mode
, int op
)
352 else if (in_egroup_p(0))
354 if ((mode
& op
& 0007) == op
)
359 static inline int ctl_perm(ctl_table
*table
, int op
)
361 return test_perm(table
->mode
, op
);
364 static int parse_table(int *name
, int nlen
,
365 void *oldval
, size_t *oldlenp
,
366 void *newval
, size_t newlen
,
367 ctl_table
*table
, void **context
)
373 if (get_user(n
, name
))
375 for ( ; table
->ctl_name
; table
++) {
376 if (n
== table
->ctl_name
|| table
->ctl_name
== CTL_ANY
) {
379 if (ctl_perm(table
, 001))
381 if (table
->strategy
) {
382 error
= table
->strategy(
385 newval
, newlen
, context
);
391 table
= table
->child
;
394 error
= do_sysctl_strategy(table
, name
, nlen
,
396 newval
, newlen
, context
);
403 /* Perform the actual read/write of a sysctl table entry. */
404 int do_sysctl_strategy (ctl_table
*table
,
406 void *oldval
, size_t *oldlenp
,
407 void *newval
, size_t newlen
, void **context
)
415 if (ctl_perm(table
, op
))
418 if (table
->strategy
) {
419 rc
= table
->strategy(table
, name
, nlen
, oldval
, oldlenp
,
420 newval
, newlen
, context
);
427 /* If there is no strategy routine, or if the strategy returns
428 * zero, proceed with automatic r/w */
429 if (table
->data
&& table
->maxlen
) {
430 if (oldval
&& oldlenp
) {
431 get_user(len
, oldlenp
);
433 if (len
> table
->maxlen
)
435 if(copy_to_user(oldval
, table
->data
, len
))
437 if(put_user(len
, oldlenp
))
441 if (newval
&& newlen
) {
443 if (len
> table
->maxlen
)
445 if(copy_from_user(table
->data
, newval
, len
))
452 struct ctl_table_header
*register_sysctl_table(ctl_table
* table
,
455 struct ctl_table_header
*tmp
;
456 tmp
= kmalloc(sizeof(struct ctl_table_header
), GFP_KERNEL
);
459 tmp
->ctl_table
= table
;
460 INIT_LIST_HEAD(&tmp
->ctl_entry
);
462 list_add(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
464 list_add_tail(&tmp
->ctl_entry
, &root_table_header
.ctl_entry
);
465 #ifdef CONFIG_PROC_FS
466 register_proc_table(table
, proc_sys_root
);
472 * Unlink and free a ctl_table.
474 void unregister_sysctl_table(struct ctl_table_header
* header
)
476 list_del(&header
->ctl_entry
);
477 #ifdef CONFIG_PROC_FS
478 unregister_proc_table(header
->ctl_table
, proc_sys_root
);
487 #ifdef CONFIG_PROC_FS
489 /* Scan the sysctl entries in table and add them all into /proc */
490 static void register_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
492 struct proc_dir_entry
*de
;
496 for (; table
->ctl_name
; table
++) {
497 /* Can't do anything without a proc name. */
498 if (!table
->procname
)
500 /* Maybe we can't do anything with it... */
501 if (!table
->proc_handler
&& !table
->child
) {
502 printk(KERN_WARNING
"SYSCTL: Can't register %s\n",
507 len
= strlen(table
->procname
);
511 if (table
->proc_handler
)
515 for (de
= root
->subdir
; de
; de
= de
->next
) {
516 if (proc_match(len
, table
->procname
, de
))
519 /* If the subdir exists already, de is non-NULL */
523 de
= create_proc_entry(table
->procname
, mode
, root
);
526 de
->data
= (void *) table
;
527 if (table
->proc_handler
) {
528 de
->proc_fops
= &proc_sys_file_operations
;
529 de
->proc_iops
= &proc_sys_inode_operations
;
533 if (de
->mode
& S_IFDIR
)
534 register_proc_table(table
->child
, de
);
539 * Unregister a /proc sysctl table and any subdirectories.
541 static void unregister_proc_table(ctl_table
* table
, struct proc_dir_entry
*root
)
543 struct proc_dir_entry
*de
;
544 for (; table
->ctl_name
; table
++) {
545 if (!(de
= table
->de
))
547 if (de
->mode
& S_IFDIR
) {
549 printk (KERN_ALERT
"Help - malformed sysctl tree on free\n");
552 unregister_proc_table(table
->child
, de
);
554 /* Don't unregister directories which still have entries.. */
559 /* Don't unregister proc entries that are still being used.. */
564 remove_proc_entry(table
->procname
, root
);
568 static ssize_t
do_rw_proc(int write
, struct file
* file
, char * buf
,
569 size_t count
, loff_t
*ppos
)
572 struct proc_dir_entry
*de
;
573 struct ctl_table
*table
;
577 de
= (struct proc_dir_entry
*) file
->f_dentry
->d_inode
->u
.generic_ip
;
578 if (!de
|| !de
->data
)
580 table
= (struct ctl_table
*) de
->data
;
581 if (!table
|| !table
->proc_handler
)
583 op
= (write
? 002 : 004);
584 if (ctl_perm(table
, op
))
590 * FIXME: we need to pass on ppos to the handler.
593 error
= (*table
->proc_handler
) (table
, write
, file
, buf
, &res
);
599 static ssize_t
proc_readsys(struct file
* file
, char * buf
,
600 size_t count
, loff_t
*ppos
)
602 return do_rw_proc(0, file
, buf
, count
, ppos
);
605 static ssize_t
proc_writesys(struct file
* file
, const char * buf
,
606 size_t count
, loff_t
*ppos
)
608 return do_rw_proc(1, file
, (char *) buf
, count
, ppos
);
611 static int proc_sys_permission(struct inode
*inode
, int op
)
613 return test_perm(inode
->i_mode
, op
);
616 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
617 void *buffer
, size_t *lenp
)
622 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
623 (filp
->f_pos
&& !write
)) {
631 while (len
< *lenp
) {
634 if (c
== 0 || c
== '\n')
638 if (len
>= table
->maxlen
)
639 len
= table
->maxlen
-1;
640 if(copy_from_user(table
->data
, buffer
, len
))
642 ((char *) table
->data
)[len
] = 0;
643 filp
->f_pos
+= *lenp
;
645 len
= strlen(table
->data
);
646 if (len
> table
->maxlen
)
651 if(copy_to_user(buffer
, table
->data
, len
))
654 if(put_user('\n', ((char *) buffer
) + len
))
665 * Special case of dostring for the UTS structure. This has locks
666 * to observe. Should this be in kernel/sys.c ????
669 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
670 void *buffer
, size_t *lenp
)
676 r
=proc_dostring(table
,0,filp
,buffer
,lenp
);
679 down_write(&uts_sem
);
680 r
=proc_dostring(table
,1,filp
,buffer
,lenp
);
692 static int do_proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
693 void *buffer
, size_t *lenp
, int conv
, int op
)
695 int *i
, vleft
, first
=1, len
, left
, neg
, val
;
697 char buf
[TMPBUFLEN
], *p
;
699 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
700 (filp
->f_pos
&& !write
)) {
705 i
= (int *) table
->data
;
706 vleft
= table
->maxlen
/ sizeof(int);
709 for (; left
&& vleft
--; i
++, first
=0) {
713 if(get_user(c
,(char *) buffer
))
724 if (len
> TMPBUFLEN
-1)
726 if(copy_from_user(buf
, buffer
, len
))
730 if (*p
== '-' && left
> 1) {
734 if (*p
< '0' || *p
> '9')
736 val
= simple_strtoul(p
, &p
, 0) * conv
;
738 if ((len
< left
) && *p
&& !isspace(*p
))
745 case OP_SET
: *i
= val
; break;
746 case OP_AND
: *i
&= val
; break;
747 case OP_OR
: *i
|= val
; break;
748 case OP_MAX
: if(*i
< val
)
751 case OP_MIN
: if(*i
> val
)
759 sprintf(p
, "%d", (*i
) / conv
);
763 if(copy_to_user(buffer
, buf
, len
))
770 if (!write
&& !first
&& left
) {
771 if(put_user('\n', (char *) buffer
))
789 filp
->f_pos
+= *lenp
;
793 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
794 void *buffer
, size_t *lenp
)
796 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,1,OP_SET
);
800 * init may raise the set.
803 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
804 void *buffer
, size_t *lenp
)
806 if (!capable(CAP_SYS_MODULE
)) {
809 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,1,
810 (current
->pid
== 1) ? OP_SET
: OP_AND
);
813 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
814 void *buffer
, size_t *lenp
)
816 int *i
, *min
, *max
, vleft
, first
=1, len
, left
, neg
, val
;
818 char buf
[TMPBUFLEN
], *p
;
820 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
821 (filp
->f_pos
&& !write
)) {
826 i
= (int *) table
->data
;
827 min
= (int *) table
->extra1
;
828 max
= (int *) table
->extra2
;
829 vleft
= table
->maxlen
/ sizeof(int);
832 for (; left
&& vleft
--; i
++, first
=0) {
836 if(get_user(c
, (char *) buffer
))
847 if (len
> TMPBUFLEN
-1)
849 if(copy_from_user(buf
, buffer
, len
))
853 if (*p
== '-' && left
> 1) {
857 if (*p
< '0' || *p
> '9')
859 val
= simple_strtoul(p
, &p
, 0);
861 if ((len
< left
) && *p
&& !isspace(*p
))
868 if (min
&& val
< *min
++)
870 if (max
&& val
> *max
++)
877 sprintf(p
, "%d", *i
);
881 if(copy_to_user(buffer
, buf
, len
))
888 if (!write
&& !first
&& left
) {
889 if(put_user('\n', (char *) buffer
))
907 filp
->f_pos
+= *lenp
;
912 * an unsigned long function version
915 static int do_proc_doulongvec_minmax(ctl_table
*table
, int write
,
917 void *buffer
, size_t *lenp
,
918 unsigned long convmul
,
919 unsigned long convdiv
)
922 unsigned long *i
, *min
, *max
, val
;
923 int vleft
, first
=1, len
, left
, neg
;
924 char buf
[TMPBUFLEN
], *p
;
926 if (!table
->data
|| !table
->maxlen
|| !*lenp
||
927 (filp
->f_pos
&& !write
)) {
932 i
= (unsigned long *) table
->data
;
933 min
= (unsigned long *) table
->extra1
;
934 max
= (unsigned long *) table
->extra2
;
935 vleft
= table
->maxlen
/ sizeof(unsigned long);
938 for (; left
&& vleft
--; i
++, first
=0) {
942 if(get_user(c
, (char *) buffer
))
953 if (len
> TMPBUFLEN
-1)
955 if(copy_from_user(buf
, buffer
, len
))
959 if (*p
== '-' && left
> 1) {
963 if (*p
< '0' || *p
> '9')
965 val
= simple_strtoul(p
, &p
, 0) * convmul
/ convdiv
;
967 if ((len
< left
) && *p
&& !isspace(*p
))
976 if (min
&& val
< *min
++)
978 if (max
&& val
> *max
++)
985 sprintf(p
, "%lu", convdiv
* (*i
) / convmul
);
989 if(copy_to_user(buffer
, buf
, len
))
996 if (!write
&& !first
&& left
) {
997 if(put_user('\n', (char *) buffer
))
1002 p
= (char *) buffer
;
1005 if(get_user(c
, p
++))
1015 filp
->f_pos
+= *lenp
;
1020 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1021 void *buffer
, size_t *lenp
)
1023 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
, lenp
, 1l, 1l);
1026 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1028 void *buffer
, size_t *lenp
)
1030 return do_proc_doulongvec_minmax(table
, write
, filp
, buffer
,
1035 /* Like proc_dointvec, but converts seconds to jiffies */
1036 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1037 void *buffer
, size_t *lenp
)
1039 return do_proc_dointvec(table
,write
,filp
,buffer
,lenp
,HZ
,OP_SET
);
1042 #else /* CONFIG_PROC_FS */
1044 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1045 void *buffer
, size_t *lenp
)
1050 static int proc_doutsstring(ctl_table
*table
, int write
, struct file
*filp
,
1051 void *buffer
, size_t *lenp
)
1056 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1057 void *buffer
, size_t *lenp
)
1062 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1063 void *buffer
, size_t *lenp
)
1068 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1069 void *buffer
, size_t *lenp
)
1074 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1075 void *buffer
, size_t *lenp
)
1080 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1081 void *buffer
, size_t *lenp
)
1086 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1088 void *buffer
, size_t *lenp
)
1094 #endif /* CONFIG_PROC_FS */
1098 * General sysctl support routines
1101 /* The generic string strategy routine: */
1102 int sysctl_string(ctl_table
*table
, int *name
, int nlen
,
1103 void *oldval
, size_t *oldlenp
,
1104 void *newval
, size_t newlen
, void **context
)
1108 if (!table
->data
|| !table
->maxlen
)
1111 if (oldval
&& oldlenp
) {
1112 if(get_user(len
, oldlenp
))
1115 l
= strlen(table
->data
);
1116 if (len
> l
) len
= l
;
1117 if (len
>= table
->maxlen
)
1118 len
= table
->maxlen
;
1119 if(copy_to_user(oldval
, table
->data
, len
))
1121 if(put_user(0, ((char *) oldval
) + len
))
1123 if(put_user(len
, oldlenp
))
1127 if (newval
&& newlen
) {
1129 if (len
> table
->maxlen
)
1130 len
= table
->maxlen
;
1131 if(copy_from_user(table
->data
, newval
, len
))
1133 if (len
== table
->maxlen
)
1135 ((char *) table
->data
)[len
] = 0;
1141 * This function makes sure that all of the integers in the vector
1142 * are between the minimum and maximum values given in the arrays
1143 * table->extra1 and table->extra2, respectively.
1145 int sysctl_intvec(ctl_table
*table
, int *name
, int nlen
,
1146 void *oldval
, size_t *oldlenp
,
1147 void *newval
, size_t newlen
, void **context
)
1149 int i
, length
, *vec
, *min
, *max
;
1151 if (newval
&& newlen
) {
1152 if (newlen
% sizeof(int) != 0)
1155 if (!table
->extra1
&& !table
->extra2
)
1158 if (newlen
> table
->maxlen
)
1159 newlen
= table
->maxlen
;
1160 length
= newlen
/ sizeof(int);
1162 vec
= (int *) newval
;
1163 min
= (int *) table
->extra1
;
1164 max
= (int *) table
->extra2
;
1166 for (i
= 0; i
< length
; i
++) {
1168 get_user(value
, vec
+ i
);
1169 if (min
&& value
< min
[i
])
1171 if (max
&& value
> max
[i
])
1178 /* Strategy function to convert jiffies to seconds */
1179 int sysctl_jiffies(ctl_table
*table
, int *name
, int nlen
,
1180 void *oldval
, size_t *oldlenp
,
1181 void *newval
, size_t newlen
, void **context
)
1186 if (get_user(olen
, oldlenp
))
1188 if (olen
!=sizeof(int))
1191 if (put_user(*(int *)(table
->data
) / HZ
, (int *)oldval
) ||
1192 (oldlenp
&& put_user(sizeof(int),oldlenp
)))
1195 if (newval
&& newlen
) {
1197 if (newlen
!= sizeof(int))
1199 if (get_user(new, (int *)newval
))
1201 *(int *)(table
->data
) = new*HZ
;
1207 void *oldval
, size_t *oldlenp
, void *newval
, size_t newlen
,
1208 int rdwr
, char *data
, size_t max
)
1210 int l
= strlen(data
) + 1;
1211 if (newval
&& !rdwr
)
1213 if (newval
&& newlen
>= max
)
1217 if(get_user(old_l
, oldlenp
))
1221 if(put_user(l
, oldlenp
) || copy_to_user(oldval
, data
, l
))
1225 if(copy_from_user(data
, newval
, newlen
))
1233 void *oldval
, size_t *oldlenp
, void *newval
, size_t newlen
,
1234 int rdwr
, int *data
)
1236 if (newval
&& !rdwr
)
1238 if (newval
&& newlen
!= sizeof(int))
1242 if(get_user(old_l
, oldlenp
))
1244 if (old_l
< sizeof(int))
1246 if(put_user(sizeof(int), oldlenp
)||copy_to_user(oldval
, data
, sizeof(int)))
1250 if(copy_from_user(data
, newval
, sizeof(int)))
1256 void *oldval
, size_t *oldlenp
, void *newval
, size_t newlen
,
1257 int rdwr
, void *data
, size_t len
)
1259 if (newval
&& !rdwr
)
1261 if (newval
&& newlen
!= len
)
1265 if(get_user(old_l
, oldlenp
))
1269 if(put_user(len
, oldlenp
) || copy_to_user(oldval
, data
, len
))
1273 if(copy_from_user(data
, newval
, len
))
1279 #else /* CONFIG_SYSCTL */
1282 extern asmlinkage
long sys_sysctl(struct __sysctl_args
*args
)
1287 int sysctl_string(ctl_table
*table
, int *name
, int nlen
,
1288 void *oldval
, size_t *oldlenp
,
1289 void *newval
, size_t newlen
, void **context
)
1294 int sysctl_intvec(ctl_table
*table
, int *name
, int nlen
,
1295 void *oldval
, size_t *oldlenp
,
1296 void *newval
, size_t newlen
, void **context
)
1301 int proc_dostring(ctl_table
*table
, int write
, struct file
*filp
,
1302 void *buffer
, size_t *lenp
)
1307 int proc_dointvec(ctl_table
*table
, int write
, struct file
*filp
,
1308 void *buffer
, size_t *lenp
)
1313 int proc_dointvec_bset(ctl_table
*table
, int write
, struct file
*filp
,
1314 void *buffer
, size_t *lenp
)
1319 int proc_dointvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1320 void *buffer
, size_t *lenp
)
1325 int proc_dointvec_jiffies(ctl_table
*table
, int write
, struct file
*filp
,
1326 void *buffer
, size_t *lenp
)
1331 int proc_doulongvec_minmax(ctl_table
*table
, int write
, struct file
*filp
,
1332 void *buffer
, size_t *lenp
)
1337 int proc_doulongvec_ms_jiffies_minmax(ctl_table
*table
, int write
,
1339 void *buffer
, size_t *lenp
)
1344 struct ctl_table_header
* register_sysctl_table(ctl_table
* table
,
1350 void unregister_sysctl_table(struct ctl_table_header
* table
)
1354 #endif /* CONFIG_SYSCTL */