Home | History | Annotate | Line # | Download | only in common
kern_info_43.c revision 1.3
      1  1.3   mycroft /*	$NetBSD: kern_info_43.c,v 1.3 1995/10/07 06:26:24 mycroft Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (c) 1982, 1986, 1991, 1993
      5  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * Redistribution and use in source and binary forms, with or without
      8  1.1  christos  * modification, are permitted provided that the following conditions
      9  1.1  christos  * are met:
     10  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  christos  *    documentation and/or other materials provided with the distribution.
     15  1.1  christos  * 3. All advertising materials mentioning features or use of this software
     16  1.1  christos  *    must display the following acknowledgement:
     17  1.1  christos  *	This product includes software developed by the University of
     18  1.1  christos  *	California, Berkeley and its contributors.
     19  1.1  christos  * 4. Neither the name of the University nor the names of its contributors
     20  1.1  christos  *    may be used to endorse or promote products derived from this software
     21  1.1  christos  *    without specific prior written permission.
     22  1.1  christos  *
     23  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  christos  * SUCH DAMAGE.
     34  1.1  christos  *
     35  1.1  christos  *	@(#)subr_xxx.c	8.1 (Berkeley) 6/10/93
     36  1.1  christos  */
     37  1.1  christos 
     38  1.1  christos #include <sys/param.h>
     39  1.1  christos #include <sys/systm.h>
     40  1.1  christos #include <sys/filedesc.h>
     41  1.1  christos #include <sys/kernel.h>
     42  1.1  christos #include <sys/vnode.h>
     43  1.1  christos #include <sys/proc.h>
     44  1.1  christos #include <sys/file.h>
     45  1.1  christos #include <sys/socket.h>
     46  1.1  christos #include <sys/socketvar.h>
     47  1.1  christos #include <sys/stat.h>
     48  1.1  christos #include <sys/ioctl.h>
     49  1.1  christos #include <sys/fcntl.h>
     50  1.1  christos #include <sys/malloc.h>
     51  1.1  christos #include <sys/syslog.h>
     52  1.1  christos #include <sys/unistd.h>
     53  1.1  christos #include <sys/resourcevar.h>
     54  1.1  christos #include <vm/vm.h>
     55  1.1  christos #include <sys/sysctl.h>
     56  1.1  christos 
     57  1.1  christos #include <sys/mount.h>
     58  1.1  christos #include <sys/syscallargs.h>
     59  1.1  christos 
     60  1.1  christos int
     61  1.3   mycroft compat_43_sys_getdtablesize(p, v, retval)
     62  1.1  christos 	struct proc *p;
     63  1.3   mycroft 	void *v;
     64  1.1  christos 	register_t *retval;
     65  1.1  christos {
     66  1.1  christos 
     67  1.1  christos 	*retval = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfiles);
     68  1.1  christos 	return (0);
     69  1.1  christos }
     70  1.1  christos 
     71  1.1  christos 
     72  1.1  christos /* ARGSUSED */
     73  1.1  christos int
     74  1.3   mycroft compat_43_sys_gethostid(p, v, retval)
     75  1.1  christos 	struct proc *p;
     76  1.3   mycroft 	void *v;
     77  1.1  christos 	register_t *retval;
     78  1.1  christos {
     79  1.1  christos 
     80  1.1  christos 	*(int32_t *)retval = hostid;
     81  1.1  christos 	return (0);
     82  1.1  christos }
     83  1.1  christos 
     84  1.1  christos 
     85  1.1  christos /*ARGSUSED*/
     86  1.1  christos int
     87  1.3   mycroft compat_43_sys_gethostname(p, v, retval)
     88  1.1  christos 	struct proc *p;
     89  1.2   thorpej 	void *v;
     90  1.2   thorpej 	register_t *retval;
     91  1.2   thorpej {
     92  1.3   mycroft 	struct compat_43_sys_gethostname_args /* {
     93  1.1  christos 		syscallarg(char *) hostname;
     94  1.1  christos 		syscallarg(u_int) len;
     95  1.2   thorpej 	} */ *uap = v;
     96  1.1  christos 	int name;
     97  1.1  christos 
     98  1.1  christos 	name = KERN_HOSTNAME;
     99  1.1  christos 	return (kern_sysctl(&name, 1, SCARG(uap, hostname), &SCARG(uap, len),
    100  1.1  christos 	    0, 0));
    101  1.1  christos }
    102  1.1  christos 
    103  1.1  christos #define	KINFO_PROC		(0<<8)
    104  1.1  christos #define	KINFO_RT		(1<<8)
    105  1.1  christos #define	KINFO_VNODE		(2<<8)
    106  1.1  christos #define	KINFO_FILE		(3<<8)
    107  1.1  christos #define	KINFO_METER		(4<<8)
    108  1.1  christos #define	KINFO_LOADAVG		(5<<8)
    109  1.1  christos #define	KINFO_CLOCKRATE		(6<<8)
    110  1.1  christos 
    111  1.1  christos int
    112  1.3   mycroft compat_43_sys_getkerninfo(p, v, retval)
    113  1.1  christos 	struct proc *p;
    114  1.2   thorpej 	void *v;
    115  1.2   thorpej 	register_t *retval;
    116  1.2   thorpej {
    117  1.3   mycroft 	register struct compat_43_sys_getkerninfo_args /* {
    118  1.1  christos 		syscallarg(int) op;
    119  1.1  christos 		syscallarg(char *) where;
    120  1.1  christos 		syscallarg(int *) size;
    121  1.1  christos 		syscallarg(int) arg;
    122  1.2   thorpej 	} */ *uap = v;
    123  1.1  christos 	int error, name[5];
    124  1.1  christos 	size_t size;
    125  1.1  christos 
    126  1.1  christos 	if (SCARG(uap, size) && (error = copyin((caddr_t)SCARG(uap, size),
    127  1.1  christos 	    (caddr_t)&size, sizeof(size))))
    128  1.1  christos 		return (error);
    129  1.1  christos 
    130  1.1  christos 	switch (SCARG(uap, op) & 0xff00) {
    131  1.1  christos 
    132  1.1  christos 	case KINFO_RT:
    133  1.1  christos 		name[0] = PF_ROUTE;
    134  1.1  christos 		name[1] = 0;
    135  1.1  christos 		name[2] = (SCARG(uap, op) & 0xff0000) >> 16;
    136  1.1  christos 		name[3] = SCARG(uap, op) & 0xff;
    137  1.1  christos 		name[4] = SCARG(uap, arg);
    138  1.1  christos 		error =
    139  1.1  christos 		    net_sysctl(name, 5, SCARG(uap, where), &size, NULL, 0, p);
    140  1.1  christos 		break;
    141  1.1  christos 
    142  1.1  christos 	case KINFO_VNODE:
    143  1.1  christos 		name[0] = KERN_VNODE;
    144  1.1  christos 		error =
    145  1.1  christos 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    146  1.1  christos 		break;
    147  1.1  christos 
    148  1.1  christos 	case KINFO_PROC:
    149  1.1  christos 		name[0] = KERN_PROC;
    150  1.1  christos 		name[1] = SCARG(uap, op) & 0xff;
    151  1.1  christos 		name[2] = SCARG(uap, arg);
    152  1.1  christos 		error =
    153  1.1  christos 		    kern_sysctl(name, 3, SCARG(uap, where), &size, NULL, 0, p);
    154  1.1  christos 		break;
    155  1.1  christos 
    156  1.1  christos 	case KINFO_FILE:
    157  1.1  christos 		name[0] = KERN_FILE;
    158  1.1  christos 		error =
    159  1.1  christos 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    160  1.1  christos 		break;
    161  1.1  christos 
    162  1.1  christos 	case KINFO_METER:
    163  1.1  christos 		name[0] = VM_METER;
    164  1.1  christos 		error =
    165  1.1  christos 		    vm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    166  1.1  christos 		break;
    167  1.1  christos 
    168  1.1  christos 	case KINFO_LOADAVG:
    169  1.1  christos 		name[0] = VM_LOADAVG;
    170  1.1  christos 		error =
    171  1.1  christos 		    vm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    172  1.1  christos 		break;
    173  1.1  christos 
    174  1.1  christos 	case KINFO_CLOCKRATE:
    175  1.1  christos 		name[0] = KERN_CLOCKRATE;
    176  1.1  christos 		error =
    177  1.1  christos 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    178  1.1  christos 		break;
    179  1.1  christos 
    180  1.1  christos 	default:
    181  1.1  christos 		return (EOPNOTSUPP);
    182  1.1  christos 	}
    183  1.1  christos 	if (error)
    184  1.1  christos 		return (error);
    185  1.1  christos 	*retval = size;
    186  1.1  christos 	if (SCARG(uap, size))
    187  1.1  christos 		error = copyout((caddr_t)&size, (caddr_t)SCARG(uap, size),
    188  1.1  christos 		    sizeof(size));
    189  1.1  christos 	return (error);
    190  1.1  christos }
    191  1.1  christos 
    192  1.1  christos 
    193  1.1  christos /* ARGSUSED */
    194  1.1  christos int
    195  1.3   mycroft compat_43_sys_sethostid(p, v, retval)
    196  1.1  christos 	struct proc *p;
    197  1.2   thorpej 	void *v;
    198  1.2   thorpej 	register_t *retval;
    199  1.2   thorpej {
    200  1.3   mycroft 	struct compat_43_sys_sethostid_args /* {
    201  1.1  christos 		syscallarg(int32_t) hostid;
    202  1.2   thorpej 	} */ *uap = v;
    203  1.1  christos 	int error;
    204  1.1  christos 
    205  1.1  christos 	if (error = suser(p->p_ucred, &p->p_acflag))
    206  1.1  christos 		return (error);
    207  1.1  christos 	hostid = SCARG(uap, hostid);
    208  1.1  christos 	return (0);
    209  1.1  christos }
    210  1.1  christos 
    211  1.1  christos 
    212  1.1  christos /* ARGSUSED */
    213  1.1  christos int
    214  1.3   mycroft compat_43_sys_sethostname(p, v, retval)
    215  1.1  christos 	struct proc *p;
    216  1.2   thorpej 	void *v;
    217  1.1  christos 	register_t *retval;
    218  1.1  christos {
    219  1.3   mycroft 	struct compat_43_sys_sethostname_args *uap = v;
    220  1.1  christos 	int name;
    221  1.1  christos 	int error;
    222  1.1  christos 
    223  1.1  christos 	if (error = suser(p->p_ucred, &p->p_acflag))
    224  1.1  christos 		return (error);
    225  1.1  christos 	name = KERN_HOSTNAME;
    226  1.1  christos 	return (kern_sysctl(&name, 1, 0, 0, SCARG(uap, hostname),
    227  1.1  christos 	    SCARG(uap, len)));
    228  1.1  christos }
    229