Home | History | Annotate | Line # | Download | only in common
kern_info_43.c revision 1.7
      1  1.7       mrg /*	$NetBSD: kern_info_43.c,v 1.7 1998/02/05 07:59:28 mrg 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.7       mrg #if defined(UVM)
     58  1.7       mrg #include <uvm/uvm_extern.h>
     59  1.7       mrg #endif
     60  1.7       mrg 
     61  1.1  christos #include <sys/mount.h>
     62  1.1  christos #include <sys/syscallargs.h>
     63  1.1  christos 
     64  1.1  christos int
     65  1.3   mycroft compat_43_sys_getdtablesize(p, v, retval)
     66  1.1  christos 	struct proc *p;
     67  1.3   mycroft 	void *v;
     68  1.1  christos 	register_t *retval;
     69  1.1  christos {
     70  1.1  christos 
     71  1.1  christos 	*retval = min((int)p->p_rlimit[RLIMIT_NOFILE].rlim_cur, maxfiles);
     72  1.1  christos 	return (0);
     73  1.1  christos }
     74  1.1  christos 
     75  1.1  christos 
     76  1.1  christos /* ARGSUSED */
     77  1.1  christos int
     78  1.3   mycroft compat_43_sys_gethostid(p, v, retval)
     79  1.1  christos 	struct proc *p;
     80  1.3   mycroft 	void *v;
     81  1.1  christos 	register_t *retval;
     82  1.1  christos {
     83  1.1  christos 
     84  1.1  christos 	*(int32_t *)retval = hostid;
     85  1.1  christos 	return (0);
     86  1.1  christos }
     87  1.1  christos 
     88  1.1  christos 
     89  1.1  christos /*ARGSUSED*/
     90  1.1  christos int
     91  1.3   mycroft compat_43_sys_gethostname(p, v, retval)
     92  1.1  christos 	struct proc *p;
     93  1.2   thorpej 	void *v;
     94  1.2   thorpej 	register_t *retval;
     95  1.2   thorpej {
     96  1.3   mycroft 	struct compat_43_sys_gethostname_args /* {
     97  1.1  christos 		syscallarg(char *) hostname;
     98  1.1  christos 		syscallarg(u_int) len;
     99  1.2   thorpej 	} */ *uap = v;
    100  1.1  christos 	int name;
    101  1.5       cgd 	size_t sz;
    102  1.1  christos 
    103  1.1  christos 	name = KERN_HOSTNAME;
    104  1.5       cgd 	sz = SCARG(uap, len);
    105  1.5       cgd 	return (kern_sysctl(&name, 1, SCARG(uap, hostname), &sz, 0, 0, p));
    106  1.1  christos }
    107  1.1  christos 
    108  1.1  christos #define	KINFO_PROC		(0<<8)
    109  1.1  christos #define	KINFO_RT		(1<<8)
    110  1.1  christos #define	KINFO_VNODE		(2<<8)
    111  1.1  christos #define	KINFO_FILE		(3<<8)
    112  1.1  christos #define	KINFO_METER		(4<<8)
    113  1.1  christos #define	KINFO_LOADAVG		(5<<8)
    114  1.1  christos #define	KINFO_CLOCKRATE		(6<<8)
    115  1.6  christos #define	KINFO_BSDI_SYSINFO	(101<<8)
    116  1.6  christos 
    117  1.6  christos 
    118  1.6  christos /*
    119  1.6  christos  * The string data is appended to the end of the bsdi_si structure during
    120  1.6  christos  * copyout. The "char *" offsets in the bsdi_si struct are relative to the
    121  1.6  christos  * base of the bsdi_si struct.
    122  1.6  christos  */
    123  1.6  christos struct bsdi_si {
    124  1.6  christos         char    *machine;
    125  1.6  christos         char    *cpu_model;
    126  1.6  christos         long    ncpu;
    127  1.6  christos         long    cpuspeed;
    128  1.6  christos         long    hwflags;
    129  1.6  christos         u_long  physmem;
    130  1.6  christos         u_long  usermem;
    131  1.6  christos         u_long  pagesize;
    132  1.6  christos 
    133  1.6  christos         char    *ostype;
    134  1.6  christos         char    *osrelease;
    135  1.6  christos         long    os_revision;
    136  1.6  christos         long    posix1_version;
    137  1.6  christos         char    *version;
    138  1.6  christos 
    139  1.6  christos         long    hz;
    140  1.6  christos         long    profhz;
    141  1.6  christos         int     ngroups_max;
    142  1.6  christos         long    arg_max;
    143  1.6  christos         long    open_max;
    144  1.6  christos         long    child_max;
    145  1.6  christos 
    146  1.6  christos         struct  timeval boottime;
    147  1.6  christos         char    *hostname;
    148  1.6  christos };
    149  1.1  christos 
    150  1.1  christos int
    151  1.3   mycroft compat_43_sys_getkerninfo(p, v, retval)
    152  1.1  christos 	struct proc *p;
    153  1.2   thorpej 	void *v;
    154  1.2   thorpej 	register_t *retval;
    155  1.2   thorpej {
    156  1.3   mycroft 	register struct compat_43_sys_getkerninfo_args /* {
    157  1.1  christos 		syscallarg(int) op;
    158  1.1  christos 		syscallarg(char *) where;
    159  1.1  christos 		syscallarg(int *) size;
    160  1.1  christos 		syscallarg(int) arg;
    161  1.2   thorpej 	} */ *uap = v;
    162  1.1  christos 	int error, name[5];
    163  1.1  christos 	size_t size;
    164  1.1  christos 
    165  1.1  christos 	if (SCARG(uap, size) && (error = copyin((caddr_t)SCARG(uap, size),
    166  1.1  christos 	    (caddr_t)&size, sizeof(size))))
    167  1.1  christos 		return (error);
    168  1.1  christos 
    169  1.1  christos 	switch (SCARG(uap, op) & 0xff00) {
    170  1.1  christos 
    171  1.1  christos 	case KINFO_RT:
    172  1.1  christos 		name[0] = PF_ROUTE;
    173  1.1  christos 		name[1] = 0;
    174  1.1  christos 		name[2] = (SCARG(uap, op) & 0xff0000) >> 16;
    175  1.1  christos 		name[3] = SCARG(uap, op) & 0xff;
    176  1.1  christos 		name[4] = SCARG(uap, arg);
    177  1.1  christos 		error =
    178  1.1  christos 		    net_sysctl(name, 5, SCARG(uap, where), &size, NULL, 0, p);
    179  1.1  christos 		break;
    180  1.1  christos 
    181  1.1  christos 	case KINFO_VNODE:
    182  1.1  christos 		name[0] = KERN_VNODE;
    183  1.1  christos 		error =
    184  1.1  christos 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    185  1.1  christos 		break;
    186  1.1  christos 
    187  1.1  christos 	case KINFO_PROC:
    188  1.1  christos 		name[0] = KERN_PROC;
    189  1.1  christos 		name[1] = SCARG(uap, op) & 0xff;
    190  1.1  christos 		name[2] = SCARG(uap, arg);
    191  1.1  christos 		error =
    192  1.1  christos 		    kern_sysctl(name, 3, SCARG(uap, where), &size, NULL, 0, p);
    193  1.1  christos 		break;
    194  1.1  christos 
    195  1.1  christos 	case KINFO_FILE:
    196  1.1  christos 		name[0] = KERN_FILE;
    197  1.1  christos 		error =
    198  1.1  christos 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    199  1.1  christos 		break;
    200  1.1  christos 
    201  1.1  christos 	case KINFO_METER:
    202  1.1  christos 		name[0] = VM_METER;
    203  1.1  christos 		error =
    204  1.7       mrg #if defined(UVM)
    205  1.7       mrg 		    uvm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    206  1.7       mrg #else
    207  1.1  christos 		    vm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    208  1.7       mrg #endif
    209  1.1  christos 		break;
    210  1.1  christos 
    211  1.1  christos 	case KINFO_LOADAVG:
    212  1.1  christos 		name[0] = VM_LOADAVG;
    213  1.1  christos 		error =
    214  1.7       mrg #if defined(UVM)
    215  1.7       mrg 		    uvm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    216  1.7       mrg #else
    217  1.1  christos 		    vm_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    218  1.7       mrg #endif
    219  1.1  christos 		break;
    220  1.1  christos 
    221  1.1  christos 	case KINFO_CLOCKRATE:
    222  1.1  christos 		name[0] = KERN_CLOCKRATE;
    223  1.1  christos 		error =
    224  1.1  christos 		    kern_sysctl(name, 1, SCARG(uap, where), &size, NULL, 0, p);
    225  1.6  christos 		break;
    226  1.6  christos 
    227  1.6  christos 
    228  1.6  christos 	case KINFO_BSDI_SYSINFO:
    229  1.6  christos 		{
    230  1.6  christos 			size_t len;
    231  1.6  christos 			struct bsdi_si *usi =
    232  1.6  christos 			    (struct bsdi_si *) SCARG(uap, where);
    233  1.6  christos 			struct bsdi_si ksi;
    234  1.6  christos 			char *us = (char *) &usi[1];
    235  1.6  christos 			extern struct timeval boottime;
    236  1.6  christos 			extern char ostype[], osrelease[], machine[],
    237  1.6  christos 			    hostname[], cpu_model[], version[];
    238  1.6  christos 
    239  1.6  christos 			if (usi == NULL) {
    240  1.6  christos 				size = sizeof(ksi) +
    241  1.6  christos 				    strlen(ostype) + strlen(cpu_model) +
    242  1.6  christos 				    strlen(osrelease) + strlen(machine) +
    243  1.6  christos 				    strlen(version) + strlen(hostname) + 6;
    244  1.6  christos 				error = 0;
    245  1.6  christos 				break;
    246  1.6  christos 			}
    247  1.6  christos 
    248  1.6  christos #define COPY(fld)							\
    249  1.6  christos 			ksi.fld = us - (u_long) usi;			\
    250  1.6  christos 			if ((error = copyoutstr(fld, us, 1024, &len)) != 0)\
    251  1.6  christos 				return error;				\
    252  1.6  christos 			us += len
    253  1.6  christos 
    254  1.6  christos 			COPY(machine);
    255  1.6  christos 			COPY(cpu_model);
    256  1.6  christos 			ksi.ncpu = 1;			/* XXX */
    257  1.6  christos 			ksi.cpuspeed = 40;		/* XXX */
    258  1.6  christos 			ksi.hwflags = 0;		/* XXX */
    259  1.6  christos 			ksi.physmem = ctob(physmem);
    260  1.6  christos 			ksi.usermem = ctob(physmem);	/* XXX */
    261  1.6  christos 			ksi.pagesize = PAGE_SIZE;
    262  1.6  christos 
    263  1.6  christos 			COPY(ostype);
    264  1.6  christos 			COPY(osrelease);
    265  1.6  christos 			ksi.os_revision = NetBSD;	/* XXX */
    266  1.6  christos 			ksi.posix1_version = _POSIX_VERSION;
    267  1.6  christos 			COPY(version);			/* XXX */
    268  1.6  christos 
    269  1.6  christos 			ksi.hz = hz;
    270  1.6  christos 			ksi.profhz = profhz;
    271  1.6  christos 			ksi.ngroups_max = NGROUPS_MAX;
    272  1.6  christos 			ksi.arg_max = ARG_MAX;
    273  1.6  christos 			ksi.open_max = OPEN_MAX;
    274  1.6  christos 			ksi.child_max = CHILD_MAX;
    275  1.6  christos 
    276  1.6  christos 			ksi.boottime = boottime;
    277  1.6  christos 			COPY(hostname);
    278  1.6  christos 
    279  1.6  christos 			size = (us - (char *) &usi[1]) + sizeof(ksi);
    280  1.6  christos 
    281  1.6  christos 			if ((error = copyout(&ksi, usi, sizeof(ksi))) != 0)
    282  1.6  christos 				return error;
    283  1.6  christos 		}
    284  1.1  christos 		break;
    285  1.1  christos 
    286  1.1  christos 	default:
    287  1.1  christos 		return (EOPNOTSUPP);
    288  1.1  christos 	}
    289  1.1  christos 	if (error)
    290  1.1  christos 		return (error);
    291  1.1  christos 	*retval = size;
    292  1.1  christos 	if (SCARG(uap, size))
    293  1.1  christos 		error = copyout((caddr_t)&size, (caddr_t)SCARG(uap, size),
    294  1.1  christos 		    sizeof(size));
    295  1.1  christos 	return (error);
    296  1.1  christos }
    297  1.1  christos 
    298  1.1  christos 
    299  1.1  christos /* ARGSUSED */
    300  1.1  christos int
    301  1.3   mycroft compat_43_sys_sethostid(p, v, retval)
    302  1.1  christos 	struct proc *p;
    303  1.2   thorpej 	void *v;
    304  1.2   thorpej 	register_t *retval;
    305  1.2   thorpej {
    306  1.3   mycroft 	struct compat_43_sys_sethostid_args /* {
    307  1.1  christos 		syscallarg(int32_t) hostid;
    308  1.2   thorpej 	} */ *uap = v;
    309  1.1  christos 	int error;
    310  1.1  christos 
    311  1.4  christos 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    312  1.1  christos 		return (error);
    313  1.1  christos 	hostid = SCARG(uap, hostid);
    314  1.1  christos 	return (0);
    315  1.1  christos }
    316  1.1  christos 
    317  1.1  christos 
    318  1.1  christos /* ARGSUSED */
    319  1.1  christos int
    320  1.3   mycroft compat_43_sys_sethostname(p, v, retval)
    321  1.1  christos 	struct proc *p;
    322  1.2   thorpej 	void *v;
    323  1.1  christos 	register_t *retval;
    324  1.1  christos {
    325  1.3   mycroft 	struct compat_43_sys_sethostname_args *uap = v;
    326  1.1  christos 	int name;
    327  1.1  christos 	int error;
    328  1.1  christos 
    329  1.4  christos 	if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
    330  1.1  christos 		return (error);
    331  1.1  christos 	name = KERN_HOSTNAME;
    332  1.1  christos 	return (kern_sysctl(&name, 1, 0, 0, SCARG(uap, hostname),
    333  1.4  christos 			    SCARG(uap, len), p));
    334  1.1  christos }
    335