The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/kern/kern_xxx.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /*-
    2  * Copyright (c) 1982, 1986, 1989, 1993
    3  *      The Regents of the University of California.  All rights reserved.
    4  *
    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  * 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  * 4. 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.
   16  *
   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
   27  * SUCH DAMAGE.
   28  *
   29  *      @(#)kern_xxx.c  8.2 (Berkeley) 11/14/93
   30  */
   31 
   32 #include <sys/cdefs.h>
   33 __FBSDID("$FreeBSD: src/sys/kern/kern_xxx.c,v 1.42.2.2 2005/01/31 23:26:16 imp Exp $");
   34 
   35 #include "opt_compat.h"
   36 
   37 #include <sys/param.h>
   38 #include <sys/systm.h>
   39 #include <sys/sysproto.h>
   40 #include <sys/kernel.h>
   41 #include <sys/proc.h>
   42 #include <sys/lock.h>
   43 #include <sys/mutex.h>
   44 #include <sys/sysctl.h>
   45 #include <sys/utsname.h>
   46 
   47 
   48 #if defined(COMPAT_43)
   49 
   50 #ifndef _SYS_SYSPROTO_H_
   51 struct gethostname_args {
   52         char    *hostname;
   53         u_int   len;
   54 };
   55 #endif
   56 /*
   57  * MPSAFE
   58  */
   59 /* ARGSUSED */
   60 int
   61 ogethostname(td, uap)
   62         struct thread *td;
   63         struct gethostname_args *uap;
   64 {
   65         int name[2];
   66         int error;
   67         size_t len = uap->len;
   68 
   69         name[0] = CTL_KERN;
   70         name[1] = KERN_HOSTNAME;
   71         mtx_lock(&Giant);
   72         error = userland_sysctl(td, name, 2, uap->hostname, &len, 1, 0, 0, 0);
   73         mtx_unlock(&Giant);
   74         return(error);
   75 }
   76 
   77 #ifndef _SYS_SYSPROTO_H_
   78 struct sethostname_args {
   79         char    *hostname;
   80         u_int   len;
   81 };
   82 #endif
   83 /*
   84  * MPSAFE
   85  */
   86 /* ARGSUSED */
   87 int
   88 osethostname(td, uap)
   89         struct thread *td;
   90         register struct sethostname_args *uap;
   91 {
   92         int name[2];
   93         int error;
   94 
   95         name[0] = CTL_KERN;
   96         name[1] = KERN_HOSTNAME;
   97         mtx_lock(&Giant);
   98         error = userland_sysctl(td, name, 2, 0, 0, 0, uap->hostname,
   99             uap->len, 0);
  100         mtx_unlock(&Giant);
  101         return (error);
  102 }
  103 
  104 #ifndef _SYS_SYSPROTO_H_
  105 struct ogethostid_args {
  106         int     dummy;
  107 };
  108 #endif
  109 /*
  110  * MPSAFE
  111  */
  112 /* ARGSUSED */
  113 int
  114 ogethostid(td, uap)
  115         struct thread *td;
  116         struct ogethostid_args *uap;
  117 {
  118 
  119         *(long *)(td->td_retval) = hostid;
  120         return (0);
  121 }
  122 #endif /* COMPAT_43 */
  123 
  124 #ifdef COMPAT_43
  125 #ifndef _SYS_SYSPROTO_H_
  126 struct osethostid_args {
  127         long    hostid;
  128 };
  129 #endif
  130 /*
  131  * MPSAFE
  132  */
  133 /* ARGSUSED */
  134 int
  135 osethostid(td, uap)
  136         struct thread *td;
  137         struct osethostid_args *uap;
  138 {
  139         int error;
  140 
  141         if ((error = suser(td)))
  142                 return (error);
  143         mtx_lock(&Giant);
  144         hostid = uap->hostid;
  145         mtx_unlock(&Giant);
  146         return (0);
  147 }
  148 
  149 /*
  150  * MPSAFE
  151  */
  152 int
  153 oquota(td, uap)
  154         struct thread *td;
  155         struct oquota_args *uap;
  156 {
  157         return (ENOSYS);
  158 }
  159 #endif /* COMPAT_43 */
  160 
  161 /*
  162  * This is the FreeBSD-1.1 compatable uname(2) interface.  These
  163  * days it is done in libc as a wrapper around a bunch of sysctl's.
  164  * This must maintain the old 1.1 binary ABI.
  165  */
  166 #if SYS_NMLN != 32
  167 #error "FreeBSD-1.1 uname syscall has been broken"
  168 #endif
  169 #ifndef _SYS_SYSPROTO_H_
  170 struct uname_args {
  171         struct utsname  *name;
  172 };
  173 #endif
  174 
  175 /*
  176  * MPSAFE
  177  */
  178 /* ARGSUSED */
  179 int
  180 uname(td, uap)
  181         struct thread *td;
  182         struct uname_args *uap;
  183 {
  184         int name[2], error;
  185         size_t len;
  186         char *s, *us;
  187 
  188         name[0] = CTL_KERN;
  189         name[1] = KERN_OSTYPE;
  190         len = sizeof (uap->name->sysname);
  191         mtx_lock(&Giant);
  192         error = userland_sysctl(td, name, 2, uap->name->sysname, &len, 
  193                 1, 0, 0, 0);
  194         if (error)
  195                 goto done2;
  196         subyte( uap->name->sysname + sizeof(uap->name->sysname) - 1, 0);
  197 
  198         name[1] = KERN_HOSTNAME;
  199         len = sizeof uap->name->nodename;
  200         error = userland_sysctl(td, name, 2, uap->name->nodename, &len, 
  201                 1, 0, 0, 0);
  202         if (error)
  203                 goto done2;
  204         subyte( uap->name->nodename + sizeof(uap->name->nodename) - 1, 0);
  205 
  206         name[1] = KERN_OSRELEASE;
  207         len = sizeof uap->name->release;
  208         error = userland_sysctl(td, name, 2, uap->name->release, &len, 
  209                 1, 0, 0, 0);
  210         if (error)
  211                 goto done2;
  212         subyte( uap->name->release + sizeof(uap->name->release) - 1, 0);
  213 
  214 /*
  215         name = KERN_VERSION;
  216         len = sizeof uap->name->version;
  217         error = userland_sysctl(td, name, 2, uap->name->version, &len, 
  218                 1, 0, 0, 0);
  219         if (error)
  220                 goto done2;
  221         subyte( uap->name->version + sizeof(uap->name->version) - 1, 0);
  222 */
  223 
  224 /*
  225  * this stupid hackery to make the version field look like FreeBSD 1.1
  226  */
  227         for(s = version; *s && *s != '#'; s++);
  228 
  229         for(us = uap->name->version; *s && *s != ':'; s++) {
  230                 error = subyte( us++, *s);
  231                 if (error)
  232                         goto done2;
  233         }
  234         error = subyte( us++, 0);
  235         if (error)
  236                 goto done2;
  237 
  238         name[0] = CTL_HW;
  239         name[1] = HW_MACHINE;
  240         len = sizeof uap->name->machine;
  241         error = userland_sysctl(td, name, 2, uap->name->machine, &len, 
  242                 1, 0, 0, 0);
  243         if (error)
  244                 goto done2;
  245         subyte( uap->name->machine + sizeof(uap->name->machine) - 1, 0);
  246 done2:
  247         mtx_unlock(&Giant);
  248         return (error);
  249 }
  250 
  251 #ifndef _SYS_SYSPROTO_H_
  252 struct getdomainname_args {
  253         char    *domainname;
  254         int     len;
  255 };
  256 #endif
  257 
  258 /*
  259  * MPSAFE
  260  */
  261 /* ARGSUSED */
  262 int
  263 getdomainname(td, uap)
  264         struct thread *td;
  265         struct getdomainname_args *uap;
  266 {
  267         int domainnamelen;
  268         int error;
  269 
  270         mtx_lock(&Giant);
  271         domainnamelen = strlen(domainname) + 1;
  272         if ((u_int)uap->len > domainnamelen)
  273                 uap->len = domainnamelen;
  274         error = copyout(domainname, uap->domainname, uap->len);
  275         mtx_unlock(&Giant);
  276         return (error);
  277 }
  278 
  279 #ifndef _SYS_SYSPROTO_H_
  280 struct setdomainname_args {
  281         char    *domainname;
  282         int     len;
  283 };
  284 #endif
  285 
  286 /*
  287  * MPSAFE
  288  */
  289 /* ARGSUSED */
  290 int
  291 setdomainname(td, uap)
  292         struct thread *td;
  293         struct setdomainname_args *uap;
  294 {
  295         int error, domainnamelen;
  296 
  297         mtx_lock(&Giant);
  298         if ((error = suser(td)))
  299                 goto done2;
  300         if ((u_int)uap->len > sizeof (domainname) - 1) {
  301                 error = EINVAL;
  302                 goto done2;
  303         }
  304         domainnamelen = uap->len;
  305         error = copyin(uap->domainname, domainname, uap->len);
  306         domainname[domainnamelen] = 0;
  307 done2:
  308         mtx_unlock(&Giant);
  309         return (error);
  310 }
  311 

Cache object: 76b414e42a5249b6be3e00e1ce7183f8


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.