2 * 43BSD_HOSTINFO.C - 4.3BSD compatibility host info syscalls
4 * Copyright (c) 1982, 1986, 1989, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * $DragonFly: src/sys/emulation/43bsd/43bsd_hostinfo.c,v 1.4 2006/09/05 00:55:44 dillon Exp $
36 * from: DragonFly kern/kern_xxx.c,v 1.7
37 * from: DragonFly kern/kern_sysctl.c,v 1.12
39 * These syscalls used to live in kern/kern_xxx.c and kern/kern_sysctl.c.
42 #include "opt_compat.h"
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/sysproto.h>
47 #include <sys/kernel.h>
50 #include <sys/socket.h>
51 #include <sys/sysctl.h>
53 #include <vm/vm_param.h>
55 #include <sys/mplock2.h>
61 sys_ogethostname(struct gethostname_args *uap)
68 name[1] = KERN_HOSTNAME;
69 len = MIN(uap->len, MAXHOSTNAMELEN);
70 hostname = kmalloc(MAXHOSTNAMELEN, M_TEMP, M_WAITOK);
73 error = kernel_sysctl(name, 2, hostname, &len, NULL, 0, NULL);
77 error = copyout(hostname, uap->hostname, len);
79 kfree(hostname, M_TEMP);
87 sys_osethostname(struct sethostname_args *uap)
89 struct thread *td = curthread;
96 name[1] = KERN_HOSTNAME;
97 error = priv_check_cred(td->td_ucred, PRIV_SETHOSTNAME, 0);
100 len = MIN(uap->len, MAXHOSTNAMELEN);
101 hostname = kmalloc(MAXHOSTNAMELEN, M_TEMP, M_WAITOK);
103 error = copyin(uap->hostname, hostname, len);
105 kfree(hostname, M_TEMP);
110 error = kernel_sysctl(name, 2, NULL, 0, hostname, len, NULL);
113 kfree(hostname, M_TEMP);
121 sys_ogethostid(struct ogethostid_args *uap)
123 uap->sysmsg_lresult = hostid;
131 sys_osethostid(struct osethostid_args *uap)
133 struct thread *td = curthread;
136 error = priv_check(td, PRIV_ROOT);
139 hostid = uap->hostid;
147 sys_oquota(struct oquota_args *uap)
152 #define KINFO_PROC (0<<8)
153 #define KINFO_RT (1<<8)
154 #define KINFO_VNODE (2<<8)
155 #define KINFO_FILE (3<<8)
156 #define KINFO_METER (4<<8)
157 #define KINFO_LOADAVG (5<<8)
158 #define KINFO_CLOCKRATE (6<<8)
160 /* Non-standard BSDI extension - only present on their 4.3 net-2 releases */
161 #define KINFO_BSDI_SYSINFO (101<<8)
164 * XXX this is bloat, but I hope it's better here than on the potentially
165 * limited kernel stack... -Peter
169 int bsdi_machine; /* "i386" on BSD/386 */
170 /* ^^^ this is an offset to the string, relative to the struct start */
179 int bsdi_ostype; /* "BSD/386" on BSD/386 */
180 int bsdi_osrelease; /* "1.1" on BSD/386 */
192 struct timeval pad16;
193 /* we dont set this, because BSDI's uname used gethostname() instead */
194 int bsdi_hostname; /* hostname on BSD/386 */
196 /* the actual string data is appended here */
200 * this data is appended to the end of the bsdi_si structure during copyout.
201 * The "char *" offsets are relative to the base of the bsdi_si struct.
202 * This contains "FreeBSD\02.0-BUILT-nnnnnn\0i386\0", and these strings
203 * should not exceed the length of the buffer here... (or else!! :-)
205 static char bsdi_strings[80]; /* It had better be less than this! */
211 sys_ogetkerninfo(struct getkerninfo_args *uap)
219 switch (uap->op & 0xff00) {
224 name[3] = (uap->op & 0xff0000) >> 16;
225 name[4] = uap->op & 0xff;
227 error = userland_sysctl(name, 6, uap->where, uap->size,
233 name[1] = KERN_VNODE;
234 error = userland_sysctl(name, 2, uap->where, uap->size,
241 name[2] = uap->op & 0xff;
243 error = userland_sysctl(name, 4, uap->where, uap->size,
250 error = userland_sysctl(name, 2, uap->where, uap->size,
257 error = userland_sysctl(name, 2, uap->where, uap->size,
263 name[1] = VM_LOADAVG;
264 error = userland_sysctl(name, 2, uap->where, uap->size,
268 case KINFO_CLOCKRATE:
270 name[1] = KERN_CLOCKRATE;
271 error = userland_sysctl(name, 2, uap->where, uap->size,
275 case KINFO_BSDI_SYSINFO: {
277 * this is pretty crude, but it's just enough for uname()
278 * from BSDI's 1.x libc to work.
279 * *size gives the size of the buffer before the call, and
280 * the amount of data copied after a successful call.
281 * If successful, the return value is the amount of data
282 * available, which can be larger than *size.
284 * BSDI's 2.x product apparently fails with ENOMEM if
285 * *size is too small.
291 bzero((char *)&bsdi_si, sizeof(bsdi_si));
292 bzero(bsdi_strings, sizeof(bsdi_strings));
296 bsdi_si.bsdi_ostype = (s - bsdi_strings) + sizeof(bsdi_si);
300 bsdi_si.bsdi_osrelease = (s - bsdi_strings) + sizeof(bsdi_si);
301 strcpy(s, osrelease);
304 bsdi_si.bsdi_machine = (s - bsdi_strings) + sizeof(bsdi_si);
308 needed = sizeof(bsdi_si) + (s - bsdi_strings);
310 if (uap->where == NULL || (uap->size == NULL)) {
311 /* process is asking how much buffer to supply.. */
317 if ((error = copyin(uap->size, &size, sizeof(size))) != 0)
320 /* if too much buffer supplied, trim it down */
324 /* how much of the buffer is remaining */
327 if ((error = copyout((char *)&bsdi_si, uap->where, left)) != 0)
330 /* is there any point in continuing? */
331 if (left > sizeof(bsdi_si)) {
332 left -= sizeof(bsdi_si);
333 error = copyout(&bsdi_strings,
334 uap->where + sizeof(bsdi_si), left);
345 uap->sysmsg_iresult = (int)size;
347 error = copyout(&size, uap->size, sizeof(size));