2 * Copyright (c) 1982, 1986, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93
32 #include <sys/cdefs.h>
33 __FBSDID("$FreeBSD$");
35 #include "opt_compat.h"
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/sysproto.h>
40 #include <sys/kernel.h>
44 #include <sys/mutex.h>
45 #include <sys/socket.h>
46 #include <sys/sysctl.h>
47 #include <sys/utsname.h>
49 #include <vm/vm_param.h>
51 #if defined(COMPAT_43)
53 #ifndef _SYS_SYSPROTO_H_
54 struct gethostname_args {
63 struct gethostname_args *uap;
66 size_t len = uap->len;
69 name[1] = KERN_HOSTNAME;
70 return (userland_sysctl(td, name, 2, uap->hostname, &len,
74 #ifndef _SYS_SYSPROTO_H_
75 struct sethostname_args {
84 register struct sethostname_args *uap;
89 name[1] = KERN_HOSTNAME;
90 return (userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname,
94 #ifndef _SYS_SYSPROTO_H_
95 struct ogethostid_args {
103 struct ogethostid_args *uap;
105 size_t len = sizeof(long);
109 name[1] = KERN_HOSTID;
110 return (kernel_sysctl(td, name, 2, (long *)td->td_retval, &len,
113 #endif /* COMPAT_43 */
116 #ifndef _SYS_SYSPROTO_H_
117 struct osethostid_args {
125 struct osethostid_args *uap;
130 name[1] = KERN_HOSTID;
131 return (kernel_sysctl(td, name, 2, NULL, NULL, &uap->hostid,
132 sizeof(uap->hostid), NULL, 0));
138 struct oquota_args *uap;
144 #define KINFO_PROC (0<<8)
145 #define KINFO_RT (1<<8)
146 #define KINFO_VNODE (2<<8)
147 #define KINFO_FILE (3<<8)
148 #define KINFO_METER (4<<8)
149 #define KINFO_LOADAVG (5<<8)
150 #define KINFO_CLOCKRATE (6<<8)
152 /* Non-standard BSDI extension - only present on their 4.3 net-2 releases */
153 #define KINFO_BSDI_SYSINFO (101<<8)
156 * XXX this is bloat, but I hope it's better here than on the potentially
157 * limited kernel stack... -Peter
161 int bsdi_machine; /* "i386" on BSD/386 */
162 /* ^^^ this is an offset to the string, relative to the struct start */
171 int bsdi_ostype; /* "BSD/386" on BSD/386 */
172 int bsdi_osrelease; /* "1.1" on BSD/386 */
184 struct timeval pad16;
185 /* we dont set this, because BSDI's uname used gethostname() instead */
186 int bsdi_hostname; /* hostname on BSD/386 */
188 /* the actual string data is appended here */
193 * this data is appended to the end of the bsdi_si structure during copyout.
194 * The "char *" offsets are relative to the base of the bsdi_si struct.
195 * This contains "FreeBSD\02.0-BUILT-nnnnnn\0i386\0", and these strings
196 * should not exceed the length of the buffer here... (or else!! :-)
198 static char bsdi_strings[80]; /* It had better be less than this! */
200 #ifndef _SYS_SYSPROTO_H_
201 struct getkerninfo_args {
209 ogetkerninfo(struct thread *td, struct getkerninfo_args *uap)
215 switch (uap->op & 0xff00) {
221 name[3] = (uap->op & 0xff0000) >> 16;
222 name[4] = uap->op & 0xff;
224 error = userland_sysctl(td, name, 6, uap->where, uap->size,
230 name[1] = KERN_VNODE;
231 error = userland_sysctl(td, name, 2, uap->where, uap->size,
238 name[2] = uap->op & 0xff;
240 error = userland_sysctl(td, name, 4, uap->where, uap->size,
247 error = userland_sysctl(td, name, 2, uap->where, uap->size,
254 error = userland_sysctl(td, name, 2, uap->where, uap->size,
260 name[1] = VM_LOADAVG;
261 error = userland_sysctl(td, name, 2, uap->where, uap->size,
265 case KINFO_CLOCKRATE:
267 name[1] = KERN_CLOCKRATE;
268 error = userland_sysctl(td, name, 2, uap->where, uap->size,
272 case KINFO_BSDI_SYSINFO: {
274 * this is pretty crude, but it's just enough for uname()
275 * from BSDI's 1.x libc to work.
277 * *size gives the size of the buffer before the call, and
278 * the amount of data copied after a successful call.
279 * If successful, the return value is the amount of data
280 * available, which can be larger than *size.
282 * BSDI's 2.x product apparently fails with ENOMEM if *size
289 bzero((char *)&bsdi_si, sizeof(bsdi_si));
290 bzero(bsdi_strings, sizeof(bsdi_strings));
294 bsdi_si.bsdi_ostype = (s - bsdi_strings) + sizeof(bsdi_si);
298 bsdi_si.bsdi_osrelease = (s - bsdi_strings) + sizeof(bsdi_si);
299 strcpy(s, osrelease);
302 bsdi_si.bsdi_machine = (s - bsdi_strings) + sizeof(bsdi_si);
306 needed = sizeof(bsdi_si) + (s - bsdi_strings);
308 if ((uap->where == NULL) || (uap->size == NULL)) {
309 /* process is asking how much buffer to supply.. */
315 if ((error = copyin(uap->size, &size, sizeof(size))) != 0)
318 /* if too much buffer supplied, trim it down */
322 /* how much of the buffer is remaining */
325 if ((error = copyout((char *)&bsdi_si, uap->where, left)) != 0)
328 /* is there any point in continuing? */
329 if (left > sizeof(bsdi_si)) {
330 left -= sizeof(bsdi_si);
331 error = copyout(&bsdi_strings,
332 uap->where + sizeof(bsdi_si), left);
342 td->td_retval[0] = needed ? needed : size;
344 error = copyout(&size, uap->size, sizeof(size));
349 #endif /* COMPAT_43 */
351 #ifdef COMPAT_FREEBSD4
353 * This is the FreeBSD-1.1 compatible uname(2) interface. These days it is
354 * done in libc as a wrapper around a bunch of sysctl's. This must maintain
355 * the old 1.1 binary ABI.
358 #error "FreeBSD-1.1 uname syscall has been broken"
360 #ifndef _SYS_SYSPROTO_H_
362 struct utsname *name;
367 freebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap)
374 name[1] = KERN_OSTYPE;
375 len = sizeof (uap->name->sysname);
376 error = userland_sysctl(td, name, 2, uap->name->sysname, &len,
380 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
382 name[1] = KERN_HOSTNAME;
383 len = sizeof uap->name->nodename;
384 error = userland_sysctl(td, name, 2, uap->name->nodename, &len,
388 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
390 name[1] = KERN_OSRELEASE;
391 len = sizeof uap->name->release;
392 error = userland_sysctl(td, name, 2, uap->name->release, &len,
396 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
400 len = sizeof uap->name->version;
401 error = userland_sysctl(td, name, 2, uap->name->version, &len,
405 subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
409 * this stupid hackery to make the version field look like FreeBSD 1.1
411 for(s = version; *s && *s != '#'; s++);
413 for(us = uap->name->version; *s && *s != ':'; s++) {
414 error = subyte( us++, *s);
418 error = subyte( us++, 0);
423 name[1] = HW_MACHINE;
424 len = sizeof uap->name->machine;
425 error = userland_sysctl(td, name, 2, uap->name->machine, &len,
429 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
433 #ifndef _SYS_SYSPROTO_H_
434 struct getdomainname_args {
441 freebsd4_getdomainname(struct thread *td,
442 struct freebsd4_getdomainname_args *uap)
445 size_t len = uap->len;
448 name[1] = KERN_NISDOMAINNAME;
449 return (userland_sysctl(td, name, 2, uap->domainname, &len,
453 #ifndef _SYS_SYSPROTO_H_
454 struct setdomainname_args {
461 freebsd4_setdomainname(struct thread *td,
462 struct freebsd4_setdomainname_args *uap)
467 name[1] = KERN_NISDOMAINNAME;
468 return (userland_sysctl(td, name, 2, 0, 0, 0, uap->domainname,
471 #endif /* COMPAT_FREEBSD4 */