drm: move to kref per-master structures.
[linux-2.6/linux-2.6-openrd.git] / kernel / utsname_sysctl.c
blob3b34b3545936dfcd179eca7f9fd2aebf4a2abfa0
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/sysctl.h>
17 static void *get_uts(ctl_table *table, int write)
19 char *which = table->data;
20 struct uts_namespace *uts_ns;
22 uts_ns = current->nsproxy->uts_ns;
23 which = (which - (char *)&init_uts_ns) + (char *)uts_ns;
25 if (!write)
26 down_read(&uts_sem);
27 else
28 down_write(&uts_sem);
29 return which;
32 static void put_uts(ctl_table *table, int write, void *which)
34 if (!write)
35 up_read(&uts_sem);
36 else
37 up_write(&uts_sem);
40 #ifdef CONFIG_PROC_FS
42 * Special case of dostring for the UTS structure. This has locks
43 * to observe. Should this be in kernel/sys.c ????
45 static int proc_do_uts_string(ctl_table *table, int write, struct file *filp,
46 void __user *buffer, size_t *lenp, loff_t *ppos)
48 struct ctl_table uts_table;
49 int r;
50 memcpy(&uts_table, table, sizeof(uts_table));
51 uts_table.data = get_uts(table, write);
52 r = proc_dostring(&uts_table,write,filp,buffer,lenp, ppos);
53 put_uts(table, write, uts_table.data);
54 return r;
56 #else
57 #define proc_do_uts_string NULL
58 #endif
61 #ifdef CONFIG_SYSCTL_SYSCALL
62 /* The generic string strategy routine: */
63 static int sysctl_uts_string(ctl_table *table,
64 void __user *oldval, size_t __user *oldlenp,
65 void __user *newval, size_t newlen)
67 struct ctl_table uts_table;
68 int r, write;
69 write = newval && newlen;
70 memcpy(&uts_table, table, sizeof(uts_table));
71 uts_table.data = get_uts(table, write);
72 r = sysctl_string(&uts_table, oldval, oldlenp, newval, newlen);
73 put_uts(table, write, uts_table.data);
74 return r;
76 #else
77 #define sysctl_uts_string NULL
78 #endif
80 static struct ctl_table uts_kern_table[] = {
82 .ctl_name = KERN_OSTYPE,
83 .procname = "ostype",
84 .data = init_uts_ns.name.sysname,
85 .maxlen = sizeof(init_uts_ns.name.sysname),
86 .mode = 0444,
87 .proc_handler = proc_do_uts_string,
88 .strategy = sysctl_uts_string,
91 .ctl_name = KERN_OSRELEASE,
92 .procname = "osrelease",
93 .data = init_uts_ns.name.release,
94 .maxlen = sizeof(init_uts_ns.name.release),
95 .mode = 0444,
96 .proc_handler = proc_do_uts_string,
97 .strategy = sysctl_uts_string,
100 .ctl_name = KERN_VERSION,
101 .procname = "version",
102 .data = init_uts_ns.name.version,
103 .maxlen = sizeof(init_uts_ns.name.version),
104 .mode = 0444,
105 .proc_handler = proc_do_uts_string,
106 .strategy = sysctl_uts_string,
109 .ctl_name = KERN_NODENAME,
110 .procname = "hostname",
111 .data = init_uts_ns.name.nodename,
112 .maxlen = sizeof(init_uts_ns.name.nodename),
113 .mode = 0644,
114 .proc_handler = proc_do_uts_string,
115 .strategy = sysctl_uts_string,
118 .ctl_name = KERN_DOMAINNAME,
119 .procname = "domainname",
120 .data = init_uts_ns.name.domainname,
121 .maxlen = sizeof(init_uts_ns.name.domainname),
122 .mode = 0644,
123 .proc_handler = proc_do_uts_string,
124 .strategy = sysctl_uts_string,
129 static struct ctl_table uts_root_table[] = {
131 .ctl_name = CTL_KERN,
132 .procname = "kernel",
133 .mode = 0555,
134 .child = uts_kern_table,
139 static int __init utsname_sysctl_init(void)
141 register_sysctl_table(uts_root_table);
142 return 0;
145 __initcall(utsname_sysctl_init);