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