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