kern_xxx.c revision 186564
1139804Simp/*- 21541Srgrimes * Copyright (c) 1982, 1986, 1989, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 291541Srgrimes * @(#)kern_xxx.c 8.2 (Berkeley) 11/14/93 301541Srgrimes */ 311541Srgrimes 32116182Sobrien#include <sys/cdefs.h> 33116182Sobrien__FBSDID("$FreeBSD: head/sys/kern/kern_xxx.c 186564 2008-12-29 12:58:45Z ed $"); 34116182Sobrien 3531778Seivind#include "opt_compat.h" 3631778Seivind 371541Srgrimes#include <sys/param.h> 381541Srgrimes#include <sys/systm.h> 3912221Sbde#include <sys/sysproto.h> 401541Srgrimes#include <sys/kernel.h> 41164033Srwatson#include <sys/priv.h> 421541Srgrimes#include <sys/proc.h> 4382717Sdillon#include <sys/lock.h> 4482717Sdillon#include <sys/mutex.h> 451541Srgrimes#include <sys/sysctl.h> 461549Srgrimes#include <sys/utsname.h> 47181803Sbz#include <sys/vimage.h> 481541Srgrimes 498876Srgrimes 50130344Sphk#if defined(COMPAT_43) 511541Srgrimes 5212221Sbde#ifndef _SYS_SYSPROTO_H_ 531541Srgrimesstruct gethostname_args { 541541Srgrimes char *hostname; 551541Srgrimes u_int len; 561541Srgrimes}; 5712221Sbde#endif 581541Srgrimes/* ARGSUSED */ 591549Srgrimesint 6083366Sjulianogethostname(td, uap) 6183366Sjulian struct thread *td; 621541Srgrimes struct gethostname_args *uap; 631541Srgrimes{ 6412171Sphk int name[2]; 6538517Sdfr size_t len = uap->len; 661541Srgrimes 6712171Sphk name[0] = CTL_KERN; 6812171Sphk name[1] = KERN_HOSTNAME; 69186564Sed return (userland_sysctl(td, name, 2, uap->hostname, &len, 70186564Sed 1, 0, 0, 0, 0)); 711541Srgrimes} 721541Srgrimes 7312221Sbde#ifndef _SYS_SYSPROTO_H_ 741541Srgrimesstruct sethostname_args { 751541Srgrimes char *hostname; 761541Srgrimes u_int len; 771541Srgrimes}; 7812221Sbde#endif 791541Srgrimes/* ARGSUSED */ 801549Srgrimesint 8183366Sjulianosethostname(td, uap) 8283366Sjulian struct thread *td; 831541Srgrimes register struct sethostname_args *uap; 841541Srgrimes{ 8512171Sphk int name[2]; 861541Srgrimes int error; 871541Srgrimes 8812171Sphk name[0] = CTL_KERN; 8912171Sphk name[1] = KERN_HOSTNAME; 90186564Sed return (userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname, 91186564Sed uap->len, 0, 0)); 921541Srgrimes} 931541Srgrimes 9412221Sbde#ifndef _SYS_SYSPROTO_H_ 9512200Sbdestruct ogethostid_args { 961541Srgrimes int dummy; 971541Srgrimes}; 9812221Sbde#endif 991541Srgrimes/* ARGSUSED */ 1001549Srgrimesint 10183366Sjulianogethostid(td, uap) 10283366Sjulian struct thread *td; 10312200Sbde struct ogethostid_args *uap; 1041541Srgrimes{ 1051541Srgrimes 10683366Sjulian *(long *)(td->td_retval) = hostid; 1071541Srgrimes return (0); 1081541Srgrimes} 109130344Sphk#endif /* COMPAT_43 */ 1101541Srgrimes 1111541Srgrimes#ifdef COMPAT_43 11212221Sbde#ifndef _SYS_SYSPROTO_H_ 11312200Sbdestruct osethostid_args { 1141541Srgrimes long hostid; 1151541Srgrimes}; 11612221Sbde#endif 1171541Srgrimes/* ARGSUSED */ 1181549Srgrimesint 11983366Sjulianosethostid(td, uap) 12083366Sjulian struct thread *td; 12112200Sbde struct osethostid_args *uap; 1221541Srgrimes{ 1231541Srgrimes int error; 1241541Srgrimes 125164033Srwatson error = priv_check(td, PRIV_SETHOSTID); 126164033Srwatson if (error) 127119364Stjr return (error); 12882717Sdillon mtx_lock(&Giant); 129119364Stjr hostid = uap->hostid; 13082717Sdillon mtx_unlock(&Giant); 131119364Stjr return (0); 1321541Srgrimes} 1331541Srgrimes 1341549Srgrimesint 13583366Sjulianoquota(td, uap) 13683366Sjulian struct thread *td; 13712200Sbde struct oquota_args *uap; 1381541Srgrimes{ 139167232Srwatson 1401541Srgrimes return (ENOSYS); 1411541Srgrimes} 1421541Srgrimes#endif /* COMPAT_43 */ 1431549Srgrimes 144184789Sed#ifdef COMPAT_FREEBSD4 14574729Speter/* 146184789Sed * This is the FreeBSD-1.1 compatible uname(2) interface. These days it is 147167232Srwatson * done in libc as a wrapper around a bunch of sysctl's. This must maintain 148167232Srwatson * the old 1.1 binary ABI. 14974729Speter */ 15074729Speter#if SYS_NMLN != 32 15174729Speter#error "FreeBSD-1.1 uname syscall has been broken" 15274729Speter#endif 15312221Sbde#ifndef _SYS_SYSPROTO_H_ 1541549Srgrimesstruct uname_args { 155180039Sjulian struct utsname *name; 1561549Srgrimes}; 15712221Sbde#endif 1581549Srgrimes/* ARGSUSED */ 1591549Srgrimesint 160184789Sedfreebsd4_uname(struct thread *td, struct freebsd4_uname_args *uap) 1611549Srgrimes{ 16282717Sdillon int name[2], error; 16338517Sdfr size_t len; 1641549Srgrimes char *s, *us; 1651549Srgrimes 16612171Sphk name[0] = CTL_KERN; 16712171Sphk name[1] = KERN_OSTYPE; 16882717Sdillon len = sizeof (uap->name->sysname); 16983366Sjulian error = userland_sysctl(td, name, 2, uap->name->sysname, &len, 170136404Speter 1, 0, 0, 0, 0); 17182717Sdillon if (error) 172186564Sed return (error); 1731549Srgrimes subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0); 1741549Srgrimes 17512171Sphk name[1] = KERN_HOSTNAME; 1761549Srgrimes len = sizeof uap->name->nodename; 17783366Sjulian error = userland_sysctl(td, name, 2, uap->name->nodename, &len, 178136404Speter 1, 0, 0, 0, 0); 17982717Sdillon if (error) 180186564Sed return (error); 1811549Srgrimes subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0); 1821549Srgrimes 18312171Sphk name[1] = KERN_OSRELEASE; 1841549Srgrimes len = sizeof uap->name->release; 18583366Sjulian error = userland_sysctl(td, name, 2, uap->name->release, &len, 186136404Speter 1, 0, 0, 0, 0); 18782717Sdillon if (error) 188186564Sed return (error); 1891549Srgrimes subyte( uap->name->release + sizeof(uap->name->release) - 1, 0); 1901549Srgrimes 1911549Srgrimes/* 1921549Srgrimes name = KERN_VERSION; 1931549Srgrimes len = sizeof uap->name->version; 19483366Sjulian error = userland_sysctl(td, name, 2, uap->name->version, &len, 195136404Speter 1, 0, 0, 0, 0); 19682717Sdillon if (error) 197186564Sed return (error); 1981549Srgrimes subyte( uap->name->version + sizeof(uap->name->version) - 1, 0); 1991549Srgrimes*/ 2001549Srgrimes 2011549Srgrimes/* 2021549Srgrimes * this stupid hackery to make the version field look like FreeBSD 1.1 2031549Srgrimes */ 2041549Srgrimes for(s = version; *s && *s != '#'; s++); 2051549Srgrimes 2061549Srgrimes for(us = uap->name->version; *s && *s != ':'; s++) { 20782717Sdillon error = subyte( us++, *s); 20882717Sdillon if (error) 209186564Sed return (error); 2101549Srgrimes } 21182717Sdillon error = subyte( us++, 0); 21282717Sdillon if (error) 213186564Sed return (error); 2141549Srgrimes 21538517Sdfr name[0] = CTL_HW; 21612171Sphk name[1] = HW_MACHINE; 2171549Srgrimes len = sizeof uap->name->machine; 21883366Sjulian error = userland_sysctl(td, name, 2, uap->name->machine, &len, 219136404Speter 1, 0, 0, 0, 0); 22082717Sdillon if (error) 221186564Sed return (error); 2221549Srgrimes subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0); 223186564Sed return (0); 2241549Srgrimes} 2251549Srgrimes 22612221Sbde#ifndef _SYS_SYSPROTO_H_ 2271549Srgrimesstruct getdomainname_args { 228180039Sjulian char *domainname; 229180039Sjulian int len; 2301549Srgrimes}; 23112222Sbde#endif 2321549Srgrimes/* ARGSUSED */ 2331549Srgrimesint 234184789Sedfreebsd4_getdomainname(struct thread *td, 235184789Sed struct freebsd4_getdomainname_args *uap) 2361549Srgrimes{ 237184789Sed int name[2]; 238184789Sed size_t len = uap->len; 23982717Sdillon 240184789Sed name[0] = CTL_KERN; 241184789Sed name[1] = KERN_NISDOMAINNAME; 242186564Sed return (userland_sysctl(td, name, 2, uap->domainname, &len, 243186564Sed 1, 0, 0, 0, 0)); 2441549Srgrimes} 2451549Srgrimes 24612221Sbde#ifndef _SYS_SYSPROTO_H_ 2471549Srgrimesstruct setdomainname_args { 248180039Sjulian char *domainname; 249180039Sjulian int len; 2501549Srgrimes}; 25112221Sbde#endif 2521549Srgrimes/* ARGSUSED */ 2531549Srgrimesint 254184789Sedfreebsd4_setdomainname(struct thread *td, 255184789Sed struct freebsd4_setdomainname_args *uap) 2561549Srgrimes{ 257184789Sed int name[2]; 2581549Srgrimes 259184789Sed name[0] = CTL_KERN; 260184789Sed name[1] = KERN_NISDOMAINNAME; 261186564Sed return (userland_sysctl(td, name, 2, 0, 0, 0, uap->domainname, 262186564Sed uap->len, 0, 0)); 2631549Srgrimes} 264184789Sed#endif /* COMPAT_FREEBSD4 */ 265