2 * SPDX-License-Identifier: BSD-3-Clause
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/sysproto.h>
35 #include <sys/kernel.h>
39 #include <sys/mutex.h>
40 #include <sys/socket.h>
41 #include <sys/sysctl.h>
42 #include <sys/utsname.h>
44 #include <vm/vm_param.h>
46 #if defined(COMPAT_43)
49 ogethostname(struct thread *td, struct ogethostname_args *uap)
52 size_t len = uap->len;
55 name[1] = KERN_HOSTNAME;
56 return (userland_sysctl(td, name, 2, uap->hostname, &len,
61 osethostname(struct thread *td, struct osethostname_args *uap)
66 name[1] = KERN_HOSTNAME;
67 return (userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname,
71 #ifndef _SYS_SYSPROTO_H_
72 struct ogethostid_args {
78 ogethostid(struct thread *td, struct ogethostid_args *uap)
80 size_t len = sizeof(long);
84 name[1] = KERN_HOSTID;
85 return (kernel_sysctl(td, name, 2, (long *)td->td_retval, &len,
90 osethostid(struct thread *td, struct osethostid_args *uap)
95 name[1] = KERN_HOSTID;
96 return (kernel_sysctl(td, name, 2, NULL, NULL, &uap->hostid,
97 sizeof(uap->hostid), NULL, 0));
101 oquota(struct thread *td, struct oquota_args *uap)
107 #define KINFO_PROC (0<<8)
108 #define KINFO_RT (1<<8)
109 /* UNUSED, was KINFO_VNODE (2<<8) */
110 #define KINFO_FILE (3<<8)
111 #define KINFO_METER (4<<8)
112 #define KINFO_LOADAVG (5<<8)
113 #define KINFO_CLOCKRATE (6<<8)
115 /* Non-standard BSDI extension - only present on their 4.3 net-2 releases */
116 #define KINFO_BSDI_SYSINFO (101<<8)
119 * XXX this is bloat, but I hope it's better here than on the potentially
120 * limited kernel stack... -Peter
124 int bsdi_machine; /* "i386" on BSD/386 */
125 /* ^^^ this is an offset to the string, relative to the struct start */
134 int bsdi_ostype; /* "BSD/386" on BSD/386 */
135 int bsdi_osrelease; /* "1.1" on BSD/386 */
147 struct timeval pad16;
148 /* we dont set this, because BSDI's uname used gethostname() instead */
149 int bsdi_hostname; /* hostname on BSD/386 */
151 /* the actual string data is appended here */
156 * this data is appended to the end of the bsdi_si structure during copyout.
157 * The "char *" offsets are relative to the base of the bsdi_si struct.
158 * This contains "FreeBSD\02.0-BUILT-nnnnnn\0i386\0", and these strings
159 * should not exceed the length of the buffer here... (or else!! :-)
161 static char bsdi_strings[80]; /* It had better be less than this! */
164 ogetkerninfo(struct thread *td, struct ogetkerninfo_args *uap)
170 switch (uap->op & 0xff00) {
175 name[3] = (uap->op & 0xff0000) >> 16;
176 name[4] = uap->op & 0xff;
178 error = userland_sysctl(td, name, 6, uap->where, uap->size,
185 name[2] = uap->op & 0xff;
187 error = userland_sysctl(td, name, 4, uap->where, uap->size,
194 error = userland_sysctl(td, name, 2, uap->where, uap->size,
201 error = userland_sysctl(td, name, 2, uap->where, uap->size,
207 name[1] = VM_LOADAVG;
208 error = userland_sysctl(td, name, 2, uap->where, uap->size,
212 case KINFO_CLOCKRATE:
214 name[1] = KERN_CLOCKRATE;
215 error = userland_sysctl(td, name, 2, uap->where, uap->size,
219 case KINFO_BSDI_SYSINFO: {
221 * this is pretty crude, but it's just enough for uname()
222 * from BSDI's 1.x libc to work.
224 * *size gives the size of the buffer before the call, and
225 * the amount of data copied after a successful call.
226 * If successful, the return value is the amount of data
227 * available, which can be larger than *size.
229 * BSDI's 2.x product apparently fails with ENOMEM if *size
236 bzero((char *)&bsdi_si, sizeof(bsdi_si));
237 bzero(bsdi_strings, sizeof(bsdi_strings));
241 bsdi_si.bsdi_ostype = (s - bsdi_strings) + sizeof(bsdi_si);
245 bsdi_si.bsdi_osrelease = (s - bsdi_strings) + sizeof(bsdi_si);
246 strcpy(s, osrelease);
249 bsdi_si.bsdi_machine = (s - bsdi_strings) + sizeof(bsdi_si);
253 needed = sizeof(bsdi_si) + (s - bsdi_strings);
255 if ((uap->where == NULL) || (uap->size == NULL)) {
256 /* process is asking how much buffer to supply.. */
262 if ((error = copyin(uap->size, &size, sizeof(size))) != 0)
265 /* if too much buffer supplied, trim it down */
269 /* how much of the buffer is remaining */
272 if ((error = copyout((char *)&bsdi_si, uap->where, left)) != 0)
275 /* is there any point in continuing? */
276 if (left > sizeof(bsdi_si)) {
277 left -= sizeof(bsdi_si);
278 error = copyout(&bsdi_strings,
279 uap->where + sizeof(bsdi_si), left);
289 td->td_retval[0] = needed ? needed : size;
291 error = copyout(&size, uap->size, sizeof(size));
296 #endif /* COMPAT_43 */
298 #ifdef COMPAT_FREEBSD4
300 * This is the FreeBSD-1.1 compatible uname(2) interface. These days it is
301 * done in libc as a wrapper around a bunch of sysctl's. This must maintain
302 * the old 1.1 binary ABI.
305 #error "FreeBSD-1.1 uname syscall has been broken"
307 #ifndef _SYS_SYSPROTO_H_
309 struct utsname *name;
314 freebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap)
321 name[1] = KERN_OSTYPE;
322 len = sizeof (uap->name->sysname);
323 error = userland_sysctl(td, name, 2, uap->name->sysname, &len,
327 subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
329 name[1] = KERN_HOSTNAME;
330 len = sizeof uap->name->nodename;
331 error = userland_sysctl(td, name, 2, uap->name->nodename, &len,
335 subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
337 name[1] = KERN_OSRELEASE;
338 len = sizeof uap->name->release;
339 error = userland_sysctl(td, name, 2, uap->name->release, &len,
343 subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
347 len = sizeof uap->name->version;
348 error = userland_sysctl(td, name, 2, uap->name->version, &len,
352 subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
356 * this stupid hackery to make the version field look like FreeBSD 1.1
358 for(s = version; *s && *s != '#'; s++);
360 for(us = uap->name->version; *s && *s != ':'; s++) {
361 error = subyte( us++, *s);
365 error = subyte( us++, 0);
370 name[1] = HW_MACHINE;
371 len = sizeof uap->name->machine;
372 error = userland_sysctl(td, name, 2, uap->name->machine, &len,
376 subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
380 #ifndef _SYS_SYSPROTO_H_
381 struct getdomainname_args {
388 freebsd4_getdomainname(struct thread *td,
389 struct freebsd4_getdomainname_args *uap)
392 size_t len = uap->len;
395 name[1] = KERN_NISDOMAINNAME;
396 return (userland_sysctl(td, name, 2, uap->domainname, &len,
400 #ifndef _SYS_SYSPROTO_H_
401 struct setdomainname_args {
408 freebsd4_setdomainname(struct thread *td,
409 struct freebsd4_setdomainname_args *uap)
414 name[1] = KERN_NISDOMAINNAME;
415 return (userland_sysctl(td, name, 2, 0, 0, 0, uap->domainname,
418 #endif /* COMPAT_FREEBSD4 */