USB: simplify hub_restart() logic
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / utsname_sysctl.c
blobfe3a56c2256d7ee44e46813aeee597559ba29131
1 /*
2 * Copyright (C) 2007
4 * Author: Eric Biederman <ebiederm@xmision.com>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation, version 2 of the
9 * License.
12 #include <linux/module.h>
13 #include <linux/uts.h>
14 #include <linux/utsname.h>
15 #include <linux/version.h>
16 #include <linux/sysctl.h>
18 static void *get_uts(ctl_table *table, int write)
20 char *which = table->data;
21 struct uts_namespace *uts_ns;
23 uts_ns = current->nsproxy->uts_ns;
24 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
26 if (!write)
27 down_read(&uts_sem);
28 else
29 down_write(&uts_sem);
30 return which;
33 static void put_uts(ctl_table *table, int write, void *which)
35 if (!write)
36 up_read(&uts_sem);
37 else
38 up_write(&uts_sem);
41 #ifdef CONFIG_PROC_FS
43 * Special case of dostring for the UTS structure. This has locks
44 * to observe. Should this be in kernel/sys.c ????
46 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
47 void __user *buffer, size_t *lenp, loff_t *ppos)
49 struct ctl_table uts_table;
50 int r;
51 memcpy(&uts_table, table, sizeof(uts_table));
52 uts_table.data = get_uts(table, write);
53 r = proc_dostring(&uts_table,write,filp,buffer,lenp, ppos);
54 put_uts(table, write, uts_table.data);
55 return r;
57 #else
58 #define proc_do_uts_string NULL
59 #endif
62 #ifdef CONFIG_SYSCTL_SYSCALL
63 /* The generic string strategy routine: */
64 static int sysctl_uts_string(ctl_table *table, int __user *name, int nlen,
65 void __user *oldval, size_t __user *oldlenp,
66 void __user *newval, size_t newlen)
68 struct ctl_table uts_table;
69 int r, write;
70 write = newval && newlen;
71 memcpy(&uts_table, table, sizeof(uts_table));
72 uts_table.data = get_uts(table, write);
73 r = sysctl_string(&uts_table, name, nlen,
74 oldval, oldlenp, newval, newlen);
75 put_uts(table, write, uts_table.data);
76 return r;
78 #else
79 #define sysctl_uts_string NULL
80 #endif
82 static struct ctl_table uts_kern_table[] = {
84 .ctl_name = KERN_OSTYPE,
85 .procname = "ostype",
86 .data = init_uts_ns.name.sysname,
87 .maxlen = sizeof(init_uts_ns.name.sysname),
88 .mode = 0444,
89 .proc_handler = proc_do_uts_string,
90 .strategy = sysctl_uts_string,
93 .ctl_name = KERN_OSRELEASE,
94 .procname = "osrelease",
95 .data = init_uts_ns.name.release,
96 .maxlen = sizeof(init_uts_ns.name.release),
97 .mode = 0444,
98 .proc_handler = proc_do_uts_string,
99 .strategy = sysctl_uts_string,
102 .ctl_name = KERN_VERSION,
103 .procname = "version",
104 .data = init_uts_ns.name.version,
105 .maxlen = sizeof(init_uts_ns.name.version),
106 .mode = 0444,
107 .proc_handler = proc_do_uts_string,
108 .strategy = sysctl_uts_string,
111 .ctl_name = KERN_NODENAME,
112 .procname = "hostname",
113 .data = init_uts_ns.name.nodename,
114 .maxlen = sizeof(init_uts_ns.name.nodename),
115 .mode = 0644,
116 .proc_handler = proc_do_uts_string,
117 .strategy = sysctl_uts_string,
120 .ctl_name = KERN_DOMAINNAME,
121 .procname = "domainname",
122 .data = init_uts_ns.name.domainname,
123 .maxlen = sizeof(init_uts_ns.name.domainname),
124 .mode = 0644,
125 .proc_handler = proc_do_uts_string,
126 .strategy = sysctl_uts_string,
131 static struct ctl_table uts_root_table[] = {
133 .ctl_name = CTL_KERN,
134 .procname = "kernel",
135 .mode = 0555,
136 .child = uts_kern_table,
141 static int __init utsname_sysctl_init(void)
143 register_sysctl_table(uts_root_table);
144 return 0;
147 __initcall(utsname_sysctl_init);