sbin/hammer: Directly access volume in volume list
[dragonfly.git] / sys / emulation / linux / linux_sysctl.c
blob66e3c4ba19bd2cde6a0e855b1325a504cccfccdb
1 /*-
2 * Copyright (c) 2001 Marcel Moolenaar
3 * All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * $FreeBSD: src/sys/compat/linux/linux_sysctl.c,v 1.2.2.1 2001/10/21 03:57:35 marcel Exp $
29 * $DragonFly: src/sys/emulation/linux/linux_sysctl.c,v 1.9 2006/12/23 00:27:02 swildner Exp $
32 #include "opt_compat.h"
34 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/proc.h>
37 #include <sys/sysproto.h>
39 #include <sys/mplock2.h>
41 #include <arch_linux/linux.h>
42 #include <arch_linux/linux_proto.h>
43 #include "linux_util.h"
45 #define LINUX_CTL_KERN 1
46 #define LINUX_CTL_VM 2
47 #define LINUX_CTL_NET 3
48 #define LINUX_CTL_PROC 4
49 #define LINUX_CTL_FS 5
50 #define LINUX_CTL_DEBUG 6
51 #define LINUX_CTL_DEV 7
52 #define LINUX_CTL_BUS 8
54 /* CTL_KERN names */
55 #define LINUX_KERN_OSTYPE 1
56 #define LINUX_KERN_OSRELEASE 2
57 #define LINUX_KERN_OSREV 3
58 #define LINUX_KERN_VERSION 4
60 static int
61 handle_string(struct l___sysctl_args *la, char *value)
63 int error;
65 if (la->oldval != NULL) {
66 l_int len = strlen(value);
67 error = copyout(value, la->oldval, len + 1);
68 if (!error && la->oldlenp != NULL)
69 error = copyout(&len, la->oldlenp, sizeof(len));
70 if (error)
71 return (error);
74 if (la->newval != NULL)
75 return (ENOTDIR);
77 return (0);
81 * MPALMOSTSAFE
83 int
84 sys_linux_sysctl(struct linux_sysctl_args *args)
86 struct l___sysctl_args la;
87 l_int *mib;
88 int error, i;
90 error = copyin((caddr_t)args->args, &la, sizeof(la));
91 if (error)
92 return (error);
94 if (la.nlen <= 0 || la.nlen > LINUX_CTL_MAXNAME)
95 return (ENOTDIR);
97 mib = kmalloc(la.nlen * sizeof(l_int), M_TEMP, M_WAITOK);
98 error = copyin(la.name, mib, la.nlen * sizeof(l_int));
99 if (error) {
100 kfree(mib, M_TEMP);
101 return (error);
104 get_mplock();
106 switch (mib[0]) {
107 case LINUX_CTL_KERN:
108 if (la.nlen < 2) {
109 error = ENOTDIR;
110 break;
113 switch (mib[1]) {
114 case LINUX_KERN_VERSION:
115 error = handle_string(&la, version);
116 break;
117 default:
118 error = ENOTDIR;
119 break;
121 break;
122 default:
123 error = ENOTDIR;
124 break;
126 rel_mplock();
128 if (error == ENOTDIR && mib) {
129 kprintf("linux: sysctl: unhandled name=");
130 for (i = 0; i < la.nlen; i++)
131 kprintf("%c%d", (i) ? ',' : '{', mib[i]);
132 kprintf("}\n");
134 if (mib)
135 kfree(mib, M_TEMP);
136 return (error);