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/slab.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 atomic_t nr_queued_signals;
49 extern int max_queued_signals;
50 extern int sysrq_enabled;
51 extern int core_uses_pid;
52 extern char core_pattern[];
55 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
56 static int maxolduid = 65535;
60 extern char modprobe_path[];
63 extern char hotplug_path[];
65 #ifdef CONFIG_CHR_DEV_SG
66 extern int sg_big_buff;
69 extern size_t shm_ctlmax;
70 extern size_t shm_ctlall;
71 extern int shm_ctlmni;
72 extern int msg_ctlmax;
73 extern int msg_ctlmnb;
74 extern int msg_ctlmni;
75 extern int sem_ctls[];
79 extern char reboot_command [];
80 extern int stop_a_enabled;
83 #ifdef CONFIG_ARCH_S390
85 extern int sysctl_ieee_emulation_warnings;
87 extern int sysctl_userprocess_debug;
90 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
91 extern int powersave_nap;
92 int proc_dol2crvec(ctl_table *table, int write, struct file *filp,
93 void *buffer, size_t *lenp);
96 #ifdef CONFIG_BSD_PROCESS_ACCT
97 extern int acct_parm[];
100 extern int pgt_cache_water[];
102 static int parse_table(int *, int, void *, size_t *, void *, size_t,
103 ctl_table *, void **);
104 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
105 void *buffer, size_t *lenp);
107 static ctl_table root_table[];
108 static struct ctl_table_header root_table_header =
109 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
111 static ctl_table kern_table[];
112 static ctl_table vm_table[];
114 extern ctl_table net_table[];
116 static ctl_table proc_table[];
117 static ctl_table fs_table[];
118 static ctl_table debug_table[];
119 static ctl_table dev_table[];
120 extern ctl_table random_table[];
122 /* /proc declarations: */
124 #ifdef CONFIG_PROC_FS
126 static ssize_t proc_readsys(struct file *, char *, size_t, loff_t *);
127 static ssize_t proc_writesys(struct file *, const char *, size_t, loff_t *);
128 static int proc_sys_permission(struct inode *, int);
130 struct file_operations proc_sys_file_operations = {
132 write: proc_writesys,
135 static struct inode_operations proc_sys_inode_operations = {
136 permission: proc_sys_permission,
139 extern struct proc_dir_entry *proc_sys_root;
141 static void register_proc_table(ctl_table *, struct proc_dir_entry *);
142 static void unregister_proc_table(ctl_table *, struct proc_dir_entry *);
145 /* The default sysctl tables: */
147 static ctl_table root_table[] = {
148 {CTL_KERN, "kernel", NULL, 0, 0555, kern_table},
149 {CTL_VM, "vm", NULL, 0, 0555, vm_table},
151 {CTL_NET, "net", NULL, 0, 0555, net_table},
153 {CTL_PROC, "proc", NULL, 0, 0555, proc_table},
154 {CTL_FS, "fs", NULL, 0, 0555, fs_table},
155 {CTL_DEBUG, "debug", NULL, 0, 0555, debug_table},
156 {CTL_DEV, "dev", NULL, 0, 0555, dev_table},
160 static ctl_table kern_table[] = {
161 {KERN_OSTYPE, "ostype", system_utsname.sysname, 64,
162 0444, NULL, &proc_doutsstring, &sysctl_string},
163 {KERN_OSRELEASE, "osrelease", system_utsname.release, 64,
164 0444, NULL, &proc_doutsstring, &sysctl_string},
165 {KERN_VERSION, "version", system_utsname.version, 64,
166 0444, NULL, &proc_doutsstring, &sysctl_string},
167 {KERN_NODENAME, "hostname", system_utsname.nodename, 64,
168 0644, NULL, &proc_doutsstring, &sysctl_string},
169 {KERN_DOMAINNAME, "domainname", system_utsname.domainname, 64,
170 0644, NULL, &proc_doutsstring, &sysctl_string},
171 {KERN_PANIC, "panic", &panic_timeout, sizeof(int),
172 0644, NULL, &proc_dointvec},
173 {KERN_CORE_USES_PID, "core_uses_pid", &core_uses_pid, sizeof(int),
174 0644, NULL, &proc_dointvec},
175 {KERN_CORE_PATTERN, "core_pattern", core_pattern, 64,
176 0644, NULL, &proc_dostring, &sysctl_string},
177 {KERN_TAINTED, "tainted", &tainted, sizeof(int),
178 0644, NULL, &proc_dointvec},
179 {KERN_CAP_BSET, "cap-bound", &cap_bset, sizeof(kernel_cap_t),
180 0600, NULL, &proc_dointvec_bset},
181 #ifdef CONFIG_BLK_DEV_INITRD
182 {KERN_REALROOTDEV, "real-root-dev", &real_root_dev, sizeof(int),
183 0644, NULL, &proc_dointvec},
186 {KERN_SPARC_REBOOT, "reboot-cmd", reboot_command,
187 256, 0644, NULL, &proc_dostring, &sysctl_string },
188 {KERN_SPARC_STOP_A, "stop-a", &stop_a_enabled, sizeof (int),
189 0644, NULL, &proc_dointvec},
191 #if defined(CONFIG_PPC32) && defined(CONFIG_6xx)
192 {KERN_PPC_POWERSAVE_NAP, "powersave-nap", &powersave_nap, sizeof(int),
193 0644, NULL, &proc_dointvec},
194 {KERN_PPC_L2CR, "l2cr", NULL, 0,
195 0644, NULL, &proc_dol2crvec},
197 {KERN_CTLALTDEL, "ctrl-alt-del", &C_A_D, sizeof(int),
198 0644, NULL, &proc_dointvec},
199 {KERN_PRINTK, "printk", &console_loglevel, 4*sizeof(int),
200 0644, NULL, &proc_dointvec},
202 {KERN_MODPROBE, "modprobe", &modprobe_path, 256,
203 0644, NULL, &proc_dostring, &sysctl_string },
205 #ifdef CONFIG_HOTPLUG
206 {KERN_HOTPLUG, "hotplug", &hotplug_path, 256,
207 0644, NULL, &proc_dostring, &sysctl_string },
209 #ifdef CONFIG_CHR_DEV_SG
210 {KERN_SG_BIG_BUFF, "sg-big-buff", &sg_big_buff, sizeof (int),
211 0444, NULL, &proc_dointvec},
213 #ifdef CONFIG_BSD_PROCESS_ACCT
214 {KERN_ACCT, "acct", &acct_parm, 3*sizeof(int),
215 0644, NULL, &proc_dointvec},
217 {KERN_RTSIGNR, "rtsig-nr", &nr_queued_signals, sizeof(int),
218 0444, NULL, &proc_dointvec},
219 {KERN_RTSIGMAX, "rtsig-max", &max_queued_signals, sizeof(int),
220 0644, NULL, &proc_dointvec},
221 #ifdef CONFIG_SYSVIPC
222 {KERN_SHMMAX, "shmmax", &shm_ctlmax, sizeof (size_t),
223 0644, NULL, &proc_doulongvec_minmax},
224 {KERN_SHMALL, "shmall", &shm_ctlall, sizeof (size_t),
225 0644, NULL, &proc_doulongvec_minmax},
226 {KERN_SHMMNI, "shmmni", &shm_ctlmni, sizeof (int),
227 0644, NULL, &proc_dointvec},
228 {KERN_MSGMAX, "msgmax", &msg_ctlmax, sizeof (int),
229 0644, NULL, &proc_dointvec},
230 {KERN_MSGMNI, "msgmni", &msg_ctlmni, sizeof (int),
231 0644, NULL, &proc_dointvec},
232 {KERN_MSGMNB, "msgmnb", &msg_ctlmnb, sizeof (int),
233 0644, NULL, &proc_dointvec},
234 {KERN_SEM, "sem", &sem_ctls, 4*sizeof (int),
235 0644, NULL, &proc_dointvec},
237 #ifdef CONFIG_MAGIC_SYSRQ
238 {KERN_SYSRQ, "sysrq", &sysrq_enabled, sizeof (int),
239 0644, NULL, &proc_dointvec},
241 {KERN_CADPID, "cad_pid", &cad_pid, sizeof (int),
242 0600, NULL, &proc_dointvec},
243 {KERN_MAX_THREADS, "threads-max", &max_threads, sizeof(int),
244 0644, NULL, &proc_dointvec},
245 {KERN_RANDOM, "random", NULL, 0, 0555, random_table},
246 {KERN_OVERFLOWUID, "overflowuid", &overflowuid, sizeof(int), 0644, NULL,
247 &proc_dointvec_minmax, &sysctl_intvec, NULL,
248 &minolduid, &maxolduid},
249 {KERN_OVERFLOWGID, "overflowgid", &overflowgid, sizeof(int), 0644, NULL,
250 &proc_dointvec_minmax, &sysctl_intvec, NULL,
251 &minolduid, &maxolduid},
252 #ifdef CONFIG_ARCH_S390
253 #ifdef CONFIG_MATHEMU
254 {KERN_IEEE_EMULATION_WARNINGS,"ieee_emulation_warnings",
255 &sysctl_ieee_emulation_warnings,sizeof(int),0644,NULL,&proc_dointvec},
257 {KERN_S390_USER_DEBUG_LOGGING,"userprocess_debug",
258 &sysctl_userprocess_debug,sizeof(int),0644,NULL,&proc_dointvec},
263 static ctl_table vm_table[] = {
264 {VM_BDFLUSH, "bdflush", &bdf_prm, 9*sizeof(int), 0644, NULL,
265 &proc_dointvec_minmax, &sysctl_intvec, NULL,
266 &bdflush_min, &bdflush_max},
267 {VM_OVERCOMMIT_MEMORY, "overcommit_memory", &sysctl_overcommit_memory,
268 sizeof(sysctl_overcommit_memory), 0644, NULL, &proc_dointvec},
269 {VM_PAGERDAEMON, "kswapd",
270 &pager_daemon, sizeof(pager_daemon_t), 0644, NULL, &proc_dointvec},
271 {VM_PGT_CACHE, "pagetable_cache",
272 &pgt_cache_water, 2*sizeof(int), 0644, NULL, &proc_dointvec},
273 {VM_PAGE_CLUSTER, "page-cluster",
274 &page_cluster, sizeof(int), 0644, NULL, &proc_dointvec},
275 {VM_MIN_READAHEAD, "min-readahead",
276 &vm_min_readahead,sizeof(int), 0644, NULL, &proc_dointvec},
277 {VM_MAX_READAHEAD, "max-readahead",
278 &vm_max_readahead,sizeof(int), 0644, NULL, &proc_dointvec},
279 {VM_MAX_MAP_COUNT, "max_map_count",
280 &max_map_count, sizeof(int), 0644, NULL, &proc_dointvec},
284 static ctl_table proc_table[] = {
288 static ctl_table fs_table[] = {
289 {FS_NRINODE, "inode-nr", &inodes_stat, 2*sizeof(int),
290 0444, NULL, &proc_dointvec},
291 {FS_STATINODE, "inode-state", &inodes_stat, 7*sizeof(int),
292 0444, NULL, &proc_dointvec},
293 {FS_NRFILE, "file-nr", &files_stat, 3*sizeof(int),
294 0444, NULL, &proc_dointvec},
295 {FS_MAXFILE, "file-max", &files_stat.max_files, sizeof(int),
296 0644, NULL, &proc_dointvec},
297 {FS_NRDQUOT, "dquot-nr", &nr_dquots, 2*sizeof(int),
298 0444, NULL, &proc_dointvec},
299 {FS_DENTRY, "dentry-state", &dentry_stat, 6*sizeof(int),
300 0444, NULL, &proc_dointvec},
301 {FS_OVERFLOWUID, "overflowuid", &fs_overflowuid, sizeof(int), 0644, NULL,
302 &proc_dointvec_minmax, &sysctl_intvec, NULL,
303 &minolduid, &maxolduid},
304 {FS_OVERFLOWGID, "overflowgid", &fs_overflowgid, sizeof(int), 0644, NULL,
305 &proc_dointvec_minmax, &sysctl_intvec, NULL,
306 &minolduid, &maxolduid},
307 {FS_LEASES, "leases-enable", &leases_enable, sizeof(int),
308 0644, NULL, &proc_dointvec},
309 {FS_DIR_NOTIFY, "dir-notify-enable", &dir_notify_enable,
310 sizeof(int), 0644, NULL, &proc_dointvec},
311 {FS_LEASE_TIME, "lease-break-time", &lease_break_time, sizeof(int),
312 0644, NULL, &proc_dointvec},
316 static ctl_table debug_table[] = {
320 static ctl_table dev_table[] = {
324 extern void init_irq_proc (void);
326 void __init sysctl_init(void)
328 #ifdef CONFIG_PROC_FS
329 register_proc_table(root_table, proc_sys_root);
334 int do_sysctl(int *name, int nlen, void *oldval, size_t *oldlenp,
335 void *newval, size_t newlen)
337 struct list_head *tmp;
339 if (nlen <= 0 || nlen >= CTL_MAXNAME)
343 if (!oldlenp || get_user(old_len, oldlenp))
346 tmp = &root_table_header.ctl_entry;
348 struct ctl_table_header *head =
349 list_entry(tmp, struct ctl_table_header, ctl_entry);
350 void *context = NULL;
351 int error = parse_table(name, nlen, oldval, oldlenp,
352 newval, newlen, head->ctl_table,
356 if (error != -ENOTDIR)
359 } while (tmp != &root_table_header.ctl_entry);
363 extern asmlinkage long sys_sysctl(struct __sysctl_args *args)
365 struct __sysctl_args tmp;
368 if (copy_from_user(&tmp, args, sizeof(tmp)))
372 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
373 tmp.newval, tmp.newlen);
379 * ctl_perm does NOT grant the superuser all rights automatically, because
380 * some sysctl variables are readonly even to root.
383 static int test_perm(int mode, int op)
387 else if (in_egroup_p(0))
389 if ((mode & op & 0007) == op)
394 static inline int ctl_perm(ctl_table *table, int op)
396 return test_perm(table->mode, op);
399 static int parse_table(int *name, int nlen,
400 void *oldval, size_t *oldlenp,
401 void *newval, size_t newlen,
402 ctl_table *table, void **context)
408 if (get_user(n, name))
410 for ( ; table->ctl_name; table++) {
411 if (n == table->ctl_name || table->ctl_name == CTL_ANY) {
414 if (ctl_perm(table, 001))
416 if (table->strategy) {
417 error = table->strategy(
420 newval, newlen, context);
426 table = table->child;
429 error = do_sysctl_strategy(table, name, nlen,
431 newval, newlen, context);
438 /* Perform the actual read/write of a sysctl table entry. */
439 int do_sysctl_strategy (ctl_table *table,
441 void *oldval, size_t *oldlenp,
442 void *newval, size_t newlen, void **context)
451 if (ctl_perm(table, op))
454 if (table->strategy) {
455 rc = table->strategy(table, name, nlen, oldval, oldlenp,
456 newval, newlen, context);
463 /* If there is no strategy routine, or if the strategy returns
464 * zero, proceed with automatic r/w */
465 if (table->data && table->maxlen) {
466 if (oldval && oldlenp) {
467 get_user(len, oldlenp);
469 if (len > table->maxlen)
471 if(copy_to_user(oldval, table->data, len))
473 if(put_user(len, oldlenp))
477 if (newval && newlen) {
479 if (len > table->maxlen)
481 if(copy_from_user(table->data, newval, len))
489 * register_sysctl_table - register a sysctl hierarchy
490 * @table: the top-level table structure
491 * @insert_at_head: whether the entry should be inserted in front or at the end
493 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
494 * array. An entry with a ctl_name of 0 terminates the table.
496 * The members of the &ctl_table structure are used as follows:
498 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
499 * must be unique within that level of sysctl
501 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
502 * enter a sysctl file
504 * data - a pointer to data for use by proc_handler
506 * maxlen - the maximum size in bytes of the data
508 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
510 * child - a pointer to the child sysctl table if this entry is a directory, or
513 * proc_handler - the text handler routine (described below)
515 * strategy - the strategy routine (described below)
517 * de - for internal use by the sysctl routines
519 * extra1, extra2 - extra pointers usable by the proc handler routines
521 * Leaf nodes in the sysctl tree will be represented by a single file
522 * under /proc; non-leaf nodes will be represented by directories.
524 * sysctl(2) can automatically manage read and write requests through
525 * the sysctl table. The data and maxlen fields of the ctl_table
526 * struct enable minimal validation of the values being written to be
527 * performed, and the mode field allows minimal authentication.
529 * More sophisticated management can be enabled by the provision of a
530 * strategy routine with the table entry. This will be called before
531 * any automatic read or write of the data is performed.
533 * The strategy routine may return
535 * < 0 - Error occurred (error is passed to user process)
537 * 0 - OK - proceed with automatic read or write.
539 * > 0 - OK - read or write has been done by the strategy routine, so
540 * return immediately.
542 * There must be a proc_handler routine for any terminal nodes
543 * mirrored under /proc/sys (non-terminals are handled by a built-in
544 * directory handler). Several default handlers are available to
545 * cover common cases -
547 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
548 * proc_dointvec_minmax(), proc_doulongvec_ms_jiffies_minmax(),
549 * proc_doulongvec_minmax()
551 * It is the handler's job to read the input buffer from user memory
552 * and process it. The handler should return 0 on success.
554 * This routine returns %NULL on a failure to register, and a pointer
555 * to the table header on success.
557 struct ctl_table_header *register_sysctl_table(ctl_table * table,
560 struct ctl_table_header *tmp;
561 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
564 tmp->ctl_table = table;
565 INIT_LIST_HEAD(&tmp->ctl_entry);
567 list_add(&tmp->ctl_entry, &root_table_header.ctl_entry);
569 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
570 #ifdef CONFIG_PROC_FS
571 register_proc_table(table, proc_sys_root);
577 * unregister_sysctl_table - unregister a sysctl table hierarchy
578 * @header: the header returned from register_sysctl_table
580 * Unregisters the sysctl table and all children. proc entries may not
581 * actually be removed until they are no longer used by anyone.
583 void unregister_sysctl_table(struct ctl_table_header * header)
585 list_del(&header->ctl_entry);
586 #ifdef CONFIG_PROC_FS
587 unregister_proc_table(header->ctl_table, proc_sys_root);
596 #ifdef CONFIG_PROC_FS
598 /* Scan the sysctl entries in table and add them all into /proc */
599 static void register_proc_table(ctl_table * table, struct proc_dir_entry *root)
601 struct proc_dir_entry *de;
605 for (; table->ctl_name; table++) {
606 /* Can't do anything without a proc name. */
607 if (!table->procname)
609 /* Maybe we can't do anything with it... */
610 if (!table->proc_handler && !table->child) {
611 printk(KERN_WARNING "SYSCTL: Can't register %s\n",
616 len = strlen(table->procname);
620 if (table->proc_handler)
624 for (de = root->subdir; de; de = de->next) {
625 if (proc_match(len, table->procname, de))
628 /* If the subdir exists already, de is non-NULL */
632 de = create_proc_entry(table->procname, mode, root);
635 de->data = (void *) table;
636 if (table->proc_handler) {
637 de->proc_fops = &proc_sys_file_operations;
638 de->proc_iops = &proc_sys_inode_operations;
642 if (de->mode & S_IFDIR)
643 register_proc_table(table->child, de);
648 * Unregister a /proc sysctl table and any subdirectories.
650 static void unregister_proc_table(ctl_table * table, struct proc_dir_entry *root)
652 struct proc_dir_entry *de;
653 for (; table->ctl_name; table++) {
654 if (!(de = table->de))
656 if (de->mode & S_IFDIR) {
658 printk (KERN_ALERT "Help - malformed sysctl tree on free\n");
661 unregister_proc_table(table->child, de);
663 /* Don't unregister directories which still have entries.. */
668 /* Don't unregister proc entries that are still being used.. */
669 if (atomic_read(&de->count))
673 remove_proc_entry(table->procname, root);
677 static ssize_t do_rw_proc(int write, struct file * file, char * buf,
678 size_t count, loff_t *ppos)
681 struct proc_dir_entry *de;
682 struct ctl_table *table;
686 de = (struct proc_dir_entry*) file->f_dentry->d_inode->u.generic_ip;
687 if (!de || !de->data)
689 table = (struct ctl_table *) de->data;
690 if (!table || !table->proc_handler)
692 op = (write ? 002 : 004);
693 if (ctl_perm(table, op))
699 * FIXME: we need to pass on ppos to the handler.
702 error = (*table->proc_handler) (table, write, file, buf, &res);
708 static ssize_t proc_readsys(struct file * file, char * buf,
709 size_t count, loff_t *ppos)
711 return do_rw_proc(0, file, buf, count, ppos);
714 static ssize_t proc_writesys(struct file * file, const char * buf,
715 size_t count, loff_t *ppos)
717 return do_rw_proc(1, file, (char *) buf, count, ppos);
720 static int proc_sys_permission(struct inode *inode, int op)
722 return test_perm(inode->i_mode, op);
726 * proc_dostring - read a string sysctl
727 * @table: the sysctl table
728 * @write: %TRUE if this is a write to the sysctl file
729 * @filp: the file structure
730 * @buffer: the user buffer
731 * @lenp: the size of the user buffer
733 * Reads/writes a string from/to the user buffer. If the kernel
734 * buffer provided is not large enough to hold the string, the
735 * string is truncated. The copied string is %NULL-terminated.
736 * If the string is being read by the user process, it is copied
737 * and a newline '\n' is added. It is truncated if the buffer is
740 * Returns 0 on success.
742 int proc_dostring(ctl_table *table, int write, struct file *filp,
743 void *buffer, size_t *lenp)
748 if (!table->data || !table->maxlen || !*lenp ||
749 (filp->f_pos && !write)) {
757 while (len < *lenp) {
760 if (c == 0 || c == '\n')
764 if (len >= table->maxlen)
765 len = table->maxlen-1;
766 if(copy_from_user(table->data, buffer, len))
768 ((char *) table->data)[len] = 0;
769 filp->f_pos += *lenp;
771 len = strlen(table->data);
772 if (len > table->maxlen)
777 if(copy_to_user(buffer, table->data, len))
780 if(put_user('\n', ((char *) buffer) + len))
791 * Special case of dostring for the UTS structure. This has locks
792 * to observe. Should this be in kernel/sys.c ????
795 static int proc_doutsstring(ctl_table *table, int write, struct file *filp,
796 void *buffer, size_t *lenp)
802 r=proc_dostring(table,0,filp,buffer,lenp);
805 down_write(&uts_sem);
806 r=proc_dostring(table,1,filp,buffer,lenp);
818 static int do_proc_dointvec(ctl_table *table, int write, struct file *filp,
819 void *buffer, size_t *lenp, int conv, int op)
821 int *i, vleft, first=1, neg, val;
825 char buf[TMPBUFLEN], *p;
827 if (!table->data || !table->maxlen || !*lenp ||
828 (filp->f_pos && !write)) {
833 i = (int *) table->data;
834 vleft = table->maxlen / sizeof(int);
837 for (; left && vleft--; i++, first=0) {
841 if(get_user(c,(char *) buffer))
852 if (len > TMPBUFLEN-1)
854 if(copy_from_user(buf, buffer, len))
858 if (*p == '-' && left > 1) {
862 if (*p < '0' || *p > '9')
864 val = simple_strtoul(p, &p, 0) * conv;
866 if ((len < left) && *p && !isspace(*p))
873 case OP_SET: *i = val; break;
874 case OP_AND: *i &= val; break;
875 case OP_OR: *i |= val; break;
876 case OP_MAX: if(*i < val)
879 case OP_MIN: if(*i > val)
887 sprintf(p, "%d", (*i) / conv);
891 if(copy_to_user(buffer, buf, len))
898 if (!write && !first && left) {
899 if(put_user('\n', (char *) buffer))
917 filp->f_pos += *lenp;
922 * proc_dointvec - read a vector of integers
923 * @table: the sysctl table
924 * @write: %TRUE if this is a write to the sysctl file
925 * @filp: the file structure
926 * @buffer: the user buffer
927 * @lenp: the size of the user buffer
929 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
930 * values from/to the user buffer, treated as an ASCII string.
932 * Returns 0 on success.
934 int proc_dointvec(ctl_table *table, int write, struct file *filp,
935 void *buffer, size_t *lenp)
937 return do_proc_dointvec(table,write,filp,buffer,lenp,1,OP_SET);
941 * init may raise the set.
944 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
945 void *buffer, size_t *lenp)
947 if (!capable(CAP_SYS_MODULE)) {
950 return do_proc_dointvec(table,write,filp,buffer,lenp,1,
951 (current->pid == 1) ? OP_SET : OP_AND);
955 * proc_dointvec_minmax - read a vector of integers with min/max values
956 * @table: the sysctl table
957 * @write: %TRUE if this is a write to the sysctl file
958 * @filp: the file structure
959 * @buffer: the user buffer
960 * @lenp: the size of the user buffer
962 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
963 * values from/to the user buffer, treated as an ASCII string.
965 * This routine will ensure the values are within the range specified by
966 * table->extra1 (min) and table->extra2 (max).
968 * Returns 0 on success.
970 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
971 void *buffer, size_t *lenp)
973 int *i, *min, *max, vleft, first=1, neg, val;
976 char buf[TMPBUFLEN], *p;
978 if (!table->data || !table->maxlen || !*lenp ||
979 (filp->f_pos && !write)) {
984 i = (int *) table->data;
985 min = (int *) table->extra1;
986 max = (int *) table->extra2;
987 vleft = table->maxlen / sizeof(int);
990 for (; left && vleft--; i++, min++, max++, first=0) {
994 if(get_user(c, (char *) buffer))
1005 if (len > TMPBUFLEN-1)
1007 if(copy_from_user(buf, buffer, len))
1011 if (*p == '-' && left > 1) {
1015 if (*p < '0' || *p > '9')
1017 val = simple_strtoul(p, &p, 0);
1019 if ((len < left) && *p && !isspace(*p))
1026 if ((min && val < *min) || (max && val > *max))
1033 sprintf(p, "%d", *i);
1037 if(copy_to_user(buffer, buf, len))
1044 if (!write && !first && left) {
1045 if(put_user('\n', (char *) buffer))
1050 p = (char *) buffer;
1053 if(get_user(c, p++))
1063 filp->f_pos += *lenp;
1067 static int do_proc_doulongvec_minmax(ctl_table *table, int write,
1069 void *buffer, size_t *lenp,
1070 unsigned long convmul,
1071 unsigned long convdiv)
1073 #define TMPBUFLEN 20
1074 unsigned long *i, *min, *max, val;
1075 int vleft, first=1, neg;
1077 char buf[TMPBUFLEN], *p;
1079 if (!table->data || !table->maxlen || !*lenp ||
1080 (filp->f_pos && !write)) {
1085 i = (unsigned long *) table->data;
1086 min = (unsigned long *) table->extra1;
1087 max = (unsigned long *) table->extra2;
1088 vleft = table->maxlen / sizeof(unsigned long);
1091 for (; left && vleft--; i++, first=0) {
1095 if(get_user(c, (char *) buffer))
1100 ((char *) buffer)++;
1106 if (len > TMPBUFLEN-1)
1108 if(copy_from_user(buf, buffer, len))
1112 if (*p == '-' && left > 1) {
1116 if (*p < '0' || *p > '9')
1118 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
1120 if ((len < left) && *p && !isspace(*p))
1129 if (min && val < *min++)
1131 if (max && val > *max++)
1138 sprintf(p, "%lu", convdiv * (*i) / convmul);
1142 if(copy_to_user(buffer, buf, len))
1149 if (!write && !first && left) {
1150 if(put_user('\n', (char *) buffer))
1155 p = (char *) buffer;
1158 if(get_user(c, p++))
1168 filp->f_pos += *lenp;
1174 * proc_doulongvec_minmax - read a vector of long integers with min/max values
1175 * @table: the sysctl table
1176 * @write: %TRUE if this is a write to the sysctl file
1177 * @filp: the file structure
1178 * @buffer: the user buffer
1179 * @lenp: the size of the user buffer
1181 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1182 * values from/to the user buffer, treated as an ASCII string.
1184 * This routine will ensure the values are within the range specified by
1185 * table->extra1 (min) and table->extra2 (max).
1187 * Returns 0 on success.
1189 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1190 void *buffer, size_t *lenp)
1192 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, 1l, 1l);
1196 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
1197 * @table: the sysctl table
1198 * @write: %TRUE if this is a write to the sysctl file
1199 * @filp: the file structure
1200 * @buffer: the user buffer
1201 * @lenp: the size of the user buffer
1203 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
1204 * values from/to the user buffer, treated as an ASCII string. The values
1205 * are treated as milliseconds, and converted to jiffies when they are stored.
1207 * This routine will ensure the values are within the range specified by
1208 * table->extra1 (min) and table->extra2 (max).
1210 * Returns 0 on success.
1212 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1214 void *buffer, size_t *lenp)
1216 return do_proc_doulongvec_minmax(table, write, filp, buffer,
1222 * proc_dointvec_jiffies - read a vector of integers as seconds
1223 * @table: the sysctl table
1224 * @write: %TRUE if this is a write to the sysctl file
1225 * @filp: the file structure
1226 * @buffer: the user buffer
1227 * @lenp: the size of the user buffer
1229 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1230 * values from/to the user buffer, treated as an ASCII string.
1231 * The values read are assumed to be in seconds, and are converted into
1234 * Returns 0 on success.
1236 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1237 void *buffer, size_t *lenp)
1239 return do_proc_dointvec(table,write,filp,buffer,lenp,HZ,OP_SET);
1242 #else /* CONFIG_PROC_FS */
1244 int proc_dostring(ctl_table *table, int write, struct file *filp,
1245 void *buffer, size_t *lenp)
1250 static int proc_doutsstring(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)
1294 #endif /* CONFIG_PROC_FS */
1298 * General sysctl support routines
1301 /* The generic string strategy routine: */
1302 int sysctl_string(ctl_table *table, int *name, int nlen,
1303 void *oldval, size_t *oldlenp,
1304 void *newval, size_t newlen, void **context)
1308 if (!table->data || !table->maxlen)
1311 if (oldval && oldlenp) {
1312 if(get_user(len, oldlenp))
1315 l = strlen(table->data);
1316 if (len > l) len = l;
1317 if (len >= table->maxlen)
1318 len = table->maxlen;
1319 if(copy_to_user(oldval, table->data, len))
1321 if(put_user(0, ((char *) oldval) + len))
1323 if(put_user(len, oldlenp))
1327 if (newval && newlen) {
1329 if (len > table->maxlen)
1330 len = table->maxlen;
1331 if(copy_from_user(table->data, newval, len))
1333 if (len == table->maxlen)
1335 ((char *) table->data)[len] = 0;
1341 * This function makes sure that all of the integers in the vector
1342 * are between the minimum and maximum values given in the arrays
1343 * table->extra1 and table->extra2, respectively.
1345 int sysctl_intvec(ctl_table *table, int *name, int nlen,
1346 void *oldval, size_t *oldlenp,
1347 void *newval, size_t newlen, void **context)
1349 int i, *vec, *min, *max;
1352 if (newval && newlen) {
1353 if (newlen % sizeof(int) != 0)
1356 if (!table->extra1 && !table->extra2)
1359 if (newlen > table->maxlen)
1360 newlen = table->maxlen;
1361 length = newlen / sizeof(int);
1363 vec = (int *) newval;
1364 min = (int *) table->extra1;
1365 max = (int *) table->extra2;
1367 for (i = 0; i < length; i++) {
1369 get_user(value, vec + i);
1370 if (min && value < min[i])
1372 if (max && value > max[i])
1379 /* Strategy function to convert jiffies to seconds */
1380 int sysctl_jiffies(ctl_table *table, int *name, int nlen,
1381 void *oldval, size_t *oldlenp,
1382 void *newval, size_t newlen, void **context)
1387 if (get_user(olen, oldlenp))
1389 if (olen!=sizeof(int))
1392 if (put_user(*(int *)(table->data) / HZ, (int *)oldval) ||
1393 (oldlenp && put_user(sizeof(int),oldlenp)))
1396 if (newval && newlen) {
1398 if (newlen != sizeof(int))
1400 if (get_user(new, (int *)newval))
1402 *(int *)(table->data) = new*HZ;
1408 #else /* CONFIG_SYSCTL */
1411 extern asmlinkage long sys_sysctl(struct __sysctl_args *args)
1416 int sysctl_string(ctl_table *table, int *name, int nlen,
1417 void *oldval, size_t *oldlenp,
1418 void *newval, size_t newlen, void **context)
1423 int sysctl_intvec(ctl_table *table, int *name, int nlen,
1424 void *oldval, size_t *oldlenp,
1425 void *newval, size_t newlen, void **context)
1430 int sysctl_jiffies(ctl_table *table, int *name, int nlen,
1431 void *oldval, size_t *oldlenp,
1432 void *newval, size_t newlen, void **context)
1437 int proc_dostring(ctl_table *table, int write, struct file *filp,
1438 void *buffer, size_t *lenp)
1443 int proc_dointvec(ctl_table *table, int write, struct file *filp,
1444 void *buffer, size_t *lenp)
1449 int proc_dointvec_bset(ctl_table *table, int write, struct file *filp,
1450 void *buffer, size_t *lenp)
1455 int proc_dointvec_minmax(ctl_table *table, int write, struct file *filp,
1456 void *buffer, size_t *lenp)
1461 int proc_dointvec_jiffies(ctl_table *table, int write, struct file *filp,
1462 void *buffer, size_t *lenp)
1467 int proc_doulongvec_minmax(ctl_table *table, int write, struct file *filp,
1468 void *buffer, size_t *lenp)
1473 int proc_doulongvec_ms_jiffies_minmax(ctl_table *table, int write,
1475 void *buffer, size_t *lenp)
1480 struct ctl_table_header * register_sysctl_table(ctl_table * table,
1486 void unregister_sysctl_table(struct ctl_table_header * table)
1490 #endif /* CONFIG_SYSCTL */