ia64/linux-2.6.18-xen.hg

annotate kernel/sysctl.c @ 912:dd42cdb0ab89

[IA64] Build blktap2 driver by default in x86 builds.

add CONFIG_XEN_BLKDEV_TAP2=y to buildconfigs/linux-defconfig_xen_ia64.

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