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