sunos_misc.c revision 1.31 1 1.31 deraadt /* $NetBSD: sunos_misc.c,v 1.31 1994/09/28 00:41:28 deraadt Exp $ */
2 1.30 cgd
3 1.1 deraadt /*
4 1.1 deraadt * Copyright (c) 1992, 1993
5 1.1 deraadt * The Regents of the University of California. All rights reserved.
6 1.1 deraadt *
7 1.1 deraadt * This software was developed by the Computer Systems Engineering group
8 1.1 deraadt * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 1.1 deraadt * contributed to Berkeley.
10 1.1 deraadt *
11 1.1 deraadt * All advertising materials mentioning features or use of this software
12 1.1 deraadt * must display the following acknowledgement:
13 1.1 deraadt * This product includes software developed by the University of
14 1.1 deraadt * California, Lawrence Berkeley Laboratory.
15 1.1 deraadt *
16 1.1 deraadt * Redistribution and use in source and binary forms, with or without
17 1.1 deraadt * modification, are permitted provided that the following conditions
18 1.1 deraadt * are met:
19 1.1 deraadt * 1. Redistributions of source code must retain the above copyright
20 1.1 deraadt * notice, this list of conditions and the following disclaimer.
21 1.1 deraadt * 2. Redistributions in binary form must reproduce the above copyright
22 1.1 deraadt * notice, this list of conditions and the following disclaimer in the
23 1.1 deraadt * documentation and/or other materials provided with the distribution.
24 1.1 deraadt * 3. All advertising materials mentioning features or use of this software
25 1.1 deraadt * must display the following acknowledgement:
26 1.1 deraadt * This product includes software developed by the University of
27 1.1 deraadt * California, Berkeley and its contributors.
28 1.1 deraadt * 4. Neither the name of the University nor the names of its contributors
29 1.1 deraadt * may be used to endorse or promote products derived from this software
30 1.1 deraadt * without specific prior written permission.
31 1.1 deraadt *
32 1.1 deraadt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 1.1 deraadt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 1.1 deraadt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 1.1 deraadt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 1.1 deraadt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 1.1 deraadt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 1.1 deraadt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 1.1 deraadt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 1.1 deraadt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 1.1 deraadt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 1.1 deraadt * SUCH DAMAGE.
43 1.1 deraadt *
44 1.1 deraadt * @(#)sun_misc.c 8.1 (Berkeley) 6/18/93
45 1.1 deraadt *
46 1.30 cgd * Header: sun_misc.c,v 1.16 93/04/07 02:46:27 torek Exp
47 1.1 deraadt */
48 1.1 deraadt
49 1.1 deraadt /*
50 1.1 deraadt * SunOS compatibility module.
51 1.1 deraadt *
52 1.1 deraadt * SunOS system calls that are implemented differently in BSD are
53 1.1 deraadt * handled here.
54 1.1 deraadt */
55 1.1 deraadt
56 1.1 deraadt #include <sys/param.h>
57 1.1 deraadt #include <sys/systm.h>
58 1.10 deraadt #include <sys/namei.h>
59 1.1 deraadt #include <sys/proc.h>
60 1.27 pk #include <sys/dir.h>
61 1.1 deraadt #include <sys/file.h>
62 1.10 deraadt #include <sys/stat.h>
63 1.1 deraadt #include <sys/filedesc.h>
64 1.1 deraadt #include <sys/ioctl.h>
65 1.8 deraadt #include <sys/kernel.h>
66 1.10 deraadt #include <sys/exec.h>
67 1.1 deraadt #include <sys/malloc.h>
68 1.1 deraadt #include <sys/mbuf.h>
69 1.1 deraadt #include <sys/mman.h>
70 1.1 deraadt #include <sys/mount.h>
71 1.1 deraadt #include <sys/resource.h>
72 1.1 deraadt #include <sys/resourcevar.h>
73 1.1 deraadt #include <sys/signal.h>
74 1.1 deraadt #include <sys/signalvar.h>
75 1.1 deraadt #include <sys/socket.h>
76 1.1 deraadt #include <sys/vnode.h>
77 1.1 deraadt #include <sys/uio.h>
78 1.1 deraadt #include <sys/wait.h>
79 1.8 deraadt #include <sys/utsname.h>
80 1.12 deraadt #include <sys/unistd.h>
81 1.1 deraadt
82 1.10 deraadt #include <netinet/in.h>
83 1.10 deraadt
84 1.7 deraadt #include <miscfs/specfs/specdev.h>
85 1.1 deraadt
86 1.27 pk #include <nfs/rpcv2.h>
87 1.27 pk #include <nfs/nfsv2.h>
88 1.27 pk #include <nfs/nfs.h>
89 1.27 pk
90 1.1 deraadt #include <vm/vm.h>
91 1.1 deraadt
92 1.1 deraadt struct sun_wait4_args {
93 1.1 deraadt int pid;
94 1.1 deraadt int *status;
95 1.1 deraadt int options;
96 1.1 deraadt struct rusage *rusage;
97 1.25 deraadt #ifdef COMPAT_43
98 1.25 deraadt int compat; /* pseudo */
99 1.25 deraadt #endif
100 1.1 deraadt };
101 1.1 deraadt sun_wait4(p, uap, retval)
102 1.1 deraadt struct proc *p;
103 1.1 deraadt struct sun_wait4_args *uap;
104 1.1 deraadt int *retval;
105 1.1 deraadt {
106 1.1 deraadt
107 1.1 deraadt if (uap->pid == 0)
108 1.1 deraadt uap->pid = WAIT_ANY;
109 1.1 deraadt return (wait4(p, uap, retval));
110 1.1 deraadt }
111 1.1 deraadt
112 1.1 deraadt struct sun_creat_args {
113 1.1 deraadt char *fname;
114 1.1 deraadt int fmode;
115 1.1 deraadt };
116 1.1 deraadt sun_creat(p, uap, retval)
117 1.1 deraadt struct proc *p;
118 1.1 deraadt struct sun_creat_args *uap;
119 1.1 deraadt int *retval;
120 1.1 deraadt {
121 1.1 deraadt struct args {
122 1.1 deraadt char *fname;
123 1.1 deraadt int mode;
124 1.1 deraadt int crtmode;
125 1.1 deraadt } openuap;
126 1.1 deraadt
127 1.1 deraadt openuap.fname = uap->fname;
128 1.1 deraadt openuap.crtmode = uap->fmode;
129 1.1 deraadt openuap.mode = O_WRONLY | O_CREAT | O_TRUNC;
130 1.1 deraadt return (open(p, &openuap, retval));
131 1.1 deraadt }
132 1.1 deraadt
133 1.1 deraadt struct sun_execv_args {
134 1.1 deraadt char *fname;
135 1.1 deraadt char **argp;
136 1.1 deraadt char **envp; /* pseudo */
137 1.1 deraadt };
138 1.1 deraadt sun_execv(p, uap, retval)
139 1.1 deraadt struct proc *p;
140 1.1 deraadt struct sun_execv_args *uap;
141 1.1 deraadt int *retval;
142 1.1 deraadt {
143 1.1 deraadt
144 1.1 deraadt uap->envp = NULL;
145 1.1 deraadt return (execve(p, uap, retval));
146 1.1 deraadt }
147 1.1 deraadt
148 1.1 deraadt struct sun_omsync_args {
149 1.1 deraadt caddr_t addr;
150 1.1 deraadt int len;
151 1.1 deraadt int flags;
152 1.1 deraadt };
153 1.1 deraadt sun_omsync(p, uap, retval)
154 1.1 deraadt struct proc *p;
155 1.1 deraadt struct sun_omsync_args *uap;
156 1.1 deraadt int *retval;
157 1.1 deraadt {
158 1.1 deraadt
159 1.1 deraadt if (uap->flags)
160 1.1 deraadt return (EINVAL);
161 1.1 deraadt return (msync(p, uap, retval));
162 1.1 deraadt }
163 1.1 deraadt
164 1.1 deraadt struct sun_unmount_args {
165 1.1 deraadt char *name;
166 1.1 deraadt int flags; /* pseudo */
167 1.1 deraadt };
168 1.1 deraadt sun_unmount(p, uap, retval)
169 1.1 deraadt struct proc *p;
170 1.1 deraadt struct sun_unmount_args *uap;
171 1.1 deraadt int *retval;
172 1.1 deraadt {
173 1.1 deraadt
174 1.1 deraadt uap->flags = 0;
175 1.1 deraadt return (unmount(p, uap, retval));
176 1.1 deraadt }
177 1.1 deraadt
178 1.1 deraadt #define SUNM_RDONLY 0x01 /* mount fs read-only */
179 1.1 deraadt #define SUNM_NOSUID 0x02 /* mount fs with setuid disallowed */
180 1.1 deraadt #define SUNM_NEWTYPE 0x04 /* type is string (char *), not int */
181 1.1 deraadt #define SUNM_GRPID 0x08 /* (bsd semantics; ignored) */
182 1.1 deraadt #define SUNM_REMOUNT 0x10 /* update existing mount */
183 1.1 deraadt #define SUNM_NOSUB 0x20 /* prevent submounts (rejected) */
184 1.1 deraadt #define SUNM_MULTI 0x40 /* (ignored) */
185 1.1 deraadt #define SUNM_SYS5 0x80 /* Sys 5-specific semantics (rejected) */
186 1.1 deraadt
187 1.10 deraadt struct sun_nfs_args {
188 1.10 deraadt struct sockaddr_in *addr; /* file server address */
189 1.10 deraadt caddr_t fh; /* file handle to be mounted */
190 1.10 deraadt int flags; /* flags */
191 1.10 deraadt int wsize; /* write size in bytes */
192 1.10 deraadt int rsize; /* read size in bytes */
193 1.10 deraadt int timeo; /* initial timeout in .1 secs */
194 1.10 deraadt int retrans; /* times to retry send */
195 1.10 deraadt char *hostname; /* server's hostname */
196 1.10 deraadt int acregmin; /* attr cache file min secs */
197 1.10 deraadt int acregmax; /* attr cache file max secs */
198 1.10 deraadt int acdirmin; /* attr cache dir min secs */
199 1.10 deraadt int acdirmax; /* attr cache dir max secs */
200 1.10 deraadt char *netname; /* server's netname */
201 1.10 deraadt struct pathcnf *pathconf; /* static pathconf kludge */
202 1.10 deraadt };
203 1.10 deraadt
204 1.1 deraadt struct sun_mount_args {
205 1.16 deraadt char *type;
206 1.1 deraadt char *dir;
207 1.1 deraadt int flags;
208 1.1 deraadt caddr_t data;
209 1.1 deraadt };
210 1.1 deraadt sun_mount(p, uap, retval)
211 1.1 deraadt struct proc *p;
212 1.1 deraadt struct sun_mount_args *uap;
213 1.1 deraadt int *retval;
214 1.1 deraadt {
215 1.1 deraadt int oflags = uap->flags, nflags, error;
216 1.10 deraadt extern char sigcode[], esigcode[];
217 1.16 deraadt char fsname[MFSNAMELEN];
218 1.16 deraadt
219 1.10 deraadt #define szsigcode (esigcode - sigcode)
220 1.1 deraadt
221 1.1 deraadt if (oflags & (SUNM_NOSUB | SUNM_SYS5))
222 1.1 deraadt return (EINVAL);
223 1.16 deraadt if ((oflags & SUNM_NEWTYPE) == 0)
224 1.16 deraadt return (EINVAL);
225 1.1 deraadt nflags = 0;
226 1.1 deraadt if (oflags & SUNM_RDONLY)
227 1.1 deraadt nflags |= MNT_RDONLY;
228 1.1 deraadt if (oflags & SUNM_NOSUID)
229 1.1 deraadt nflags |= MNT_NOSUID;
230 1.1 deraadt if (oflags & SUNM_REMOUNT)
231 1.1 deraadt nflags |= MNT_UPDATE;
232 1.1 deraadt uap->flags = nflags;
233 1.10 deraadt
234 1.16 deraadt if (error = copyinstr((caddr_t)uap->type, fsname, sizeof fsname, (u_int *)0))
235 1.16 deraadt return (error);
236 1.16 deraadt
237 1.16 deraadt if (strcmp(fsname, "4.2") == 0) {
238 1.31 deraadt uap->type = STACKGAPBASE;
239 1.16 deraadt if (error = copyout("ufs", uap->type, sizeof("ufs")))
240 1.16 deraadt return (error);
241 1.16 deraadt } else if (strcmp(fsname, "nfs") == 0) {
242 1.10 deraadt struct sun_nfs_args sna;
243 1.10 deraadt struct sockaddr_in sain;
244 1.10 deraadt struct nfs_args na;
245 1.10 deraadt struct sockaddr sa;
246 1.10 deraadt
247 1.10 deraadt if (error = copyin(uap->data, &sna, sizeof sna))
248 1.10 deraadt return (error);
249 1.10 deraadt if (error = copyin(sna.addr, &sain, sizeof sain))
250 1.10 deraadt return (error);
251 1.10 deraadt bcopy(&sain, &sa, sizeof sa);
252 1.10 deraadt sa.sa_len = sizeof(sain);
253 1.31 deraadt uap->data = STACKGAPBASE;
254 1.10 deraadt na.addr = (struct sockaddr *)((int)uap->data + sizeof na);
255 1.29 pk na.addrlen = sizeof(struct sockaddr);
256 1.10 deraadt na.sotype = SOCK_DGRAM;
257 1.10 deraadt na.proto = IPPROTO_UDP;
258 1.10 deraadt na.fh = (nfsv2fh_t *)sna.fh;
259 1.10 deraadt na.flags = sna.flags;
260 1.10 deraadt na.wsize = sna.wsize;
261 1.10 deraadt na.rsize = sna.rsize;
262 1.10 deraadt na.timeo = sna.timeo;
263 1.10 deraadt na.retrans = sna.retrans;
264 1.10 deraadt na.hostname = sna.hostname;
265 1.10 deraadt
266 1.10 deraadt if (error = copyout(&sa, na.addr, sizeof sa))
267 1.10 deraadt return (error);
268 1.10 deraadt if (error = copyout(&na, uap->data, sizeof na))
269 1.10 deraadt return (error);
270 1.10 deraadt }
271 1.1 deraadt return (mount(p, uap, retval));
272 1.1 deraadt }
273 1.1 deraadt
274 1.28 deraadt #if defined(NFSCLIENT)
275 1.27 pk async_daemon(p, uap, retval)
276 1.27 pk struct proc *p;
277 1.27 pk void *uap;
278 1.27 pk int *retval;
279 1.27 pk {
280 1.27 pk struct nfssvc_args {
281 1.27 pk int flag;
282 1.27 pk caddr_t argp;
283 1.27 pk } args;
284 1.27 pk
285 1.27 pk args.flag = NFSSVC_BIOD;
286 1.27 pk return nfssvc(p, &args, retval);
287 1.27 pk }
288 1.28 deraadt #endif /* NFSCLIENT */
289 1.27 pk
290 1.1 deraadt struct sun_sigpending_args {
291 1.1 deraadt int *mask;
292 1.1 deraadt };
293 1.1 deraadt sun_sigpending(p, uap, retval)
294 1.1 deraadt struct proc *p;
295 1.1 deraadt struct sun_sigpending_args *uap;
296 1.1 deraadt int *retval;
297 1.1 deraadt {
298 1.21 deraadt int mask = p->p_siglist & p->p_sigmask;
299 1.1 deraadt
300 1.1 deraadt return (copyout((caddr_t)&mask, (caddr_t)uap->mask, sizeof(int)));
301 1.1 deraadt }
302 1.1 deraadt
303 1.1 deraadt /*
304 1.1 deraadt * Here is the sun layout. (Compare the BSD layout in <sys/dirent.h>.)
305 1.1 deraadt * We can assume big-endian, so the BSD d_type field is just the high
306 1.1 deraadt * byte of the SunOS d_namlen field, after adjusting for the extra "long".
307 1.1 deraadt */
308 1.1 deraadt struct sun_dirent {
309 1.1 deraadt long d_off;
310 1.1 deraadt u_long d_fileno;
311 1.1 deraadt u_short d_reclen;
312 1.1 deraadt u_short d_namlen;
313 1.1 deraadt char d_name[256];
314 1.1 deraadt };
315 1.1 deraadt
316 1.1 deraadt /*
317 1.1 deraadt * Read Sun-style directory entries. We suck them into kernel space so
318 1.1 deraadt * that they can be massaged before being copied out to user code. Like
319 1.1 deraadt * SunOS, we squish out `empty' entries.
320 1.1 deraadt *
321 1.1 deraadt * This is quite ugly, but what do you expect from compatibility code?
322 1.1 deraadt */
323 1.1 deraadt struct sun_getdents_args {
324 1.1 deraadt int fd;
325 1.1 deraadt char *buf;
326 1.1 deraadt int nbytes;
327 1.1 deraadt };
328 1.1 deraadt sun_getdents(p, uap, retval)
329 1.1 deraadt struct proc *p;
330 1.1 deraadt register struct sun_getdents_args *uap;
331 1.1 deraadt int *retval;
332 1.1 deraadt {
333 1.1 deraadt register struct vnode *vp;
334 1.1 deraadt register caddr_t inp, buf; /* BSD-format */
335 1.1 deraadt register int len, reclen; /* BSD-format */
336 1.1 deraadt register caddr_t outp; /* Sun-format */
337 1.1 deraadt register int resid; /* Sun-format */
338 1.1 deraadt struct file *fp;
339 1.1 deraadt struct uio auio;
340 1.1 deraadt struct iovec aiov;
341 1.1 deraadt off_t off; /* true file offset */
342 1.1 deraadt long soff; /* Sun file offset */
343 1.1 deraadt int buflen, error, eofflag;
344 1.1 deraadt #define BSD_DIRENT(cp) ((struct dirent *)(cp))
345 1.1 deraadt #define SUN_RECLEN(reclen) (reclen + sizeof(long))
346 1.1 deraadt
347 1.1 deraadt if ((error = getvnode(p->p_fd, uap->fd, &fp)) != 0)
348 1.1 deraadt return (error);
349 1.1 deraadt if ((fp->f_flag & FREAD) == 0)
350 1.1 deraadt return (EBADF);
351 1.1 deraadt vp = (struct vnode *)fp->f_data;
352 1.1 deraadt if (vp->v_type != VDIR) /* XXX vnode readdir op should do this */
353 1.1 deraadt return (EINVAL);
354 1.1 deraadt buflen = min(MAXBSIZE, uap->nbytes);
355 1.1 deraadt buf = malloc(buflen, M_TEMP, M_WAITOK);
356 1.1 deraadt VOP_LOCK(vp);
357 1.1 deraadt off = fp->f_offset;
358 1.1 deraadt again:
359 1.1 deraadt aiov.iov_base = buf;
360 1.1 deraadt aiov.iov_len = buflen;
361 1.1 deraadt auio.uio_iov = &aiov;
362 1.1 deraadt auio.uio_iovcnt = 1;
363 1.1 deraadt auio.uio_rw = UIO_READ;
364 1.1 deraadt auio.uio_segflg = UIO_SYSSPACE;
365 1.1 deraadt auio.uio_procp = p;
366 1.1 deraadt auio.uio_resid = buflen;
367 1.1 deraadt auio.uio_offset = off;
368 1.1 deraadt /*
369 1.1 deraadt * First we read into the malloc'ed buffer, then
370 1.1 deraadt * we massage it into user space, one record at a time.
371 1.1 deraadt */
372 1.26 mycroft if (error = VOP_READDIR(vp, &auio, fp->f_cred, &eofflag, (u_long *)0,
373 1.26 mycroft 0))
374 1.1 deraadt goto out;
375 1.1 deraadt inp = buf;
376 1.1 deraadt outp = uap->buf;
377 1.1 deraadt resid = uap->nbytes;
378 1.1 deraadt if ((len = buflen - auio.uio_resid) == 0)
379 1.1 deraadt goto eof;
380 1.1 deraadt for (; len > 0; len -= reclen) {
381 1.1 deraadt reclen = ((struct dirent *)inp)->d_reclen;
382 1.1 deraadt if (reclen & 3)
383 1.1 deraadt panic("sun_getdents");
384 1.1 deraadt off += reclen; /* each entry points to next */
385 1.1 deraadt if (BSD_DIRENT(inp)->d_fileno == 0) {
386 1.1 deraadt inp += reclen; /* it is a hole; squish it out */
387 1.1 deraadt continue;
388 1.1 deraadt }
389 1.1 deraadt if (reclen > len || resid < SUN_RECLEN(reclen)) {
390 1.1 deraadt /* entry too big for buffer, so just stop */
391 1.1 deraadt outp++;
392 1.1 deraadt break;
393 1.1 deraadt }
394 1.1 deraadt /*
395 1.1 deraadt * Massage in place to make a Sun-shaped dirent (otherwise
396 1.1 deraadt * we have to worry about touching user memory outside of
397 1.1 deraadt * the copyout() call).
398 1.1 deraadt */
399 1.1 deraadt BSD_DIRENT(inp)->d_reclen = SUN_RECLEN(reclen);
400 1.4 deraadt #if notdef
401 1.4 deraadt BSD_DIRENT(inp)->d_type = 0; /* 4.4 specific */
402 1.4 deraadt #endif
403 1.1 deraadt soff = off;
404 1.1 deraadt if ((error = copyout((caddr_t)&soff, outp, sizeof soff)) != 0 ||
405 1.1 deraadt (error = copyout(inp, outp + sizeof soff, reclen)) != 0)
406 1.1 deraadt goto out;
407 1.1 deraadt /* advance past this real entry */
408 1.1 deraadt inp += reclen;
409 1.1 deraadt /* advance output past Sun-shaped entry */
410 1.1 deraadt outp += SUN_RECLEN(reclen);
411 1.1 deraadt resid -= SUN_RECLEN(reclen);
412 1.1 deraadt }
413 1.1 deraadt /* if we squished out the whole block, try again */
414 1.1 deraadt if (outp == uap->buf)
415 1.1 deraadt goto again;
416 1.1 deraadt fp->f_offset = off; /* update the vnode offset */
417 1.1 deraadt eof:
418 1.1 deraadt *retval = uap->nbytes - resid;
419 1.1 deraadt out:
420 1.1 deraadt VOP_UNLOCK(vp);
421 1.1 deraadt free(buf, M_TEMP);
422 1.1 deraadt return (error);
423 1.1 deraadt }
424 1.1 deraadt
425 1.4 deraadt #define SUN__MAP_NEW 0x80000000 /* if not, old mmap & cannot handle */
426 1.4 deraadt
427 1.1 deraadt struct sun_mmap_args {
428 1.1 deraadt caddr_t addr;
429 1.1 deraadt size_t len;
430 1.1 deraadt int prot;
431 1.1 deraadt int flags;
432 1.1 deraadt int fd;
433 1.15 cgd long off; /* not off_t! */
434 1.15 cgd off_t qoff; /* created here and fed to mmap() */
435 1.1 deraadt };
436 1.1 deraadt sun_mmap(p, uap, retval)
437 1.1 deraadt register struct proc *p;
438 1.1 deraadt register struct sun_mmap_args *uap;
439 1.1 deraadt int *retval;
440 1.1 deraadt {
441 1.1 deraadt register struct filedesc *fdp;
442 1.1 deraadt register struct file *fp;
443 1.1 deraadt register struct vnode *vp;
444 1.1 deraadt
445 1.1 deraadt /*
446 1.14 cgd * Verify the arguments.
447 1.1 deraadt */
448 1.14 cgd if (uap->prot & ~(PROT_READ|PROT_WRITE|PROT_EXEC))
449 1.14 cgd return (EINVAL); /* XXX still needed? */
450 1.4 deraadt
451 1.14 cgd if ((uap->flags & SUN__MAP_NEW) == 0)
452 1.1 deraadt return (EINVAL);
453 1.14 cgd uap->flags &= ~SUN__MAP_NEW;
454 1.1 deraadt
455 1.14 cgd if ((uap->flags & MAP_FIXED) == 0 &&
456 1.10 deraadt uap->addr != 0 &&
457 1.14 cgd uap->addr < (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ))
458 1.14 cgd uap->addr = (caddr_t)round_page(p->p_vmspace->vm_daddr+MAXDSIZ);
459 1.10 deraadt
460 1.1 deraadt /*
461 1.1 deraadt * Special case: if fd refers to /dev/zero, map as MAP_ANON. (XXX)
462 1.1 deraadt */
463 1.1 deraadt fdp = p->p_fd;
464 1.1 deraadt if ((unsigned)uap->fd < fdp->fd_nfiles && /*XXX*/
465 1.1 deraadt (fp = fdp->fd_ofiles[uap->fd]) != NULL && /*XXX*/
466 1.1 deraadt fp->f_type == DTYPE_VNODE && /*XXX*/
467 1.1 deraadt (vp = (struct vnode *)fp->f_data)->v_type == VCHR && /*XXX*/
468 1.23 deraadt iszerodev(vp->v_rdev)) { /*XXX*/
469 1.14 cgd uap->flags |= MAP_ANON;
470 1.1 deraadt uap->fd = -1;
471 1.14 cgd }
472 1.4 deraadt
473 1.15 cgd uap->qoff = uap->off;
474 1.18 cgd return (mmap(p, uap, retval));
475 1.1 deraadt }
476 1.1 deraadt
477 1.1 deraadt #define MC_SYNC 1
478 1.1 deraadt #define MC_LOCK 2
479 1.1 deraadt #define MC_UNLOCK 3
480 1.1 deraadt #define MC_ADVISE 4
481 1.1 deraadt #define MC_LOCKAS 5
482 1.1 deraadt #define MC_UNLOCKAS 6
483 1.1 deraadt
484 1.1 deraadt struct sun_mctl_args {
485 1.1 deraadt caddr_t addr;
486 1.1 deraadt size_t len;
487 1.1 deraadt int func;
488 1.1 deraadt void *arg;
489 1.1 deraadt };
490 1.1 deraadt sun_mctl(p, uap, retval)
491 1.1 deraadt register struct proc *p;
492 1.1 deraadt register struct sun_mctl_args *uap;
493 1.1 deraadt int *retval;
494 1.1 deraadt {
495 1.1 deraadt
496 1.1 deraadt switch (uap->func) {
497 1.1 deraadt
498 1.1 deraadt case MC_ADVISE: /* ignore for now */
499 1.1 deraadt return (0);
500 1.1 deraadt
501 1.1 deraadt case MC_SYNC: /* translate to msync */
502 1.1 deraadt return (msync(p, uap, retval));
503 1.1 deraadt
504 1.1 deraadt default:
505 1.1 deraadt return (EINVAL);
506 1.1 deraadt }
507 1.1 deraadt }
508 1.1 deraadt
509 1.1 deraadt struct sun_setsockopt_args {
510 1.1 deraadt int s;
511 1.1 deraadt int level;
512 1.1 deraadt int name;
513 1.1 deraadt caddr_t val;
514 1.1 deraadt int valsize;
515 1.1 deraadt };
516 1.1 deraadt sun_setsockopt(p, uap, retval)
517 1.1 deraadt struct proc *p;
518 1.1 deraadt register struct sun_setsockopt_args *uap;
519 1.1 deraadt int *retval;
520 1.1 deraadt {
521 1.1 deraadt struct file *fp;
522 1.1 deraadt struct mbuf *m = NULL;
523 1.1 deraadt int error;
524 1.1 deraadt
525 1.1 deraadt if (error = getsock(p->p_fd, uap->s, &fp))
526 1.1 deraadt return (error);
527 1.1 deraadt #define SO_DONTLINGER (~SO_LINGER)
528 1.1 deraadt if (uap->name == SO_DONTLINGER) {
529 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
530 1.1 deraadt if (m == NULL)
531 1.1 deraadt return (ENOBUFS);
532 1.1 deraadt mtod(m, struct linger *)->l_onoff = 0;
533 1.1 deraadt m->m_len = sizeof(struct linger);
534 1.1 deraadt return (sosetopt((struct socket *)fp->f_data, uap->level,
535 1.1 deraadt SO_LINGER, m));
536 1.1 deraadt }
537 1.1 deraadt if (uap->valsize > MLEN)
538 1.1 deraadt return (EINVAL);
539 1.1 deraadt if (uap->val) {
540 1.1 deraadt m = m_get(M_WAIT, MT_SOOPTS);
541 1.1 deraadt if (m == NULL)
542 1.1 deraadt return (ENOBUFS);
543 1.1 deraadt if (error = copyin(uap->val, mtod(m, caddr_t),
544 1.1 deraadt (u_int)uap->valsize)) {
545 1.1 deraadt (void) m_free(m);
546 1.1 deraadt return (error);
547 1.1 deraadt }
548 1.1 deraadt m->m_len = uap->valsize;
549 1.1 deraadt }
550 1.1 deraadt return (sosetopt((struct socket *)fp->f_data, uap->level,
551 1.1 deraadt uap->name, m));
552 1.1 deraadt }
553 1.1 deraadt
554 1.1 deraadt struct sun_fchroot_args {
555 1.1 deraadt int fdes;
556 1.1 deraadt };
557 1.1 deraadt sun_fchroot(p, uap, retval)
558 1.1 deraadt register struct proc *p;
559 1.1 deraadt register struct sun_fchroot_args *uap;
560 1.1 deraadt int *retval;
561 1.1 deraadt {
562 1.1 deraadt register struct filedesc *fdp = p->p_fd;
563 1.1 deraadt register struct vnode *vp;
564 1.1 deraadt struct file *fp;
565 1.1 deraadt int error;
566 1.1 deraadt
567 1.1 deraadt if ((error = suser(p->p_ucred, &p->p_acflag)) != 0)
568 1.1 deraadt return (error);
569 1.1 deraadt if ((error = getvnode(fdp, uap->fdes, &fp)) != 0)
570 1.1 deraadt return (error);
571 1.1 deraadt vp = (struct vnode *)fp->f_data;
572 1.1 deraadt VOP_LOCK(vp);
573 1.1 deraadt if (vp->v_type != VDIR)
574 1.1 deraadt error = ENOTDIR;
575 1.1 deraadt else
576 1.1 deraadt error = VOP_ACCESS(vp, VEXEC, p->p_ucred, p);
577 1.1 deraadt VOP_UNLOCK(vp);
578 1.1 deraadt if (error)
579 1.1 deraadt return (error);
580 1.1 deraadt VREF(vp);
581 1.1 deraadt if (fdp->fd_rdir != NULL)
582 1.1 deraadt vrele(fdp->fd_rdir);
583 1.1 deraadt fdp->fd_rdir = vp;
584 1.1 deraadt return (0);
585 1.3 deraadt }
586 1.3 deraadt
587 1.3 deraadt /*
588 1.3 deraadt * XXX: This needs cleaning up.
589 1.3 deraadt */
590 1.8 deraadt sun_auditsys(...)
591 1.3 deraadt {
592 1.3 deraadt return 0;
593 1.8 deraadt }
594 1.8 deraadt
595 1.8 deraadt struct sun_utsname {
596 1.8 deraadt char sysname[9];
597 1.8 deraadt char nodename[9];
598 1.8 deraadt char nodeext[65-9];
599 1.8 deraadt char release[9];
600 1.8 deraadt char version[9];
601 1.8 deraadt char machine[9];
602 1.8 deraadt };
603 1.8 deraadt
604 1.8 deraadt struct sun_uname_args {
605 1.8 deraadt struct sun_utsname *name;
606 1.8 deraadt };
607 1.8 deraadt sun_uname(p, uap, retval)
608 1.8 deraadt struct proc *p;
609 1.8 deraadt struct sun_uname_args *uap;
610 1.8 deraadt int *retval;
611 1.8 deraadt {
612 1.8 deraadt struct sun_utsname sut;
613 1.22 deraadt extern char ostype[], machine[], osrelease[];
614 1.8 deraadt
615 1.22 deraadt bzero(&sut, sizeof(sut));
616 1.8 deraadt
617 1.22 deraadt bcopy(ostype, sut.sysname, sizeof(sut.sysname) - 1);
618 1.22 deraadt bcopy(hostname, sut.nodename, sizeof(sut.nodename));
619 1.22 deraadt sut.nodename[sizeof(sut.nodename)-1] = '\0';
620 1.22 deraadt bcopy(osrelease, sut.release, sizeof(sut.release) - 1);
621 1.22 deraadt bcopy("1", sut.version, sizeof(sut.version) - 1);
622 1.22 deraadt bcopy(machine, sut.machine, sizeof(sut.machine) - 1);
623 1.8 deraadt
624 1.8 deraadt return copyout((caddr_t)&sut, (caddr_t)uap->name, sizeof(struct sun_utsname));
625 1.8 deraadt }
626 1.8 deraadt
627 1.8 deraadt struct sun_setpgid_args {
628 1.8 deraadt int pid; /* target process id */
629 1.8 deraadt int pgid; /* target pgrp id */
630 1.8 deraadt };
631 1.8 deraadt int
632 1.8 deraadt sun_setpgid(p, uap, retval)
633 1.8 deraadt struct proc *p;
634 1.8 deraadt struct sun_setpgid_args *uap;
635 1.8 deraadt int *retval;
636 1.8 deraadt {
637 1.8 deraadt /*
638 1.8 deraadt * difference to our setpgid call is to include backwards
639 1.8 deraadt * compatibility to pre-setsid() binaries. Do setsid()
640 1.8 deraadt * instead of setpgid() in those cases where the process
641 1.8 deraadt * tries to create a new session the old way.
642 1.8 deraadt */
643 1.8 deraadt if (!uap->pgid && (!uap->pid || uap->pid == p->p_pid))
644 1.8 deraadt return setsid(p, uap, retval);
645 1.8 deraadt else
646 1.8 deraadt return setpgid(p, uap, retval);
647 1.8 deraadt }
648 1.8 deraadt
649 1.8 deraadt struct sun_open_args {
650 1.8 deraadt char *fname;
651 1.8 deraadt int fmode;
652 1.8 deraadt int crtmode;
653 1.8 deraadt };
654 1.8 deraadt sun_open(p, uap, retval)
655 1.8 deraadt struct proc *p;
656 1.8 deraadt struct sun_open_args *uap;
657 1.8 deraadt int *retval;
658 1.8 deraadt {
659 1.8 deraadt int l, r;
660 1.8 deraadt int noctty = uap->fmode & 0x8000;
661 1.8 deraadt int ret;
662 1.8 deraadt
663 1.8 deraadt /* convert mode into NetBSD mode */
664 1.8 deraadt l = uap->fmode;
665 1.8 deraadt r = (l & (0x0001 | 0x0002 | 0x0008 | 0x0040 | 0x0200 | 0x0400 | 0x0800));
666 1.8 deraadt r |= ((l & (0x0004 | 0x1000 | 0x4000)) ? O_NONBLOCK : 0);
667 1.8 deraadt r |= ((l & 0x0080) ? O_SHLOCK : 0);
668 1.8 deraadt r |= ((l & 0x0100) ? O_EXLOCK : 0);
669 1.8 deraadt r |= ((l & 0x2000) ? O_FSYNC : 0);
670 1.8 deraadt
671 1.8 deraadt uap->fmode = r;
672 1.8 deraadt ret = open(p, uap, retval);
673 1.8 deraadt
674 1.20 cgd if (!ret && !noctty && SESS_LEADER(p) && !(p->p_flag & P_CONTROLT)) {
675 1.8 deraadt struct filedesc *fdp = p->p_fd;
676 1.8 deraadt struct file *fp = fdp->fd_ofiles[*retval];
677 1.8 deraadt
678 1.8 deraadt /* ignore any error, just give it a try */
679 1.8 deraadt if (fp->f_type == DTYPE_VNODE)
680 1.8 deraadt (fp->f_ops->fo_ioctl)(fp, TIOCSCTTY, (caddr_t) 0, p);
681 1.8 deraadt }
682 1.8 deraadt return ret;
683 1.10 deraadt }
684 1.10 deraadt
685 1.11 chopps #if defined (NFSSERVER)
686 1.10 deraadt struct nfssvc_args {
687 1.10 deraadt int fd;
688 1.10 deraadt caddr_t mskval;
689 1.10 deraadt int msklen;
690 1.10 deraadt caddr_t mtchval;
691 1.10 deraadt int mtchlen;
692 1.10 deraadt };
693 1.10 deraadt struct sun_nfssvc_args {
694 1.10 deraadt int fd;
695 1.10 deraadt };
696 1.10 deraadt sun_nfssvc(p, uap, retval)
697 1.10 deraadt struct proc *p;
698 1.10 deraadt struct sun_nfssvc_args *uap;
699 1.10 deraadt int *retval;
700 1.10 deraadt {
701 1.10 deraadt struct nfssvc_args outuap;
702 1.10 deraadt struct sockaddr sa;
703 1.10 deraadt int error;
704 1.10 deraadt extern char sigcode[], esigcode[];
705 1.10 deraadt
706 1.10 deraadt bzero(&outuap, sizeof outuap);
707 1.10 deraadt outuap.fd = uap->fd;
708 1.31 deraadt outuap.mskval = STACKGAPBASE;
709 1.10 deraadt outuap.msklen = sizeof sa;
710 1.10 deraadt outuap.mtchval = outuap.mskval + sizeof sa;
711 1.10 deraadt outuap.mtchlen = sizeof sa;
712 1.10 deraadt
713 1.10 deraadt bzero(&sa, sizeof sa);
714 1.10 deraadt if (error = copyout(&sa, outuap.mskval, outuap.msklen))
715 1.10 deraadt return (error);
716 1.10 deraadt if (error = copyout(&sa, outuap.mtchval, outuap.mtchlen))
717 1.10 deraadt return (error);
718 1.10 deraadt
719 1.10 deraadt return nfssvc(p, &outuap, retval);
720 1.10 deraadt }
721 1.11 chopps #endif /* NFSSERVER */
722 1.10 deraadt
723 1.10 deraadt struct sun_ustat {
724 1.10 deraadt daddr_t f_tfree; /* total free */
725 1.10 deraadt ino_t f_tinode; /* total inodes free */
726 1.10 deraadt char f_fname[6]; /* filsys name */
727 1.10 deraadt char f_fpack[6]; /* filsys pack name */
728 1.10 deraadt };
729 1.10 deraadt struct sun_ustat_args {
730 1.10 deraadt int dev;
731 1.10 deraadt struct sun_ustat *buf;
732 1.10 deraadt };
733 1.10 deraadt sun_ustat(p, uap, retval)
734 1.10 deraadt struct proc *p;
735 1.10 deraadt struct sun_ustat_args *uap;
736 1.10 deraadt int *retval;
737 1.10 deraadt {
738 1.10 deraadt struct sun_ustat us;
739 1.10 deraadt int error;
740 1.10 deraadt
741 1.10 deraadt bzero(&us, sizeof us);
742 1.10 deraadt
743 1.10 deraadt /*
744 1.10 deraadt * XXX: should set f_tfree and f_tinode at least
745 1.10 deraadt * How do we translate dev -> fstat? (and then to sun_ustat)
746 1.10 deraadt */
747 1.10 deraadt
748 1.10 deraadt if (error = copyout(&us, uap->buf, sizeof us))
749 1.10 deraadt return (error);
750 1.10 deraadt return 0;
751 1.10 deraadt }
752 1.10 deraadt
753 1.10 deraadt struct sun_quotactl_args {
754 1.10 deraadt int cmd;
755 1.10 deraadt char *special;
756 1.10 deraadt int uid;
757 1.10 deraadt caddr_t addr;
758 1.10 deraadt };
759 1.10 deraadt sun_quotactl(p, uap, retval)
760 1.10 deraadt struct proc *p;
761 1.10 deraadt struct sun_quotactl_args *uap;
762 1.10 deraadt int *retval;
763 1.10 deraadt {
764 1.10 deraadt return EINVAL;
765 1.10 deraadt }
766 1.10 deraadt
767 1.10 deraadt sun_vhangup(p, uap, retval)
768 1.10 deraadt struct proc *p;
769 1.10 deraadt void *uap;
770 1.10 deraadt int *retval;
771 1.10 deraadt {
772 1.10 deraadt return 0;
773 1.10 deraadt }
774 1.10 deraadt
775 1.10 deraadt struct sun_statfs {
776 1.10 deraadt long f_type; /* type of info, zero for now */
777 1.10 deraadt long f_bsize; /* fundamental file system block size */
778 1.10 deraadt long f_blocks; /* total blocks in file system */
779 1.10 deraadt long f_bfree; /* free blocks */
780 1.10 deraadt long f_bavail; /* free blocks available to non-super-user */
781 1.10 deraadt long f_files; /* total file nodes in file system */
782 1.10 deraadt long f_ffree; /* free file nodes in fs */
783 1.10 deraadt fsid_t f_fsid; /* file system id */
784 1.10 deraadt long f_spare[7]; /* spare for later */
785 1.10 deraadt };
786 1.10 deraadt static
787 1.10 deraadt sunstatfs(sp, buf)
788 1.10 deraadt struct statfs *sp;
789 1.10 deraadt caddr_t buf;
790 1.10 deraadt {
791 1.10 deraadt struct sun_statfs ssfs;
792 1.10 deraadt
793 1.10 deraadt bzero(&ssfs, sizeof ssfs);
794 1.10 deraadt ssfs.f_type = 0;
795 1.16 deraadt ssfs.f_bsize = sp->f_bsize;
796 1.10 deraadt ssfs.f_blocks = sp->f_blocks;
797 1.10 deraadt ssfs.f_bfree = sp->f_bfree;
798 1.10 deraadt ssfs.f_bavail = sp->f_bavail;
799 1.10 deraadt ssfs.f_files = sp->f_files;
800 1.10 deraadt ssfs.f_ffree = sp->f_ffree;
801 1.10 deraadt ssfs.f_fsid = sp->f_fsid;
802 1.10 deraadt return copyout((caddr_t)&ssfs, buf, sizeof ssfs);
803 1.10 deraadt }
804 1.10 deraadt
805 1.10 deraadt struct sun_statfs_args {
806 1.10 deraadt char *path;
807 1.10 deraadt struct sun_statfs *buf;
808 1.10 deraadt };
809 1.10 deraadt sun_statfs(p, uap, retval)
810 1.10 deraadt struct proc *p;
811 1.10 deraadt struct sun_statfs_args *uap;
812 1.10 deraadt int *retval;
813 1.10 deraadt {
814 1.10 deraadt register struct mount *mp;
815 1.10 deraadt register struct statfs *sp;
816 1.10 deraadt int error;
817 1.10 deraadt struct nameidata nd;
818 1.10 deraadt
819 1.27 pk NDINIT(&nd, LOOKUP, FOLLOW, UIO_USERSPACE, uap->path, p);
820 1.27 pk if (error = namei(&nd))
821 1.10 deraadt return (error);
822 1.27 pk mp = nd.ni_vp->v_mount;
823 1.10 deraadt sp = &mp->mnt_stat;
824 1.27 pk vrele(nd.ni_vp);
825 1.10 deraadt if (error = VFS_STATFS(mp, sp, p))
826 1.10 deraadt return (error);
827 1.10 deraadt sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
828 1.10 deraadt return sunstatfs(sp, (caddr_t)uap->buf);
829 1.10 deraadt }
830 1.10 deraadt
831 1.10 deraadt struct sun_fstatfs_args {
832 1.10 deraadt int fd;
833 1.10 deraadt struct sun_statfs *buf;
834 1.10 deraadt };
835 1.10 deraadt sun_fstatfs(p, uap, retval)
836 1.10 deraadt struct proc *p;
837 1.10 deraadt struct sun_fstatfs_args *uap;
838 1.10 deraadt int *retval;
839 1.10 deraadt {
840 1.10 deraadt struct file *fp;
841 1.10 deraadt struct mount *mp;
842 1.10 deraadt register struct statfs *sp;
843 1.10 deraadt int error;
844 1.10 deraadt
845 1.10 deraadt if (error = getvnode(p->p_fd, uap->fd, &fp))
846 1.10 deraadt return (error);
847 1.10 deraadt mp = ((struct vnode *)fp->f_data)->v_mount;
848 1.10 deraadt sp = &mp->mnt_stat;
849 1.10 deraadt if (error = VFS_STATFS(mp, sp, p))
850 1.10 deraadt return (error);
851 1.10 deraadt sp->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
852 1.10 deraadt return sunstatfs(sp, (caddr_t)uap->buf);
853 1.10 deraadt }
854 1.10 deraadt
855 1.10 deraadt struct sun_exportfs_args {
856 1.10 deraadt char *path;
857 1.10 deraadt char *ex; /* struct sun_export * */
858 1.10 deraadt };
859 1.10 deraadt sun_exportfs(p, uap, retval)
860 1.10 deraadt struct proc *p;
861 1.10 deraadt struct sun_exportfs_args *uap;
862 1.10 deraadt int *retval;
863 1.10 deraadt {
864 1.10 deraadt /*
865 1.10 deraadt * XXX: should perhaps translate into a mount(2)
866 1.10 deraadt * with MOUNT_EXPORT?
867 1.10 deraadt */
868 1.10 deraadt return 0;
869 1.10 deraadt }
870 1.10 deraadt
871 1.10 deraadt struct sun_mknod_args {
872 1.10 deraadt char *fname;
873 1.10 deraadt int fmode;
874 1.10 deraadt int dev;
875 1.10 deraadt };
876 1.10 deraadt
877 1.10 deraadt sun_mknod(p, uap, retval)
878 1.10 deraadt struct proc *p;
879 1.10 deraadt struct sun_mknod_args *uap;
880 1.10 deraadt int *retval;
881 1.10 deraadt {
882 1.10 deraadt if (S_ISFIFO(uap->fmode))
883 1.10 deraadt return mkfifo(p, uap, retval);
884 1.10 deraadt
885 1.10 deraadt return mknod(p, uap, retval);
886 1.12 deraadt }
887 1.12 deraadt
888 1.12 deraadt #define SUN_SC_ARG_MAX 1
889 1.12 deraadt #define SUN_SC_CHILD_MAX 2
890 1.12 deraadt #define SUN_SC_CLK_TCK 3
891 1.12 deraadt #define SUN_SC_NGROUPS_MAX 4
892 1.12 deraadt #define SUN_SC_OPEN_MAX 5
893 1.12 deraadt #define SUN_SC_JOB_CONTROL 6
894 1.12 deraadt #define SUN_SC_SAVED_IDS 7
895 1.12 deraadt #define SUN_SC_VERSION 8
896 1.12 deraadt
897 1.12 deraadt struct sun_sysconf_args {
898 1.12 deraadt int name;
899 1.12 deraadt };
900 1.12 deraadt
901 1.12 deraadt sun_sysconf(p, uap, retval)
902 1.12 deraadt struct proc *p;
903 1.12 deraadt struct sun_sysconf_args *uap;
904 1.12 deraadt int *retval;
905 1.12 deraadt {
906 1.24 deraadt extern int maxfiles;
907 1.12 deraadt
908 1.12 deraadt switch(uap->name) {
909 1.12 deraadt case SUN_SC_ARG_MAX:
910 1.12 deraadt *retval = ARG_MAX;
911 1.13 deraadt break;
912 1.12 deraadt case SUN_SC_CHILD_MAX:
913 1.12 deraadt *retval = maxproc;
914 1.13 deraadt break;
915 1.12 deraadt case SUN_SC_CLK_TCK:
916 1.12 deraadt *retval = 60; /* should this be `hz', ie. 100? */
917 1.13 deraadt break;
918 1.12 deraadt case SUN_SC_NGROUPS_MAX:
919 1.12 deraadt *retval = NGROUPS_MAX;
920 1.13 deraadt break;
921 1.12 deraadt case SUN_SC_OPEN_MAX:
922 1.24 deraadt *retval = maxfiles;
923 1.13 deraadt break;
924 1.12 deraadt case SUN_SC_JOB_CONTROL:
925 1.12 deraadt *retval = 1;
926 1.13 deraadt break;
927 1.12 deraadt case SUN_SC_SAVED_IDS:
928 1.12 deraadt #ifdef _POSIX_SAVED_IDS
929 1.12 deraadt *retval = 1;
930 1.12 deraadt #else
931 1.12 deraadt *retval = 0;
932 1.12 deraadt #endif
933 1.13 deraadt break;
934 1.12 deraadt case SUN_SC_VERSION:
935 1.12 deraadt *retval = 198808;
936 1.13 deraadt break;
937 1.12 deraadt default:
938 1.12 deraadt return EINVAL;
939 1.12 deraadt }
940 1.12 deraadt return 0;
941 1.17 pk }
942 1.17 pk
943 1.17 pk #define SUN_RLIMIT_NOFILE 6 /* Other RLIMIT_* are the same */
944 1.17 pk #define SUN_RLIM_NLIMITS 7
945 1.17 pk
946 1.17 pk struct sun_getrlimit_args {
947 1.17 pk int which;
948 1.19 cgd struct orlimit *rlp;
949 1.17 pk };
950 1.17 pk
951 1.17 pk sun_getrlimit(p, uap, retval)
952 1.17 pk struct proc *p;
953 1.17 pk struct sun_getrlimit_args *uap;
954 1.17 pk int *retval;
955 1.17 pk {
956 1.17 pk if (uap->which >= SUN_RLIM_NLIMITS)
957 1.17 pk return EINVAL;
958 1.17 pk
959 1.17 pk if (uap->which == SUN_RLIMIT_NOFILE)
960 1.17 pk uap->which = RLIMIT_NOFILE;
961 1.17 pk
962 1.19 cgd return ogetrlimit(p, uap, retval);
963 1.17 pk }
964 1.17 pk
965 1.17 pk struct sun_setrlimit_args {
966 1.17 pk int which;
967 1.19 cgd struct orlimit *rlp;
968 1.17 pk };
969 1.17 pk
970 1.17 pk sun_setrlimit(p, uap, retval)
971 1.17 pk struct proc *p;
972 1.17 pk struct sun_getrlimit_args *uap;
973 1.17 pk int *retval;
974 1.17 pk {
975 1.17 pk if (uap->which >= SUN_RLIM_NLIMITS)
976 1.17 pk return EINVAL;
977 1.17 pk
978 1.17 pk if (uap->which == SUN_RLIMIT_NOFILE)
979 1.17 pk uap->which = RLIMIT_NOFILE;
980 1.17 pk
981 1.19 cgd return osetrlimit(p, uap, retval);
982 1.1 deraadt }
983