Home | History | Annotate | Line # | Download | only in common
kern_info_43.c revision 1.1
      1 /*	$NetBSD: kern_info_43.c,v 1.1 1995/06/24 20:16:13 christos Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1982, 1986, 1991, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     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.
     22  *
     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
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)subr_xxx.c	8.1 (Berkeley) 6/10/93
     36  */
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/filedesc.h>
     41 #include <sys/kernel.h>
     42 #include <sys/vnode.h>
     43 #include <sys/proc.h>
     44 #include <sys/file.h>
     45 #include <sys/socket.h>
     46 #include <sys/socketvar.h>
     47 #include <sys/stat.h>
     48 #include <sys/ioctl.h>
     49 #include <sys/fcntl.h>
     50 #include <sys/malloc.h>
     51 #include <sys/syslog.h>
     52 #include <sys/unistd.h>
     53 #include <sys/resourcevar.h>
     54 #include <vm/vm.h>
     55 #include <sys/sysctl.h>
     56 
     57 #include <sys/mount.h>
     58 #include <sys/syscallargs.h>
     59 
     60 int
     61 compat_43_getdtablesize(p, uap, retval)
     62 	struct proc *p;
     63 	void *uap;
     64 	register_t *retval;
     65 {
     66 
     67 	*retval = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfiles);
     68 	return (0);
     69 }
     70 
     71 
     72 /* ARGSUSED */
     73 int
     74 compat_43_gethostid(p, uap, retval)
     75 	struct proc *p;
     76 	void *uap;
     77 	register_t *retval;
     78 {
     79 
     80 	*(int32_t *)retval = hostid;
     81 	return (0);
     82 }
     83 
     84 
     85 /*ARGSUSED*/
     86 int
     87 compat_43_gethostname(p, uap, retval)
     88 	struct proc *p;
     89 	struct compat_43_gethostname_args /* {
     90 		syscallarg(char *) hostname;
     91 		syscallarg(u_int) len;
     92 	} */ *uap;
     93 	register_t *retval;
     94 {
     95 	int name;
     96 
     97 	name = KERN_HOSTNAME;
     98 	return (kern_sysctl(&name, 1, SCARG(uap, hostname), &SCARG(uap, len),
     99 	    0, 0));
    100 }
    101 
    102 #define	KINFO_PROC		(0<<8)
    103 #define	KINFO_RT		(1<<8)
    104 #define	KINFO_VNODE		(2<<8)
    105 #define	KINFO_FILE		(3<<8)
    106 #define	KINFO_METER		(4<<8)
    107 #define	KINFO_LOADAVG		(5<<8)
    108 #define	KINFO_CLOCKRATE		(6<<8)
    109 
    110 int
    111 compat_43_getkerninfo(p, uap, retval)
    112 	struct proc *p;
    113 	register struct compat_43_getkerninfo_args /* {
    114 		syscallarg(int) op;
    115 		syscallarg(char *) where;
    116 		syscallarg(int *) size;
    117 		syscallarg(int) arg;
    118 	} */ *uap;
    119 	register_t *retval;
    120 {
    121 	int error, name[5];
    122 	size_t size;
    123 
    124 	if (SCARG(uap, size) && (error = copyin((caddr_t)SCARG(uap, size),
    125 	    (caddr_t)&size, sizeof(size))))
    126 		return (error);
    127 
    128 	switch (SCARG(uap, op) & 0xff00) {
    129 
    130 	case KINFO_RT:
    131 		name[0] = PF_ROUTE;
    132 		name[1] = 0;
    133 		name[2] = (SCARG(uap, op) & 0xff0000) >> 16;
    134 		name[3] = SCARG(uap, op) & 0xff;
    135 		name[4] = SCARG(uap, arg);
    136 		error =
    137 		    net_sysctl(name, 5, SCARG(uap, where), &size, NULL, 0, p);
    138 		break;
    139 
    140 	case KINFO_VNODE:
    141 		name[0] = KERN_VNODE;
    142 		error =
    143 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    144 		break;
    145 
    146 	case KINFO_PROC:
    147 		name[0] = KERN_PROC;
    148 		name[1] = SCARG(uap, op) & 0xff;
    149 		name[2] = SCARG(uap, arg);
    150 		error =
    151 		    kern_sysctl(name, 3, SCARG(uap, where), &size, NULL, 0, p);
    152 		break;
    153 
    154 	case KINFO_FILE:
    155 		name[0] = KERN_FILE;
    156 		error =
    157 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    158 		break;
    159 
    160 	case KINFO_METER:
    161 		name[0] = VM_METER;
    162 		error =
    163 		    vm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    164 		break;
    165 
    166 	case KINFO_LOADAVG:
    167 		name[0] = VM_LOADAVG;
    168 		error =
    169 		    vm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    170 		break;
    171 
    172 	case KINFO_CLOCKRATE:
    173 		name[0] = KERN_CLOCKRATE;
    174 		error =
    175 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    176 		break;
    177 
    178 	default:
    179 		return (EOPNOTSUPP);
    180 	}
    181 	if (error)
    182 		return (error);
    183 	*retval = size;
    184 	if (SCARG(uap, size))
    185 		error = copyout((caddr_t)&size, (caddr_t)SCARG(uap, size),
    186 		    sizeof(size));
    187 	return (error);
    188 }
    189 
    190 
    191 /* ARGSUSED */
    192 int
    193 compat_43_sethostid(p, uap, retval)
    194 	struct proc *p;
    195 	struct compat_43_sethostid_args /* {
    196 		syscallarg(int32_t) hostid;
    197 	} */ *uap;
    198 	register_t *retval;
    199 {
    200 	int error;
    201 
    202 	if (error = suser(p->p_ucred, &p->p_acflag))
    203 		return (error);
    204 	hostid = SCARG(uap, hostid);
    205 	return (0);
    206 }
    207 
    208 
    209 /* ARGSUSED */
    210 int
    211 compat_43_sethostname(p, uap, retval)
    212 	struct proc *p;
    213 	register struct compat_43_sethostname_args *uap;
    214 	register_t *retval;
    215 {
    216 	int name;
    217 	int error;
    218 
    219 	if (error = suser(p->p_ucred, &p->p_acflag))
    220 		return (error);
    221 	name = KERN_HOSTNAME;
    222 	return (kern_sysctl(&name, 1, 0, 0, SCARG(uap, hostname),
    223 	    SCARG(uap, len)));
    224 }
    225